changeset 96:3e715b3e0ecd

Start a series to cleanup/refactor the e1000 sample a little bit
author Louis Opter <louis@lse.epita.fr>
date Sun, 18 Nov 2012 02:19:07 +0100
parents 4e7107e284de
children ffdb018893e2
files rathaxes_remove_useless_xmit_tso_cksum_offload_method_from_e1000.patch rathaxes_rename_pci_device_to_pci_abstractdevice.patch rathaxes_rewrite_create_and_destroy_device_in_the_e1000_sample.patch series
diffstat 4 files changed, 435 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rathaxes_remove_useless_xmit_tso_cksum_offload_method_from_e1000.patch	Sun Nov 18 02:19:07 2012 +0100
@@ -0,0 +1,40 @@
+# HG changeset patch
+# Parent 73167fa965b16dfafac934b854f0d862eb8749ad
+rathaxes: remove an useless sequence in the e1000 sample
+
+The provided sequence e1000::_xmit_tso_cksum_offload has been replaced
+by a method of the TxRing type template.
+
+
+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
+@@ -1101,13 +1101,6 @@
+         }
+     }
+ 
+-    template sequence   e1000::_xmit_tso_cksum_offload(Ethernet::Device ctx, Socket::SKBuff skb)
+-    {
+-        chunk   ::CALL()
+-        {
+-        }
+-    }
+-
+     template sequence   e1000::xmit(Ethernet::Device ctx, Socket::AbstractSKBuff kernel_skb)
+     {
+         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
+@@ -134,11 +134,6 @@
+         provided chunk  ::CALL();
+     }
+ 
+-    provided sequence   _xmit_tso_cksum_offload(Ethernet::Device, Socket::SKBuff)
+-    {
+-        provided chunk  ::CALL();
+-    }
+-
+     provided sequence   xmit(Ethernet::Device, Socket::AbstractSKBuff)
+     {
+         provided chunk  ::CALL();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rathaxes_rename_pci_device_to_pci_abstractdevice.patch	Sun Nov 18 02:19:07 2012 +0100
@@ -0,0 +1,199 @@
+# HG changeset patch
+# Parent 71f853429e57cb8926fb03e2cacf04a45ad4e8dd
+rathaxes: rename PCI::Device to PCI::AbstractDevice in the e1000 sample
+
+To respect my "new" convention of prefixing Rathaxes types that just map
+types from the kernel with "Abstract".
+
+
+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
+@@ -479,7 +479,7 @@
+ 
+     template sequence   e1000::create_device()
+     {
+-        chunk Ethernet::create_device(PCI::Device pdev, Ethernet::Device rtx_ether_ctx)
++        chunk Ethernet::create_device(PCI::AbstractDevice pdev, Ethernet::Device rtx_ether_ctx)
+         {
+             /*
+              * PCI init stuff:
+@@ -547,7 +547,7 @@
+ 
+     template sequence   e1000::destroy_device()
+     {
+-        chunk   Ethernet::destroy_device(PCI::Device pdev, Ethernet::Device rtx_ether_ctx)
++        chunk   Ethernet::destroy_device(PCI::AbstractDevice pdev, Ethernet::Device rtx_ether_ctx)
+         {
+             /*
+              * Here, we should have some checks to avoid to free resources that
+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
+@@ -78,13 +78,13 @@
+ 
+     provided sequence   create_device()
+     {
+-        provided chunk  Ethernet::create_device(PCI::Device, Ethernet::Device);
++        provided chunk  Ethernet::create_device(PCI::AbstractDevice, Ethernet::Device);
+         provided chunk  ::CALL();
+     }
+ 
+     provided sequence   destroy_device()
+     {
+-        provided chunk  Ethernet::destroy_device(PCI::Device, Ethernet::Device);
++        provided chunk  Ethernet::destroy_device(PCI::AbstractDevice, 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
+@@ -86,7 +86,7 @@
+             typedef struct rtx_ethernet_dev
+             {
+                 /*
+-                 * I think it's useless to use the ${PCI::Device} "abstraction"
++                 * I think it's useless to use the ${PCI::AbstractDevice} "abstraction"
+                  * here, since we already are in a Linux specific context.
+                  */
+                 struct pci_dev          *pci_dev;
+@@ -100,7 +100,7 @@
+             } *rtx_ethernet_dev_p;
+         }
+ 
+-        chunk ::init(Ethernet::AbstractDevice net_dev, PCI::Device pci_dev)
++        chunk ::init(Ethernet::AbstractDevice net_dev, PCI::AbstractDevice pci_dev)
+         {
+             ${self} = netdev_priv(${net_dev});
+             /*
+@@ -211,7 +211,7 @@
+         }
+ 
+         /* For now the type is not handled, so we just omit it (see #17) */
+-        chunk PCI::pci_probe_hook(PCI::Device pdev)
++        chunk PCI::pci_probe_hook(PCI::AbstractDevice pdev)
+         {
+             /*
+              * This typedef is needed to workaround a bug in CNorm __std__
+@@ -262,7 +262,7 @@
+ 
+     template sequence   Ethernet::exit()
+     {
+-        chunk   PCI::pci_remove_hook(PCI::Device pdev)
++        chunk   PCI::pci_remove_hook(PCI::AbstractDevice pdev)
+         {
+             /* workaround for cnorm unstrict */
+             struct net_device *net_dev = pci_get_drvdata(${pdev});
+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
+@@ -17,16 +17,11 @@
+         method      decl();
+     }
+ 
+-    /*
+-     * Unlike PCI::Device, Ethernet::Device doesn't match the struct net_device
+-     * from Linux. Ethernet::Device is the type that we use in the private
+-     * field of the struct net_device.
+-     */
+     provided type   Device
+     {
+         chunk       LKM::includes();
+         method      decl();
+-        method      init(Ethernet::AbstractDevice, PCI::Device);
++        method      init(Ethernet::AbstractDevice, PCI::AbstractDevice);
+         pointcut    Ethernet::SubContext();
+     }
+ 
+@@ -57,15 +52,15 @@
+     provided sequence   init()
+     {
+         provided chunk  LKM::data();
+-        provided chunk  PCI::pci_probe_hook(PCI::Device);
++        provided chunk  PCI::pci_probe_hook(PCI::AbstractDevice);
+ 
+-        provided pointcut   Ethernet::create_device(PCI::Device, Ethernet::Device);
++        provided pointcut   Ethernet::create_device(PCI::AbstractDevice, Ethernet::Device);
+     }
+ 
+     provided sequence   exit()
+     {
+-        provided chunk  PCI::pci_remove_hook(PCI::Device);
++        provided chunk  PCI::pci_remove_hook(PCI::AbstractDevice);
+ 
+-        provided pointcut   Ethernet::destroy_device(PCI::Device, Ethernet::Device);
++        provided pointcut   Ethernet::destroy_device(PCI::AbstractDevice, Ethernet::Device);
+     }
+ }
+diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt
+--- a/rathaxes/samples/e1000/pci.blt
++++ b/rathaxes/samples/e1000/pci.blt
+@@ -1,6 +1,6 @@
+ with PCI, LKM, Log
+ {
+-    template type   PCI::Device()
++    template type   PCI::AbstractDevice()
+     {
+         chunk   LKM::includes()
+         {
+@@ -12,7 +12,7 @@
+             struct pci_dev;
+         }
+ 
+-        chunk ::init(PCI::Device)
++        chunk ::init(PCI::AbstractDevice)
+         {
+         }
+ 
+@@ -41,7 +41,7 @@
+                     goto fail;
+ 
+                 /* Use local. to reference a local C variable: */
+-                ${cast local.pdev as PCI::Device};
++                ${cast local.pdev as PCI::AbstractDevice};
+                 ${pointcut PCI::pci_probe_hook(local.pdev)};
+ 
+                 return 0;
+@@ -68,7 +68,7 @@
+         {
+             static void rtx_pci_remove(struct pci_dev *pdev)
+             {
+-                ${cast local.pdev as PCI::Device};
++                ${cast local.pdev as PCI::AbstractDevice};
+                 ${pointcut PCI::pci_remove_hook(local.pdev)};
+ 
+                 pci_disable_device(pdev);
+diff --git a/rathaxes/samples/e1000/pci.rti b/rathaxes/samples/e1000/pci.rti
+--- a/rathaxes/samples/e1000/pci.rti
++++ b/rathaxes/samples/e1000/pci.rti
+@@ -1,10 +1,10 @@
+ interface PCI : LKM
+ {
+-    provided type   PCI::Device
++    provided type   PCI::AbstractDevice
+     {
+         chunk       LKM::includes();
+         method      decl();
+-        method      init(PCI::Device);
++        method      init(PCI::AbstractDevice);
+     }
+ 
+     required variable Builtin::number  PCI::vendor_id;
+@@ -28,7 +28,7 @@
+         provided chunk  LKM::prototypes();
+         provided chunk  LKM::code();
+ 
+-        provided pointcut   PCI::pci_probe_hook(PCI::Device);
++        provided pointcut   PCI::pci_probe_hook(PCI::AbstractDevice);
+     }
+ 
+     provided sequence   remove()
+@@ -36,6 +36,6 @@
+         provided chunk  LKM::prototypes();
+         provided chunk  LKM::code();
+ 
+-        provided pointcut   PCI::pci_remove_hook(PCI::Device);
++        provided pointcut   PCI::pci_remove_hook(PCI::AbstractDevice);
+     }
+ }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rathaxes_rewrite_create_and_destroy_device_in_the_e1000_sample.patch	Sun Nov 18 02:19:07 2012 +0100
@@ -0,0 +1,193 @@
+# HG changeset patch
+# Parent a7ba4e6eae2c9086c0b9876494165bf21ad1f405
+rathaxes: rewrite the {create,destroy}_device functions in the e1000 sample
+
+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
+@@ -1,4 +1,4 @@
+-with e1000, Ethernet, Socket, PCI, LKM, Log
++with e1000, Ethernet, Socket, PCI, LKM, Log, Builtin
+ {
+     template type   e1000::RxDescriptor()
+     {
+@@ -288,7 +288,7 @@
+             {
+                 int                         bars;
+                 unsigned char /* __iomem */ *ioaddr;
+-                int                         irq;
++                unsigned int                irq;
+ 
+                 /* we can't use the Rathaxes type here (#8) */
+                 //${e1000::RxRing}    rx_ring;
+@@ -298,8 +298,11 @@
+             };
+         }
+ 
+-        chunk   ::init()
++        chunk   ::init(Builtin::number bars, Builtin::number ioaddr, Builtin::number irq)
+         {
++            ${self}->bars = ${bars};
++            ${self}->ioaddr = ${ioaddr};
++            ${self}->irq = irq;
+         }
+ 
+         map
+@@ -479,40 +482,16 @@
+ 
+     template sequence   e1000::create_device()
+     {
+-        chunk Ethernet::create_device(PCI::AbstractDevice pdev, Ethernet::Device rtx_ether_ctx)
++        chunk Ethernet::create_device(Ethernet::Device rtx_ether_ctx,
++                                      Builtin::number bars,
++                                      Builtin::number ioaddr,
++                                      Builtin::number irq)
+         {
+-            /*
+-             * PCI init stuff:
+-             *
+-             * Some of that code should certainly be moved in the PCI/Ethernet
+-             * blts, also at some point maybe we could do that completely
+-             * automatically in the PCI/Ethernet blts.
+-             */
++            /* XXX: Use the rathaxes type directly here (#51): */
++            struct rtx_e1000_ctx *hw_ctx = &${rtx_ether_ctx}->hw_ctx;
++            ${cast local.hw_ctx as e1000::Context};
+ 
+-            /*
+-             * We could have used an init function here but since we can't init
+-             * all the fields at once (see, ioaddr) and cannot call a C
+-             * function within a placeholder (${}), it wasn't really worth it.
+-             */
+-            ${rtx_ether_ctx}->hw_ctx.bars = pci_select_bars(${pdev}, IORESOURCE_MEM);
+-            ${rtx_ether_ctx}->hw_ctx.irq = ${pdev}->irq;
+-
+-            if (pci_enable_device_mem(${pdev}))
+-                ${Log::info("e1000::create: pci_enable_device_mem failed")};
+-            if (pci_request_selected_regions(${pdev}, ${rtx_ether_ctx}->hw_ctx.bars, ${config.name}))
+-                ${Log::info("e1000::create: pci_request_selected_regions failed")};
+-            if (${config.set_master})
+-                pci_set_master(${pdev});
+-
+-            /* 0 here is for BAR_0: */
+-            ${rtx_ether_ctx}->hw_ctx.ioaddr = pci_ioremap_bar(${pdev}, 0);
+-            if (!${rtx_ether_ctx}->hw_ctx.ioaddr)
+-                ${Log::info("e1000::create: pci_ioremap_bar failed")};
+-
+-            /*
+-             * The really device specific algorithm starts here (so it should
+-             * certainly be written in the frontend):
+-             */
++            ${local.hw_ctx.init(bars, ioaddr, irq)};
+ 
+             /* Reset the card */
+             rtx_e1000_register_write32(&${rtx_ether_ctx}->hw_ctx, E1000_CTRL, E1000_CMD_RST);
+@@ -533,6 +512,7 @@
+                 ${rtx_ether_ctx}->net_dev->dev_addr[i * 2 + 1] = (value >> 8) & 0xff;
+             }
+ 
++            /* XXX: use ${rtx_ether_ctx.set_mac_address()}; : */
+             memcpy(${rtx_ether_ctx}->net_dev->perm_addr,
+                    ${rtx_ether_ctx}->net_dev->dev_addr,
+                    ${rtx_ether_ctx}->net_dev->addr_len);
+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
+@@ -1,8 +1,5 @@
+ interface e1000 : Socket, Ethernet, PCI, LKM, Builtin
+ {
+-    /* XXX: This should be in pci.rti, also maybe we need a bool type */
+-    required variable   Builtin::symbol set_master;
+-
+     required variable   Builtin::number rx_ring_size;
+     required variable   Builtin::number tx_ring_size;
+     required variable   Builtin::number rx_buffer_len;
+@@ -12,7 +9,8 @@
+     {
+         chunk       Ethernet::SubContext();
+         method      decl();
+-        method      init();
++        /* XXX: used types: */
++        method      init(Builtin::number, Builtin::number, Builtin::number);
+     }
+ 
+     provided type   RxDescriptor
+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
+@@ -111,6 +111,13 @@
+             ${self}->net_dev = ${net_dev};
+         }
+ 
++        chunk set_mac_address(Builtin::number addr)
++        {
++            memcpy(${self}->net_dev->perm_addr,
++                   ${self}->net_dev->dev_addr,
++                   ${self}->net_dev->addr_len);
++        }
++
+         map
+         {
+         }
+@@ -249,9 +256,26 @@
+             /* Initialize our context held by the net_device structure */
+             ${rtx_ether_ctx.init(local.net_dev, pdev)};
+ 
++            /* XXX: The following code should probably part of PCI:: */
++
+             pci_set_drvdata(${pdev}, net_dev);
+ 
+-            ${pointcut Ethernet::create_device(pdev, local.rtx_ether_ctx)};
++            int bars = pci_select_bars(${pdev}, IORESOURCE_MEM);
++
++            if (pci_enable_device_mem(${pdev}))
++                ${Log::info("pci_enable_device_mem failed")};
++            if (pci_request_selected_regions(${pdev}, bars, ${config.name}))
++                ${Log::info("pci_request_selected_regions failed")};
++            if (${config.set_master})
++                pci_set_master(${pdev});
++
++            /* 0 here is for BAR_0: */
++            unsigned char /* __iomem */ *ioaddr = pci_ioremap_bar(${pdev}, 0);
++            if (!ioaddr)
++                ${Log::info("pci_ioremap_bar failed")};
++
++            unsigned int irq = net_dev->irq;
++            ${pointcut Ethernet::create_device(local.rtx_ether_ctx, local.bars, local.ioaddr, local.irq)};
+         }
+ 
+         /* This chunk should be removed (see #26) */
+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
+@@ -1,5 +1,8 @@
+-interface Ethernet : Socket, PCI, LKM
++interface Ethernet : Socket, PCI, LKM, Builtin
+ {
++    /* XXX: This should be in pci.rti, also maybe we need a bool type */
++    required variable   Builtin::symbol set_master;
++
+     required variable   Builtin::string ifname;
+ 
+      provided type   ProtocolId
+@@ -22,6 +25,8 @@
+         chunk       LKM::includes();
+         method      decl();
+         method      init(Ethernet::AbstractDevice, PCI::AbstractDevice);
++        method      set_mac_address(Builtin::number);
++
+         pointcut    Ethernet::SubContext();
+     }
+ 
+@@ -54,7 +59,10 @@
+         provided chunk  LKM::data();
+         provided chunk  PCI::pci_probe_hook(PCI::AbstractDevice);
+ 
+-        provided pointcut   Ethernet::create_device(PCI::AbstractDevice, Ethernet::Device);
++        provided pointcut   Ethernet::create_device(Ethernet::Device,
++                                                    Builtin::number,
++                                                    Builtin::number,
++                                                    Builtin::number);
+     }
+ 
+     provided sequence   exit()
--- a/series	Mon Oct 22 02:02:22 2012 +0200
+++ b/series	Sun Nov 18 02:19:07 2012 +0100
@@ -1,3 +1,6 @@
 rathaxes_add_a_test_to_reproduce_the_pointer_to_rathaxes_bug.patch
 rathaxes_use_single_file_language_tests.patch
+rathaxes_rename_pci_device_to_pci_abstractdevice.patch
+rathaxes_remove_useless_xmit_tso_cksum_offload_method_from_e1000.patch
+rathaxes_rewrite_create_and_destroy_device_in_the_e1000_sample.patch
 rathaxes_cleanups_in_ethernet_rti_blt.patch