From: Mahesh Bandewar <maheshb@google.com>
To: Matt Carlson <mcarlson@broadcom.com>, David Miller <davem@davemloft.net>
Cc: netdev <netdev@vger.kernel.org>,
"Michael Chan" <mchan@broadcom.com>,
"Ben Hutchings" <bhutchings@solarflare.com>,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Tom Herbert" <therbert@google.com>,
"Mahesh Bandewar" <maheshb@google.com>
Subject: [PATCHv3 2/2] tg3: Allow ethtool to enable/disable loopback.
Date: Tue, 3 May 2011 18:18:55 -0700 [thread overview]
Message-ID: <1304471935-402-3-git-send-email-maheshb@google.com> (raw)
In-Reply-To: <1304471935-402-2-git-send-email-maheshb@google.com>
This patch adds tg3_set_features() to handle loopback mode. Currently the
capability is added for the devices which support internal MAC loopback mode.
So when enabled, it enables internal-MAC loopback.
Signed-off-by: Mahesh Bandewar <maheshb@google.com>
---
Changes since v2:
Implemtned Joe Perches's style change.
Changes since v1:
Implemented Matt Carlson's suggestions.
(a) Enable this capability on the devices which are capable of MAC-loopback
mode.
(b) check if the device is running before making changes.
(c) check bits before making changes.
drivers/net/tg3.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 7c7c9a8..46de633 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -6319,6 +6319,51 @@ static u32 tg3_fix_features(struct net_device *dev, u32 features)
return features;
}
+static int tg3_set_features(struct net_device *dev, u32 features)
+{
+ struct tg3 *tp = netdev_priv(dev);
+ u32 cur_mode = 0;
+ int err = 0;
+
+ if (!netif_running(dev)) {
+ err = -EAGAIN;
+ goto sfeatures_out;
+ }
+
+ spin_lock_bh(&tp->lock);
+ cur_mode = tr32(MAC_MODE);
+
+ if (features & NETIF_F_LOOPBACK) {
+ if (cur_mode & MAC_MODE_PORT_INT_LPBACK)
+ goto sfeatures_unlock;
+
+ /*
+ * Clear MAC_MODE_HALF_DUPLEX or you won't get packets back in
+ * loopback mode if Half-Duplex mode was negotiated earlier.
+ */
+ cur_mode &= ~MAC_MODE_HALF_DUPLEX;
+
+ /* Enable internal MAC loopback mode */
+ tw32(MAC_MODE, cur_mode | MAC_MODE_PORT_INT_LPBACK);
+ netif_carrier_on(tp->dev);
+ netdev_info(dev, "Internal MAC loopback mode enabled.\n");
+ } else {
+ if (!(cur_mode & MAC_MODE_PORT_INT_LPBACK))
+ goto sfeatures_unlock;
+
+ /* Disable internal MAC loopback mode */
+ tw32(MAC_MODE, cur_mode & ~MAC_MODE_PORT_INT_LPBACK);
+ /* Force link status check */
+ tg3_setup_phy(tp, 1);
+ netdev_info(dev, "Internal MAC loopback mode disabled.\n");
+ }
+sfeatures_unlock:
+ spin_unlock_bh(&tp->lock);
+
+sfeatures_out:
+ return err;
+}
+
static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
int new_mtu)
{
@@ -15029,6 +15074,7 @@ static const struct net_device_ops tg3_netdev_ops = {
.ndo_tx_timeout = tg3_tx_timeout,
.ndo_change_mtu = tg3_change_mtu,
.ndo_fix_features = tg3_fix_features,
+ .ndo_set_features = tg3_set_features,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = tg3_poll_controller,
#endif
@@ -15045,6 +15091,7 @@ static const struct net_device_ops tg3_netdev_ops_dma_bug = {
.ndo_do_ioctl = tg3_ioctl,
.ndo_tx_timeout = tg3_tx_timeout,
.ndo_change_mtu = tg3_change_mtu,
+ .ndo_set_features = tg3_set_features,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = tg3_poll_controller,
#endif
@@ -15242,6 +15289,16 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
dev->features |= hw_features;
dev->vlan_features |= hw_features;
+ /*
+ * Add loopback capability only for a subset of devices that support
+ * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY
+ * loopback for the remaining devices.
+ */
+ if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 ||
+ !tg3_flag(tp, CPMU_PRESENT))
+ /* Add the loopback capability */
+ dev->hw_features |= NETIF_F_LOOPBACK;
+
if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
!tg3_flag(tp, TSO_CAPABLE) &&
!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
--
1.7.3.1
next prev parent reply other threads:[~2011-05-04 1:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-04 1:18 [PATCHv3 0/2] Loopback Mahesh Bandewar
2011-05-04 1:18 ` [PATCH 1/2] net: Allow ethtool to set interface in loopback mode Mahesh Bandewar
2011-05-04 1:18 ` Mahesh Bandewar [this message]
2011-05-04 1:52 ` [PATCHv3 2/2] tg3: Allow ethtool to enable/disable loopback Matt Carlson
2011-05-04 11:11 ` Michał Mirosław
2011-05-04 15:04 ` Stephen Hemminger
2011-05-04 16:05 ` Michał Mirosław
2011-05-04 16:08 ` Ben Hutchings
2011-05-05 1:34 ` [PATCHv4 " Mahesh Bandewar
2011-05-05 6:59 ` Michał Mirosław
2011-05-05 17:47 ` Mahesh Bandewar
2011-05-05 18:35 ` Michał Mirosław
2011-05-05 23:16 ` Mahesh Bandewar
2011-05-06 6:35 ` Michał Mirosław
2011-05-07 6:18 ` [PATCHv5 " Mahesh Bandewar
2011-05-07 7:43 ` Michał Mirosław
2011-05-08 16:50 ` Mahesh Bandewar
2011-05-08 16:51 ` [PATCHv6 " Mahesh Bandewar
2011-05-12 22:04 ` David Miller
2011-05-04 11:15 ` [PATCH 1/2] net: Allow ethtool to set interface in loopback mode Michał Mirosław
2011-05-05 1:30 ` [PATCHv2 " Mahesh Bandewar
2011-05-05 1:52 ` Ben Hutchings
2011-05-08 23:00 ` David Miller
2011-05-06 0:12 ` [PATCH net-next-2.6] sfc: Implement NETIF_F_LOOPBACK Ben Hutchings
2011-05-09 7:36 ` Michał Mirosław
2011-05-09 13:47 ` Ben Hutchings
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1304471935-402-3-git-send-email-maheshb@google.com \
--to=maheshb@google.com \
--cc=bhutchings@solarflare.com \
--cc=davem@davemloft.net \
--cc=mcarlson@broadcom.com \
--cc=mchan@broadcom.com \
--cc=mirq-linux@rere.qmqm.pl \
--cc=netdev@vger.kernel.org \
--cc=therbert@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).