Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3926185pxf; Tue, 6 Apr 2021 03:59:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/PsbCWa7bq1ZpHyLwT+BUvguLrABCjvLBBOj+4jL0+XQwJmUn7B0gG1bvGHyylieuWr7D X-Received: by 2002:a92:dc83:: with SMTP id c3mr24463348iln.167.1617706743640; Tue, 06 Apr 2021 03:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617706743; cv=none; d=google.com; s=arc-20160816; b=vKhqA2+5HFXuIm98OZqUFluNaxiOosheZ5eZVCDIbOo1PSJnAm5u/M+Nlqq/JDChJz kIHPWGnqejwaGaDFPR/zQZe1stjNM1DTDbeF1RknIS8jD+rtK+6QiL0lW66dLz0TJizV JuAc+2Q0pHOg3AAYAiBw4MlX8LPgKAPvqirqyyzlAFxQYE19l0p5BqaYaEvV0Jvu8BvX B78o0JRdKtR8XkWPCT4rbN+V8SDuYGAkK42WnB4KLGuB/5ZWO+nNLOhtrf+19AfOQPKi oNeyhVOmOdbHVShvZy+RuIDytuMG+tdoupfXj0I7lfFy/LwzMKvgY44ejIMGkXx7FE/2 egsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P/PJIlYMvtvOjmWKMvD86+isUEsA4SFh08VG5H5krSE=; b=pfHYZYd/a7jwg2exhAAJGiIydbOWE/xAHbTGi9GbknNPuOtbdRCA6eKozXbN53QT9X sgdfd6PSv3yaMlq77HcxqUHbMKrRvon5lls2aJQfVJ5/v3T9T1moOZEdKFIssJ54Lbqr nDRZ9UxgbjKZKPLS35WT8YeJ4TqLW+hJ9FNHZ4mUwhpO1QtejKRqrR1ZjZN8Aj1nv90s /RVx/RhXhu4OpiqUEqtdY9jUgUllTF32518JFpy1eTJkR0ZKPoSJDESjWmTFEbDwN5ru dIAsXIFYNEG0TIBBYq8+29fKkosLwAYQS3VPsPjt5Oymyxy3e4G0YQfJvo5irom/xCPR pd4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AtUtSyil; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n5si16994636ioz.16.2021.04.06.03.58.49; Tue, 06 Apr 2021 03:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AtUtSyil; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241663AbhDEXOZ (ORCPT + 99 others); Mon, 5 Apr 2021 19:14:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241563AbhDEXOS (ORCPT ); Mon, 5 Apr 2021 19:14:18 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAD8DC061794 for ; Mon, 5 Apr 2021 16:14:10 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id j17so6227226qvo.13 for ; Mon, 05 Apr 2021 16:14:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P/PJIlYMvtvOjmWKMvD86+isUEsA4SFh08VG5H5krSE=; b=AtUtSyilVCumg3/2d6qBmx4TlBGwzZFJS3Q617LXCDmHu5oLh1kGA+L5ts+JvS1eY4 H/V2H6nYyxLmPTJuMHGAhoi9Q1M9FrG1Je23/C0LjLZsr+3mHCMd1Dz5phPPnP54JPCU nH7SghuJPwL6STx+334CH8HRxOQqmTNDd/Muw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P/PJIlYMvtvOjmWKMvD86+isUEsA4SFh08VG5H5krSE=; b=lb2spHxr+2sWP0WemP9/+zQFKjbcecRIb4JuYkBOIdfTAJSrNC9QRRHofgPCtKY/8y AB69tKIJ2vb29YTh6xuyQtTLlK+1JItGqdlgDpbt5vCQSSdZpFmUDlg1Kc2B1GScZb13 EiM38JuOWxJ03OfQcwKYFWxp6sRQv0lI/1l6ZaBOQzpwkMsdOwwVP7MucD+Hee0plkxk rU7M7oNnjwSmGInkTSAI22JhdjgG51MZvCmIoiEqncUxV3HiJPnipYyGv0Dl2/i4gYK4 t7GkoXd+OBmuhRRhGnSrwRvoM8MvmvJYGyUksOq7hUtw7VPLVp67rQBGMHpdnTz1jmne ZQ5g== X-Gm-Message-State: AOAM530uomdce5q3ZNgyWNq1Q3MQVqWuMBIlymommzgEs4nmBBtq2P4Q ztplhVepb8tYtg5YbD+/49U8JQ== X-Received: by 2002:a0c:b294:: with SMTP id r20mr25283932qve.16.1617664450042; Mon, 05 Apr 2021 16:14:10 -0700 (PDT) Received: from grundler-glapstation.lan ([70.134.62.80]) by smtp.gmail.com with ESMTPSA id b17sm13151650qtp.73.2021.04.05.16.14.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Apr 2021 16:14:09 -0700 (PDT) From: Grant Grundler To: Oliver Neukum , Jakub Kicinski Cc: Roland Dreier , nic_swsd , netdev , "David S . Miller" , LKML , Andrew Lunn , Grant Grundler Subject: [PATCH net-next v4 4/4] net: cdc_ether: record speed in status method Date: Mon, 5 Apr 2021 16:13:44 -0700 Message-Id: <20210405231344.1403025-5-grundler@chromium.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog In-Reply-To: <20210405231344.1403025-1-grundler@chromium.org> References: <20210405231344.1403025-1-grundler@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Until very recently, the usbnet framework only had support functions for devices which reported the link speed by explicitly querying the PHY over a MDIO interface. However, the cdc_ether devices send notifications when the link state or link speeds change and do not expose the PHY (or modem) directly. Support funtions (e.g. usbnet_get_link_ksettings_internal()) to directly query state recorded by the cdc_ether driver were added in a previous patch. Instead of cdc_ether spewing the link speed into the dmesg buffer, record the link speed encoded in these notifications and tell the usbnet framework to use the new functions to get link speed/state. User space can now get the most recent link speed/state using ethtool. v4: added to series since cdc_ether uses same notifications as cdc_ncm driver. Signed-off-by: Grant Grundler Reviewed-by: Andrew Lunn --- drivers/net/usb/cdc_ether.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c index a9b551028659..7eb0109e9baa 100644 --- a/drivers/net/usb/cdc_ether.c +++ b/drivers/net/usb/cdc_ether.c @@ -92,6 +92,18 @@ void usbnet_cdc_update_filter(struct usbnet *dev) } EXPORT_SYMBOL_GPL(usbnet_cdc_update_filter); +/* We need to override usbnet_*_link_ksettings in bind() */ +static const struct ethtool_ops cdc_ether_ethtool_ops = { + .get_link = usbnet_get_link, + .nway_reset = usbnet_nway_reset, + .get_drvinfo = usbnet_get_drvinfo, + .get_msglevel = usbnet_get_msglevel, + .set_msglevel = usbnet_set_msglevel, + .get_ts_info = ethtool_op_get_ts_info, + .get_link_ksettings = usbnet_get_link_ksettings_internal, + .set_link_ksettings = NULL, +}; + /* probes control interface, claims data interface, collects the bulk * endpoints, activates data interface (if needed), maybe sets MTU. * all pure cdc, except for certain firmware workarounds, and knowing @@ -310,6 +322,9 @@ int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf) return -ENODEV; } + /* override ethtool_ops */ + dev->net->ethtool_ops = &cdc_ether_ethtool_ops; + return 0; bad_desc: @@ -379,12 +394,10 @@ EXPORT_SYMBOL_GPL(usbnet_cdc_unbind); * (by Brad Hards) talked with, with more functionality. */ -static void dumpspeed(struct usbnet *dev, __le32 *speeds) +static void speed_change(struct usbnet *dev, __le32 *speeds) { - netif_info(dev, timer, dev->net, - "link speeds: %u kbps up, %u kbps down\n", - __le32_to_cpu(speeds[0]) / 1000, - __le32_to_cpu(speeds[1]) / 1000); + dev->tx_speed = __le32_to_cpu(speeds[0]); + dev->rx_speed = __le32_to_cpu(speeds[1]); } void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) @@ -396,7 +409,7 @@ void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) /* SPEED_CHANGE can get split into two 8-byte packets */ if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) { - dumpspeed(dev, (__le32 *) urb->transfer_buffer); + speed_change(dev, (__le32 *) urb->transfer_buffer); return; } @@ -413,7 +426,7 @@ void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) if (urb->actual_length != (sizeof(*event) + 8)) set_bit(EVENT_STS_SPLIT, &dev->flags); else - dumpspeed(dev, (__le32 *) &event[1]); + speed_change(dev, (__le32 *) &event[1]); break; /* USB_CDC_NOTIFY_RESPONSE_AVAILABLE can happen too (e.g. RNDIS), * but there are no standard formats for the response data. -- 2.30.1