Mercurial > archived > louis > epitech > mq > rathaxes
annotate e1000_initialize_reception.patch @ 80:0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
author | Louis Opter <louis@lse.epitech.net> |
---|---|
date | Sun, 15 Apr 2012 02:53:38 +0200 |
parents | f07f6c6d6cd4 |
children |
rev | line source |
---|---|
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
1 # HG changeset patch |
80
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
2 # Parent d8fce7ee2b630bf8bd681fa4d66832b82c5e6de2 |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
3 rathaxes: initialize reception on the e1000 sample: |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
4 |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
5 - This is documented in details in the sections 14.4 and 3.2 of the |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
6 Intel Gigabit Controller Software Developer manual; |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
7 - "Address filtering" is set up, address filters just tell the hardware |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
8 which packets they should accept (unicast/multicast/vlan/promisc), we |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
9 simply configure the hardware to accept packet for its own mac |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
10 address (receive address); |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
11 - It involves setting up a ring of receive descriptors (their format is |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
12 documented in section 3.2.3) and an internal data structure to keep |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
13 track of the ring; |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
14 - Each descriptor of the ring correspond to an skbuff (skbuff are |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
15 allocated individually). |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
16 |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
17 diff --git a/rathaxes/samples/e1000/e1000.blt b/rathaxes/samples/e1000/e1000.blt |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
18 --- a/rathaxes/samples/e1000/e1000.blt |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
19 +++ b/rathaxes/samples/e1000/e1000.blt |
79 | 20 @@ -1,5 +1,81 @@ |
21 with e1000, Ethernet, Socket, PCI, LKM, Log | |
22 { | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
23 + template type e1000::RxDescriptor() |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
24 + { |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
25 + chunk LKM::includes() |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
26 + { |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
27 + typedef int ${e1000::RxDescriptor}; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
28 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
29 + #include <linux/types.h> |
79 | 30 + |
31 + static const ${e1000::RxDescriptor} force_rtx_e1000_rx_descriptor_decl; | |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
32 + } |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
33 + |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
34 + chunk ::decl() |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
35 + { |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
36 + typedef struct rtx_e1000_rx_descriptor |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
37 + { |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
38 + /* actual types are in comments */ |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
39 + unsigned long int /* __le64 */ buff_addr; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
40 + unsigned short /* __le16 */ length; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
41 + unsigned short /* __le16 */ csum; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
42 + unsigned char status; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
43 + unsigned char errors; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
44 + unsigned short /* __le16 */ special; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
45 + } *rtx_e1000_rx_descriptor_p; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
46 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
47 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
48 + chunk ::init() |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
49 + { |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
50 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
51 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
52 + map |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
53 + { |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
54 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
55 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
56 + |
79 | 57 + /* |
58 + * Ring of e1000::RxDescriptors and their corresponding skbuffs. | |
59 + * | |
60 + * - size: total size of the ring in bytes. | |
61 + * - base: address of the ring (we can't use the typedef here until we get | |
62 + * CNorm unstrict); | |
63 + * - dma_base: (physical) address of the ring where the device can access | |
64 + * the different descriptors; | |
65 + * - skbuffs: array of the skbuffs associated with each descriptor; | |
66 + * - dma_skbuffs: (physical) address of each skbuff where the device can | |
67 + * write the received packets; | |
68 + */ | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
69 + template type e1000::RxRing() |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
70 + { |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
71 + chunk LKM::includes() |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
72 + { |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
73 + typedef int ${e1000::RxRing}; |
79 | 74 + |
75 + static const ${e1000::RxRing} force_rtx_e1000_rx_ring_decl; | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
76 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
77 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
78 + chunk ::decl() |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
79 + { |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
80 + struct rtx_e1000_rx_ring |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
81 + { |
79 | 82 + unsigned int size; |
83 + struct rtx_e1000_rx_descriptor *base; | |
84 + void* /* dma_addr_t */ dma_base; | |
85 + struct sk_buff *skbuffs[256 /* ${config.rx_ring_size} */]; | |
86 + void* /* dma_addr_t */ dma_skbuffs[256 /* ${config.rx_ring_size} */]; | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
87 + }; |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
88 + } |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
89 + |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
90 + chunk ::init() |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
91 + { |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
92 + } |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
93 + |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
94 + map |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
95 + { |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
96 + } |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
97 + } |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
98 + |
79 | 99 template type e1000::Context() |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
100 { |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
101 chunk LKM::includes() |
79 | 102 @@ -21,9 +97,12 @@ |
103 */ | |
104 typedef struct rtx_e1000_ctx | |
105 { | |
106 - int bars; | |
107 - unsigned char /* __iomem */ *ioaddr; | |
108 - int irq; | |
109 + int bars; | |
110 + unsigned char /* __iomem */ *ioaddr; | |
111 + int irq; | |
112 + | |
113 + /* we can't use the Rathaxes type here (#8) */ | |
114 + struct rtx_e1000_rx_ring rx_ring; | |
115 } *rtx_e1000_ctx_p; | |
116 } | |
117 | |
118 @@ -34,6 +113,7 @@ | |
119 map | |
120 { | |
121 } | |
122 + | |
123 } | |
124 | |
125 template type e1000::Register() | |
126 @@ -64,6 +144,9 @@ | |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
127 E1000_FCT = 0x00030, /* Flow Control Type */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
128 E1000_FCTTV = 0x00170, /* Flow Control Transmit Timer Value */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
129 E1000_CRCERRS = 0x04000, /* CRC Error Count (base address of the statistic register spaces) */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
130 + E1000_RAL = 0x05400, /* Receive Address Low */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
131 + E1000_RAH = 0x05404, /* Receive Address High */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
132 + E1000_MTA = 0x05200, /* Multicast Table Array */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
133 }; |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
134 } |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
135 |
79 | 136 @@ -132,7 +215,8 @@ |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
137 E1000_INTR_RXDMT0 = 0x00000010, /* rx desc min. threshold (0) */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
138 E1000_INTR_RXO = 0x00000040, /* rx overrun */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
139 E1000_INTR_RXT0 = 0x00000080, /* rx timer intr (ring 0) */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
140 - E1000_INTR_MDAC = 0x00000200 /* MDIO access complete */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
141 + E1000_INTR_MDAC = 0x00000200, /* MDIO access complete */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
142 + E1000_RAH_AV = (1 << 31), /* Set the MAC Address as Valid */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
143 }; |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
144 } |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
145 |
79 | 146 @@ -457,15 +541,27 @@ |
147 { | |
78
501bf9cf65dc
wip on e1000 add some fixes for the generation and check that it works on tip
Louis Opter <louis@lse.epitech.net>
parents:
77
diff
changeset
|
148 chunk ::CALL() |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
149 { |
79 | 150 + typedef unsigned long int dma_addr_t; |
151 + | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
152 /* |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
153 - * This is documented in the Intel Gigabit Ethernet Controller |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
154 - * Software Developper manual. |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
155 + * This part is documented in the Intel Gigabit Ethernet Controller |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
156 + * Software Developper manual. (You can find it in the doc/hardware |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
157 + * directory). |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
158 * |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
159 * Since this part is actually completely device specific it should |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
160 * not be written here. (but in the front-end). |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
161 */ |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
162 |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
163 /* |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
164 + * shortcut hw_ctx... maybe we should directly take an |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
165 + * e1000::Context? (but we would need to make it point back to |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
166 + * the struct net_device) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
167 + */ |
78
501bf9cf65dc
wip on e1000 add some fixes for the generation and check that it works on tip
Louis Opter <louis@lse.epitech.net>
parents:
77
diff
changeset
|
168 + typedef int ${e1000::Context}; |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
169 + ${e1000::Context} hw_ctx; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
170 + hw_ctx = &${ctx}->hw_ctx; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
171 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
172 + /* |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
173 * "General Configuration" (section 14.3): |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
174 * |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
175 * - CTRL.ASDE/CTRL.SLU: Let the PHY handle the speed detection & |
80
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
176 @@ -478,22 +574,181 @@ |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
177 * - Finally, initialize all the statistic registers from |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
178 * E1000_CRCERRS to E1000_TSCTFC. |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
179 */ |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
180 - rtx_e1000_register_set32(&${ctx}->hw_ctx, E1000_CTRL, |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
181 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
182 + rtx_e1000_register_set32(hw_ctx, E1000_CTRL, |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
183 E1000_CMD_ASDE | |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
184 E1000_CMD_SLU); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
185 - rtx_e1000_register_unset32(&${ctx}->hw_ctx, E1000_CTRL, |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
186 + rtx_e1000_register_unset32(hw_ctx, E1000_CTRL, |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
187 E1000_CMD_LRST | |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
188 E1000_CMD_FRCSPD | |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
189 E1000_CMD_PHY_RST | |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
190 E1000_CMD_ILOS | |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
191 E1000_CMD_VME); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
192 - rtx_e1000_register_write32(&${ctx}->hw_ctx, E1000_FCAH, 0); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
193 - rtx_e1000_register_write32(&${ctx}->hw_ctx, E1000_FCAL, 0); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
194 - rtx_e1000_register_write32(&${ctx}->hw_ctx, E1000_FCT, 0); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
195 - rtx_e1000_register_write32(&${ctx}->hw_ctx, E1000_FCTTV, 0); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
196 + rtx_e1000_register_write32(hw_ctx, E1000_FCAH, 0); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
197 + rtx_e1000_register_write32(hw_ctx, E1000_FCAL, 0); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
198 + rtx_e1000_register_write32(hw_ctx, E1000_FCT, 0); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
199 + rtx_e1000_register_write32(hw_ctx, E1000_FCTTV, 0); |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
200 + int i = 0; /* CNorm workaround, the init part of for isn't generated */ |
80
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
201 + for (i = 0; i != 64; ++i) |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
202 + rtx_e1000_register_write32(hw_ctx, E1000_CRCERRS + i * 4, 0); |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
203 + |
80
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
204 + { |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
205 + ${Log::info("setup_device: general configuration done")}; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
206 + } |
79 | 207 + |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
208 + /* |
79 | 209 + * Receive initialization: |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
210 + * |
79 | 211 + * 1. Program the receive address, in RAL/RAH; |
212 + * 2. Initialize the Multicast Table Array; | |
213 + * 3. Program the interrupt mask register (done in | |
214 + * e1000::activate_device_interruption); | |
215 + * 4. Allocate the receive descriptor ring and map it to make it | |
216 + * accessible by the device. | |
217 + * | |
218 + * The ugly casts in here are caused by the lack of CNorm unstrict. | |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
219 + */ |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
220 + |
79 | 221 + /* 1. Program the receive address */ |
222 + | |
223 + /* (We should use uint{32,16}_t but CNorm doesn't know them yet) */ | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
224 + rtx_e1000_register_write32(hw_ctx, E1000_RAL, |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
225 + *(unsigned int *)(${ctx}->net_dev->dev_addr)); |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
226 + /* |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
227 + * The 16 upper bits of RAH also store the AS bits (which should be |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
228 + * 0) and the AV bit (should be 1 to set the address as valid). |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
229 + */ |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
230 + rtx_e1000_register_write32(hw_ctx, E1000_RAH, |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
231 + *(unsigned short *)(&${ctx}->net_dev->dev_addr[4])); |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
232 + rtx_e1000_register_set32(hw_ctx, E1000_RAH, E1000_RAH_AV); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
233 + |
80
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
234 + { |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
235 + ${Log::info("setup_device: program receieve address done")}; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
236 + } |
79 | 237 + |
238 + /* 2. Initialize the MTA */ | |
239 + | |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
240 + i = 0; /* CNorm workaround, the init part of for isn't generated */ |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
241 + for (i = 0; i != 128; ++i) |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
242 + rtx_e1000_register_write32(hw_ctx, E1000_MTA + i * 4, 0); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
243 + |
80
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
244 + { |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
245 + ${Log::info("setup_device: MTA init done")}; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
246 + } |
79 | 247 + |
248 + /* 4. Setup the receive descriptor ring */ | |
249 + | |
250 + /* Allocate the descriptors */ | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
251 + hw_ctx->rx_ring.size = ${config.rx_ring_size} * sizeof(*hw_ctx->rx_ring.base); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
252 + hw_ctx->rx_ring.size = ALIGN(hw_ctx->rx_ring.size, 4096); |
79 | 253 + hw_ctx->rx_ring.base = dma_alloc_coherent( |
254 + &${ctx}->pci_dev->dev, | |
255 + hw_ctx->rx_ring.size, | |
256 + (dma_addr_t *)&hw_ctx->rx_ring.dma_base, | |
257 + GFP_KERNEL); | |
258 + if (!hw_ctx->rx_ring.base) | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
259 + { |
79 | 260 + ${Log::info("cannot allocate the descriptors for the rx ring")}; |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
261 + goto err_rx_ring_alloc; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
262 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
263 + |
80
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
264 + { |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
265 + ${Log::info("setup_device: descriptors allocated")}; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
266 + } |
79 | 267 + |
268 + /* | |
269 + * Allocate the skbuffs, map them for DMA, and write their address | |
270 + * in the corresponding descriptor. | |
271 + */ | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
272 + i = 0; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
273 + for (i = 0; i != ${config.rx_ring_size}; ++i) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
274 + { |
79 | 275 + hw_ctx->rx_ring.skbuffs[i] = netdev_alloc_skb( |
276 + ${ctx}->net_dev, | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
277 + ${config.rx_buffer_len}); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
278 + if (!hw_ctx->rx_ring.skbuffs[i]) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
279 + { |
79 | 280 + ${Log::info("cannot allocate a skbuff for the rx ring")}; |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
281 + goto err_skbuffs_alloc; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
282 + } |
79 | 283 + hw_ctx->rx_ring.dma_skbuffs[i] = (void *)dma_map_single( |
284 + &${ctx}->pci_dev->dev, | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
285 + hw_ctx->rx_ring.skbuffs[i]->data, |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
286 + ${config.rx_buffer_len}, |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
287 + DMA_FROM_DEVICE); |
79 | 288 + /* |
289 + * Either this fails because, when compiling with gcc because | |
290 + * the last argument is not of the correct type (dma_addr_t). | |
291 + * Or it fails because of the lack of CNorm Unstrict. | |
292 + */ | |
293 + if (dma_mapping_error(&${ctx}->pci_dev->dev, (dma_addr_t)hw_ctx->rx_ring.dma_skbuffs[i])) | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
294 + { |
79 | 295 + ${Log::info("cannot dma-map a skbuff for the rx ring")}; |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
296 + goto err_skbuffs_map; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
297 + } |
79 | 298 + hw_ctx->rx_ring.base[i].buff_addr = (unsigned long int)cpu_to_le64( |
299 + hw_ctx->rx_ring.dma_skbuffs[i]); | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
300 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
301 + |
80
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
302 + { |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
303 + ${Log::info("setup_device: skbuffs allocated")}; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
304 + } |
79 | 305 + |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
306 + /* |
79 | 307 + * XXX: We can't return here since we are not in a function but in |
308 + * a chunk of code (injected in a function). | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
309 + */ |
79 | 310 + goto ok; |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
311 + |
79 | 312 + /* |
313 + * Likewise, always the same problem with error handling, we don't | |
314 + * know where we are at in the "parent context": | |
315 + */ | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
316 + err_skbuffs_alloc: |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
317 + while (i--) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
318 + { |
79 | 319 + dma_unmap_single( |
320 + &${ctx}->pci_dev->dev, | |
321 + (dma_addr_t)hw_ctx->rx_ring.dma_skbuffs[i], | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
322 + ${config.rx_buffer_len}, |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
323 + DMA_FROM_DEVICE); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
324 + err_skbuffs_map: |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
325 + dev_kfree_skb(hw_ctx->rx_ring.skbuffs[i]); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
326 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
327 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
328 + dma_free_coherent(&${ctx}->pci_dev->dev, hw_ctx->rx_ring.size, |
79 | 329 + hw_ctx->rx_ring.base, (dma_addr_t)hw_ctx->rx_ring.dma_base); |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
330 + err_rx_ring_alloc: |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
331 + return -ENOMEM; |
79 | 332 + |
333 + ok: | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
334 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
335 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
336 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
337 + template sequence e1000::free_rx_tx(Ethernet::Device ctx) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
338 + { |
78
501bf9cf65dc
wip on e1000 add some fixes for the generation and check that it works on tip
Louis Opter <louis@lse.epitech.net>
parents:
77
diff
changeset
|
339 + chunk ::CALL() |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
340 + { |
80
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
341 + typedef unsigned long int dma_addr_t; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
342 + |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
343 + typedef int ${e1000::Context}; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
344 + ${e1000::Context} hw_ctx; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
345 + hw_ctx = &${ctx}->hw_ctx; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
346 + |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
347 + /* Free the rx ring: */ |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
348 int i = 0; |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
349 - for (i = 0; i != 64; ++i) |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
350 - rtx_e1000_register_write32(&${ctx}->hw_ctx, E1000_CRCERRS + i * 4, 0); |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
351 + for (i = 0; i != ${config.rx_ring_size}; ++i) |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
352 + { |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
353 + dma_unmap_single( |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
354 + &${ctx}->pci_dev->dev, |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
355 + (dma_addr_t)hw_ctx->rx_ring.dma_skbuffs[i], |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
356 + ${config.rx_buffer_len}, |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
357 + DMA_FROM_DEVICE); |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
358 + dev_kfree_skb(hw_ctx->rx_ring.skbuffs[i]); |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
359 + } |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
360 + dma_free_coherent(&${ctx}->pci_dev->dev, hw_ctx->rx_ring.size, |
0354cceee710
WIP on e1000, try to add the code to free the RX ring when shutting the interface down
Louis Opter <louis@lse.epitech.net>
parents:
79
diff
changeset
|
361 + hw_ctx->rx_ring.base, (dma_addr_t)hw_ctx->rx_ring.dma_base); |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
362 + |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
363 } |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
364 } |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
365 |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
366 diff --git a/rathaxes/samples/e1000/e1000.rti b/rathaxes/samples/e1000/e1000.rti |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
367 --- a/rathaxes/samples/e1000/e1000.rti |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
368 +++ b/rathaxes/samples/e1000/e1000.rti |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
369 @@ -1,6 +1,9 @@ |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
370 interface e1000 : Socket, Ethernet, PCI, LKM |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
371 { |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
372 provided type e1000::Context; |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
373 + provided type e1000::RxDescriptor; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
374 + provided type e1000::RxRing; |
76
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
375 + |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
376 /* |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
377 * These two types should actually be registers definitions in the frontend: |
51bea596df7f
Start a patch for the Rx init
Louis Opter <louis@lse.epitech.net>
parents:
diff
changeset
|
378 */ |
78
501bf9cf65dc
wip on e1000 add some fixes for the generation and check that it works on tip
Louis Opter <louis@lse.epitech.net>
parents:
77
diff
changeset
|
379 @@ -55,6 +58,11 @@ |
501bf9cf65dc
wip on e1000 add some fixes for the generation and check that it works on tip
Louis Opter <louis@lse.epitech.net>
parents:
77
diff
changeset
|
380 provided chunk ::CALL(); |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
381 } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
382 |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
383 + provided sequence e1000::free_rx_tx(Ethernet::Device dev) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
384 + { |
78
501bf9cf65dc
wip on e1000 add some fixes for the generation and check that it works on tip
Louis Opter <louis@lse.epitech.net>
parents:
77
diff
changeset
|
385 + provided chunk ::CALL(); |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
386 + } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
387 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
388 provided sequence e1000::handle_interrupt(Ethernet::Device) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
389 { |
78
501bf9cf65dc
wip on e1000 add some fixes for the generation and check that it works on tip
Louis Opter <louis@lse.epitech.net>
parents:
77
diff
changeset
|
390 provided chunk ::CALL(); |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
391 diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
392 --- a/rathaxes/samples/e1000/ethernet.blt |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
393 +++ b/rathaxes/samples/e1000/ethernet.blt |
79 | 394 @@ -64,7 +64,6 @@ |
395 static int rtx_ethernet_open(struct net_device *dev) | |
396 { | |
397 struct rtx_ethernet_dev* rtx_ether_dev = netdev_priv(dev); | |
398 - struct rtx_e1000_ctx* ctx = &rtx_ether_dev->hw_ctx; | |
399 | |
400 ${cast local.rtx_ether_dev as Ethernet::Device}; | |
401 ${pointcut ::IMPLEMENTATION(local.rtx_ether_dev)}; | |
402 @@ -105,8 +104,7 @@ | |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
403 { |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
404 static int rtx_ethernet_close(struct net_device *dev) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
405 { |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
406 - struct rtx_ethernet_dev* rtx_ether_dev = netdev_priv(dev); |
79 | 407 - struct rtx_e1000_ctx* ctx = &rtx_ether_dev->hw_ctx; |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
408 + struct rtx_ethernet_dev* rtx_ether_dev = netdev_priv(dev); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
409 |
78
501bf9cf65dc
wip on e1000 add some fixes for the generation and check that it works on tip
Louis Opter <louis@lse.epitech.net>
parents:
77
diff
changeset
|
410 ${cast local.rtx_ether_dev as Ethernet::Device}; |
79 | 411 ${pointcut ::IMPLEMENTATION(local.rtx_ether_dev)}; |
77
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
412 diff --git a/rathaxes/samples/e1000/lkm.rtx b/rathaxes/samples/e1000/lkm.rtx |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
413 --- a/rathaxes/samples/e1000/lkm.rtx |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
414 +++ b/rathaxes/samples/e1000/lkm.rtx |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
415 @@ -24,7 +24,17 @@ |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
416 Ethernet::close(Ethernet::Device dev) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
417 { |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
418 Log::info("closing the device"); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
419 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
420 + /* |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
421 + * Note: some calls to release resources must be done when IRQs are |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
422 + * enabled (dma_free_coherent() for example). So we have to cleanup our |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
423 + * stuff before free_interrupt_handler(). |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
424 + */ |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
425 + e1000::free_rx_tx(dev); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
426 + Log::info("free'ed up skbuffs"); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
427 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
428 e1000::free_interrupt_handler(dev); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
429 + Log::info("interrupt handler free'ed"); |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
430 } |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
431 |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
432 Ethernet::interrupt_handler(Ethernet::Device dev) |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
433 @@ -61,4 +71,11 @@ |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
434 PCI::set_master = true; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
435 |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
436 Ethernet::ifname = "rtx%d"; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
437 + |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
438 + e1000::rx_ring_size = 256; /* Number of incoming packets we can buffer */ |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
439 + /* |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
440 + * The e1000 supports seven receive buffer sizes: 256, 512, 1024, 2048, |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
441 + * 4096, 8192 and 16384 bytes: |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
442 + */ |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
443 + e1000::rx_buffer_len = 2048; |
892b3bc7e43b
Wip on the RX init in the e1000 sample
Louis Opter <louis@lse.epitech.net>
parents:
76
diff
changeset
|
444 } |
79 | 445 diff --git a/rathaxes/samples/e1000/socket.blt b/rathaxes/samples/e1000/socket.blt |
446 --- a/rathaxes/samples/e1000/socket.blt | |
447 +++ b/rathaxes/samples/e1000/socket.blt | |
448 @@ -4,7 +4,11 @@ | |
449 { | |
450 chunk LKM::includes() | |
451 { | |
452 + typedef int ${Socket::SKBuff}; | |
453 + | |
454 #include <linux/skbuff.h> | |
455 + | |
456 + static const ${Socket::SKBuff} force_rtx_lnux_skbuf_decl; | |
457 } | |
458 | |
459 chunk ::decl() |