Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758107AbcJHRHV (ORCPT ); Sat, 8 Oct 2016 13:07:21 -0400 Received: from mail-co1nam03on0112.outbound.protection.outlook.com ([104.47.40.112]:59109 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751704AbcJHRGu (ORCPT ); Sat, 8 Oct 2016 13:06:50 -0400 X-Greylist: delayed 2144 seconds by postgrey-1.27 at vger.kernel.org; Sat, 08 Oct 2016 13:06:50 EDT Authentication-Results: spf=softfail (sender IP is 66.129.239.18) smtp.mailfrom=juniper.net; linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=juniper.net; Date: Sat, 8 Oct 2016 09:30:57 -0700 From: Georgi Vlaev To: Andrew Lunn CC: Pantelis Antoniou , David Miller , Lee Jones , Rob Herring , Mark Rutland , Frank Rowand , Florian Fainelli , "Debjit Ghosh" , Guenter Roeck , Maryam Seraj , , , Subject: Re: [PATCH 09/10] net: phy: Add MDIO driver for Juniper's SAM FPGA Message-ID: <20161008163056.GA17131@svl-evodev-gvlaev.juniper.net> References: <1475853518-22264-1-git-send-email-pantelis.antoniou@konsulko.com> <1475853518-22264-10-git-send-email-pantelis.antoniou@konsulko.com> <20161007211326.GB10197@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20161007211326.GB10197@lunn.ch> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:66.129.239.18;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(7916002)(2980300002)(24454002)(199003)(377424004)(189002)(2950100002)(6916009)(1076002)(586003)(305945005)(11100500001)(23726003)(97756001)(8676002)(47776003)(92566002)(356003)(7846002)(69596002)(19580405001)(19580395003)(86362001)(81156014)(81166006)(50466002)(83506001)(189998001)(106466001)(2906002)(87936001)(4326007)(5660300001)(68736007)(7696004)(110136003)(7416002)(626004)(76176999)(54356999)(50986999)(46406003)(53416004)(8936002)(97736004)(105596002)(77096005)(4001350100001)(33656002)(18370500001);DIR:OUT;SFP:1102;SCL:1;SRVR:SN2PR05MB2736;H:p-emfe01a-sac.jnpr.net;FPR:;SPF:SoftFail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD038;1:qyHJCv+h4ZcZjQd+EUl80KRliLsu+yQCGAF/JYr6xyCE4xd39okC46W3CLJUpz5rZ6j8edDS3DsR+LItfHZ+h/0YBYZnmFPpfCEk1hWPQn0mOjYR2J7AZOz7zD0f+5dY2tVIwN0tKgDkf1fYYOJBN3G2TgOkNz2UBWb4RbE8F0UWUxMAwo8iDT3uz+mtU7vZhfZC/VTwv0JJjbR1Uv+GRz/S0YGfPR2tKF47GV50xXeGmEVDYq4X/MVGnABc6T4xd7VfryUNnQrNMpkuTPhyIEda94Xc7ooHCbTy1Iy4mN5gU9HTmCKPzktc0AzyoOuMARnIdwfk6z5N0egjqjz6OFmU36I5R/eBTq991yEyh1nX2Voalq0bds/yxnpNhOdcFUwe5WHv+iobLCVg0fe7ltcYegmpecwfFMICJaMNlUXa4tl/G8ShAE4KXENQbQbHMYETNdyy64k4dRZYMeISyi5fS264CRrMtdXpt3MewptBPXNDS48r5drFczTlRZGG7Rpn0SaVaXBx+xxFQapWIw92DHEX0XdTdkoUsgbSLsqPgOp3hAuKPpfukgtMPacab/WcuLR2KXecSXdXinB2ZA== X-MS-Office365-Filtering-Correlation-Id: 0107de47-6097-4407-6e08-08d3ef987d8e X-Microsoft-Exchange-Diagnostics: 1;SN2PR05MB2736;2:iWN+/F7IMV09yBopU4Rind4K1EqOSBtVNviCbh9KsiPpzz0zq2FXSNfUenOt5CeU76GQvN4ssDvH6f4cm/MdovsHKAqYwSx/gSLDzpjX/24Y/4TwUS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hjM/Xxh7b+5cK95YxMptu9L/s0nDHs5rpIwrLTpdcgs1d2kws59Fo9UFfKGY9pALt2mvbTtje6cBtqGWuN4JWNTVkpZnDvKpL7Lmb8Mm4F93M1omjD0kZ9mp5NTlGTRzSH3uccGUgHd3skrzv X-Microsoft-Exchange-Diagnostics: 1;SN2PR05MB2736;31:1V+mpJBGUbwJIds3ZFz9ULSyBWvxv1RtJu3yfAbbNNeetd+rhkkWaZWcCKpoXVW8p7HWG4PcNtL/5aSqoJInH7PEEiBbY8b/PFkj+LcTH2xonttmkEo3/BdA+K5t+GllR1nEjE0CngXjaa2C2dsTV7X5Y9WRD7nDZO/1KxGLg9CXYix3hli3iacCY49cB+G6s49cmyV3FESPwetuUvY3Oeq8Fg5tb0kiJ4XSoOspRzKErABc8Vr984750Jnqq+jB4vu8LwuRo2jMLN/MpI7t3A==;20:UIxc6rBBhLHxSUr0nTWlgsYcTvN7DKtW8mbFyObBt9ENqiez4KZHrdV9aCIOH7ZsfUIemwTX5bvnEQMfiarD6lzHTKeHWcSh0/MxzrSL8HIDIEmZeHZX23p2r1wM4y6SuFffpns86KRCWdjYcM+ea7/oCe/wcjWT9gE+R7yN9d3X7k5OFTxUyfl6A/ozLhph5vTv2yJwSbETUavNdWHTPXcX3ZYbWCboucLeuNtUwl38Ba4pNHWlEPqOHcED5Pd8dWkm6hhqw5AC5fB2323Y2hi833nZBrADAipKZhOtbatFlkt43FTwePuPkFLqII4Mr9UD6dPeEsyrhqPhBDRaL0l/z+fpan+/UWa64z51gSEiFrhq4wLGII621DH++Amu7mKHjPs8QT8uUBYyJ8bkVUsqIN4lTRqIYNzBdrpdOOnm1inyEwnNw8jeii7aEtkyGYgPFhC1heu57H+qN0C/izaYGXtcW7cAcIKWtdru27R0liI3exZmkNMtJfdAdRck X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(138986009662008); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(13024025)(13017025)(13015025)(13018025)(13023025)(8121501046)(5005006)(3002001)(10201501046)(6055026);SRVR:SN2PR05MB2736;BCL:0;PCL:0;RULEID:;SRVR:SN2PR05MB2736; X-Microsoft-Exchange-Diagnostics: 1;SN2PR05MB2736;4:l2YFW/HF9f1EQyyXBHna16+eyZdRjVtYZj6cnzs6IfbJ7yxgcNy2NXpE/GlkWIlHKgoXFbOYIxKgb/zDbvMjjCX/wTYrVoK8nsBkE+YjcCUg+5toaGm/6pCbsDlPFzQXLRd4HMm6wh3OKEMkjwLO3/Q+CGgkDc3oWcrKrBbWNB8g89kjPxImF6JTlWUB4ClLBsVcR62UQ9M1OXF06MBhtUXVNjW9dcP33p5IROdQlpBhdMmJCMiwqUehVoDjDMe2y/d/tbIfPID7ATYVkCe5W0iq7ugNRb6mUSYzklC8StLl+V+iNmeIdPGocpMmyxdKzLloXMP96TYrDMlOhWBCqHGtILdOyRDf5GeaFY+MDrzMm1/+pCnK1Isq5CnXbjCX961/ulBT8zIgpOAGq9vvZqKPw8OsPEYfDOyAGFf7aKXy6qPhZGFt+na7yGiDbtiQFtOV6mQdP2jr9NV/5Nw0Lzc9syamUzJX8hnpg8S1AQJH2WDsxsNd3CzJbKlnG8QH8aTIGfAl+C7VfJ/bgONwkklJUkbdYk6oiGKpCZ+x8M3ZlV9diHJfY/90wHn6GI1z X-Forefront-PRVS: 008960E8EC X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR05MB2736;23:Jw/CycN/NPIpZ5hhPQjsP74uFqDvZ4VjYmOhrITdC?= =?us-ascii?Q?D/9Cwc0p9A1GjpVP0y1KUWMfZNHxbX1cBhQGuD1BcJYRIptrmho0sQSYgBiL?= =?us-ascii?Q?pNQxLqETp2X6X+Vqri/DvLunJBwzFP1NEyQnxZFn+hLmgPwYd1b/+3+RlXlC?= =?us-ascii?Q?g+dYctEXQ3lmABZ7sTg6elptLsHy2hqqfuPkHR43qu/wuD7ZKXAnsWhuq8oV?= =?us-ascii?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OIBnFqtSqVjfECnL8Nsuc2/gugXxtStKUZVMBkY02R7fNt39ElSTa0slBLR5Mt31Svlka4e/gRrMFmC4zFDG6MMbTLQs9e SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: juniper.net X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2016 16:31:00.5557 (UTC) X-MS-Exchange-CrossTenant-Id: bea78b3c-4cdb-4130-854a-1d193232e5f4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=bea78b3c-4cdb-4130-854a-1d193232e5f4;Ip=[66.129.239.18];Helo=[p-emfe01a-sac.jnpr.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR05MB2736 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9030 Lines: 331 Hi Andrew, On 16-10-07 23:13:26, Andrew Lunn wrote: > On Fri, Oct 07, 2016 at 06:18:37PM +0300, Pantelis Antoniou wrote: > > From: Georgi Vlaev > > > > Add driver for the MDIO IP block present in Juniper's > > SAM FPGA. > > > > This driver supports only Clause 45 of the 802.3 spec. > > > > Note that due to the fact that there are no drivers for > > Broadcom/Avago retimers on 10/40Ge path that are controlled > > from the MDIO interface there is a method to have direct > > access to registers via a debugfs interface. > > This seems to be the wrong solution. Why not write those drivers? > > Controlling stuff from user space is generally frowned up. So i expect > DaveM will NACK this patch. Please remove all the debugfs stuff. I'll drop the debugfs and sysfs attributes. This will remove the access from the user space. > > > +static int mdio_sam_stat_wait(struct mii_bus *bus, u32 wait_mask) > > +{ > > + struct mdio_sam_data *data = bus->priv; > > + unsigned long timeout; > > + u32 stat; > > + > > + timeout = jiffies + msecs_to_jiffies(MDIO_RDY_TMO); > > + do { > > + stat = ioread32(data->base + MDIO_STATUS); > > + if (stat & wait_mask) > > + return 0; > > + > > + usleep_range(50, 100); > > + } while (time_before(jiffies, timeout)); > > + > > + return -EBUSY; > > I've recently had to fix a loop like this in another > driver. usleep_range(50, 100) can sleep for a lot longer. If it sleeps > for MDIO_RDY_TMO you exit out with -EBUSY after a single iteration, > which is not what you want. It is better to make a fixed number of > iterations rather than a timeout. > OK, I'll change it. > > +} > > + > > +static int mdio_sam_read(struct mii_bus *bus, int phy_id, int regnum) > > +{ > > + struct mdio_sam_data *data = bus->priv; > > + u32 command, res; > > + int ret; > > + > > + /* mdiobus_read holds the bus->mdio_lock mutex */ > > + > > + if (!(regnum & MII_ADDR_C45)) > > + return -ENXIO; > > + > > + ret = mdio_sam_stat_wait(bus, STAT_REG_RDY); > > + if (ret < 0) > > + return ret; > > + > > + command = regnum & 0x1fffff; /* regnum = (dev_id << 16) | reg */ > > + command |= ((phy_id & 0x1f) << 21); > > + > > + iowrite32(command, data->base + MDIO_CMD1); > > + ioread32(data->base + MDIO_CMD1); > > > > + iowrite32(CMD2_READ | CMD2_ENABLE, data->base + MDIO_CMD2); > > + ioread32(data->base + MDIO_CMD2); > > Why do you need to read the values back? Hardware bug? > We have a lot of these 'SAM' type of FPGAs, that follow the same spec, but implemented in a different way. Some software revisions have issues. > > + iowrite32(TBL_CMD_REG_GO, data->base + MDIO_TBL_CMD); > > + ioread32(data->base + MDIO_TBL_CMD); > > Although not wrong, most drivers use writel(). > > > + > > + usleep_range(50, 100); > > + > > + ret = mdio_sam_stat_wait(bus, (STAT_REG_DONE | STAT_REG_ERR)); > > Do you really need a wait before calling mdio_sam_stat_wait()? Isn't > that what it is supposed to do, wait... > I'll remove it. > > + if (ret < 0) > > + return ret; > > + > > + res = ioread32(data->base + MDIO_RESULT); > > + > > + if (res & RES_ERROR || !(res & RES_SUCCESS)) > > + return -EIO; > > + > > + return (res & 0xffff); > > +} > > + > > +static int mdio_sam_write(struct mii_bus *bus, int phy_id, int regnum, u16 val) > > +{ > > + struct mdio_sam_data *data = bus->priv; > > + u32 command; > > + int ret; > > + > > + /* mdiobus_write holds the bus->mdio_lock mutex */ > > + > > + if (!(regnum & MII_ADDR_C45)) > > + return -ENXIO; > > + > > + ret = mdio_sam_stat_wait(bus, STAT_REG_RDY); > > + if (ret < 0) > > + return ret; > > + > > + command = regnum & 0x1fffff; /* regnum = (dev_id << 16) | reg */ > > + command |= ((phy_id & 0x1f) << 21); > > + > > + iowrite32(command, data->base + MDIO_CMD1); > > + ioread32(data->base + MDIO_CMD1); > > + iowrite32(CMD2_ENABLE | val, data->base + MDIO_CMD2); > > + ioread32(data->base + MDIO_CMD2); > > + iowrite32(TBL_CMD_REG_GO, data->base + MDIO_TBL_CMD); > > + ioread32(data->base + MDIO_TBL_CMD); > > + > > + usleep_range(50, 100); > > + > > + ret = mdio_sam_stat_wait(bus, (STAT_REG_DONE | STAT_REG_ERR)); > > + if (ret < 0) > > + return ret; > > + > > + return 0; > > +} > > + > > +static int mdio_sam_reset(struct mii_bus *bus) > > +{ > > + struct mdio_sam_data *data = bus->priv; > > + > > + iowrite32(TBL_CMD_SOFT_RESET, data->base + MDIO_TBL_CMD); > > + ioread32(data->base + MDIO_TBL_CMD); > > + mdelay(10); > > + iowrite32(0, data->base + MDIO_TBL_CMD); > > + ioread32(data->base + MDIO_TBL_CMD); > > + > > + /* zero tables */ > > + memset_io(data->base + MDIO_CMD1, 0, 0x1000); > > + memset_io(data->base + MDIO_PRI_CMD1, 0, 0x1000); > > What tables? > For each bus, the MDIO block has 3 tables of 512 entries - 2 "command" and one "result" table. Addresses and data are written in the "command" table, the returned value for a read command is written in the "result" table. Once a start is triggered, the FPGA will flush all entries in those tables, starting from offset 0. We don't want to have stale entries in the tables, as they might result in transactions on the bus, so we have to clear everything at least once. Actually we're using just a single entry (1/512) from those tables. > > + > > + return 0; > > +} > > + > > +static int mdio_sam_of_register_bus(struct platform_device *pdev, > > + struct device_node *np, void __iomem *base) > > +{ > > + struct mii_bus *bus; > > + struct mdio_sam_data *data; > > + u32 reg; > > + int ret; > > + > > + bus = devm_mdiobus_alloc_size(&pdev->dev, sizeof(*data)); > > + if (!bus) > > + return -ENOMEM; > > + > > + /* bus offset */ > > + ret = of_property_read_u32(np, "reg", ®); > > + if (ret) > > + return -ENODEV; > > + > > + data = bus->priv; > > + data->base = base + reg; > > + > > + bus->parent = &pdev->dev; > > + bus->name = "mdio-sam"; > > + bus->read = mdio_sam_read; > > + bus->write = mdio_sam_write; > > + bus->reset = mdio_sam_reset; > > + snprintf(bus->id, MII_BUS_ID_SIZE, "mdiosam-%x-%x", pdev->id, reg); > > + > > + ret = of_mdiobus_register(bus, np); > > + if (ret < 0) > > + return ret; > > +#ifdef CONFIG_DEBUG_FS > > + ret = mdio_sam_debugfs_init(bus); > > + if (ret < 0) > > + goto err_unregister; > > +#endif > > + ret = device_create_bin_file(&bus->dev, &bin_attr_raw_io); > > + if (ret) > > + goto err_debugfs; > > + > > + return 0; > > + > > +err_debugfs: > > +#ifdef CONFIG_DEBUG_FS > > + mdio_sam_debugfs_remove(bus); > > +#endif > > +err_unregister: > > + mdiobus_unregister(bus); > > + > > + return ret; > > +} > > + > > +static int mdio_sam_of_unregister_bus(struct device_node *np) > > +{ > > + struct mii_bus *bus; > > + > > + bus = of_mdio_find_bus(np); > > + if (bus) { > > + device_remove_bin_file(&bus->dev, &bin_attr_raw_io); > > +#ifdef CONFIG_DEBUG_FS > > + mdio_sam_debugfs_remove(bus); > > +#endif > > + mdiobus_unregister(bus); > > + } > > + return 0; > > +} > > + > > +static int mdio_sam_probe(struct platform_device *pdev) > > +{ > > + struct device_node *np; > > + struct resource *res; > > + void __iomem *base; > > + int ret; > > + > > + if (!pdev->dev.of_node) > > + return -ENODEV; > > + > > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > + base = devm_ioremap_nocache(&pdev->dev, res->start, > > + resource_size(res)); > > Why nocache? > I'll change it to devm_ioremap(). > > + if (IS_ERR(base)) > > + return PTR_ERR(base); > > + > > + for_each_available_child_of_node(pdev->dev.of_node, np) { > > + ret = mdio_sam_of_register_bus(pdev, np, base); > > + if (ret) > > + goto err; > > + } > > This is odd. There does not seem to be any shared resources. So you > should really have one MDIO bus as one device in the device tree. > Well, there's no shared resource, so probably it can be changed to a single device/bus. This might require changing the parent MFD as well. > > > Andrew > > > + > > + return 0; > > +err: > > + /* roll back everything */ > > + for_each_available_child_of_node(pdev->dev.of_node, np) > > + mdio_sam_of_unregister_bus(np); > > + > > + return ret; > > +} > > + > > +static int mdio_sam_remove(struct platform_device *pdev) > > +{ > > + struct device_node *np; > > + > > + for_each_available_child_of_node(pdev->dev.of_node, np) > > + mdio_sam_of_unregister_bus(np); > > + > > + return 0; > > +} > > + > > +static const struct of_device_id mdio_sam_of_match[] = { > > + { .compatible = "jnx,mdio-sam" }, > > + { } > > +}; > > +MODULE_DEVICE_TABLE(of, mdio_sam_of_match); > > + > > +static struct platform_driver mdio_sam_driver = { > > + .probe = mdio_sam_probe, > > + .remove = mdio_sam_remove, > > + .driver = { > > + .name = "mdio-sam", > > + .owner = THIS_MODULE, > > + .of_match_table = mdio_sam_of_match, > > + }, > > +}; > > + > > +module_platform_driver(mdio_sam_driver); > > + > > +MODULE_ALIAS("platform:mdio-sam"); > > +MODULE_AUTHOR("Georgi Vlaev "); > > +MODULE_LICENSE("GPL"); > > +MODULE_DESCRIPTION("Juniper Networks SAM MDIO bus driver"); > > -- > > 1.9.1 > > -- joe