comparison rathaxes_start_to_implement_sk_buff_in_the_lkm.patch @ 26:8eac832f763d

rathaxes: free the pci resources
author Thomas Sanchez <thomas.sanchz@gmail.com>
date Sat, 07 Jan 2012 20:48:27 +0100
parents e330b0cea45e
children 1b7399e39afd
comparison
equal deleted inserted replaced
25:e330b0cea45e 26:8eac832f763d
2 # Parent 606e807b8bc7a3a7ea6f1b895bfe909cd7875c2e 2 # Parent 606e807b8bc7a3a7ea6f1b895bfe909cd7875c2e
3 rathaxes: add sk_buff abstraction and add the implementation of the xmit function for the ethernet system. We have a fully (empty) functionnal ethernet driver 3 rathaxes: add sk_buff abstraction and add the implementation of the xmit function for the ethernet system. We have a fully (empty) functionnal ethernet driver
4 4
5 diff -r 606e807b8bc7 rathaxes/samples/lkm/CMakeLists.txt 5 diff -r 606e807b8bc7 rathaxes/samples/lkm/CMakeLists.txt
6 --- a/rathaxes/samples/lkm/CMakeLists.txt Sat Jan 07 20:02:55 2012 +0100 6 --- a/rathaxes/samples/lkm/CMakeLists.txt Sat Jan 07 20:02:55 2012 +0100
7 +++ b/rathaxes/samples/lkm/CMakeLists.txt Sat Jan 07 20:10:46 2012 +0100 7 +++ b/rathaxes/samples/lkm/CMakeLists.txt Sat Jan 07 20:48:23 2012 +0100
8 @@ -1,6 +1,6 @@ 8 @@ -1,6 +1,6 @@
9 ADD_RATHAXES_SOURCES(lkm lkm.rtx 9 ADD_RATHAXES_SOURCES(lkm lkm.rtx
10 - RTI log.rti lkm.rti pci.rti ethernet.rti 10 - RTI log.rti lkm.rti pci.rti ethernet.rti
11 - BLT log.blt lkm.blt pci.blt ethernet.blt) 11 - BLT log.blt lkm.blt pci.blt ethernet.blt)
12 + RTI log.rti lkm.rti pci.rti socket.rti ethernet.rti e1000.rti 12 + RTI log.rti lkm.rti pci.rti socket.rti ethernet.rti e1000.rti
14 14
15 # We can't name lkm since it's already used as the target name to generate the 15 # We can't name lkm since it's already used as the target name to generate the
16 # source (with ADD_RATHAXES_SOURCES). 16 # source (with ADD_RATHAXES_SOURCES).
17 diff -r 606e807b8bc7 rathaxes/samples/lkm/e1000.blt 17 diff -r 606e807b8bc7 rathaxes/samples/lkm/e1000.blt
18 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19 +++ b/rathaxes/samples/lkm/e1000.blt Sat Jan 07 20:10:46 2012 +0100 19 +++ b/rathaxes/samples/lkm/e1000.blt Sat Jan 07 20:48:23 2012 +0100
20 @@ -0,0 +1,57 @@ 20 @@ -0,0 +1,72 @@
21 +with e1000, Ethernet, Socket, PCI, LKM, Log 21 +with e1000, Ethernet, Socket, PCI, LKM, Log
22 +{ 22 +{
23 + template type e1000::Context() 23 + template type e1000::Context()
24 + { 24 + {
25 + chunk LKM::includes() 25 + chunk LKM::includes()
35 + 35 +
36 + chunk ::decl() 36 + chunk ::decl()
37 + { 37 + {
38 + struct rtx_e1000_ctx 38 + struct rtx_e1000_ctx
39 + { 39 + {
40 + unsigned char /* __iomem */ *ioaddr; 40 + int bars;
41 + unsigned char /* __iomem */ *ioaddr;
41 + }; 42 + };
42 + } 43 + }
43 + 44 +
44 + map 45 + map
45 + { 46 + {
48 + 49 +
49 + template sequence e1000::create() 50 + template sequence e1000::create()
50 + { 51 + {
51 + chunk ::CALL 52 + chunk ::CALL
52 + { 53 + {
53 + int bars = pci_select_bars(pdev, IORESOURCE_MEM); 54 + rtx_ether_ctx->hw_ctx.bars = pci_select_bars(pdev, IORESOURCE_MEM);
54 + if (pci_enable_device_mem(pdev)) 55 + if (pci_enable_device_mem(pdev))
55 + { 56 + {
56 + ${Log::info("e1000::create: pci_enable_device_mem failed")}; 57 + ${Log::info("e1000::create: pci_enable_device_mem failed")};
57 + } 58 + }
58 + 59 +
59 + if (pci_request_selected_regions(pdev, bars, ${config.name})) 60 + if (pci_request_selected_regions(pdev, rtx_ether_ctx->hw_ctx.bars, ${config.name}))
60 + { 61 + {
61 + ${Log::info("e1000::create: pci_request_selected_regions failed")}; 62 + ${Log::info("e1000::create: pci_request_selected_regions failed")};
62 + } 63 + }
63 + 64 +
64 + if (${config.set_master}) 65 + if (${config.set_master})
72 + { 73 + {
73 + ${Log::info("e1000::create: pci_ioremap_bar failed")}; 74 + ${Log::info("e1000::create: pci_ioremap_bar failed")};
74 + } 75 + }
75 + } 76 + }
76 + } 77 + }
78 +
79 + template sequence e1000::destroy()
80 + {
81 + chunk ::CALL
82 + {
83 + // XXX: add a check in order to avoid freeing none allocated
84 + // resources.
85 + struct net_device *net_dev = pci_get_drvdata(pdev);
86 + struct rtx_ethernet_dev* rtx_ether_ctx = netdev_priv(net_dev);
87 + iounmap(rtx_ether_ctx->hw_ctx.ioaddr);
88 + pci_release_selected_regions(pdev, rtx_ether_ctx->hw_ctx.bars);
89 + pci_release_region(pdev, 0);
90 + }
91 + }
77 +} 92 +}
78 diff -r 606e807b8bc7 rathaxes/samples/lkm/e1000.rti 93 diff -r 606e807b8bc7 rathaxes/samples/lkm/e1000.rti
79 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 94 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
80 +++ b/rathaxes/samples/lkm/e1000.rti Sat Jan 07 20:10:46 2012 +0100 95 +++ b/rathaxes/samples/lkm/e1000.rti Sat Jan 07 20:48:23 2012 +0100
81 @@ -0,0 +1,10 @@ 96 @@ -0,0 +1,15 @@
82 +interface e1000 : Socket, Ethernet, PCI, LKM 97 +interface e1000 : Socket, Ethernet, PCI, LKM
83 +{ 98 +{
84 + provided type e1000::Context; 99 + provided type e1000::Context;
85 + 100 +
86 + /* Not sure if we need the argument */ 101 + /* Not sure if we need the argument */
87 + provided sequence e1000::create() 102 + provided sequence e1000::create()
88 + { 103 + {
89 + provided chunk ::CALL; 104 + provided chunk ::CALL;
90 + } 105 + }
106 +
107 + provided sequence e1000::destroy()
108 + {
109 + provided chunk ::CALL;
110 + }
91 +} 111 +}
92 diff -r 606e807b8bc7 rathaxes/samples/lkm/ethernet.blt 112 diff -r 606e807b8bc7 rathaxes/samples/lkm/ethernet.blt
93 --- a/rathaxes/samples/lkm/ethernet.blt Sat Jan 07 20:02:55 2012 +0100 113 --- a/rathaxes/samples/lkm/ethernet.blt Sat Jan 07 20:02:55 2012 +0100
94 +++ b/rathaxes/samples/lkm/ethernet.blt Sat Jan 07 20:10:46 2012 +0100 114 +++ b/rathaxes/samples/lkm/ethernet.blt Sat Jan 07 20:48:23 2012 +0100
95 @@ -18,8 +18,11 @@ 115 @@ -18,8 +18,11 @@
96 * I think it's useless to use the ${PCI::Device} "abstraction" 116 * I think it's useless to use the ${PCI::Device} "abstraction"
97 * here, since we are already in a Linux specific context here. 117 * here, since we are already in a Linux specific context here.
98 */ 118 */
99 - struct pci_dev *pci_dev; 119 - struct pci_dev *pci_dev;
138 - .ndo_start_xmit = NULL, 158 - .ndo_start_xmit = NULL,
139 + .ndo_start_xmit = rtx_ethernet_xmit, 159 + .ndo_start_xmit = rtx_ethernet_xmit,
140 }; 160 };
141 } 161 }
142 162
163 @@ -159,9 +180,6 @@
164 {
165 chunk ::CALL
166 {
167 - struct net_device *net_dev;
168 -
169 - net_dev = pci_get_drvdata(pdev); // should be ${pdev}, see above
170 unregister_netdev(net_dev);
171 /*
172 * If we had some cleanup todo with struct rtx_ether_ctx we would
143 diff -r 606e807b8bc7 rathaxes/samples/lkm/ethernet.rti 173 diff -r 606e807b8bc7 rathaxes/samples/lkm/ethernet.rti
144 --- a/rathaxes/samples/lkm/ethernet.rti Sat Jan 07 20:02:55 2012 +0100 174 --- a/rathaxes/samples/lkm/ethernet.rti Sat Jan 07 20:02:55 2012 +0100
145 +++ b/rathaxes/samples/lkm/ethernet.rti Sat Jan 07 20:10:46 2012 +0100 175 +++ b/rathaxes/samples/lkm/ethernet.rti Sat Jan 07 20:48:23 2012 +0100
146 @@ -1,4 +1,4 @@ 176 @@ -1,4 +1,4 @@
147 -interface Ethernet : PCI, LKM 177 -interface Ethernet : PCI, LKM
148 +interface Ethernet : Socket, PCI, LKM 178 +interface Ethernet : Socket, PCI, LKM
149 { 179 {
150 provided type Ethernet::Device; 180 provided type Ethernet::Device;
162 required sequence Ethernet::close(Ethernet::Device) 192 required sequence Ethernet::close(Ethernet::Device)
163 { 193 {
164 provided chunk LKM::prototypes; 194 provided chunk LKM::prototypes;
165 diff -r 606e807b8bc7 rathaxes/samples/lkm/lkm.rtx 195 diff -r 606e807b8bc7 rathaxes/samples/lkm/lkm.rtx
166 --- a/rathaxes/samples/lkm/lkm.rtx Sat Jan 07 20:02:55 2012 +0100 196 --- a/rathaxes/samples/lkm/lkm.rtx Sat Jan 07 20:02:55 2012 +0100
167 +++ b/rathaxes/samples/lkm/lkm.rtx Sat Jan 07 20:10:46 2012 +0100 197 +++ b/rathaxes/samples/lkm/lkm.rtx Sat Jan 07 20:48:23 2012 +0100
168 @@ -15,10 +15,16 @@ 198 @@ -15,15 +15,22 @@
169 Log::info("Got an interruption"); 199 Log::info("Got an interruption");
170 } 200 }
171 201
172 + Ethernet::send(Ethernet::Device dev, Socket::SKBuff skb) 202 + Ethernet::send(Ethernet::Device dev, Socket::SKBuff skb)
173 + { 203 + {
180 Ethernet::init(dev); 210 Ethernet::init(dev);
181 + e1000::create(); 211 + e1000::create();
182 } 212 }
183 213
184 PCI::remove(PCI::Device dev) 214 PCI::remove(PCI::Device dev)
185 @@ -45,10 +51,11 @@ 215 {
216 Log::info("Remove the pci device");
217 + e1000::destroy();
218 Ethernet::exit(dev);
219 }
220
221 @@ -45,10 +52,11 @@
186 LKM::name = "hello"; 222 LKM::name = "hello";
187 LKM::author = "Rathaxes"; 223 LKM::author = "Rathaxes";
188 LKM::description = "Hello World Loadable Kernel Module (LKM)"; 224 LKM::description = "Hello World Loadable Kernel Module (LKM)";
189 - LKM::license = "BSD"; 225 - LKM::license = "BSD";
190 + LKM::license = "GPL"; 226 + LKM::license = "GPL";
195 231
196 Ethernet::ifname = "rtx%d"; 232 Ethernet::ifname = "rtx%d";
197 } 233 }
198 diff -r 606e807b8bc7 rathaxes/samples/lkm/socket.blt 234 diff -r 606e807b8bc7 rathaxes/samples/lkm/socket.blt
199 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 235 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
200 +++ b/rathaxes/samples/lkm/socket.blt Sat Jan 07 20:10:46 2012 +0100 236 +++ b/rathaxes/samples/lkm/socket.blt Sat Jan 07 20:48:23 2012 +0100
201 @@ -0,0 +1,27 @@ 237 @@ -0,0 +1,27 @@
202 +with Socket, LKM 238 +with Socket, LKM
203 +{ 239 +{
204 + template type Socket::SKBuff() 240 + template type Socket::SKBuff()
205 + { 241 + {
226 + } 262 + }
227 + } 263 + }
228 +} 264 +}
229 diff -r 606e807b8bc7 rathaxes/samples/lkm/socket.rti 265 diff -r 606e807b8bc7 rathaxes/samples/lkm/socket.rti
230 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 266 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
231 +++ b/rathaxes/samples/lkm/socket.rti Sat Jan 07 20:10:46 2012 +0100 267 +++ b/rathaxes/samples/lkm/socket.rti Sat Jan 07 20:48:23 2012 +0100
232 @@ -0,0 +1,4 @@ 268 @@ -0,0 +1,4 @@
233 +interface Socket : LKM 269 +interface Socket : LKM
234 +{ 270 +{
235 + provided type Socket::SKBuff; 271 + provided type Socket::SKBuff;
236 +} 272 +}