# HG changeset patch # User Louis Opter # Date 1326030423 -3600 # Node ID d761c8c625d39f724bcca2ad797e99a8b269b350 # Parent f43900ad7e663e2aa8237318041b2afa5dd6fd2e Try to read a register on the card diff -r f43900ad7e66 -r d761c8c625d3 rathaxes_add_lkm_ethernet_sample.patch --- a/rathaxes_add_lkm_ethernet_sample.patch Sun Jan 08 01:51:34 2012 +0100 +++ b/rathaxes_add_lkm_ethernet_sample.patch Sun Jan 08 14:47:03 2012 +0100 @@ -14,18 +14,18 @@ --- /dev/null +++ b/rathaxes/samples/lkm/CMakeLists.txt @@ -0,0 +1,7 @@ -+ADD_RATHAXES_SOURCES(lkm lkm.rtx ++ADD_RATHAXES_SOURCES(lkm_src lkm.rtx + RTI log.rti lkm.rti pci.rti socket.rti ethernet.rti e1000.rti + BLT log.blt lkm.blt pci.blt socket.blt ethernet.blt e1000.blt) + +# We can't name lkm since it's already used as the target name to generate the +# source (with ADD_RATHAXES_SOURCES). -+ADD_RATHAXES_LKM(lkm_hello lkm) ++ADD_RATHAXES_LKM(lkm lkm_src) diff --git a/rathaxes/samples/lkm/e1000.blt b/rathaxes/samples/lkm/e1000.blt new file mode 100644 --- /dev/null +++ b/rathaxes/samples/lkm/e1000.blt -@@ -0,0 +1,80 @@ +@@ -0,0 +1,170 @@ +with e1000, Ethernet, Socket, PCI, LKM, Log +{ + template type e1000::Context() @@ -38,7 +38,7 @@ + * (we hacked a bit and used it in ethernet.blt directly). + */ + typedef int ${e1000::Context}; /* CNorm __std__ workaround */ -+ ${e1000::Context} force_declaration_in_includes; ++ static const ${e1000::Context} force_struct_rtx_10000_ctx_decl; + } + + chunk ::decl() @@ -50,6 +50,45 @@ + }; + } + ++ chunk ::init(bars, ioaddr) ++ { ++ ${self}.bars = ${bars}; ++ ${self}.ioaddr = ${ioaddr}; ++ } ++ ++ map ++ { ++ } ++ } ++ ++ template type e1000::Register() ++ { ++ chunk LKM::includes() ++ { ++ typedef int ${e1000::Register}; ++ static const ${e1000::Register} force_enum_rtx_e1000_registers_decl; ++ } ++ ++ chunk ::decl() ++ { ++ enum rtx_e1000_registers ++ { ++ E1000_CTRL = 0x00000, ++ E1000_CTRL_DUP = 0x00004, ++ E1000_STATUS = 0x00008, ++ E1000_EEPROM_FLASH = 0x00010, ++ E1000_EEPROM_READ = 0x00014, ++ E1000_CTRL_EXT = 0x00018, ++ E1000_FLA = 0x0001C, ++ E1000_MDIC = 0x00020, ++ }; ++ } ++ ++ chunk ::init(value) ++ { ++ ${self} = ${value}; ++ } ++ + map + { + } @@ -81,6 +120,36 @@ + { + ${Log::info("e1000::create: pci_ioremap_bar failed")}; + } ++ ++ /* Now we can reset the card and load its mac address */ ++ ++ /* ++ * We should have been able to do something along those lines, but ++ * it didn't work so we made the call manually. ++ * ++ * Ideally: ++ * ${e1000::register_read32(rtx_ether_ctx->hw_ctx, E1000_STATUS)}; ++ * ++ * Ideally2, not sure about the syntax on the register parameter: ++ * ${e1000::register_read32(rtx_ether_ctx->hw_ctx, ${e1000::Register.E1000_STATUS})}; ++ * ++ * "Acceptable": ++ * typedef int ${e1000::Register}; // cnorm __std__ workaround ++ * ${e1000::Register} reg_status; ++ * ${e1000.init(E1000_STATUS); // didn't work, so we used the next line ++ * reg_status = E1000_STATUS; ++ * ${e1000::register_read32(rtx_ether_ctx->hw_ctx, reg_status)}; ++ * ++ */ ++ ++ unsigned int status = rtx_e1000_register_read32(&rtx_ether_ctx->hw_ctx, E1000_STATUS); ++ ++ pr_info("Status of the e1000 card:\n"); ++ pr_info("\tStatus: %i\n", status); ++ pr_info("\tMode: %s\n", (status & 1) ? "Full": "Half"); ++ pr_info("\tLink: %s\n", (status & 2) ? "UP" : "Down"); ++ pr_info("\tTransmission: %s\n", (status & 4) ? "Paused" : "Ok"); ++ pr_info("\tInterface: %s\n", (status & 3) == 3 ? "UP" : "Down"); + } + + chunk ::CALL @@ -105,15 +174,37 @@ + { + } + } ++ ++ template sequence e1000::register_read32(e1000::Context ctx, e1000::Register reg_offset) ++ { ++ chunk LKM::prototypes() ++ { ++ static unsigned int rtx_e1000_register_read32(struct rtx_e1000_ctx *, unsigned int); ++ } ++ ++ chunk LKM::code() ++ { ++ static unsigned int rtx_e1000_register_read32(struct rtx_e1000_ctx *ctx, unsigned int reg_offset) ++ { ++ return ioread32(ctx->ioaddr + reg_offset); ++ } ++ } ++ ++ chunk ::CALL() ++ { ++ rtx_e1000_register_read32(&${ctx}, ${reg_offset}); ++ } ++ } +} diff --git a/rathaxes/samples/lkm/e1000.rti b/rathaxes/samples/lkm/e1000.rti new file mode 100644 --- /dev/null +++ b/rathaxes/samples/lkm/e1000.rti -@@ -0,0 +1,24 @@ +@@ -0,0 +1,39 @@ +interface e1000 : Socket, Ethernet, PCI, LKM +{ + provided type e1000::Context; ++ provided type e1000::Register; + + /* + * This sequence should receive an argument like Ethernet::Device, but it is @@ -134,6 +225,20 @@ + provided chunk Ethernet::destroy_device; + provided chunk ::CALL; + } ++ ++ /* ++ * It should also take an e1000::Context argument as the first parameter. ++ * But we weren't able to call the sequence afterwards, with expression ++ * like: ++ * ++ * ${e1000::register_read32(rtx_ether_ctx->hw_ctx, E1000_STATUS)}; ++ */ ++ provided sequence e1000::register_read32(e1000::Context, e1000::Register) ++ { ++ provided chunk LKM::prototypes; ++ provided chunk LKM::code; ++ provided chunk ::CALL; ++ } +} diff --git a/rathaxes/samples/lkm/ethernet.blt b/rathaxes/samples/lkm/ethernet.blt new file mode 100644