Commit Graph

158 Commits

Author SHA1 Message Date
CKI Backport Bot 1f4777d4d9 net: usb: lan78xx: Fix double free issue with interrupt buffer allocation
JIRA: https://issues.redhat.com/browse/RHEL-72355
CVE: CVE-2024-53213

commit 03819abbeb11117dcbba40bfe322b88c0c88a6b6
Author: Oleksij Rempel <linux@rempel-privat.de>
Date:   Sat Nov 16 14:05:57 2024 +0100

    net: usb: lan78xx: Fix double free issue with interrupt buffer allocation

    In lan78xx_probe(), the buffer `buf` was being freed twice: once
    implicitly through `usb_free_urb(dev->urb_intr)` with the
    `URB_FREE_BUFFER` flag and again explicitly by `kfree(buf)`. This caused
    a double free issue.

    To resolve this, reordered `kmalloc()` and `usb_alloc_urb()` calls to
    simplify the initialization sequence and removed the redundant
    `kfree(buf)`.  Now, `buf` is allocated after `usb_alloc_urb()`, ensuring
    it is correctly managed by  `usb_fill_int_urb()` and freed by
    `usb_free_urb()` as intended.

    Fixes: a6df95cae40b ("lan78xx: Fix memory allocation bug")
    Cc: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Link: https://patch.msgid.link/20241116130558.1352230-1-o.rempel@pengutronix.de
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2025-01-14 11:45:06 +00:00
Lucas Zampieri ebc21c5164 Merge: net: usb: lan78xx: add phy dependency for user tools
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4383

net: usb: lan78xx: add phy dependency for user tools

JIRA: https://issues.redhat.com/browse/RHEL-17582

Upstream Status: RHEL-only

For lan78xx driver, the related module for the phy is loaded dynamically
depending on the current hardware. In this case, the associated phy is
read using mdio bus and then the associated phy module is loaded during
runtime (kernel function phy_request_driver_module). However, no software
dependency is defined, so the user tools will no be able to get this
dependency. For example, if dracut is used and the hardware is present,
lan78xx will be included but no phy module will be added, and in the next
restart the device will not work from boot because no related phy will be
found during initramfs stage.

In order to solve this for this release, we are going to define a normal
'pre' software dependency in lan78xx module with the requested phy module
(micrel) for the hardware requested by the customer.

A new procedure has been created in kmod, that is called 'weak' dependency:
05828b4a6e
to optimize this, but the complete approval for kernel and dracut user
package in upstream will take more time.

So, let's do it in this way for now and use the new procedure
for the next release (then this commit will be reverted).

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>

Approved-by: Desnes Nunes <desnesn@redhat.com>
Approved-by: Michal Schmidt <mschmidt@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Lucas Zampieri <lzampier@redhat.com>
2024-06-25 13:31:44 +00:00
Lucas Zampieri a14ac2400e Merge: CNB95: net: annotate writes on dev->mtu from ndo_change_mtu()
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4387

JIRA: https://issues.redhat.com/browse/RHEL-39583  
Tested: Just built... no way to test  

Commit(s):
```
1eb2cded45b3 ("net: annotate writes on dev->mtu from ndo_change_mtu()")
```

Signed-off-by: Ivan Vecera <ivecera@redhat.com>

Approved-by: Tony Camuso <tcamuso@redhat.com>
Approved-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Approved-by: Antoine Tenart <atenart@redhat.com>
Approved-by: José Ignacio Tornos Martínez <jtornosm@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Lucas Zampieri <lzampier@redhat.com>
2024-06-19 18:24:31 +00:00
Ivan Vecera 24ef7349da net: annotate writes on dev->mtu from ndo_change_mtu()
JIRA: https://issues.redhat.com/browse/RHEL-39583

Conflicts:
- hunks for non-existing files and non-applicable hunks for unsupported
  drivers, batman-adv and DSA were skipped

commit 1eb2cded45b35816085c1f962933c187d970f9dc
Author: Eric Dumazet <edumazet@google.com>
Date:   Mon May 6 10:28:12 2024 +0000

    net: annotate writes on dev->mtu from ndo_change_mtu()

    Simon reported that ndo_change_mtu() methods were never
    updated to use WRITE_ONCE(dev->mtu, new_mtu) as hinted
    in commit 501a90c945 ("inet: protect against too small
    mtu values.")

    We read dev->mtu without holding RTNL in many places,
    with READ_ONCE() annotations.

    It is time to take care of ndo_change_mtu() methods
    to use corresponding WRITE_ONCE()

    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Reported-by: Simon Horman <horms@kernel.org>
    Closes: https://lore.kernel.org/netdev/20240505144608.GB67882@kernel.org/
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
    Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
    Reviewed-by: Simon Horman <horms@kernel.org>
    Acked-by: Shannon Nelson <shannon.nelson@amd.com>
    Link: https://lore.kernel.org/r/20240506102812.3025432-1-edumazet@google.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2024-05-31 21:00:33 +02:00
Jose Ignacio Tornos Martinez 8a5105db7f net: usb: lan78xx: add phy dependency for user tools
JIRA: https://issues.redhat.com/browse/RHEL-17582
Upstream Status: RHEL-only

For lan78xx driver, the related module for the phy is loaded dynamically
depending on the current hardware. In this case, the associated phy is
read using mdio bus and then the associated phy module is loaded during
runtime (kernel function phy_request_driver_module). However, no software
dependency is defined, so the user tools will no be able to get this
dependency. For example, if dracut is used and the hardware is present,
lan78xx will be included but no phy module will be added, and in the next
restart the device will not work from boot because no related phy will be
found during initramfs stage.

In order to solve this for this release, we are going to define a normal
'pre' software dependency in lan78xx module with the requested phy module
(micrel) for the hardware requested by the customer.

A new procedure has been created in kmod, that is called 'weak' dependency:
05828b4a6e
to optimize this, but the complete approval for kernel and dracut user
package in upstream will take more time.

So, let's do it in this way for now and use the new procedure
for the next release (then this commit will be reverted).

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
2024-05-31 12:25:04 +02:00
Ivan Vecera fa738d292c ethtool: replace struct ethtool_eee with a new struct ethtool_keee on kernel side
JIRA: https://issues.redhat.com/browse/RHEL-32101

Conflicts:
- hunks for missing files were omitted
- conversion for qca was done in drivers/net/dsa/qca/qca8k.c due to
  missing commits in qca driver
- net/dsa changes were done in net/dsa/slave.c due to missing commits
  in DSA subsystem

commit d80a52335374e484a4ff2afdc9af843e73273945
Author: Heiner Kallweit <hkallweit1@gmail.com>
Date:   Sat Jan 27 14:25:09 2024 +0100

    ethtool: replace struct ethtool_eee with a new struct ethtool_keee on kernel side

    In order to pass EEE link modes beyond bit 32 to userspace we have to
    complement the 32 bit bitmaps in struct ethtool_eee with linkmode
    bitmaps. Therefore, similar to ethtool_link_settings and
    ethtool_link_ksettings, add a struct ethtool_keee. In a first step
    it's an identical copy of ethtool_eee. This patch simply does a
    s/ethtool_eee/ethtool_keee/g for all users.
    No functional change intended.

    Suggested-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2024-04-29 12:11:22 +02:00
Jamie Bainbridge 9f0cd6595a net: lan78xx: fix runtime PM count underflow on link stop
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 1eecc7ab82c42133b748e1895275942a054a7f67
Author: Oleksij Rempel <o.rempel@pengutronix.de>
Date:   Wed Feb 28 13:45:17 2024 +0100

    net: lan78xx: fix runtime PM count underflow on link stop

    Current driver has some asymmetry in the runtime PM calls. On lan78xx_open()
    it will call usb_autopm_get() and unconditionally usb_autopm_put(). And
    on lan78xx_stop() it will call only usb_autopm_put(). So far, it was
    working only because this driver do not activate autosuspend by default,
    so it was visible only by warning "Runtime PM usage count underflow!".

    Since, with current driver, we can't use runtime PM with active link,
    execute lan78xx_open()->usb_autopm_put() only in error case. Otherwise,
    keep ref counting high as long as interface is open.

    Fixes: 55d7de9de6 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")
    Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:59:04 +10:00
Jamie Bainbridge 938adcd9e9 net: lan78xx: fix "softirq work is pending" error
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit e3d5d70cb483df8296dd44e9ae3b6355ef86494c
Author: Oleksij Rempel <o.rempel@pengutronix.de>
Date:   Mon Feb 26 12:08:20 2024 +0100

    net: lan78xx: fix "softirq work is pending" error

    Disable BH around the call to napi_schedule() to avoid following
    error:
    NOHZ tick-stop error: local softirq work is pending, handler #08!!!

    Fixes: ec4c7e12396b ("lan78xx: Introduce NAPI polling support")
    Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Link: https://lore.kernel.org/r/20240226110820.2113584-1-o.rempel@pengutronix.de
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:57:52 +10:00
Jamie Bainbridge 222d70646e lan78xx: enable auto speed configuration for LAN7850 if no EEPROM is detected
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 0e67899abfbfdea0c3c0ed3fd263ffc601c5c157
Author: Oleksij Rempel <o.rempel@pengutronix.de>
Date:   Thu Feb 22 13:38:38 2024 +0100

    lan78xx: enable auto speed configuration for LAN7850 if no EEPROM is detected

    Same as LAN7800, LAN7850 can be used without EEPROM. If EEPROM is not
    present or not flashed, LAN7850 will fail to sync the speed detected by the PHY
    with the MAC. In case link speed is 100Mbit, it will accidentally work,
    otherwise no data can be transferred.

    Better way would be to implement link_up callback, or set auto speed
    configuration unconditionally. But this changes would be more intrusive.
    So, for now, set it only if no EEPROM is found.

    Fixes: e69647a19c ("lan78xx: Set ASD in MAC_CR when EEE is enabled.")
    Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Link: https://lore.kernel.org/r/20240222123839.2816561-1-o.rempel@pengutronix.de
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:57:17 +10:00
Jamie Bainbridge de06872eac lan78xx: remove redundant statement in lan78xx_get_eee
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 9b0f510971470b495a707a4475d5a065c6e4d1f6
Author: Heiner Kallweit <hkallweit1@gmail.com>
Date:   Fri Jan 5 23:21:52 2024 +0100

    lan78xx: remove redundant statement in lan78xx_get_eee

    eee_active is set by phy_ethtool_get_eee() already, using the same
    logic plus an additional check against link speed/duplex values.
    See genphy_c45_eee_is_active() for details.
    So we can remove this line.

    Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
    Link: https://lore.kernel.org/r/b086b296-0a1b-42d4-8e2b-ef6682598185@gmail.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:55:00 +10:00
Jamie Bainbridge c02f84c023 lan78xx: replace deprecated strncpy with strscpy
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 2242f22ae509f018af3e60787d8773a9481ec9f6
Author: Justin Stitt <justinstitt@google.com>
Date:   Thu Oct 12 22:30:54 2023 +0000

    lan78xx: replace deprecated strncpy with strscpy

    strncpy() is deprecated for use on NUL-terminated destination strings
    [1] and as such we should prefer more robust and less ambiguous string
    interfaces.

    Other implementations of .*get_drvinfo use strscpy so this patch brings
    lan78xx_get_drvinfo() in line as well:

    igb/igb_ethtool.c +851
    static void igb_get_drvinfo(struct net_device *netdev,

    igbvf/ethtool.c
    167:static void igbvf_get_drvinfo(struct net_device *netdev,

    i40e/i40e_ethtool.c
    1999:static void i40e_get_drvinfo(struct net_device *netdev,

    e1000/e1000_ethtool.c
    529:static void e1000_get_drvinfo(struct net_device *netdev,

    ixgbevf/ethtool.c
    211:static void ixgbevf_get_drvinfo(struct net_device *netdev,

    Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
    Link: https://github.com/KSPP/linux/issues/90
    Signed-off-by: Justin Stitt <justinstitt@google.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://lore.kernel.org/r/20231012-strncpy-drivers-net-usb-lan78xx-c-v1-1-99d513061dfc@google.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:54:12 +10:00
Jamie Bainbridge f6eff70efa net: usb: lan78xx: reorder cleanup operations to avoid UAF bugs
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 1e7417c188d0a83fb385ba2dbe35fd2563f2b6f3
Author: Duoming Zhou <duoming@zju.edu.cn>
Date:   Wed Jul 26 16:14:07 2023 +0800

    net: usb: lan78xx: reorder cleanup operations to avoid UAF bugs

    The timer dev->stat_monitor can schedule the delayed work dev->wq and
    the delayed work dev->wq can also arm the dev->stat_monitor timer.

    When the device is detaching, the net_device will be deallocated. but
    the net_device private data could still be dereferenced in delayed work
    or timer handler. As a result, the UAF bugs will happen.

    One racy situation is shown below:

          (Thread 1)                 |      (Thread 2)
    lan78xx_stat_monitor()           |
     ...                             |  lan78xx_disconnect()
     lan78xx_defer_kevent()          |    ...
      ...                            |    cancel_delayed_work_sync(&dev->wq);
      schedule_delayed_work()        |    ...
      (wait some time)               |    free_netdev(net); //free net_device
      lan78xx_delayedwork()          |
      //use net_device private data  |
      dev-> //use                    |

    Although we use cancel_delayed_work_sync() to cancel the delayed work
    in lan78xx_disconnect(), it could still be scheduled in timer handler
    lan78xx_stat_monitor().

    Another racy situation is shown below:

          (Thread 1)                |      (Thread 2)
    lan78xx_delayedwork             |
     mod_timer()                    |  lan78xx_disconnect()
                                    |   cancel_delayed_work_sync()
     (wait some time)               |   if (timer_pending(&dev->stat_monitor))
                                    |       del_timer_sync(&dev->stat_monitor);
     lan78xx_stat_monitor()         |   ...
      lan78xx_defer_kevent()        |   free_netdev(net); //free
       //use net_device private data|
       dev-> //use                  |

    Although we use del_timer_sync() to delete the timer, the function
    timer_pending() returns 0 when the timer is activated. As a result,
    the del_timer_sync() will not be executed and the timer could be
    re-armed.

    In order to mitigate this bug, We use timer_shutdown_sync() to shutdown
    the timer and then use cancel_delayed_work_sync() to cancel the delayed
    work. As a result, the net_device could be deallocated safely.

    What's more, the dev->flags is set to EVENT_DEV_DISCONNECT in
    lan78xx_disconnect(). But it could still be set to EVENT_STAT_UPDATE
    in lan78xx_stat_monitor(). So this patch put the set_bit() behind
    timer_shutdown_sync().

    Fixes: 77dfff5bb7e2 ("lan78xx: Fix race condition in disconnect handling")
    Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:46:35 +10:00
Jamie Bainbridge fb7c87cc0b net: usb: lan78xx: Limit packet length to skb->len
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 7f247f5a2c18b3f21206cdd51193df4f38e1b9f5
Author: Szymon Heidrich <szymon.heidrich@gmail.com>
Date:   Sat Mar 18 10:25:52 2023 +0100

    net: usb: lan78xx: Limit packet length to skb->len

    Packet length retrieved from descriptor may be larger than
    the actual socket buffer length. In such case the cloned
    skb passed up the network stack will leak kernel memory contents.

    Additionally prevent integer underflow when size is less than
    ETH_FCS_LEN.

    Fixes: 55d7de9de6 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")
    Signed-off-by: Szymon Heidrich <szymon.heidrich@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:45:49 +10:00
Jamie Bainbridge 63f47e4736 lan78xx: drop the weight argument from netif_napi_add
JIRA: https://issues.redhat.com/browse/RHEL-33332

Conflicts: RHEL 9 has 0ee29fbc3055("net: drop the weight argument from
netif_napi_add") which dropped the change to this driver due to missing
earlier commits. Those commits are added by this patch series. Restore
the changes to lan78xx to bring EL9 in sync with upstream.

This is just the lan78xx lines from commit:

commit b48b89f9c189d24eb5e2b4a0ac067da5a24ee86d
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Tue Sep 27 06:27:53 2022 -0700

    net: drop the weight argument from netif_napi_add

    We tell driver developers to always pass NAPI_POLL_WEIGHT
    as the weight to netif_napi_add(). This may be confusing
    to newcomers, drop the weight argument, those who really
    need to tweak the weight can use netif_napi_add_weight().

    Acked-by: Marc Kleine-Budde <mkl@pengutronix.de> # for CAN
    Link: https://lore.kernel.org/r/20220927132753.750069-1-kuba@kernel.org
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:41:19 +10:00
Jamie Bainbridge bfd70838e1 usb: lan78xx: remove a copy of the NAPI_POLL_WEIGHT define
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit f130683b1e24292cb99f46653b7f6799c318f7ec
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Thu Apr 28 14:23:14 2022 -0700

    usb: lan78xx: remove a copy of the NAPI_POLL_WEIGHT define

    Defining local versions of NAPI_POLL_WEIGHT with the same
    values in the drivers just makes refactoring harder.

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:37:20 +10:00
Jamie Bainbridge 023e321141 net: usb: lan78xx: Use generic_handle_irq_safe().
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit bfe6b967948c251955bcf175cb2d4e8d169102ca
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Fri Feb 11 19:14:59 2022 +0100

    net: usb: lan78xx: Use generic_handle_irq_safe().

    Instead of manually disabling interrupts before invoking use
    generic_handle_irq_safe() which can be invoked with enabled and disabled
    interrupts.

    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Cc: Woojung Huh <woojung.huh@microchip.com>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: Jakub Kicinski <kuba@kernel.org>
    Cc: UNGLinuxDriver@microchip.com
    Link: https://lore.kernel.org/r/20220211181500.1856198-7-bigeasy@linutronix.de

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:36:31 +10:00
Jamie Bainbridge bd937b6d27 net: usb: lan78xx: add Allied Telesis AT29M2-AF
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit ef8a0f6eab1ca5d1a75c242c5c7b9d386735fa0a
Author: Greg Jesionowski <jesionowskigreg@gmail.com>
Date:   Tue Dec 14 15:10:27 2021 -0700

    net: usb: lan78xx: add Allied Telesis AT29M2-AF

    This adds the vendor and product IDs for the AT29M2-AF which is a
    lan7801-based device.

    Signed-off-by: Greg Jesionowski <jesionowskigreg@gmail.com>
    Link: https://lore.kernel.org/r/20211214221027.305784-1-jesionowskigreg@gmail.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:35:45 +10:00
Jamie Bainbridge b2f84490da net: usb: lan78xx: lan78xx_phy_init(): use PHY_POLL instead of "0" if no IRQ is available
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 817b653160db9852d5a0498a31f047e18ce27e5b
Author: Sven Schuchmann <schuchmann@schleissheimer.de>
Date:   Sat Nov 27 11:47:07 2021 +0100

    net: usb: lan78xx: lan78xx_phy_init(): use PHY_POLL instead of "0" if no IRQ is available

    On most systems request for IRQ 0 will fail, phylib will print an error message
    and fall back to polling. To fix this set the phydev->irq to PHY_POLL if no IRQ
    is available.

    Fixes: cc89c323a3 ("lan78xx: Use irq_domain for phy interrupt from USB Int. EP")
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: Sven Schuchmann <schuchmann@schleissheimer.de>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:34:37 +10:00
Jamie Bainbridge f941f05a45 lan78xx: Clean up some inconsistent indenting
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 45932221bd948c635a09a4075c189d25bfcc7449
Author: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Date:   Wed Nov 24 18:09:56 2021 +0800

    lan78xx: Clean up some inconsistent indenting

    Eliminate the follow smatch warning:

    drivers/net/usb/lan78xx.c:4961 lan78xx_resume() warn: inconsistent
    indenting.

    Reported-by: Abaci Robot <abaci@linux.alibaba.com>
    Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:32:44 +10:00
Jamie Bainbridge 0f9d8aadf9 lan78xx: Introduce NAPI polling support
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit ec4c7e12396b1a30fbacfa68425118f5b46ea878
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Thu Nov 18 11:01:39 2021 +0000

    lan78xx: Introduce NAPI polling support

    This patch introduces a NAPI-style approach for processing completed
    Rx URBs that contributes to improving driver throughput and reducing
    CPU load.

    Packets in completed URBs are copied to NAPI SKBs and passed to the
    network stack for processing. Each frame passed to the stack is one
    work item in the NAPI budget.

    If the NAPI budget is consumed and frames remain, they are added to
    an overflow queue that is processed at the start of the next NAPI
    polling cycle.

    The NAPI handler is also responsible for copying pending Tx data to
    Tx URBs and submitting them to the USB host controller for
    transmission.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:30:11 +10:00
Jamie Bainbridge b957dd83f9 lan78xx: Remove hardware-specific header update
JIRA: https://issues.redhat.com/browse/RHEL-33332

Conflicts: EL9 already has 4ba4dadfe417("net: make drivers set the TSO
limit not the GSO limit") which made a modification to this driver
because of other missing commits. This patch series adds those missing
commits. Fix the conflict to bring EL9 back into sync with upstream.

commit 0dd87266c1337db64cd6d3bbd1503553b922aa88
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Thu Nov 18 11:01:38 2021 +0000

    lan78xx: Remove hardware-specific header update

    Remove hardware-specific header length adjustment as it is no longer
    required. It also breaks generic receive offload (GRO) processing of
    received TCP frames that results in a TCP ACK being sent for each
    received frame.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:28:58 +10:00
Jamie Bainbridge d1f161db20 lan78xx: Re-order rx_submit() to remove forward declaration
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 9d2da72189a8d233cdcf6ebe5ff0689730e93e1f
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Thu Nov 18 11:01:37 2021 +0000

    lan78xx: Re-order rx_submit() to remove forward declaration

    Move position of rx_submit() to remove forward declaration of
    rx_complete() which is now no longer required.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:15:34 +10:00
Jamie Bainbridge 55eb5e6bbe lan78xx: Introduce Rx URB processing improvements
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit c450a8eb187a4d7ebe92e0afec54ac31ce403e79
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Thu Nov 18 11:01:36 2021 +0000

    lan78xx: Introduce Rx URB processing improvements

    This patch introduces a new approach to allocating and managing
    Rx URBs that contributes to improving driver throughput and reducing
    CPU load.

    A pool of Rx URBs is created during driver instantiation. All the
    URBs are initially submitted to the USB host controller for
    processing.

    The default URB buffer size is different for each USB bus speed.
    The chosen sizes provide good USB utilisation with little impact on
    overall packet latency.

    Completed URBs are processed in the driver bottom half. The URB
    buffer contents are copied to a dynamically allocated SKB, which is
    then passed to the network stack. The URB is then re-submitted to
    the USB host controller.

    NOTE: the call to skb_copy() in rx_process() that copies the URB
    contents to a new SKB is a temporary change to make this patch work
    in its own right. This call will be removed when the NAPI processing
    is introduced by patch 6 in this patch set.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:14:48 +10:00
Jamie Bainbridge d5a8bc4497 lan78xx: Introduce Tx URB processing improvements
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit d383216a7efec3b38b8bd4925a208383b2492d84
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Thu Nov 18 11:01:35 2021 +0000

    lan78xx: Introduce Tx URB processing improvements

    This patch introduces a new approach to allocating and managing
    Tx URBs that contributes to improving driver throughput and reducing
    CPU load.

    A pool of Tx URBs is created during driver instantiation. A URB is
    allocated from the pool when there is data to transmit. The URB is
    released back to the pool when the data has been transmitted by the
    device.

    The default URB buffer size is different for each USB bus speed.
    The chosen sizes provide good USB utilisation with little impact on
    overall packet latency.

    SKBs to be transmitted are added to a pending queue for processing.
    The driver tracks the available Tx URB buffer space and copies as
    much pending data as possible into each free URB. Each full URB
    is then submitted to the USB host controller for transmission.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:13:45 +10:00
Jamie Bainbridge c197088a15 lan78xx: Fix memory allocation bug
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit a6df95cae40bee555e01a37b4023ce8e97ffa249
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Thu Nov 18 11:01:34 2021 +0000

    lan78xx: Fix memory allocation bug

    Fix memory allocation that fails to check for NULL return.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 15:12:42 +10:00
Jamie Bainbridge 99161fb31f net: lan78xx: fix division by zero in send path
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit db6c3c064f5d55fa9969f33eafca3cdbefbb3541
Author: Johan Hovold <johan@kernel.org>
Date:   Tue Oct 26 12:36:17 2021 +0200

    net: lan78xx: fix division by zero in send path

    Add the missing endpoint max-packet sanity check to probe() to avoid
    division by zero in lan78xx_tx_bh() in case a malicious device has
    broken descriptors (or when doing descriptor fuzz testing).

    Note that USB core will reject URBs submitted for endpoints with zero
    wMaxPacketSize but that drivers doing packet-size calculations still
    need to handle this (cf. commit 2548288b4f ("USB: Fix: Don't skip
    endpoint descriptors with maxpacket=0")).

    Fixes: 55d7de9de6 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")
    Cc: stable@vger.kernel.org      # 4.3
    Cc: Woojung.Huh@microchip.com <Woojung.Huh@microchip.com>
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:58:28 +10:00
Jamie Bainbridge 86d4fa5eca lan78xx: Limit number of driver warning messages
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit df0d6f7a342cd8e4fad1dff4ca262462300223f7
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:13 2021 +0100

    lan78xx: Limit number of driver warning messages

    Device removal can result in a large burst of driver warning messages
    (20 - 30) sent to the kernel log. Most of these are register read/write
    failures.

    This change limits the rate at which these messages are emitted.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:57:36 +10:00
Jamie Bainbridge 6654db25a2 lan78xx: Fix race condition in disconnect handling
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 77dfff5bb7e20ce1eaaf4c599d9c54a8f4331124
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:12 2021 +0100

    lan78xx: Fix race condition in disconnect handling

    If there is a device disconnect at roughly the same time as a
    deferred PHY link reset there is a race condition that can result
    in a kernel lock up due to a null pointer dereference in the
    driver's deferred work handling routine lan78xx_delayedwork().
    The following changes fix this problem.

    Add new status flag EVENT_DEV_DISCONNECT to indicate when the
    device has been removed and use it to prevent operations, such as
    register access, that will fail once the device is removed.

    Stop processing of deferred work items when the driver's USB
    disconnect handler is invoked.

    Disconnect the PHY only after the network device has been
    unregistered and all delayed work has been cancelled.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:56:57 +10:00
Jamie Bainbridge 0cc4f9b9a2 lan78xx: Fix race conditions in suspend/resume handling
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 5f4cc6e25148cc141f97afb41b4dfe9eb1cce613
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:11 2021 +0100

    lan78xx: Fix race conditions in suspend/resume handling

    If the interface is given an IP address while the device is
    suspended (as a result of an auto-suspend event) there is a race
    between lan78xx_resume() and lan78xx_open() that can result in an
    exception or failure to handle incoming packets. The following
    changes fix this problem.

    Introduce a mutex to serialise operations in the network interface
    open and stop entry points with respect to the USB driver suspend
    and resume entry points.

    Move Tx and Rx data path start/stop to lan78xx_start() and
    lan78xx_stop() respectively and flush the packet FIFOs before
    starting the Tx and Rx data paths. This prevents the MAC and FIFOs
    getting out of step and delivery of malformed packets to the network
    stack.

    Stop processing of received packets before disconnecting the
    PHY from the MAC to prevent a kernel exception caused by handling
    packets after the PHY device has been removed.

    Refactor device auto-suspend code to make it consistent with the
    the system suspend code and make the suspend handler easier to read.

    Add new code to stop wake-on-lan packets or PHY events resuming the
    host or device from suspend if the device has not been opened
    (typically after an IP address is assigned).

    This patch is dependent on changes to lan78xx_suspend() and
    lan78xx_resume() introduced in the previous patch of this patch set.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:54:02 +10:00
Jamie Bainbridge 2db32e9141 lan78xx: Fix partial packet errors on suspend/resume
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit e1210fe63bf8b080edd0805240e90b81b6b069c1
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:10 2021 +0100

    lan78xx: Fix partial packet errors on suspend/resume

    The MAC can get out of step with the internal packet FIFOs if the
    system goes to sleep when the link is active, especially at high
    data rates. This can result in partial frames in the packet FIFOs
    that in result in malformed frames being delivered to the host.
    This occurs because the driver does not enable/disable the internal
    packet FIFOs in step with the corresponding MAC data path. The
    following changes fix this problem.

    Update code that enables/disables the MAC receiver and transmitter
    to the more general Rx and Tx data path, where the data path in each
    direction consists of both the MAC function (Tx or Rx) and the
    corresponding packet FIFO.

    In the receive path the packet FIFO must be enabled before the MAC
    receiver but disabled after the MAC receiver.

    In the transmit path the opposite is true: the packet FIFO must be
    enabled after the MAC transmitter but disabled before the MAC
    transmitter.

    The packet FIFOs can be flushed safely once the corresponding data
    path is stopped.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:53:20 +10:00
Jamie Bainbridge 0e97f9830a lan78xx: Fix exception on link speed change
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit b1f6696daafebea243ed59ed18a8b10cfd33b474
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:09 2021 +0100

    lan78xx: Fix exception on link speed change

    An exception is sometimes seen when the link speed is changed
    from auto-negotiation to a fixed speed, or vice versa. The
    exception occurs when the MAC is reset (due to the link speed
    change) at the same time as the PHY state machine is accessing
    a PHY register. The following changes fix this problem.

    Rework the MAC reset to ensure there is no outstanding MDIO
    register transaction before the reset and then wait until the
    reset is complete before allowing any further MAC register access.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:52:27 +10:00
Jamie Bainbridge 7b4ad71fa9 lan78xx: Add missing return code checks
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 3415f6baaddb9b39d7112247ab39ef3c700f882e
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:08 2021 +0100

    lan78xx: Add missing return code checks

    There are many places in the driver where the return code from a
    function call is captured but without a subsequent test of the
    return code and appropriate action taken.

    This patch adds the missing return code tests and action. In most
    cases the action is an early exit from the calling function.

    The function lan78xx_set_suspend() was also updated to make it
    consistent with lan78xx_suspend().

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:51:52 +10:00
Jamie Bainbridge a8760692c6 lan78xx: Remove unused pause frame queue
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 40b8452fa8b4567ab7d862c7d4c3d02f635f17fd
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:07 2021 +0100

    lan78xx: Remove unused pause frame queue

    Remove the pause frame queue from the driver. It is initialised
    but not actually used.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:50:51 +10:00
Jamie Bainbridge c95e30d153 lan78xx: Set flow control threshold to prevent packet loss
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit dc35f8548e005b8a32fedaa5b01d52585eba5f1d
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:06 2021 +0100

    lan78xx: Set flow control threshold to prevent packet loss

    Set threshold at which flow control is triggered to 3/4 full of
    the internal Rx packet FIFO to prevent packet drops at high data
    rates. The new setting reduces the number of dropped UDP frames
    and TCP retransmit requests especially on less capable CPUs.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:49:57 +10:00
Jamie Bainbridge 45aee82456 lan78xx: Remove unused timer
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 3bef6b9e98888456805331201c0d8587c14fa108
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:05 2021 +0100

    lan78xx: Remove unused timer

    Remove kernel timer that is not used by the driver.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:48:42 +10:00
Jamie Bainbridge 2367558ab6 lan78xx: Fix white space and style issues
JIRA: https://issues.redhat.com/browse/RHEL-33332

Clean cherry-pick of upstream commit:

commit 9ceec7d33adf9647293f24d2fd9a055b89c63864
Author: John Efstathiades <john.efstathiades@pebblebay.com>
Date:   Tue Aug 24 19:56:04 2021 +0100

    lan78xx: Fix white space and style issues

    Fix white space and code style issues identified by checkpatch.

    Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jamie Bainbridge <jbainbri@redhat.com>
2024-04-18 14:43:25 +10:00
Adrien Thierry 66c193d990 net: lan78xx: fix accessing the LAN7800's internal phy specific registers from the MAC driver
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit e57cf3639c323eeed05d3725fd82f91b349adca8
Author: Yuiko Oshino <yuiko.oshino@microchip.com>
Date:   Wed Mar 1 08:43:07 2023 -0700

    net: lan78xx: fix accessing the LAN7800's internal phy specific registers from the MAC driver

    Move the LAN7800 internal phy (phy ID  0x0007c132) specific register
    accesses to the phy driver (microchip.c).

    Fix the error reported by Enguerrand de Ribaucourt in December 2022,
    "Some operations during the cable switch workaround modify the register
    LAN88XX_INT_MASK of the PHY. However, this register is specific to the
    LAN8835 PHY. For instance, if a DP8322I PHY is connected to the LAN7801,
    that register (0x19), corresponds to the LED and MAC address
    configuration, resulting in unapropriate behavior."

    I did not test with the DP8322I PHY, but I tested with an EVB-LAN7800
    with the internal PHY.

    Fixes: 14437e3fa2 ("lan78xx: workaround of forced 100 Full/Half duplex mode error")
    Signed-off-by: Yuiko Oshino <yuiko.oshino@microchip.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://lore.kernel.org/r/20230301154307.30438-1-yuiko.oshino@microchip.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:09 -04:00
Íñigo Huguet 4a3ebea37a net: remove third argument of usb_maxpacket()
Bugzilla: https://bugzilla.redhat.com/2143363

Conflicts:
 - lan78xx: context conflicts, many missing commits
 - usbnet: context conflict, missing 397430b50a36 ("usbnet: sanity check for
   maxpacket")

commit e13adbfa391264673bd3ff29ca966af0147b6f4d
Author: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Date:   Thu Mar 17 12:55:10 2022 +0900

    net: remove third argument of usb_maxpacket()
    
    The third argument of usb_maxpacket(): in_out has been deprecated
    because it could be derived from the second argument (e.g. using
    usb_pipeout(pipe)).
    
    N.B. function usb_maxpacket() was made variadic to accommodate the
    transition from the old prototype with three arguments to the new one
    with only two arguments (so that no renaming is needed). The variadic
    argument is to be removed once all users of usb_maxpacket() get
    migrated.
    
    CC: Oliver Neukum <oliver@neukum.org>
    CC: David S. Miller <davem@davemloft.net>
    CC: Jakub Kicinski <kuba@kernel.org>
    CC: Woojung Huh <woojung.huh@microchip.com>
    CC: Felix Fietkau <nbd@nbd.name>
    CC: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
    CC: Ryder Lee <ryder.lee@mediatek.com>
    CC: Kalle Valo <kvalo@kernel.org>
    CC: Matthias Brugger <matthias.bgg@gmail.com>
    CC: Stanislaw Gruszka <stf_xl@wp.pl>
    CC: Helmut Schaa <helmut.schaa@googlemail.com>
    Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
    Link: https://lore.kernel.org/r/20220317035514.6378-6-mailhol.vincent@wanadoo.fr
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Íñigo Huguet <ihuguet@redhat.com>
2022-11-18 12:10:50 +01:00
Ivan Vecera 4ba4dadfe4 net: make drivers set the TSO limit not the GSO limit
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2128180

Conflicts:
* drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
* drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
  - small context conflicts
* drivers/net/usb/ax88179_178a.c
  - hunk removed, the driver does not call netif_set_gso_max_size()
* drivers/net/usb/lan78xx.c
  - modified due to absence of commits d383216a7efe ("lan78xx: Introduce
    Tx URB processing improvements") and 0dd87266c133 ("lan78xx: Remove
    hardware-specific header update")

commit ee8b7a1156f357613646d6c69d07ac5a087a1071
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Thu May 5 19:51:33 2022 -0700

    net: make drivers set the TSO limit not the GSO limit

    Drivers should call the TSO setting helper, GSO is controllable
    by user space.

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2022-10-18 10:27:21 +02:00
Ivan Vecera 292aba8d62 net: usb: use eth_hw_addr_set() instead of ether_addr_copy()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2081256

commit af804e6db9f60b923ff5149d9bf782e0baa82a2b
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Fri Oct 1 14:32:24 2021 -0700

    net: usb: use eth_hw_addr_set() instead of ether_addr_copy()

    Commit 406f42fa0d3c ("net-next: When a bond have a massive amount
    of VLANs...") introduced a rbtree for faster Ethernet address look
    up. To maintain netdev->dev_addr in this tree we need to make all
    the writes to it got through appropriate helpers.

    Convert net/usb from ether_addr_copy() to eth_hw_addr_set():

      @@
      expression dev, np;
      @@
      - ether_addr_copy(dev->dev_addr, np)
      + eth_hw_addr_set(dev, np)

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2022-05-03 13:24:52 +02:00
Ivan Vecera 5064c2ed3b dev_ioctl: split out ndo_eth_ioctl
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2008927

commit a76053707dbf0dc020a73b4d90cd952409ef3691
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Tue Jul 27 15:45:13 2021 +0200

    dev_ioctl: split out ndo_eth_ioctl

    Most users of ndo_do_ioctl are ethernet drivers that implement
    the MII commands SIOCGMIIPHY/SIOCGMIIREG/SIOCSMIIREG, or hardware
    timestamping with SIOCSHWTSTAMP/SIOCGHWTSTAMP.

    Separate these from the few drivers that use ndo_do_ioctl to
    implement SIOCBOND, SIOCBR and SIOCWANDEV commands.

    This is a purely cosmetic change intended to help readers find
    their way through the implementation.

    Cc: Doug Ledford <dledford@redhat.com>
    Cc: Jason Gunthorpe <jgg@ziepe.ca>
    Cc: Jay Vosburgh <j.vosburgh@gmail.com>
    Cc: Veaceslav Falico <vfalico@gmail.com>
    Cc: Andy Gospodarek <andy@greyhouse.net>
    Cc: Andrew Lunn <andrew@lunn.ch>
    Cc: Vivien Didelot <vivien.didelot@gmail.com>
    Cc: Florian Fainelli <f.fainelli@gmail.com>
    Cc: Vladimir Oltean <olteanv@gmail.com>
    Cc: Leon Romanovsky <leon@kernel.org>
    Cc: linux-rdma@vger.kernel.org
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Acked-by: Jason Gunthorpe <jgg@nvidia.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2021-10-11 15:44:02 +02:00
Ivan T. Ivanov 6b67d4d63e net: usb: lan78xx: don't modify phy_device state concurrently
Currently phy_device state could be left in inconsistent state shown
by following alert message[1]. This is because phy_read_status could
be called concurrently from lan78xx_delayedwork, phy_state_machine and
__ethtool_get_link. Fix this by making sure that phy_device state is
updated atomically.

[1] lan78xx 1-1.1.1:1.0 eth0: No phy led trigger registered for speed(-1)

Signed-off-by: Ivan T. Ivanov <iivanov@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-08-04 12:51:14 +01:00
Zheng Yongjun f62c4f3870 net: usb: Fix spelling mistakes
wierdness  ==> weirdness
multicat  ==> multicast
limite  ==> limit
adddress  ==> address
operater  ==> operator
intial  ==> initial
smaler  ==> smaller
Communcation  ==> Communication
funcitons  ==> functions
everytime  ==> every time
Neigbor  ==> Neighbor
performace  ==> performance

Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-01 17:05:05 -07:00
Markus Bloechl 33e6b1674f net: lan78xx: advertise tx software timestamping support
lan78xx already calls skb_tx_timestamp() in its lan78xx_start_xmit().
Override .get_ts_info to also advertise this capability
(SOF_TIMESTAMPING_TX_SOFTWARE) via ethtool.

Signed-off-by: Markus Blöchl <markus.bloechl@ipetronik.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-05-18 13:38:48 -07:00
Zheng Yongjun a9bada338b net: usb: lan78xx: remove unused including <linux/version.h>
Remove including <linux/version.h> that don't need it.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
Acked-by: Woojung Huh <Woojung.Huh@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-03-25 16:55:33 -07:00
Emil Renner Berthing c23d544e99 net: usb: lan78xx: use new tasklet API
This converts the driver to use the new tasklet API introduced in
commit 12cc923f1c ("tasklet: Introduce new initialization API")

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-02-02 15:51:18 -08:00
Lee Jones 06cd7c46b3 net: usb: lan78xx: Remove lots of set but unused 'ret' variables
Fixes the following W=1 kernel build warning(s):

 drivers/net/usb/lan78xx.c: In function ‘lan78xx_read_raw_otp’:
 drivers/net/usb/lan78xx.c:825:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_write_raw_otp’:
 drivers/net/usb/lan78xx.c:879:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_deferred_multicast_write’:
 drivers/net/usb/lan78xx.c:1041:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_update_flowcontrol’:
 drivers/net/usb/lan78xx.c:1127:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_init_mac_address’:
 drivers/net/usb/lan78xx.c:1666:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_link_status_change’:
 drivers/net/usb/lan78xx.c:1841:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_irq_bus_sync_unlock’:
 drivers/net/usb/lan78xx.c:1920:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan8835_fixup’:
 drivers/net/usb/lan78xx.c:1994:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_set_rx_max_frame_length’:
 drivers/net/usb/lan78xx.c:2192:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_change_mtu’:
 drivers/net/usb/lan78xx.c:2270:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_set_mac_addr’:
 drivers/net/usb/lan78xx.c:2299:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_set_features’:
 drivers/net/usb/lan78xx.c:2333:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
 drivers/net/usb/lan78xx.c: In function ‘lan78xx_set_suspend’:
 drivers/net/usb/lan78xx.c:3807:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]

Signed-off-by: Lee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/20201102114512.1062724-25-lee.jones@linaro.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-11-03 16:37:44 -08:00
Gustavo A. R. Silva df561f6688 treewide: Use fallthrough pseudo-keyword
Replace the existing /* fall through */ comments and its variants with
the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
fall-through markings when it is the case.

[1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2020-08-23 17:36:59 -05:00
Johan Hovold ea060b3526 net: lan78xx: replace bogus endpoint lookup
Drop the bogus endpoint-lookup helper which could end up accepting
interfaces based on endpoints belonging to unrelated altsettings.

Note that the returned bulk pipes and interrupt endpoint descriptor
were never actually used. Instead the bulk-endpoint numbers are
hardcoded to 1 and 2 (matching the specification), while the interrupt-
endpoint descriptor was assumed to be the third descriptor created by
USB core.

Try to bring some order to this by dropping the bogus lookup helper and
adding the missing endpoint sanity checks while keeping the interrupt-
descriptor assumption for now.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-07-28 13:35:44 -07:00
Johan Hovold 63634aa679 net: lan78xx: fix transfer-buffer memory leak
The interrupt URB transfer-buffer was never freed on disconnect or after
probe errors.

Fixes: 55d7de9de6 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")
Cc: Woojung.Huh@microchip.com <Woojung.Huh@microchip.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-07-28 13:35:44 -07:00