Question

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?

Was it helpful?

Solution

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 ??

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top