firewire: net: style changes

Change names of types, variables, functions.
Omit debug code.
Use get_unaligned*, put_unaligned*.
Annotate big endian data.
Handle errors in __init.
Change whitespace.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>

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