view rathaxes_e1000_move_the_interrupt_init_and_cleanup_into_ethernet.patch @ 108:7efe3212db3a

Put the patches on e1000 above the patches on the compiler
author Louis Opter <louis@lse.epita.fr>
date Sun, 31 Mar 2013 20:00:09 -0700
parents f42751b8ca99
children
line wrap: on
line source

# HG changeset patch
# Parent 7be52c02870a053b3a12e75423226c252e256c6b
Move the interrupt handler init/cleanup out of e1000.blt

This is not device dependant and can be done from the Ethernet subsystem
right now, (plus the interrupt handler itself was already in the
Ethernet subsytem).

diff --git a/rathaxes/samples/e1000/e1000.blt b/rathaxes/samples/e1000/e1000.blt
--- a/rathaxes/samples/e1000/e1000.blt
+++ b/rathaxes/samples/e1000/e1000.blt
@@ -247,7 +247,6 @@
         {
             int                         bars;
             unsigned char /* __iomem */ *ioaddr;
-            int                         irq;
 
             ${e1000::RxRing}    rx_ring;
             ${e1000::TxRing}    tx_ring;
@@ -265,14 +264,12 @@
 
         chunk   Ethernet::adapter_init_context(Ethernet::Device rtx_ether_ctx,
                                                Builtin::number bars,
-                                               Builtin::symbol ioaddr,
-                                               Builtin::number irq)
+                                               Builtin::symbol ioaddr)
         {
             {
                 ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx;
                 hw_ctx->bars = ${bars};
                 hw_ctx->ioaddr = ${ioaddr};
-                hw_ctx->irq = ${irq};
             }
         }
 
@@ -605,68 +602,6 @@
         }
     }
 
-    template sequence   e1000::setup_interrupt_handler(Ethernet::Device rtx_ether_ctx)
-    {
-        chunk   LKM::includes()
-        {
-            #include <linux/interrupt.h>
-        }
-
-        chunk   LKM::prototypes()
-        {
-            static int e1000_setup_interrupt_handler(${Ethernet::Device} *);
-        }
-
-        chunk   LKM::code()
-        {
-            static int e1000_setup_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx)
-            {
-                int error;
-
-                error = request_irq(rtx_ether_ctx->hw_ctx.irq,
-                        rtx_ethernet_interrupt_handler,
-                        IRQF_SHARED,
-                        ${config.name},
-                        rtx_ether_ctx);
-
-                if (error)
-                    ${Log::info("cannot register the interrupt handler")};
-
-                return error;
-            }
-        }
-
-        chunk   ::CALL()
-        {
-                int error = e1000_setup_interrupt_handler(${rtx_ether_ctx});
-                if (error)
-                {
-                        return error;
-                }
-        }
-    }
-
-    template sequence   free_interrupt_handler(Ethernet::Device rtx_ether_ctx)
-    {
-        chunk   prototypes()
-        {
-            static void e1000_free_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx);
-        }
-
-        chunk code()
-        {
-            static void e1000_free_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx)
-            {
-                free_irq(rtx_ether_ctx->hw_ctx.irq, rtx_ether_ctx);
-            }
-        }
-
-        chunk ::CALL()
-        {
-            e1000_free_interrupt_handler(${rtx_ether_ctx});
-        }
-    }
-
     template sequence   activate_device_interruption(Ethernet::Device rtx_ether_ctx)
     {
         chunk  ::CALL()
diff --git a/rathaxes/samples/e1000/e1000.rti b/rathaxes/samples/e1000/e1000.rti
--- a/rathaxes/samples/e1000/e1000.rti
+++ b/rathaxes/samples/e1000/e1000.rti
@@ -13,8 +13,7 @@
         /* Callbacks/Hooks which should probably be in the front-end: */
         chunk       Ethernet::adapter_init_context(Ethernet::Device,
                                                    Builtin::number,
-                                                   Builtin::symbol,
-                                                   Builtin::number);
+                                                   Builtin::symbol);
         chunk       Ethernet::adapter_reset(Ethernet::Device);
         chunk       Ethernet::adapter_load_mac_address(Ethernet::Device);
     }
@@ -85,21 +84,6 @@
         provided chunk  ::CALL();
     }
 
-    provided sequence   setup_interrupt_handler(Ethernet::Device)
-    {
-        provided chunk  LKM::includes(); // works without this one
-        provided chunk  LKM::prototypes();
-        provided chunk  LKM::code();
-        provided chunk  ::CALL();
-    }
-
-    provided sequence   free_interrupt_handler(Ethernet::Device)
-    {
-        provided chunk  LKM::prototypes();
-        provided chunk  LKM::code();
-        provided chunk  ::CALL();
-    }
-
     provided sequence   activate_device_interruption(Ethernet::Device)
     {
         provided chunk  ::CALL();
diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt
--- a/rathaxes/samples/e1000/ethernet.blt
+++ b/rathaxes/samples/e1000/ethernet.blt
@@ -1,4 +1,4 @@
-with Ethernet, PCI, LKM, Log
+with Ethernet, PCI, LKM, Log, Builtin
 {
     template type   Ethernet::ProtocolId()
     {
@@ -61,7 +61,9 @@
 
         map
         {
-            netdev:   ${self}->ndev;
+            netdev: ${self}->ndev;
+            /* This could be another init method for Ethernet::Device: */
+            rtx_ether_ctx: netdev_priv(&${self}->ndev);
         }
     }
 
@@ -106,11 +108,17 @@
             net_device: ${self}->net_dev;
             perm_addr: ${self}->net_dev->ndev.perm_addr;
             dev_addr: ${self}->net_dev->ndev.dev_addr;
+            irq: ${self}->pci_dev->data.irq;
         }
     }
 
     template sequence   Ethernet::open(Ethernet::Device dev)
     {
+        chunk   LKM::includes()
+        {
+            #include <linux/interrupt.h>
+        }
+
         chunk LKM::prototypes()
         {
             static int  rtx_ethernet_open(struct net_device *);
@@ -122,6 +130,20 @@
             {
                 ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev);
 
+                int error;
+                {
+                    ${Log::info("installing the interrupt handler")};
+                }
+                error = request_irq(${local.rtx_ether_ctx.irq},
+                                    rtx_ethernet_interrupt_handler,
+                                    IRQF_SHARED,
+                                    ${config.name},
+                                    dev);
+                if (error)
+                {
+                    ${Log::info("Cannot register the interrupt handler")};
+                    return error;
+                }
                 ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)};
 
                 return 0;
@@ -161,7 +183,15 @@
             {
                 ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev);
 
-                ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)};
+                /* TODO: change this pointcut into a pointcut/adapter/callback: */
+                {
+                    ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)};
+                }
+
+                free_irq(${local.rtx_ether_ctx.irq}, dev);
+                {
+                    ${Log::info("interrupt handler free'ed")};
+                }
 
                 return 0;
             }
@@ -183,7 +213,9 @@
         {
             static enum irqreturn   rtx_ethernet_interrupt_handler(int irq, void *dev_id)
             {
-                ${Ethernet::Device.ref} rtx_ether_ctx = dev_id;
+                ${Ethernet::AbstractDevice.ref} rtx_net_dev = dev_id;
+                ${Ethernet::Device.ref} rtx_ether_ctx;
+                rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx};
 
                 ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)};
 
@@ -260,13 +292,10 @@
              */
             int bars = ${rtx_pci_dev.bars};
             unsigned char /* __iomem */ *ioaddr = ${rtx_pci_dev.ioaddr};
-            int irq = ${rtx_pci_dev.irq};
             ${cast local.bars as Builtin::number};
-            ${cast local.irq as Builtin::number};
             ${pointcut Ethernet::adapter_init_context(local.rtx_ether_ctx,
                                                       local.bars,
-                                                      local.ioaddr,
-                                                      local.irq)};
+                                                      local.ioaddr)};
             ${pointcut Ethernet::adapter_reset(local.rtx_ether_ctx)};
             ${pointcut Ethernet::adapter_load_mac_address(local.rtx_ether_ctx)};
             memcpy(${local.rtx_ether_ctx.perm_addr},
diff --git a/rathaxes/samples/e1000/ethernet.rti b/rathaxes/samples/e1000/ethernet.rti
--- a/rathaxes/samples/e1000/ethernet.rti
+++ b/rathaxes/samples/e1000/ethernet.rti
@@ -18,6 +18,11 @@
         chunk       LKM::includes();
         decl        data_types();
         attribute   Builtin::symbol.scalar netdev;
+        /*
+         * XXX: should be a Ethernet::Device, but that causes a circular
+         * dependency:
+         */
+        attribute   Builtin::symbol.scalar rtx_ether_ctx;
     }
 
     provided type   Device
@@ -34,12 +39,14 @@
          * I'd like to use better names here, but I'd like to understand the
          * difference between the two first:
          */
-        attribute   Builtin::symbol.ref perm_addr;
-        attribute   Builtin::symbol.ref dev_addr;
+        attribute   Builtin::symbol.ref     perm_addr;
+        attribute   Builtin::symbol.ref     dev_addr;
+        attribute   Builtin::symbol.scalar  irq;
     }
 
     required sequence   open(Ethernet::Device)
     {
+        provided chunk  LKM::includes();
         provided chunk  LKM::prototypes();
         provided chunk  LKM::code();
     }
@@ -69,8 +76,7 @@
 
         provided pointcut   Ethernet::adapter_init_context(Ethernet::Device,
                                                            Builtin::number,
-                                                           Builtin::symbol,
-                                                           Builtin::number);
+                                                           Builtin::symbol);
         provided pointcut   Ethernet::adapter_reset(Ethernet::Device);
         provided pointcut   Ethernet::adapter_load_mac_address(Ethernet::Device);
     }
diff --git a/rathaxes/samples/e1000/lkm.rtx b/rathaxes/samples/e1000/lkm.rtx
--- a/rathaxes/samples/e1000/lkm.rtx
+++ b/rathaxes/samples/e1000/lkm.rtx
@@ -4,13 +4,6 @@
     {
         Log::info("opening the device");
 
-        /*
-         * Maybe e1000::create_device should be called from here, to be
-         * more coherent.
-         */
-
-        e1000::setup_interrupt_handler(dev);
-        Log::info("interrupt handler installed");
 
         e1000::set_up_device(dev);
         Log::info("device activated");
@@ -32,9 +25,6 @@
          */
         e1000::free_rx_tx(dev);
         Log::info("free'ed up rx/tx resources");
-
-        e1000::free_interrupt_handler(dev);
-        Log::info("interrupt handler free'ed");
     }
 
     Ethernet::interrupt_handler(Ethernet::Device dev)