Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: cdc_ether: record speed in status method

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 <grundler@chromium.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Grant Grundler and committed by
David S. Miller
d42ebcbb eb47c274

+20 -7
+20 -7
drivers/net/usb/cdc_ether.c
··· 92 92 } 93 93 EXPORT_SYMBOL_GPL(usbnet_cdc_update_filter); 94 94 95 + /* We need to override usbnet_*_link_ksettings in bind() */ 96 + static const struct ethtool_ops cdc_ether_ethtool_ops = { 97 + .get_link = usbnet_get_link, 98 + .nway_reset = usbnet_nway_reset, 99 + .get_drvinfo = usbnet_get_drvinfo, 100 + .get_msglevel = usbnet_get_msglevel, 101 + .set_msglevel = usbnet_set_msglevel, 102 + .get_ts_info = ethtool_op_get_ts_info, 103 + .get_link_ksettings = usbnet_get_link_ksettings_internal, 104 + .set_link_ksettings = NULL, 105 + }; 106 + 95 107 /* probes control interface, claims data interface, collects the bulk 96 108 * endpoints, activates data interface (if needed), maybe sets MTU. 97 109 * all pure cdc, except for certain firmware workarounds, and knowing ··· 322 310 return -ENODEV; 323 311 } 324 312 313 + /* override ethtool_ops */ 314 + dev->net->ethtool_ops = &cdc_ether_ethtool_ops; 315 + 325 316 return 0; 326 317 327 318 bad_desc: ··· 394 379 * (by Brad Hards) talked with, with more functionality. 395 380 */ 396 381 397 - static void dumpspeed(struct usbnet *dev, __le32 *speeds) 382 + static void speed_change(struct usbnet *dev, __le32 *speeds) 398 383 { 399 - netif_info(dev, timer, dev->net, 400 - "link speeds: %u kbps up, %u kbps down\n", 401 - __le32_to_cpu(speeds[0]) / 1000, 402 - __le32_to_cpu(speeds[1]) / 1000); 384 + dev->tx_speed = __le32_to_cpu(speeds[0]); 385 + dev->rx_speed = __le32_to_cpu(speeds[1]); 403 386 } 404 387 405 388 void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) ··· 409 396 410 397 /* SPEED_CHANGE can get split into two 8-byte packets */ 411 398 if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) { 412 - dumpspeed(dev, (__le32 *) urb->transfer_buffer); 399 + speed_change(dev, (__le32 *) urb->transfer_buffer); 413 400 return; 414 401 } 415 402 ··· 426 413 if (urb->actual_length != (sizeof(*event) + 8)) 427 414 set_bit(EVENT_STS_SPLIT, &dev->flags); 428 415 else 429 - dumpspeed(dev, (__le32 *) &event[1]); 416 + speed_change(dev, (__le32 *) &event[1]); 430 417 break; 431 418 /* USB_CDC_NOTIFY_RESPONSE_AVAILABLE can happen too (e.g. RNDIS), 432 419 * but there are no standard formats for the response data.