I am going through Linux Networking device driver code and wanted to know is it possible call device layer code from driver code.
--- a/drivers/net/ethernet/realtek/8139too.c
+++ b/drivers/net/ethernet/realtek/8139too.c
@@ -1706,10 +1706,20 @@ static netdev_tx_t rtl8139_start_xmit (struct sk_buff *skb,
unsigned int entry;
unsigned int len = skb->len;
unsigned long flags;
-
+ int ret=0;
/* Calculate the next Tx descriptor entry. */
entry = tp->cur_tx % NUM_TX_DESC;
+
+ ret = dev_queue_xmit(skb);
+
+ if (likely(ret == NET_XMIT_SUCCESS || ret == NET_XMIT_CN)) {}
+
+ else {
+ dev->stats.tx_dropped++;
+
+ }
+
In above code ,I tried to call dev_queque_xmit(skb),which is an interface to device layer and it hooked up with Linux QoS code.
I made these changes in hope that packet drop due to Linux traffic control is captured by ifconfig stats under tx drop byte field,But not sure these changes would work?
Is it possible to call device layer from driver layer in such a way I tried?
The kernel calls a device driver to perform I/O operations on the device such as open(2), read(2), and ioctl(2). User-level requests. The kernel calls device drivers to service requests from commands such as prtconf(1M).
Device drivers works within the kernel layer of the operating system. Kernel is the part of the operating system that directly interacts with the physical structure of the system.
Linux allows you to include device drivers at kernel build time via its configuration scripts. When these drivers are initialized at boot time they may not discover any hardware to control. Other drivers can be loaded as kernel modules when they are needed.
Answer: In general, drivers provide detail implementation to specific physical or logical devices, while kernel then provide a set of interface for drivers, and manage them in a higher abstracted level (HAL). By the way, kernel does a lot more than managing hardware resources.
As for if this code could work correctly, I doubt so. This change would cause trouble, like:
dev_queue_xmit()
-> enqueue to QoS (I assume you mean Qdisc)
-> rtl8139_start_xmit()
-> dev_queue_xmit() # creating a loop
Currently, no way for "ifconfig" to get to know "number of drop packets(due to QoS)", because "ifconfig" read statistics from /proc/net/dev, and those statistics doesn't contain QoS statistics, but just NIC driver itself.
But you can get to know "number of drop packets(due to QoS)", in other way. In kernel source code, there is:
rtnl_register(PF_UNSPEC, RTM_GETQDISC, tc_get_qdisc, tc_dump_qdisc, NULL); # it fill "gnet_stats_queue", and there is a drop counter internally.
which is to dump Qdisc status, including drop number due to congestion. It is a interface for Advanced user-level admin tool ( not "ifconfig" ) to retrieve more detailed information via rtlink message, in addition of "/proc/net/dev". However, I am not sure what those advanced user-level admin tool are (not familar with them). Maybe "ip" command could ??
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With