diff options
Diffstat (limited to 'drivers/firewire/net.c')
-rw-r--r-- | drivers/firewire/net.c | 1819 |
1 files changed, 1819 insertions, 0 deletions
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c new file mode 100644 index 000000000000..15353886bd80 --- /dev/null +++ b/drivers/firewire/net.c | |||
@@ -0,0 +1,1819 @@ | |||
1 | /* | ||
2 | * IPv4 over IEEE 1394, per RFC 2734 | ||
3 | * | ||
4 | * Copyright (C) 2009 Jay Fenlason <fenlason@redhat.com> | ||
5 | * | ||
6 | * based on eth1394 by Ben Collins et al | ||
7 | */ | ||
8 | |||
9 | #include <linux/device.h> | ||
10 | #include <linux/ethtool.h> | ||
11 | #include <linux/firewire.h> | ||
12 | #include <linux/firewire-constants.h> | ||
13 | #include <linux/highmem.h> | ||
14 | #include <linux/in.h> | ||
15 | #include <linux/ip.h> | ||
16 | #include <linux/mod_devicetable.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/moduleparam.h> | ||
19 | #include <linux/netdevice.h> | ||
20 | #include <linux/skbuff.h> | ||
21 | |||
22 | #include <asm/unaligned.h> | ||
23 | #include <net/arp.h> | ||
24 | |||
25 | /* Things to potentially make runtime cofigurable */ | ||
26 | /* must be at least as large as our maximum receive size */ | ||
27 | #define FIFO_SIZE 4096 | ||
28 | /* Network timeout in glibbles */ | ||
29 | #define IPV4_TIMEOUT 100000 | ||
30 | |||
31 | /* Runitme configurable paramaters */ | ||
32 | static int ipv4_mpd = 25; | ||
33 | static int ipv4_max_xmt = 0; | ||
34 | /* 16k for receiving arp and broadcast packets. Enough? */ | ||
35 | static int ipv4_iso_page_count = 4; | ||
36 | |||
37 | MODULE_AUTHOR("Jay Fenlason (fenlason@redhat.com)"); | ||
38 | MODULE_DESCRIPTION("Firewire IPv4 Driver (IPv4-over-IEEE1394 as per RFC 2734)"); | ||
39 | MODULE_LICENSE("GPL"); | ||
40 | MODULE_DEVICE_TABLE(ieee1394, ipv4_id_table); | ||
41 | module_param_named(max_partial_datagrams, ipv4_mpd, int, S_IRUGO | S_IWUSR); | ||
42 | MODULE_PARM_DESC(max_partial_datagrams, "Maximum number of received" | ||
43 | " incomplete fragmented datagrams (default = 25)."); | ||
44 | |||
45 | /* Max xmt is useful for forcing fragmentation, which makes testing easier. */ | ||
46 | module_param_named(max_transmit, ipv4_max_xmt, int, S_IRUGO | S_IWUSR); | ||
47 | MODULE_PARM_DESC(max_transmit, "Maximum datagram size to transmit" | ||
48 | " (larger datagrams will be fragmented) (default = 0 (use hardware defaults)."); | ||
49 | |||
50 | /* iso page count controls how many pages will be used for receiving broadcast packets. */ | ||
51 | module_param_named(iso_pages, ipv4_iso_page_count, int, S_IRUGO | S_IWUSR); | ||
52 | MODULE_PARM_DESC(iso_pages, "Number of pages to use for receiving broadcast packets" | ||
53 | " (default = 4)."); | ||
54 | |||
55 | /* uncomment this line to do debugging */ | ||
56 | #define fw_debug(s, args...) printk(KERN_DEBUG KBUILD_MODNAME ": " s, ## args) | ||
57 | |||
58 | /* comment out these lines to do debugging. */ | ||
59 | /* #undef fw_debug */ | ||
60 | /* #define fw_debug(s...) */ | ||
61 | /* #define print_hex_dump(l...) */ | ||
62 | |||
63 | /* Define a fake hardware header format for the networking core. Note that | ||
64 | * header size cannot exceed 16 bytes as that is the size of the header cache. | ||
65 | * Also, we do not need the source address in the header so we omit it and | ||
66 | * keep the header to under 16 bytes */ | ||
67 | #define IPV4_ALEN (8) | ||
68 | /* This must equal sizeof(struct ipv4_ether_hdr) */ | ||
69 | #define IPV4_HLEN (10) | ||
70 | |||
71 | /* FIXME: what's a good size for this? */ | ||
72 | #define INVALID_FIFO_ADDR (u64)~0ULL | ||
73 | |||
74 | /* Things specified by standards */ | ||
75 | #define BROADCAST_CHANNEL 31 | ||
76 | |||
77 | #define S100_BUFFER_SIZE 512 | ||
78 | #define MAX_BUFFER_SIZE 4096 | ||
79 | |||
80 | #define IPV4_GASP_SPECIFIER_ID 0x00005EU | ||
81 | #define IPV4_GASP_VERSION 0x00000001U | ||
82 | |||
83 | #define IPV4_GASP_OVERHEAD (2 * sizeof(u32)) /* for GASP header */ | ||
84 | |||
85 | #define IPV4_UNFRAG_HDR_SIZE sizeof(u32) | ||
86 | #define IPV4_FRAG_HDR_SIZE (2 * sizeof(u32)) | ||
87 | #define IPV4_FRAG_OVERHEAD sizeof(u32) | ||
88 | |||
89 | #define ALL_NODES (0xffc0 | 0x003f) | ||
90 | |||
91 | #define IPV4_HDR_UNFRAG 0 /* unfragmented */ | ||
92 | #define IPV4_HDR_FIRSTFRAG 1 /* first fragment */ | ||
93 | #define IPV4_HDR_LASTFRAG 2 /* last fragment */ | ||
94 | #define IPV4_HDR_INTFRAG 3 /* interior fragment */ | ||
95 | |||
96 | /* Our arp packet (ARPHRD_IEEE1394) */ | ||
97 | /* FIXME: note that this is probably bogus on weird-endian machines */ | ||
98 | struct ipv4_arp { | ||
99 | u16 hw_type; /* 0x0018 */ | ||
100 | u16 proto_type; /* 0x0806 */ | ||
101 | u8 hw_addr_len; /* 16 */ | ||
102 | u8 ip_addr_len; /* 4 */ | ||
103 | u16 opcode; /* ARP Opcode */ | ||
104 | /* Above is exactly the same format as struct arphdr */ | ||
105 | |||
106 | u64 s_uniq_id; /* Sender's 64bit EUI */ | ||
107 | u8 max_rec; /* Sender's max packet size */ | ||
108 | u8 sspd; /* Sender's max speed */ | ||
109 | u16 fifo_hi; /* hi 16bits of sender's FIFO addr */ | ||
110 | u32 fifo_lo; /* lo 32bits of sender's FIFO addr */ | ||
111 | u32 sip; /* Sender's IP Address */ | ||
112 | u32 tip; /* IP Address of requested hw addr */ | ||
113 | } __attribute__((packed)); | ||
114 | |||
115 | struct ipv4_ether_hdr { | ||
116 | unsigned char h_dest[IPV4_ALEN]; /* destination address */ | ||
117 | unsigned short h_proto; /* packet type ID field */ | ||
118 | } __attribute__((packed)); | ||
119 | |||
120 | static inline struct ipv4_ether_hdr *ipv4_ether_hdr(const struct sk_buff *skb) | ||
121 | { | ||
122 | return (struct ipv4_ether_hdr *)skb_mac_header(skb); | ||
123 | } | ||
124 | |||
125 | enum ipv4_tx_type { | ||
126 | IPV4_UNKNOWN = 0, | ||
127 | IPV4_GASP = 1, | ||
128 | IPV4_WRREQ = 2, | ||
129 | }; | ||
130 | |||
131 | enum ipv4_broadcast_state { | ||
132 | IPV4_BROADCAST_ERROR, | ||
133 | IPV4_BROADCAST_RUNNING, | ||
134 | IPV4_BROADCAST_STOPPED, | ||
135 | }; | ||
136 | |||
137 | #define ipv4_get_hdr_lf(h) (((h)->w0&0xC0000000)>>30) | ||
138 | #define ipv4_get_hdr_ether_type(h) (((h)->w0&0x0000FFFF) ) | ||
139 | #define ipv4_get_hdr_dg_size(h) (((h)->w0&0x0FFF0000)>>16) | ||
140 | #define ipv4_get_hdr_fg_off(h) (((h)->w0&0x00000FFF) ) | ||
141 | #define ipv4_get_hdr_dgl(h) (((h)->w1&0xFFFF0000)>>16) | ||
142 | |||
143 | #define ipv4_set_hdr_lf(lf) (( lf)<<30) | ||
144 | #define ipv4_set_hdr_ether_type(et) (( et) ) | ||
145 | #define ipv4_set_hdr_dg_size(dgs) ((dgs)<<16) | ||
146 | #define ipv4_set_hdr_fg_off(fgo) ((fgo) ) | ||
147 | |||
148 | #define ipv4_set_hdr_dgl(dgl) ((dgl)<<16) | ||
149 | |||
150 | struct ipv4_hdr { | ||
151 | u32 w0; | ||
152 | u32 w1; | ||
153 | }; | ||
154 | |||
155 | static inline void ipv4_make_uf_hdr( struct ipv4_hdr *hdr, unsigned ether_type) { | ||
156 | hdr->w0 = ipv4_set_hdr_lf(IPV4_HDR_UNFRAG) | ||
157 | |ipv4_set_hdr_ether_type(ether_type); | ||
158 | fw_debug ( "Setting unfragmented header %p to %x\n", hdr, hdr->w0 ); | ||
159 | } | ||
160 | |||
161 | static inline void ipv4_make_ff_hdr ( struct ipv4_hdr *hdr, unsigned ether_type, unsigned dg_size, unsigned dgl ) { | ||
162 | hdr->w0 = ipv4_set_hdr_lf(IPV4_HDR_FIRSTFRAG) | ||
163 | |ipv4_set_hdr_dg_size(dg_size) | ||
164 | |ipv4_set_hdr_ether_type(ether_type); | ||
165 | hdr->w1 = ipv4_set_hdr_dgl(dgl); | ||
166 | fw_debug ( "Setting fragmented header %p to first_frag %x,%x (et %x, dgs %x, dgl %x)\n", hdr, hdr->w0, hdr->w1, | ||
167 | ether_type, dg_size, dgl ); | ||
168 | } | ||
169 | |||
170 | static inline void ipv4_make_sf_hdr ( struct ipv4_hdr *hdr, unsigned lf, unsigned dg_size, unsigned fg_off, unsigned dgl) { | ||
171 | hdr->w0 = ipv4_set_hdr_lf(lf) | ||
172 | |ipv4_set_hdr_dg_size(dg_size) | ||
173 | |ipv4_set_hdr_fg_off(fg_off); | ||
174 | hdr->w1 = ipv4_set_hdr_dgl(dgl); | ||
175 | fw_debug ( "Setting fragmented header %p to %x,%x (lf %x, dgs %x, fo %x dgl %x)\n", | ||
176 | hdr, hdr->w0, hdr->w1, | ||
177 | lf, dg_size, fg_off, dgl ); | ||
178 | } | ||
179 | |||
180 | /* End of IP1394 headers */ | ||
181 | |||
182 | /* Fragment types */ | ||
183 | #define ETH1394_HDR_LF_UF 0 /* unfragmented */ | ||
184 | #define ETH1394_HDR_LF_FF 1 /* first fragment */ | ||
185 | #define ETH1394_HDR_LF_LF 2 /* last fragment */ | ||
186 | #define ETH1394_HDR_LF_IF 3 /* interior fragment */ | ||
187 | |||
188 | #define IP1394_HW_ADDR_LEN 16 /* As per RFC */ | ||
189 | |||
190 | /* This list keeps track of what parts of the datagram have been filled in */ | ||
191 | struct ipv4_fragment_info { | ||
192 | struct list_head fragment_info; | ||
193 | u16 offset; | ||
194 | u16 len; | ||
195 | }; | ||
196 | |||
197 | struct ipv4_partial_datagram { | ||
198 | struct list_head pdg_list; | ||
199 | struct list_head fragment_info; | ||
200 | struct sk_buff *skb; | ||
201 | /* FIXME Why not use skb->data? */ | ||
202 | char *pbuf; | ||
203 | u16 datagram_label; | ||
204 | u16 ether_type; | ||
205 | u16 datagram_size; | ||
206 | }; | ||
207 | |||
208 | /* | ||
209 | * We keep one of these for each IPv4 capable device attached to a fw_card. | ||
210 | * The list of them is stored in the fw_card structure rather than in the | ||
211 | * ipv4_priv because the remote IPv4 nodes may be probed before the card is, | ||
212 | * so we need a place to store them before the ipv4_priv structure is | ||
213 | * allocated. | ||
214 | */ | ||
215 | struct ipv4_node { | ||
216 | struct list_head ipv4_nodes; | ||
217 | /* guid of the remote node */ | ||
218 | u64 guid; | ||
219 | /* FIFO address to transmit datagrams to, or INVALID_FIFO_ADDR */ | ||
220 | u64 fifo; | ||
221 | |||
222 | spinlock_t pdg_lock; /* partial datagram lock */ | ||
223 | /* List of partial datagrams received from this node */ | ||
224 | struct list_head pdg_list; | ||
225 | /* Number of entries in pdg_list at the moment */ | ||
226 | unsigned pdg_size; | ||
227 | |||
228 | /* max payload to transmit to this remote node */ | ||
229 | /* This already includes the IPV4_FRAG_HDR_SIZE overhead */ | ||
230 | u16 max_payload; | ||
231 | /* outgoing datagram label */ | ||
232 | u16 datagram_label; | ||
233 | /* Current node_id of the remote node */ | ||
234 | u16 nodeid; | ||
235 | /* current generation of the remote node */ | ||
236 | u8 generation; | ||
237 | /* max speed that this node can receive at */ | ||
238 | u8 xmt_speed; | ||
239 | }; | ||
240 | |||
241 | struct ipv4_priv { | ||
242 | spinlock_t lock; | ||
243 | |||
244 | enum ipv4_broadcast_state broadcast_state; | ||
245 | struct fw_iso_context *broadcast_rcv_context; | ||
246 | struct fw_iso_buffer broadcast_rcv_buffer; | ||
247 | void **broadcast_rcv_buffer_ptrs; | ||
248 | unsigned broadcast_rcv_next_ptr; | ||
249 | unsigned num_broadcast_rcv_ptrs; | ||
250 | unsigned rcv_buffer_size; | ||
251 | /* | ||
252 | * This value is the maximum unfragmented datagram size that can be | ||
253 | * sent by the hardware. It already has the GASP overhead and the | ||
254 | * unfragmented datagram header overhead calculated into it. | ||
255 | */ | ||
256 | unsigned broadcast_xmt_max_payload; | ||
257 | u16 broadcast_xmt_datagramlabel; | ||
258 | |||
259 | /* | ||
260 | * The csr address that remote nodes must send datagrams to for us to | ||
261 | * receive them. | ||
262 | */ | ||
263 | struct fw_address_handler handler; | ||
264 | u64 local_fifo; | ||
265 | |||
266 | /* Wake up to xmt */ | ||
267 | /* struct work_struct wake;*/ | ||
268 | /* List of packets to be sent */ | ||
269 | struct list_head packet_list; | ||
270 | /* | ||
271 | * List of packets that were broadcasted. When we get an ISO interrupt | ||
272 | * one of them has been sent | ||
273 | */ | ||
274 | struct list_head broadcasted_list; | ||
275 | /* List of packets that have been sent but not yet acked */ | ||
276 | struct list_head sent_list; | ||
277 | |||
278 | struct fw_card *card; | ||
279 | }; | ||
280 | |||
281 | /* This is our task struct. It's used for the packet complete callback. */ | ||
282 | struct ipv4_packet_task { | ||
283 | /* | ||
284 | * ptask can actually be on priv->packet_list, priv->broadcasted_list, | ||
285 | * or priv->sent_list depending on its current state. | ||
286 | */ | ||
287 | struct list_head packet_list; | ||
288 | struct fw_transaction transaction; | ||
289 | struct ipv4_hdr hdr; | ||
290 | struct sk_buff *skb; | ||
291 | struct ipv4_priv *priv; | ||
292 | enum ipv4_tx_type tx_type; | ||
293 | int outstanding_pkts; | ||
294 | unsigned max_payload; | ||
295 | u64 fifo_addr; | ||
296 | u16 dest_node; | ||
297 | u8 generation; | ||
298 | u8 speed; | ||
299 | }; | ||
300 | |||
301 | static struct kmem_cache *ipv4_packet_task_cache; | ||
302 | |||
303 | static const char ipv4_driver_name[] = "firewire-ipv4"; | ||
304 | |||
305 | static const struct ieee1394_device_id ipv4_id_table[] = { | ||
306 | { | ||
307 | .match_flags = IEEE1394_MATCH_SPECIFIER_ID | | ||
308 | IEEE1394_MATCH_VERSION, | ||
309 | .specifier_id = IPV4_GASP_SPECIFIER_ID, | ||
310 | .version = IPV4_GASP_VERSION, | ||
311 | }, | ||
312 | { } | ||
313 | }; | ||
314 | |||
315 | static u32 ipv4_unit_directory_data[] = { | ||
316 | 0x00040000, /* unit directory */ | ||
317 | 0x12000000 | IPV4_GASP_SPECIFIER_ID, /* specifier ID */ | ||
318 | 0x81000003, /* text descriptor */ | ||
319 | 0x13000000 | IPV4_GASP_VERSION, /* version */ | ||
320 | 0x81000005, /* text descriptor */ | ||
321 | |||
322 | 0x00030000, /* Three quadlets */ | ||
323 | 0x00000000, /* Text */ | ||
324 | 0x00000000, /* Language 0 */ | ||
325 | 0x49414e41, /* I A N A */ | ||
326 | 0x00030000, /* Three quadlets */ | ||
327 | 0x00000000, /* Text */ | ||
328 | 0x00000000, /* Language 0 */ | ||
329 | 0x49507634, /* I P v 4 */ | ||
330 | }; | ||
331 | |||
332 | static struct fw_descriptor ipv4_unit_directory = { | ||
333 | .length = ARRAY_SIZE(ipv4_unit_directory_data), | ||
334 | .key = 0xd1000000, | ||
335 | .data = ipv4_unit_directory_data | ||
336 | }; | ||
337 | |||
338 | static int ipv4_send_packet(struct ipv4_packet_task *ptask ); | ||
339 | |||
340 | /* ------------------------------------------------------------------ */ | ||
341 | /****************************************** | ||
342 | * HW Header net device functions | ||
343 | ******************************************/ | ||
344 | /* These functions have been adapted from net/ethernet/eth.c */ | ||
345 | |||
346 | /* Create a fake MAC header for an arbitrary protocol layer. | ||
347 | * saddr=NULL means use device source address | ||
348 | * daddr=NULL means leave destination address (eg unresolved arp). */ | ||
349 | |||
350 | static int ipv4_header ( struct sk_buff *skb, struct net_device *dev, | ||
351 | unsigned short type, const void *daddr, | ||
352 | const void *saddr, unsigned len) { | ||
353 | struct ipv4_ether_hdr *eth; | ||
354 | |||
355 | eth = (struct ipv4_ether_hdr *)skb_push(skb, sizeof(*eth)); | ||
356 | eth->h_proto = htons(type); | ||
357 | |||
358 | if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) { | ||
359 | memset(eth->h_dest, 0, dev->addr_len); | ||
360 | return dev->hard_header_len; | ||
361 | } | ||
362 | |||
363 | if (daddr) { | ||
364 | memcpy(eth->h_dest, daddr, dev->addr_len); | ||
365 | return dev->hard_header_len; | ||
366 | } | ||
367 | |||
368 | return -dev->hard_header_len; | ||
369 | } | ||
370 | |||
371 | /* Rebuild the faked MAC header. This is called after an ARP | ||
372 | * (or in future other address resolution) has completed on this | ||
373 | * sk_buff. We now let ARP fill in the other fields. | ||
374 | * | ||
375 | * This routine CANNOT use cached dst->neigh! | ||
376 | * Really, it is used only when dst->neigh is wrong. | ||
377 | */ | ||
378 | |||
379 | static int ipv4_rebuild_header(struct sk_buff *skb) | ||
380 | { | ||
381 | struct ipv4_ether_hdr *eth; | ||
382 | |||
383 | eth = (struct ipv4_ether_hdr *)skb->data; | ||
384 | if (eth->h_proto == htons(ETH_P_IP)) | ||
385 | return arp_find((unsigned char *)ð->h_dest, skb); | ||
386 | |||
387 | fw_notify ( "%s: unable to resolve type %04x addresses\n", | ||
388 | skb->dev->name,ntohs(eth->h_proto) ); | ||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | static int ipv4_header_cache(const struct neighbour *neigh, struct hh_cache *hh) { | ||
393 | unsigned short type = hh->hh_type; | ||
394 | struct net_device *dev; | ||
395 | struct ipv4_ether_hdr *eth; | ||
396 | |||
397 | if (type == htons(ETH_P_802_3)) | ||
398 | return -1; | ||
399 | dev = neigh->dev; | ||
400 | eth = (struct ipv4_ether_hdr *)((u8 *)hh->hh_data + 16 - sizeof(*eth)); | ||
401 | eth->h_proto = type; | ||
402 | memcpy(eth->h_dest, neigh->ha, dev->addr_len); | ||
403 | |||
404 | hh->hh_len = IPV4_HLEN; | ||
405 | return 0; | ||
406 | } | ||
407 | |||
408 | /* Called by Address Resolution module to notify changes in address. */ | ||
409 | static void ipv4_header_cache_update(struct hh_cache *hh, const struct net_device *dev, const unsigned char * haddr ) { | ||
410 | memcpy((u8 *)hh->hh_data + 16 - IPV4_HLEN, haddr, dev->addr_len); | ||
411 | } | ||
412 | |||
413 | static int ipv4_header_parse(const struct sk_buff *skb, unsigned char *haddr) { | ||
414 | memcpy(haddr, skb->dev->dev_addr, IPV4_ALEN); | ||
415 | return IPV4_ALEN; | ||
416 | } | ||
417 | |||
418 | static const struct header_ops ipv4_header_ops = { | ||
419 | .create = ipv4_header, | ||
420 | .rebuild = ipv4_rebuild_header, | ||
421 | .cache = ipv4_header_cache, | ||
422 | .cache_update = ipv4_header_cache_update, | ||
423 | .parse = ipv4_header_parse, | ||
424 | }; | ||
425 | |||
426 | /* ------------------------------------------------------------------ */ | ||
427 | |||
428 | /* FIXME: is this correct for all cases? */ | ||
429 | static bool ipv4_frag_overlap(struct ipv4_partial_datagram *pd, unsigned offset, unsigned len) | ||
430 | { | ||
431 | struct ipv4_fragment_info *fi; | ||
432 | unsigned end = offset + len; | ||
433 | |||
434 | list_for_each_entry(fi, &pd->fragment_info, fragment_info) { | ||
435 | if (offset < fi->offset + fi->len && end > fi->offset) { | ||
436 | fw_debug ( "frag_overlap pd %p fi %p (%x@%x) with %x@%x\n", pd, fi, fi->len, fi->offset, len, offset ); | ||
437 | return true; | ||
438 | } | ||
439 | } | ||
440 | fw_debug ( "frag_overlap %p does not overlap with %x@%x\n", pd, len, offset ); | ||
441 | return false; | ||
442 | } | ||
443 | |||
444 | /* Assumes that new fragment does not overlap any existing fragments */ | ||
445 | static struct ipv4_fragment_info *ipv4_frag_new ( struct ipv4_partial_datagram *pd, unsigned offset, unsigned len ) { | ||
446 | struct ipv4_fragment_info *fi, *fi2, *new; | ||
447 | struct list_head *list; | ||
448 | |||
449 | fw_debug ( "frag_new pd %p %x@%x\n", pd, len, offset ); | ||
450 | list = &pd->fragment_info; | ||
451 | list_for_each_entry(fi, &pd->fragment_info, fragment_info) { | ||
452 | if (fi->offset + fi->len == offset) { | ||
453 | /* The new fragment can be tacked on to the end */ | ||
454 | /* Did the new fragment plug a hole? */ | ||
455 | fi2 = list_entry(fi->fragment_info.next, struct ipv4_fragment_info, fragment_info); | ||
456 | if (fi->offset + fi->len == fi2->offset) { | ||
457 | fw_debug ( "pd %p: hole filling %p (%x@%x) and %p(%x@%x): now %x@%x\n", pd, fi, fi->len, fi->offset, | ||
458 | fi2, fi2->len, fi2->offset, fi->len + len + fi2->len, fi->offset ); | ||
459 | /* glue fragments together */ | ||
460 | fi->len += len + fi2->len; | ||
461 | list_del(&fi2->fragment_info); | ||
462 | kfree(fi2); | ||
463 | } else { | ||
464 | fw_debug ( "pd %p: extending %p from %x@%x to %x@%x\n", pd, fi, fi->len, fi->offset, fi->len+len, fi->offset ); | ||
465 | fi->len += len; | ||
466 | } | ||
467 | return fi; | ||
468 | } | ||
469 | if (offset + len == fi->offset) { | ||
470 | /* The new fragment can be tacked on to the beginning */ | ||
471 | /* Did the new fragment plug a hole? */ | ||
472 | fi2 = list_entry(fi->fragment_info.prev, struct ipv4_fragment_info, fragment_info); | ||
473 | if (fi2->offset + fi2->len == fi->offset) { | ||
474 | /* glue fragments together */ | ||
475 | fw_debug ( "pd %p: extending %p and merging with %p from %x@%x to %x@%x\n", | ||
476 | pd, fi2, fi, fi2->len, fi2->offset, fi2->len + fi->len + len, fi2->offset ); | ||
477 | fi2->len += fi->len + len; | ||
478 | list_del(&fi->fragment_info); | ||
479 | kfree(fi); | ||
480 | return fi2; | ||
481 | } | ||
482 | fw_debug ( "pd %p: extending %p from %x@%x to %x@%x\n", pd, fi, fi->len, fi->offset, offset, fi->len + len ); | ||
483 | fi->offset = offset; | ||
484 | fi->len += len; | ||
485 | return fi; | ||
486 | } | ||
487 | if (offset > fi->offset + fi->len) { | ||
488 | list = &fi->fragment_info; | ||
489 | break; | ||
490 | } | ||
491 | if (offset + len < fi->offset) { | ||
492 | list = fi->fragment_info.prev; | ||
493 | break; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | new = kmalloc(sizeof(*new), GFP_ATOMIC); | ||
498 | if (!new) { | ||
499 | fw_error ( "out of memory in fragment handling!\n" ); | ||
500 | return NULL; | ||
501 | } | ||
502 | |||
503 | new->offset = offset; | ||
504 | new->len = len; | ||
505 | list_add(&new->fragment_info, list); | ||
506 | fw_debug ( "pd %p: new frag %p %x@%x\n", pd, new, new->len, new->offset ); | ||
507 | list_for_each_entry( fi, &pd->fragment_info, fragment_info ) | ||
508 | fw_debug ( "fi %p %x@%x\n", fi, fi->len, fi->offset ); | ||
509 | return new; | ||
510 | } | ||
511 | |||
512 | /* ------------------------------------------------------------------ */ | ||
513 | |||
514 | static struct ipv4_partial_datagram *ipv4_pd_new(struct net_device *netdev, | ||
515 | struct ipv4_node *node, u16 datagram_label, unsigned dg_size, u32 *frag_buf, | ||
516 | unsigned frag_off, unsigned frag_len) { | ||
517 | struct ipv4_partial_datagram *new; | ||
518 | struct ipv4_fragment_info *fi; | ||
519 | |||
520 | new = kmalloc(sizeof(*new), GFP_ATOMIC); | ||
521 | if (!new) | ||
522 | goto fail; | ||
523 | INIT_LIST_HEAD(&new->fragment_info); | ||
524 | fi = ipv4_frag_new ( new, frag_off, frag_len); | ||
525 | if ( fi == NULL ) | ||
526 | goto fail_w_new; | ||
527 | new->datagram_label = datagram_label; | ||
528 | new->datagram_size = dg_size; | ||
529 | new->skb = dev_alloc_skb(dg_size + netdev->hard_header_len + 15); | ||
530 | if ( new->skb == NULL ) | ||
531 | goto fail_w_fi; | ||
532 | skb_reserve(new->skb, (netdev->hard_header_len + 15) & ~15); | ||
533 | new->pbuf = skb_put(new->skb, dg_size); | ||
534 | memcpy(new->pbuf + frag_off, frag_buf, frag_len); | ||
535 | list_add_tail(&new->pdg_list, &node->pdg_list); | ||
536 | fw_debug ( "pd_new: new pd %p { dgl %u, dg_size %u, skb %p, pbuf %p } on node %p\n", | ||
537 | new, new->datagram_label, new->datagram_size, new->skb, new->pbuf, node ); | ||
538 | return new; | ||
539 | |||
540 | fail_w_fi: | ||
541 | kfree(fi); | ||
542 | fail_w_new: | ||
543 | kfree(new); | ||
544 | fail: | ||
545 | fw_error("ipv4_pd_new: no memory\n"); | ||
546 | return NULL; | ||
547 | } | ||
548 | |||
549 | static struct ipv4_partial_datagram *ipv4_pd_find(struct ipv4_node *node, u16 datagram_label) { | ||
550 | struct ipv4_partial_datagram *pd; | ||
551 | |||
552 | list_for_each_entry(pd, &node->pdg_list, pdg_list) { | ||
553 | if ( pd->datagram_label == datagram_label ) { | ||
554 | fw_debug ( "pd_find(node %p, label %u): pd %p\n", node, datagram_label, pd ); | ||
555 | return pd; | ||
556 | } | ||
557 | } | ||
558 | fw_debug ( "pd_find(node %p, label %u) no entry\n", node, datagram_label ); | ||
559 | return NULL; | ||
560 | } | ||
561 | |||
562 | |||
563 | static void ipv4_pd_delete ( struct ipv4_partial_datagram *old ) { | ||
564 | struct ipv4_fragment_info *fi, *n; | ||
565 | |||
566 | fw_debug ( "pd_delete %p\n", old ); | ||
567 | list_for_each_entry_safe(fi, n, &old->fragment_info, fragment_info) { | ||
568 | fw_debug ( "Freeing fi %p\n", fi ); | ||
569 | kfree(fi); | ||
570 | } | ||
571 | list_del(&old->pdg_list); | ||
572 | dev_kfree_skb_any(old->skb); | ||
573 | kfree(old); | ||
574 | } | ||
575 | |||
576 | static bool ipv4_pd_update ( struct ipv4_node *node, struct ipv4_partial_datagram *pd, | ||
577 | u32 *frag_buf, unsigned frag_off, unsigned frag_len) { | ||
578 | fw_debug ( "pd_update node %p, pd %p, frag_buf %p, %x@%x\n", node, pd, frag_buf, frag_len, frag_off ); | ||
579 | if ( ipv4_frag_new ( pd, frag_off, frag_len ) == NULL) | ||
580 | return false; | ||
581 | memcpy(pd->pbuf + frag_off, frag_buf, frag_len); | ||
582 | |||
583 | /* | ||
584 | * Move list entry to beginnig of list so that oldest partial | ||
585 | * datagrams percolate to the end of the list | ||
586 | */ | ||
587 | list_move_tail(&pd->pdg_list, &node->pdg_list); | ||
588 | fw_debug ( "New pd list:\n" ); | ||
589 | list_for_each_entry ( pd, &node->pdg_list, pdg_list ) { | ||
590 | fw_debug ( "pd %p\n", pd ); | ||
591 | } | ||
592 | return true; | ||
593 | } | ||
594 | |||
595 | static bool ipv4_pd_is_complete ( struct ipv4_partial_datagram *pd ) { | ||
596 | struct ipv4_fragment_info *fi; | ||
597 | bool ret; | ||
598 | |||
599 | fi = list_entry(pd->fragment_info.next, struct ipv4_fragment_info, fragment_info); | ||
600 | |||
601 | ret = (fi->len == pd->datagram_size); | ||
602 | fw_debug ( "pd_is_complete (pd %p, dgs %x): fi %p (%x@%x) %s\n", pd, pd->datagram_size, fi, fi->len, fi->offset, ret ? "yes" : "no" ); | ||
603 | return ret; | ||
604 | } | ||
605 | |||
606 | /* ------------------------------------------------------------------ */ | ||
607 | |||
608 | static int ipv4_node_new ( struct fw_card *card, struct fw_device *device ) { | ||
609 | struct ipv4_node *node; | ||
610 | |||
611 | node = kmalloc ( sizeof(*node), GFP_KERNEL ); | ||
612 | if ( ! node ) { | ||
613 | fw_error ( "allocate new node failed\n" ); | ||
614 | return -ENOMEM; | ||
615 | } | ||
616 | node->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; | ||
617 | node->fifo = INVALID_FIFO_ADDR; | ||
618 | INIT_LIST_HEAD(&node->pdg_list); | ||
619 | spin_lock_init(&node->pdg_lock); | ||
620 | node->pdg_size = 0; | ||
621 | node->generation = device->generation; | ||
622 | rmb(); | ||
623 | node->nodeid = device->node_id; | ||
624 | /* FIXME what should it really be? */ | ||
625 | node->max_payload = S100_BUFFER_SIZE - IPV4_UNFRAG_HDR_SIZE; | ||
626 | node->datagram_label = 0U; | ||
627 | node->xmt_speed = device->max_speed; | ||
628 | list_add_tail ( &node->ipv4_nodes, &card->ipv4_nodes ); | ||
629 | fw_debug ( "node_new: %p { guid %016llx, generation %u, nodeid %x, max_payload %x, xmt_speed %x } added\n", | ||
630 | node, (unsigned long long)node->guid, node->generation, node->nodeid, node->max_payload, node->xmt_speed ); | ||
631 | return 0; | ||
632 | } | ||
633 | |||
634 | static struct ipv4_node *ipv4_node_find_by_guid(struct ipv4_priv *priv, u64 guid) { | ||
635 | struct ipv4_node *node; | ||
636 | unsigned long flags; | ||
637 | |||
638 | spin_lock_irqsave(&priv->lock, flags); | ||
639 | list_for_each_entry(node, &priv->card->ipv4_nodes, ipv4_nodes) | ||
640 | if (node->guid == guid) { | ||
641 | /* FIXME: lock the node first? */ | ||
642 | spin_unlock_irqrestore ( &priv->lock, flags ); | ||
643 | fw_debug ( "node_find_by_guid (%016llx) found %p\n", (unsigned long long)guid, node ); | ||
644 | return node; | ||
645 | } | ||
646 | |||
647 | spin_unlock_irqrestore ( &priv->lock, flags ); | ||
648 | fw_debug ( "node_find_by_guid (%016llx) not found\n", (unsigned long long)guid ); | ||
649 | return NULL; | ||
650 | } | ||
651 | |||
652 | static struct ipv4_node *ipv4_node_find_by_nodeid(struct ipv4_priv *priv, u16 nodeid) { | ||
653 | struct ipv4_node *node; | ||
654 | unsigned long flags; | ||
655 | |||
656 | spin_lock_irqsave(&priv->lock, flags); | ||
657 | list_for_each_entry(node, &priv->card->ipv4_nodes, ipv4_nodes) | ||
658 | if (node->nodeid == nodeid) { | ||
659 | /* FIXME: lock the node first? */ | ||
660 | spin_unlock_irqrestore ( &priv->lock, flags ); | ||
661 | fw_debug ( "node_find_by_nodeid (%x) found %p\n", nodeid, node ); | ||
662 | return node; | ||
663 | } | ||
664 | fw_debug ( "node_find_by_nodeid (%x) not found\n", nodeid ); | ||
665 | spin_unlock_irqrestore ( &priv->lock, flags ); | ||
666 | return NULL; | ||
667 | } | ||
668 | |||
669 | /* This is only complicated because we can't assume priv exists */ | ||
670 | static void ipv4_node_delete ( struct fw_card *card, struct fw_device *device ) { | ||
671 | struct net_device *netdev; | ||
672 | struct ipv4_priv *priv; | ||
673 | struct ipv4_node *node; | ||
674 | u64 guid; | ||
675 | unsigned long flags; | ||
676 | struct ipv4_partial_datagram *pd, *pd_next; | ||
677 | |||
678 | guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; | ||
679 | netdev = card->netdev; | ||
680 | if ( netdev ) | ||
681 | priv = netdev_priv ( netdev ); | ||
682 | else | ||
683 | priv = NULL; | ||
684 | if ( priv ) | ||
685 | spin_lock_irqsave ( &priv->lock, flags ); | ||
686 | list_for_each_entry( node, &card->ipv4_nodes, ipv4_nodes ) { | ||
687 | if ( node->guid == guid ) { | ||
688 | list_del ( &node->ipv4_nodes ); | ||
689 | list_for_each_entry_safe( pd, pd_next, &node->pdg_list, pdg_list ) | ||
690 | ipv4_pd_delete ( pd ); | ||
691 | break; | ||
692 | } | ||
693 | } | ||
694 | if ( priv ) | ||
695 | spin_unlock_irqrestore ( &priv->lock, flags ); | ||
696 | } | ||
697 | |||
698 | /* ------------------------------------------------------------------ */ | ||
699 | |||
700 | |||
701 | static int ipv4_finish_incoming_packet ( struct net_device *netdev, | ||
702 | struct sk_buff *skb, u16 source_node_id, bool is_broadcast, u16 ether_type ) { | ||
703 | struct ipv4_priv *priv; | ||
704 | static u64 broadcast_hw = ~0ULL; | ||
705 | int status; | ||
706 | u64 guid; | ||
707 | |||
708 | fw_debug ( "ipv4_finish_incoming_packet(%p, %p, %x, %s, %x\n", | ||
709 | netdev, skb, source_node_id, is_broadcast ? "true" : "false", ether_type ); | ||
710 | priv = netdev_priv(netdev); | ||
711 | /* Write metadata, and then pass to the receive level */ | ||
712 | skb->dev = netdev; | ||
713 | skb->ip_summed = CHECKSUM_UNNECESSARY; /* don't check it */ | ||
714 | |||
715 | /* | ||
716 | * Parse the encapsulation header. This actually does the job of | ||
717 | * converting to an ethernet frame header, as well as arp | ||
718 | * conversion if needed. ARP conversion is easier in this | ||
719 | * direction, since we are using ethernet as our backend. | ||
720 | */ | ||
721 | /* | ||
722 | * If this is an ARP packet, convert it. First, we want to make | ||
723 | * use of some of the fields, since they tell us a little bit | ||
724 | * about the sending machine. | ||
725 | */ | ||
726 | if (ether_type == ETH_P_ARP) { | ||
727 | struct ipv4_arp *arp1394; | ||
728 | struct arphdr *arp; | ||
729 | unsigned char *arp_ptr; | ||
730 | u64 fifo_addr; | ||
731 | u8 max_rec; | ||
732 | u8 sspd; | ||
733 | u16 max_payload; | ||
734 | struct ipv4_node *node; | ||
735 | static const u16 ipv4_speed_to_max_payload[] = { | ||
736 | /* S100, S200, S400, S800, S1600, S3200 */ | ||
737 | 512, 1024, 2048, 4096, 4096, 4096 | ||
738 | }; | ||
739 | |||
740 | /* fw_debug ( "ARP packet\n" ); */ | ||
741 | arp1394 = (struct ipv4_arp *)skb->data; | ||
742 | arp = (struct arphdr *)skb->data; | ||
743 | arp_ptr = (unsigned char *)(arp + 1); | ||
744 | fifo_addr = (u64)ntohs(arp1394->fifo_hi) << 32 | | ||
745 | ntohl(arp1394->fifo_lo); | ||
746 | max_rec = priv->card->max_receive; | ||
747 | if ( arp1394->max_rec < max_rec ) | ||
748 | max_rec = arp1394->max_rec; | ||
749 | sspd = arp1394->sspd; | ||
750 | /* | ||
751 | * Sanity check. MacOSX seems to be sending us 131 in this | ||
752 | * field (atleast on my Panther G5). Not sure why. | ||
753 | */ | ||
754 | if (sspd > 5 ) { | ||
755 | fw_notify ( "sspd %x out of range\n", sspd ); | ||
756 | sspd = 0; | ||
757 | } | ||
758 | |||
759 | max_payload = min(ipv4_speed_to_max_payload[sspd], | ||
760 | (u16)(1 << (max_rec + 1))) - IPV4_UNFRAG_HDR_SIZE; | ||
761 | |||
762 | guid = be64_to_cpu(get_unaligned(&arp1394->s_uniq_id)); | ||
763 | node = ipv4_node_find_by_guid(priv, guid); | ||
764 | if (!node) { | ||
765 | fw_notify ( "No node for ARP packet from %llx\n", guid ); | ||
766 | goto failed_proto; | ||
767 | } | ||
768 | if ( node->nodeid != source_node_id || node->generation != priv->card->generation ) { | ||
769 | fw_notify ( "Internal error: node->nodeid (%x) != soucre_node_id (%x) or node->generation (%x) != priv->card->generation(%x)\n", | ||
770 | node->nodeid, source_node_id, node->generation, priv->card->generation ); | ||
771 | node->nodeid = source_node_id; | ||
772 | node->generation = priv->card->generation; | ||
773 | } | ||
774 | |||
775 | /* FIXME: for debugging */ | ||
776 | if ( sspd > SCODE_400 ) | ||
777 | sspd = SCODE_400; | ||
778 | /* Update our speed/payload/fifo_offset table */ | ||
779 | /* | ||
780 | * FIXME: this does not handle cases where two high-speed endpoints must use a slower speed because of | ||
781 | * a lower speed hub between them. We need to look at the actual topology map here. | ||
782 | */ | ||
783 | fw_debug ( "Setting node %p fifo %llx (was %llx), max_payload %x (was %x), speed %x (was %x)\n", | ||
784 | node, fifo_addr, node->fifo, max_payload, node->max_payload, sspd, node->xmt_speed ); | ||
785 | node->fifo = fifo_addr; | ||
786 | node->max_payload = max_payload; | ||
787 | /* | ||
788 | * Only allow speeds to go down from their initial value. | ||
789 | * Otherwise a local node that can only do S400 or slower may | ||
790 | * be told to transmit at S800 to a faster remote node. | ||
791 | */ | ||
792 | if ( node->xmt_speed > sspd ) | ||
793 | node->xmt_speed = sspd; | ||
794 | |||
795 | /* | ||
796 | * Now that we're done with the 1394 specific stuff, we'll | ||
797 | * need to alter some of the data. Believe it or not, all | ||
798 | * that needs to be done is sender_IP_address needs to be | ||
799 | * moved, the destination hardware address get stuffed | ||
800 | * in and the hardware address length set to 8. | ||
801 | * | ||
802 | * IMPORTANT: The code below overwrites 1394 specific data | ||
803 | * needed above so keep the munging of the data for the | ||
804 | * higher level IP stack last. | ||
805 | */ | ||
806 | |||
807 | arp->ar_hln = 8; | ||
808 | arp_ptr += arp->ar_hln; /* skip over sender unique id */ | ||
809 | *(u32 *)arp_ptr = arp1394->sip; /* move sender IP addr */ | ||
810 | arp_ptr += arp->ar_pln; /* skip over sender IP addr */ | ||
811 | |||
812 | if (arp->ar_op == htons(ARPOP_REQUEST)) | ||
813 | memset(arp_ptr, 0, sizeof(u64)); | ||
814 | else | ||
815 | memcpy(arp_ptr, netdev->dev_addr, sizeof(u64)); | ||
816 | } | ||
817 | |||
818 | /* Now add the ethernet header. */ | ||
819 | guid = cpu_to_be64(priv->card->guid); | ||
820 | if (dev_hard_header(skb, netdev, ether_type, is_broadcast ? &broadcast_hw : &guid, NULL, | ||
821 | skb->len) >= 0) { | ||
822 | struct ipv4_ether_hdr *eth; | ||
823 | u16 *rawp; | ||
824 | __be16 protocol; | ||
825 | |||
826 | skb_reset_mac_header(skb); | ||
827 | skb_pull(skb, sizeof(*eth)); | ||
828 | eth = ipv4_ether_hdr(skb); | ||
829 | if (*eth->h_dest & 1) { | ||
830 | if (memcmp(eth->h_dest, netdev->broadcast, netdev->addr_len) == 0) { | ||
831 | fw_debug ( "Broadcast\n" ); | ||
832 | skb->pkt_type = PACKET_BROADCAST; | ||
833 | } | ||
834 | #if 0 | ||
835 | else | ||
836 | skb->pkt_type = PACKET_MULTICAST; | ||
837 | #endif | ||
838 | } else { | ||
839 | if (memcmp(eth->h_dest, netdev->dev_addr, netdev->addr_len)) { | ||
840 | u64 a1, a2; | ||
841 | |||
842 | memcpy ( &a1, eth->h_dest, sizeof(u64)); | ||
843 | memcpy ( &a2, netdev->dev_addr, sizeof(u64)); | ||
844 | fw_debug ( "Otherhost %llx %llx %x\n", a1, a2, netdev->addr_len ); | ||
845 | skb->pkt_type = PACKET_OTHERHOST; | ||
846 | } | ||
847 | } | ||
848 | if (ntohs(eth->h_proto) >= 1536) { | ||
849 | fw_debug ( " proto %x %x\n", eth->h_proto, ntohs(eth->h_proto) ); | ||
850 | protocol = eth->h_proto; | ||
851 | } else { | ||
852 | rawp = (u16 *)skb->data; | ||
853 | if (*rawp == 0xFFFF) { | ||
854 | fw_debug ( "proto 802_3\n" ); | ||
855 | protocol = htons(ETH_P_802_3); | ||
856 | } else { | ||
857 | fw_debug ( "proto 802_2\n" ); | ||
858 | protocol = htons(ETH_P_802_2); | ||
859 | } | ||
860 | } | ||
861 | skb->protocol = protocol; | ||
862 | } | ||
863 | status = netif_rx(skb); | ||
864 | if ( status == NET_RX_DROP) { | ||
865 | netdev->stats.rx_errors++; | ||
866 | netdev->stats.rx_dropped++; | ||
867 | } else { | ||
868 | netdev->stats.rx_packets++; | ||
869 | netdev->stats.rx_bytes += skb->len; | ||
870 | } | ||
871 | if (netif_queue_stopped(netdev)) | ||
872 | netif_wake_queue(netdev); | ||
873 | return 0; | ||
874 | |||
875 | failed_proto: | ||
876 | netdev->stats.rx_errors++; | ||
877 | netdev->stats.rx_dropped++; | ||
878 | dev_kfree_skb_any(skb); | ||
879 | if (netif_queue_stopped(netdev)) | ||
880 | netif_wake_queue(netdev); | ||
881 | netdev->last_rx = jiffies; | ||
882 | return 0; | ||
883 | } | ||
884 | |||
885 | /* ------------------------------------------------------------------ */ | ||
886 | |||
887 | static int ipv4_incoming_packet ( struct ipv4_priv *priv, u32 *buf, int len, u16 source_node_id, bool is_broadcast ) { | ||
888 | struct sk_buff *skb; | ||
889 | struct net_device *netdev; | ||
890 | struct ipv4_hdr hdr; | ||
891 | unsigned lf; | ||
892 | unsigned long flags; | ||
893 | struct ipv4_node *node; | ||
894 | struct ipv4_partial_datagram *pd; | ||
895 | int fg_off; | ||
896 | int dg_size; | ||
897 | u16 datagram_label; | ||
898 | int retval; | ||
899 | u16 ether_type; | ||
900 | |||
901 | fw_debug ( "ipv4_incoming_packet(%p, %p, %d, %x, %s)\n", priv, buf, len, source_node_id, is_broadcast ? "true" : "false" ); | ||
902 | netdev = priv->card->netdev; | ||
903 | |||
904 | hdr.w0 = ntohl(buf[0]); | ||
905 | lf = ipv4_get_hdr_lf(&hdr); | ||
906 | if ( lf == IPV4_HDR_UNFRAG ) { | ||
907 | /* | ||
908 | * An unfragmented datagram has been received by the ieee1394 | ||
909 | * bus. Build an skbuff around it so we can pass it to the | ||
910 | * high level network layer. | ||
911 | */ | ||
912 | ether_type = ipv4_get_hdr_ether_type(&hdr); | ||
913 | fw_debug ( "header w0 = %x, lf = %x, ether_type = %x\n", hdr.w0, lf, ether_type ); | ||
914 | buf++; | ||
915 | len -= IPV4_UNFRAG_HDR_SIZE; | ||
916 | |||
917 | skb = dev_alloc_skb(len + netdev->hard_header_len + 15); | ||
918 | if (unlikely(!skb)) { | ||
919 | fw_error ( "Out of memory for incoming packet\n"); | ||
920 | netdev->stats.rx_dropped++; | ||
921 | return -1; | ||
922 | } | ||
923 | skb_reserve(skb, (netdev->hard_header_len + 15) & ~15); | ||
924 | memcpy(skb_put(skb, len), buf, len ); | ||
925 | return ipv4_finish_incoming_packet(netdev, skb, source_node_id, is_broadcast, ether_type ); | ||
926 | } | ||
927 | /* A datagram fragment has been received, now the fun begins. */ | ||
928 | hdr.w1 = ntohl(buf[1]); | ||
929 | buf +=2; | ||
930 | len -= IPV4_FRAG_HDR_SIZE; | ||
931 | if ( lf ==IPV4_HDR_FIRSTFRAG ) { | ||
932 | ether_type = ipv4_get_hdr_ether_type(&hdr); | ||
933 | fg_off = 0; | ||
934 | } else { | ||
935 | fg_off = ipv4_get_hdr_fg_off(&hdr); | ||
936 | ether_type = 0; /* Shut up compiler! */ | ||
937 | } | ||
938 | datagram_label = ipv4_get_hdr_dgl(&hdr); | ||
939 | dg_size = ipv4_get_hdr_dg_size(&hdr); /* ??? + 1 */ | ||
940 | fw_debug ( "fragmented: %x.%x = lf %x, ether_type %x, fg_off %x, dgl %x, dg_size %x\n", hdr.w0, hdr.w1, lf, ether_type, fg_off, datagram_label, dg_size ); | ||
941 | node = ipv4_node_find_by_nodeid ( priv, source_node_id); | ||
942 | spin_lock_irqsave(&node->pdg_lock, flags); | ||
943 | pd = ipv4_pd_find( node, datagram_label ); | ||
944 | if (pd == NULL) { | ||
945 | while ( node->pdg_size >= ipv4_mpd ) { | ||
946 | /* remove the oldest */ | ||
947 | ipv4_pd_delete ( list_first_entry(&node->pdg_list, struct ipv4_partial_datagram, pdg_list) ); | ||
948 | node->pdg_size--; | ||
949 | } | ||
950 | pd = ipv4_pd_new ( netdev, node, datagram_label, dg_size, | ||
951 | buf, fg_off, len); | ||
952 | if ( pd == NULL) { | ||
953 | retval = -ENOMEM; | ||
954 | goto bad_proto; | ||
955 | } | ||
956 | node->pdg_size++; | ||
957 | } else { | ||
958 | if (ipv4_frag_overlap(pd, fg_off, len) || pd->datagram_size != dg_size) { | ||
959 | /* | ||
960 | * Differing datagram sizes or overlapping fragments, | ||
961 | * Either way the remote machine is playing silly buggers | ||
962 | * with us: obliterate the old datagram and start a new one. | ||
963 | */ | ||
964 | ipv4_pd_delete ( pd ); | ||
965 | pd = ipv4_pd_new ( netdev, node, datagram_label, | ||
966 | dg_size, buf, fg_off, len); | ||
967 | if ( pd == NULL ) { | ||
968 | retval = -ENOMEM; | ||
969 | node->pdg_size--; | ||
970 | goto bad_proto; | ||
971 | } | ||
972 | } else { | ||
973 | bool worked; | ||
974 | |||
975 | worked = ipv4_pd_update ( node, pd, | ||
976 | buf, fg_off, len ); | ||
977 | if ( ! worked ) { | ||
978 | /* | ||
979 | * Couldn't save off fragment anyway | ||
980 | * so might as well obliterate the | ||
981 | * datagram now. | ||
982 | */ | ||
983 | ipv4_pd_delete ( pd ); | ||
984 | node->pdg_size--; | ||
985 | goto bad_proto; | ||
986 | } | ||
987 | } | ||
988 | } /* new datagram or add to existing one */ | ||
989 | |||
990 | if ( lf == IPV4_HDR_FIRSTFRAG ) | ||
991 | pd->ether_type = ether_type; | ||
992 | if ( ipv4_pd_is_complete ( pd ) ) { | ||
993 | ether_type = pd->ether_type; | ||
994 | node->pdg_size--; | ||
995 | skb = skb_get(pd->skb); | ||
996 | ipv4_pd_delete ( pd ); | ||
997 | spin_unlock_irqrestore(&node->pdg_lock, flags); | ||
998 | return ipv4_finish_incoming_packet ( netdev, skb, source_node_id, false, ether_type ); | ||
999 | } | ||
1000 | /* | ||
1001 | * Datagram is not complete, we're done for the | ||
1002 | * moment. | ||
1003 | */ | ||
1004 | spin_unlock_irqrestore(&node->pdg_lock, flags); | ||
1005 | return 0; | ||
1006 | |||
1007 | bad_proto: | ||
1008 | spin_unlock_irqrestore(&node->pdg_lock, flags); | ||
1009 | if (netif_queue_stopped(netdev)) | ||
1010 | netif_wake_queue(netdev); | ||
1011 | return 0; | ||
1012 | } | ||
1013 | |||
1014 | static void ipv4_receive_packet ( struct fw_card *card, struct fw_request *r, | ||
1015 | int tcode, int destination, int source, int generation, int speed, | ||
1016 | unsigned long long offset, void *payload, size_t length, void *callback_data ) { | ||
1017 | struct ipv4_priv *priv; | ||
1018 | int status; | ||
1019 | |||
1020 | fw_debug ( "ipv4_receive_packet(%p,%p,%x,%x,%x,%x,%x,%llx,%p,%lx,%p)\n", | ||
1021 | card, r, tcode, destination, source, generation, speed, offset, payload, | ||
1022 | (unsigned long)length, callback_data); | ||
1023 | print_hex_dump ( KERN_DEBUG, "header: ", DUMP_PREFIX_OFFSET, 32, 1, payload, length, false ); | ||
1024 | priv = callback_data; | ||
1025 | if ( tcode != TCODE_WRITE_BLOCK_REQUEST | ||
1026 | || destination != card->node_id | ||
1027 | || generation != card->generation | ||
1028 | || offset != priv->handler.offset ) { | ||
1029 | fw_send_response(card, r, RCODE_CONFLICT_ERROR); | ||
1030 | fw_debug("Conflict error card node_id=%x, card generation=%x, local offset %llx\n", | ||
1031 | card->node_id, card->generation, (unsigned long long)priv->handler.offset ); | ||
1032 | return; | ||
1033 | } | ||
1034 | status = ipv4_incoming_packet ( priv, payload, length, source, false ); | ||
1035 | if ( status != 0 ) { | ||
1036 | fw_error ( "Incoming packet failure\n" ); | ||
1037 | fw_send_response ( card, r, RCODE_CONFLICT_ERROR ); | ||
1038 | return; | ||
1039 | } | ||
1040 | fw_send_response ( card, r, RCODE_COMPLETE ); | ||
1041 | } | ||
1042 | |||
1043 | static void ipv4_receive_broadcast(struct fw_iso_context *context, u32 cycle, | ||
1044 | size_t header_length, void *header, void *data) { | ||
1045 | struct ipv4_priv *priv; | ||
1046 | struct fw_iso_packet packet; | ||
1047 | struct fw_card *card; | ||
1048 | u16 *hdr_ptr; | ||
1049 | u32 *buf_ptr; | ||
1050 | int retval; | ||
1051 | u32 length; | ||
1052 | u16 source_node_id; | ||
1053 | u32 specifier_id; | ||
1054 | u32 ver; | ||
1055 | unsigned long offset; | ||
1056 | unsigned long flags; | ||
1057 | |||
1058 | fw_debug ( "ipv4_receive_broadcast ( context=%p, cycle=%x, header_length=%lx, header=%p, data=%p )\n", context, cycle, (unsigned long)header_length, header, data ); | ||
1059 | print_hex_dump ( KERN_DEBUG, "header: ", DUMP_PREFIX_OFFSET, 32, 1, header, header_length, false ); | ||
1060 | priv = data; | ||
1061 | card = priv->card; | ||
1062 | hdr_ptr = header; | ||
1063 | length = ntohs(hdr_ptr[0]); | ||
1064 | spin_lock_irqsave(&priv->lock,flags); | ||
1065 | offset = priv->rcv_buffer_size * priv->broadcast_rcv_next_ptr; | ||
1066 | buf_ptr = priv->broadcast_rcv_buffer_ptrs[priv->broadcast_rcv_next_ptr++]; | ||
1067 | if ( priv->broadcast_rcv_next_ptr == priv->num_broadcast_rcv_ptrs ) | ||
1068 | priv->broadcast_rcv_next_ptr = 0; | ||
1069 | spin_unlock_irqrestore(&priv->lock,flags); | ||
1070 | fw_debug ( "length %u at %p\n", length, buf_ptr ); | ||
1071 | print_hex_dump ( KERN_DEBUG, "buffer: ", DUMP_PREFIX_OFFSET, 32, 1, buf_ptr, length, false ); | ||
1072 | |||
1073 | specifier_id = (be32_to_cpu(buf_ptr[0]) & 0xffff) << 8 | ||
1074 | | (be32_to_cpu(buf_ptr[1]) & 0xff000000) >> 24; | ||
1075 | ver = be32_to_cpu(buf_ptr[1]) & 0xFFFFFF; | ||
1076 | source_node_id = be32_to_cpu(buf_ptr[0]) >> 16; | ||
1077 | /* fw_debug ( "source %x SpecID %x ver %x\n", source_node_id, specifier_id, ver ); */ | ||
1078 | if ( specifier_id == IPV4_GASP_SPECIFIER_ID && ver == IPV4_GASP_VERSION ) { | ||
1079 | buf_ptr += 2; | ||
1080 | length -= IPV4_GASP_OVERHEAD; | ||
1081 | ipv4_incoming_packet(priv, buf_ptr, length, source_node_id, true); | ||
1082 | } else | ||
1083 | fw_debug ( "Ignoring packet: not GASP\n" ); | ||
1084 | packet.payload_length = priv->rcv_buffer_size; | ||
1085 | packet.interrupt = 1; | ||
1086 | packet.skip = 0; | ||
1087 | packet.tag = 3; | ||
1088 | packet.sy = 0; | ||
1089 | packet.header_length = IPV4_GASP_OVERHEAD; | ||
1090 | spin_lock_irqsave(&priv->lock,flags); | ||
1091 | retval = fw_iso_context_queue ( priv->broadcast_rcv_context, &packet, | ||
1092 | &priv->broadcast_rcv_buffer, offset ); | ||
1093 | spin_unlock_irqrestore(&priv->lock,flags); | ||
1094 | if ( retval < 0 ) | ||
1095 | fw_error ( "requeue failed\n" ); | ||
1096 | } | ||
1097 | |||
1098 | static void debug_ptask ( struct ipv4_packet_task *ptask ) { | ||
1099 | static const char *tx_types[] = { "Unknown", "GASP", "Write" }; | ||
1100 | |||
1101 | fw_debug ( "packet %p { hdr { w0 %x w1 %x }, skb %p, priv %p," | ||
1102 | " tx_type %s, outstanding_pkts %d, max_payload %x, fifo %llx," | ||
1103 | " speed %x, dest_node %x, generation %x }\n", | ||
1104 | ptask, ptask->hdr.w0, ptask->hdr.w1, ptask->skb, ptask->priv, | ||
1105 | ptask->tx_type > IPV4_WRREQ ? "Invalid" : tx_types[ptask->tx_type], | ||
1106 | ptask->outstanding_pkts, ptask->max_payload, | ||
1107 | ptask->fifo_addr, ptask->speed, ptask->dest_node, ptask->generation ); | ||
1108 | print_hex_dump ( KERN_DEBUG, "packet :", DUMP_PREFIX_OFFSET, 32, 1, | ||
1109 | ptask->skb->data, ptask->skb->len, false ); | ||
1110 | } | ||
1111 | |||
1112 | static void ipv4_transmit_packet_done ( struct ipv4_packet_task *ptask ) { | ||
1113 | struct ipv4_priv *priv; | ||
1114 | unsigned long flags; | ||
1115 | |||
1116 | priv = ptask->priv; | ||
1117 | spin_lock_irqsave ( &priv->lock, flags ); | ||
1118 | list_del ( &ptask->packet_list ); | ||
1119 | spin_unlock_irqrestore ( &priv->lock, flags ); | ||
1120 | ptask->outstanding_pkts--; | ||
1121 | if ( ptask->outstanding_pkts > 0 ) { | ||
1122 | u16 dg_size; | ||
1123 | u16 fg_off; | ||
1124 | u16 datagram_label; | ||
1125 | u16 lf; | ||
1126 | struct sk_buff *skb; | ||
1127 | |||
1128 | /* Update the ptask to point to the next fragment and send it */ | ||
1129 | lf = ipv4_get_hdr_lf(&ptask->hdr); | ||
1130 | switch (lf) { | ||
1131 | case IPV4_HDR_LASTFRAG: | ||
1132 | case IPV4_HDR_UNFRAG: | ||
1133 | default: | ||
1134 | fw_error ( "Outstanding packet %x lf %x, header %x,%x\n", ptask->outstanding_pkts, lf, ptask->hdr.w0, ptask->hdr.w1 ); | ||
1135 | BUG(); | ||
1136 | |||
1137 | case IPV4_HDR_FIRSTFRAG: | ||
1138 | /* Set frag type here for future interior fragments */ | ||
1139 | dg_size = ipv4_get_hdr_dg_size(&ptask->hdr); | ||
1140 | fg_off = ptask->max_payload - IPV4_FRAG_HDR_SIZE; | ||
1141 | datagram_label = ipv4_get_hdr_dgl(&ptask->hdr); | ||
1142 | break; | ||
1143 | |||
1144 | case IPV4_HDR_INTFRAG: | ||
1145 | dg_size = ipv4_get_hdr_dg_size(&ptask->hdr); | ||
1146 | fg_off = ipv4_get_hdr_fg_off(&ptask->hdr) + ptask->max_payload - IPV4_FRAG_HDR_SIZE; | ||
1147 | datagram_label = ipv4_get_hdr_dgl(&ptask->hdr); | ||
1148 | break; | ||
1149 | } | ||
1150 | skb = ptask->skb; | ||
1151 | skb_pull ( skb, ptask->max_payload ); | ||
1152 | if ( ptask->outstanding_pkts > 1 ) { | ||
1153 | ipv4_make_sf_hdr ( &ptask->hdr, | ||
1154 | IPV4_HDR_INTFRAG, dg_size, fg_off, datagram_label ); | ||
1155 | } else { | ||
1156 | ipv4_make_sf_hdr ( &ptask->hdr, | ||
1157 | IPV4_HDR_LASTFRAG, dg_size, fg_off, datagram_label ); | ||
1158 | ptask->max_payload = skb->len + IPV4_FRAG_HDR_SIZE; | ||
1159 | |||
1160 | } | ||
1161 | ipv4_send_packet ( ptask ); | ||
1162 | } else { | ||
1163 | dev_kfree_skb_any ( ptask->skb ); | ||
1164 | kmem_cache_free( ipv4_packet_task_cache, ptask ); | ||
1165 | } | ||
1166 | } | ||
1167 | |||
1168 | static void ipv4_write_complete ( struct fw_card *card, int rcode, | ||
1169 | void *payload, size_t length, void *data ) { | ||
1170 | struct ipv4_packet_task *ptask; | ||
1171 | |||
1172 | ptask = data; | ||
1173 | fw_debug ( "ipv4_write_complete ( %p, %x, %p, %lx, %p )\n", | ||
1174 | card, rcode, payload, (unsigned long)length, data ); | ||
1175 | debug_ptask ( ptask ); | ||
1176 | |||
1177 | if ( rcode == RCODE_COMPLETE ) { | ||
1178 | ipv4_transmit_packet_done ( ptask ); | ||
1179 | } else { | ||
1180 | fw_error ( "ipv4_write_complete: failed: %x\n", rcode ); | ||
1181 | /* ??? error recovery */ | ||
1182 | } | ||
1183 | } | ||
1184 | |||
1185 | static int ipv4_send_packet ( struct ipv4_packet_task *ptask ) { | ||
1186 | struct ipv4_priv *priv; | ||
1187 | unsigned tx_len; | ||
1188 | struct ipv4_hdr *bufhdr; | ||
1189 | unsigned long flags; | ||
1190 | struct net_device *netdev; | ||
1191 | #if 0 /* stefanr */ | ||
1192 | int retval; | ||
1193 | #endif | ||
1194 | |||
1195 | fw_debug ( "ipv4_send_packet\n" ); | ||
1196 | debug_ptask ( ptask ); | ||
1197 | priv = ptask->priv; | ||
1198 | tx_len = ptask->max_payload; | ||
1199 | switch (ipv4_get_hdr_lf(&ptask->hdr)) { | ||
1200 | case IPV4_HDR_UNFRAG: | ||
1201 | bufhdr = (struct ipv4_hdr *)skb_push(ptask->skb, IPV4_UNFRAG_HDR_SIZE); | ||
1202 | bufhdr->w0 = htonl(ptask->hdr.w0); | ||
1203 | break; | ||
1204 | |||
1205 | case IPV4_HDR_FIRSTFRAG: | ||
1206 | case IPV4_HDR_INTFRAG: | ||
1207 | case IPV4_HDR_LASTFRAG: | ||
1208 | bufhdr = (struct ipv4_hdr *)skb_push(ptask->skb, IPV4_FRAG_HDR_SIZE); | ||
1209 | bufhdr->w0 = htonl(ptask->hdr.w0); | ||
1210 | bufhdr->w1 = htonl(ptask->hdr.w1); | ||
1211 | break; | ||
1212 | |||
1213 | default: | ||
1214 | BUG(); | ||
1215 | } | ||
1216 | if ( ptask->tx_type == IPV4_GASP ) { | ||
1217 | u32 *packets; | ||
1218 | int generation; | ||
1219 | int nodeid; | ||
1220 | |||
1221 | /* ptask->generation may not have been set yet */ | ||
1222 | generation = priv->card->generation; | ||
1223 | smp_rmb(); | ||
1224 | nodeid = priv->card->node_id; | ||
1225 | packets = (u32 *)skb_push(ptask->skb, sizeof(u32)*2); | ||
1226 | packets[0] = htonl(nodeid << 16 | (IPV4_GASP_SPECIFIER_ID>>8)); | ||
1227 | packets[1] = htonl((IPV4_GASP_SPECIFIER_ID & 0xFF) << 24 | IPV4_GASP_VERSION); | ||
1228 | fw_send_request ( priv->card, &ptask->transaction, TCODE_STREAM_DATA, | ||
1229 | fw_stream_packet_destination_id(3, BROADCAST_CHANNEL, 0), | ||
1230 | generation, SCODE_100, 0ULL, ptask->skb->data, tx_len + 8, ipv4_write_complete, ptask ); | ||
1231 | spin_lock_irqsave(&priv->lock,flags); | ||
1232 | list_add_tail ( &ptask->packet_list, &priv->broadcasted_list ); | ||
1233 | spin_unlock_irqrestore(&priv->lock,flags); | ||
1234 | #if 0 /* stefanr */ | ||
1235 | return retval; | ||
1236 | #else | ||
1237 | return 0; | ||
1238 | #endif | ||
1239 | } | ||
1240 | fw_debug("send_request (%p, %p, WRITE_BLOCK, %x, %x, %x, %llx, %p, %d, %p, %p\n", | ||
1241 | priv->card, &ptask->transaction, ptask->dest_node, ptask->generation, | ||
1242 | ptask->speed, (unsigned long long)ptask->fifo_addr, ptask->skb->data, tx_len, | ||
1243 | ipv4_write_complete, ptask ); | ||
1244 | fw_send_request ( priv->card, &ptask->transaction, | ||
1245 | TCODE_WRITE_BLOCK_REQUEST, ptask->dest_node, ptask->generation, ptask->speed, | ||
1246 | ptask->fifo_addr, ptask->skb->data, tx_len, ipv4_write_complete, ptask ); | ||
1247 | spin_lock_irqsave(&priv->lock,flags); | ||
1248 | list_add_tail ( &ptask->packet_list, &priv->sent_list ); | ||
1249 | spin_unlock_irqrestore(&priv->lock,flags); | ||
1250 | netdev = priv->card->netdev; | ||
1251 | netdev->trans_start = jiffies; | ||
1252 | return 0; | ||
1253 | } | ||
1254 | |||
1255 | static int ipv4_broadcast_start ( struct ipv4_priv *priv ) { | ||
1256 | struct fw_iso_context *context; | ||
1257 | int retval; | ||
1258 | unsigned num_packets; | ||
1259 | unsigned max_receive; | ||
1260 | struct fw_iso_packet packet; | ||
1261 | unsigned long offset; | ||
1262 | unsigned u; | ||
1263 | /* unsigned transmit_speed; */ | ||
1264 | |||
1265 | #if 0 /* stefanr */ | ||
1266 | if ( priv->card->broadcast_channel != (BROADCAST_CHANNEL_VALID|BROADCAST_CHANNEL_INITIAL)) { | ||
1267 | fw_notify ( "Invalid broadcast channel %x\n", priv->card->broadcast_channel ); | ||
1268 | /* FIXME: try again later? */ | ||
1269 | /* return -EINVAL; */ | ||
1270 | } | ||
1271 | #endif | ||
1272 | if ( priv->local_fifo == INVALID_FIFO_ADDR ) { | ||
1273 | struct fw_address_region region; | ||
1274 | |||
1275 | priv->handler.length = FIFO_SIZE; | ||
1276 | priv->handler.address_callback = ipv4_receive_packet; | ||
1277 | priv->handler.callback_data = priv; | ||
1278 | /* FIXME: this is OHCI, but what about others? */ | ||
1279 | region.start = 0xffff00000000ULL; | ||
1280 | region.end = 0xfffffffffffcULL; | ||
1281 | |||
1282 | retval = fw_core_add_address_handler ( &priv->handler, ®ion ); | ||
1283 | if ( retval < 0 ) | ||
1284 | goto failed_initial; | ||
1285 | priv->local_fifo = priv->handler.offset; | ||
1286 | } | ||
1287 | |||
1288 | /* | ||
1289 | * FIXME: rawiso limits us to PAGE_SIZE. This only matters if we ever have | ||
1290 | * a machine with PAGE_SIZE < 4096 | ||
1291 | */ | ||
1292 | max_receive = 1U << (priv->card->max_receive + 1); | ||
1293 | num_packets = ( ipv4_iso_page_count * PAGE_SIZE ) / max_receive; | ||
1294 | if ( ! priv->broadcast_rcv_context ) { | ||
1295 | void **ptrptr; | ||
1296 | |||
1297 | context = fw_iso_context_create ( priv->card, | ||
1298 | FW_ISO_CONTEXT_RECEIVE, BROADCAST_CHANNEL, | ||
1299 | priv->card->link_speed, 8, ipv4_receive_broadcast, priv ); | ||
1300 | if (IS_ERR(context)) { | ||
1301 | retval = PTR_ERR(context); | ||
1302 | goto failed_context_create; | ||
1303 | } | ||
1304 | retval = fw_iso_buffer_init ( &priv->broadcast_rcv_buffer, | ||
1305 | priv->card, ipv4_iso_page_count, DMA_FROM_DEVICE ); | ||
1306 | if ( retval < 0 ) | ||
1307 | goto failed_buffer_init; | ||
1308 | ptrptr = kmalloc ( sizeof(void*)*num_packets, GFP_KERNEL ); | ||
1309 | if ( ! ptrptr ) { | ||
1310 | retval = -ENOMEM; | ||
1311 | goto failed_ptrs_alloc; | ||
1312 | } | ||
1313 | priv->broadcast_rcv_buffer_ptrs = ptrptr; | ||
1314 | for ( u = 0; u < ipv4_iso_page_count; u++ ) { | ||
1315 | void *ptr; | ||
1316 | unsigned v; | ||
1317 | |||
1318 | ptr = kmap ( priv->broadcast_rcv_buffer.pages[u] ); | ||
1319 | for ( v = 0; v < num_packets / ipv4_iso_page_count; v++ ) | ||
1320 | *ptrptr++ = (void *)((char *)ptr + v * max_receive); | ||
1321 | } | ||
1322 | priv->broadcast_rcv_context = context; | ||
1323 | } else | ||
1324 | context = priv->broadcast_rcv_context; | ||
1325 | |||
1326 | packet.payload_length = max_receive; | ||
1327 | packet.interrupt = 1; | ||
1328 | packet.skip = 0; | ||
1329 | packet.tag = 3; | ||
1330 | packet.sy = 0; | ||
1331 | packet.header_length = IPV4_GASP_OVERHEAD; | ||
1332 | offset = 0; | ||
1333 | for ( u = 0; u < num_packets; u++ ) { | ||
1334 | retval = fw_iso_context_queue ( context, &packet, | ||
1335 | &priv->broadcast_rcv_buffer, offset ); | ||
1336 | if ( retval < 0 ) | ||
1337 | goto failed_rcv_queue; | ||
1338 | offset += max_receive; | ||
1339 | } | ||
1340 | priv->num_broadcast_rcv_ptrs = num_packets; | ||
1341 | priv->rcv_buffer_size = max_receive; | ||
1342 | priv->broadcast_rcv_next_ptr = 0U; | ||
1343 | retval = fw_iso_context_start ( context, -1, 0, FW_ISO_CONTEXT_MATCH_ALL_TAGS ); /* ??? sync */ | ||
1344 | if ( retval < 0 ) | ||
1345 | goto failed_rcv_queue; | ||
1346 | /* FIXME: adjust this when we know the max receive speeds of all other IP nodes on the bus. */ | ||
1347 | /* since we only xmt at S100 ??? */ | ||
1348 | priv->broadcast_xmt_max_payload = S100_BUFFER_SIZE - IPV4_GASP_OVERHEAD - IPV4_UNFRAG_HDR_SIZE; | ||
1349 | priv->broadcast_state = IPV4_BROADCAST_RUNNING; | ||
1350 | return 0; | ||
1351 | |||
1352 | failed_rcv_queue: | ||
1353 | kfree ( priv->broadcast_rcv_buffer_ptrs ); | ||
1354 | priv->broadcast_rcv_buffer_ptrs = NULL; | ||
1355 | failed_ptrs_alloc: | ||
1356 | fw_iso_buffer_destroy ( &priv->broadcast_rcv_buffer, priv->card ); | ||
1357 | failed_buffer_init: | ||
1358 | fw_iso_context_destroy ( context ); | ||
1359 | priv->broadcast_rcv_context = NULL; | ||
1360 | failed_context_create: | ||
1361 | fw_core_remove_address_handler ( &priv->handler ); | ||
1362 | failed_initial: | ||
1363 | priv->local_fifo = INVALID_FIFO_ADDR; | ||
1364 | return retval; | ||
1365 | } | ||
1366 | |||
1367 | /* This is called after an "ifup" */ | ||
1368 | static int ipv4_open(struct net_device *dev) { | ||
1369 | struct ipv4_priv *priv; | ||
1370 | int ret; | ||
1371 | |||
1372 | priv = netdev_priv(dev); | ||
1373 | if (priv->broadcast_state == IPV4_BROADCAST_ERROR) { | ||
1374 | ret = ipv4_broadcast_start ( priv ); | ||
1375 | if (ret) | ||
1376 | return ret; | ||
1377 | } | ||
1378 | netif_start_queue(dev); | ||
1379 | return 0; | ||
1380 | } | ||
1381 | |||
1382 | /* This is called after an "ifdown" */ | ||
1383 | static int ipv4_stop(struct net_device *netdev) | ||
1384 | { | ||
1385 | /* flush priv->wake */ | ||
1386 | /* flush_scheduled_work(); */ | ||
1387 | |||
1388 | netif_stop_queue(netdev); | ||
1389 | return 0; | ||
1390 | } | ||
1391 | |||
1392 | /* Transmit a packet (called by kernel) */ | ||
1393 | static int ipv4_tx(struct sk_buff *skb, struct net_device *netdev) | ||
1394 | { | ||
1395 | struct ipv4_ether_hdr hdr_buf; | ||
1396 | struct ipv4_priv *priv = netdev_priv(netdev); | ||
1397 | __be16 proto; | ||
1398 | u16 dest_node; | ||
1399 | enum ipv4_tx_type tx_type; | ||
1400 | unsigned max_payload; | ||
1401 | u16 dg_size; | ||
1402 | u16 *datagram_label_ptr; | ||
1403 | struct ipv4_packet_task *ptask; | ||
1404 | struct ipv4_node *node = NULL; | ||
1405 | |||
1406 | ptask = kmem_cache_alloc(ipv4_packet_task_cache, GFP_ATOMIC); | ||
1407 | if (ptask == NULL) | ||
1408 | goto fail; | ||
1409 | |||
1410 | skb = skb_share_check(skb, GFP_ATOMIC); | ||
1411 | if (!skb) | ||
1412 | goto fail; | ||
1413 | |||
1414 | /* | ||
1415 | * Get rid of the fake ipv4 header, but first make a copy. | ||
1416 | * We might need to rebuild the header on tx failure. | ||
1417 | */ | ||
1418 | memcpy(&hdr_buf, skb->data, sizeof(hdr_buf)); | ||
1419 | skb_pull(skb, sizeof(hdr_buf)); | ||
1420 | |||
1421 | proto = hdr_buf.h_proto; | ||
1422 | dg_size = skb->len; | ||
1423 | |||
1424 | /* | ||
1425 | * Set the transmission type for the packet. ARP packets and IP | ||
1426 | * broadcast packets are sent via GASP. | ||
1427 | */ | ||
1428 | if ( memcmp(hdr_buf.h_dest, netdev->broadcast, IPV4_ALEN) == 0 | ||
1429 | || proto == htons(ETH_P_ARP) | ||
1430 | || ( proto == htons(ETH_P_IP) | ||
1431 | && IN_MULTICAST(ntohl(ip_hdr(skb)->daddr)) ) ) { | ||
1432 | /* fw_debug ( "transmitting arp or multicast packet\n" );*/ | ||
1433 | tx_type = IPV4_GASP; | ||
1434 | dest_node = ALL_NODES; | ||
1435 | max_payload = priv->broadcast_xmt_max_payload; | ||
1436 | /* BUG_ON(max_payload < S100_BUFFER_SIZE - IPV4_GASP_OVERHEAD); */ | ||
1437 | datagram_label_ptr = &priv->broadcast_xmt_datagramlabel; | ||
1438 | ptask->fifo_addr = INVALID_FIFO_ADDR; | ||
1439 | ptask->generation = 0U; | ||
1440 | ptask->dest_node = 0U; | ||
1441 | ptask->speed = 0; | ||
1442 | } else { | ||
1443 | __be64 guid = get_unaligned((u64 *)hdr_buf.h_dest); | ||
1444 | u8 generation; | ||
1445 | |||
1446 | node = ipv4_node_find_by_guid(priv, be64_to_cpu(guid)); | ||
1447 | if (!node) { | ||
1448 | fw_debug ( "Normal packet but no node\n" ); | ||
1449 | goto fail; | ||
1450 | } | ||
1451 | |||
1452 | if (node->fifo == INVALID_FIFO_ADDR) { | ||
1453 | fw_debug ( "Normal packet but no fifo addr\n" ); | ||
1454 | goto fail; | ||
1455 | } | ||
1456 | |||
1457 | /* fw_debug ( "Transmitting normal packet to %x at %llxx\n", node->nodeid, node->fifo ); */ | ||
1458 | generation = node->generation; | ||
1459 | dest_node = node->nodeid; | ||
1460 | max_payload = node->max_payload; | ||
1461 | /* BUG_ON(max_payload < S100_BUFFER_SIZE - IPV4_FRAG_HDR_SIZE); */ | ||
1462 | |||
1463 | datagram_label_ptr = &node->datagram_label; | ||
1464 | tx_type = IPV4_WRREQ; | ||
1465 | ptask->fifo_addr = node->fifo; | ||
1466 | ptask->generation = generation; | ||
1467 | ptask->dest_node = dest_node; | ||
1468 | ptask->speed = node->xmt_speed; | ||
1469 | } | ||
1470 | |||
1471 | /* If this is an ARP packet, convert it */ | ||
1472 | if (proto == htons(ETH_P_ARP)) { | ||
1473 | /* Convert a standard ARP packet to 1394 ARP. The first 8 bytes (the entire | ||
1474 | * arphdr) is the same format as the ip1394 header, so they overlap. The rest | ||
1475 | * needs to be munged a bit. The remainder of the arphdr is formatted based | ||
1476 | * on hwaddr len and ipaddr len. We know what they'll be, so it's easy to | ||
1477 | * judge. | ||
1478 | * | ||
1479 | * Now that the EUI is used for the hardware address all we need to do to make | ||
1480 | * this work for 1394 is to insert 2 quadlets that contain max_rec size, | ||
1481 | * speed, and unicast FIFO address information between the sender_unique_id | ||
1482 | * and the IP addresses. | ||
1483 | */ | ||
1484 | struct arphdr *arp = (struct arphdr *)skb->data; | ||
1485 | unsigned char *arp_ptr = (unsigned char *)(arp + 1); | ||
1486 | struct ipv4_arp *arp1394 = (struct ipv4_arp *)skb->data; | ||
1487 | u32 ipaddr; | ||
1488 | |||
1489 | ipaddr = *(u32*)(arp_ptr + IPV4_ALEN); | ||
1490 | arp1394->hw_addr_len = 16; | ||
1491 | arp1394->max_rec = priv->card->max_receive; | ||
1492 | arp1394->sspd = priv->card->link_speed; | ||
1493 | arp1394->fifo_hi = htons(priv->local_fifo >> 32); | ||
1494 | arp1394->fifo_lo = htonl(priv->local_fifo & 0xFFFFFFFF); | ||
1495 | arp1394->sip = ipaddr; | ||
1496 | } | ||
1497 | if ( ipv4_max_xmt && max_payload > ipv4_max_xmt ) | ||
1498 | max_payload = ipv4_max_xmt; | ||
1499 | |||
1500 | ptask->hdr.w0 = 0; | ||
1501 | ptask->hdr.w1 = 0; | ||
1502 | ptask->skb = skb; | ||
1503 | ptask->priv = priv; | ||
1504 | ptask->tx_type = tx_type; | ||
1505 | /* Does it all fit in one packet? */ | ||
1506 | if ( dg_size <= max_payload ) { | ||
1507 | ipv4_make_uf_hdr(&ptask->hdr, be16_to_cpu(proto)); | ||
1508 | ptask->outstanding_pkts = 1; | ||
1509 | max_payload = dg_size + IPV4_UNFRAG_HDR_SIZE; | ||
1510 | } else { | ||
1511 | u16 datagram_label; | ||
1512 | |||
1513 | max_payload -= IPV4_FRAG_OVERHEAD; | ||
1514 | datagram_label = (*datagram_label_ptr)++; | ||
1515 | ipv4_make_ff_hdr(&ptask->hdr, be16_to_cpu(proto), dg_size, datagram_label ); | ||
1516 | ptask->outstanding_pkts = DIV_ROUND_UP(dg_size, max_payload); | ||
1517 | max_payload += IPV4_FRAG_HDR_SIZE; | ||
1518 | } | ||
1519 | ptask->max_payload = max_payload; | ||
1520 | ipv4_send_packet ( ptask ); | ||
1521 | return NETDEV_TX_OK; | ||
1522 | |||
1523 | fail: | ||
1524 | if (ptask) | ||
1525 | kmem_cache_free(ipv4_packet_task_cache, ptask); | ||
1526 | |||
1527 | if (skb != NULL) | ||
1528 | dev_kfree_skb(skb); | ||
1529 | |||
1530 | netdev->stats.tx_dropped++; | ||
1531 | netdev->stats.tx_errors++; | ||
1532 | |||
1533 | /* | ||
1534 | * FIXME: According to a patch from 2003-02-26, "returning non-zero | ||
1535 | * causes serious problems" here, allegedly. Before that patch, | ||
1536 | * -ERRNO was returned which is not appropriate under Linux 2.6. | ||
1537 | * Perhaps more needs to be done? Stop the queue in serious | ||
1538 | * conditions and restart it elsewhere? | ||
1539 | */ | ||
1540 | return NETDEV_TX_OK; | ||
1541 | } | ||
1542 | |||
1543 | /* | ||
1544 | * FIXME: What to do if we timeout? I think a host reset is probably in order, | ||
1545 | * so that's what we do. Should we increment the stat counters too? | ||
1546 | */ | ||
1547 | static void ipv4_tx_timeout(struct net_device *dev) { | ||
1548 | struct ipv4_priv *priv; | ||
1549 | |||
1550 | priv = netdev_priv(dev); | ||
1551 | fw_error ( "%s: Timeout, resetting host\n", dev->name ); | ||
1552 | #if 0 /* stefanr */ | ||
1553 | fw_core_initiate_bus_reset ( priv->card, 1 ); | ||
1554 | #endif | ||
1555 | } | ||
1556 | |||
1557 | static int ipv4_change_mtu ( struct net_device *dev, int new_mtu ) { | ||
1558 | #if 0 | ||
1559 | int max_mtu; | ||
1560 | struct ipv4_priv *priv; | ||
1561 | #endif | ||
1562 | |||
1563 | if (new_mtu < 68) | ||
1564 | return -EINVAL; | ||
1565 | |||
1566 | #if 0 | ||
1567 | priv = netdev_priv(dev); | ||
1568 | /* This is not actually true because we can fragment packets at the firewire layer */ | ||
1569 | max_mtu = (1 << (priv->card->max_receive + 1)) | ||
1570 | - sizeof(struct ipv4_hdr) - IPV4_GASP_OVERHEAD; | ||
1571 | if (new_mtu > max_mtu) { | ||
1572 | fw_notify ( "%s: Local node constrains MTU to %d\n", dev->name, max_mtu); | ||
1573 | return -ERANGE; | ||
1574 | } | ||
1575 | #endif | ||
1576 | dev->mtu = new_mtu; | ||
1577 | return 0; | ||
1578 | } | ||
1579 | |||
1580 | static void ipv4_get_drvinfo(struct net_device *dev, | ||
1581 | struct ethtool_drvinfo *info) { | ||
1582 | strcpy(info->driver, ipv4_driver_name); | ||
1583 | strcpy(info->bus_info, "ieee1394"); /* FIXME provide more detail? */ | ||
1584 | } | ||
1585 | |||
1586 | static struct ethtool_ops ipv4_ethtool_ops = { | ||
1587 | .get_drvinfo = ipv4_get_drvinfo, | ||
1588 | }; | ||
1589 | |||
1590 | static const struct net_device_ops ipv4_netdev_ops = { | ||
1591 | .ndo_open = ipv4_open, | ||
1592 | .ndo_stop = ipv4_stop, | ||
1593 | .ndo_start_xmit = ipv4_tx, | ||
1594 | .ndo_tx_timeout = ipv4_tx_timeout, | ||
1595 | .ndo_change_mtu = ipv4_change_mtu, | ||
1596 | }; | ||
1597 | |||
1598 | static void ipv4_init_dev ( struct net_device *dev ) { | ||
1599 | dev->header_ops = &ipv4_header_ops; | ||
1600 | dev->netdev_ops = &ipv4_netdev_ops; | ||
1601 | SET_ETHTOOL_OPS(dev, &ipv4_ethtool_ops); | ||
1602 | |||
1603 | dev->watchdog_timeo = IPV4_TIMEOUT; | ||
1604 | dev->flags = IFF_BROADCAST | IFF_MULTICAST; | ||
1605 | dev->features = NETIF_F_HIGHDMA; | ||
1606 | dev->addr_len = IPV4_ALEN; | ||
1607 | dev->hard_header_len = IPV4_HLEN; | ||
1608 | dev->type = ARPHRD_IEEE1394; | ||
1609 | |||
1610 | /* FIXME: This value was copied from ether_setup(). Is it too much? */ | ||
1611 | dev->tx_queue_len = 1000; | ||
1612 | } | ||
1613 | |||
1614 | static int ipv4_probe ( struct device *dev ) { | ||
1615 | struct fw_unit * unit; | ||
1616 | struct fw_device *device; | ||
1617 | struct fw_card *card; | ||
1618 | struct net_device *netdev; | ||
1619 | struct ipv4_priv *priv; | ||
1620 | unsigned max_mtu; | ||
1621 | __be64 guid; | ||
1622 | |||
1623 | fw_debug("ipv4 Probing\n" ); | ||
1624 | unit = fw_unit ( dev ); | ||
1625 | device = fw_device ( unit->device.parent ); | ||
1626 | card = device->card; | ||
1627 | |||
1628 | if ( ! device->is_local ) { | ||
1629 | int added; | ||
1630 | |||
1631 | fw_debug ( "Non-local, adding remote node entry\n" ); | ||
1632 | added = ipv4_node_new ( card, device ); | ||
1633 | return added; | ||
1634 | } | ||
1635 | fw_debug("ipv4 Local: adding netdev\n" ); | ||
1636 | netdev = alloc_netdev ( sizeof(*priv), "firewire%d", ipv4_init_dev ); | ||
1637 | if ( netdev == NULL) { | ||
1638 | fw_error( "Out of memory\n"); | ||
1639 | goto out; | ||
1640 | } | ||
1641 | |||
1642 | SET_NETDEV_DEV(netdev, card->device); | ||
1643 | priv = netdev_priv(netdev); | ||
1644 | |||
1645 | spin_lock_init(&priv->lock); | ||
1646 | priv->broadcast_state = IPV4_BROADCAST_ERROR; | ||
1647 | priv->broadcast_rcv_context = NULL; | ||
1648 | priv->broadcast_xmt_max_payload = 0; | ||
1649 | priv->broadcast_xmt_datagramlabel = 0; | ||
1650 | |||
1651 | priv->local_fifo = INVALID_FIFO_ADDR; | ||
1652 | |||
1653 | /* INIT_WORK(&priv->wake, ipv4_handle_queue);*/ | ||
1654 | INIT_LIST_HEAD(&priv->packet_list); | ||
1655 | INIT_LIST_HEAD(&priv->broadcasted_list); | ||
1656 | INIT_LIST_HEAD(&priv->sent_list ); | ||
1657 | |||
1658 | priv->card = card; | ||
1659 | |||
1660 | /* | ||
1661 | * Use the RFC 2734 default 1500 octets or the maximum payload | ||
1662 | * as initial MTU | ||
1663 | */ | ||
1664 | max_mtu = (1 << (card->max_receive + 1)) | ||
1665 | - sizeof(struct ipv4_hdr) - IPV4_GASP_OVERHEAD; | ||
1666 | netdev->mtu = min(1500U, max_mtu); | ||
1667 | |||
1668 | /* Set our hardware address while we're at it */ | ||
1669 | guid = cpu_to_be64(card->guid); | ||
1670 | memcpy(netdev->dev_addr, &guid, sizeof(u64)); | ||
1671 | memset(netdev->broadcast, 0xff, sizeof(u64)); | ||
1672 | if ( register_netdev ( netdev ) ) { | ||
1673 | fw_error ( "Cannot register the driver\n"); | ||
1674 | goto out; | ||
1675 | } | ||
1676 | |||
1677 | fw_notify ( "%s: IPv4 over Firewire on device %016llx\n", | ||
1678 | netdev->name, card->guid ); | ||
1679 | card->netdev = netdev; | ||
1680 | |||
1681 | return 0 /* ipv4_new_node ( ud ) */; | ||
1682 | out: | ||
1683 | if ( netdev ) | ||
1684 | free_netdev ( netdev ); | ||
1685 | return -ENOENT; | ||
1686 | } | ||
1687 | |||
1688 | |||
1689 | static int ipv4_remove ( struct device *dev ) { | ||
1690 | struct fw_unit * unit; | ||
1691 | struct fw_device *device; | ||
1692 | struct fw_card *card; | ||
1693 | struct net_device *netdev; | ||
1694 | struct ipv4_priv *priv; | ||
1695 | struct ipv4_node *node; | ||
1696 | struct ipv4_partial_datagram *pd, *pd_next; | ||
1697 | struct ipv4_packet_task *ptask, *pt_next; | ||
1698 | |||
1699 | fw_debug("ipv4 Removing\n" ); | ||
1700 | unit = fw_unit ( dev ); | ||
1701 | device = fw_device ( unit->device.parent ); | ||
1702 | card = device->card; | ||
1703 | |||
1704 | if ( ! device->is_local ) { | ||
1705 | fw_debug ( "Node %x is non-local, removing remote node entry\n", device->node_id ); | ||
1706 | ipv4_node_delete ( card, device ); | ||
1707 | return 0; | ||
1708 | } | ||
1709 | netdev = card->netdev; | ||
1710 | if ( netdev ) { | ||
1711 | fw_debug ( "Node %x is local: deleting netdev\n", device->node_id ); | ||
1712 | priv = netdev_priv ( netdev ); | ||
1713 | unregister_netdev ( netdev ); | ||
1714 | fw_debug ( "unregistered\n" ); | ||
1715 | if ( priv->local_fifo != INVALID_FIFO_ADDR ) | ||
1716 | fw_core_remove_address_handler ( &priv->handler ); | ||
1717 | fw_debug ( "address handler gone\n" ); | ||
1718 | if ( priv->broadcast_rcv_context ) { | ||
1719 | fw_iso_context_stop ( priv->broadcast_rcv_context ); | ||
1720 | fw_iso_buffer_destroy ( &priv->broadcast_rcv_buffer, priv->card ); | ||
1721 | fw_iso_context_destroy ( priv->broadcast_rcv_context ); | ||
1722 | fw_debug ( "rcv stopped\n" ); | ||
1723 | } | ||
1724 | list_for_each_entry_safe( ptask, pt_next, &priv->packet_list, packet_list ) { | ||
1725 | dev_kfree_skb_any ( ptask->skb ); | ||
1726 | kmem_cache_free( ipv4_packet_task_cache, ptask ); | ||
1727 | } | ||
1728 | list_for_each_entry_safe( ptask, pt_next, &priv->broadcasted_list, packet_list ) { | ||
1729 | dev_kfree_skb_any ( ptask->skb ); | ||
1730 | kmem_cache_free( ipv4_packet_task_cache, ptask ); | ||
1731 | } | ||
1732 | list_for_each_entry_safe( ptask, pt_next, &priv->sent_list, packet_list ) { | ||
1733 | dev_kfree_skb_any ( ptask->skb ); | ||
1734 | kmem_cache_free( ipv4_packet_task_cache, ptask ); | ||
1735 | } | ||
1736 | fw_debug ( "lists emptied\n" ); | ||
1737 | list_for_each_entry( node, &card->ipv4_nodes, ipv4_nodes ) { | ||
1738 | if ( node->pdg_size ) { | ||
1739 | list_for_each_entry_safe( pd, pd_next, &node->pdg_list, pdg_list ) | ||
1740 | ipv4_pd_delete ( pd ); | ||
1741 | node->pdg_size = 0; | ||
1742 | } | ||
1743 | node->fifo = INVALID_FIFO_ADDR; | ||
1744 | } | ||
1745 | fw_debug ( "nodes cleaned up\n" ); | ||
1746 | free_netdev ( netdev ); | ||
1747 | card->netdev = NULL; | ||
1748 | fw_debug ( "done\n" ); | ||
1749 | } | ||
1750 | return 0; | ||
1751 | } | ||
1752 | |||
1753 | static void ipv4_update ( struct fw_unit *unit ) { | ||
1754 | struct fw_device *device; | ||
1755 | struct fw_card *card; | ||
1756 | |||
1757 | fw_debug ( "ipv4_update unit %p\n", unit ); | ||
1758 | device = fw_device ( unit->device.parent ); | ||
1759 | card = device->card; | ||
1760 | if ( ! device->is_local ) { | ||
1761 | struct ipv4_node *node; | ||
1762 | u64 guid; | ||
1763 | struct net_device *netdev; | ||
1764 | struct ipv4_priv *priv; | ||
1765 | |||
1766 | netdev = card->netdev; | ||
1767 | if ( netdev ) { | ||
1768 | priv = netdev_priv ( netdev ); | ||
1769 | guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; | ||
1770 | node = ipv4_node_find_by_guid ( priv, guid ); | ||
1771 | if ( ! node ) { | ||
1772 | fw_error ( "ipv4_update: no node for device %llx\n", guid ); | ||
1773 | return; | ||
1774 | } | ||
1775 | fw_debug ( "Non-local, updating remote node entry for guid %llx old generation %x, old nodeid %x\n", guid, node->generation, node->nodeid ); | ||
1776 | node->generation = device->generation; | ||
1777 | rmb(); | ||
1778 | node->nodeid = device->node_id; | ||
1779 | fw_debug ( "New generation %x, new nodeid %x\n", node->generation, node->nodeid ); | ||
1780 | } else | ||
1781 | fw_error ( "nonlocal, but no netdev? How can that be?\n" ); | ||
1782 | } else { | ||
1783 | /* FIXME: What do we need to do on bus reset? */ | ||
1784 | fw_debug ( "Local, doing nothing\n" ); | ||
1785 | } | ||
1786 | } | ||
1787 | |||
1788 | static struct fw_driver ipv4_driver = { | ||
1789 | .driver = { | ||
1790 | .owner = THIS_MODULE, | ||
1791 | .name = ipv4_driver_name, | ||
1792 | .bus = &fw_bus_type, | ||
1793 | .probe = ipv4_probe, | ||
1794 | .remove = ipv4_remove, | ||
1795 | }, | ||
1796 | .update = ipv4_update, | ||
1797 | .id_table = ipv4_id_table, | ||
1798 | }; | ||
1799 | |||
1800 | static int __init ipv4_init ( void ) { | ||
1801 | int added; | ||
1802 | |||
1803 | added = fw_core_add_descriptor ( &ipv4_unit_directory ); | ||
1804 | if ( added < 0 ) | ||
1805 | fw_error ( "Failed to add descriptor" ); | ||
1806 | ipv4_packet_task_cache = kmem_cache_create("packet_task", | ||
1807 | sizeof(struct ipv4_packet_task), 0, 0, NULL); | ||
1808 | fw_debug("Adding ipv4 module\n" ); | ||
1809 | return driver_register ( &ipv4_driver.driver ); | ||
1810 | } | ||
1811 | |||
1812 | static void __exit ipv4_cleanup ( void ) { | ||
1813 | fw_core_remove_descriptor ( &ipv4_unit_directory ); | ||
1814 | fw_debug("Removing ipv4 module\n" ); | ||
1815 | driver_unregister ( &ipv4_driver.driver ); | ||
1816 | } | ||
1817 | |||
1818 | module_init(ipv4_init); | ||
1819 | module_exit(ipv4_cleanup); | ||