Message ID | 20240123221749.793069-2-almasrymina@google.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Abstract page from net stack | expand |
On Tue, 2024-01-23 at 14:17 -0800, Mina Almasry wrote: > diff --git a/include/net/netmem.h b/include/net/netmem.h > new file mode 100644 > index 000000000000..9f327d964782 > --- /dev/null > +++ b/include/net/netmem.h > @@ -0,0 +1,41 @@ > +/* SPDX-License-Identifier: GPL-2.0 > + * > + * Network memory > + * > + * Author: Mina Almasry <almasrymina@google.com> > + */ > + > +#ifndef _NET_NETMEM_H > +#define _NET_NETMEM_H > + > +/** > + * netmem_ref - a nonexistent type marking a reference to generic network Minor nit: here you need to prepend 'struct' to avoid a kdoc warning: include/net/netmem.h:20: warning: cannot understand function prototype: 'typedef unsigned long __bitwise netmem_ref; ' Should be: * struct netmem_ref - a nonexistent type marking a reference to generic network Cheers, Paolo
On Tue, 30 Jan 2024 10:59:53 +0100 Paolo Abeni wrote: > > + * netmem_ref - a nonexistent type marking a reference to generic network > > Minor nit: here you need to prepend 'struct' to avoid a kdoc warning: > > include/net/netmem.h:20: warning: cannot understand function prototype: 'typedef unsigned long __bitwise netmem_ref; ' > > Should be: > > * struct netmem_ref - a nonexistent type marking a reference to generic network s/struct/typedef/ /** * typedef netmem_ref - .... */ Somewhat surprisingly kdoc understands the typedef keyword just fine :)
diff --git a/include/net/netmem.h b/include/net/netmem.h new file mode 100644 index 000000000000..9f327d964782 --- /dev/null +++ b/include/net/netmem.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Network memory + * + * Author: Mina Almasry <almasrymina@google.com> + */ + +#ifndef _NET_NETMEM_H +#define _NET_NETMEM_H + +/** + * netmem_ref - a nonexistent type marking a reference to generic network + * memory. + * + * A netmem_ref currently is always a reference to a struct page. This + * abstraction is introduced so support for new memory types can be added. + * + * Use the supplied helpers to obtain the underlying memory pointer and fields. + */ +typedef unsigned long __bitwise netmem_ref; + +/* This conversion fails (returns NULL) if the netmem_ref is not struct page + * backed. + * + * Currently struct page is the only possible netmem, and this helper never + * fails. + */ +static inline struct page *netmem_to_page(netmem_ref netmem) +{ + return (__force struct page *)netmem; +} + +/* Converting from page to netmem is always safe, because a page can always be + * a netmem. + */ +static inline netmem_ref page_to_netmem(struct page *page) +{ + return (__force netmem_ref)page; +} + +#endif /* _NET_NETMEM_H */