changeset 15:74d9d18d4732

WIP on the ethernet part of the LKM sample
author Louis Opter <louis@lse.epitech.net>
date Fri, 06 Jan 2012 22:46:33 +0100
parents 4aac69287060
children 41a434b0676b
files maintainers_add_add_rathaxes_lkm_in_use_rathaxes_cmake_file.patch rathaxes_start_to_implement_the_ethernet_subsystem_in_the_lkm.patch
diffstat 2 files changed, 80 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/maintainers_add_add_rathaxes_lkm_in_use_rathaxes_cmake_file.patch	Fri Jan 06 19:09:16 2012 +0100
+++ b/maintainers_add_add_rathaxes_lkm_in_use_rathaxes_cmake_file.patch	Fri Jan 06 22:46:33 2012 +0100
@@ -1,5 +1,5 @@
 # HG changeset patch
-# Parent d2807f4a86fdd8e40cf6ee1a5f19fefd1d3fccae
+# Parent dd92091de0edd583c8dd1ff884b5ca5fcd080c3d
 maintainers: add the equivalent of ADD_RATHAXES_EXECUTABLE for kernel modules, only support Linux for now
 
 diff --git a/maintainers/CMakeScripts/Templates/MakefileLKM.in b/maintainers/CMakeScripts/Templates/MakefileLKM.in
@@ -7,8 +7,8 @@
 --- /dev/null
 +++ b/maintainers/CMakeScripts/Templates/MakefileLKM.in
 @@ -0,0 +1,12 @@
-+KDIR =	/lib/modules/$(shell uname -r)/build
-+obj-m := @LKM_OBJECTS@
++KDIR	= /lib/modules/$(shell uname -r)/build
++obj-m	:= @LKM_OBJECTS@
 +
 +all:
 +	$(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd) modules
--- a/rathaxes_start_to_implement_the_ethernet_subsystem_in_the_lkm.patch	Fri Jan 06 19:09:16 2012 +0100
+++ b/rathaxes_start_to_implement_the_ethernet_subsystem_in_the_lkm.patch	Fri Jan 06 22:46:33 2012 +0100
@@ -18,7 +18,7 @@
 new file mode 100644
 --- /dev/null
 +++ b/rathaxes/samples/lkm/ethernet.blt
-@@ -0,0 +1,144 @@
+@@ -0,0 +1,162 @@
 +with Ethernet, PCI, LKM
 +{
 +    template type   Ethernet::Device()
@@ -33,7 +33,15 @@
 +
 +        chunk ::decl()
 +        {
-+            struct net_device;
++            struct rtx_ethernet_dev
++            {
++                /*
++                 * I think it's useless to use the ${PCI::Device} "abstraction"
++                 * here, since we are already in a Linux specific context here.
++                 */
++                struct pci_dev      *pci_dev;
++                struct net_device   *net_dev;
++            };
 +        }
 +
 +        chunk ::init(net_dev)
@@ -105,61 +113,71 @@
 +        }
 +    }
 +
-+    template sequence   Ethernet::init(PCI::Device dev)
++    template sequence   Ethernet::init(PCI::Device pdev)
 +    {
 +        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,
 +            };
-+
 +        }
 +
 +        chunk ::CALL
 +        {
 +            /*
-+             * int should be replaced by the sizeof of an hypothetic "context"
-+             * structure defined in the front-end.
++             * This typedef is needed to workaround a bug in CNorm __std__
++             * dialect.
 +             */
-+            rtx_net_dev = alloc_etherdev(sizeof(int));
-+            /*
-+             * if (rtx_net_dev == NULL)
-+             *  {
-+             *      // What can we do here?
-+             *  }
-+             */
++            typedef int ${Ethernet::Device};
++            ${Ethernet::Device} *rtx_ether_ctx;
++            struct net_device   *net_dev;
++
++            net_dev = alloc_etherdev(sizeof(*rtx_ether_ctx));
++            //if (net_dev == NULL)
++                // How should we raise the error in the parent context?
++            // Maybe we should try ${rtx_ether_ctx.init()} here:
++            rtx_ether_ctx = netdev_priv(net_dev);
++            //rtx_ether_ctx->pci_dev = ${pdev};
++            rtx_ether_ctx->pci_dev = pdev; // In the meantime do it directly
++            rtx_ether_ctx->net_dev = net_dev;
 +
 +            /*
-+             * The substitution of ${dev} fails here. I also tried to add a
++             * The substitution of ${pdev} fails here. I also tried to add a
 +             * "substitute method" to the PCI::Device that was just doing
 +             * "${self}" but it didn't work either (it was subsituted by a
 +             * placeholder, e.g: _1).
++             *
++             * That's why we cheated a bit and named all the arguments pdev.
 +             */
-+            //SET_NETDEV_DEV(rtx_net_dev, &${dev}->dev);
-+            rtx_net_dev->netdev_ops = &rtx_ether_ops;
++            //SET_NETDEV_DEV(net_dev, &${pdev}->dev);
++            SET_NETDEV_DEV(net_dev, &pdev->dev);
++            net_dev->netdev_ops = &rtx_ether_ops;
 +
-+            /* if (*/register_netdev(rtx_net_dev);/*)*/
-+            /* {
-+             *   XXX: handle the error
-+             * }
-+             */
++            /* if (*/register_netdev(net_dev);/*)*/
++                // Handle the error
++
++            /* same problem as above with ${pdev} */
++            //pci_set_drvdata(${pdev}, net_dev);
++            pci_set_drvdata(pdev, net_dev);
 +        }
 +    }
 +
-+    template sequence   Ethernet::exit(PCI::Device dev)
++    template sequence   Ethernet::exit(PCI::Device pdev)
 +    {
 +        chunk ::CALL
 +        {
++            struct net_device   *net_dev;
++
++            net_dev = pci_get_drvdata(pdev); // should be ${pdev}, see above
++            unregister_netdev(net_dev);
++            /*
++             * If we had some cleanup todo with struct rtx_ether_ctx we would
++             * do a netdev_priv(net_dev) here and do it.
++             */
++            free_netdev(net_dev);
 +        }
 +    }
 +}
@@ -167,7 +185,7 @@
 new file mode 100644
 --- /dev/null
 +++ b/rathaxes/samples/lkm/ethernet.rti
-@@ -0,0 +1,33 @@
+@@ -0,0 +1,35 @@
 +interface Ethernet : PCI, LKM
 +{
 +    provided type       Ethernet::Device;
@@ -190,12 +208,14 @@
 +        provided chunk  LKM::code;
 +    }
 +
++    /* Kinda extends PCI::probe */
 +    provided sequence   Ethernet::init(PCI::Device)
 +    {
 +        provided chunk  LKM::data;
 +        provided chunk  ::CALL;
 +    }
 +
++    /* Likely extends PCI::remove */
 +    provided sequence   Ethernet::exit(PCI::Device)
 +    {
 +        provided chunk  ::CALL;
@@ -204,7 +224,7 @@
 diff --git a/rathaxes/samples/lkm/lkm.rtx b/rathaxes/samples/lkm/lkm.rtx
 --- a/rathaxes/samples/lkm/lkm.rtx
 +++ b/rathaxes/samples/lkm/lkm.rtx
-@@ -1,13 +1,24 @@
+@@ -1,13 +1,25 @@
  device LKM use LKM, PCI, Log
  {
 +    Ethernet::open(Ethernet::Device dev)
@@ -228,6 +248,7 @@
      PCI::remove(PCI::Device dev)
      {
 -
++        Ethernet::exit(dev);
      }
  
      LKM::init()
@@ -252,10 +273,11 @@
          }
  
          map
-@@ -27,6 +24,16 @@
+@@ -27,7 +24,17 @@
          }
      }
  
+-    template sequence   PCI::probe(PCI::Device dev)
 +    /*
 +     * The PCI::probe sequence is a "required" sequence which means that its
 +     * implementation will be done in the .rtx. Here we just define the context
@@ -266,9 +288,10 @@
 +     *
 +     * The only thing I can imagine is: ${pointcut ::IMPLEMENTATION(pdev)};
 +     */
-     template sequence   PCI::probe(PCI::Device dev)
++    template sequence   PCI::probe(PCI::Device pdev)
      {
          chunk LKM::prototypes()
+         {
 @@ -40,11 +47,7 @@
              static int /* __devinit */  rtx_pci_probe(struct pci_dev *pdev,
                                                        const struct pci_device_id *pdev_id)
@@ -290,6 +313,27 @@
                  return 0;
  
                  fail:
+@@ -62,7 +63,7 @@
+         }
+     }
+ 
+-    template sequence   PCI::remove(PCI::Device dev)
++    template sequence   PCI::remove(PCI::Device pdev)
+     {
+         chunk LKM::prototypes()
+         {
+@@ -73,9 +74,9 @@
+         {
+             static void rtx_pci_remove(struct pci_dev *pdev)
+             {
++                ${pointcut ::IMPLEMENTATION};
++
+                 pci_disable_device(pdev);
+-
+-                ${pointcut ::IMPLEMENTATION};
+             }
+         }
+     }
 @@ -88,9 +89,10 @@
               * CNorm doesn't seem to like "dynamic" arrays (i.e: you always
               * have to specify the exact size).