2 * IPv4 over IEEE 1394, per RFC 2734
4 * Copyright (C) 2009 Jay Fenlason <fenlason@redhat.com>
6 * based on eth1394 by Ben Collins et al
10 #include <linux/compiler.h>
11 #include <linux/delay.h>
12 #include <linux/device.h>
13 #include <linux/ethtool.h>
14 #include <linux/firewire.h>
15 #include <linux/firewire-constants.h>
16 #include <linux/highmem.h>
19 #include <linux/jiffies.h>
20 #include <linux/mod_devicetable.h>
21 #include <linux/module.h>
22 #include <linux/moduleparam.h>
23 #include <linux/mutex.h>
24 #include <linux/netdevice.h>
25 #include <linux/skbuff.h>
26 #include <linux/slab.h>
27 #include <linux/spinlock.h>
29 #include <asm/unaligned.h>
31 #include <net/firewire.h>
34 #define FWNET_MAX_FRAGMENTS 30 /* arbitrary, > TX queue depth */
35 #define FWNET_ISO_PAGE_COUNT (PAGE_SIZE < 16*1024 ? 4 : 2)
38 #define FWNET_MAX_QUEUED_DATAGRAMS 20 /* < 64 = number of tlabels */
39 #define FWNET_MIN_QUEUED_DATAGRAMS 10 /* should keep AT DMA busy enough */
40 #define FWNET_TX_QUEUE_LEN FWNET_MAX_QUEUED_DATAGRAMS /* ? */
42 #define IEEE1394_BROADCAST_CHANNEL 31
43 #define IEEE1394_ALL_NODES (0xffc0 | 0x003f)
44 #define IEEE1394_MAX_PAYLOAD_S100 512
45 #define FWNET_NO_FIFO_ADDR (~0ULL)
47 #define IANA_SPECIFIER_ID 0x00005eU
48 #define RFC2734_SW_VERSION 0x000001U
50 #define IEEE1394_GASP_HDR_SIZE 8
52 #define RFC2374_UNFRAG_HDR_SIZE 4
53 #define RFC2374_FRAG_HDR_SIZE 8
54 #define RFC2374_FRAG_OVERHEAD 4
56 #define RFC2374_HDR_UNFRAG 0 /* unfragmented */
57 #define RFC2374_HDR_FIRSTFRAG 1 /* first fragment */
58 #define RFC2374_HDR_LASTFRAG 2 /* last fragment */
59 #define RFC2374_HDR_INTFRAG 3 /* interior fragment */
61 static bool fwnet_hwaddr_is_multicast(u8
*ha
)
66 /* IPv4 and IPv6 encapsulation header */
67 struct rfc2734_header
{
72 #define fwnet_get_hdr_lf(h) (((h)->w0 & 0xc0000000) >> 30)
73 #define fwnet_get_hdr_ether_type(h) (((h)->w0 & 0x0000ffff))
74 #define fwnet_get_hdr_dg_size(h) (((h)->w0 & 0x0fff0000) >> 16)
75 #define fwnet_get_hdr_fg_off(h) (((h)->w0 & 0x00000fff))
76 #define fwnet_get_hdr_dgl(h) (((h)->w1 & 0xffff0000) >> 16)
78 #define fwnet_set_hdr_lf(lf) ((lf) << 30)
79 #define fwnet_set_hdr_ether_type(et) (et)
80 #define fwnet_set_hdr_dg_size(dgs) ((dgs) << 16)
81 #define fwnet_set_hdr_fg_off(fgo) (fgo)
83 #define fwnet_set_hdr_dgl(dgl) ((dgl) << 16)
85 static inline void fwnet_make_uf_hdr(struct rfc2734_header
*hdr
,
88 hdr
->w0
= fwnet_set_hdr_lf(RFC2374_HDR_UNFRAG
)
89 | fwnet_set_hdr_ether_type(ether_type
);
92 static inline void fwnet_make_ff_hdr(struct rfc2734_header
*hdr
,
93 unsigned ether_type
, unsigned dg_size
, unsigned dgl
)
95 hdr
->w0
= fwnet_set_hdr_lf(RFC2374_HDR_FIRSTFRAG
)
96 | fwnet_set_hdr_dg_size(dg_size
)
97 | fwnet_set_hdr_ether_type(ether_type
);
98 hdr
->w1
= fwnet_set_hdr_dgl(dgl
);
101 static inline void fwnet_make_sf_hdr(struct rfc2734_header
*hdr
,
102 unsigned lf
, unsigned dg_size
, unsigned fg_off
, unsigned dgl
)
104 hdr
->w0
= fwnet_set_hdr_lf(lf
)
105 | fwnet_set_hdr_dg_size(dg_size
)
106 | fwnet_set_hdr_fg_off(fg_off
);
107 hdr
->w1
= fwnet_set_hdr_dgl(dgl
);
110 /* This list keeps track of what parts of the datagram have been filled in */
111 struct fwnet_fragment_info
{
112 struct list_head fi_link
;
117 struct fwnet_partial_datagram
{
118 struct list_head pd_link
;
119 struct list_head fi_list
;
121 /* FIXME Why not use skb->data? */
128 static DEFINE_MUTEX(fwnet_device_mutex
);
129 static LIST_HEAD(fwnet_device_list
);
131 struct fwnet_device
{
132 struct list_head dev_link
;
135 FWNET_BROADCAST_ERROR
,
136 FWNET_BROADCAST_RUNNING
,
137 FWNET_BROADCAST_STOPPED
,
139 struct fw_iso_context
*broadcast_rcv_context
;
140 struct fw_iso_buffer broadcast_rcv_buffer
;
141 void **broadcast_rcv_buffer_ptrs
;
142 unsigned broadcast_rcv_next_ptr
;
143 unsigned num_broadcast_rcv_ptrs
;
144 unsigned rcv_buffer_size
;
146 * This value is the maximum unfragmented datagram size that can be
147 * sent by the hardware. It already has the GASP overhead and the
148 * unfragmented datagram header overhead calculated into it.
150 unsigned broadcast_xmt_max_payload
;
151 u16 broadcast_xmt_datagramlabel
;
154 * The CSR address that remote nodes must send datagrams to for us to
157 struct fw_address_handler handler
;
160 /* Number of tx datagrams that have been queued but not yet acked */
161 int queued_datagrams
;
164 struct list_head peer_list
;
165 struct fw_card
*card
;
166 struct net_device
*netdev
;
170 struct list_head peer_link
;
171 struct fwnet_device
*dev
;
174 /* guarded by dev->lock */
175 struct list_head pd_list
; /* received partial datagrams */
176 unsigned pdg_size
; /* pd_list size */
178 u16 datagram_label
; /* outgoing datagram label */
179 u16 max_payload
; /* includes RFC2374_FRAG_HDR_SIZE overhead */
185 /* This is our task struct. It's used for the packet complete callback. */
186 struct fwnet_packet_task
{
187 struct fw_transaction transaction
;
188 struct rfc2734_header hdr
;
190 struct fwnet_device
*dev
;
192 int outstanding_pkts
;
202 * Get fifo address embedded in hwaddr
204 static __u64
fwnet_hwaddr_fifo(union fwnet_hwaddr
*ha
)
206 return (u64
)get_unaligned_be16(&ha
->uc
.fifo_hi
) << 32
207 | get_unaligned_be32(&ha
->uc
.fifo_lo
);
211 * saddr == NULL means use device source address.
212 * daddr == NULL means leave destination address (eg unresolved arp).
214 static int fwnet_header_create(struct sk_buff
*skb
, struct net_device
*net
,
215 unsigned short type
, const void *daddr
,
216 const void *saddr
, unsigned len
)
218 struct fwnet_header
*h
;
220 h
= (struct fwnet_header
*)skb_push(skb
, sizeof(*h
));
221 put_unaligned_be16(type
, &h
->h_proto
);
223 if (net
->flags
& (IFF_LOOPBACK
| IFF_NOARP
)) {
224 memset(h
->h_dest
, 0, net
->addr_len
);
226 return net
->hard_header_len
;
230 memcpy(h
->h_dest
, daddr
, net
->addr_len
);
232 return net
->hard_header_len
;
235 return -net
->hard_header_len
;
238 static int fwnet_header_rebuild(struct sk_buff
*skb
)
240 struct fwnet_header
*h
= (struct fwnet_header
*)skb
->data
;
242 if (get_unaligned_be16(&h
->h_proto
) == ETH_P_IP
)
243 return arp_find((unsigned char *)&h
->h_dest
, skb
);
245 dev_notice(&skb
->dev
->dev
, "unable to resolve type %04x addresses\n",
246 be16_to_cpu(h
->h_proto
));
250 static int fwnet_header_cache(const struct neighbour
*neigh
,
251 struct hh_cache
*hh
, __be16 type
)
253 struct net_device
*net
;
254 struct fwnet_header
*h
;
256 if (type
== cpu_to_be16(ETH_P_802_3
))
259 h
= (struct fwnet_header
*)((u8
*)hh
->hh_data
+ HH_DATA_OFF(sizeof(*h
)));
261 memcpy(h
->h_dest
, neigh
->ha
, net
->addr_len
);
262 hh
->hh_len
= FWNET_HLEN
;
267 /* Called by Address Resolution module to notify changes in address. */
268 static void fwnet_header_cache_update(struct hh_cache
*hh
,
269 const struct net_device
*net
, const unsigned char *haddr
)
271 memcpy((u8
*)hh
->hh_data
+ HH_DATA_OFF(FWNET_HLEN
), haddr
, net
->addr_len
);
274 static int fwnet_header_parse(const struct sk_buff
*skb
, unsigned char *haddr
)
276 memcpy(haddr
, skb
->dev
->dev_addr
, FWNET_ALEN
);
281 static const struct header_ops fwnet_header_ops
= {
282 .create
= fwnet_header_create
,
283 .rebuild
= fwnet_header_rebuild
,
284 .cache
= fwnet_header_cache
,
285 .cache_update
= fwnet_header_cache_update
,
286 .parse
= fwnet_header_parse
,
289 /* FIXME: is this correct for all cases? */
290 static bool fwnet_frag_overlap(struct fwnet_partial_datagram
*pd
,
291 unsigned offset
, unsigned len
)
293 struct fwnet_fragment_info
*fi
;
294 unsigned end
= offset
+ len
;
296 list_for_each_entry(fi
, &pd
->fi_list
, fi_link
)
297 if (offset
< fi
->offset
+ fi
->len
&& end
> fi
->offset
)
303 /* Assumes that new fragment does not overlap any existing fragments */
304 static struct fwnet_fragment_info
*fwnet_frag_new(
305 struct fwnet_partial_datagram
*pd
, unsigned offset
, unsigned len
)
307 struct fwnet_fragment_info
*fi
, *fi2
, *new;
308 struct list_head
*list
;
311 list_for_each_entry(fi
, &pd
->fi_list
, fi_link
) {
312 if (fi
->offset
+ fi
->len
== offset
) {
313 /* The new fragment can be tacked on to the end */
314 /* Did the new fragment plug a hole? */
315 fi2
= list_entry(fi
->fi_link
.next
,
316 struct fwnet_fragment_info
, fi_link
);
317 if (fi
->offset
+ fi
->len
== fi2
->offset
) {
318 /* glue fragments together */
319 fi
->len
+= len
+ fi2
->len
;
320 list_del(&fi2
->fi_link
);
328 if (offset
+ len
== fi
->offset
) {
329 /* The new fragment can be tacked on to the beginning */
330 /* Did the new fragment plug a hole? */
331 fi2
= list_entry(fi
->fi_link
.prev
,
332 struct fwnet_fragment_info
, fi_link
);
333 if (fi2
->offset
+ fi2
->len
== fi
->offset
) {
334 /* glue fragments together */
335 fi2
->len
+= fi
->len
+ len
;
336 list_del(&fi
->fi_link
);
346 if (offset
> fi
->offset
+ fi
->len
) {
350 if (offset
+ len
< fi
->offset
) {
351 list
= fi
->fi_link
.prev
;
356 new = kmalloc(sizeof(*new), GFP_ATOMIC
);
358 dev_err(&pd
->skb
->dev
->dev
, "out of memory\n");
362 new->offset
= offset
;
364 list_add(&new->fi_link
, list
);
369 static struct fwnet_partial_datagram
*fwnet_pd_new(struct net_device
*net
,
370 struct fwnet_peer
*peer
, u16 datagram_label
, unsigned dg_size
,
371 void *frag_buf
, unsigned frag_off
, unsigned frag_len
)
373 struct fwnet_partial_datagram
*new;
374 struct fwnet_fragment_info
*fi
;
376 new = kmalloc(sizeof(*new), GFP_ATOMIC
);
380 INIT_LIST_HEAD(&new->fi_list
);
381 fi
= fwnet_frag_new(new, frag_off
, frag_len
);
385 new->datagram_label
= datagram_label
;
386 new->datagram_size
= dg_size
;
387 new->skb
= dev_alloc_skb(dg_size
+ LL_RESERVED_SPACE(net
));
388 if (new->skb
== NULL
)
391 skb_reserve(new->skb
, LL_RESERVED_SPACE(net
));
392 new->pbuf
= skb_put(new->skb
, dg_size
);
393 memcpy(new->pbuf
+ frag_off
, frag_buf
, frag_len
);
394 list_add_tail(&new->pd_link
, &peer
->pd_list
);
403 dev_err(&net
->dev
, "out of memory\n");
408 static struct fwnet_partial_datagram
*fwnet_pd_find(struct fwnet_peer
*peer
,
411 struct fwnet_partial_datagram
*pd
;
413 list_for_each_entry(pd
, &peer
->pd_list
, pd_link
)
414 if (pd
->datagram_label
== datagram_label
)
421 static void fwnet_pd_delete(struct fwnet_partial_datagram
*old
)
423 struct fwnet_fragment_info
*fi
, *n
;
425 list_for_each_entry_safe(fi
, n
, &old
->fi_list
, fi_link
)
428 list_del(&old
->pd_link
);
429 dev_kfree_skb_any(old
->skb
);
433 static bool fwnet_pd_update(struct fwnet_peer
*peer
,
434 struct fwnet_partial_datagram
*pd
, void *frag_buf
,
435 unsigned frag_off
, unsigned frag_len
)
437 if (fwnet_frag_new(pd
, frag_off
, frag_len
) == NULL
)
440 memcpy(pd
->pbuf
+ frag_off
, frag_buf
, frag_len
);
443 * Move list entry to beginning of list so that oldest partial
444 * datagrams percolate to the end of the list
446 list_move_tail(&pd
->pd_link
, &peer
->pd_list
);
451 static bool fwnet_pd_is_complete(struct fwnet_partial_datagram
*pd
)
453 struct fwnet_fragment_info
*fi
;
455 fi
= list_entry(pd
->fi_list
.next
, struct fwnet_fragment_info
, fi_link
);
457 return fi
->len
== pd
->datagram_size
;
460 /* caller must hold dev->lock */
461 static struct fwnet_peer
*fwnet_peer_find_by_guid(struct fwnet_device
*dev
,
464 struct fwnet_peer
*peer
;
466 list_for_each_entry(peer
, &dev
->peer_list
, peer_link
)
467 if (peer
->guid
== guid
)
473 /* caller must hold dev->lock */
474 static struct fwnet_peer
*fwnet_peer_find_by_node_id(struct fwnet_device
*dev
,
475 int node_id
, int generation
)
477 struct fwnet_peer
*peer
;
479 list_for_each_entry(peer
, &dev
->peer_list
, peer_link
)
480 if (peer
->node_id
== node_id
&&
481 peer
->generation
== generation
)
487 /* See IEEE 1394-2008 table 6-4, table 8-8, table 16-18. */
488 static unsigned fwnet_max_payload(unsigned max_rec
, unsigned speed
)
490 max_rec
= min(max_rec
, speed
+ 8);
491 max_rec
= clamp(max_rec
, 8U, 11U); /* 512...4096 */
493 return (1 << (max_rec
+ 1)) - RFC2374_FRAG_HDR_SIZE
;
497 static int fwnet_finish_incoming_packet(struct net_device
*net
,
498 struct sk_buff
*skb
, u16 source_node_id
,
499 bool is_broadcast
, u16 ether_type
)
501 struct fwnet_device
*dev
;
505 switch (ether_type
) {
513 dev
= netdev_priv(net
);
514 /* Write metadata, and then pass to the receive level */
516 skb
->ip_summed
= CHECKSUM_NONE
;
519 * Parse the encapsulation header. This actually does the job of
520 * converting to an ethernet-like pseudo frame header.
522 guid
= cpu_to_be64(dev
->card
->guid
);
523 if (dev_hard_header(skb
, net
, ether_type
,
524 is_broadcast
? net
->broadcast
: net
->dev_addr
,
525 NULL
, skb
->len
) >= 0) {
526 struct fwnet_header
*eth
;
530 skb_reset_mac_header(skb
);
531 skb_pull(skb
, sizeof(*eth
));
532 eth
= (struct fwnet_header
*)skb_mac_header(skb
);
533 if (fwnet_hwaddr_is_multicast(eth
->h_dest
)) {
534 if (memcmp(eth
->h_dest
, net
->broadcast
,
536 skb
->pkt_type
= PACKET_BROADCAST
;
539 skb
->pkt_type
= PACKET_MULTICAST
;
542 if (memcmp(eth
->h_dest
, net
->dev_addr
, net
->addr_len
))
543 skb
->pkt_type
= PACKET_OTHERHOST
;
545 if (ntohs(eth
->h_proto
) >= 1536) {
546 protocol
= eth
->h_proto
;
548 rawp
= (u16
*)skb
->data
;
550 protocol
= htons(ETH_P_802_3
);
552 protocol
= htons(ETH_P_802_2
);
554 skb
->protocol
= protocol
;
556 status
= netif_rx(skb
);
557 if (status
== NET_RX_DROP
) {
558 net
->stats
.rx_errors
++;
559 net
->stats
.rx_dropped
++;
561 net
->stats
.rx_packets
++;
562 net
->stats
.rx_bytes
+= skb
->len
;
568 net
->stats
.rx_errors
++;
569 net
->stats
.rx_dropped
++;
571 dev_kfree_skb_any(skb
);
576 static int fwnet_incoming_packet(struct fwnet_device
*dev
, __be32
*buf
, int len
,
577 int source_node_id
, int generation
,
581 struct net_device
*net
= dev
->netdev
;
582 struct rfc2734_header hdr
;
585 struct fwnet_peer
*peer
;
586 struct fwnet_partial_datagram
*pd
;
593 hdr
.w0
= be32_to_cpu(buf
[0]);
594 lf
= fwnet_get_hdr_lf(&hdr
);
595 if (lf
== RFC2374_HDR_UNFRAG
) {
597 * An unfragmented datagram has been received by the ieee1394
598 * bus. Build an skbuff around it so we can pass it to the
599 * high level network layer.
601 ether_type
= fwnet_get_hdr_ether_type(&hdr
);
603 len
-= RFC2374_UNFRAG_HDR_SIZE
;
605 skb
= dev_alloc_skb(len
+ LL_RESERVED_SPACE(net
));
606 if (unlikely(!skb
)) {
607 dev_err(&net
->dev
, "out of memory\n");
608 net
->stats
.rx_dropped
++;
612 skb_reserve(skb
, LL_RESERVED_SPACE(net
));
613 memcpy(skb_put(skb
, len
), buf
, len
);
615 return fwnet_finish_incoming_packet(net
, skb
, source_node_id
,
616 is_broadcast
, ether_type
);
618 /* A datagram fragment has been received, now the fun begins. */
619 hdr
.w1
= ntohl(buf
[1]);
621 len
-= RFC2374_FRAG_HDR_SIZE
;
622 if (lf
== RFC2374_HDR_FIRSTFRAG
) {
623 ether_type
= fwnet_get_hdr_ether_type(&hdr
);
627 fg_off
= fwnet_get_hdr_fg_off(&hdr
);
629 datagram_label
= fwnet_get_hdr_dgl(&hdr
);
630 dg_size
= fwnet_get_hdr_dg_size(&hdr
); /* ??? + 1 */
632 spin_lock_irqsave(&dev
->lock
, flags
);
634 peer
= fwnet_peer_find_by_node_id(dev
, source_node_id
, generation
);
640 pd
= fwnet_pd_find(peer
, datagram_label
);
642 while (peer
->pdg_size
>= FWNET_MAX_FRAGMENTS
) {
643 /* remove the oldest */
644 fwnet_pd_delete(list_first_entry(&peer
->pd_list
,
645 struct fwnet_partial_datagram
, pd_link
));
648 pd
= fwnet_pd_new(net
, peer
, datagram_label
,
649 dg_size
, buf
, fg_off
, len
);
656 if (fwnet_frag_overlap(pd
, fg_off
, len
) ||
657 pd
->datagram_size
!= dg_size
) {
659 * Differing datagram sizes or overlapping fragments,
660 * discard old datagram and start a new one.
663 pd
= fwnet_pd_new(net
, peer
, datagram_label
,
664 dg_size
, buf
, fg_off
, len
);
671 if (!fwnet_pd_update(peer
, pd
, buf
, fg_off
, len
)) {
673 * Couldn't save off fragment anyway
674 * so might as well obliterate the
683 } /* new datagram or add to existing one */
685 if (lf
== RFC2374_HDR_FIRSTFRAG
)
686 pd
->ether_type
= ether_type
;
688 if (fwnet_pd_is_complete(pd
)) {
689 ether_type
= pd
->ether_type
;
691 skb
= skb_get(pd
->skb
);
694 spin_unlock_irqrestore(&dev
->lock
, flags
);
696 return fwnet_finish_incoming_packet(net
, skb
, source_node_id
,
700 * Datagram is not complete, we're done for the
705 spin_unlock_irqrestore(&dev
->lock
, flags
);
710 static void fwnet_receive_packet(struct fw_card
*card
, struct fw_request
*r
,
711 int tcode
, int destination
, int source
, int generation
,
712 unsigned long long offset
, void *payload
, size_t length
,
715 struct fwnet_device
*dev
= callback_data
;
718 if (destination
== IEEE1394_ALL_NODES
) {
724 if (offset
!= dev
->handler
.offset
)
725 rcode
= RCODE_ADDRESS_ERROR
;
726 else if (tcode
!= TCODE_WRITE_BLOCK_REQUEST
)
727 rcode
= RCODE_TYPE_ERROR
;
728 else if (fwnet_incoming_packet(dev
, payload
, length
,
729 source
, generation
, false) != 0) {
730 dev_err(&dev
->netdev
->dev
, "incoming packet failure\n");
731 rcode
= RCODE_CONFLICT_ERROR
;
733 rcode
= RCODE_COMPLETE
;
735 fw_send_response(card
, r
, rcode
);
738 static void fwnet_receive_broadcast(struct fw_iso_context
*context
,
739 u32 cycle
, size_t header_length
, void *header
, void *data
)
741 struct fwnet_device
*dev
;
742 struct fw_iso_packet packet
;
750 unsigned long offset
;
755 length
= be16_to_cpup(hdr_ptr
);
757 spin_lock_irqsave(&dev
->lock
, flags
);
759 offset
= dev
->rcv_buffer_size
* dev
->broadcast_rcv_next_ptr
;
760 buf_ptr
= dev
->broadcast_rcv_buffer_ptrs
[dev
->broadcast_rcv_next_ptr
++];
761 if (dev
->broadcast_rcv_next_ptr
== dev
->num_broadcast_rcv_ptrs
)
762 dev
->broadcast_rcv_next_ptr
= 0;
764 spin_unlock_irqrestore(&dev
->lock
, flags
);
766 specifier_id
= (be32_to_cpu(buf_ptr
[0]) & 0xffff) << 8
767 | (be32_to_cpu(buf_ptr
[1]) & 0xff000000) >> 24;
768 ver
= be32_to_cpu(buf_ptr
[1]) & 0xffffff;
769 source_node_id
= be32_to_cpu(buf_ptr
[0]) >> 16;
771 if (specifier_id
== IANA_SPECIFIER_ID
&& ver
== RFC2734_SW_VERSION
) {
773 length
-= IEEE1394_GASP_HDR_SIZE
;
774 fwnet_incoming_packet(dev
, buf_ptr
, length
, source_node_id
,
775 context
->card
->generation
, true);
778 packet
.payload_length
= dev
->rcv_buffer_size
;
779 packet
.interrupt
= 1;
783 packet
.header_length
= IEEE1394_GASP_HDR_SIZE
;
785 spin_lock_irqsave(&dev
->lock
, flags
);
787 retval
= fw_iso_context_queue(dev
->broadcast_rcv_context
, &packet
,
788 &dev
->broadcast_rcv_buffer
, offset
);
790 spin_unlock_irqrestore(&dev
->lock
, flags
);
793 fw_iso_context_queue_flush(dev
->broadcast_rcv_context
);
795 dev_err(&dev
->netdev
->dev
, "requeue failed\n");
798 static struct kmem_cache
*fwnet_packet_task_cache
;
800 static void fwnet_free_ptask(struct fwnet_packet_task
*ptask
)
802 dev_kfree_skb_any(ptask
->skb
);
803 kmem_cache_free(fwnet_packet_task_cache
, ptask
);
806 /* Caller must hold dev->lock. */
807 static void dec_queued_datagrams(struct fwnet_device
*dev
)
809 if (--dev
->queued_datagrams
== FWNET_MIN_QUEUED_DATAGRAMS
)
810 netif_wake_queue(dev
->netdev
);
813 static int fwnet_send_packet(struct fwnet_packet_task
*ptask
);
815 static void fwnet_transmit_packet_done(struct fwnet_packet_task
*ptask
)
817 struct fwnet_device
*dev
= ptask
->dev
;
818 struct sk_buff
*skb
= ptask
->skb
;
822 spin_lock_irqsave(&dev
->lock
, flags
);
824 ptask
->outstanding_pkts
--;
826 /* Check whether we or the networking TX soft-IRQ is last user. */
827 free
= (ptask
->outstanding_pkts
== 0 && ptask
->enqueued
);
829 dec_queued_datagrams(dev
);
831 if (ptask
->outstanding_pkts
== 0) {
832 dev
->netdev
->stats
.tx_packets
++;
833 dev
->netdev
->stats
.tx_bytes
+= skb
->len
;
836 spin_unlock_irqrestore(&dev
->lock
, flags
);
838 if (ptask
->outstanding_pkts
> 0) {
844 /* Update the ptask to point to the next fragment and send it */
845 lf
= fwnet_get_hdr_lf(&ptask
->hdr
);
847 case RFC2374_HDR_LASTFRAG
:
848 case RFC2374_HDR_UNFRAG
:
850 dev_err(&dev
->netdev
->dev
,
851 "outstanding packet %x lf %x, header %x,%x\n",
852 ptask
->outstanding_pkts
, lf
, ptask
->hdr
.w0
,
856 case RFC2374_HDR_FIRSTFRAG
:
857 /* Set frag type here for future interior fragments */
858 dg_size
= fwnet_get_hdr_dg_size(&ptask
->hdr
);
859 fg_off
= ptask
->max_payload
- RFC2374_FRAG_HDR_SIZE
;
860 datagram_label
= fwnet_get_hdr_dgl(&ptask
->hdr
);
863 case RFC2374_HDR_INTFRAG
:
864 dg_size
= fwnet_get_hdr_dg_size(&ptask
->hdr
);
865 fg_off
= fwnet_get_hdr_fg_off(&ptask
->hdr
)
866 + ptask
->max_payload
- RFC2374_FRAG_HDR_SIZE
;
867 datagram_label
= fwnet_get_hdr_dgl(&ptask
->hdr
);
871 if (ptask
->dest_node
== IEEE1394_ALL_NODES
) {
873 ptask
->max_payload
+ IEEE1394_GASP_HDR_SIZE
);
875 skb_pull(skb
, ptask
->max_payload
);
877 if (ptask
->outstanding_pkts
> 1) {
878 fwnet_make_sf_hdr(&ptask
->hdr
, RFC2374_HDR_INTFRAG
,
879 dg_size
, fg_off
, datagram_label
);
881 fwnet_make_sf_hdr(&ptask
->hdr
, RFC2374_HDR_LASTFRAG
,
882 dg_size
, fg_off
, datagram_label
);
883 ptask
->max_payload
= skb
->len
+ RFC2374_FRAG_HDR_SIZE
;
885 fwnet_send_packet(ptask
);
889 fwnet_free_ptask(ptask
);
892 static void fwnet_transmit_packet_failed(struct fwnet_packet_task
*ptask
)
894 struct fwnet_device
*dev
= ptask
->dev
;
898 spin_lock_irqsave(&dev
->lock
, flags
);
900 /* One fragment failed; don't try to send remaining fragments. */
901 ptask
->outstanding_pkts
= 0;
903 /* Check whether we or the networking TX soft-IRQ is last user. */
904 free
= ptask
->enqueued
;
906 dec_queued_datagrams(dev
);
908 dev
->netdev
->stats
.tx_dropped
++;
909 dev
->netdev
->stats
.tx_errors
++;
911 spin_unlock_irqrestore(&dev
->lock
, flags
);
914 fwnet_free_ptask(ptask
);
917 static void fwnet_write_complete(struct fw_card
*card
, int rcode
,
918 void *payload
, size_t length
, void *data
)
920 struct fwnet_packet_task
*ptask
= data
;
921 static unsigned long j
;
922 static int last_rcode
, errors_skipped
;
924 if (rcode
== RCODE_COMPLETE
) {
925 fwnet_transmit_packet_done(ptask
);
927 fwnet_transmit_packet_failed(ptask
);
929 if (printk_timed_ratelimit(&j
, 1000) || rcode
!= last_rcode
) {
930 dev_err(&ptask
->dev
->netdev
->dev
,
931 "fwnet_write_complete failed: %x (skipped %d)\n",
932 rcode
, errors_skipped
);
941 static int fwnet_send_packet(struct fwnet_packet_task
*ptask
)
943 struct fwnet_device
*dev
;
945 struct rfc2734_header
*bufhdr
;
950 tx_len
= ptask
->max_payload
;
951 switch (fwnet_get_hdr_lf(&ptask
->hdr
)) {
952 case RFC2374_HDR_UNFRAG
:
953 bufhdr
= (struct rfc2734_header
*)
954 skb_push(ptask
->skb
, RFC2374_UNFRAG_HDR_SIZE
);
955 put_unaligned_be32(ptask
->hdr
.w0
, &bufhdr
->w0
);
958 case RFC2374_HDR_FIRSTFRAG
:
959 case RFC2374_HDR_INTFRAG
:
960 case RFC2374_HDR_LASTFRAG
:
961 bufhdr
= (struct rfc2734_header
*)
962 skb_push(ptask
->skb
, RFC2374_FRAG_HDR_SIZE
);
963 put_unaligned_be32(ptask
->hdr
.w0
, &bufhdr
->w0
);
964 put_unaligned_be32(ptask
->hdr
.w1
, &bufhdr
->w1
);
970 if (ptask
->dest_node
== IEEE1394_ALL_NODES
) {
975 /* ptask->generation may not have been set yet */
976 generation
= dev
->card
->generation
;
978 node_id
= dev
->card
->node_id
;
980 p
= skb_push(ptask
->skb
, IEEE1394_GASP_HDR_SIZE
);
981 put_unaligned_be32(node_id
<< 16 | IANA_SPECIFIER_ID
>> 8, p
);
982 put_unaligned_be32((IANA_SPECIFIER_ID
& 0xff) << 24
983 | RFC2734_SW_VERSION
, &p
[4]);
985 /* We should not transmit if broadcast_channel.valid == 0. */
986 fw_send_request(dev
->card
, &ptask
->transaction
,
988 fw_stream_packet_destination_id(3,
989 IEEE1394_BROADCAST_CHANNEL
, 0),
990 generation
, SCODE_100
, 0ULL, ptask
->skb
->data
,
991 tx_len
+ 8, fwnet_write_complete
, ptask
);
993 spin_lock_irqsave(&dev
->lock
, flags
);
995 /* If the AT tasklet already ran, we may be last user. */
996 free
= (ptask
->outstanding_pkts
== 0 && !ptask
->enqueued
);
998 ptask
->enqueued
= true;
1000 dec_queued_datagrams(dev
);
1002 spin_unlock_irqrestore(&dev
->lock
, flags
);
1007 fw_send_request(dev
->card
, &ptask
->transaction
,
1008 TCODE_WRITE_BLOCK_REQUEST
, ptask
->dest_node
,
1009 ptask
->generation
, ptask
->speed
, ptask
->fifo_addr
,
1010 ptask
->skb
->data
, tx_len
, fwnet_write_complete
, ptask
);
1012 spin_lock_irqsave(&dev
->lock
, flags
);
1014 /* If the AT tasklet already ran, we may be last user. */
1015 free
= (ptask
->outstanding_pkts
== 0 && !ptask
->enqueued
);
1017 ptask
->enqueued
= true;
1019 dec_queued_datagrams(dev
);
1021 spin_unlock_irqrestore(&dev
->lock
, flags
);
1023 dev
->netdev
->trans_start
= jiffies
;
1026 fwnet_free_ptask(ptask
);
1031 static void fwnet_fifo_stop(struct fwnet_device
*dev
)
1033 if (dev
->local_fifo
== FWNET_NO_FIFO_ADDR
)
1036 fw_core_remove_address_handler(&dev
->handler
);
1037 dev
->local_fifo
= FWNET_NO_FIFO_ADDR
;
1040 static int fwnet_fifo_start(struct fwnet_device
*dev
)
1044 if (dev
->local_fifo
!= FWNET_NO_FIFO_ADDR
)
1047 dev
->handler
.length
= 4096;
1048 dev
->handler
.address_callback
= fwnet_receive_packet
;
1049 dev
->handler
.callback_data
= dev
;
1051 retval
= fw_core_add_address_handler(&dev
->handler
,
1052 &fw_high_memory_region
);
1056 dev
->local_fifo
= dev
->handler
.offset
;
1061 static void __fwnet_broadcast_stop(struct fwnet_device
*dev
)
1065 if (dev
->broadcast_state
!= FWNET_BROADCAST_ERROR
) {
1066 for (u
= 0; u
< FWNET_ISO_PAGE_COUNT
; u
++)
1067 kunmap(dev
->broadcast_rcv_buffer
.pages
[u
]);
1068 fw_iso_buffer_destroy(&dev
->broadcast_rcv_buffer
, dev
->card
);
1070 if (dev
->broadcast_rcv_context
) {
1071 fw_iso_context_destroy(dev
->broadcast_rcv_context
);
1072 dev
->broadcast_rcv_context
= NULL
;
1074 kfree(dev
->broadcast_rcv_buffer_ptrs
);
1075 dev
->broadcast_rcv_buffer_ptrs
= NULL
;
1076 dev
->broadcast_state
= FWNET_BROADCAST_ERROR
;
1079 static void fwnet_broadcast_stop(struct fwnet_device
*dev
)
1081 if (dev
->broadcast_state
== FWNET_BROADCAST_ERROR
)
1083 fw_iso_context_stop(dev
->broadcast_rcv_context
);
1084 __fwnet_broadcast_stop(dev
);
1087 static int fwnet_broadcast_start(struct fwnet_device
*dev
)
1089 struct fw_iso_context
*context
;
1091 unsigned num_packets
;
1092 unsigned max_receive
;
1093 struct fw_iso_packet packet
;
1094 unsigned long offset
;
1098 if (dev
->broadcast_state
!= FWNET_BROADCAST_ERROR
)
1101 max_receive
= 1U << (dev
->card
->max_receive
+ 1);
1102 num_packets
= (FWNET_ISO_PAGE_COUNT
* PAGE_SIZE
) / max_receive
;
1104 ptrptr
= kmalloc(sizeof(void *) * num_packets
, GFP_KERNEL
);
1109 dev
->broadcast_rcv_buffer_ptrs
= ptrptr
;
1111 context
= fw_iso_context_create(dev
->card
, FW_ISO_CONTEXT_RECEIVE
,
1112 IEEE1394_BROADCAST_CHANNEL
,
1113 dev
->card
->link_speed
, 8,
1114 fwnet_receive_broadcast
, dev
);
1115 if (IS_ERR(context
)) {
1116 retval
= PTR_ERR(context
);
1120 retval
= fw_iso_buffer_init(&dev
->broadcast_rcv_buffer
, dev
->card
,
1121 FWNET_ISO_PAGE_COUNT
, DMA_FROM_DEVICE
);
1125 dev
->broadcast_state
= FWNET_BROADCAST_STOPPED
;
1127 for (u
= 0; u
< FWNET_ISO_PAGE_COUNT
; u
++) {
1131 ptr
= kmap(dev
->broadcast_rcv_buffer
.pages
[u
]);
1132 for (v
= 0; v
< num_packets
/ FWNET_ISO_PAGE_COUNT
; v
++)
1133 *ptrptr
++ = (void *) ((char *)ptr
+ v
* max_receive
);
1135 dev
->broadcast_rcv_context
= context
;
1137 packet
.payload_length
= max_receive
;
1138 packet
.interrupt
= 1;
1142 packet
.header_length
= IEEE1394_GASP_HDR_SIZE
;
1145 for (u
= 0; u
< num_packets
; u
++) {
1146 retval
= fw_iso_context_queue(context
, &packet
,
1147 &dev
->broadcast_rcv_buffer
, offset
);
1151 offset
+= max_receive
;
1153 dev
->num_broadcast_rcv_ptrs
= num_packets
;
1154 dev
->rcv_buffer_size
= max_receive
;
1155 dev
->broadcast_rcv_next_ptr
= 0U;
1156 retval
= fw_iso_context_start(context
, -1, 0,
1157 FW_ISO_CONTEXT_MATCH_ALL_TAGS
); /* ??? sync */
1161 /* FIXME: adjust it according to the min. speed of all known peers? */
1162 dev
->broadcast_xmt_max_payload
= IEEE1394_MAX_PAYLOAD_S100
1163 - IEEE1394_GASP_HDR_SIZE
- RFC2374_UNFRAG_HDR_SIZE
;
1164 dev
->broadcast_state
= FWNET_BROADCAST_RUNNING
;
1169 __fwnet_broadcast_stop(dev
);
1173 static void set_carrier_state(struct fwnet_device
*dev
)
1175 if (dev
->peer_count
> 1)
1176 netif_carrier_on(dev
->netdev
);
1178 netif_carrier_off(dev
->netdev
);
1182 static int fwnet_open(struct net_device
*net
)
1184 struct fwnet_device
*dev
= netdev_priv(net
);
1187 ret
= fwnet_broadcast_start(dev
);
1191 netif_start_queue(net
);
1193 spin_lock_irq(&dev
->lock
);
1194 set_carrier_state(dev
);
1195 spin_unlock_irq(&dev
->lock
);
1201 static int fwnet_stop(struct net_device
*net
)
1203 struct fwnet_device
*dev
= netdev_priv(net
);
1205 netif_stop_queue(net
);
1206 fwnet_broadcast_stop(dev
);
1211 static netdev_tx_t
fwnet_tx(struct sk_buff
*skb
, struct net_device
*net
)
1213 struct fwnet_header hdr_buf
;
1214 struct fwnet_device
*dev
= netdev_priv(net
);
1217 unsigned max_payload
;
1219 u16
*datagram_label_ptr
;
1220 struct fwnet_packet_task
*ptask
;
1221 struct fwnet_peer
*peer
;
1222 unsigned long flags
;
1224 spin_lock_irqsave(&dev
->lock
, flags
);
1226 /* Can this happen? */
1227 if (netif_queue_stopped(dev
->netdev
)) {
1228 spin_unlock_irqrestore(&dev
->lock
, flags
);
1230 return NETDEV_TX_BUSY
;
1233 ptask
= kmem_cache_alloc(fwnet_packet_task_cache
, GFP_ATOMIC
);
1237 skb
= skb_share_check(skb
, GFP_ATOMIC
);
1242 * Make a copy of the driver-specific header.
1243 * We might need to rebuild the header on tx failure.
1245 memcpy(&hdr_buf
, skb
->data
, sizeof(hdr_buf
));
1246 proto
= hdr_buf
.h_proto
;
1249 case htons(ETH_P_ARP
):
1250 case htons(ETH_P_IP
):
1256 skb_pull(skb
, sizeof(hdr_buf
));
1260 * Set the transmission type for the packet. ARP packets and IP
1261 * broadcast packets are sent via GASP.
1263 if (fwnet_hwaddr_is_multicast(hdr_buf
.h_dest
)) {
1264 max_payload
= dev
->broadcast_xmt_max_payload
;
1265 datagram_label_ptr
= &dev
->broadcast_xmt_datagramlabel
;
1267 ptask
->fifo_addr
= FWNET_NO_FIFO_ADDR
;
1268 ptask
->generation
= 0;
1269 ptask
->dest_node
= IEEE1394_ALL_NODES
;
1270 ptask
->speed
= SCODE_100
;
1272 union fwnet_hwaddr
*ha
= (union fwnet_hwaddr
*)hdr_buf
.h_dest
;
1273 __be64 guid
= get_unaligned(&ha
->uc
.uniq_id
);
1276 peer
= fwnet_peer_find_by_guid(dev
, be64_to_cpu(guid
));
1280 generation
= peer
->generation
;
1281 dest_node
= peer
->node_id
;
1282 max_payload
= peer
->max_payload
;
1283 datagram_label_ptr
= &peer
->datagram_label
;
1285 ptask
->fifo_addr
= fwnet_hwaddr_fifo(ha
);
1286 ptask
->generation
= generation
;
1287 ptask
->dest_node
= dest_node
;
1288 ptask
->speed
= peer
->speed
;
1296 /* Does it all fit in one packet? */
1297 if (dg_size
<= max_payload
) {
1298 fwnet_make_uf_hdr(&ptask
->hdr
, ntohs(proto
));
1299 ptask
->outstanding_pkts
= 1;
1300 max_payload
= dg_size
+ RFC2374_UNFRAG_HDR_SIZE
;
1304 max_payload
-= RFC2374_FRAG_OVERHEAD
;
1305 datagram_label
= (*datagram_label_ptr
)++;
1306 fwnet_make_ff_hdr(&ptask
->hdr
, ntohs(proto
), dg_size
,
1308 ptask
->outstanding_pkts
= DIV_ROUND_UP(dg_size
, max_payload
);
1309 max_payload
+= RFC2374_FRAG_HDR_SIZE
;
1312 if (++dev
->queued_datagrams
== FWNET_MAX_QUEUED_DATAGRAMS
)
1313 netif_stop_queue(dev
->netdev
);
1315 spin_unlock_irqrestore(&dev
->lock
, flags
);
1317 ptask
->max_payload
= max_payload
;
1318 ptask
->enqueued
= 0;
1320 fwnet_send_packet(ptask
);
1322 return NETDEV_TX_OK
;
1325 spin_unlock_irqrestore(&dev
->lock
, flags
);
1328 kmem_cache_free(fwnet_packet_task_cache
, ptask
);
1333 net
->stats
.tx_dropped
++;
1334 net
->stats
.tx_errors
++;
1337 * FIXME: According to a patch from 2003-02-26, "returning non-zero
1338 * causes serious problems" here, allegedly. Before that patch,
1339 * -ERRNO was returned which is not appropriate under Linux 2.6.
1340 * Perhaps more needs to be done? Stop the queue in serious
1341 * conditions and restart it elsewhere?
1343 return NETDEV_TX_OK
;
1346 static int fwnet_change_mtu(struct net_device
*net
, int new_mtu
)
1355 static const struct ethtool_ops fwnet_ethtool_ops
= {
1356 .get_link
= ethtool_op_get_link
,
1359 static const struct net_device_ops fwnet_netdev_ops
= {
1360 .ndo_open
= fwnet_open
,
1361 .ndo_stop
= fwnet_stop
,
1362 .ndo_start_xmit
= fwnet_tx
,
1363 .ndo_change_mtu
= fwnet_change_mtu
,
1366 static void fwnet_init_dev(struct net_device
*net
)
1368 net
->header_ops
= &fwnet_header_ops
;
1369 net
->netdev_ops
= &fwnet_netdev_ops
;
1370 net
->watchdog_timeo
= 2 * HZ
;
1371 net
->flags
= IFF_BROADCAST
| IFF_MULTICAST
;
1372 net
->features
= NETIF_F_HIGHDMA
;
1373 net
->addr_len
= FWNET_ALEN
;
1374 net
->hard_header_len
= FWNET_HLEN
;
1375 net
->type
= ARPHRD_IEEE1394
;
1376 net
->tx_queue_len
= FWNET_TX_QUEUE_LEN
;
1377 net
->ethtool_ops
= &fwnet_ethtool_ops
;
1380 /* caller must hold fwnet_device_mutex */
1381 static struct fwnet_device
*fwnet_dev_find(struct fw_card
*card
)
1383 struct fwnet_device
*dev
;
1385 list_for_each_entry(dev
, &fwnet_device_list
, dev_link
)
1386 if (dev
->card
== card
)
1392 static int fwnet_add_peer(struct fwnet_device
*dev
,
1393 struct fw_unit
*unit
, struct fw_device
*device
)
1395 struct fwnet_peer
*peer
;
1397 peer
= kmalloc(sizeof(*peer
), GFP_KERNEL
);
1401 dev_set_drvdata(&unit
->device
, peer
);
1404 peer
->guid
= (u64
)device
->config_rom
[3] << 32 | device
->config_rom
[4];
1405 INIT_LIST_HEAD(&peer
->pd_list
);
1407 peer
->datagram_label
= 0;
1408 peer
->speed
= device
->max_speed
;
1409 peer
->max_payload
= fwnet_max_payload(device
->max_rec
, peer
->speed
);
1411 peer
->generation
= device
->generation
;
1413 peer
->node_id
= device
->node_id
;
1415 spin_lock_irq(&dev
->lock
);
1416 list_add_tail(&peer
->peer_link
, &dev
->peer_list
);
1418 set_carrier_state(dev
);
1419 spin_unlock_irq(&dev
->lock
);
1424 static int fwnet_probe(struct device
*_dev
)
1426 struct fw_unit
*unit
= fw_unit(_dev
);
1427 struct fw_device
*device
= fw_parent_device(unit
);
1428 struct fw_card
*card
= device
->card
;
1429 struct net_device
*net
;
1430 bool allocated_netdev
= false;
1431 struct fwnet_device
*dev
;
1434 union fwnet_hwaddr
*ha
;
1436 mutex_lock(&fwnet_device_mutex
);
1438 dev
= fwnet_dev_find(card
);
1444 net
= alloc_netdev(sizeof(*dev
), "firewire%d", fwnet_init_dev
);
1450 allocated_netdev
= true;
1451 SET_NETDEV_DEV(net
, card
->device
);
1452 dev
= netdev_priv(net
);
1454 spin_lock_init(&dev
->lock
);
1455 dev
->broadcast_state
= FWNET_BROADCAST_ERROR
;
1456 dev
->broadcast_rcv_context
= NULL
;
1457 dev
->broadcast_xmt_max_payload
= 0;
1458 dev
->broadcast_xmt_datagramlabel
= 0;
1459 dev
->local_fifo
= FWNET_NO_FIFO_ADDR
;
1460 dev
->queued_datagrams
= 0;
1461 INIT_LIST_HEAD(&dev
->peer_list
);
1465 ret
= fwnet_fifo_start(dev
);
1468 dev
->local_fifo
= dev
->handler
.offset
;
1471 * Use the RFC 2734 default 1500 octets or the maximum payload
1474 max_mtu
= (1 << (card
->max_receive
+ 1))
1475 - sizeof(struct rfc2734_header
) - IEEE1394_GASP_HDR_SIZE
;
1476 net
->mtu
= min(1500U, max_mtu
);
1478 /* Set our hardware address while we're at it */
1479 ha
= (union fwnet_hwaddr
*)net
->dev_addr
;
1480 put_unaligned_be64(card
->guid
, &ha
->uc
.uniq_id
);
1481 ha
->uc
.max_rec
= dev
->card
->max_receive
;
1482 ha
->uc
.sspd
= dev
->card
->link_speed
;
1483 put_unaligned_be16(dev
->local_fifo
>> 32, &ha
->uc
.fifo_hi
);
1484 put_unaligned_be32(dev
->local_fifo
& 0xffffffff, &ha
->uc
.fifo_lo
);
1486 memset(net
->broadcast
, -1, net
->addr_len
);
1488 ret
= register_netdev(net
);
1492 list_add_tail(&dev
->dev_link
, &fwnet_device_list
);
1493 dev_notice(&net
->dev
, "IPv4 over IEEE 1394 on card %s\n",
1494 dev_name(card
->device
));
1496 ret
= fwnet_add_peer(dev
, unit
, device
);
1497 if (ret
&& allocated_netdev
) {
1498 unregister_netdev(net
);
1499 list_del(&dev
->dev_link
);
1501 fwnet_fifo_stop(dev
);
1505 mutex_unlock(&fwnet_device_mutex
);
1510 static void fwnet_remove_peer(struct fwnet_peer
*peer
, struct fwnet_device
*dev
)
1512 struct fwnet_partial_datagram
*pd
, *pd_next
;
1514 spin_lock_irq(&dev
->lock
);
1515 list_del(&peer
->peer_link
);
1517 set_carrier_state(dev
);
1518 spin_unlock_irq(&dev
->lock
);
1520 list_for_each_entry_safe(pd
, pd_next
, &peer
->pd_list
, pd_link
)
1521 fwnet_pd_delete(pd
);
1526 static int fwnet_remove(struct device
*_dev
)
1528 struct fwnet_peer
*peer
= dev_get_drvdata(_dev
);
1529 struct fwnet_device
*dev
= peer
->dev
;
1530 struct net_device
*net
;
1533 mutex_lock(&fwnet_device_mutex
);
1537 fwnet_remove_peer(peer
, dev
);
1539 if (list_empty(&dev
->peer_list
)) {
1540 unregister_netdev(net
);
1542 fwnet_fifo_stop(dev
);
1544 for (i
= 0; dev
->queued_datagrams
&& i
< 5; i
++)
1546 WARN_ON(dev
->queued_datagrams
);
1547 list_del(&dev
->dev_link
);
1552 mutex_unlock(&fwnet_device_mutex
);
1558 * FIXME abort partially sent fragmented datagrams,
1559 * discard partially received fragmented datagrams
1561 static void fwnet_update(struct fw_unit
*unit
)
1563 struct fw_device
*device
= fw_parent_device(unit
);
1564 struct fwnet_peer
*peer
= dev_get_drvdata(&unit
->device
);
1567 generation
= device
->generation
;
1569 spin_lock_irq(&peer
->dev
->lock
);
1570 peer
->node_id
= device
->node_id
;
1571 peer
->generation
= generation
;
1572 spin_unlock_irq(&peer
->dev
->lock
);
1575 static const struct ieee1394_device_id fwnet_id_table
[] = {
1577 .match_flags
= IEEE1394_MATCH_SPECIFIER_ID
|
1578 IEEE1394_MATCH_VERSION
,
1579 .specifier_id
= IANA_SPECIFIER_ID
,
1580 .version
= RFC2734_SW_VERSION
,
1585 static struct fw_driver fwnet_driver
= {
1587 .owner
= THIS_MODULE
,
1588 .name
= KBUILD_MODNAME
,
1589 .bus
= &fw_bus_type
,
1590 .probe
= fwnet_probe
,
1591 .remove
= fwnet_remove
,
1593 .update
= fwnet_update
,
1594 .id_table
= fwnet_id_table
,
1597 static const u32 rfc2374_unit_directory_data
[] = {
1598 0x00040000, /* directory_length */
1599 0x1200005e, /* unit_specifier_id: IANA */
1600 0x81000003, /* textual descriptor offset */
1601 0x13000001, /* unit_sw_version: RFC 2734 */
1602 0x81000005, /* textual descriptor offset */
1603 0x00030000, /* descriptor_length */
1604 0x00000000, /* text */
1605 0x00000000, /* minimal ASCII, en */
1606 0x49414e41, /* I A N A */
1607 0x00030000, /* descriptor_length */
1608 0x00000000, /* text */
1609 0x00000000, /* minimal ASCII, en */
1610 0x49507634, /* I P v 4 */
1613 static struct fw_descriptor rfc2374_unit_directory
= {
1614 .length
= ARRAY_SIZE(rfc2374_unit_directory_data
),
1615 .key
= (CSR_DIRECTORY
| CSR_UNIT
) << 24,
1616 .data
= rfc2374_unit_directory_data
1619 static int __init
fwnet_init(void)
1623 err
= fw_core_add_descriptor(&rfc2374_unit_directory
);
1627 fwnet_packet_task_cache
= kmem_cache_create("packet_task",
1628 sizeof(struct fwnet_packet_task
), 0, 0, NULL
);
1629 if (!fwnet_packet_task_cache
) {
1634 err
= driver_register(&fwnet_driver
.driver
);
1638 kmem_cache_destroy(fwnet_packet_task_cache
);
1640 fw_core_remove_descriptor(&rfc2374_unit_directory
);
1644 module_init(fwnet_init
);
1646 static void __exit
fwnet_cleanup(void)
1648 driver_unregister(&fwnet_driver
.driver
);
1649 kmem_cache_destroy(fwnet_packet_task_cache
);
1650 fw_core_remove_descriptor(&rfc2374_unit_directory
);
1652 module_exit(fwnet_cleanup
);
1654 MODULE_AUTHOR("Jay Fenlason <fenlason@redhat.com>");
1655 MODULE_DESCRIPTION("IPv4 over IEEE1394 as per RFC 2734");
1656 MODULE_LICENSE("GPL");
1657 MODULE_DEVICE_TABLE(ieee1394
, fwnet_id_table
);