From patchwork Mon Aug 15 15:16:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 73918 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1494493qga; Mon, 15 Aug 2016 08:16:57 -0700 (PDT) X-Received: by 10.98.103.70 with SMTP id b67mr55089393pfc.30.1471274217680; Mon, 15 Aug 2016 08:16:57 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4si27096896pfj.267.2016.08.15.08.16.57; Mon, 15 Aug 2016 08:16:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753000AbcHOPQk (ORCPT + 4 others); Mon, 15 Aug 2016 11:16:40 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:35185 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752902AbcHOPQd (ORCPT ); Mon, 15 Aug 2016 11:16:33 -0400 Received: by mail-wm0-f46.google.com with SMTP id f65so94705221wmi.0 for ; Mon, 15 Aug 2016 08:16:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=r37SF7eIiNTHUN+LDF2KVe012qfRigO9vcYdXMJ5F6I=; b=WkYZnxd2PQPVeLBY5GRp6RE9AxIO6vrYtgv35iAN1sBixMxoT/ET66EZJekpvFTsQj RsyMFr0Ma7KXQkIRh2EuizlIlWz8Hpxagkmkjzu5Xmxdu1wFDeG0v7L39xadQvrYIbkx NQp4nNLFhEV+7/N3Ji+PdFL/cBWDh27Q/5dN4= 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=r37SF7eIiNTHUN+LDF2KVe012qfRigO9vcYdXMJ5F6I=; b=ZUUhTHBpxRRGyo0eeXyCQbr5bsmST6OYhVGI72EIlA0ljfQEMhNxDkFMNaCWlD2B6H +XKkZB6QZajCkJP6ofFyWeZrQ1kUW5RhH0C5C9JVz//1ha0BbBktq07Gs+sj8mjVO3mB pNJwRzIcD4ynucL2zOW2NckUH+Ajktq3ZOphuyz6yltEJqm/SHh3EGoT44gL3SgfcEND hxsMPIMzeCdYCBEXOV+hvdj1cO3oIs7LW59Rr5cd8l6zBASGLmghJQh2YNGgYD2ZP6mf IYSTDPP0Rzn8+KwWrFfy+aieLJFa28ZlrbVIi5tn0Hw7UbAaaAIvwzZZ6wmlffQDkx1t gGZA== X-Gm-Message-State: AEkoousJPBeKtHvmhY9yHddT9N1zDA5DwdlJLamAfdDESaoGqZhhZK+K/0nHjVmZ9qW///NI X-Received: by 10.25.25.12 with SMTP id 12mr5779878lfz.149.1471274191519; Mon, 15 Aug 2016 08:16:31 -0700 (PDT) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id 17sm77949ljj.49.2016.08.15.08.16.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Aug 2016 08:16:30 -0700 (PDT) From: Ivan Khoronzhuk To: davem@davemloft.net, netdev@vger.kernel.org, mugunthanvnm@ti.com, grygorii.strashko@ti.com Cc: linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, nsekhar@ti.com, Ivan Khoronzhuk Subject: [PATCH v2 4/4] net: ethernet: ti: cpsw: add ethtool channels support Date: Mon, 15 Aug 2016 18:16:21 +0300 Message-Id: <1471274181-780-5-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471274181-780-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1471274181-780-1-git-send-email-ivan.khoronzhuk@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org These ops allow to control number of channels driver is allowed to work with at cpdma level. The maximum number of channels is 8 for rx and 8 for tx. In dual_emac mode the h/w channels are shared between two interfaces and changing number on one interface changes number of channels on another. How many channels are supported and enabled: $ ethtool -l ethX Change number of channels (up to 8) $ ethtool -L ethX rx 6 tx 6 Per-channel statistic: $ ethtool -S ethX Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw.c | 177 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index d084c29..546a6ba 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -735,6 +735,11 @@ static void cpsw_rx_handler(void *token, int len, int status) } requeue: + if (netif_dormant(ndev)) { + dev_kfree_skb_any(new_skb); + return; + } + ch = cpsw->rxch[skb_get_queue_mapping(new_skb)]; ret = cpdma_chan_submit(ch, new_skb, new_skb->data, skb_tailroom(new_skb), 0); @@ -1267,9 +1272,8 @@ static void cpsw_init_host_port(struct cpsw_priv *priv) } } -static int cpsw_fill_rx_channels(struct net_device *ndev) +static int cpsw_fill_rx_channels(struct cpsw_priv *priv) { - struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = priv->cpsw; struct sk_buff *skb; int ch, i, ret; @@ -1279,7 +1283,7 @@ static int cpsw_fill_rx_channels(struct net_device *ndev) ch_buf_num = cpdma_chan_get_rx_buf_num(cpsw->rxch[ch]); for (i = 0; i < ch_buf_num; i++) { - skb = __netdev_alloc_skb_ip_align(ndev, + skb = __netdev_alloc_skb_ip_align(priv->ndev, cpsw->rx_packet_max, GFP_KERNEL); if (!skb) { @@ -1397,7 +1401,7 @@ static int cpsw_ndo_open(struct net_device *ndev) enable_irq(cpsw->irqs_table[0]); } - ret = cpsw_fill_rx_channels(ndev); + ret = cpsw_fill_rx_channels(priv); if (ret < 0) goto err_cleanup; @@ -2061,6 +2065,169 @@ static void cpsw_ethtool_op_complete(struct net_device *ndev) cpsw_err(priv, drv, "ethtool complete failed %d\n", ret); } +static void cpsw_get_channels(struct net_device *ndev, + struct ethtool_channels *ch) +{ + struct cpsw_common *cpsw = ndev_to_cpsw(ndev); + + ch->max_combined = 0; + ch->max_rx = CPSW_MAX_QUEUES; + ch->max_tx = CPSW_MAX_QUEUES; + ch->max_other = 0; + ch->other_count = 0; + ch->rx_count = cpsw->rx_ch_num; + ch->tx_count = cpsw->tx_ch_num; + ch->combined_count = 0; +} + +static int cpsw_check_ch_settings(struct cpsw_common *cpsw, + struct ethtool_channels *ch) +{ + if (ch->combined_count) + return -EINVAL; + + /* verify we have at least one channel in each direction */ + if (!ch->rx_count || !ch->tx_count) + return -EINVAL; + + if (ch->rx_count > cpsw->data.channels || + ch->tx_count > cpsw->data.channels) + return -EINVAL; + + return 0; +} + +static int cpsw_update_channels_res(struct cpsw_priv *priv, int ch_num, int rx) +{ + int ret, *ch; + struct cpdma_chan **chan; + void (*handler)(void *, int, int); + struct cpsw_common *cpsw = priv->cpsw; + int (*poll)(struct napi_struct *, int); + + if (rx) { + ch = &cpsw->rx_ch_num; + chan = cpsw->rxch; + handler = cpsw_rx_handler; + poll = cpsw_rx_poll; + } else { + ch = &cpsw->tx_ch_num; + chan = cpsw->txch; + handler = cpsw_tx_handler; + poll = cpsw_tx_poll; + } + + while (*ch < ch_num) { + chan[*ch] = cpdma_chan_create(cpsw->dma, *ch, handler, rx); + + if (IS_ERR(chan[*ch])) + return PTR_ERR(chan[*ch]); + + if (!chan[*ch]) + return -EINVAL; + + cpsw_info(priv, ifup, "created new %d %s channel\n", *ch, + (rx ? "rx" : "tx")); + (*ch)++; + } + + while (*ch > ch_num) { + (*ch)--; + + ret = cpdma_chan_destroy(chan[*ch]); + if (ret) + return ret; + + cpsw_info(priv, ifup, "destroyed %d %s channel\n", *ch, + (rx ? "rx" : "tx")); + } + + return 0; +} + +static int cpsw_update_channels(struct cpsw_priv *priv, + struct ethtool_channels *ch) +{ + int ret; + + ret = cpsw_update_channels_res(priv, ch->rx_count, 1); + if (ret) + return ret; + + ret = cpsw_update_channels_res(priv, ch->tx_count, 0); + if (ret) + return ret; + + return 0; +} + +static int cpsw_set_channels(struct net_device *ndev, + struct ethtool_channels *chs) +{ + int i, ret; + struct cpsw_slave *slave; + struct cpsw_priv *priv = netdev_priv(ndev); + struct cpsw_common *cpsw = priv->cpsw; + + ret = cpsw_check_ch_settings(cpsw, chs); + if (ret < 0) + return ret; + + cpsw_intr_disable(cpsw); + + for (i = cpsw->data.slaves, slave = cpsw->slaves; i; i--, slave++) { + if (!(slave->ndev && netif_running(slave->ndev))) + continue; + + netif_tx_stop_all_queues(slave->ndev); + netif_dormant_on(slave->ndev); + } + + cpdma_ctlr_stop(cpsw->dma); + ret = cpsw_update_channels(priv, chs); + if (ret) + goto err; + + for (i = cpsw->data.slaves, slave = cpsw->slaves; i; i--, slave++) { + if (!(slave->ndev && netif_running(slave->ndev))) + continue; + + /* inform stack about new count of queues */ + ret = netif_set_real_num_tx_queues(slave->ndev, + cpsw->tx_ch_num); + if (ret) { + dev_err(priv->dev, "cannot set real number of tx queues\n"); + goto err; + } + + ret = netif_set_real_num_rx_queues(slave->ndev, + cpsw->rx_ch_num); + if (ret) { + dev_err(priv->dev, "cannot set real number of rx queues\n"); + goto err; + } + + netif_dormant_off(slave->ndev); + } + + if (cpsw_fill_rx_channels(priv)) + goto err; + + cpdma_ctlr_start(cpsw->dma); + cpsw_intr_enable(cpsw); + for (i = cpsw->data.slaves, slave = cpsw->slaves; i; i--, slave++) { + if (!(slave->ndev && netif_running(slave->ndev))) + continue; + netif_tx_start_all_queues(slave->ndev); + } + + return 0; +err: + dev_err(priv->dev, "cannot update channels number, closing device\n"); + dev_close(ndev); + return ret; +} + static const struct ethtool_ops cpsw_ethtool_ops = { .get_drvinfo = cpsw_get_drvinfo, .get_msglevel = cpsw_get_msglevel, @@ -2082,6 +2249,8 @@ static const struct ethtool_ops cpsw_ethtool_ops = { .get_regs = cpsw_get_regs, .begin = cpsw_ethtool_op_begin, .complete = cpsw_ethtool_op_complete, + .get_channels = cpsw_get_channels, + .set_channels = cpsw_set_channels, }; static void cpsw_slave_init(struct cpsw_slave *slave, struct cpsw_common *cpsw,