# HG changeset patch # User Louis Opter # Date 1390183997 28800 # Node ID ab3a2aa22f952c36d833cc42ea42f00cff6a7edc # Parent 6527e078252cf0ceb21afe38c4c25fb18a591d85 Wip on cleaning up the existing code, now starting to build with gcc diff -r 6527e078252c -r ab3a2aa22f95 rathaxes_sample_e1000_rewrite_device_dependent_code.patch --- a/rathaxes_sample_e1000_rewrite_device_dependent_code.patch Sun Jan 19 13:45:30 2014 -0800 +++ b/rathaxes_sample_e1000_rewrite_device_dependent_code.patch Sun Jan 19 18:13:17 2014 -0800 @@ -6,7 +6,7 @@ new file mode 100644 --- /dev/null +++ b/notes.txt -@@ -0,0 +1,52 @@ +@@ -0,0 +1,54 @@ +Remarks for David & Lionel: + +- Too much changes to not start over; @@ -32,7 +32,9 @@ + susystem are going to expose the same pointcuts that can be used by the + Ethernet subsystem); +- The compiler adds a & when I try to expand e1000::Context.io_addr regardless -+ of whether the attribute is declared as Builtin::symbol.ref or .scalar. ++ of whether the attribute is declared as Builtin::symbol.ref or .scalar; ++- No understanding of arrays, e.g: ${local.self.ring.buffs[local.i].sk_buffs} ++ (I'm not saying this is the right syntax). + +Todo/Totry: + @@ -74,7 +76,7 @@ diff --git a/rathaxes/samples/e1000/CMakeLists.txt b/rathaxes/samples/e1000/CMakeLists.txt --- a/rathaxes/samples/e1000/CMakeLists.txt +++ b/rathaxes/samples/e1000/CMakeLists.txt -@@ -17,9 +17,9 @@ +@@ -17,8 +17,8 @@ dma.blt pci.blt socket.blt @@ -83,12 +85,8 @@ + ethernet.blt + e1000.blt) --IF (LINUX_KBUILD_DIR) -- ADD_RATHAXES_LKM(e1000 e1000_src) --ENDIF (LINUX_KBUILD_DIR) -+#IF (LINUX_KBUILD_DIR) -+# ADD_RATHAXES_LKM(e1000 e1000_src) -+#ENDIF (LINUX_KBUILD_DIR) + IF (LINUX_KBUILD_DIR) + ADD_RATHAXES_LKM(e1000 e1000_src) 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 @@ -694,7 +692,7 @@ { E1000_TXD_DTYP_D = 0x00100000, /* Data Descriptor */ E1000_TXD_DTYP_C = 0x00000000, /* Context Descriptor */ -@@ -701,326 +140,703 @@ +@@ -701,326 +140,721 @@ } } @@ -1016,7 +1014,7 @@ + { + ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx; + rtx_e1000_reg_write32( -+ hw_ctx, ++ ${local.hw_ctx}, + E1000_IMS, + E1000_INTR_TXDW|E1000_INTR_TXQE|E1000_INTR_LSC| + E1000_INTR_RXO|E1000_INTR_RXT0 @@ -1026,7 +1024,7 @@ + // be done right after we enabled interrupts when this was + // still in lkm.rtx): + // XXX #46: ${local.hw_ctx.print_status()}; -+ rtx_e1000_print_status(hw_ctx); ++ rtx_e1000_print_status(${local.hw_ctx}); + } + } + @@ -1080,7 +1078,12 @@ + + chunk Ethernet::adapter_free_rx_tx(Ethernet::Device rtx_ether_ctx) + { ++ ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx; ++ + { ${Log::info("adapter_free_rx_tx: TBD..")}; } ++ ++ rtx_e1000_rx_ring_free_resources(${local.hw_ctx.rx_ring}); ++ rtx_e1000_tx_ring_free_ressources(${local.hw_ctx.tx_ring}); + } + + method print_status() @@ -1194,8 +1197,6 @@ + static int rtx_e1000_rx_ring_alloc_resources(${e1000::RxRing.ref} self) { - iowrite32(value, ctx->ioaddr + reg_offset); -+ // XXX Reread & Fix everything down there (data structure changes and so on) -+ + // 4. Setup the receive descriptor ring + + int i; @@ -1211,43 +1212,61 @@ + goto err_rx_ring_alloc; + } + -+ // XXX The generated code is completely scrambled if this is -+ // not scoped: ++ // XXX The generated code is totally wrong if this is not scoped: + { ${Log::info("adapter_init_rx: rx descriptors allocated")}; } + + // Allocate the skbuffs, map them for DMA, and write their address + // in the corresponding descriptor. -+// for (i = 0; i != ${config.rx_ring_size}; ++i) { -+// ${Socket::SKBuff.ref} skbuff = &hw_ctx->rx_ring.skbuffs[i]; -+// // XXX #46: ${rtx_ether_ctx.alloc_rx_skbuff(local.skbuff, config.rx_buffer_len)}; -+// if (rtx_ethernet_alloc_rx_skbuff(ocal.skbuff, ${config.rx_buffer_len})) { -+// ${Log::info("adapter_init_rx: cannot allocate a skbuff for the rx ring")}; -+// goto err_skbuffs_alloc; -+// } -+// /* TODO: recuperer le dma handle et le placer correctement dans le descripteur. */ -+// ${DMA::map(rtx_ether_ctx.device, local.skbuff.data, local.skbuff.len, RTX_DMA_FROM_DEVICE)} -+// if (${DMA::map(rtx_ether_ctx.device, local.skbuff.data, local.skbuff.len, RTX_DMA_FROM_DEVICE)}) { -+// ${Log::info("adapter_init_rx: cannot dma-map a skbuff for the rx ring")}; -+// goto err_skbuffs_map; -+// } -+// hw_ctx->rx_ring.base[i].buff_addr = cpu_to_le64(${local.skbuff.sk_buff}); -+// } ++ for (i = 0; i != ${config.rx_ring_size}; ++i) { ++ // XXX No support for arrays: ++ ${e1000::Buffer.ref} buff = &${local.self.buffs}[i]; ++ // XXX #46: ${rtx_ether_ctx.alloc_rx_skbuff(local.buff.skbuff, config.rx_buffer_len)}; ++ if (rtx_ethernet_alloc_rx_skbuff(&${local.buff.sk_buff}, ${config.rx_buffer_len})) { ++ ${Log::info("adapter_init_rx: cannot allocate a skbuff for the rx ring")}; ++ goto err_skbuffs_alloc; ++ } ++ // XXX I couldn't manage to get this call working: ++ //${local.buff.dma.dma_handle} = ${DMA::map( ++ // local.self.hw_ctx.net_dev.device, local.buff.sk_buff.data, ++ // config.rx_buffer_len, RTX_DMA_FROM_DEVICE ++ //)}; ++ ${local.buff.dma.dma_handle.k_dma_handle} = dma_map_single( ++ ${local.self.hw_ctx.net_dev.device.k_device}, ${local.buff.sk_buff.data}, ++ ${config.rx_buffer_len}, RTX_DMA_FROM_DEVICE ++ ); ++ int err = ${DMA::mapping_error( ++ local.self.hw_ctx.net_dev.device, local.buff.dma.dma_handle ++ )}; ++ if (err) { ++ ${Log::info("adapter_init_rx: cannot dma-map a skbuff for the rx ring")}; ++ goto err_skbuffs_map; ++ } ++ ${local.self.descs}[i].buff_addr = cpu_to_le64(${local.buff.dma.dma_handle.k_dma_handle}); ++ } + -+ // ${Log::info("adapter_init_rx: skbuffs allocated}; -+ pr_info("rtx_e1k: adapter_init_rx: skbuffs allocated, headlen=%d", skb_headlen((struct sk_buff *)hw_ctx->rx_ring.skbuffs[i - 1].skbuff)); ++ { ${Log::info("adapter_init_rx: skbuffs allocated")}; } ++ ++ return 0; + + err_skbuffs_alloc: + while (i--) { -+// XXX ${DMA::unmap( -+// local.self.hw_ctx.net_dev.device, -+// // XXX Leaking cast because of the array: (TODO: the data structure changed) -+// *((dma_addr_t *)&(self->buffs[i].dma_handle)), -+// config.rx_buffer_len, -+// RTX_DMA_FROM_DEVICE -+// )}; ++ ${e1000::Buffer.ref} buff = &${local.self.buffs}[i]; ++ // XXX I couldn't manage to get this call working ++ //${DMA::unmap( ++ // local.self.hw_ctx.net_dev.device, ++ // local.buff.dma.dma_handle, ++ // config.rx_buffer_len, ++ // RTX_DMA_FROM_DEVICE ++ //)}; ++ dma_unmap_single( ++ ${local.self.hw_ctx.net_dev.device.k_device}, ++ ${local.buff.dma.dma_handle.k_dma_handle}, ++ ${config.rx_buffer_len}, ++ RTX_DMA_FROM_DEVICE ++ ); + err_skbuffs_map: -+ // XXX leaking cast: (TODO: the data structure changed) -+ dev_kfree_skb((struct sk_buff *)hw_ctx->rx_ring.skbuffs[i].skbuff); ++ // XXX #46: ${local.buff.sk_buff.free()}; ++ dev_kfree_skb(${local.buff.sk_buff.sk_buff.k_sk_buff}); + } + + void *descs = ${local.self.descs}; @@ -1267,8 +1286,6 @@ + + static void rtx_e1000_rx_ring_configure(${e1000::RxRing.ref} self) + { -+ // XXX Reread & Fix everything down there (data structure changes and so on) -+ + // Receive initialization (section 14.4): + // + // 1. Program the receive address, in RAL/RAH; @@ -1316,15 +1333,15 @@ + // 5. Save the emplacement and the size of the ring in RDBA/RDLEN + rtx_e1000_reg_write32( + ${local.self.hw_ctx}, E1000_RDBAL, -+ ${local.self.hw_ctx}->rx_ring.dma_base & 0xffffffff ++ ${local.self.dma.dma_handle.k_dma_handle} & 0xffffffff + ); + rtx_e1000_reg_write32( + ${local.self.hw_ctx}, E1000_RDBAH, -+ ${local.self.hw_ctx}->rx_ring.dma_base >> 32 ++ ${local.self.dma.dma_handle.k_dma_handle} >> 32 + ); + rtx_e1000_reg_write32( + ${local.self.hw_ctx}, E1000_RDLEN, -+ ${local.self.hw_ctx}->rx_ring.size ++ ${local.self.size} + ); + + // 6. Setup RDH/RDT @@ -1420,8 +1437,7 @@ + + static void rtx_e1000_tx_ring_configure(${e1000::TxRing.ref} self) + { -+ // return ; XXX wtf fails with: -+ // function 'rtxPH_compile(local_node : node, compile : node, node_idx : value)' hasn't been implemented ++ ${Log::info("e1000_tx_ring_configure: TBD...")}; } } @@ -1683,8 +1699,8 @@ + + method init(Socket::SKBuff, DMA::DMAHandle); + -+ attribute Socket::SKBuff.ref sk_buff; -+ attribute DMA::DMAHandle.ref dma; ++ attribute Socket::SKBuff.scalar sk_buff; ++ attribute DMA::DMAHandle.scalar dma; } - provided type TxDescriptor @@ -2690,7 +2706,7 @@ } chunk LKM::code() -@@ -52,98 +48,29 @@ +@@ -52,96 +48,32 @@ * arguments yet. */ pr_info( @@ -2779,7 +2795,8 @@ } - method map_to(Device::AbstractDevice dev) -- { ++ method free() + { - rtx_socket_skbuff_map(${self}, ${dev}, RTX_DMA_TO_DEVICE); - } - @@ -2796,12 +2813,11 @@ - method unmap_from_and_free(Device::AbstractDevice dev) - { - rtx_socket_skbuff_unmap_and_free(${self}, ${dev}, RTX_DMA_FROM_DEVICE); -- } -- ++ dev_kfree_skb(${self.sk_buff.k_sk_buff}); + } + map - { - // Some work may have to be done here in order to access to some -@@ -151,13 +78,9 @@ +@@ -151,13 +83,9 @@ // management can be abstracted from the user. But this is at least // useful for internal use: sk_buff: (${self})->skbuff; @@ -2813,15 +2829,15 @@ - dma_handle: (*((dma_addr_t *)&(${self})->dma_handle)); - size: (${self})->size; + -+ data: ((struct sk_buff *)((${self})->sk_buff))->data; -+ len: ((struct sk_buff *)((${self})->sk_buff))->len; ++ data: ((struct sk_buff *)((${self})->skbuff))->data; ++ len: ((struct sk_buff *)((${self})->skbuff))->len; } } } diff --git a/rathaxes/samples/e1000/socket.rti b/rathaxes/samples/e1000/socket.rti --- a/rathaxes/samples/e1000/socket.rti +++ b/rathaxes/samples/e1000/socket.rti -@@ -12,20 +12,14 @@ +@@ -12,20 +12,15 @@ { chunk LKM::prototypes(); chunk LKM::code(); @@ -2839,6 +2855,7 @@ - method map_from(Device::AbstractDevice); - method unmap_to_and_free(Device::AbstractDevice); - method unmap_from_and_free(Device::AbstractDevice); ++ method free(); - attribute Socket::AbstractSKBuff.ref sk_buff; - attribute DMA::AbstractDMAHandle.scalar dma_handle;