From patchwork Fri Oct 10 01:32:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iyappan Subramanian X-Patchwork-Id: 5063191 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3A4CD9F295 for ; Fri, 10 Oct 2014 01:35:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F285C20204 for ; Fri, 10 Oct 2014 01:35:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B69262020E for ; Fri, 10 Oct 2014 01:35:18 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XcP4v-0005C9-DQ; Fri, 10 Oct 2014 01:33:09 +0000 Received: from exprod5og113.obsmtp.com ([64.18.0.26]) by bombadil.infradead.org with smtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XcP4E-0004sG-Qk for linux-arm-kernel@lists.infradead.org; Fri, 10 Oct 2014 01:32:28 +0000 Received: from mail-pd0-f174.google.com ([209.85.192.174]) (using TLSv1) by exprod5ob113.postini.com ([64.18.4.12]) with SMTP ID DSNKVDc3FVz3s5j+t2MgjRLVqz1S62X0pex0@postini.com; Thu, 09 Oct 2014 18:32:26 PDT Received: by mail-pd0-f174.google.com with SMTP id y13so689187pdi.5 for ; Thu, 09 Oct 2014 18:32:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cpyKE7W8WmsC/Q5WoUDA5uUo4JKwW/q/4rJDxj4/nAM=; b=QRkp1CrMSFERb/sOFt82P/1v6A93HDZ8mhnOnXI11RQKEH3BlGPsan9PiEz9KopOqG P6Asw+/ktL7rYcbWd7x9EIiWwMEuy1r9FOWlC7cjPTmnI3m62NmbwiY423jdl5+zEafu JgGLFbi40LxksnwGkU736d5LT0brSR5CilT2YhmJrMkghxXIlVnxmldfhhscAsFi1Ntw /P0Uz4btnT2MQGKUFYZenrgpq7EVboznfwIOuSxt8AG14UoQcPzYDZk5jdNGs9S1xCmG mXMbu3yFr5WcuJsd03Yo9/ldpGOwg9edx8exXi2ytr9/bqZec4uYGIfVfXFy+KcT500L +BQQ== X-Gm-Message-State: ALoCoQlqFux9l98garojdf8F2m0P8yLJ8dnyAEDQ9QRNpAn+ee3xxIirdH+JLI03oTzTzDhyIf0DyAZNTXM3h8AzI9k7VQ1BjwyEVcf2HB8UrpOEl8VQfxMT32W5Yvmhi1h6OHy/eMYO/3061T6n90uj6nMRK8KFIr1qBtgUK/h19n+ynbsCu28= X-Received: by 10.66.254.195 with SMTP id ak3mr390805pad.142.1412904725216; Thu, 09 Oct 2014 18:32:05 -0700 (PDT) X-Received: by 10.66.254.195 with SMTP id ak3mr390798pad.142.1412904725143; Thu, 09 Oct 2014 18:32:05 -0700 (PDT) Received: from svdclab-13-11.amcc.com (67-207-112-226.static.wiline.com. [67.207.112.226]) by mx.google.com with ESMTPSA id a1sm1686537pdc.68.2014.10.09.18.32.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Oct 2014 18:32:03 -0700 (PDT) From: Iyappan Subramanian To: davem@davemloft.net, netdev@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v4 4/6] drivers: net: xgene: Preparing for adding 10GbE support Date: Thu, 9 Oct 2014 18:32:05 -0700 Message-Id: <1412904727-23485-5-git-send-email-isubramanian@apm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412904727-23485-1-git-send-email-isubramanian@apm.com> References: <1412904727-23485-1-git-send-email-isubramanian@apm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141009_183226_965266_086542ED X-CRM114-Status: GOOD ( 16.50 ) X-Spam-Score: -2.3 (--) Cc: kchudgar@apm.com, patches@apm.com, linux-arm-kernel@lists.infradead.org, Iyappan Subramanian X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - Rearranged code to pave the way for adding 10GbE support - Added mac_ops structure containing function pointers for mac specific functions - Added port_ops structure containing function pointers for port specific functions Signed-off-by: Iyappan Subramanian Signed-off-by: Keyur Chudgar --- drivers/net/ethernet/apm/xgene/xgene_enet_hw.c | 44 ++++++++++++++++-------- drivers/net/ethernet/apm/xgene/xgene_enet_hw.h | 16 ++------- drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 40 +++++++++++++-------- drivers/net/ethernet/apm/xgene/xgene_enet_main.h | 19 ++++++++++ 4 files changed, 78 insertions(+), 41 deletions(-) diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c index 812d8d6..c8f3824 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c @@ -402,7 +402,7 @@ static int xgene_mii_phy_read(struct xgene_enet_pdata *pdata, return data; } -void xgene_gmac_set_mac_addr(struct xgene_enet_pdata *pdata) +static void xgene_gmac_set_mac_addr(struct xgene_enet_pdata *pdata) { u32 addr0, addr1; u8 *dev_addr = pdata->ndev->dev_addr; @@ -436,13 +436,13 @@ static int xgene_enet_ecc_init(struct xgene_enet_pdata *pdata) return 0; } -void xgene_gmac_reset(struct xgene_enet_pdata *pdata) +static void xgene_gmac_reset(struct xgene_enet_pdata *pdata) { xgene_enet_wr_mcx_mac(pdata, MAC_CONFIG_1_ADDR, SOFT_RESET1); xgene_enet_wr_mcx_mac(pdata, MAC_CONFIG_1_ADDR, 0); } -void xgene_gmac_init(struct xgene_enet_pdata *pdata, int speed) +static void xgene_gmac_init(struct xgene_enet_pdata *pdata) { u32 value, mc2; u32 intf_ctl, rgmii; @@ -456,7 +456,7 @@ void xgene_gmac_init(struct xgene_enet_pdata *pdata, int speed) xgene_enet_rd_mcx_mac(pdata, INTERFACE_CONTROL_ADDR, &intf_ctl); xgene_enet_rd_csr(pdata, RGMII_REG_0_ADDR, &rgmii); - switch (speed) { + switch (pdata->phy_speed) { case SPEED_10: ENET_INTERFACE_MODE2_SET(&mc2, 1); CFG_MACMODE_SET(&icm0, 0); @@ -525,8 +525,8 @@ static void xgene_enet_config_ring_if_assoc(struct xgene_enet_pdata *pdata) xgene_enet_wr_ring_if(pdata, ENET_CFGSSQMIQMLITEFPQASSOC_ADDR, val); } -void xgene_enet_cle_bypass(struct xgene_enet_pdata *pdata, - u32 dst_ring_num, u16 bufpool_id) +static void xgene_enet_cle_bypass(struct xgene_enet_pdata *pdata, + u32 dst_ring_num, u16 bufpool_id) { u32 cb; u32 fpsel; @@ -544,7 +544,7 @@ void xgene_enet_cle_bypass(struct xgene_enet_pdata *pdata, xgene_enet_wr_csr(pdata, CLE_BYPASS_REG1_0_ADDR, cb); } -void xgene_gmac_rx_enable(struct xgene_enet_pdata *pdata) +static void xgene_gmac_rx_enable(struct xgene_enet_pdata *pdata) { u32 data; @@ -552,7 +552,7 @@ void xgene_gmac_rx_enable(struct xgene_enet_pdata *pdata) xgene_enet_wr_mcx_mac(pdata, MAC_CONFIG_1_ADDR, data | RX_EN); } -void xgene_gmac_tx_enable(struct xgene_enet_pdata *pdata) +static void xgene_gmac_tx_enable(struct xgene_enet_pdata *pdata) { u32 data; @@ -560,7 +560,7 @@ void xgene_gmac_tx_enable(struct xgene_enet_pdata *pdata) xgene_enet_wr_mcx_mac(pdata, MAC_CONFIG_1_ADDR, data | TX_EN); } -void xgene_gmac_rx_disable(struct xgene_enet_pdata *pdata) +static void xgene_gmac_rx_disable(struct xgene_enet_pdata *pdata) { u32 data; @@ -568,7 +568,7 @@ void xgene_gmac_rx_disable(struct xgene_enet_pdata *pdata) xgene_enet_wr_mcx_mac(pdata, MAC_CONFIG_1_ADDR, data & ~RX_EN); } -void xgene_gmac_tx_disable(struct xgene_enet_pdata *pdata) +static void xgene_gmac_tx_disable(struct xgene_enet_pdata *pdata) { u32 data; @@ -576,7 +576,7 @@ void xgene_gmac_tx_disable(struct xgene_enet_pdata *pdata) xgene_enet_wr_mcx_mac(pdata, MAC_CONFIG_1_ADDR, data & ~TX_EN); } -void xgene_enet_reset(struct xgene_enet_pdata *pdata) +static void xgene_enet_reset(struct xgene_enet_pdata *pdata) { u32 val; @@ -593,7 +593,7 @@ void xgene_enet_reset(struct xgene_enet_pdata *pdata) xgene_enet_wr_mcx_mac(pdata, MII_MGMT_CONFIG_ADDR, val); } -void xgene_gport_shutdown(struct xgene_enet_pdata *pdata) +static void xgene_gport_shutdown(struct xgene_enet_pdata *pdata) { clk_disable_unprepare(pdata->clk); } @@ -627,10 +627,10 @@ static void xgene_enet_adjust_link(struct net_device *ndev) if (phydev->link) { if (pdata->phy_speed != phydev->speed) { - xgene_gmac_init(pdata, phydev->speed); + pdata->phy_speed = phydev->speed; + xgene_gmac_init(pdata); xgene_gmac_rx_enable(pdata); xgene_gmac_tx_enable(pdata); - pdata->phy_speed = phydev->speed; phy_print_status(phydev); } } else { @@ -726,3 +726,19 @@ void xgene_enet_mdio_remove(struct xgene_enet_pdata *pdata) mdiobus_free(pdata->mdio_bus); pdata->mdio_bus = NULL; } + +struct xgene_mac_ops xgene_gmac_ops = { + .init = xgene_gmac_init, + .reset = xgene_gmac_reset, + .rx_enable = xgene_gmac_rx_enable, + .tx_enable = xgene_gmac_tx_enable, + .rx_disable = xgene_gmac_rx_disable, + .tx_disable = xgene_gmac_tx_disable, + .set_mac_addr = xgene_gmac_set_mac_addr, +}; + +struct xgene_port_ops xgene_gport_ops = { + .reset = xgene_enet_reset, + .cle_bypass = xgene_enet_cle_bypass, + .shutdown = xgene_gport_shutdown, +}; diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h index 371e7a5..084ac68 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h @@ -318,20 +318,10 @@ void xgene_enet_parse_error(struct xgene_enet_desc_ring *ring, struct xgene_enet_pdata *pdata, enum xgene_enet_err_code status); -void xgene_enet_reset(struct xgene_enet_pdata *priv); -void xgene_gmac_reset(struct xgene_enet_pdata *priv); -void xgene_gmac_init(struct xgene_enet_pdata *priv, int speed); -void xgene_gmac_tx_enable(struct xgene_enet_pdata *priv); -void xgene_gmac_rx_enable(struct xgene_enet_pdata *priv); -void xgene_gmac_tx_disable(struct xgene_enet_pdata *priv); -void xgene_gmac_rx_disable(struct xgene_enet_pdata *priv); -void xgene_gmac_set_mac_addr(struct xgene_enet_pdata *pdata); -void xgene_enet_cle_bypass(struct xgene_enet_pdata *pdata, - u32 dst_ring_num, u16 bufpool_id); -void xgene_gport_shutdown(struct xgene_enet_pdata *priv); -void xgene_gmac_get_tx_stats(struct xgene_enet_pdata *pdata); - int xgene_enet_mdio_config(struct xgene_enet_pdata *pdata); void xgene_enet_mdio_remove(struct xgene_enet_pdata *pdata); +extern struct xgene_mac_ops xgene_gmac_ops; +extern struct xgene_port_ops xgene_gport_ops; + #endif /* __XGENE_ENET_HW_H__ */ diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c index e4222af..c432644 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c @@ -413,7 +413,7 @@ static void xgene_enet_timeout(struct net_device *ndev) { struct xgene_enet_pdata *pdata = netdev_priv(ndev); - xgene_gmac_reset(pdata); + pdata->mac_ops->reset(pdata); } static int xgene_enet_register_irq(struct net_device *ndev) @@ -445,10 +445,11 @@ static void xgene_enet_free_irq(struct net_device *ndev) static int xgene_enet_open(struct net_device *ndev) { struct xgene_enet_pdata *pdata = netdev_priv(ndev); + struct xgene_mac_ops *mac_ops = pdata->mac_ops; int ret; - xgene_gmac_tx_enable(pdata); - xgene_gmac_rx_enable(pdata); + mac_ops->tx_enable(pdata); + mac_ops->rx_enable(pdata); ret = xgene_enet_register_irq(ndev); if (ret) @@ -466,6 +467,7 @@ static int xgene_enet_open(struct net_device *ndev) static int xgene_enet_close(struct net_device *ndev) { struct xgene_enet_pdata *pdata = netdev_priv(ndev); + struct xgene_mac_ops *mac_ops = pdata->mac_ops; netif_stop_queue(ndev); @@ -476,8 +478,8 @@ static int xgene_enet_close(struct net_device *ndev) xgene_enet_free_irq(ndev); xgene_enet_process_ring(pdata->rx_ring, -1); - xgene_gmac_tx_disable(pdata); - xgene_gmac_rx_disable(pdata); + mac_ops->tx_disable(pdata); + mac_ops->rx_disable(pdata); return 0; } @@ -724,7 +726,7 @@ static int xgene_enet_set_mac_address(struct net_device *ndev, void *addr) ret = eth_mac_addr(ndev, addr); if (ret) return ret; - xgene_gmac_set_mac_addr(pdata); + pdata->mac_ops->set_mac_addr(pdata); return ret; } @@ -834,8 +836,8 @@ static int xgene_enet_init_hw(struct xgene_enet_pdata *pdata) u16 dst_ring_num; int ret; - xgene_gmac_tx_disable(pdata); - xgene_gmac_rx_disable(pdata); + pdata->mac_ops->tx_disable(pdata); + pdata->mac_ops->rx_disable(pdata); ret = xgene_enet_create_desc_rings(ndev); if (ret) { @@ -853,11 +855,17 @@ static int xgene_enet_init_hw(struct xgene_enet_pdata *pdata) } dst_ring_num = xgene_enet_dst_ring_num(pdata->rx_ring); - xgene_enet_cle_bypass(pdata, dst_ring_num, buf_pool->id); + pdata->port_ops->cle_bypass(pdata, dst_ring_num, buf_pool->id); return ret; } +static void xgene_enet_setup_ops(struct xgene_enet_pdata *pdata) +{ + pdata->mac_ops = &xgene_gmac_ops; + pdata->port_ops = &xgene_gport_ops; +} + static int xgene_enet_probe(struct platform_device *pdev) { struct net_device *ndev; @@ -886,8 +894,9 @@ static int xgene_enet_probe(struct platform_device *pdev) if (ret) goto err; - xgene_enet_reset(pdata); - xgene_gmac_init(pdata, SPEED_1000); + xgene_enet_setup_ops(pdata); + pdata->port_ops->reset(pdata); + pdata->mac_ops->init(pdata); ret = register_netdev(ndev); if (ret) { @@ -918,19 +927,21 @@ err: static int xgene_enet_remove(struct platform_device *pdev) { struct xgene_enet_pdata *pdata; + struct xgene_mac_ops *mac_ops; struct net_device *ndev; pdata = platform_get_drvdata(pdev); + mac_ops = pdata->mac_ops; ndev = pdata->ndev; - xgene_gmac_rx_disable(pdata); - xgene_gmac_tx_disable(pdata); + mac_ops->rx_disable(pdata); + mac_ops->tx_disable(pdata); netif_napi_del(&pdata->rx_ring->napi); xgene_enet_mdio_remove(pdata); xgene_enet_delete_desc_rings(pdata); unregister_netdev(ndev); - xgene_gport_shutdown(pdata); + pdata->port_ops->shutdown(pdata); free_netdev(ndev); return 0; @@ -956,5 +967,6 @@ module_platform_driver(xgene_enet_driver); MODULE_DESCRIPTION("APM X-Gene SoC Ethernet driver"); MODULE_VERSION(XGENE_DRV_VERSION); +MODULE_AUTHOR("Iyappan Subramanian "); MODULE_AUTHOR("Keyur Chudgar "); MODULE_LICENSE("GPL"); diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.h b/drivers/net/ethernet/apm/xgene/xgene_enet_main.h index 0815866..ac180f9 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.h +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.h @@ -68,6 +68,23 @@ struct xgene_enet_desc_ring { }; }; +struct xgene_mac_ops { + void (*init)(struct xgene_enet_pdata *pdata); + void (*reset)(struct xgene_enet_pdata *pdata); + void (*tx_enable)(struct xgene_enet_pdata *pdata); + void (*rx_enable)(struct xgene_enet_pdata *pdata); + void (*tx_disable)(struct xgene_enet_pdata *pdata); + void (*rx_disable)(struct xgene_enet_pdata *pdata); + void (*set_mac_addr)(struct xgene_enet_pdata *pdata); +}; + +struct xgene_port_ops { + void (*reset)(struct xgene_enet_pdata *pdata); + void (*cle_bypass)(struct xgene_enet_pdata *pdata, + u32 dst_ring_num, u16 bufpool_id); + void (*shutdown)(struct xgene_enet_pdata *pdata); +}; + /* ethernet private data */ struct xgene_enet_pdata { struct net_device *ndev; @@ -98,6 +115,8 @@ struct xgene_enet_pdata { u32 speed; u16 rm; struct rtnl_link_stats64 stats; + struct xgene_mac_ops *mac_ops; + struct xgene_port_ops *port_ops; }; /* Set the specified value into a bit-field defined by its starting position