2 * eth1394.c -- IPv4 driver for Linux IEEE-1394 Subsystem
4 * Copyright (C) 2001-2003 Ben Collins <bcollins@debian.org>
5 * 2000 Bonin Franck <boninf@free.fr>
6 * 2003 Steve Kinneberg <kinnebergsteve@acmsystems.com>
8 * Mainly based on work by Emanuel Pirker and Andreas E. Bombe
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * This driver intends to support RFC 2734, which describes a method for
27 * transporting IPv4 datagrams over IEEE-1394 serial busses.
31 * - Add MCAP. Limited Multicast exists only to 224.0.0.1 and 224.0.0.2.
33 * Non-RFC 2734 related:
34 * - Handle fragmented skb's coming from the networking layer.
35 * - Move generic GASP reception to core 1394 code
36 * - Convert kmalloc/kfree for link fragments to use kmem_cache_* instead
37 * - Stability improvements
38 * - Performance enhancements
39 * - Consider garbage collecting old partial datagrams after X amount of time
42 #include <linux/module.h>
44 #include <linux/kernel.h>
45 #include <linux/slab.h>
46 #include <linux/errno.h>
47 #include <linux/types.h>
48 #include <linux/delay.h>
49 #include <linux/init.h>
51 #include <linux/netdevice.h>
52 #include <linux/inetdevice.h>
53 #include <linux/etherdevice.h>
54 #include <linux/if_arp.h>
55 #include <linux/if_ether.h>
58 #include <linux/tcp.h>
59 #include <linux/skbuff.h>
60 #include <linux/bitops.h>
61 #include <linux/ethtool.h>
62 #include <asm/uaccess.h>
63 #include <asm/delay.h>
64 #include <asm/unaligned.h>
67 #include "config_roms.h"
70 #include "highlevel.h"
72 #include "ieee1394_core.h"
73 #include "ieee1394_hotplug.h"
74 #include "ieee1394_transactions.h"
75 #include "ieee1394_types.h"
79 #define ETH1394_PRINT_G(level, fmt, args...) \
80 printk(level "%s: " fmt, driver_name, ## args)
82 #define ETH1394_PRINT(level, dev_name, fmt, args...) \
83 printk(level "%s: %s: " fmt, driver_name, dev_name, ## args)
85 struct fragment_info {
86 struct list_head list;
91 struct partial_datagram {
92 struct list_head list;
98 struct list_head frag_info;
102 struct list_head list; /* partial datagram list per node */
103 unsigned int sz; /* partial datagram list size per node */
104 spinlock_t lock; /* partial datagram lock */
107 struct eth1394_host_info {
108 struct hpsb_host *host;
109 struct net_device *dev;
112 struct eth1394_node_ref {
113 struct unit_directory *ud;
114 struct list_head list;
117 struct eth1394_node_info {
118 u16 maxpayload; /* max payload */
119 u8 sspd; /* max speed */
120 u64 fifo; /* FIFO address */
121 struct pdg_list pdg; /* partial RX datagram lists */
122 int dgl; /* outgoing datagram label */
125 static const char driver_name[] = "eth1394";
127 static struct kmem_cache *packet_task_cache;
129 static struct hpsb_highlevel eth1394_highlevel;
131 /* Use common.lf to determine header len */
132 static const int hdr_type_len[] = {
133 sizeof(struct eth1394_uf_hdr),
134 sizeof(struct eth1394_ff_hdr),
135 sizeof(struct eth1394_sf_hdr),
136 sizeof(struct eth1394_sf_hdr)
139 static const u16 eth1394_speedto_maxpayload[] = {
140 /* S100, S200, S400, S800, S1600, S3200 */
141 512, 1024, 2048, 4096, 4096, 4096
144 MODULE_AUTHOR("Ben Collins (bcollins@debian.org)");
145 MODULE_DESCRIPTION("IEEE 1394 IPv4 Driver (IPv4-over-1394 as per RFC 2734)");
146 MODULE_LICENSE("GPL");
149 * The max_partial_datagrams parameter is the maximum number of fragmented
150 * datagrams per node that eth1394 will keep in memory. Providing an upper
151 * bound allows us to limit the amount of memory that partial datagrams
152 * consume in the event that some partial datagrams are never completed.
154 static int max_partial_datagrams = 25;
155 module_param(max_partial_datagrams, int, S_IRUGO | S_IWUSR);
156 MODULE_PARM_DESC(max_partial_datagrams,
157 "Maximum number of partially received fragmented datagrams "
161 static int ether1394_header(struct sk_buff *skb, struct net_device *dev,
162 unsigned short type, void *daddr, void *saddr,
164 static int ether1394_rebuild_header(struct sk_buff *skb);
165 static int ether1394_header_parse(struct sk_buff *skb, unsigned char *haddr);
166 static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh);
167 static void ether1394_header_cache_update(struct hh_cache *hh,
168 struct net_device *dev,
169 unsigned char *haddr);
170 static int ether1394_tx(struct sk_buff *skb, struct net_device *dev);
171 static void ether1394_iso(struct hpsb_iso *iso);
173 static struct ethtool_ops ethtool_ops;
175 static int ether1394_write(struct hpsb_host *host, int srcid, int destid,
176 quadlet_t *data, u64 addr, size_t len, u16 flags);
177 static void ether1394_add_host(struct hpsb_host *host);
178 static void ether1394_remove_host(struct hpsb_host *host);
179 static void ether1394_host_reset(struct hpsb_host *host);
181 /* Function for incoming 1394 packets */
182 static struct hpsb_address_ops addr_ops = {
183 .write = ether1394_write,
186 /* Ieee1394 highlevel driver functions */
187 static struct hpsb_highlevel eth1394_highlevel = {
189 .add_host = ether1394_add_host,
190 .remove_host = ether1394_remove_host,
191 .host_reset = ether1394_host_reset,
194 static int ether1394_recv_init(struct eth1394_priv *priv)
196 unsigned int iso_buf_size;
198 /* FIXME: rawiso limits us to PAGE_SIZE */
199 iso_buf_size = min((unsigned int)PAGE_SIZE,
200 2 * (1U << (priv->host->csr.max_rec + 1)));
202 priv->iso = hpsb_iso_recv_init(priv->host,
203 ETHER1394_GASP_BUFFERS * iso_buf_size,
204 ETHER1394_GASP_BUFFERS,
205 priv->broadcast_channel,
206 HPSB_ISO_DMA_PACKET_PER_BUFFER,
208 if (priv->iso == NULL) {
209 ETH1394_PRINT_G(KERN_ERR, "Failed to allocate IR context\n");
210 priv->bc_state = ETHER1394_BC_ERROR;
214 if (hpsb_iso_recv_start(priv->iso, -1, (1 << 3), -1) < 0)
215 priv->bc_state = ETHER1394_BC_STOPPED;
217 priv->bc_state = ETHER1394_BC_RUNNING;
221 /* This is called after an "ifup" */
222 static int ether1394_open(struct net_device *dev)
224 struct eth1394_priv *priv = netdev_priv(dev);
227 if (priv->bc_state == ETHER1394_BC_ERROR) {
228 ret = ether1394_recv_init(priv);
232 netif_start_queue(dev);
236 /* This is called after an "ifdown" */
237 static int ether1394_stop(struct net_device *dev)
239 netif_stop_queue(dev);
243 /* Return statistics to the caller */
244 static struct net_device_stats *ether1394_stats(struct net_device *dev)
246 return &(((struct eth1394_priv *)netdev_priv(dev))->stats);
249 /* FIXME: What to do if we timeout? I think a host reset is probably in order,
250 * so that's what we do. Should we increment the stat counters too? */
251 static void ether1394_tx_timeout(struct net_device *dev)
253 struct hpsb_host *host =
254 ((struct eth1394_priv *)netdev_priv(dev))->host;
256 ETH1394_PRINT(KERN_ERR, dev->name, "Timeout, resetting host\n");
257 ether1394_host_reset(host);
260 static inline int ether1394_max_mtu(struct hpsb_host* host)
262 return (1 << (host->csr.max_rec + 1))
263 - sizeof(union eth1394_hdr) - ETHER1394_GASP_OVERHEAD;
266 static int ether1394_change_mtu(struct net_device *dev, int new_mtu)
273 max_mtu = ether1394_max_mtu(
274 ((struct eth1394_priv *)netdev_priv(dev))->host);
275 if (new_mtu > max_mtu) {
276 ETH1394_PRINT(KERN_INFO, dev->name,
277 "Local node constrains MTU to %d\n", max_mtu);
285 static void purge_partial_datagram(struct list_head *old)
287 struct partial_datagram *pd;
288 struct list_head *lh, *n;
289 struct fragment_info *fi;
291 pd = list_entry(old, struct partial_datagram, list);
293 list_for_each_safe(lh, n, &pd->frag_info) {
294 fi = list_entry(lh, struct fragment_info, list);
303 /******************************************
304 * 1394 bus activity functions
305 ******************************************/
307 static struct eth1394_node_ref *eth1394_find_node(struct list_head *inl,
308 struct unit_directory *ud)
310 struct eth1394_node_ref *node;
312 list_for_each_entry(node, inl, list)
319 static struct eth1394_node_ref *eth1394_find_node_guid(struct list_head *inl,
322 struct eth1394_node_ref *node;
324 list_for_each_entry(node, inl, list)
325 if (node->ud->ne->guid == guid)
331 static struct eth1394_node_ref *eth1394_find_node_nodeid(struct list_head *inl,
334 struct eth1394_node_ref *node;
336 list_for_each_entry(node, inl, list)
337 if (node->ud->ne->nodeid == nodeid)
343 static int eth1394_new_node(struct eth1394_host_info *hi,
344 struct unit_directory *ud)
346 struct eth1394_priv *priv;
347 struct eth1394_node_ref *new_node;
348 struct eth1394_node_info *node_info;
350 new_node = kmalloc(sizeof(*new_node), GFP_KERNEL);
354 node_info = kmalloc(sizeof(*node_info), GFP_KERNEL);
360 spin_lock_init(&node_info->pdg.lock);
361 INIT_LIST_HEAD(&node_info->pdg.list);
362 node_info->pdg.sz = 0;
363 node_info->fifo = CSR1212_INVALID_ADDR_SPACE;
365 ud->device.driver_data = node_info;
368 priv = netdev_priv(hi->dev);
369 list_add_tail(&new_node->list, &priv->ip_node_list);
373 static int eth1394_probe(struct device *dev)
375 struct unit_directory *ud;
376 struct eth1394_host_info *hi;
378 ud = container_of(dev, struct unit_directory, device);
379 hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host);
383 return eth1394_new_node(hi, ud);
386 static int eth1394_remove(struct device *dev)
388 struct unit_directory *ud;
389 struct eth1394_host_info *hi;
390 struct eth1394_priv *priv;
391 struct eth1394_node_ref *old_node;
392 struct eth1394_node_info *node_info;
393 struct list_head *lh, *n;
396 ud = container_of(dev, struct unit_directory, device);
397 hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host);
401 priv = netdev_priv(hi->dev);
403 old_node = eth1394_find_node(&priv->ip_node_list, ud);
407 list_del(&old_node->list);
410 node_info = (struct eth1394_node_info*)ud->device.driver_data;
412 spin_lock_irqsave(&node_info->pdg.lock, flags);
413 /* The partial datagram list should be empty, but we'll just
414 * make sure anyway... */
415 list_for_each_safe(lh, n, &node_info->pdg.list)
416 purge_partial_datagram(lh);
417 spin_unlock_irqrestore(&node_info->pdg.lock, flags);
420 ud->device.driver_data = NULL;
424 static int eth1394_update(struct unit_directory *ud)
426 struct eth1394_host_info *hi;
427 struct eth1394_priv *priv;
428 struct eth1394_node_ref *node;
430 hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host);
434 priv = netdev_priv(hi->dev);
435 node = eth1394_find_node(&priv->ip_node_list, ud);
439 return eth1394_new_node(hi, ud);
442 static struct ieee1394_device_id eth1394_id_table[] = {
444 .match_flags = (IEEE1394_MATCH_SPECIFIER_ID |
445 IEEE1394_MATCH_VERSION),
446 .specifier_id = ETHER1394_GASP_SPECIFIER_ID,
447 .version = ETHER1394_GASP_VERSION,
452 MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table);
454 static struct hpsb_protocol_driver eth1394_proto_driver = {
456 .id_table = eth1394_id_table,
457 .update = eth1394_update,
459 .probe = eth1394_probe,
460 .remove = eth1394_remove,
464 static void ether1394_reset_priv(struct net_device *dev, int set_mtu)
468 struct eth1394_priv *priv = netdev_priv(dev);
469 struct hpsb_host *host = priv->host;
470 u64 guid = get_unaligned((u64 *)&(host->csr.rom->bus_info_data[3]));
471 int max_speed = IEEE1394_SPEED_MAX;
473 spin_lock_irqsave(&priv->lock, flags);
475 memset(priv->ud_list, 0, sizeof(priv->ud_list));
476 priv->bc_maxpayload = 512;
478 /* Determine speed limit */
479 for (i = 0; i < host->node_count; i++)
480 if (max_speed > host->speed[i])
481 max_speed = host->speed[i];
482 priv->bc_sspd = max_speed;
485 /* Use the RFC 2734 default 1500 octets or the maximum payload
487 dev->mtu = min(1500, ether1394_max_mtu(host));
489 /* Set our hardware address while we're at it */
490 memcpy(dev->dev_addr, &guid, sizeof(u64));
491 memset(dev->broadcast, 0xff, sizeof(u64));
494 spin_unlock_irqrestore(&priv->lock, flags);
497 /* This function is called right before register_netdev */
498 static void ether1394_init_dev(struct net_device *dev)
501 dev->open = ether1394_open;
502 dev->stop = ether1394_stop;
503 dev->hard_start_xmit = ether1394_tx;
504 dev->get_stats = ether1394_stats;
505 dev->tx_timeout = ether1394_tx_timeout;
506 dev->change_mtu = ether1394_change_mtu;
508 dev->hard_header = ether1394_header;
509 dev->rebuild_header = ether1394_rebuild_header;
510 dev->hard_header_cache = ether1394_header_cache;
511 dev->header_cache_update= ether1394_header_cache_update;
512 dev->hard_header_parse = ether1394_header_parse;
513 dev->set_mac_address = NULL;
514 SET_ETHTOOL_OPS(dev, ðtool_ops);
517 dev->watchdog_timeo = ETHER1394_TIMEOUT;
518 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
519 dev->features = NETIF_F_HIGHDMA;
520 dev->addr_len = ETH1394_ALEN;
521 dev->hard_header_len = ETH1394_HLEN;
522 dev->type = ARPHRD_IEEE1394;
524 ether1394_reset_priv(dev, 1);
528 * This function is called every time a card is found. It is generally called
529 * when the module is installed. This is where we add all of our ethernet
530 * devices. One for each host.
532 static void ether1394_add_host(struct hpsb_host *host)
534 struct eth1394_host_info *hi = NULL;
535 struct net_device *dev = NULL;
536 struct eth1394_priv *priv;
539 if (hpsb_config_rom_ip1394_add(host) != 0) {
540 ETH1394_PRINT_G(KERN_ERR, "Can't add IP-over-1394 ROM entry\n");
544 fifo_addr = hpsb_allocate_and_register_addrspace(
545 ð1394_highlevel, host, &addr_ops,
546 ETHER1394_REGION_ADDR_LEN, ETHER1394_REGION_ADDR_LEN,
547 CSR1212_INVALID_ADDR_SPACE, CSR1212_INVALID_ADDR_SPACE);
548 if (fifo_addr == CSR1212_INVALID_ADDR_SPACE) {
549 ETH1394_PRINT_G(KERN_ERR, "Cannot register CSR space\n");
550 hpsb_config_rom_ip1394_remove(host);
554 /* We should really have our own alloc_hpsbdev() function in
555 * net_init.c instead of calling the one for ethernet then hijacking
556 * it for ourselves. That way we'd be a real networking device. */
557 dev = alloc_etherdev(sizeof (struct eth1394_priv));
560 ETH1394_PRINT_G(KERN_ERR, "Out of memory\n");
564 SET_MODULE_OWNER(dev);
566 /* FIXME - Is this the correct parent device anyway? */
567 SET_NETDEV_DEV(dev, &host->device);
570 priv = netdev_priv(dev);
572 INIT_LIST_HEAD(&priv->ip_node_list);
574 spin_lock_init(&priv->lock);
576 priv->local_fifo = fifo_addr;
578 hi = hpsb_create_hostinfo(ð1394_highlevel, host, sizeof(*hi));
581 ETH1394_PRINT_G(KERN_ERR, "Out of memory\n");
585 ether1394_init_dev(dev);
587 if (register_netdev(dev)) {
588 ETH1394_PRINT_G(KERN_ERR, "Cannot register the driver\n");
592 ETH1394_PRINT(KERN_INFO, dev->name, "IPv4 over IEEE 1394 (fw-host%d)\n",
598 /* Ignore validity in hopes that it will be set in the future. It'll
599 * be checked when the eth device is opened. */
600 priv->broadcast_channel = host->csr.broadcast_channel & 0x3f;
602 ether1394_recv_init(priv);
608 hpsb_destroy_hostinfo(ð1394_highlevel, host);
609 hpsb_unregister_addrspace(ð1394_highlevel, host, fifo_addr);
610 hpsb_config_rom_ip1394_remove(host);
613 /* Remove a card from our list */
614 static void ether1394_remove_host(struct hpsb_host *host)
616 struct eth1394_host_info *hi;
617 struct eth1394_priv *priv;
619 hi = hpsb_get_hostinfo(ð1394_highlevel, host);
622 priv = netdev_priv(hi->dev);
623 hpsb_unregister_addrspace(ð1394_highlevel, host, priv->local_fifo);
624 hpsb_config_rom_ip1394_remove(host);
626 hpsb_iso_shutdown(priv->iso);
627 unregister_netdev(hi->dev);
628 free_netdev(hi->dev);
631 /* A bus reset happened */
632 static void ether1394_host_reset(struct hpsb_host *host)
634 struct eth1394_host_info *hi;
635 struct eth1394_priv *priv;
636 struct net_device *dev;
637 struct list_head *lh, *n;
638 struct eth1394_node_ref *node;
639 struct eth1394_node_info *node_info;
642 hi = hpsb_get_hostinfo(ð1394_highlevel, host);
644 /* This can happen for hosts that we don't use */
649 priv = netdev_priv(dev);
651 /* Reset our private host data, but not our MTU */
652 netif_stop_queue(dev);
653 ether1394_reset_priv(dev, 0);
655 list_for_each_entry(node, &priv->ip_node_list, list) {
656 node_info = node->ud->device.driver_data;
658 spin_lock_irqsave(&node_info->pdg.lock, flags);
660 list_for_each_safe(lh, n, &node_info->pdg.list)
661 purge_partial_datagram(lh);
663 INIT_LIST_HEAD(&(node_info->pdg.list));
664 node_info->pdg.sz = 0;
666 spin_unlock_irqrestore(&node_info->pdg.lock, flags);
669 netif_wake_queue(dev);
672 /******************************************
673 * HW Header net device functions
674 ******************************************/
675 /* These functions have been adapted from net/ethernet/eth.c */
677 /* Create a fake MAC header for an arbitrary protocol layer.
678 * saddr=NULL means use device source address
679 * daddr=NULL means leave destination address (eg unresolved arp). */
680 static int ether1394_header(struct sk_buff *skb, struct net_device *dev,
681 unsigned short type, void *daddr, void *saddr,
684 struct eth1394hdr *eth =
685 (struct eth1394hdr *)skb_push(skb, ETH1394_HLEN);
687 eth->h_proto = htons(type);
689 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
690 memset(eth->h_dest, 0, dev->addr_len);
691 return dev->hard_header_len;
695 memcpy(eth->h_dest, daddr, dev->addr_len);
696 return dev->hard_header_len;
699 return -dev->hard_header_len;
702 /* Rebuild the faked MAC header. This is called after an ARP
703 * (or in future other address resolution) has completed on this
704 * sk_buff. We now let ARP fill in the other fields.
706 * This routine CANNOT use cached dst->neigh!
707 * Really, it is used only when dst->neigh is wrong.
709 static int ether1394_rebuild_header(struct sk_buff *skb)
711 struct eth1394hdr *eth = (struct eth1394hdr *)skb->data;
713 if (eth->h_proto == htons(ETH_P_IP))
714 return arp_find((unsigned char *)ð->h_dest, skb);
716 ETH1394_PRINT(KERN_DEBUG, skb->dev->name,
717 "unable to resolve type %04x addresses\n",
718 ntohs(eth->h_proto));
722 static int ether1394_header_parse(struct sk_buff *skb, unsigned char *haddr)
724 struct net_device *dev = skb->dev;
726 memcpy(haddr, dev->dev_addr, ETH1394_ALEN);
730 static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh)
732 unsigned short type = hh->hh_type;
733 struct net_device *dev = neigh->dev;
734 struct eth1394hdr *eth =
735 (struct eth1394hdr *)((u8 *)hh->hh_data + 16 - ETH1394_HLEN);
737 if (type == htons(ETH_P_802_3))
741 memcpy(eth->h_dest, neigh->ha, dev->addr_len);
743 hh->hh_len = ETH1394_HLEN;
747 /* Called by Address Resolution module to notify changes in address. */
748 static void ether1394_header_cache_update(struct hh_cache *hh,
749 struct net_device *dev,
750 unsigned char * haddr)
752 memcpy((u8 *)hh->hh_data + 16 - ETH1394_HLEN, haddr, dev->addr_len);
755 /******************************************
756 * Datagram reception code
757 ******************************************/
759 /* Copied from net/ethernet/eth.c */
760 static u16 ether1394_type_trans(struct sk_buff *skb, struct net_device *dev)
762 struct eth1394hdr *eth;
765 skb_reset_mac_header(skb);
766 skb_pull(skb, ETH1394_HLEN);
767 eth = eth1394_hdr(skb);
769 if (*eth->h_dest & 1) {
770 if (memcmp(eth->h_dest, dev->broadcast, dev->addr_len) == 0)
771 skb->pkt_type = PACKET_BROADCAST;
774 skb->pkt_type = PACKET_MULTICAST;
777 if (memcmp(eth->h_dest, dev->dev_addr, dev->addr_len))
778 skb->pkt_type = PACKET_OTHERHOST;
781 if (ntohs(eth->h_proto) >= 1536)
786 if (*(unsigned short *)rawp == 0xFFFF)
787 return htons(ETH_P_802_3);
789 return htons(ETH_P_802_2);
792 /* Parse an encapsulated IP1394 header into an ethernet frame packet.
793 * We also perform ARP translation here, if need be. */
794 static u16 ether1394_parse_encap(struct sk_buff *skb, struct net_device *dev,
795 nodeid_t srcid, nodeid_t destid,
798 struct eth1394_priv *priv = netdev_priv(dev);
800 unsigned short ret = 0;
802 /* Setup our hw addresses. We use these to build the ethernet header. */
803 if (destid == (LOCAL_BUS | ALL_NODES))
804 dest_hw = ~0ULL; /* broadcast */
806 dest_hw = cpu_to_be64((u64)priv->host->csr.guid_hi << 32 |
807 priv->host->csr.guid_lo);
809 /* If this is an ARP packet, convert it. First, we want to make
810 * use of some of the fields, since they tell us a little bit
811 * about the sending machine. */
812 if (ether_type == htons(ETH_P_ARP)) {
813 struct eth1394_arp *arp1394 = (struct eth1394_arp *)skb->data;
814 struct arphdr *arp = (struct arphdr *)skb->data;
815 unsigned char *arp_ptr = (unsigned char *)(arp + 1);
816 u64 fifo_addr = (u64)ntohs(arp1394->fifo_hi) << 32 |
817 ntohl(arp1394->fifo_lo);
818 u8 max_rec = min(priv->host->csr.max_rec,
819 (u8)(arp1394->max_rec));
820 int sspd = arp1394->sspd;
822 struct eth1394_node_ref *node;
823 struct eth1394_node_info *node_info;
826 /* Sanity check. MacOSX seems to be sending us 131 in this
827 * field (atleast on my Panther G5). Not sure why. */
828 if (sspd > 5 || sspd < 0)
831 maxpayload = min(eth1394_speedto_maxpayload[sspd],
832 (u16)(1 << (max_rec + 1)));
834 guid = get_unaligned(&arp1394->s_uniq_id);
835 node = eth1394_find_node_guid(&priv->ip_node_list,
841 (struct eth1394_node_info *)node->ud->device.driver_data;
843 /* Update our speed/payload/fifo_offset table */
844 node_info->maxpayload = maxpayload;
845 node_info->sspd = sspd;
846 node_info->fifo = fifo_addr;
848 /* Now that we're done with the 1394 specific stuff, we'll
849 * need to alter some of the data. Believe it or not, all
850 * that needs to be done is sender_IP_address needs to be
851 * moved, the destination hardware address get stuffed
852 * in and the hardware address length set to 8.
854 * IMPORTANT: The code below overwrites 1394 specific data
855 * needed above so keep the munging of the data for the
856 * higher level IP stack last. */
859 arp_ptr += arp->ar_hln; /* skip over sender unique id */
860 *(u32 *)arp_ptr = arp1394->sip; /* move sender IP addr */
861 arp_ptr += arp->ar_pln; /* skip over sender IP addr */
863 if (arp->ar_op == htons(ARPOP_REQUEST))
864 memset(arp_ptr, 0, sizeof(u64));
866 memcpy(arp_ptr, dev->dev_addr, sizeof(u64));
869 /* Now add the ethernet header. */
870 if (dev->hard_header(skb, dev, ntohs(ether_type), &dest_hw, NULL,
872 ret = ether1394_type_trans(skb, dev);
877 static int fragment_overlap(struct list_head *frag_list, int offset, int len)
879 struct fragment_info *fi;
881 list_for_each_entry(fi, frag_list, list) {
882 if ( ! ((offset > (fi->offset + fi->len - 1)) ||
883 ((offset + len - 1) < fi->offset)))
889 static struct list_head *find_partial_datagram(struct list_head *pdgl, int dgl)
891 struct partial_datagram *pd;
893 list_for_each_entry(pd, pdgl, list)
900 /* Assumes that new fragment does not overlap any existing fragments */
901 static int new_fragment(struct list_head *frag_info, int offset, int len)
903 struct list_head *lh;
904 struct fragment_info *fi, *fi2, *new;
906 list_for_each(lh, frag_info) {
907 fi = list_entry(lh, struct fragment_info, list);
908 if (fi->offset + fi->len == offset) {
909 /* The new fragment can be tacked on to the end */
911 /* Did the new fragment plug a hole? */
912 fi2 = list_entry(lh->next, struct fragment_info, list);
913 if (fi->offset + fi->len == fi2->offset) {
914 /* glue fragments together */
920 } else if (offset + len == fi->offset) {
921 /* The new fragment can be tacked on to the beginning */
924 /* Did the new fragment plug a hole? */
925 fi2 = list_entry(lh->prev, struct fragment_info, list);
926 if (fi2->offset + fi2->len == fi->offset) {
927 /* glue fragments together */
933 } else if (offset > fi->offset + fi->len) {
935 } else if (offset + len < fi->offset) {
941 new = kmalloc(sizeof(*new), GFP_ATOMIC);
945 new->offset = offset;
948 list_add(&new->list, lh);
952 static int new_partial_datagram(struct net_device *dev, struct list_head *pdgl,
953 int dgl, int dg_size, char *frag_buf,
954 int frag_off, int frag_len)
956 struct partial_datagram *new;
958 new = kmalloc(sizeof(*new), GFP_ATOMIC);
962 INIT_LIST_HEAD(&new->frag_info);
964 if (new_fragment(&new->frag_info, frag_off, frag_len) < 0) {
970 new->dg_size = dg_size;
972 new->skb = dev_alloc_skb(dg_size + dev->hard_header_len + 15);
974 struct fragment_info *fi = list_entry(new->frag_info.next,
975 struct fragment_info,
982 skb_reserve(new->skb, (dev->hard_header_len + 15) & ~15);
983 new->pbuf = skb_put(new->skb, dg_size);
984 memcpy(new->pbuf + frag_off, frag_buf, frag_len);
986 list_add(&new->list, pdgl);
990 static int update_partial_datagram(struct list_head *pdgl, struct list_head *lh,
991 char *frag_buf, int frag_off, int frag_len)
993 struct partial_datagram *pd =
994 list_entry(lh, struct partial_datagram, list);
996 if (new_fragment(&pd->frag_info, frag_off, frag_len) < 0)
999 memcpy(pd->pbuf + frag_off, frag_buf, frag_len);
1001 /* Move list entry to beginnig of list so that oldest partial
1002 * datagrams percolate to the end of the list */
1003 list_move(lh, pdgl);
1007 static int is_datagram_complete(struct list_head *lh, int dg_size)
1009 struct partial_datagram *pd;
1010 struct fragment_info *fi;
1012 pd = list_entry(lh, struct partial_datagram, list);
1013 fi = list_entry(pd->frag_info.next, struct fragment_info, list);
1015 return (fi->len == dg_size);
1018 /* Packet reception. We convert the IP1394 encapsulation header to an
1019 * ethernet header, and fill it with some of our other fields. This is
1020 * an incoming packet from the 1394 bus. */
1021 static int ether1394_data_handler(struct net_device *dev, int srcid, int destid,
1024 struct sk_buff *skb;
1025 unsigned long flags;
1026 struct eth1394_priv *priv = netdev_priv(dev);
1027 union eth1394_hdr *hdr = (union eth1394_hdr *)buf;
1028 u16 ether_type = 0; /* initialized to clear warning */
1030 struct unit_directory *ud = priv->ud_list[NODEID_TO_NODE(srcid)];
1031 struct eth1394_node_info *node_info;
1034 struct eth1394_node_ref *node;
1035 node = eth1394_find_node_nodeid(&priv->ip_node_list, srcid);
1037 HPSB_PRINT(KERN_ERR, "ether1394 rx: sender nodeid "
1038 "lookup failure: " NODE_BUS_FMT,
1039 NODE_BUS_ARGS(priv->host, srcid));
1040 priv->stats.rx_dropped++;
1045 priv->ud_list[NODEID_TO_NODE(srcid)] = ud;
1048 node_info = (struct eth1394_node_info *)ud->device.driver_data;
1050 /* First, did we receive a fragmented or unfragmented datagram? */
1051 hdr->words.word1 = ntohs(hdr->words.word1);
1053 hdr_len = hdr_type_len[hdr->common.lf];
1055 if (hdr->common.lf == ETH1394_HDR_LF_UF) {
1056 /* An unfragmented datagram has been received by the ieee1394
1057 * bus. Build an skbuff around it so we can pass it to the
1058 * high level network layer. */
1060 skb = dev_alloc_skb(len + dev->hard_header_len + 15);
1062 ETH1394_PRINT_G(KERN_ERR, "Out of memory\n");
1063 priv->stats.rx_dropped++;
1066 skb_reserve(skb, (dev->hard_header_len + 15) & ~15);
1067 memcpy(skb_put(skb, len - hdr_len), buf + hdr_len,
1069 ether_type = hdr->uf.ether_type;
1071 /* A datagram fragment has been received, now the fun begins. */
1073 struct list_head *pdgl, *lh;
1074 struct partial_datagram *pd;
1076 int fg_len = len - hdr_len;
1080 struct pdg_list *pdg = &(node_info->pdg);
1082 hdr->words.word3 = ntohs(hdr->words.word3);
1083 /* The 4th header word is reserved so no need to do ntohs() */
1085 if (hdr->common.lf == ETH1394_HDR_LF_FF) {
1086 ether_type = hdr->ff.ether_type;
1088 dg_size = hdr->ff.dg_size + 1;
1091 hdr->words.word2 = ntohs(hdr->words.word2);
1093 dg_size = hdr->sf.dg_size + 1;
1094 fg_off = hdr->sf.fg_off;
1096 spin_lock_irqsave(&pdg->lock, flags);
1098 pdgl = &(pdg->list);
1099 lh = find_partial_datagram(pdgl, dgl);
1102 while (pdg->sz >= max_partial_datagrams) {
1103 /* remove the oldest */
1104 purge_partial_datagram(pdgl->prev);
1108 retval = new_partial_datagram(dev, pdgl, dgl, dg_size,
1109 buf + hdr_len, fg_off,
1112 spin_unlock_irqrestore(&pdg->lock, flags);
1116 lh = find_partial_datagram(pdgl, dgl);
1118 struct partial_datagram *pd;
1120 pd = list_entry(lh, struct partial_datagram, list);
1122 if (fragment_overlap(&pd->frag_info, fg_off, fg_len)) {
1123 /* Overlapping fragments, obliterate old
1124 * datagram and start new one. */
1125 purge_partial_datagram(lh);
1126 retval = new_partial_datagram(dev, pdgl, dgl,
1132 spin_unlock_irqrestore(&pdg->lock, flags);
1136 retval = update_partial_datagram(pdgl, lh,
1140 /* Couldn't save off fragment anyway
1141 * so might as well obliterate the
1143 purge_partial_datagram(lh);
1145 spin_unlock_irqrestore(&pdg->lock, flags);
1148 } /* fragment overlap */
1149 } /* new datagram or add to existing one */
1151 pd = list_entry(lh, struct partial_datagram, list);
1153 if (hdr->common.lf == ETH1394_HDR_LF_FF)
1154 pd->ether_type = ether_type;
1156 if (is_datagram_complete(lh, dg_size)) {
1157 ether_type = pd->ether_type;
1159 skb = skb_get(pd->skb);
1160 purge_partial_datagram(lh);
1161 spin_unlock_irqrestore(&pdg->lock, flags);
1163 /* Datagram is not complete, we're done for the
1165 spin_unlock_irqrestore(&pdg->lock, flags);
1168 } /* unframgented datagram or fragmented one */
1170 /* Write metadata, and then pass to the receive level */
1172 skb->ip_summed = CHECKSUM_UNNECESSARY; /* don't check it */
1174 /* Parse the encapsulation header. This actually does the job of
1175 * converting to an ethernet frame header, aswell as arp
1176 * conversion if needed. ARP conversion is easier in this
1177 * direction, since we are using ethernet as our backend. */
1178 skb->protocol = ether1394_parse_encap(skb, dev, srcid, destid,
1181 spin_lock_irqsave(&priv->lock, flags);
1183 if (!skb->protocol) {
1184 priv->stats.rx_errors++;
1185 priv->stats.rx_dropped++;
1186 dev_kfree_skb_any(skb);
1190 if (netif_rx(skb) == NET_RX_DROP) {
1191 priv->stats.rx_errors++;
1192 priv->stats.rx_dropped++;
1197 priv->stats.rx_packets++;
1198 priv->stats.rx_bytes += skb->len;
1201 if (netif_queue_stopped(dev))
1202 netif_wake_queue(dev);
1203 spin_unlock_irqrestore(&priv->lock, flags);
1205 dev->last_rx = jiffies;
1210 static int ether1394_write(struct hpsb_host *host, int srcid, int destid,
1211 quadlet_t *data, u64 addr, size_t len, u16 flags)
1213 struct eth1394_host_info *hi;
1215 hi = hpsb_get_hostinfo(ð1394_highlevel, host);
1217 ETH1394_PRINT_G(KERN_ERR, "No net device at fw-host%d\n",
1219 return RCODE_ADDRESS_ERROR;
1222 if (ether1394_data_handler(hi->dev, srcid, destid, (char*)data, len))
1223 return RCODE_ADDRESS_ERROR;
1225 return RCODE_COMPLETE;
1228 static void ether1394_iso(struct hpsb_iso *iso)
1232 struct eth1394_host_info *hi;
1233 struct net_device *dev;
1234 struct eth1394_priv *priv;
1241 hi = hpsb_get_hostinfo(ð1394_highlevel, iso->host);
1243 ETH1394_PRINT_G(KERN_ERR, "No net device at fw-host%d\n",
1250 nready = hpsb_iso_n_ready(iso);
1251 for (i = 0; i < nready; i++) {
1252 struct hpsb_iso_packet_info *info =
1253 &iso->infos[(iso->first_packet + i) % iso->buf_packets];
1254 data = (quadlet_t *)(iso->data_buf.kvirt + info->offset);
1256 /* skip over GASP header */
1257 buf = (char *)data + 8;
1258 len = info->len - 8;
1260 specifier_id = (be32_to_cpu(data[0]) & 0xffff) << 8 |
1261 (be32_to_cpu(data[1]) & 0xff000000) >> 24;
1262 source_id = be32_to_cpu(data[0]) >> 16;
1264 priv = netdev_priv(dev);
1266 if (info->channel != (iso->host->csr.broadcast_channel & 0x3f)
1267 || specifier_id != ETHER1394_GASP_SPECIFIER_ID) {
1268 /* This packet is not for us */
1271 ether1394_data_handler(dev, source_id, LOCAL_BUS | ALL_NODES,
1275 hpsb_iso_recv_release_packets(iso, i);
1277 dev->last_rx = jiffies;
1280 /******************************************
1281 * Datagram transmission code
1282 ******************************************/
1284 /* Convert a standard ARP packet to 1394 ARP. The first 8 bytes (the entire
1285 * arphdr) is the same format as the ip1394 header, so they overlap. The rest
1286 * needs to be munged a bit. The remainder of the arphdr is formatted based
1287 * on hwaddr len and ipaddr len. We know what they'll be, so it's easy to
1290 * Now that the EUI is used for the hardware address all we need to do to make
1291 * this work for 1394 is to insert 2 quadlets that contain max_rec size,
1292 * speed, and unicast FIFO address information between the sender_unique_id
1293 * and the IP addresses.
1295 static void ether1394_arp_to_1394arp(struct sk_buff *skb,
1296 struct net_device *dev)
1298 struct eth1394_priv *priv = netdev_priv(dev);
1299 struct arphdr *arp = (struct arphdr *)skb->data;
1300 unsigned char *arp_ptr = (unsigned char *)(arp + 1);
1301 struct eth1394_arp *arp1394 = (struct eth1394_arp *)skb->data;
1303 arp1394->hw_addr_len = 16;
1304 arp1394->sip = *(u32*)(arp_ptr + ETH1394_ALEN);
1305 arp1394->max_rec = priv->host->csr.max_rec;
1306 arp1394->sspd = priv->host->csr.lnk_spd;
1307 arp1394->fifo_hi = htons(priv->local_fifo >> 32);
1308 arp1394->fifo_lo = htonl(priv->local_fifo & ~0x0);
1311 /* We need to encapsulate the standard header with our own. We use the
1312 * ethernet header's proto for our own. */
1313 static unsigned int ether1394_encapsulate_prep(unsigned int max_payload,
1315 union eth1394_hdr *hdr,
1316 u16 dg_size, u16 dgl)
1318 unsigned int adj_max_payload =
1319 max_payload - hdr_type_len[ETH1394_HDR_LF_UF];
1321 /* Does it all fit in one packet? */
1322 if (dg_size <= adj_max_payload) {
1323 hdr->uf.lf = ETH1394_HDR_LF_UF;
1324 hdr->uf.ether_type = proto;
1326 hdr->ff.lf = ETH1394_HDR_LF_FF;
1327 hdr->ff.ether_type = proto;
1328 hdr->ff.dg_size = dg_size - 1;
1330 adj_max_payload = max_payload - hdr_type_len[ETH1394_HDR_LF_FF];
1332 return (dg_size + adj_max_payload - 1) / adj_max_payload;
1335 static unsigned int ether1394_encapsulate(struct sk_buff *skb,
1336 unsigned int max_payload,
1337 union eth1394_hdr *hdr)
1339 union eth1394_hdr *bufhdr;
1340 int ftype = hdr->common.lf;
1341 int hdrsz = hdr_type_len[ftype];
1342 unsigned int adj_max_payload = max_payload - hdrsz;
1345 case ETH1394_HDR_LF_UF:
1346 bufhdr = (union eth1394_hdr *)skb_push(skb, hdrsz);
1347 bufhdr->words.word1 = htons(hdr->words.word1);
1348 bufhdr->words.word2 = hdr->words.word2;
1351 case ETH1394_HDR_LF_FF:
1352 bufhdr = (union eth1394_hdr *)skb_push(skb, hdrsz);
1353 bufhdr->words.word1 = htons(hdr->words.word1);
1354 bufhdr->words.word2 = hdr->words.word2;
1355 bufhdr->words.word3 = htons(hdr->words.word3);
1356 bufhdr->words.word4 = 0;
1358 /* Set frag type here for future interior fragments */
1359 hdr->common.lf = ETH1394_HDR_LF_IF;
1364 hdr->sf.fg_off += adj_max_payload;
1365 bufhdr = (union eth1394_hdr *)skb_pull(skb, adj_max_payload);
1366 if (max_payload >= skb->len)
1367 hdr->common.lf = ETH1394_HDR_LF_LF;
1368 bufhdr->words.word1 = htons(hdr->words.word1);
1369 bufhdr->words.word2 = htons(hdr->words.word2);
1370 bufhdr->words.word3 = htons(hdr->words.word3);
1371 bufhdr->words.word4 = 0;
1373 return min(max_payload, skb->len);
1376 static struct hpsb_packet *ether1394_alloc_common_packet(struct hpsb_host *host)
1378 struct hpsb_packet *p;
1380 p = hpsb_alloc_packet(0);
1383 p->generation = get_hpsb_generation(host);
1384 p->type = hpsb_async;
1389 static int ether1394_prep_write_packet(struct hpsb_packet *p,
1390 struct hpsb_host *host, nodeid_t node,
1391 u64 addr, void *data, int tx_len)
1396 p->tcode = TCODE_WRITEB;
1397 p->header[1] = host->node_id << 16 | addr >> 32;
1398 p->header[2] = addr & 0xffffffff;
1400 p->header_size = 16;
1401 p->expect_response = 1;
1403 if (hpsb_get_tlabel(p)) {
1404 ETH1394_PRINT_G(KERN_ERR, "Out of tlabels\n");
1408 p->node_id << 16 | p->tlabel << 10 | 1 << 8 | TCODE_WRITEB << 4;
1410 p->header[3] = tx_len << 16;
1411 p->data_size = (tx_len + 3) & ~3;
1417 static void ether1394_prep_gasp_packet(struct hpsb_packet *p,
1418 struct eth1394_priv *priv,
1419 struct sk_buff *skb, int length)
1422 p->tcode = TCODE_STREAM_DATA;
1424 p->header[0] = length << 16 | 3 << 14 | priv->broadcast_channel << 8 |
1425 TCODE_STREAM_DATA << 4;
1426 p->data_size = length;
1427 p->data = (quadlet_t *)skb->data - 2;
1428 p->data[0] = cpu_to_be32(priv->host->node_id << 16 |
1429 ETHER1394_GASP_SPECIFIER_ID_HI);
1430 p->data[1] = cpu_to_be32(ETHER1394_GASP_SPECIFIER_ID_LO << 24 |
1431 ETHER1394_GASP_VERSION);
1433 /* Setting the node id to ALL_NODES (not LOCAL_BUS | ALL_NODES)
1434 * prevents hpsb_send_packet() from setting the speed to an arbitrary
1435 * value based on packet->node_id if packet->node_id is not set. */
1436 p->node_id = ALL_NODES;
1437 p->speed_code = priv->bc_sspd;
1440 static void ether1394_free_packet(struct hpsb_packet *packet)
1442 if (packet->tcode != TCODE_STREAM_DATA)
1443 hpsb_free_tlabel(packet);
1444 hpsb_free_packet(packet);
1447 static void ether1394_complete_cb(void *__ptask);
1449 static int ether1394_send_packet(struct packet_task *ptask, unsigned int tx_len)
1451 struct eth1394_priv *priv = ptask->priv;
1452 struct hpsb_packet *packet = NULL;
1454 packet = ether1394_alloc_common_packet(priv->host);
1458 if (ptask->tx_type == ETH1394_GASP) {
1459 int length = tx_len + 2 * sizeof(quadlet_t);
1461 ether1394_prep_gasp_packet(packet, priv, ptask->skb, length);
1462 } else if (ether1394_prep_write_packet(packet, priv->host,
1464 ptask->addr, ptask->skb->data,
1466 hpsb_free_packet(packet);
1470 ptask->packet = packet;
1471 hpsb_set_packet_complete_task(ptask->packet, ether1394_complete_cb,
1474 if (hpsb_send_packet(packet) < 0) {
1475 ether1394_free_packet(packet);
1482 /* Task function to be run when a datagram transmission is completed */
1483 static void ether1394_dg_complete(struct packet_task *ptask, int fail)
1485 struct sk_buff *skb = ptask->skb;
1486 struct eth1394_priv *priv = netdev_priv(skb->dev);
1487 unsigned long flags;
1490 spin_lock_irqsave(&priv->lock, flags);
1492 priv->stats.tx_dropped++;
1493 priv->stats.tx_errors++;
1495 priv->stats.tx_bytes += skb->len;
1496 priv->stats.tx_packets++;
1498 spin_unlock_irqrestore(&priv->lock, flags);
1500 dev_kfree_skb_any(skb);
1501 kmem_cache_free(packet_task_cache, ptask);
1504 /* Callback for when a packet has been sent and the status of that packet is
1506 static void ether1394_complete_cb(void *__ptask)
1508 struct packet_task *ptask = (struct packet_task *)__ptask;
1509 struct hpsb_packet *packet = ptask->packet;
1512 if (packet->tcode != TCODE_STREAM_DATA)
1513 fail = hpsb_packet_success(packet);
1515 ether1394_free_packet(packet);
1517 ptask->outstanding_pkts--;
1518 if (ptask->outstanding_pkts > 0 && !fail) {
1521 /* Add the encapsulation header to the fragment */
1522 tx_len = ether1394_encapsulate(ptask->skb, ptask->max_payload,
1524 if (ether1394_send_packet(ptask, tx_len))
1525 ether1394_dg_complete(ptask, 1);
1527 ether1394_dg_complete(ptask, fail);
1531 /* Transmit a packet (called by kernel) */
1532 static int ether1394_tx(struct sk_buff *skb, struct net_device *dev)
1534 gfp_t kmflags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
1535 struct eth1394hdr *eth;
1536 struct eth1394_priv *priv = netdev_priv(dev);
1538 unsigned long flags;
1540 eth1394_tx_type tx_type;
1542 unsigned int tx_len;
1543 unsigned int max_payload;
1546 struct packet_task *ptask;
1547 struct eth1394_node_ref *node;
1548 struct eth1394_node_info *node_info = NULL;
1550 ptask = kmem_cache_alloc(packet_task_cache, kmflags);
1551 if (ptask == NULL) {
1556 /* XXX Ignore this for now. Noticed that when MacOSX is the IRM,
1557 * it does not set our validity bit. We need to compensate for
1558 * that somewhere else, but not in eth1394. */
1560 if ((priv->host->csr.broadcast_channel & 0xc0000000) != 0xc0000000) {
1566 skb = skb_share_check(skb, kmflags);
1572 /* Get rid of the fake eth1394 header, but save a pointer */
1573 eth = (struct eth1394hdr *)skb->data;
1574 skb_pull(skb, ETH1394_HLEN);
1576 proto = eth->h_proto;
1579 /* Set the transmission type for the packet. ARP packets and IP
1580 * broadcast packets are sent via GASP. */
1581 if (memcmp(eth->h_dest, dev->broadcast, ETH1394_ALEN) == 0 ||
1582 proto == htons(ETH_P_ARP) ||
1583 (proto == htons(ETH_P_IP) &&
1584 IN_MULTICAST(ntohl(ip_hdr(skb)->daddr)))) {
1585 tx_type = ETH1394_GASP;
1586 dest_node = LOCAL_BUS | ALL_NODES;
1587 max_payload = priv->bc_maxpayload - ETHER1394_GASP_OVERHEAD;
1588 BUG_ON(max_payload < 512 - ETHER1394_GASP_OVERHEAD);
1590 if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF])
1593 __be64 guid = get_unaligned((u64 *)eth->h_dest);
1595 node = eth1394_find_node_guid(&priv->ip_node_list,
1602 (struct eth1394_node_info *)node->ud->device.driver_data;
1603 if (node_info->fifo == CSR1212_INVALID_ADDR_SPACE) {
1608 dest_node = node->ud->ne->nodeid;
1609 max_payload = node_info->maxpayload;
1610 BUG_ON(max_payload < 512 - ETHER1394_GASP_OVERHEAD);
1612 dgl = node_info->dgl;
1613 if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF])
1615 tx_type = ETH1394_WRREQ;
1618 /* If this is an ARP packet, convert it */
1619 if (proto == htons(ETH_P_ARP))
1620 ether1394_arp_to_1394arp(skb, dev);
1622 ptask->hdr.words.word1 = 0;
1623 ptask->hdr.words.word2 = 0;
1624 ptask->hdr.words.word3 = 0;
1625 ptask->hdr.words.word4 = 0;
1628 ptask->tx_type = tx_type;
1630 if (tx_type != ETH1394_GASP) {
1633 spin_lock_irqsave(&priv->lock, flags);
1634 addr = node_info->fifo;
1635 spin_unlock_irqrestore(&priv->lock, flags);
1638 ptask->dest_node = dest_node;
1641 ptask->tx_type = tx_type;
1642 ptask->max_payload = max_payload;
1643 ptask->outstanding_pkts = ether1394_encapsulate_prep(max_payload,
1644 proto, &ptask->hdr, dg_size, dgl);
1646 /* Add the encapsulation header to the fragment */
1647 tx_len = ether1394_encapsulate(skb, max_payload, &ptask->hdr);
1648 dev->trans_start = jiffies;
1649 if (ether1394_send_packet(ptask, tx_len))
1652 netif_wake_queue(dev);
1656 kmem_cache_free(packet_task_cache, ptask);
1661 spin_lock_irqsave(&priv->lock, flags);
1662 priv->stats.tx_dropped++;
1663 priv->stats.tx_errors++;
1664 spin_unlock_irqrestore(&priv->lock, flags);
1666 if (netif_queue_stopped(dev))
1667 netif_wake_queue(dev);
1669 return 0; /* returning non-zero causes serious problems */
1672 static void ether1394_get_drvinfo(struct net_device *dev,
1673 struct ethtool_drvinfo *info)
1675 strcpy(info->driver, driver_name);
1676 strcpy(info->bus_info, "ieee1394"); /* FIXME provide more detail? */
1679 static struct ethtool_ops ethtool_ops = {
1680 .get_drvinfo = ether1394_get_drvinfo
1683 static int __init ether1394_init_module (void)
1685 packet_task_cache = kmem_cache_create("packet_task",
1686 sizeof(struct packet_task),
1689 hpsb_register_highlevel(ð1394_highlevel);
1690 return hpsb_register_protocol(ð1394_proto_driver);
1693 static void __exit ether1394_exit_module (void)
1695 hpsb_unregister_protocol(ð1394_proto_driver);
1696 hpsb_unregister_highlevel(ð1394_highlevel);
1697 kmem_cache_destroy(packet_task_cache);
1700 module_init(ether1394_init_module);
1701 module_exit(ether1394_exit_module);