comparison rathaxes_sample_e1000_rewrite_device_dependent_code.patch @ 135:9c6ae3a2e180

Wip, fixes + workarounds
author Louis Opter <kalessin@kalessin.fr>
date Sat, 11 Jan 2014 18:42:05 -0800
parents 79226bb06e6a
children 8229a46ec658
comparison
equal deleted inserted replaced
134:79226bb06e6a 135:9c6ae3a2e180
694 - decl data_types() 694 - decl data_types()
695 + decl data_types() 695 + decl data_types()
696 { 696 {
697 E1000_TXD_DTYP_D = 0x00100000, /* Data Descriptor */ 697 E1000_TXD_DTYP_D = 0x00100000, /* Data Descriptor */
698 E1000_TXD_DTYP_C = 0x00000000, /* Context Descriptor */ 698 E1000_TXD_DTYP_C = 0x00000000, /* Context Descriptor */
699 @@ -701,326 +140,683 @@ 699 @@ -701,326 +140,687 @@
700 } 700 }
701 } 701 }
702 702
703 - /* TODO: make that a method of e1000::Context */ 703 - /* TODO: make that a method of e1000::Context */
704 - template sequence e1000::print_status(Ethernet::Device rtx_ether_ctx) 704 - template sequence e1000::print_status(Ethernet::Device rtx_ether_ctx)
896 + } 896 + }
897 + 897 +
898 + chunk Ethernet::adapter_init_context(Ethernet::Device rtx_ether_ctx, Builtin::symbol io_addr) 898 + chunk Ethernet::adapter_init_context(Ethernet::Device rtx_ether_ctx, Builtin::symbol io_addr)
899 + { 899 + {
900 + { 900 + {
901 + ${e1000::Context.ref} hw_ctx = &${local.rtx_ether_ctx}->hw_ctx; 901 + ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx;
902 + ${local.hw_ctx.init(local.rtx_ether_ctx, local.io_addr)}; 902 + // XXX doesn't work: ${local.hw_ctx.init(rtx_ether_ctx, io_addr)};
903 + ${local.hw_ctx.rx_ring.init(local.hw_ctx.io, config.rx_ring_size)}; 903 + ${local.hw_ctx.net_dev} = ${rtx_ether_ctx};
904 + ${local.hw_ctx.tx_ring.init(local.hw_ctx.io, config.tx_ring_size)}; 904 + ${local.hw_ctx.io_addr} = ${io_addr};
905 + ${local.hw_ctx.rx_ring.init(local.hw_ctx, config.rx_ring_size)};
906 + ${local.hw_ctx.tx_ring.init(local.hw_ctx, config.tx_ring_size)};
905 + } 907 + }
906 + } 908 + }
907 + 909 +
908 + chunk Ethernet::adapter_reset(Ethernet::Device rtx_ether_ctx) 910 + chunk Ethernet::adapter_reset(Ethernet::Device rtx_ether_ctx)
909 + { 911 + {
910 + { 912 + {
911 + ${e1000::Context.ref} hw_ctx = &${local.rtx_ether_ctx}->hw_ctx; 913 + ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx;
912 + // XXX #46: ${local.hw_ctx.io.write32(E1000_CTRL, E1000_CMD_RST)}; 914 + // XXX #46: ${local.hw_ctx.io.write32(E1000_CTRL, E1000_CMD_RST)};
913 + rtx_e1000_reg_write32(hw_ctx, E1000_CTRL, E1000_CMD_RST); 915 + rtx_e1000_reg_write32(hw_ctx, E1000_CTRL, E1000_CMD_RST);
914 + udelay(10); // TODO: abstract udelay too... 916 + udelay(10); // TODO: abstract udelay too...
915 + ${Log::info("adapter has been reset")}; 917 + ${Log::info("adapter has been reset")};
916 + } 918 + }
917 + } 919 + }
918 + 920 +
919 + chunk Ethernet::adapter_load_mac_address(Ethernet::Device rtx_ether_ctx) 921 + chunk Ethernet::adapter_load_mac_address(Ethernet::Device rtx_ether_ctx)
920 + { 922 + {
921 + { 923 + {
922 + ${e1000::Context.ref} hw_ctx = &${local.rtx_ether_ctx}->hw_ctx; 924 + ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx;
923 + // Shamelessly borrowed from Minix 925 + // Shamelessly borrowed from Minix
924 + for (int i = 0; i < 3; ++i) { 926 + for (int i = 0; i < 3; ++i) {
925 + rtx_e1000_reg_write32(hw_ctx, E1000_EEPROM_READ, (i << 8) | 1); 927 + rtx_e1000_reg_write32(hw_ctx, E1000_EEPROM_READ, (i << 8) | 1);
926 + int value; 928 + int value;
927 + do { 929 + do {
930 + value >>= 16; 932 + value >>= 16;
931 + // NOTE: I'm not sure if Ethernet::Device should be 933 + // NOTE: I'm not sure if Ethernet::Device should be
932 + // accessed directly here. But since we need to take it in 934 + // accessed directly here. But since we need to take it in
933 + // parameter (so we can get back our e1000::Context) it 935 + // parameter (so we can get back our e1000::Context) it
934 + // seems inadequate to set this in another way: 936 + // seems inadequate to set this in another way:
935 + ${local.rtx_ether_ctx.dev_addr}[i * 2] = value & 0xff; 937 + ${rtx_ether_ctx.dev_addr}[i * 2] = value & 0xff;
936 + ${local.rtx_ether_ctx.dev_addr}[i * 2 + 1] = (value >> 8) & 0xff; 938 + ${rtx_ether_ctx.dev_addr}[i * 2 + 1] = (value >> 8) & 0xff;
937 + } 939 + }
938 + 940 +
939 + ${Log::info("mac address loaded from the EEPROM")}; 941 + ${Log::info("mac address loaded from the EEPROM")};
940 + } 942 + }
941 + } 943 + }
944 + // Controller Software Developper manual. (You can find it in the 946 + // Controller Software Developper manual. (You can find it in the
945 + // doc/hardware directory). 947 + // doc/hardware directory).
946 + chunk Ethernet::adapter_setup_rx_tx(Ethernet::Device rtx_ether_ctx) 948 + chunk Ethernet::adapter_setup_rx_tx(Ethernet::Device rtx_ether_ctx)
947 + { 949 + {
948 + { 950 + {
949 + ${e1000::Context.ref} hw_ctx = &${local.rtx_ether_ctx}->hw_ctx; 951 + ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx;
950 + 952 +
951 + // "General Configuration" (section 14.3): 953 + // "General Configuration" (section 14.3):
952 + // 954 + //
953 + // - CTRL.ASDE/CTRL.SLU: Let the PHY handle the speed detection & 955 + // - CTRL.ASDE/CTRL.SLU: Let the PHY handle the speed detection &
954 + // negociation; 956 + // negociation;
999 + } 1001 + }
1000 + 1002 +
1001 + chunk Ethernet::adapter_enable_interrupts(Ethernet::Device) 1003 + chunk Ethernet::adapter_enable_interrupts(Ethernet::Device)
1002 + { 1004 + {
1003 + { 1005 + {
1004 + ${e1000::Context.ref} hw_ctx = &${local.rtx_ether_ctx}->hw_ctx; 1006 + ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx;
1005 + rtx_e1000_reg_write32( 1007 + rtx_e1000_reg_write32(
1006 + hw_ctx, 1008 + hw_ctx,
1007 + E1000_IMS, 1009 + E1000_IMS,
1008 + E1000_INTR_TXDW|E1000_INTR_TXQE|E1000_INTR_LSC| 1010 + E1000_INTR_TXDW|E1000_INTR_TXQE|E1000_INTR_LSC|
1009 + E1000_INTR_RXO|E1000_INTR_RXT0 1011 + E1000_INTR_RXO|E1000_INTR_RXT0
1023 + } 1025 + }
1024 + 1026 +
1025 + chunk Ethernet::adapter_handle_interrupt(Ethernet::Device rtx_ether_ctx) 1027 + chunk Ethernet::adapter_handle_interrupt(Ethernet::Device rtx_ether_ctx)
1026 + { 1028 + {
1027 + { 1029 + {
1028 + ${e1000::Context.ref} hw_ctx = &${local.rtx_ether_ctx}->hw_ctx; 1030 + ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx;
1029 + unsigned int icr = rtx_e1000_reg_read32(hw_ctx, E1000_ICR); 1031 + unsigned int icr = rtx_e1000_reg_read32(hw_ctx, E1000_ICR);
1030 + pr_info("%s: interrupt received, ICR: 0x%x", ${config.name}, icr); 1032 + pr_info("%s: interrupt received, ICR: 0x%x", ${config.name}, icr);
1031 + if (icr) { 1033 + if (icr) {
1032 + if (icr & E1000_INTR_LSC) { 1034 + if (icr & E1000_INTR_LSC) {
1033 + ${Log::info("handle_interrupt: cable link status changed, dumping card status:")}; 1035 + ${Log::info("handle_interrupt: cable link status changed, dumping card status:")};
1207 +// if (rtx_ethernet_alloc_rx_skbuff(ocal.skbuff, ${config.rx_buffer_len})) { 1209 +// if (rtx_ethernet_alloc_rx_skbuff(ocal.skbuff, ${config.rx_buffer_len})) {
1208 +// ${Log::info("adapter_init_rx: cannot allocate a skbuff for the rx ring")}; 1210 +// ${Log::info("adapter_init_rx: cannot allocate a skbuff for the rx ring")};
1209 +// goto err_skbuffs_alloc; 1211 +// goto err_skbuffs_alloc;
1210 +// } 1212 +// }
1211 +// /* TODO: recuperer le dma handle et le placer correctement dans le descripteur. */ 1213 +// /* TODO: recuperer le dma handle et le placer correctement dans le descripteur. */
1212 +// ${DMA::map(local.rtx_ether_ctx.device, local.skbuff.data, local.skbuff.len, RTX_DMA_FROM_DEVICE)} 1214 +// ${DMA::map(rtx_ether_ctx.device, local.skbuff.data, local.skbuff.len, RTX_DMA_FROM_DEVICE)}
1213 +// if (${DMA::map(local.rtx_ether_ctx.device, local.skbuff.data, local.skbuff.len, RTX_DMA_FROM_DEVICE)}) { 1215 +// if (${DMA::map(rtx_ether_ctx.device, local.skbuff.data, local.skbuff.len, RTX_DMA_FROM_DEVICE)}) {
1214 +// ${Log::info("adapter_init_rx: cannot dma-map a skbuff for the rx ring")}; 1216 +// ${Log::info("adapter_init_rx: cannot dma-map a skbuff for the rx ring")};
1215 +// goto err_skbuffs_map; 1217 +// goto err_skbuffs_map;
1216 +// } 1218 +// }
1217 +// hw_ctx->rx_ring.base[i].buff_addr = cpu_to_le64(${local.skbuff.sk_buff}); 1219 +// hw_ctx->rx_ring.base[i].buff_addr = cpu_to_le64(${local.skbuff.sk_buff});
1218 +// } 1220 +// }
1333 1335
1334 - chunk ::CALL() 1336 - chunk ::CALL()
1335 + method init(e1000::Context hw_ctx, Builtin::number desc_count) 1337 + method init(e1000::Context hw_ctx, Builtin::number desc_count)
1336 { 1338 {
1337 - rtx_e1000_register_write32(${ctx}, ${reg_offset}, ${value}); 1339 - rtx_e1000_register_write32(${ctx}, ${reg_offset}, ${value});
1338 + ${self.ring.init(hw_ctx, desc_count, self.desc_size)}; 1340 + // XXX doesn't work: ${self.ring.init(hw_ctx, desc_count, self.desc_size)};
1341 + rtx_e1000_ring_init(&${self}, ${hw_ctx}, ${desc_count}, ${self.desc_size});
1339 + } 1342 + }
1340 + 1343 +
1341 + method alloc() 1344 + method alloc()
1342 + { 1345 + {
1343 + rtx_e1000_rx_ring_alloc_resources(${self}); 1346 + rtx_e1000_rx_ring_alloc_resources(${self});
1418 - { 1421 - {
1419 - chunk LKM::prototypes() 1422 - chunk LKM::prototypes()
1420 - { 1423 - {
1421 - /* FIXME: See issue #54 */ 1424 - /* FIXME: See issue #54 */
1422 - static void rtx_e1000_register_unset32(/*const*/ ${e1000::Context.ref}, unsigned int, unsigned int); 1425 - static void rtx_e1000_register_unset32(/*const*/ ${e1000::Context.ref}, unsigned int, unsigned int);
1423 + ${self.ring.init(hw_ctx, desc_count, self.desc_size)}; 1426 + // XXX doesn't work: ${self.ring.init(hw_ctx, desc_count, self.desc_size)};
1427 + rtx_e1000_ring_init(&${self}, ${hw_ctx}, ${desc_count}, ${self.desc_size});
1424 } 1428 }
1425 1429
1426 - chunk LKM::code() 1430 - chunk LKM::code()
1427 + method alloc() 1431 + method alloc()
1428 { 1432 {