Skip to content

Commit da5da5d

Browse files
committed
rust: add initial netdevice support
Added minimum abstration APIs for network device drivers. Signed-off-by: FUJITA Tomonori <[email protected]>
1 parent f509ede commit da5da5d

File tree

3 files changed

+403
-2
lines changed

3 files changed

+403
-2
lines changed

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/irq.h>
2323
#include <linux/miscdevice.h>
2424
#include <linux/module.h>
25+
#include <linux/netdevice.h>
2526
#include <linux/netfilter_arp.h>
2627
#include <linux/netfilter.h>
2728
#include <linux/netfilter_ipv4.h>

rust/helpers.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/build_bug.h>
2424
#include <linux/clk.h>
2525
#include <linux/errname.h>
26+
#include <linux/etherdevice.h>
2627
#include <linux/fs_parser.h>
2728
#include <linux/gfp.h>
2829
#include <linux/highmem.h>
@@ -478,6 +479,12 @@ void *rust_helper_dev_get_drvdata(struct device *dev)
478479
}
479480
EXPORT_SYMBOL_GPL(rust_helper_dev_get_drvdata);
480481

482+
void rust_helper_dev_set_drvdata(struct device *dev, void *data)
483+
{
484+
dev_set_drvdata(dev, data);
485+
}
486+
EXPORT_SYMBOL_GPL(rust_helper_dev_set_drvdata);
487+
481488
const char *rust_helper_dev_name(const struct device *dev)
482489
{
483490
return dev_name(dev);
@@ -655,6 +662,36 @@ int rust_helper_fs_parse(struct fs_context *fc,
655662
}
656663
EXPORT_SYMBOL_GPL(rust_helper_fs_parse);
657664

665+
#ifdef CONFIG_NET
666+
void rust_helper_eth_hw_addr_set(struct net_device *dev, const u8 *addr)
667+
{
668+
eth_hw_addr_set(dev, addr);
669+
}
670+
EXPORT_SYMBOL_GPL(rust_helper_eth_hw_addr_set);
671+
672+
void rust_helper_netif_start_queue(struct net_device *dev)
673+
{
674+
netif_start_queue(dev);
675+
}
676+
EXPORT_SYMBOL_GPL(rust_helper_netif_start_queue);
677+
678+
void rust_helper_netif_stop_queue(struct net_device *dev) {
679+
netif_stop_queue(dev);
680+
}
681+
EXPORT_SYMBOL_GPL(rust_helper_netif_stop_queue);
682+
683+
void rust_helper_netdev_sent_queue(struct net_device *dev, unsigned int bytes) {
684+
return netdev_sent_queue(dev, bytes);
685+
}
686+
EXPORT_SYMBOL_GPL(rust_helper_netdev_sent_queue);
687+
688+
struct sk_buff *rust_helper_netdev_alloc_skb_ip_align(struct net_device *dev,
689+
unsigned int length) {
690+
return netdev_alloc_skb_ip_align(dev, length);
691+
}
692+
EXPORT_SYMBOL_GPL(rust_helper_netdev_alloc_skb_ip_align);
693+
#endif
694+
658695
/*
659696
* We use `bindgen`'s `--size_t-is-usize` option to bind the C `size_t` type
660697
* as the Rust `usize` type, so we can use it in contexts where Rust

0 commit comments

Comments
 (0)