]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[netdevice] Add the concept of an insomniac network device
authorMichael Brown <mcb30@ipxe.org>
Wed, 16 Apr 2025 23:27:13 +0000 (00:27 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 17 Apr 2025 09:42:22 +0000 (10:42 +0100)
Some network devices (observed with the SNP interface to the wireless
network card on an HP Elitebook 840 G10) will stop working if they are
left for too long without being polled.

Add the concept of an insomniac network device, that must continue to
be polled even when closed.

Note that drivers are already permitted to call netdev_rx() et al even
when closed: this will already be happening for USB devices since
polling operates at the level of the whole USB bus, rather than at the
level of individual USB devices.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/netdevice.h
src/net/netdevice.c

index caa83b44bd2acd3955e640b6d04ce12d6136cb99..17695d5b64e48c324b986ce8eaca01f7eca08995 100644 (file)
@@ -457,6 +457,9 @@ struct net_device {
 /** Network device poll is in progress */
 #define NETDEV_POLL_IN_PROGRESS 0x0020
 
+/** Network device must be polled even when closed */
+#define NETDEV_INSOMNIAC 0x0040
+
 /** Link-layer protocol table */
 #define LL_PROTOCOLS __table ( struct ll_protocol, "ll_protocols" )
 
@@ -693,6 +696,17 @@ netdev_rx_frozen ( struct net_device *netdev ) {
        return ( netdev->state & NETDEV_RX_FROZEN );
 }
 
+/**
+ * Check whether or not network device must be polled even while closed
+ *
+ * @v netdev           Network device
+ * @ret insomniac      Network device must be polled even while closed
+ */
+static inline __attribute__ (( always_inline )) int
+netdev_insomniac ( struct net_device *netdev ) {
+       return ( netdev->state & NETDEV_INSOMNIAC );
+}
+
 extern void * netdev_priv ( struct net_device *netdev,
                            struct net_driver *driver );
 extern void netdev_rx_freeze ( struct net_device *netdev );
index a9ed181346374722987db10f855e675c1f4fddeb..c89585708927db3eb92f93aaf269898d6e278c79 100644 (file)
@@ -611,8 +611,8 @@ void netdev_rx_err ( struct net_device *netdev,
  */
 void netdev_poll ( struct net_device *netdev ) {
 
-       /* Avoid calling poll() on unopened network devices */
-       if ( ! netdev_is_open ( netdev ) )
+       /* Call poll() only on open (or insomniac) network devices */
+       if ( ! ( netdev->state & ( NETDEV_OPEN | NETDEV_INSOMNIAC ) ) )
                return;
 
        /* Guard against re-entry */