diff mbox series

[8/8] usbnet: smsc95xx: add rx_turbo attribute

Message ID 20181012083405.19246-9-ben.dooks@codethink.co.uk (mailing list archive)
State New, archived
Headers show
Series [1/8] usbnet: smsc95xx: fix rx packet alignment | expand

Commit Message

Ben Dooks Oct. 12, 2018, 8:34 a.m. UTC
Add attribute for the rx_turbo mode to allow run-time configuration of
this feature.

Note, this requires a restart of the device to take effect.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
 drivers/net/usb/smsc95xx.c | 41 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 1eb0795ec90f..330c3cf5d6f6 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -73,6 +73,7 @@  struct smsc95xx_priv {
 	u8 features;
 	u8 suspend_flags;
 	u8 mdix_ctrl;
+	bool rx_turbo;
 	bool link_ok;
 	struct delayed_work carrier_check;
 	struct usbnet *dev;
@@ -1103,7 +1104,7 @@  static int smsc95xx_reset(struct usbnet *dev)
 		  "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
 		  read_buf);
 
-	if (!turbo_mode) {
+	if (!pdata->rx_turbo) {
 		burst_cap = 0;
 		dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
 	} else if (dev->udev->speed == USB_SPEED_HIGH) {
@@ -1259,6 +1260,37 @@  static const struct net_device_ops smsc95xx_netdev_ops = {
 	.ndo_set_features	= smsc95xx_set_features,
 };
 
+static inline struct smsc95xx_priv *dev_to_priv(struct device *dev)
+{
+	struct usb_interface *ui = container_of(dev, struct usb_interface, dev);
+	return usbnet_to_smsc(usb_get_intfdata(ui));
+}
+
+/* Currently rx_turbo will not take effect until next close/open */
+static ssize_t rx_turbo_show(struct device *adev,
+			     struct device_attribute *attr,
+			     char *buf)
+{
+	struct smsc95xx_priv *priv = dev_to_priv(adev);
+	return snprintf(buf, PAGE_SIZE, "%d", priv->rx_turbo);
+}
+
+static ssize_t rx_turbo_store(struct device *adev,
+			      struct device_attribute *attr,
+			      const char *buf, size_t count)
+{
+	struct smsc95xx_priv *priv = dev_to_priv(adev);
+	bool res;
+
+	if (kstrtobool(buf, &res))
+		return -EINVAL;
+
+	priv->rx_turbo = res;
+	return count;
+}
+
+static DEVICE_ATTR_RW(rx_turbo);
+
 static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
 {
 	struct smsc95xx_priv *pdata = NULL;
@@ -1280,6 +1312,7 @@  static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
 	if (!pdata)
 		return -ENOMEM;
 
+	pdata->rx_turbo = turbo_mode;
 	spin_lock_init(&pdata->mac_cr_lock);
 
 	/* LAN95xx devices do not alter the computed checksum of 0 to 0xffff.
@@ -1328,6 +1361,11 @@  static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
 	INIT_DELAYED_WORK(&pdata->carrier_check, check_carrier);
 	schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY);
 
+	ret = device_create_file(&dev->udev->dev, &dev_attr_rx_turbo);
+	if (ret)
+		netdev_warn(dev->net,
+			    "failed to create rx_turbo attribute: %d\n", ret);
+
 	return 0;
 }
 
@@ -1336,6 +1374,7 @@  static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
 	struct smsc95xx_priv *pdata = usbnet_to_smsc(dev);
 
 	if (pdata) {
+		device_remove_file(&dev->udev->dev, &dev_attr_rx_turbo);
 		cancel_delayed_work(&pdata->carrier_check);
 		netif_dbg(dev, ifdown, dev->net, "free pdata\n");
 		kfree(pdata);