view rathaxes_start_to_implement_the_ethernet_subsystem_in_the_lkm.patch @ 13:d00a5829811d

rathaxes: add net_dev_ops + register netdev device, but still a bug, see the diff
author Thomas Sanchez <thomas.sanchz@gmail.com>
date Fri, 06 Jan 2012 18:08:41 +0100
parents 80cfe40c1136
children 4aac69287060
line wrap: on
line source

# HG changeset patch
# Parent 6d15ec109487b733721b6dbe84c27841f441e196
rathaxes: start to implement the Ethernet subsystem in linux LKM sample

diff -r 6d15ec109487 rathaxes/samples/lkm/CMakeLists.txt
--- a/rathaxes/samples/lkm/CMakeLists.txt	Fri Jan 06 17:34:47 2012 +0100
+++ b/rathaxes/samples/lkm/CMakeLists.txt	Fri Jan 06 18:06:48 2012 +0100
@@ -1,6 +1,6 @@
 ADD_RATHAXES_SOURCES(lkm lkm.rtx
-                     RTI log.rti lkm.rti pci.rti
-                     BLT log.blt lkm.blt pci.blt)
+                     RTI log.rti lkm.rti pci.rti ethernet.rti
+                     BLT log.blt lkm.blt pci.blt ethernet.blt)
 
 # We can't name lkm since it's already used as the target name to generate the
 # source (with ADD_RATHAXES_SOURCES).
diff -r 6d15ec109487 rathaxes/samples/lkm/ethernet.blt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rathaxes/samples/lkm/ethernet.blt	Fri Jan 06 18:06:48 2012 +0100
@@ -0,0 +1,135 @@
+with Ethernet, PCI, LKM
+{
+    template type   Ethernet::Device()
+    {
+        chunk LKM::includes()
+        {
+            #include <linux/netdevice.h>
+            #include <linux/etherdevice.h>
+
+            typedef int include_linux_net_system_stamp;
+        }
+
+        chunk ::decl()
+        {
+            struct net_device;
+        }
+
+        chunk ::init(net_dev)
+        {
+            ${self} = ${net_dev};
+        }
+
+        map
+        {
+        }
+    }
+
+    template sequence   Ethernet::open(Ethernet::Device dev)
+    {
+        chunk LKM::prototypes()
+        {
+            static int  rtx_ethernet_open(struct net_device *);
+        }
+
+        chunk LKM::code()
+        {
+            static int  rtx_ethernet_open(struct net_device *dev)
+            {
+                ${pointcut ::IMPLEMENTATION};
+            }
+        }
+    }
+
+    template sequence   Ethernet::close(Ethernet::Device dev)
+    {
+        chunk LKM::prototypes()
+        {
+            static int  rtx_ethernet_close(struct net_device );
+        }
+
+        chunk LKM::code()
+        {
+            static int  rtx_ethernet_close(struct net_device dev)
+            {
+                ${pointcut ::IMPLEMENTATION};
+            }
+        }
+    }
+
+    template sequence   Ethernet::interrupt_handler(Ethernet::Device dev)
+    {
+        /*
+         * Why we can't use irqreturn_t here? (we are forced to use enum
+         * irqreturn, which is the real type).
+         */
+
+        chunk LKM::prototypes()
+        {
+            static enum irqreturn   rtx_ethernet_interrupt_handler(int, void *);
+        }
+
+        chunk LKM::code()
+        {
+            static enum irqreturn   rtx_ethernet_interrupt_handler(int irq, void *dev_id)
+            {
+                ${pointcut ::IMPLEMENTATION};
+            }
+        }
+    }
+
+    template sequence   Ethernet::init(PCI::Device dev)
+    {
+        chunk LKM::data()
+        {
+            /*
+             * This typedef is needed to workaround a bug in CNorm __std__
+             * dialect.
+             */
+            typedef int ${Ethernet::Device};
+
+            static ${Ethernet::Device} *rtx_net_dev = NULL;
+            static const struct net_device_ops rtx_ether_ops= {
+                .ndo_open = rtx_ethernet_open,
+                .ndo_stop = rtx_ethernet_close,
+                .ndo_start_xmit = NULL, // XXX: 
+            };
+
+        }
+
+        chunk ::CALL
+        {
+            /*
+             * int should be replaced by the sizeof an hypothetic "context"
+             * structure defined in the front-end.
+             */
+            rtx_net_dev = alloc_etherdev(sizeof(int));
+            /*
+             * if (rtx_net_dev == NULL)
+             *  {
+             *      // What can we do here?
+             *  }
+             */
+
+            /*
+             * Does not work atm
+             */
+            // -> this is the problem, dev cannot be resolved ${dev} = 0;
+            // SET_NETDEV_DEV(rtx_net_dev, &${dev}->dev);
+            rtx_net_dev->netdev_ops = rtx_ether_ops;
+
+            /* if (*/register_netdev(rtx_net_dev);/*)*/
+            /* {
+             *   XXX: handle the error
+             * }
+             */
+        }
+    }
+
+    template sequence   Ethernet::exit(PCI::Device dev)
+    {
+        chunk ::CALL
+        {
+        }
+    }
+}
diff -r 6d15ec109487 rathaxes/samples/lkm/ethernet.rti
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rathaxes/samples/lkm/ethernet.rti	Fri Jan 06 18:06:48 2012 +0100
@@ -0,0 +1,33 @@
+interface Ethernet : PCI, LKM
+{
+    provided type       Ethernet::Device;
+
+    required sequence   Ethernet::open(Ethernet::Device)
+    {
+        provided chunk  LKM::prototypes;
+        provided chunk  LKM::code;
+    }
+
+    required sequence   Ethernet::close(Ethernet::Device)
+    {
+        provided chunk  LKM::prototypes;
+        provided chunk  LKM::code;
+    }
+
+    required sequence   Ethernet::interrupt_handler(Ethernet::Device)
+    {
+        provided chunk  LKM::prototypes;
+        provided chunk  LKM::code;
+    }
+
+    provided sequence   Ethernet::init(PCI::Device)
+    {
+        provided chunk  LKM::data;
+        provided chunk  ::CALL;
+    }
+
+    provided sequence   Ethernet::exit(PCI::Device)
+    {
+        provided chunk  ::CALL;
+    }
+}
diff -r 6d15ec109487 rathaxes/samples/lkm/lkm.rtx
--- a/rathaxes/samples/lkm/lkm.rtx	Fri Jan 06 17:34:47 2012 +0100
+++ b/rathaxes/samples/lkm/lkm.rtx	Fri Jan 06 18:06:48 2012 +0100
@@ -1,13 +1,24 @@
 device LKM use LKM, PCI, Log
 {
+    Ethernet::open(Ethernet::Device dev)
+    {
+    }
+
+    Ethernet::close(Ethernet::Device dev)
+    {
+    }
+
+    Ethernet::interrupt_handler(Ethernet::Device dev)
+    {
+    }
+
     PCI::probe(PCI::Device dev)
     {
-
+        Ethernet::init(dev);
     }
 
     PCI::remove(PCI::Device dev)
     {
-
     }
 
     LKM::init()
diff -r 6d15ec109487 rathaxes/samples/lkm/pci.blt
--- a/rathaxes/samples/lkm/pci.blt	Fri Jan 06 17:34:47 2012 +0100
+++ b/rathaxes/samples/lkm/pci.blt	Fri Jan 06 18:06:48 2012 +0100
@@ -11,15 +11,12 @@
 
         chunk   ::decl()
         {
-            struct  rtx_pci_device
-            {
-                struct pci_dev  *pci_dev;
-            };
+            struct pci_dev;
         }
 
         chunk   ::init(pci_dev)
         {
-            ${self}.pci_dev = pci_dev;
+            ${self} = ${pci_dev};
         }
 
         map
@@ -40,11 +37,7 @@
             static int /* __devinit */  rtx_pci_probe(struct pci_dev *pdev,
                                                       const struct pci_device_id *pdev_id)
             {
-                /* workaround for CNorm __std__ dialect, shouldn't be here */
-                typedef int ${PCI::Device};
-
                 int             err;
-                ${PCI::Device}  *dev = NULL;
 
                 err = pci_enable_device(pdev);
 //              if (err < 0) /* `if' doesn't work */
@@ -52,8 +45,6 @@
 
                 ${pointcut ::IMPLEMENTATION};
 
-                pci_set_drvdata(pdev, dev);
-
                 return 0;
 
                 fail: