Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 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 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 9 | #include <linux/bug.h> |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 10 | #include <linux/device.h> |
| 11 | #include <linux/ethtool.h> |
| 12 | #include <linux/firewire.h> |
| 13 | #include <linux/firewire-constants.h> |
| 14 | #include <linux/highmem.h> |
| 15 | #include <linux/in.h> |
| 16 | #include <linux/ip.h> |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 17 | #include <linux/jiffies.h> |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 18 | #include <linux/mod_devicetable.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/moduleparam.h> |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 21 | #include <linux/mutex.h> |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/skbuff.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 25 | #include <linux/spinlock.h> |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 26 | |
| 27 | #include <asm/unaligned.h> |
| 28 | #include <net/arp.h> |
| 29 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 30 | #define FWNET_MAX_FRAGMENTS 25 /* arbitrary limit */ |
| 31 | #define FWNET_ISO_PAGE_COUNT (PAGE_SIZE < 16 * 1024 ? 4 : 2) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 32 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 33 | #define IEEE1394_BROADCAST_CHANNEL 31 |
| 34 | #define IEEE1394_ALL_NODES (0xffc0 | 0x003f) |
| 35 | #define IEEE1394_MAX_PAYLOAD_S100 512 |
| 36 | #define FWNET_NO_FIFO_ADDR (~0ULL) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 37 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 38 | #define IANA_SPECIFIER_ID 0x00005eU |
| 39 | #define RFC2734_SW_VERSION 0x000001U |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 40 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 41 | #define IEEE1394_GASP_HDR_SIZE 8 |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 42 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 43 | #define RFC2374_UNFRAG_HDR_SIZE 4 |
| 44 | #define RFC2374_FRAG_HDR_SIZE 8 |
| 45 | #define RFC2374_FRAG_OVERHEAD 4 |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 46 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 47 | #define RFC2374_HDR_UNFRAG 0 /* unfragmented */ |
| 48 | #define RFC2374_HDR_FIRSTFRAG 1 /* first fragment */ |
| 49 | #define RFC2374_HDR_LASTFRAG 2 /* last fragment */ |
| 50 | #define RFC2374_HDR_INTFRAG 3 /* interior fragment */ |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 51 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 52 | #define RFC2734_HW_ADDR_LEN 16 |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 53 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 54 | struct rfc2734_arp { |
| 55 | __be16 hw_type; /* 0x0018 */ |
| 56 | __be16 proto_type; /* 0x0806 */ |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 57 | u8 hw_addr_len; /* 16 */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 58 | u8 ip_addr_len; /* 4 */ |
| 59 | __be16 opcode; /* ARP Opcode */ |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 60 | /* Above is exactly the same format as struct arphdr */ |
| 61 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 62 | __be64 s_uniq_id; /* Sender's 64bit EUI */ |
| 63 | u8 max_rec; /* Sender's max packet size */ |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 64 | u8 sspd; /* Sender's max speed */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 65 | __be16 fifo_hi; /* hi 16bits of sender's FIFO addr */ |
| 66 | __be32 fifo_lo; /* lo 32bits of sender's FIFO addr */ |
| 67 | __be32 sip; /* Sender's IP Address */ |
| 68 | __be32 tip; /* IP Address of requested hw addr */ |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 69 | } __attribute__((packed)); |
| 70 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 71 | /* This header format is specific to this driver implementation. */ |
| 72 | #define FWNET_ALEN 8 |
| 73 | #define FWNET_HLEN 10 |
| 74 | struct fwnet_header { |
| 75 | u8 h_dest[FWNET_ALEN]; /* destination address */ |
| 76 | __be16 h_proto; /* packet type ID field */ |
| 77 | } __attribute__((packed)); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 78 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 79 | /* IPv4 and IPv6 encapsulation header */ |
| 80 | struct rfc2734_header { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 81 | u32 w0; |
| 82 | u32 w1; |
| 83 | }; |
| 84 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 85 | #define fwnet_get_hdr_lf(h) (((h)->w0 & 0xc0000000) >> 30) |
| 86 | #define fwnet_get_hdr_ether_type(h) (((h)->w0 & 0x0000ffff)) |
| 87 | #define fwnet_get_hdr_dg_size(h) (((h)->w0 & 0x0fff0000) >> 16) |
| 88 | #define fwnet_get_hdr_fg_off(h) (((h)->w0 & 0x00000fff)) |
| 89 | #define fwnet_get_hdr_dgl(h) (((h)->w1 & 0xffff0000) >> 16) |
| 90 | |
| 91 | #define fwnet_set_hdr_lf(lf) ((lf) << 30) |
| 92 | #define fwnet_set_hdr_ether_type(et) (et) |
| 93 | #define fwnet_set_hdr_dg_size(dgs) ((dgs) << 16) |
| 94 | #define fwnet_set_hdr_fg_off(fgo) (fgo) |
| 95 | |
| 96 | #define fwnet_set_hdr_dgl(dgl) ((dgl) << 16) |
| 97 | |
| 98 | static inline void fwnet_make_uf_hdr(struct rfc2734_header *hdr, |
| 99 | unsigned ether_type) |
| 100 | { |
| 101 | hdr->w0 = fwnet_set_hdr_lf(RFC2374_HDR_UNFRAG) |
| 102 | | fwnet_set_hdr_ether_type(ether_type); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 105 | static inline void fwnet_make_ff_hdr(struct rfc2734_header *hdr, |
| 106 | unsigned ether_type, unsigned dg_size, unsigned dgl) |
| 107 | { |
| 108 | hdr->w0 = fwnet_set_hdr_lf(RFC2374_HDR_FIRSTFRAG) |
| 109 | | fwnet_set_hdr_dg_size(dg_size) |
| 110 | | fwnet_set_hdr_ether_type(ether_type); |
| 111 | hdr->w1 = fwnet_set_hdr_dgl(dgl); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 112 | } |
| 113 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 114 | static inline void fwnet_make_sf_hdr(struct rfc2734_header *hdr, |
| 115 | unsigned lf, unsigned dg_size, unsigned fg_off, unsigned dgl) |
| 116 | { |
| 117 | hdr->w0 = fwnet_set_hdr_lf(lf) |
| 118 | | fwnet_set_hdr_dg_size(dg_size) |
| 119 | | fwnet_set_hdr_fg_off(fg_off); |
| 120 | hdr->w1 = fwnet_set_hdr_dgl(dgl); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 123 | /* This list keeps track of what parts of the datagram have been filled in */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 124 | struct fwnet_fragment_info { |
| 125 | struct list_head fi_link; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 126 | u16 offset; |
| 127 | u16 len; |
| 128 | }; |
| 129 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 130 | struct fwnet_partial_datagram { |
| 131 | struct list_head pd_link; |
| 132 | struct list_head fi_list; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 133 | struct sk_buff *skb; |
| 134 | /* FIXME Why not use skb->data? */ |
| 135 | char *pbuf; |
| 136 | u16 datagram_label; |
| 137 | u16 ether_type; |
| 138 | u16 datagram_size; |
| 139 | }; |
| 140 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 141 | static DEFINE_MUTEX(fwnet_device_mutex); |
| 142 | static LIST_HEAD(fwnet_device_list); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 143 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 144 | struct fwnet_device { |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 145 | struct list_head dev_link; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 146 | spinlock_t lock; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 147 | enum { |
| 148 | FWNET_BROADCAST_ERROR, |
| 149 | FWNET_BROADCAST_RUNNING, |
| 150 | FWNET_BROADCAST_STOPPED, |
| 151 | } broadcast_state; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 152 | struct fw_iso_context *broadcast_rcv_context; |
| 153 | struct fw_iso_buffer broadcast_rcv_buffer; |
| 154 | void **broadcast_rcv_buffer_ptrs; |
| 155 | unsigned broadcast_rcv_next_ptr; |
| 156 | unsigned num_broadcast_rcv_ptrs; |
| 157 | unsigned rcv_buffer_size; |
| 158 | /* |
| 159 | * This value is the maximum unfragmented datagram size that can be |
| 160 | * sent by the hardware. It already has the GASP overhead and the |
| 161 | * unfragmented datagram header overhead calculated into it. |
| 162 | */ |
| 163 | unsigned broadcast_xmt_max_payload; |
| 164 | u16 broadcast_xmt_datagramlabel; |
| 165 | |
| 166 | /* |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 167 | * The CSR address that remote nodes must send datagrams to for us to |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 168 | * receive them. |
| 169 | */ |
| 170 | struct fw_address_handler handler; |
| 171 | u64 local_fifo; |
| 172 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 173 | /* List of packets to be sent */ |
| 174 | struct list_head packet_list; |
| 175 | /* |
| 176 | * List of packets that were broadcasted. When we get an ISO interrupt |
| 177 | * one of them has been sent |
| 178 | */ |
| 179 | struct list_head broadcasted_list; |
| 180 | /* List of packets that have been sent but not yet acked */ |
| 181 | struct list_head sent_list; |
| 182 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 183 | struct list_head peer_list; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 184 | struct fw_card *card; |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 185 | struct net_device *netdev; |
| 186 | }; |
| 187 | |
| 188 | struct fwnet_peer { |
| 189 | struct list_head peer_link; |
| 190 | struct fwnet_device *dev; |
| 191 | u64 guid; |
| 192 | u64 fifo; |
| 193 | |
| 194 | /* guarded by dev->lock */ |
| 195 | struct list_head pd_list; /* received partial datagrams */ |
| 196 | unsigned pdg_size; /* pd_list size */ |
| 197 | |
| 198 | u16 datagram_label; /* outgoing datagram label */ |
| 199 | unsigned max_payload; /* includes RFC2374_FRAG_HDR_SIZE overhead */ |
| 200 | int node_id; |
| 201 | int generation; |
| 202 | unsigned speed; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | /* This is our task struct. It's used for the packet complete callback. */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 206 | struct fwnet_packet_task { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 207 | /* |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 208 | * ptask can actually be on dev->packet_list, dev->broadcasted_list, |
| 209 | * or dev->sent_list depending on its current state. |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 210 | */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 211 | struct list_head pt_link; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 212 | struct fw_transaction transaction; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 213 | struct rfc2734_header hdr; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 214 | struct sk_buff *skb; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 215 | struct fwnet_device *dev; |
| 216 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 217 | int outstanding_pkts; |
| 218 | unsigned max_payload; |
| 219 | u64 fifo_addr; |
| 220 | u16 dest_node; |
| 221 | u8 generation; |
| 222 | u8 speed; |
| 223 | }; |
| 224 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 225 | /* |
| 226 | * saddr == NULL means use device source address. |
| 227 | * daddr == NULL means leave destination address (eg unresolved arp). |
| 228 | */ |
| 229 | static int fwnet_header_create(struct sk_buff *skb, struct net_device *net, |
| 230 | unsigned short type, const void *daddr, |
| 231 | const void *saddr, unsigned len) |
| 232 | { |
| 233 | struct fwnet_header *h; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 234 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 235 | h = (struct fwnet_header *)skb_push(skb, sizeof(*h)); |
| 236 | put_unaligned_be16(type, &h->h_proto); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 237 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 238 | if (net->flags & (IFF_LOOPBACK | IFF_NOARP)) { |
| 239 | memset(h->h_dest, 0, net->addr_len); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 240 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 241 | return net->hard_header_len; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | if (daddr) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 245 | memcpy(h->h_dest, daddr, net->addr_len); |
| 246 | |
| 247 | return net->hard_header_len; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 248 | } |
| 249 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 250 | return -net->hard_header_len; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 253 | static int fwnet_header_rebuild(struct sk_buff *skb) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 254 | { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 255 | struct fwnet_header *h = (struct fwnet_header *)skb->data; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 256 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 257 | if (get_unaligned_be16(&h->h_proto) == ETH_P_IP) |
| 258 | return arp_find((unsigned char *)&h->h_dest, skb); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 259 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 260 | fw_notify("%s: unable to resolve type %04x addresses\n", |
| 261 | skb->dev->name, be16_to_cpu(h->h_proto)); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 265 | static int fwnet_header_cache(const struct neighbour *neigh, |
| 266 | struct hh_cache *hh) |
| 267 | { |
| 268 | struct net_device *net; |
| 269 | struct fwnet_header *h; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 270 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 271 | if (hh->hh_type == cpu_to_be16(ETH_P_802_3)) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 272 | return -1; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 273 | net = neigh->dev; |
| 274 | h = (struct fwnet_header *)((u8 *)hh->hh_data + 16 - sizeof(*h)); |
| 275 | h->h_proto = hh->hh_type; |
| 276 | memcpy(h->h_dest, neigh->ha, net->addr_len); |
| 277 | hh->hh_len = FWNET_HLEN; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 278 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | /* Called by Address Resolution module to notify changes in address. */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 283 | static void fwnet_header_cache_update(struct hh_cache *hh, |
| 284 | const struct net_device *net, const unsigned char *haddr) |
| 285 | { |
| 286 | memcpy((u8 *)hh->hh_data + 16 - FWNET_HLEN, haddr, net->addr_len); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 287 | } |
| 288 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 289 | static int fwnet_header_parse(const struct sk_buff *skb, unsigned char *haddr) |
| 290 | { |
| 291 | memcpy(haddr, skb->dev->dev_addr, FWNET_ALEN); |
| 292 | |
| 293 | return FWNET_ALEN; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 296 | static const struct header_ops fwnet_header_ops = { |
| 297 | .create = fwnet_header_create, |
| 298 | .rebuild = fwnet_header_rebuild, |
| 299 | .cache = fwnet_header_cache, |
| 300 | .cache_update = fwnet_header_cache_update, |
| 301 | .parse = fwnet_header_parse, |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 302 | }; |
| 303 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 304 | /* FIXME: is this correct for all cases? */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 305 | static bool fwnet_frag_overlap(struct fwnet_partial_datagram *pd, |
| 306 | unsigned offset, unsigned len) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 307 | { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 308 | struct fwnet_fragment_info *fi; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 309 | unsigned end = offset + len; |
| 310 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 311 | list_for_each_entry(fi, &pd->fi_list, fi_link) |
| 312 | if (offset < fi->offset + fi->len && end > fi->offset) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 313 | return true; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 314 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 315 | return false; |
| 316 | } |
| 317 | |
| 318 | /* Assumes that new fragment does not overlap any existing fragments */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 319 | static struct fwnet_fragment_info *fwnet_frag_new( |
| 320 | struct fwnet_partial_datagram *pd, unsigned offset, unsigned len) |
| 321 | { |
| 322 | struct fwnet_fragment_info *fi, *fi2, *new; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 323 | struct list_head *list; |
| 324 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 325 | list = &pd->fi_list; |
| 326 | list_for_each_entry(fi, &pd->fi_list, fi_link) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 327 | if (fi->offset + fi->len == offset) { |
| 328 | /* The new fragment can be tacked on to the end */ |
| 329 | /* Did the new fragment plug a hole? */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 330 | fi2 = list_entry(fi->fi_link.next, |
| 331 | struct fwnet_fragment_info, fi_link); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 332 | if (fi->offset + fi->len == fi2->offset) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 333 | /* glue fragments together */ |
| 334 | fi->len += len + fi2->len; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 335 | list_del(&fi2->fi_link); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 336 | kfree(fi2); |
| 337 | } else { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 338 | fi->len += len; |
| 339 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 340 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 341 | return fi; |
| 342 | } |
| 343 | if (offset + len == fi->offset) { |
| 344 | /* The new fragment can be tacked on to the beginning */ |
| 345 | /* Did the new fragment plug a hole? */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 346 | fi2 = list_entry(fi->fi_link.prev, |
| 347 | struct fwnet_fragment_info, fi_link); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 348 | if (fi2->offset + fi2->len == fi->offset) { |
| 349 | /* glue fragments together */ |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 350 | fi2->len += fi->len + len; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 351 | list_del(&fi->fi_link); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 352 | kfree(fi); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 353 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 354 | return fi2; |
| 355 | } |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 356 | fi->offset = offset; |
| 357 | fi->len += len; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 358 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 359 | return fi; |
| 360 | } |
| 361 | if (offset > fi->offset + fi->len) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 362 | list = &fi->fi_link; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | if (offset + len < fi->offset) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 366 | list = fi->fi_link.prev; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 367 | break; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | new = kmalloc(sizeof(*new), GFP_ATOMIC); |
| 372 | if (!new) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 373 | fw_error("out of memory\n"); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 374 | return NULL; |
| 375 | } |
| 376 | |
| 377 | new->offset = offset; |
| 378 | new->len = len; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 379 | list_add(&new->fi_link, list); |
| 380 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 381 | return new; |
| 382 | } |
| 383 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 384 | static struct fwnet_partial_datagram *fwnet_pd_new(struct net_device *net, |
| 385 | struct fwnet_peer *peer, u16 datagram_label, unsigned dg_size, |
| 386 | void *frag_buf, unsigned frag_off, unsigned frag_len) |
| 387 | { |
| 388 | struct fwnet_partial_datagram *new; |
| 389 | struct fwnet_fragment_info *fi; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 390 | |
| 391 | new = kmalloc(sizeof(*new), GFP_ATOMIC); |
| 392 | if (!new) |
| 393 | goto fail; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 394 | |
| 395 | INIT_LIST_HEAD(&new->fi_list); |
| 396 | fi = fwnet_frag_new(new, frag_off, frag_len); |
| 397 | if (fi == NULL) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 398 | goto fail_w_new; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 399 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 400 | new->datagram_label = datagram_label; |
| 401 | new->datagram_size = dg_size; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 402 | new->skb = dev_alloc_skb(dg_size + net->hard_header_len + 15); |
| 403 | if (new->skb == NULL) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 404 | goto fail_w_fi; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 405 | |
| 406 | skb_reserve(new->skb, (net->hard_header_len + 15) & ~15); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 407 | new->pbuf = skb_put(new->skb, dg_size); |
| 408 | memcpy(new->pbuf + frag_off, frag_buf, frag_len); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 409 | list_add_tail(&new->pd_link, &peer->pd_list); |
| 410 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 411 | return new; |
| 412 | |
| 413 | fail_w_fi: |
| 414 | kfree(fi); |
| 415 | fail_w_new: |
| 416 | kfree(new); |
| 417 | fail: |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 418 | fw_error("out of memory\n"); |
| 419 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 420 | return NULL; |
| 421 | } |
| 422 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 423 | static struct fwnet_partial_datagram *fwnet_pd_find(struct fwnet_peer *peer, |
| 424 | u16 datagram_label) |
| 425 | { |
| 426 | struct fwnet_partial_datagram *pd; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 427 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 428 | list_for_each_entry(pd, &peer->pd_list, pd_link) |
| 429 | if (pd->datagram_label == datagram_label) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 430 | return pd; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 431 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 432 | return NULL; |
| 433 | } |
| 434 | |
| 435 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 436 | static void fwnet_pd_delete(struct fwnet_partial_datagram *old) |
| 437 | { |
| 438 | struct fwnet_fragment_info *fi, *n; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 439 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 440 | list_for_each_entry_safe(fi, n, &old->fi_list, fi_link) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 441 | kfree(fi); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 442 | |
| 443 | list_del(&old->pd_link); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 444 | dev_kfree_skb_any(old->skb); |
| 445 | kfree(old); |
| 446 | } |
| 447 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 448 | static bool fwnet_pd_update(struct fwnet_peer *peer, |
| 449 | struct fwnet_partial_datagram *pd, void *frag_buf, |
| 450 | unsigned frag_off, unsigned frag_len) |
| 451 | { |
| 452 | if (fwnet_frag_new(pd, frag_off, frag_len) == NULL) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 453 | return false; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 454 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 455 | memcpy(pd->pbuf + frag_off, frag_buf, frag_len); |
| 456 | |
| 457 | /* |
| 458 | * Move list entry to beginnig of list so that oldest partial |
| 459 | * datagrams percolate to the end of the list |
| 460 | */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 461 | list_move_tail(&pd->pd_link, &peer->pd_list); |
| 462 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 463 | return true; |
| 464 | } |
| 465 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 466 | static bool fwnet_pd_is_complete(struct fwnet_partial_datagram *pd) |
| 467 | { |
| 468 | struct fwnet_fragment_info *fi; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 469 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 470 | fi = list_entry(pd->fi_list.next, struct fwnet_fragment_info, fi_link); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 471 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 472 | return fi->len == pd->datagram_size; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 473 | } |
| 474 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 475 | /* caller must hold dev->lock */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 476 | static struct fwnet_peer *fwnet_peer_find_by_guid(struct fwnet_device *dev, |
| 477 | u64 guid) |
| 478 | { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 479 | struct fwnet_peer *peer; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 480 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 481 | list_for_each_entry(peer, &dev->peer_list, peer_link) |
| 482 | if (peer->guid == guid) |
| 483 | return peer; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 484 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 485 | return NULL; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 486 | } |
| 487 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 488 | /* caller must hold dev->lock */ |
| 489 | static struct fwnet_peer *fwnet_peer_find_by_node_id(struct fwnet_device *dev, |
| 490 | int node_id, int generation) |
| 491 | { |
| 492 | struct fwnet_peer *peer; |
| 493 | |
| 494 | list_for_each_entry(peer, &dev->peer_list, peer_link) |
| 495 | if (peer->node_id == node_id && |
| 496 | peer->generation == generation) |
| 497 | return peer; |
| 498 | |
| 499 | return NULL; |
| 500 | } |
| 501 | |
| 502 | /* See IEEE 1394-2008 table 6-4, table 8-8, table 16-18. */ |
| 503 | static unsigned fwnet_max_payload(unsigned max_rec, unsigned speed) |
| 504 | { |
| 505 | max_rec = min(max_rec, speed + 8); |
| 506 | max_rec = min(max_rec, 0xbU); /* <= 4096 */ |
| 507 | if (max_rec < 8) { |
| 508 | fw_notify("max_rec %x out of range\n", max_rec); |
| 509 | max_rec = 8; |
| 510 | } |
| 511 | |
| 512 | return (1 << (max_rec + 1)) - RFC2374_FRAG_HDR_SIZE; |
| 513 | } |
| 514 | |
| 515 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 516 | static int fwnet_finish_incoming_packet(struct net_device *net, |
| 517 | struct sk_buff *skb, u16 source_node_id, |
| 518 | bool is_broadcast, u16 ether_type) |
| 519 | { |
| 520 | struct fwnet_device *dev; |
| 521 | static const __be64 broadcast_hw = cpu_to_be64(~0ULL); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 522 | int status; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 523 | __be64 guid; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 524 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 525 | dev = netdev_priv(net); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 526 | /* Write metadata, and then pass to the receive level */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 527 | skb->dev = net; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 528 | skb->ip_summed = CHECKSUM_UNNECESSARY; /* don't check it */ |
| 529 | |
| 530 | /* |
| 531 | * Parse the encapsulation header. This actually does the job of |
| 532 | * converting to an ethernet frame header, as well as arp |
| 533 | * conversion if needed. ARP conversion is easier in this |
| 534 | * direction, since we are using ethernet as our backend. |
| 535 | */ |
| 536 | /* |
| 537 | * If this is an ARP packet, convert it. First, we want to make |
| 538 | * use of some of the fields, since they tell us a little bit |
| 539 | * about the sending machine. |
| 540 | */ |
| 541 | if (ether_type == ETH_P_ARP) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 542 | struct rfc2734_arp *arp1394; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 543 | struct arphdr *arp; |
| 544 | unsigned char *arp_ptr; |
| 545 | u64 fifo_addr; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 546 | u64 peer_guid; |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 547 | unsigned sspd; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 548 | u16 max_payload; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 549 | struct fwnet_peer *peer; |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 550 | unsigned long flags; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 551 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 552 | arp1394 = (struct rfc2734_arp *)skb->data; |
| 553 | arp = (struct arphdr *)skb->data; |
| 554 | arp_ptr = (unsigned char *)(arp + 1); |
| 555 | peer_guid = get_unaligned_be64(&arp1394->s_uniq_id); |
| 556 | fifo_addr = (u64)get_unaligned_be16(&arp1394->fifo_hi) << 32 |
| 557 | | get_unaligned_be32(&arp1394->fifo_lo); |
| 558 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 559 | sspd = arp1394->sspd; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 560 | /* Sanity check. OS X 10.3 PPC reportedly sends 131. */ |
| 561 | if (sspd > SCODE_3200) { |
| 562 | fw_notify("sspd %x out of range\n", sspd); |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 563 | sspd = SCODE_3200; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 564 | } |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 565 | max_payload = fwnet_max_payload(arp1394->max_rec, sspd); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 566 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 567 | spin_lock_irqsave(&dev->lock, flags); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 568 | peer = fwnet_peer_find_by_guid(dev, peer_guid); |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 569 | if (peer) { |
| 570 | peer->fifo = fifo_addr; |
| 571 | |
| 572 | if (peer->speed > sspd) |
| 573 | peer->speed = sspd; |
| 574 | if (peer->max_payload > max_payload) |
| 575 | peer->max_payload = max_payload; |
| 576 | } |
| 577 | spin_unlock_irqrestore(&dev->lock, flags); |
| 578 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 579 | if (!peer) { |
| 580 | fw_notify("No peer for ARP packet from %016llx\n", |
| 581 | (unsigned long long)peer_guid); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 582 | goto failed_proto; |
| 583 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 584 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 585 | /* |
| 586 | * Now that we're done with the 1394 specific stuff, we'll |
| 587 | * need to alter some of the data. Believe it or not, all |
| 588 | * that needs to be done is sender_IP_address needs to be |
| 589 | * moved, the destination hardware address get stuffed |
| 590 | * in and the hardware address length set to 8. |
| 591 | * |
| 592 | * IMPORTANT: The code below overwrites 1394 specific data |
| 593 | * needed above so keep the munging of the data for the |
| 594 | * higher level IP stack last. |
| 595 | */ |
| 596 | |
| 597 | arp->ar_hln = 8; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 598 | /* skip over sender unique id */ |
| 599 | arp_ptr += arp->ar_hln; |
| 600 | /* move sender IP addr */ |
| 601 | put_unaligned(arp1394->sip, (u32 *)arp_ptr); |
| 602 | /* skip over sender IP addr */ |
| 603 | arp_ptr += arp->ar_pln; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 604 | |
| 605 | if (arp->ar_op == htons(ARPOP_REQUEST)) |
| 606 | memset(arp_ptr, 0, sizeof(u64)); |
| 607 | else |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 608 | memcpy(arp_ptr, net->dev_addr, sizeof(u64)); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /* Now add the ethernet header. */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 612 | guid = cpu_to_be64(dev->card->guid); |
| 613 | if (dev_hard_header(skb, net, ether_type, |
| 614 | is_broadcast ? &broadcast_hw : &guid, |
| 615 | NULL, skb->len) >= 0) { |
| 616 | struct fwnet_header *eth; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 617 | u16 *rawp; |
| 618 | __be16 protocol; |
| 619 | |
| 620 | skb_reset_mac_header(skb); |
| 621 | skb_pull(skb, sizeof(*eth)); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 622 | eth = (struct fwnet_header *)skb_mac_header(skb); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 623 | if (*eth->h_dest & 1) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 624 | if (memcmp(eth->h_dest, net->broadcast, |
| 625 | net->addr_len) == 0) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 626 | skb->pkt_type = PACKET_BROADCAST; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 627 | #if 0 |
| 628 | else |
| 629 | skb->pkt_type = PACKET_MULTICAST; |
| 630 | #endif |
| 631 | } else { |
Stefan Richter | 156ce86 | 2009-06-14 11:46:57 +0200 | [diff] [blame] | 632 | if (memcmp(eth->h_dest, net->dev_addr, net->addr_len)) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 633 | skb->pkt_type = PACKET_OTHERHOST; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 634 | } |
| 635 | if (ntohs(eth->h_proto) >= 1536) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 636 | protocol = eth->h_proto; |
| 637 | } else { |
| 638 | rawp = (u16 *)skb->data; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 639 | if (*rawp == 0xffff) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 640 | protocol = htons(ETH_P_802_3); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 641 | else |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 642 | protocol = htons(ETH_P_802_2); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 643 | } |
| 644 | skb->protocol = protocol; |
| 645 | } |
| 646 | status = netif_rx(skb); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 647 | if (status == NET_RX_DROP) { |
| 648 | net->stats.rx_errors++; |
| 649 | net->stats.rx_dropped++; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 650 | } else { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 651 | net->stats.rx_packets++; |
| 652 | net->stats.rx_bytes += skb->len; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 653 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 654 | if (netif_queue_stopped(net)) |
| 655 | netif_wake_queue(net); |
| 656 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 657 | return 0; |
| 658 | |
| 659 | failed_proto: |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 660 | net->stats.rx_errors++; |
| 661 | net->stats.rx_dropped++; |
| 662 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 663 | dev_kfree_skb_any(skb); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 664 | if (netif_queue_stopped(net)) |
| 665 | netif_wake_queue(net); |
| 666 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 667 | return 0; |
| 668 | } |
| 669 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 670 | static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len, |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 671 | int source_node_id, int generation, |
| 672 | bool is_broadcast) |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 673 | { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 674 | struct sk_buff *skb; |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 675 | struct net_device *net = dev->netdev; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 676 | struct rfc2734_header hdr; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 677 | unsigned lf; |
| 678 | unsigned long flags; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 679 | struct fwnet_peer *peer; |
| 680 | struct fwnet_partial_datagram *pd; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 681 | int fg_off; |
| 682 | int dg_size; |
| 683 | u16 datagram_label; |
| 684 | int retval; |
| 685 | u16 ether_type; |
| 686 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 687 | hdr.w0 = be32_to_cpu(buf[0]); |
| 688 | lf = fwnet_get_hdr_lf(&hdr); |
| 689 | if (lf == RFC2374_HDR_UNFRAG) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 690 | /* |
| 691 | * An unfragmented datagram has been received by the ieee1394 |
| 692 | * bus. Build an skbuff around it so we can pass it to the |
| 693 | * high level network layer. |
| 694 | */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 695 | ether_type = fwnet_get_hdr_ether_type(&hdr); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 696 | buf++; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 697 | len -= RFC2374_UNFRAG_HDR_SIZE; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 698 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 699 | skb = dev_alloc_skb(len + net->hard_header_len + 15); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 700 | if (unlikely(!skb)) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 701 | fw_error("out of memory\n"); |
| 702 | net->stats.rx_dropped++; |
| 703 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 704 | return -1; |
| 705 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 706 | skb_reserve(skb, (net->hard_header_len + 15) & ~15); |
| 707 | memcpy(skb_put(skb, len), buf, len); |
| 708 | |
| 709 | return fwnet_finish_incoming_packet(net, skb, source_node_id, |
| 710 | is_broadcast, ether_type); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 711 | } |
| 712 | /* A datagram fragment has been received, now the fun begins. */ |
| 713 | hdr.w1 = ntohl(buf[1]); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 714 | buf += 2; |
| 715 | len -= RFC2374_FRAG_HDR_SIZE; |
| 716 | if (lf == RFC2374_HDR_FIRSTFRAG) { |
| 717 | ether_type = fwnet_get_hdr_ether_type(&hdr); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 718 | fg_off = 0; |
| 719 | } else { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 720 | ether_type = 0; |
| 721 | fg_off = fwnet_get_hdr_fg_off(&hdr); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 722 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 723 | datagram_label = fwnet_get_hdr_dgl(&hdr); |
| 724 | dg_size = fwnet_get_hdr_dg_size(&hdr); /* ??? + 1 */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 725 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 726 | spin_lock_irqsave(&dev->lock, flags); |
| 727 | |
| 728 | peer = fwnet_peer_find_by_node_id(dev, source_node_id, generation); |
| 729 | if (!peer) |
| 730 | goto bad_proto; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 731 | |
| 732 | pd = fwnet_pd_find(peer, datagram_label); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 733 | if (pd == NULL) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 734 | while (peer->pdg_size >= FWNET_MAX_FRAGMENTS) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 735 | /* remove the oldest */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 736 | fwnet_pd_delete(list_first_entry(&peer->pd_list, |
| 737 | struct fwnet_partial_datagram, pd_link)); |
| 738 | peer->pdg_size--; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 739 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 740 | pd = fwnet_pd_new(net, peer, datagram_label, |
| 741 | dg_size, buf, fg_off, len); |
| 742 | if (pd == NULL) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 743 | retval = -ENOMEM; |
| 744 | goto bad_proto; |
| 745 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 746 | peer->pdg_size++; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 747 | } else { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 748 | if (fwnet_frag_overlap(pd, fg_off, len) || |
| 749 | pd->datagram_size != dg_size) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 750 | /* |
| 751 | * Differing datagram sizes or overlapping fragments, |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 752 | * discard old datagram and start a new one. |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 753 | */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 754 | fwnet_pd_delete(pd); |
| 755 | pd = fwnet_pd_new(net, peer, datagram_label, |
| 756 | dg_size, buf, fg_off, len); |
| 757 | if (pd == NULL) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 758 | retval = -ENOMEM; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 759 | peer->pdg_size--; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 760 | goto bad_proto; |
| 761 | } |
| 762 | } else { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 763 | if (!fwnet_pd_update(peer, pd, buf, fg_off, len)) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 764 | /* |
| 765 | * Couldn't save off fragment anyway |
| 766 | * so might as well obliterate the |
| 767 | * datagram now. |
| 768 | */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 769 | fwnet_pd_delete(pd); |
| 770 | peer->pdg_size--; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 771 | goto bad_proto; |
| 772 | } |
| 773 | } |
| 774 | } /* new datagram or add to existing one */ |
| 775 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 776 | if (lf == RFC2374_HDR_FIRSTFRAG) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 777 | pd->ether_type = ether_type; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 778 | |
| 779 | if (fwnet_pd_is_complete(pd)) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 780 | ether_type = pd->ether_type; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 781 | peer->pdg_size--; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 782 | skb = skb_get(pd->skb); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 783 | fwnet_pd_delete(pd); |
| 784 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 785 | spin_unlock_irqrestore(&dev->lock, flags); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 786 | |
| 787 | return fwnet_finish_incoming_packet(net, skb, source_node_id, |
| 788 | false, ether_type); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 789 | } |
| 790 | /* |
| 791 | * Datagram is not complete, we're done for the |
| 792 | * moment. |
| 793 | */ |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 794 | spin_unlock_irqrestore(&dev->lock, flags); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 795 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 796 | return 0; |
| 797 | |
| 798 | bad_proto: |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 799 | spin_unlock_irqrestore(&dev->lock, flags); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 800 | |
| 801 | if (netif_queue_stopped(net)) |
| 802 | netif_wake_queue(net); |
| 803 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 804 | return 0; |
| 805 | } |
| 806 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 807 | static void fwnet_receive_packet(struct fw_card *card, struct fw_request *r, |
| 808 | int tcode, int destination, int source, int generation, |
| 809 | int speed, unsigned long long offset, void *payload, |
| 810 | size_t length, void *callback_data) |
| 811 | { |
Stefan Richter | 00635b8 | 2009-06-16 22:35:32 +0200 | [diff] [blame] | 812 | struct fwnet_device *dev = callback_data; |
| 813 | int rcode; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 814 | |
Stefan Richter | 00635b8 | 2009-06-16 22:35:32 +0200 | [diff] [blame] | 815 | if (destination == IEEE1394_ALL_NODES) { |
| 816 | kfree(r); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 817 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 818 | return; |
| 819 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 820 | |
Stefan Richter | 00635b8 | 2009-06-16 22:35:32 +0200 | [diff] [blame] | 821 | if (offset != dev->handler.offset) |
| 822 | rcode = RCODE_ADDRESS_ERROR; |
| 823 | else if (tcode != TCODE_WRITE_BLOCK_REQUEST) |
| 824 | rcode = RCODE_TYPE_ERROR; |
| 825 | else if (fwnet_incoming_packet(dev, payload, length, |
| 826 | source, generation, false) != 0) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 827 | fw_error("Incoming packet failure\n"); |
Stefan Richter | 00635b8 | 2009-06-16 22:35:32 +0200 | [diff] [blame] | 828 | rcode = RCODE_CONFLICT_ERROR; |
| 829 | } else |
| 830 | rcode = RCODE_COMPLETE; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 831 | |
Stefan Richter | 00635b8 | 2009-06-16 22:35:32 +0200 | [diff] [blame] | 832 | fw_send_response(card, r, rcode); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 833 | } |
| 834 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 835 | static void fwnet_receive_broadcast(struct fw_iso_context *context, |
| 836 | u32 cycle, size_t header_length, void *header, void *data) |
| 837 | { |
| 838 | struct fwnet_device *dev; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 839 | struct fw_iso_packet packet; |
| 840 | struct fw_card *card; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 841 | __be16 *hdr_ptr; |
| 842 | __be32 *buf_ptr; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 843 | int retval; |
| 844 | u32 length; |
| 845 | u16 source_node_id; |
| 846 | u32 specifier_id; |
| 847 | u32 ver; |
| 848 | unsigned long offset; |
| 849 | unsigned long flags; |
| 850 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 851 | dev = data; |
| 852 | card = dev->card; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 853 | hdr_ptr = header; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 854 | length = be16_to_cpup(hdr_ptr); |
| 855 | |
| 856 | spin_lock_irqsave(&dev->lock, flags); |
| 857 | |
| 858 | offset = dev->rcv_buffer_size * dev->broadcast_rcv_next_ptr; |
| 859 | buf_ptr = dev->broadcast_rcv_buffer_ptrs[dev->broadcast_rcv_next_ptr++]; |
| 860 | if (dev->broadcast_rcv_next_ptr == dev->num_broadcast_rcv_ptrs) |
| 861 | dev->broadcast_rcv_next_ptr = 0; |
| 862 | |
| 863 | spin_unlock_irqrestore(&dev->lock, flags); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 864 | |
| 865 | specifier_id = (be32_to_cpu(buf_ptr[0]) & 0xffff) << 8 |
| 866 | | (be32_to_cpu(buf_ptr[1]) & 0xff000000) >> 24; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 867 | ver = be32_to_cpu(buf_ptr[1]) & 0xffffff; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 868 | source_node_id = be32_to_cpu(buf_ptr[0]) >> 16; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 869 | |
| 870 | if (specifier_id == IANA_SPECIFIER_ID && ver == RFC2734_SW_VERSION) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 871 | buf_ptr += 2; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 872 | length -= IEEE1394_GASP_HDR_SIZE; |
| 873 | fwnet_incoming_packet(dev, buf_ptr, length, |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 874 | source_node_id, -1, true); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | packet.payload_length = dev->rcv_buffer_size; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 878 | packet.interrupt = 1; |
| 879 | packet.skip = 0; |
| 880 | packet.tag = 3; |
| 881 | packet.sy = 0; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 882 | packet.header_length = IEEE1394_GASP_HDR_SIZE; |
| 883 | |
| 884 | spin_lock_irqsave(&dev->lock, flags); |
| 885 | |
| 886 | retval = fw_iso_context_queue(dev->broadcast_rcv_context, &packet, |
| 887 | &dev->broadcast_rcv_buffer, offset); |
| 888 | |
| 889 | spin_unlock_irqrestore(&dev->lock, flags); |
| 890 | |
| 891 | if (retval < 0) |
| 892 | fw_error("requeue failed\n"); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 893 | } |
| 894 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 895 | static struct kmem_cache *fwnet_packet_task_cache; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 896 | |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 897 | static void fwnet_free_ptask(struct fwnet_packet_task *ptask) |
| 898 | { |
| 899 | dev_kfree_skb_any(ptask->skb); |
| 900 | kmem_cache_free(fwnet_packet_task_cache, ptask); |
| 901 | } |
| 902 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 903 | static int fwnet_send_packet(struct fwnet_packet_task *ptask); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 904 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 905 | static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask) |
| 906 | { |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 907 | struct fwnet_device *dev = ptask->dev; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 908 | unsigned long flags; |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 909 | bool free; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 910 | |
| 911 | spin_lock_irqsave(&dev->lock, flags); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 912 | |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 913 | ptask->outstanding_pkts--; |
| 914 | |
| 915 | /* Check whether we or the networking TX soft-IRQ is last user. */ |
| 916 | free = (ptask->outstanding_pkts == 0 && !list_empty(&ptask->pt_link)); |
| 917 | |
| 918 | if (ptask->outstanding_pkts == 0) |
| 919 | list_del(&ptask->pt_link); |
| 920 | |
| 921 | spin_unlock_irqrestore(&dev->lock, flags); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 922 | |
| 923 | if (ptask->outstanding_pkts > 0) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 924 | u16 dg_size; |
| 925 | u16 fg_off; |
| 926 | u16 datagram_label; |
| 927 | u16 lf; |
| 928 | struct sk_buff *skb; |
| 929 | |
| 930 | /* Update the ptask to point to the next fragment and send it */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 931 | lf = fwnet_get_hdr_lf(&ptask->hdr); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 932 | switch (lf) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 933 | case RFC2374_HDR_LASTFRAG: |
| 934 | case RFC2374_HDR_UNFRAG: |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 935 | default: |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 936 | fw_error("Outstanding packet %x lf %x, header %x,%x\n", |
| 937 | ptask->outstanding_pkts, lf, ptask->hdr.w0, |
| 938 | ptask->hdr.w1); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 939 | BUG(); |
| 940 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 941 | case RFC2374_HDR_FIRSTFRAG: |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 942 | /* Set frag type here for future interior fragments */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 943 | dg_size = fwnet_get_hdr_dg_size(&ptask->hdr); |
| 944 | fg_off = ptask->max_payload - RFC2374_FRAG_HDR_SIZE; |
| 945 | datagram_label = fwnet_get_hdr_dgl(&ptask->hdr); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 946 | break; |
| 947 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 948 | case RFC2374_HDR_INTFRAG: |
| 949 | dg_size = fwnet_get_hdr_dg_size(&ptask->hdr); |
| 950 | fg_off = fwnet_get_hdr_fg_off(&ptask->hdr) |
| 951 | + ptask->max_payload - RFC2374_FRAG_HDR_SIZE; |
| 952 | datagram_label = fwnet_get_hdr_dgl(&ptask->hdr); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 953 | break; |
| 954 | } |
| 955 | skb = ptask->skb; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 956 | skb_pull(skb, ptask->max_payload); |
| 957 | if (ptask->outstanding_pkts > 1) { |
| 958 | fwnet_make_sf_hdr(&ptask->hdr, RFC2374_HDR_INTFRAG, |
| 959 | dg_size, fg_off, datagram_label); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 960 | } else { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 961 | fwnet_make_sf_hdr(&ptask->hdr, RFC2374_HDR_LASTFRAG, |
| 962 | dg_size, fg_off, datagram_label); |
| 963 | ptask->max_payload = skb->len + RFC2374_FRAG_HDR_SIZE; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 964 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 965 | fwnet_send_packet(ptask); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 966 | } |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 967 | |
| 968 | if (free) |
| 969 | fwnet_free_ptask(ptask); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 970 | } |
| 971 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 972 | static void fwnet_write_complete(struct fw_card *card, int rcode, |
| 973 | void *payload, size_t length, void *data) |
| 974 | { |
| 975 | struct fwnet_packet_task *ptask; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 976 | |
| 977 | ptask = data; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 978 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 979 | if (rcode == RCODE_COMPLETE) |
| 980 | fwnet_transmit_packet_done(ptask); |
| 981 | else |
| 982 | fw_error("fwnet_write_complete: failed: %x\n", rcode); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 983 | /* ??? error recovery */ |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 984 | } |
| 985 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 986 | static int fwnet_send_packet(struct fwnet_packet_task *ptask) |
| 987 | { |
| 988 | struct fwnet_device *dev; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 989 | unsigned tx_len; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 990 | struct rfc2734_header *bufhdr; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 991 | unsigned long flags; |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 992 | bool free; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 993 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 994 | dev = ptask->dev; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 995 | tx_len = ptask->max_payload; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 996 | switch (fwnet_get_hdr_lf(&ptask->hdr)) { |
| 997 | case RFC2374_HDR_UNFRAG: |
| 998 | bufhdr = (struct rfc2734_header *) |
| 999 | skb_push(ptask->skb, RFC2374_UNFRAG_HDR_SIZE); |
| 1000 | put_unaligned_be32(ptask->hdr.w0, &bufhdr->w0); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1001 | break; |
| 1002 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1003 | case RFC2374_HDR_FIRSTFRAG: |
| 1004 | case RFC2374_HDR_INTFRAG: |
| 1005 | case RFC2374_HDR_LASTFRAG: |
| 1006 | bufhdr = (struct rfc2734_header *) |
| 1007 | skb_push(ptask->skb, RFC2374_FRAG_HDR_SIZE); |
| 1008 | put_unaligned_be32(ptask->hdr.w0, &bufhdr->w0); |
| 1009 | put_unaligned_be32(ptask->hdr.w1, &bufhdr->w1); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1010 | break; |
| 1011 | |
| 1012 | default: |
| 1013 | BUG(); |
| 1014 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1015 | if (ptask->dest_node == IEEE1394_ALL_NODES) { |
| 1016 | u8 *p; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1017 | int generation; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1018 | int node_id; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1019 | |
| 1020 | /* ptask->generation may not have been set yet */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1021 | generation = dev->card->generation; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1022 | smp_rmb(); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1023 | node_id = dev->card->node_id; |
| 1024 | |
| 1025 | p = skb_push(ptask->skb, 8); |
| 1026 | put_unaligned_be32(node_id << 16 | IANA_SPECIFIER_ID >> 8, p); |
| 1027 | put_unaligned_be32((IANA_SPECIFIER_ID & 0xff) << 24 |
| 1028 | | RFC2734_SW_VERSION, &p[4]); |
| 1029 | |
| 1030 | /* We should not transmit if broadcast_channel.valid == 0. */ |
| 1031 | fw_send_request(dev->card, &ptask->transaction, |
| 1032 | TCODE_STREAM_DATA, |
| 1033 | fw_stream_packet_destination_id(3, |
| 1034 | IEEE1394_BROADCAST_CHANNEL, 0), |
| 1035 | generation, SCODE_100, 0ULL, ptask->skb->data, |
| 1036 | tx_len + 8, fwnet_write_complete, ptask); |
| 1037 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1038 | spin_lock_irqsave(&dev->lock, flags); |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 1039 | |
| 1040 | /* If the AT tasklet already ran, we may be last user. */ |
| 1041 | free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link)); |
| 1042 | if (!free) |
| 1043 | list_add_tail(&ptask->pt_link, &dev->broadcasted_list); |
| 1044 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1045 | spin_unlock_irqrestore(&dev->lock, flags); |
| 1046 | |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 1047 | goto out; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1048 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1049 | |
| 1050 | fw_send_request(dev->card, &ptask->transaction, |
| 1051 | TCODE_WRITE_BLOCK_REQUEST, ptask->dest_node, |
| 1052 | ptask->generation, ptask->speed, ptask->fifo_addr, |
| 1053 | ptask->skb->data, tx_len, fwnet_write_complete, ptask); |
| 1054 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1055 | spin_lock_irqsave(&dev->lock, flags); |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 1056 | |
| 1057 | /* If the AT tasklet already ran, we may be last user. */ |
| 1058 | free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link)); |
| 1059 | if (!free) |
| 1060 | list_add_tail(&ptask->pt_link, &dev->sent_list); |
| 1061 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1062 | spin_unlock_irqrestore(&dev->lock, flags); |
| 1063 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1064 | dev->netdev->trans_start = jiffies; |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 1065 | out: |
| 1066 | if (free) |
| 1067 | fwnet_free_ptask(ptask); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1068 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1069 | return 0; |
| 1070 | } |
| 1071 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1072 | static int fwnet_broadcast_start(struct fwnet_device *dev) |
| 1073 | { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1074 | struct fw_iso_context *context; |
| 1075 | int retval; |
| 1076 | unsigned num_packets; |
| 1077 | unsigned max_receive; |
| 1078 | struct fw_iso_packet packet; |
| 1079 | unsigned long offset; |
| 1080 | unsigned u; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1081 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1082 | if (dev->local_fifo == FWNET_NO_FIFO_ADDR) { |
| 1083 | /* outside OHCI posted write area? */ |
| 1084 | static const struct fw_address_region region = { |
| 1085 | .start = 0xffff00000000ULL, |
| 1086 | .end = CSR_REGISTER_BASE, |
| 1087 | }; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1088 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1089 | dev->handler.length = 4096; |
| 1090 | dev->handler.address_callback = fwnet_receive_packet; |
| 1091 | dev->handler.callback_data = dev; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1092 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1093 | retval = fw_core_add_address_handler(&dev->handler, ®ion); |
| 1094 | if (retval < 0) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1095 | goto failed_initial; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1096 | |
| 1097 | dev->local_fifo = dev->handler.offset; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1098 | } |
| 1099 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1100 | max_receive = 1U << (dev->card->max_receive + 1); |
| 1101 | num_packets = (FWNET_ISO_PAGE_COUNT * PAGE_SIZE) / max_receive; |
| 1102 | |
| 1103 | if (!dev->broadcast_rcv_context) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1104 | void **ptrptr; |
| 1105 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1106 | context = fw_iso_context_create(dev->card, |
| 1107 | FW_ISO_CONTEXT_RECEIVE, IEEE1394_BROADCAST_CHANNEL, |
| 1108 | dev->card->link_speed, 8, fwnet_receive_broadcast, dev); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1109 | if (IS_ERR(context)) { |
| 1110 | retval = PTR_ERR(context); |
| 1111 | goto failed_context_create; |
| 1112 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1113 | |
| 1114 | retval = fw_iso_buffer_init(&dev->broadcast_rcv_buffer, |
| 1115 | dev->card, FWNET_ISO_PAGE_COUNT, DMA_FROM_DEVICE); |
| 1116 | if (retval < 0) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1117 | goto failed_buffer_init; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1118 | |
| 1119 | ptrptr = kmalloc(sizeof(void *) * num_packets, GFP_KERNEL); |
| 1120 | if (!ptrptr) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1121 | retval = -ENOMEM; |
| 1122 | goto failed_ptrs_alloc; |
| 1123 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1124 | |
| 1125 | dev->broadcast_rcv_buffer_ptrs = ptrptr; |
| 1126 | for (u = 0; u < FWNET_ISO_PAGE_COUNT; u++) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1127 | void *ptr; |
| 1128 | unsigned v; |
| 1129 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1130 | ptr = kmap(dev->broadcast_rcv_buffer.pages[u]); |
| 1131 | for (v = 0; v < num_packets / FWNET_ISO_PAGE_COUNT; v++) |
| 1132 | *ptrptr++ = (void *) |
| 1133 | ((char *)ptr + v * max_receive); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1134 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1135 | dev->broadcast_rcv_context = context; |
| 1136 | } else { |
| 1137 | context = dev->broadcast_rcv_context; |
| 1138 | } |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1139 | |
| 1140 | packet.payload_length = max_receive; |
| 1141 | packet.interrupt = 1; |
| 1142 | packet.skip = 0; |
| 1143 | packet.tag = 3; |
| 1144 | packet.sy = 0; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1145 | packet.header_length = IEEE1394_GASP_HDR_SIZE; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1146 | offset = 0; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1147 | |
| 1148 | for (u = 0; u < num_packets; u++) { |
| 1149 | retval = fw_iso_context_queue(context, &packet, |
| 1150 | &dev->broadcast_rcv_buffer, offset); |
| 1151 | if (retval < 0) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1152 | goto failed_rcv_queue; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1153 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1154 | offset += max_receive; |
| 1155 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1156 | dev->num_broadcast_rcv_ptrs = num_packets; |
| 1157 | dev->rcv_buffer_size = max_receive; |
| 1158 | dev->broadcast_rcv_next_ptr = 0U; |
| 1159 | retval = fw_iso_context_start(context, -1, 0, |
| 1160 | FW_ISO_CONTEXT_MATCH_ALL_TAGS); /* ??? sync */ |
| 1161 | if (retval < 0) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1162 | goto failed_rcv_queue; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1163 | |
| 1164 | /* FIXME: adjust it according to the min. speed of all known peers? */ |
| 1165 | dev->broadcast_xmt_max_payload = IEEE1394_MAX_PAYLOAD_S100 |
| 1166 | - IEEE1394_GASP_HDR_SIZE - RFC2374_UNFRAG_HDR_SIZE; |
| 1167 | dev->broadcast_state = FWNET_BROADCAST_RUNNING; |
| 1168 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1169 | return 0; |
| 1170 | |
| 1171 | failed_rcv_queue: |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1172 | kfree(dev->broadcast_rcv_buffer_ptrs); |
| 1173 | dev->broadcast_rcv_buffer_ptrs = NULL; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1174 | failed_ptrs_alloc: |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1175 | fw_iso_buffer_destroy(&dev->broadcast_rcv_buffer, dev->card); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1176 | failed_buffer_init: |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1177 | fw_iso_context_destroy(context); |
| 1178 | dev->broadcast_rcv_context = NULL; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1179 | failed_context_create: |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1180 | fw_core_remove_address_handler(&dev->handler); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1181 | failed_initial: |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1182 | dev->local_fifo = FWNET_NO_FIFO_ADDR; |
| 1183 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1184 | return retval; |
| 1185 | } |
| 1186 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1187 | /* ifup */ |
| 1188 | static int fwnet_open(struct net_device *net) |
| 1189 | { |
| 1190 | struct fwnet_device *dev = netdev_priv(net); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1191 | int ret; |
| 1192 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1193 | if (dev->broadcast_state == FWNET_BROADCAST_ERROR) { |
| 1194 | ret = fwnet_broadcast_start(dev); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1195 | if (ret) |
| 1196 | return ret; |
| 1197 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1198 | netif_start_queue(net); |
| 1199 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1203 | /* ifdown */ |
| 1204 | static int fwnet_stop(struct net_device *net) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1205 | { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1206 | netif_stop_queue(net); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1207 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1208 | /* Deallocate iso context for use by other applications? */ |
| 1209 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1210 | return 0; |
| 1211 | } |
| 1212 | |
Stephen Hemminger | 424efe9 | 2009-08-31 19:50:51 +0000 | [diff] [blame] | 1213 | static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net) |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1214 | { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1215 | struct fwnet_header hdr_buf; |
| 1216 | struct fwnet_device *dev = netdev_priv(net); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1217 | __be16 proto; |
| 1218 | u16 dest_node; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1219 | unsigned max_payload; |
| 1220 | u16 dg_size; |
| 1221 | u16 *datagram_label_ptr; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1222 | struct fwnet_packet_task *ptask; |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1223 | struct fwnet_peer *peer; |
| 1224 | unsigned long flags; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1225 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1226 | ptask = kmem_cache_alloc(fwnet_packet_task_cache, GFP_ATOMIC); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1227 | if (ptask == NULL) |
| 1228 | goto fail; |
| 1229 | |
| 1230 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 1231 | if (!skb) |
| 1232 | goto fail; |
| 1233 | |
| 1234 | /* |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1235 | * Make a copy of the driver-specific header. |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1236 | * We might need to rebuild the header on tx failure. |
| 1237 | */ |
| 1238 | memcpy(&hdr_buf, skb->data, sizeof(hdr_buf)); |
| 1239 | skb_pull(skb, sizeof(hdr_buf)); |
| 1240 | |
| 1241 | proto = hdr_buf.h_proto; |
| 1242 | dg_size = skb->len; |
| 1243 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1244 | /* serialize access to peer, including peer->datagram_label */ |
| 1245 | spin_lock_irqsave(&dev->lock, flags); |
| 1246 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1247 | /* |
| 1248 | * Set the transmission type for the packet. ARP packets and IP |
| 1249 | * broadcast packets are sent via GASP. |
| 1250 | */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1251 | if (memcmp(hdr_buf.h_dest, net->broadcast, FWNET_ALEN) == 0 |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1252 | || proto == htons(ETH_P_ARP) |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1253 | || (proto == htons(ETH_P_IP) |
| 1254 | && IN_MULTICAST(ntohl(ip_hdr(skb)->daddr)))) { |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1255 | max_payload = dev->broadcast_xmt_max_payload; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1256 | datagram_label_ptr = &dev->broadcast_xmt_datagramlabel; |
| 1257 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1258 | ptask->fifo_addr = FWNET_NO_FIFO_ADDR; |
| 1259 | ptask->generation = 0; |
| 1260 | ptask->dest_node = IEEE1394_ALL_NODES; |
| 1261 | ptask->speed = SCODE_100; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1262 | } else { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1263 | __be64 guid = get_unaligned((__be64 *)hdr_buf.h_dest); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1264 | u8 generation; |
| 1265 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1266 | peer = fwnet_peer_find_by_guid(dev, be64_to_cpu(guid)); |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1267 | if (!peer || peer->fifo == FWNET_NO_FIFO_ADDR) |
| 1268 | goto fail_unlock; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1269 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1270 | generation = peer->generation; |
| 1271 | dest_node = peer->node_id; |
| 1272 | max_payload = peer->max_payload; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1273 | datagram_label_ptr = &peer->datagram_label; |
| 1274 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1275 | ptask->fifo_addr = peer->fifo; |
| 1276 | ptask->generation = generation; |
| 1277 | ptask->dest_node = dest_node; |
| 1278 | ptask->speed = peer->speed; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | /* If this is an ARP packet, convert it */ |
| 1282 | if (proto == htons(ETH_P_ARP)) { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1283 | struct arphdr *arp = (struct arphdr *)skb->data; |
| 1284 | unsigned char *arp_ptr = (unsigned char *)(arp + 1); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1285 | struct rfc2734_arp *arp1394 = (struct rfc2734_arp *)skb->data; |
| 1286 | __be32 ipaddr; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1287 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1288 | ipaddr = get_unaligned((__be32 *)(arp_ptr + FWNET_ALEN)); |
| 1289 | |
| 1290 | arp1394->hw_addr_len = RFC2734_HW_ADDR_LEN; |
| 1291 | arp1394->max_rec = dev->card->max_receive; |
| 1292 | arp1394->sspd = dev->card->link_speed; |
| 1293 | |
| 1294 | put_unaligned_be16(dev->local_fifo >> 32, |
| 1295 | &arp1394->fifo_hi); |
| 1296 | put_unaligned_be32(dev->local_fifo & 0xffffffff, |
| 1297 | &arp1394->fifo_lo); |
| 1298 | put_unaligned(ipaddr, &arp1394->sip); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1299 | } |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1300 | |
| 1301 | ptask->hdr.w0 = 0; |
| 1302 | ptask->hdr.w1 = 0; |
| 1303 | ptask->skb = skb; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1304 | ptask->dev = dev; |
| 1305 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1306 | /* Does it all fit in one packet? */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1307 | if (dg_size <= max_payload) { |
| 1308 | fwnet_make_uf_hdr(&ptask->hdr, ntohs(proto)); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1309 | ptask->outstanding_pkts = 1; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1310 | max_payload = dg_size + RFC2374_UNFRAG_HDR_SIZE; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1311 | } else { |
| 1312 | u16 datagram_label; |
| 1313 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1314 | max_payload -= RFC2374_FRAG_OVERHEAD; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1315 | datagram_label = (*datagram_label_ptr)++; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1316 | fwnet_make_ff_hdr(&ptask->hdr, ntohs(proto), dg_size, |
| 1317 | datagram_label); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1318 | ptask->outstanding_pkts = DIV_ROUND_UP(dg_size, max_payload); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1319 | max_payload += RFC2374_FRAG_HDR_SIZE; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1320 | } |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1321 | |
| 1322 | spin_unlock_irqrestore(&dev->lock, flags); |
| 1323 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1324 | ptask->max_payload = max_payload; |
Stefan Richter | 110f82d | 2010-01-18 22:36:49 +0100 | [diff] [blame] | 1325 | INIT_LIST_HEAD(&ptask->pt_link); |
| 1326 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1327 | fwnet_send_packet(ptask); |
| 1328 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1329 | return NETDEV_TX_OK; |
| 1330 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1331 | fail_unlock: |
| 1332 | spin_unlock_irqrestore(&dev->lock, flags); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1333 | fail: |
| 1334 | if (ptask) |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1335 | kmem_cache_free(fwnet_packet_task_cache, ptask); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1336 | |
| 1337 | if (skb != NULL) |
| 1338 | dev_kfree_skb(skb); |
| 1339 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1340 | net->stats.tx_dropped++; |
| 1341 | net->stats.tx_errors++; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1342 | |
| 1343 | /* |
| 1344 | * FIXME: According to a patch from 2003-02-26, "returning non-zero |
| 1345 | * causes serious problems" here, allegedly. Before that patch, |
| 1346 | * -ERRNO was returned which is not appropriate under Linux 2.6. |
| 1347 | * Perhaps more needs to be done? Stop the queue in serious |
| 1348 | * conditions and restart it elsewhere? |
| 1349 | */ |
| 1350 | return NETDEV_TX_OK; |
| 1351 | } |
| 1352 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1353 | static int fwnet_change_mtu(struct net_device *net, int new_mtu) |
| 1354 | { |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1355 | if (new_mtu < 68) |
| 1356 | return -EINVAL; |
| 1357 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1358 | net->mtu = new_mtu; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1359 | return 0; |
| 1360 | } |
| 1361 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1362 | static void fwnet_get_drvinfo(struct net_device *net, |
| 1363 | struct ethtool_drvinfo *info) |
| 1364 | { |
| 1365 | strcpy(info->driver, KBUILD_MODNAME); |
| 1366 | strcpy(info->bus_info, "ieee1394"); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1367 | } |
| 1368 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 1369 | static const struct ethtool_ops fwnet_ethtool_ops = { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1370 | .get_drvinfo = fwnet_get_drvinfo, |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1371 | }; |
| 1372 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1373 | static const struct net_device_ops fwnet_netdev_ops = { |
| 1374 | .ndo_open = fwnet_open, |
| 1375 | .ndo_stop = fwnet_stop, |
| 1376 | .ndo_start_xmit = fwnet_tx, |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1377 | .ndo_change_mtu = fwnet_change_mtu, |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1378 | }; |
| 1379 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1380 | static void fwnet_init_dev(struct net_device *net) |
| 1381 | { |
| 1382 | net->header_ops = &fwnet_header_ops; |
| 1383 | net->netdev_ops = &fwnet_netdev_ops; |
Stefan Richter | 1337f85 | 2009-06-14 11:47:44 +0200 | [diff] [blame] | 1384 | net->watchdog_timeo = 2 * HZ; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1385 | net->flags = IFF_BROADCAST | IFF_MULTICAST; |
| 1386 | net->features = NETIF_F_HIGHDMA; |
| 1387 | net->addr_len = FWNET_ALEN; |
| 1388 | net->hard_header_len = FWNET_HLEN; |
| 1389 | net->type = ARPHRD_IEEE1394; |
Stefan Richter | 1337f85 | 2009-06-14 11:47:44 +0200 | [diff] [blame] | 1390 | net->tx_queue_len = 10; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1391 | SET_ETHTOOL_OPS(net, &fwnet_ethtool_ops); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1394 | /* caller must hold fwnet_device_mutex */ |
| 1395 | static struct fwnet_device *fwnet_dev_find(struct fw_card *card) |
| 1396 | { |
| 1397 | struct fwnet_device *dev; |
| 1398 | |
| 1399 | list_for_each_entry(dev, &fwnet_device_list, dev_link) |
| 1400 | if (dev->card == card) |
| 1401 | return dev; |
| 1402 | |
| 1403 | return NULL; |
| 1404 | } |
| 1405 | |
| 1406 | static int fwnet_add_peer(struct fwnet_device *dev, |
| 1407 | struct fw_unit *unit, struct fw_device *device) |
| 1408 | { |
| 1409 | struct fwnet_peer *peer; |
| 1410 | |
| 1411 | peer = kmalloc(sizeof(*peer), GFP_KERNEL); |
| 1412 | if (!peer) |
| 1413 | return -ENOMEM; |
| 1414 | |
Stefan Richter | b01b4ba | 2009-06-16 20:43:55 +0200 | [diff] [blame] | 1415 | dev_set_drvdata(&unit->device, peer); |
| 1416 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1417 | peer->dev = dev; |
| 1418 | peer->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; |
| 1419 | peer->fifo = FWNET_NO_FIFO_ADDR; |
| 1420 | INIT_LIST_HEAD(&peer->pd_list); |
| 1421 | peer->pdg_size = 0; |
| 1422 | peer->datagram_label = 0; |
| 1423 | peer->speed = device->max_speed; |
| 1424 | peer->max_payload = fwnet_max_payload(device->max_rec, peer->speed); |
| 1425 | |
| 1426 | peer->generation = device->generation; |
| 1427 | smp_rmb(); |
| 1428 | peer->node_id = device->node_id; |
| 1429 | |
| 1430 | spin_lock_irq(&dev->lock); |
| 1431 | list_add_tail(&peer->peer_link, &dev->peer_list); |
| 1432 | spin_unlock_irq(&dev->lock); |
| 1433 | |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1437 | static int fwnet_probe(struct device *_dev) |
| 1438 | { |
| 1439 | struct fw_unit *unit = fw_unit(_dev); |
| 1440 | struct fw_device *device = fw_parent_device(unit); |
| 1441 | struct fw_card *card = device->card; |
| 1442 | struct net_device *net; |
Stefan Richter | b01b4ba | 2009-06-16 20:43:55 +0200 | [diff] [blame] | 1443 | bool allocated_netdev = false; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1444 | struct fwnet_device *dev; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1445 | unsigned max_mtu; |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1446 | int ret; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1447 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1448 | mutex_lock(&fwnet_device_mutex); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1449 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1450 | dev = fwnet_dev_find(card); |
| 1451 | if (dev) { |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1452 | net = dev->netdev; |
| 1453 | goto have_dev; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1454 | } |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1455 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1456 | net = alloc_netdev(sizeof(*dev), "firewire%d", fwnet_init_dev); |
| 1457 | if (net == NULL) { |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1458 | ret = -ENOMEM; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1459 | goto out; |
| 1460 | } |
| 1461 | |
Stefan Richter | b01b4ba | 2009-06-16 20:43:55 +0200 | [diff] [blame] | 1462 | allocated_netdev = true; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1463 | SET_NETDEV_DEV(net, card->device); |
| 1464 | dev = netdev_priv(net); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1465 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1466 | spin_lock_init(&dev->lock); |
| 1467 | dev->broadcast_state = FWNET_BROADCAST_ERROR; |
| 1468 | dev->broadcast_rcv_context = NULL; |
| 1469 | dev->broadcast_xmt_max_payload = 0; |
| 1470 | dev->broadcast_xmt_datagramlabel = 0; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1471 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1472 | dev->local_fifo = FWNET_NO_FIFO_ADDR; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1473 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1474 | INIT_LIST_HEAD(&dev->packet_list); |
| 1475 | INIT_LIST_HEAD(&dev->broadcasted_list); |
| 1476 | INIT_LIST_HEAD(&dev->sent_list); |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1477 | INIT_LIST_HEAD(&dev->peer_list); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1478 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1479 | dev->card = card; |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1480 | dev->netdev = net; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1481 | |
| 1482 | /* |
| 1483 | * Use the RFC 2734 default 1500 octets or the maximum payload |
| 1484 | * as initial MTU |
| 1485 | */ |
| 1486 | max_mtu = (1 << (card->max_receive + 1)) |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1487 | - sizeof(struct rfc2734_header) - IEEE1394_GASP_HDR_SIZE; |
| 1488 | net->mtu = min(1500U, max_mtu); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1489 | |
| 1490 | /* Set our hardware address while we're at it */ |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1491 | put_unaligned_be64(card->guid, net->dev_addr); |
| 1492 | put_unaligned_be64(~0ULL, net->broadcast); |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1493 | ret = register_netdev(net); |
| 1494 | if (ret) { |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1495 | fw_error("Cannot register the driver\n"); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1496 | goto out; |
| 1497 | } |
| 1498 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1499 | list_add_tail(&dev->dev_link, &fwnet_device_list); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1500 | fw_notify("%s: IPv4 over FireWire on device %016llx\n", |
| 1501 | net->name, (unsigned long long)card->guid); |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1502 | have_dev: |
| 1503 | ret = fwnet_add_peer(dev, unit, device); |
Stefan Richter | b01b4ba | 2009-06-16 20:43:55 +0200 | [diff] [blame] | 1504 | if (ret && allocated_netdev) { |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1505 | unregister_netdev(net); |
| 1506 | list_del(&dev->dev_link); |
| 1507 | } |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1508 | out: |
Stefan Richter | b01b4ba | 2009-06-16 20:43:55 +0200 | [diff] [blame] | 1509 | if (ret && allocated_netdev) |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1510 | free_netdev(net); |
| 1511 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1512 | mutex_unlock(&fwnet_device_mutex); |
| 1513 | |
| 1514 | return ret; |
| 1515 | } |
| 1516 | |
| 1517 | static void fwnet_remove_peer(struct fwnet_peer *peer) |
| 1518 | { |
| 1519 | struct fwnet_partial_datagram *pd, *pd_next; |
| 1520 | |
| 1521 | spin_lock_irq(&peer->dev->lock); |
| 1522 | list_del(&peer->peer_link); |
| 1523 | spin_unlock_irq(&peer->dev->lock); |
| 1524 | |
| 1525 | list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link) |
| 1526 | fwnet_pd_delete(pd); |
| 1527 | |
| 1528 | kfree(peer); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1529 | } |
| 1530 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1531 | static int fwnet_remove(struct device *_dev) |
| 1532 | { |
Stefan Richter | b01b4ba | 2009-06-16 20:43:55 +0200 | [diff] [blame] | 1533 | struct fwnet_peer *peer = dev_get_drvdata(_dev); |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1534 | struct fwnet_device *dev = peer->dev; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1535 | struct net_device *net; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1536 | struct fwnet_packet_task *ptask, *pt_next; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1537 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1538 | mutex_lock(&fwnet_device_mutex); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1539 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1540 | fwnet_remove_peer(peer); |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1541 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1542 | if (list_empty(&dev->peer_list)) { |
| 1543 | net = dev->netdev; |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1544 | unregister_netdev(net); |
| 1545 | |
| 1546 | if (dev->local_fifo != FWNET_NO_FIFO_ADDR) |
| 1547 | fw_core_remove_address_handler(&dev->handler); |
| 1548 | if (dev->broadcast_rcv_context) { |
| 1549 | fw_iso_context_stop(dev->broadcast_rcv_context); |
| 1550 | fw_iso_buffer_destroy(&dev->broadcast_rcv_buffer, |
| 1551 | dev->card); |
| 1552 | fw_iso_context_destroy(dev->broadcast_rcv_context); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1553 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1554 | list_for_each_entry_safe(ptask, pt_next, |
| 1555 | &dev->packet_list, pt_link) { |
| 1556 | dev_kfree_skb_any(ptask->skb); |
| 1557 | kmem_cache_free(fwnet_packet_task_cache, ptask); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1558 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1559 | list_for_each_entry_safe(ptask, pt_next, |
| 1560 | &dev->broadcasted_list, pt_link) { |
| 1561 | dev_kfree_skb_any(ptask->skb); |
| 1562 | kmem_cache_free(fwnet_packet_task_cache, ptask); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1563 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1564 | list_for_each_entry_safe(ptask, pt_next, |
| 1565 | &dev->sent_list, pt_link) { |
| 1566 | dev_kfree_skb_any(ptask->skb); |
| 1567 | kmem_cache_free(fwnet_packet_task_cache, ptask); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1568 | } |
Stefan Richter | b01b4ba | 2009-06-16 20:43:55 +0200 | [diff] [blame] | 1569 | list_del(&dev->dev_link); |
| 1570 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1571 | free_netdev(net); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1572 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1573 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1574 | mutex_unlock(&fwnet_device_mutex); |
| 1575 | |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1576 | return 0; |
| 1577 | } |
| 1578 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1579 | /* |
| 1580 | * FIXME abort partially sent fragmented datagrams, |
| 1581 | * discard partially received fragmented datagrams |
| 1582 | */ |
| 1583 | static void fwnet_update(struct fw_unit *unit) |
| 1584 | { |
| 1585 | struct fw_device *device = fw_parent_device(unit); |
Stefan Richter | b01b4ba | 2009-06-16 20:43:55 +0200 | [diff] [blame] | 1586 | struct fwnet_peer *peer = dev_get_drvdata(&unit->device); |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1587 | int generation; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1588 | |
Stefan Richter | 5a124d3 | 2009-06-14 11:45:27 +0200 | [diff] [blame] | 1589 | generation = device->generation; |
| 1590 | |
| 1591 | spin_lock_irq(&peer->dev->lock); |
| 1592 | peer->node_id = device->node_id; |
| 1593 | peer->generation = generation; |
| 1594 | spin_unlock_irq(&peer->dev->lock); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1595 | } |
| 1596 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1597 | static const struct ieee1394_device_id fwnet_id_table[] = { |
| 1598 | { |
| 1599 | .match_flags = IEEE1394_MATCH_SPECIFIER_ID | |
| 1600 | IEEE1394_MATCH_VERSION, |
| 1601 | .specifier_id = IANA_SPECIFIER_ID, |
| 1602 | .version = RFC2734_SW_VERSION, |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1603 | }, |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1604 | { } |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1605 | }; |
| 1606 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1607 | static struct fw_driver fwnet_driver = { |
| 1608 | .driver = { |
| 1609 | .owner = THIS_MODULE, |
| 1610 | .name = "net", |
| 1611 | .bus = &fw_bus_type, |
| 1612 | .probe = fwnet_probe, |
| 1613 | .remove = fwnet_remove, |
| 1614 | }, |
| 1615 | .update = fwnet_update, |
| 1616 | .id_table = fwnet_id_table, |
| 1617 | }; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1618 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1619 | static const u32 rfc2374_unit_directory_data[] = { |
| 1620 | 0x00040000, /* directory_length */ |
| 1621 | 0x1200005e, /* unit_specifier_id: IANA */ |
| 1622 | 0x81000003, /* textual descriptor offset */ |
| 1623 | 0x13000001, /* unit_sw_version: RFC 2734 */ |
| 1624 | 0x81000005, /* textual descriptor offset */ |
| 1625 | 0x00030000, /* descriptor_length */ |
| 1626 | 0x00000000, /* text */ |
| 1627 | 0x00000000, /* minimal ASCII, en */ |
| 1628 | 0x49414e41, /* I A N A */ |
| 1629 | 0x00030000, /* descriptor_length */ |
| 1630 | 0x00000000, /* text */ |
| 1631 | 0x00000000, /* minimal ASCII, en */ |
| 1632 | 0x49507634, /* I P v 4 */ |
| 1633 | }; |
| 1634 | |
| 1635 | static struct fw_descriptor rfc2374_unit_directory = { |
| 1636 | .length = ARRAY_SIZE(rfc2374_unit_directory_data), |
| 1637 | .key = (CSR_DIRECTORY | CSR_UNIT) << 24, |
| 1638 | .data = rfc2374_unit_directory_data |
| 1639 | }; |
| 1640 | |
| 1641 | static int __init fwnet_init(void) |
| 1642 | { |
| 1643 | int err; |
| 1644 | |
| 1645 | err = fw_core_add_descriptor(&rfc2374_unit_directory); |
| 1646 | if (err) |
| 1647 | return err; |
| 1648 | |
| 1649 | fwnet_packet_task_cache = kmem_cache_create("packet_task", |
| 1650 | sizeof(struct fwnet_packet_task), 0, 0, NULL); |
| 1651 | if (!fwnet_packet_task_cache) { |
| 1652 | err = -ENOMEM; |
| 1653 | goto out; |
| 1654 | } |
| 1655 | |
| 1656 | err = driver_register(&fwnet_driver.driver); |
| 1657 | if (!err) |
| 1658 | return 0; |
| 1659 | |
| 1660 | kmem_cache_destroy(fwnet_packet_task_cache); |
| 1661 | out: |
| 1662 | fw_core_remove_descriptor(&rfc2374_unit_directory); |
| 1663 | |
| 1664 | return err; |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1665 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1666 | module_init(fwnet_init); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1667 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1668 | static void __exit fwnet_cleanup(void) |
| 1669 | { |
| 1670 | driver_unregister(&fwnet_driver.driver); |
| 1671 | kmem_cache_destroy(fwnet_packet_task_cache); |
| 1672 | fw_core_remove_descriptor(&rfc2374_unit_directory); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1673 | } |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1674 | module_exit(fwnet_cleanup); |
Jay Fenlason | c76acec | 2009-05-18 13:08:06 -0400 | [diff] [blame] | 1675 | |
Stefan Richter | f91e3bd | 2009-06-07 22:57:53 +0200 | [diff] [blame] | 1676 | MODULE_AUTHOR("Jay Fenlason <fenlason@redhat.com>"); |
| 1677 | MODULE_DESCRIPTION("IPv4 over IEEE1394 as per RFC 2734"); |
| 1678 | MODULE_LICENSE("GPL"); |
| 1679 | MODULE_DEVICE_TABLE(ieee1394, fwnet_id_table); |