Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Common code for low-level network console, dump, and debugger code
0004  *
0005  * Derived from netconsole, kgdb-over-ethernet, and netdump patches
0006  */
0007 
0008 #ifndef _LINUX_NETPOLL_H
0009 #define _LINUX_NETPOLL_H
0010 
0011 #include <linux/netdevice.h>
0012 #include <linux/interrupt.h>
0013 #include <linux/rcupdate.h>
0014 #include <linux/list.h>
0015 #include <linux/refcount.h>
0016 
0017 union inet_addr {
0018     __u32       all[4];
0019     __be32      ip;
0020     __be32      ip6[4];
0021     struct in_addr  in;
0022     struct in6_addr in6;
0023 };
0024 
0025 struct netpoll {
0026     struct net_device *dev;
0027     netdevice_tracker dev_tracker;
0028     char dev_name[IFNAMSIZ];
0029     const char *name;
0030 
0031     union inet_addr local_ip, remote_ip;
0032     bool ipv6;
0033     u16 local_port, remote_port;
0034     u8 remote_mac[ETH_ALEN];
0035 };
0036 
0037 struct netpoll_info {
0038     refcount_t refcnt;
0039 
0040     struct semaphore dev_lock;
0041 
0042     struct sk_buff_head txq;
0043 
0044     struct delayed_work tx_work;
0045 
0046     struct netpoll *netpoll;
0047     struct rcu_head rcu;
0048 };
0049 
0050 #ifdef CONFIG_NETPOLL
0051 void netpoll_poll_dev(struct net_device *dev);
0052 void netpoll_poll_disable(struct net_device *dev);
0053 void netpoll_poll_enable(struct net_device *dev);
0054 #else
0055 static inline void netpoll_poll_disable(struct net_device *dev) { return; }
0056 static inline void netpoll_poll_enable(struct net_device *dev) { return; }
0057 #endif
0058 
0059 void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
0060 void netpoll_print_options(struct netpoll *np);
0061 int netpoll_parse_options(struct netpoll *np, char *opt);
0062 int __netpoll_setup(struct netpoll *np, struct net_device *ndev);
0063 int netpoll_setup(struct netpoll *np);
0064 void __netpoll_cleanup(struct netpoll *np);
0065 void __netpoll_free(struct netpoll *np);
0066 void netpoll_cleanup(struct netpoll *np);
0067 netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb);
0068 
0069 #ifdef CONFIG_NETPOLL
0070 static inline void *netpoll_poll_lock(struct napi_struct *napi)
0071 {
0072     struct net_device *dev = napi->dev;
0073 
0074     if (dev && dev->npinfo) {
0075         int owner = smp_processor_id();
0076 
0077         while (cmpxchg(&napi->poll_owner, -1, owner) != -1)
0078             cpu_relax();
0079 
0080         return napi;
0081     }
0082     return NULL;
0083 }
0084 
0085 static inline void netpoll_poll_unlock(void *have)
0086 {
0087     struct napi_struct *napi = have;
0088 
0089     if (napi)
0090         smp_store_release(&napi->poll_owner, -1);
0091 }
0092 
0093 static inline bool netpoll_tx_running(struct net_device *dev)
0094 {
0095     return irqs_disabled();
0096 }
0097 
0098 #else
0099 static inline void *netpoll_poll_lock(struct napi_struct *napi)
0100 {
0101     return NULL;
0102 }
0103 static inline void netpoll_poll_unlock(void *have)
0104 {
0105 }
0106 static inline bool netpoll_tx_running(struct net_device *dev)
0107 {
0108     return false;
0109 }
0110 #endif
0111 
0112 #endif