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/if_arp.h>
54 #include <linux/if_ether.h>
57 #include <linux/tcp.h>
58 #include <linux/skbuff.h>
59 #include <linux/bitops.h>
60 #include <linux/ethtool.h>
61 #include <asm/uaccess.h>
62 #include <asm/delay.h>
63 #include <asm/unaligned.h>
66 #include "config_roms.h"
69 #include "highlevel.h"
71 #include "ieee1394_core.h"
72 #include "ieee1394_hotplug.h"
73 #include "ieee1394_transactions.h"
74 #include "ieee1394_types.h"
78 #define ETH1394_PRINT_G(level, fmt, args...) \
79 printk(level "%s: " fmt, driver_name, ## args)
81 #define ETH1394_PRINT(level, dev_name, fmt, args...) \
82 printk(level "%s: %s: " fmt, driver_name, dev_name, ## args)
84 struct fragment_info {
85 struct list_head list;
90 struct partial_datagram {
91 struct list_head list;
97 struct list_head frag_info;
101 struct list_head list; /* partial datagram list per node */
102 unsigned int sz; /* partial datagram list size per node */
103 spinlock_t lock; /* partial datagram lock */
106 struct eth1394_host_info {
107 struct hpsb_host *host;
108 struct net_device *dev;
111 struct eth1394_node_ref {
112 struct unit_directory *ud;
113 struct list_head list;
116 struct eth1394_node_info {
117 u16 maxpayload; /* max payload */
118 u8 sspd; /* max speed */
119 u64 fifo; /* FIFO address */
120 struct pdg_list pdg; /* partial RX datagram lists */
121 int dgl; /* outgoing datagram label */
124 static const char driver_name[] = "eth1394";
126 static struct kmem_cache *packet_task_cache;
128 static struct hpsb_highlevel eth1394_highlevel;
130 /* Use common.lf to determine header len */
131 static const int hdr_type_len[] = {
132 sizeof(struct eth1394_uf_hdr),
133 sizeof(struct eth1394_ff_hdr),
134 sizeof(struct eth1394_sf_hdr),
135 sizeof(struct eth1394_sf_hdr)
138 static const u16 eth1394_speedto_maxpayload[] = {
139 /* S100, S200, S400, S800, S1600, S3200 */
140 512, 1024, 2048, 4096, 4096, 4096
143 MODULE_AUTHOR("Ben Collins (bcollins@debian.org)");
144 MODULE_DESCRIPTION("IEEE 1394 IPv4 Driver (IPv4-over-1394 as per RFC 2734)");
145 MODULE_LICENSE("GPL");
148 * The max_partial_datagrams parameter is the maximum number of fragmented
149 * datagrams per node that eth1394 will keep in memory. Providing an upper
150 * bound allows us to limit the amount of memory that partial datagrams
151 * consume in the event that some partial datagrams are never completed.
153 static int max_partial_datagrams = 25;
154 module_param(max_partial_datagrams, int, S_IRUGO | S_IWUSR);
155 MODULE_PARM_DESC(max_partial_datagrams,
156 "Maximum number of partially received fragmented datagrams "
160 static int ether1394_header(struct sk_buff *skb, struct net_device *dev,
161 unsigned short type, void *daddr, void *saddr,
163 static int ether1394_rebuild_header(struct sk_buff *skb);
164 static int ether1394_header_parse(struct sk_buff *skb, unsigned char *haddr);
165 static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh);
166 static void ether1394_header_cache_update(struct hh_cache *hh,
167 struct net_device *dev,
168 unsigned char *haddr);
169 static int ether1394_tx(struct sk_buff *skb, struct net_device *dev);
170 static void ether1394_iso(struct hpsb_iso *iso);
172 static struct ethtool_ops ethtool_ops;
174 static int ether1394_write(struct hpsb_host *host, int srcid, int destid,
175 quadlet_t *data, u64 addr, size_t len, u16 flags);
176 static void ether1394_add_host(struct hpsb_host *host);
177 static void ether1394_remove_host(struct hpsb_host *host);
178 static void ether1394_host_reset(struct hpsb_host *host);
180 /* Function for incoming 1394 packets */
181 static struct hpsb_address_ops addr_ops = {
182 .write = ether1394_write,
185 /* Ieee1394 highlevel driver functions */
186 static struct hpsb_highlevel eth1394_highlevel = {
188 .add_host = ether1394_add_host,
189 .remove_host = ether1394_remove_host,
190 .host_reset = ether1394_host_reset,
193 static int ether1394_recv_init(struct eth1394_priv *priv)
195 unsigned int iso_buf_size;
197 /* FIXME: rawiso limits us to PAGE_SIZE */
198 iso_buf_size = min((unsigned int)PAGE_SIZE,
199 2 * (1U << (priv->host->csr.max_rec + 1)));
201 priv->iso = hpsb_iso_recv_init(priv->host,
202 ETHER1394_GASP_BUFFERS * iso_buf_size,
203 ETHER1394_GASP_BUFFERS,
204 priv->broadcast_channel,
205 HPSB_ISO_DMA_PACKET_PER_BUFFER,
207 if (priv->iso == NULL) {
208 ETH1394_PRINT_G(KERN_ERR, "Failed to allocate IR context\n");
209 priv->bc_state = ETHER1394_BC_ERROR;
213 if (hpsb_iso_recv_start(priv->iso, -1, (1 << 3), -1) < 0)
214 priv->bc_state = ETHER1394_BC_STOPPED;
216 priv->bc_state = ETHER1394_BC_RUNNING;
220 /* This is called after an "ifup" */
221 static int ether1394_open(struct net_device *dev)
223 struct eth1394_priv *priv = netdev_priv(dev);
226 if (priv->bc_state == ETHER1394_BC_ERROR) {
227 ret = ether1394_recv_init(priv);
231 netif_start_queue(dev);
235 /* This is called after an "ifdown" */
236 static int ether1394_stop(struct net_device *dev)
238 netif_stop_queue(dev);
242 /* Return statistics to the caller */
243 static struct net_device_stats *ether1394_stats(struct net_device *dev)
245 return &(((struct eth1394_priv *)netdev_priv(dev))->stats);
248 /* FIXME: What to do if we timeout? I think a host reset is probably in order,
249 * so that's what we do. Should we increment the stat counters too? */
250 static void ether1394_tx_timeout(struct net_device *dev)
252 struct hpsb_host *host =
253 ((struct eth1394_priv *)netdev_priv(dev))->host;
255 ETH1394_PRINT(KERN_ERR, dev->name, "Timeout, resetting host\n");
256 ether1394_host_reset(host);
259 static inline int ether1394_max_mtu(struct hpsb_host* host)
261 return (1 << (host->csr.max_rec + 1))
262 - sizeof(union eth1394_hdr) - ETHER1394_GASP_OVERHEAD;
265 static int ether1394_change_mtu(struct net_device *dev, int new_mtu)
272 max_mtu = ether1394_max_mtu(
273 ((struct eth1394_priv *)netdev_priv(dev))->host);
274 if (new_mtu > max_mtu) {
275 ETH1394_PRINT(KERN_INFO, dev->name,
276 "Local node constrains MTU to %d\n", max_mtu);
284 static void purge_partial_datagram(struct list_head *old)
286 struct partial_datagram *pd;
287 struct list_head *lh, *n;
288 struct fragment_info *fi;
290 pd = list_entry(old, struct partial_datagram, list);
292 list_for_each_safe(lh, n, &pd->frag_info) {
293 fi = list_entry(lh, struct fragment_info, list);
302 /******************************************
303 * 1394 bus activity functions
304 ******************************************/
306 static struct eth1394_node_ref *eth1394_find_node(struct list_head *inl,
307 struct unit_directory *ud)
309 struct eth1394_node_ref *node;
311 list_for_each_entry(node, inl, list)
318 static struct eth1394_node_ref *eth1394_find_node_guid(struct list_head *inl,
321 struct eth1394_node_ref *node;
323 list_for_each_entry(node, inl, list)
324 if (node->ud->ne->guid == guid)
330 static struct eth1394_node_ref *eth1394_find_node_nodeid(struct list_head *inl,
333 struct eth1394_node_ref *node;
335 list_for_each_entry(node, inl, list)
336 if (node->ud->ne->nodeid == nodeid)
342 static int eth1394_new_node(struct eth1394_host_info *hi,
343 struct unit_directory *ud)
345 struct eth1394_priv *priv;
346 struct eth1394_node_ref *new_node;
347 struct eth1394_node_info *node_info;
349 new_node = kmalloc(sizeof(*new_node), GFP_KERNEL);
353 node_info = kmalloc(sizeof(*node_info), GFP_KERNEL);
359 spin_lock_init(&node_info->pdg.lock);
360 INIT_LIST_HEAD(&node_info->pdg.list);
361 node_info->pdg.sz = 0;
362 node_info->fifo = CSR1212_INVALID_ADDR_SPACE;
364 ud->device.driver_data = node_info;
367 priv = netdev_priv(hi->dev);
368 list_add_tail(&new_node->list, &priv->ip_node_list);
372 static int eth1394_probe(struct device *dev)
374 struct unit_directory *ud;
375 struct eth1394_host_info *hi;
377 ud = container_of(dev, struct unit_directory, device);
378 hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host);
382 return eth1394_new_node(hi, ud);
385 static int eth1394_remove(struct device *dev)
387 struct unit_directory *ud;
388 struct eth1394_host_info *hi;
389 struct eth1394_priv *priv;
390 struct eth1394_node_ref *old_node;
391 struct eth1394_node_info *node_info;
392 struct list_head *lh, *n;
395 ud = container_of(dev, struct unit_directory, device);
396 hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host);
400 priv = netdev_priv(hi->dev);
402 old_node = eth1394_find_node(&priv->ip_node_list, ud);
406 list_del(&old_node->list);
409 node_info = (struct eth1394_node_info*)ud->device.driver_data;
411 spin_lock_irqsave(&node_info->pdg.lock, flags);
412 /* The partial datagram list should be empty, but we'll just
413 * make sure anyway... */
414 list_for_each_safe(lh, n, &node_info->pdg.list)
415 purge_partial_datagram(lh);
416 spin_unlock_irqrestore(&node_info->pdg.lock, flags);
419 ud->device.driver_data = NULL;
423 static int eth1394_update(struct unit_directory *ud)
425 struct eth1394_host_info *hi;
426 struct eth1394_priv *priv;
427 struct eth1394_node_ref *node;
429 hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host);
433 priv = netdev_priv(hi->dev);
434 node = eth1394_find_node(&priv->ip_node_list, ud);
438 return eth1394_new_node(hi, ud);
441 static struct ieee1394_device_id eth1394_id_table[] = {
443 .match_flags = (IEEE1394_MATCH_SPECIFIER_ID |
444 IEEE1394_MATCH_VERSION),
445 .specifier_id = ETHER1394_GASP_SPECIFIER_ID,
446 .version = ETHER1394_GASP_VERSION,
451 MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table);
453 static struct hpsb_protocol_driver eth1394_proto_driver = {
455 .id_table = eth1394_id_table,
456 .update = eth1394_update,
458 .probe = eth1394_probe,
459 .remove = eth1394_remove,
463 static void ether1394_reset_priv(struct net_device *dev, int set_mtu)
467 struct eth1394_priv *priv = netdev_priv(dev);
468 struct hpsb_host *host = priv->host;
469 u64 guid = get_unaligned((u64 *)&(host->csr.rom->bus_info_data[3]));
470 int max_speed = IEEE1394_SPEED_MAX;
472 spin_lock_irqsave(&priv->lock, flags);
474 memset(priv->ud_list, 0, sizeof(priv->ud_list));
475 priv->bc_maxpayload = 512;
477 /* Determine speed limit */
478 for (i = 0; i < host->node_count; i++)
479 if (max_speed > host->speed[i])
480 max_speed = host->speed[i];
481 priv->bc_sspd = max_speed;
484 /* Use the RFC 2734 default 1500 octets or the maximum payload
486 dev->mtu = min(1500, ether1394_max_mtu(host));
488 /* Set our hardware address while we're at it */
489 memcpy(dev->dev_addr, &guid, sizeof(u64));
490 memset(dev->broadcast, 0xff, sizeof(u64));
493 spin_unlock_irqrestore(&priv->lock, flags);
496 static void ether1394_init_dev(struct net_device *dev)
498 dev->open = ether1394_open;
499 dev->stop = ether1394_stop;
500 dev->hard_start_xmit = ether1394_tx;
501 dev->get_stats = ether1394_stats;
502 dev->tx_timeout = ether1394_tx_timeout;
503 dev->change_mtu = ether1394_change_mtu;
505 dev->hard_header = ether1394_header;
506 dev->rebuild_header = ether1394_rebuild_header;
507 dev->hard_header_cache = ether1394_header_cache;
508 dev->header_cache_update= ether1394_header_cache_update;
509 dev->hard_header_parse = ether1394_header_parse;
511 SET_ETHTOOL_OPS(dev, ðtool_ops);
513 dev->watchdog_timeo = ETHER1394_TIMEOUT;
514 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
515 dev->features = NETIF_F_HIGHDMA;
516 dev->addr_len = ETH1394_ALEN;
517 dev->hard_header_len = ETH1394_HLEN;
518 dev->type = ARPHRD_IEEE1394;
520 /* FIXME: This value was copied from ether_setup(). Is it too much? */
521 dev->tx_queue_len = 1000;
525 * This function is called every time a card is found. It is generally called
526 * when the module is installed. This is where we add all of our ethernet
527 * devices. One for each host.
529 static void ether1394_add_host(struct hpsb_host *host)
531 struct eth1394_host_info *hi = NULL;
532 struct net_device *dev = NULL;
533 struct eth1394_priv *priv;
536 if (hpsb_config_rom_ip1394_add(host) != 0) {
537 ETH1394_PRINT_G(KERN_ERR, "Can't add IP-over-1394 ROM entry\n");
541 fifo_addr = hpsb_allocate_and_register_addrspace(
542 ð1394_highlevel, host, &addr_ops,
543 ETHER1394_REGION_ADDR_LEN, ETHER1394_REGION_ADDR_LEN,
544 CSR1212_INVALID_ADDR_SPACE, CSR1212_INVALID_ADDR_SPACE);
545 if (fifo_addr == CSR1212_INVALID_ADDR_SPACE) {
546 ETH1394_PRINT_G(KERN_ERR, "Cannot register CSR space\n");
547 hpsb_config_rom_ip1394_remove(host);
551 dev = alloc_netdev(sizeof(*priv), "eth%d", ether1394_init_dev);
553 ETH1394_PRINT_G(KERN_ERR, "Out of memory\n");
557 SET_MODULE_OWNER(dev);
559 /* FIXME - Is this the correct parent device anyway? */
560 SET_NETDEV_DEV(dev, &host->device);
563 priv = netdev_priv(dev);
564 INIT_LIST_HEAD(&priv->ip_node_list);
565 spin_lock_init(&priv->lock);
567 priv->local_fifo = fifo_addr;
569 hi = hpsb_create_hostinfo(ð1394_highlevel, host, sizeof(*hi));
571 ETH1394_PRINT_G(KERN_ERR, "Out of memory\n");
575 ether1394_reset_priv(dev, 1);
577 if (register_netdev(dev)) {
578 ETH1394_PRINT_G(KERN_ERR, "Cannot register the driver\n");
582 ETH1394_PRINT(KERN_INFO, dev->name, "IPv4 over IEEE 1394 (fw-host%d)\n",
588 /* Ignore validity in hopes that it will be set in the future. It'll
589 * be checked when the eth device is opened. */
590 priv->broadcast_channel = host->csr.broadcast_channel & 0x3f;
592 ether1394_recv_init(priv);
598 hpsb_destroy_hostinfo(ð1394_highlevel, host);
599 hpsb_unregister_addrspace(ð1394_highlevel, host, fifo_addr);
600 hpsb_config_rom_ip1394_remove(host);
603 /* Remove a card from our list */
604 static void ether1394_remove_host(struct hpsb_host *host)
606 struct eth1394_host_info *hi;
607 struct eth1394_priv *priv;
609 hi = hpsb_get_hostinfo(ð1394_highlevel, host);
612 priv = netdev_priv(hi->dev);
613 hpsb_unregister_addrspace(ð1394_highlevel, host, priv->local_fifo);
614 hpsb_config_rom_ip1394_remove(host);
616 hpsb_iso_shutdown(priv->iso);
617 unregister_netdev(hi->dev);
618 free_netdev(hi->dev);
621 /* A bus reset happened */
622 static void ether1394_host_reset(struct hpsb_host *host)
624 struct eth1394_host_info *hi;
625 struct eth1394_priv *priv;
626 struct net_device *dev;
627 struct list_head *lh, *n;
628 struct eth1394_node_ref *node;
629 struct eth1394_node_info *node_info;
632 hi = hpsb_get_hostinfo(ð1394_highlevel, host);
634 /* This can happen for hosts that we don't use */
639 priv = netdev_priv(dev);
641 /* Reset our private host data, but not our MTU */
642 netif_stop_queue(dev);
643 ether1394_reset_priv(dev, 0);
645 list_for_each_entry(node, &priv->ip_node_list, list) {
646 node_info = node->ud->device.driver_data;
648 spin_lock_irqsave(&node_info->pdg.lock, flags);
650 list_for_each_safe(lh, n, &node_info->pdg.list)
651 purge_partial_datagram(lh);
653 INIT_LIST_HEAD(&(node_info->pdg.list));
654 node_info->pdg.sz = 0;
656 spin_unlock_irqrestore(&node_info->pdg.lock, flags);
659 netif_wake_queue(dev);
662 /******************************************
663 * HW Header net device functions
664 ******************************************/
665 /* These functions have been adapted from net/ethernet/eth.c */
667 /* Create a fake MAC header for an arbitrary protocol layer.
668 * saddr=NULL means use device source address
669 * daddr=NULL means leave destination address (eg unresolved arp). */
670 static int ether1394_header(struct sk_buff *skb, struct net_device *dev,
671 unsigned short type, void *daddr, void *saddr,
674 struct eth1394hdr *eth =
675 (struct eth1394hdr *)skb_push(skb, ETH1394_HLEN);
677 eth->h_proto = htons(type);
679 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
680 memset(eth->h_dest, 0, dev->addr_len);
681 return dev->hard_header_len;
685 memcpy(eth->h_dest, daddr, dev->addr_len);
686 return dev->hard_header_len;
689 return -dev->hard_header_len;
692 /* Rebuild the faked MAC header. This is called after an ARP
693 * (or in future other address resolution) has completed on this
694 * sk_buff. We now let ARP fill in the other fields.
696 * This routine CANNOT use cached dst->neigh!
697 * Really, it is used only when dst->neigh is wrong.
699 static int ether1394_rebuild_header(struct sk_buff *skb)
701 struct eth1394hdr *eth = (struct eth1394hdr *)skb->data;
703 if (eth->h_proto == htons(ETH_P_IP))
704 return arp_find((unsigned char *)ð->h_dest, skb);
706 ETH1394_PRINT(KERN_DEBUG, skb->dev->name,
707 "unable to resolve type %04x addresses\n",
708 ntohs(eth->h_proto));
712 static int ether1394_header_parse(struct sk_buff *skb, unsigned char *haddr)
714 struct net_device *dev = skb->dev;
716 memcpy(haddr, dev->dev_addr, ETH1394_ALEN);
720 static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh)
722 unsigned short type = hh->hh_type;
723 struct net_device *dev = neigh->dev;
724 struct eth1394hdr *eth =
725 (struct eth1394hdr *)((u8 *)hh->hh_data + 16 - ETH1394_HLEN);
727 if (type == htons(ETH_P_802_3))
731 memcpy(eth->h_dest, neigh->ha, dev->addr_len);
733 hh->hh_len = ETH1394_HLEN;
737 /* Called by Address Resolution module to notify changes in address. */
738 static void ether1394_header_cache_update(struct hh_cache *hh,
739 struct net_device *dev,
740 unsigned char * haddr)
742 memcpy((u8 *)hh->hh_data + 16 - ETH1394_HLEN, haddr, dev->addr_len);
745 /******************************************
746 * Datagram reception code
747 ******************************************/
749 /* Copied from net/ethernet/eth.c */
750 static u16 ether1394_type_trans(struct sk_buff *skb, struct net_device *dev)
752 struct eth1394hdr *eth;
755 skb_reset_mac_header(skb);
756 skb_pull(skb, ETH1394_HLEN);
757 eth = eth1394_hdr(skb);
759 if (*eth->h_dest & 1) {
760 if (memcmp(eth->h_dest, dev->broadcast, dev->addr_len) == 0)
761 skb->pkt_type = PACKET_BROADCAST;
764 skb->pkt_type = PACKET_MULTICAST;
767 if (memcmp(eth->h_dest, dev->dev_addr, dev->addr_len))
768 skb->pkt_type = PACKET_OTHERHOST;
771 if (ntohs(eth->h_proto) >= 1536)
776 if (*(unsigned short *)rawp == 0xFFFF)
777 return htons(ETH_P_802_3);
779 return htons(ETH_P_802_2);
782 /* Parse an encapsulated IP1394 header into an ethernet frame packet.
783 * We also perform ARP translation here, if need be. */
784 static u16 ether1394_parse_encap(struct sk_buff *skb, struct net_device *dev,
785 nodeid_t srcid, nodeid_t destid,
788 struct eth1394_priv *priv = netdev_priv(dev);
790 unsigned short ret = 0;
792 /* Setup our hw addresses. We use these to build the ethernet header. */
793 if (destid == (LOCAL_BUS | ALL_NODES))
794 dest_hw = ~0ULL; /* broadcast */
796 dest_hw = cpu_to_be64((u64)priv->host->csr.guid_hi << 32 |
797 priv->host->csr.guid_lo);
799 /* If this is an ARP packet, convert it. First, we want to make
800 * use of some of the fields, since they tell us a little bit
801 * about the sending machine. */
802 if (ether_type == htons(ETH_P_ARP)) {
803 struct eth1394_arp *arp1394 = (struct eth1394_arp *)skb->data;
804 struct arphdr *arp = (struct arphdr *)skb->data;
805 unsigned char *arp_ptr = (unsigned char *)(arp + 1);
806 u64 fifo_addr = (u64)ntohs(arp1394->fifo_hi) << 32 |
807 ntohl(arp1394->fifo_lo);
808 u8 max_rec = min(priv->host->csr.max_rec,
809 (u8)(arp1394->max_rec));
810 int sspd = arp1394->sspd;
812 struct eth1394_node_ref *node;
813 struct eth1394_node_info *node_info;
816 /* Sanity check. MacOSX seems to be sending us 131 in this
817 * field (atleast on my Panther G5). Not sure why. */
818 if (sspd > 5 || sspd < 0)
821 maxpayload = min(eth1394_speedto_maxpayload[sspd],
822 (u16)(1 << (max_rec + 1)));
824 guid = get_unaligned(&arp1394->s_uniq_id);
825 node = eth1394_find_node_guid(&priv->ip_node_list,
831 (struct eth1394_node_info *)node->ud->device.driver_data;
833 /* Update our speed/payload/fifo_offset table */
834 node_info->maxpayload = maxpayload;
835 node_info->sspd = sspd;
836 node_info->fifo = fifo_addr;
838 /* Now that we're done with the 1394 specific stuff, we'll
839 * need to alter some of the data. Believe it or not, all
840 * that needs to be done is sender_IP_address needs to be
841 * moved, the destination hardware address get stuffed
842 * in and the hardware address length set to 8.
844 * IMPORTANT: The code below overwrites 1394 specific data
845 * needed above so keep the munging of the data for the
846 * higher level IP stack last. */
849 arp_ptr += arp->ar_hln; /* skip over sender unique id */
850 *(u32 *)arp_ptr = arp1394->sip; /* move sender IP addr */
851 arp_ptr += arp->ar_pln; /* skip over sender IP addr */
853 if (arp->ar_op == htons(ARPOP_REQUEST))
854 memset(arp_ptr, 0, sizeof(u64));
856 memcpy(arp_ptr, dev->dev_addr, sizeof(u64));
859 /* Now add the ethernet header. */
860 if (dev->hard_header(skb, dev, ntohs(ether_type), &dest_hw, NULL,
862 ret = ether1394_type_trans(skb, dev);
867 static int fragment_overlap(struct list_head *frag_list, int offset, int len)
869 struct fragment_info *fi;
870 int end = offset + len;
872 list_for_each_entry(fi, frag_list, list)
873 if (offset < fi->offset + fi->len && end > fi->offset)
879 static struct list_head *find_partial_datagram(struct list_head *pdgl, int dgl)
881 struct partial_datagram *pd;
883 list_for_each_entry(pd, pdgl, list)
890 /* Assumes that new fragment does not overlap any existing fragments */
891 static int new_fragment(struct list_head *frag_info, int offset, int len)
893 struct list_head *lh;
894 struct fragment_info *fi, *fi2, *new;
896 list_for_each(lh, frag_info) {
897 fi = list_entry(lh, struct fragment_info, list);
898 if (fi->offset + fi->len == offset) {
899 /* The new fragment can be tacked on to the end */
901 /* Did the new fragment plug a hole? */
902 fi2 = list_entry(lh->next, struct fragment_info, list);
903 if (fi->offset + fi->len == fi2->offset) {
904 /* glue fragments together */
910 } else if (offset + len == fi->offset) {
911 /* The new fragment can be tacked on to the beginning */
914 /* Did the new fragment plug a hole? */
915 fi2 = list_entry(lh->prev, struct fragment_info, list);
916 if (fi2->offset + fi2->len == fi->offset) {
917 /* glue fragments together */
923 } else if (offset > fi->offset + fi->len) {
925 } else if (offset + len < fi->offset) {
931 new = kmalloc(sizeof(*new), GFP_ATOMIC);
935 new->offset = offset;
938 list_add(&new->list, lh);
942 static int new_partial_datagram(struct net_device *dev, struct list_head *pdgl,
943 int dgl, int dg_size, char *frag_buf,
944 int frag_off, int frag_len)
946 struct partial_datagram *new;
948 new = kmalloc(sizeof(*new), GFP_ATOMIC);
952 INIT_LIST_HEAD(&new->frag_info);
954 if (new_fragment(&new->frag_info, frag_off, frag_len) < 0) {
960 new->dg_size = dg_size;
962 new->skb = dev_alloc_skb(dg_size + dev->hard_header_len + 15);
964 struct fragment_info *fi = list_entry(new->frag_info.next,
965 struct fragment_info,
972 skb_reserve(new->skb, (dev->hard_header_len + 15) & ~15);
973 new->pbuf = skb_put(new->skb, dg_size);
974 memcpy(new->pbuf + frag_off, frag_buf, frag_len);
976 list_add(&new->list, pdgl);
980 static int update_partial_datagram(struct list_head *pdgl, struct list_head *lh,
981 char *frag_buf, int frag_off, int frag_len)
983 struct partial_datagram *pd =
984 list_entry(lh, struct partial_datagram, list);
986 if (new_fragment(&pd->frag_info, frag_off, frag_len) < 0)
989 memcpy(pd->pbuf + frag_off, frag_buf, frag_len);
991 /* Move list entry to beginnig of list so that oldest partial
992 * datagrams percolate to the end of the list */
997 static int is_datagram_complete(struct list_head *lh, int dg_size)
999 struct partial_datagram *pd;
1000 struct fragment_info *fi;
1002 pd = list_entry(lh, struct partial_datagram, list);
1003 fi = list_entry(pd->frag_info.next, struct fragment_info, list);
1005 return (fi->len == dg_size);
1008 /* Packet reception. We convert the IP1394 encapsulation header to an
1009 * ethernet header, and fill it with some of our other fields. This is
1010 * an incoming packet from the 1394 bus. */
1011 static int ether1394_data_handler(struct net_device *dev, int srcid, int destid,
1014 struct sk_buff *skb;
1015 unsigned long flags;
1016 struct eth1394_priv *priv = netdev_priv(dev);
1017 union eth1394_hdr *hdr = (union eth1394_hdr *)buf;
1018 u16 ether_type = 0; /* initialized to clear warning */
1020 struct unit_directory *ud = priv->ud_list[NODEID_TO_NODE(srcid)];
1021 struct eth1394_node_info *node_info;
1024 struct eth1394_node_ref *node;
1025 node = eth1394_find_node_nodeid(&priv->ip_node_list, srcid);
1026 if (unlikely(!node)) {
1027 HPSB_PRINT(KERN_ERR, "ether1394 rx: sender nodeid "
1028 "lookup failure: " NODE_BUS_FMT,
1029 NODE_BUS_ARGS(priv->host, srcid));
1030 priv->stats.rx_dropped++;
1035 priv->ud_list[NODEID_TO_NODE(srcid)] = ud;
1038 node_info = (struct eth1394_node_info *)ud->device.driver_data;
1040 /* First, did we receive a fragmented or unfragmented datagram? */
1041 hdr->words.word1 = ntohs(hdr->words.word1);
1043 hdr_len = hdr_type_len[hdr->common.lf];
1045 if (hdr->common.lf == ETH1394_HDR_LF_UF) {
1046 /* An unfragmented datagram has been received by the ieee1394
1047 * bus. Build an skbuff around it so we can pass it to the
1048 * high level network layer. */
1050 skb = dev_alloc_skb(len + dev->hard_header_len + 15);
1051 if (unlikely(!skb)) {
1052 ETH1394_PRINT_G(KERN_ERR, "Out of memory\n");
1053 priv->stats.rx_dropped++;
1056 skb_reserve(skb, (dev->hard_header_len + 15) & ~15);
1057 memcpy(skb_put(skb, len - hdr_len), buf + hdr_len,
1059 ether_type = hdr->uf.ether_type;
1061 /* A datagram fragment has been received, now the fun begins. */
1063 struct list_head *pdgl, *lh;
1064 struct partial_datagram *pd;
1066 int fg_len = len - hdr_len;
1070 struct pdg_list *pdg = &(node_info->pdg);
1072 hdr->words.word3 = ntohs(hdr->words.word3);
1073 /* The 4th header word is reserved so no need to do ntohs() */
1075 if (hdr->common.lf == ETH1394_HDR_LF_FF) {
1076 ether_type = hdr->ff.ether_type;
1078 dg_size = hdr->ff.dg_size + 1;
1081 hdr->words.word2 = ntohs(hdr->words.word2);
1083 dg_size = hdr->sf.dg_size + 1;
1084 fg_off = hdr->sf.fg_off;
1086 spin_lock_irqsave(&pdg->lock, flags);
1088 pdgl = &(pdg->list);
1089 lh = find_partial_datagram(pdgl, dgl);
1092 while (pdg->sz >= max_partial_datagrams) {
1093 /* remove the oldest */
1094 purge_partial_datagram(pdgl->prev);
1098 retval = new_partial_datagram(dev, pdgl, dgl, dg_size,
1099 buf + hdr_len, fg_off,
1102 spin_unlock_irqrestore(&pdg->lock, flags);
1106 lh = find_partial_datagram(pdgl, dgl);
1108 struct partial_datagram *pd;
1110 pd = list_entry(lh, struct partial_datagram, list);
1112 if (fragment_overlap(&pd->frag_info, fg_off, fg_len)) {
1113 /* Overlapping fragments, obliterate old
1114 * datagram and start new one. */
1115 purge_partial_datagram(lh);
1116 retval = new_partial_datagram(dev, pdgl, dgl,
1122 spin_unlock_irqrestore(&pdg->lock, flags);
1126 retval = update_partial_datagram(pdgl, lh,
1130 /* Couldn't save off fragment anyway
1131 * so might as well obliterate the
1133 purge_partial_datagram(lh);
1135 spin_unlock_irqrestore(&pdg->lock, flags);
1138 } /* fragment overlap */
1139 } /* new datagram or add to existing one */
1141 pd = list_entry(lh, struct partial_datagram, list);
1143 if (hdr->common.lf == ETH1394_HDR_LF_FF)
1144 pd->ether_type = ether_type;
1146 if (is_datagram_complete(lh, dg_size)) {
1147 ether_type = pd->ether_type;
1149 skb = skb_get(pd->skb);
1150 purge_partial_datagram(lh);
1151 spin_unlock_irqrestore(&pdg->lock, flags);
1153 /* Datagram is not complete, we're done for the
1155 spin_unlock_irqrestore(&pdg->lock, flags);
1158 } /* unframgented datagram or fragmented one */
1160 /* Write metadata, and then pass to the receive level */
1162 skb->ip_summed = CHECKSUM_UNNECESSARY; /* don't check it */
1164 /* Parse the encapsulation header. This actually does the job of
1165 * converting to an ethernet frame header, aswell as arp
1166 * conversion if needed. ARP conversion is easier in this
1167 * direction, since we are using ethernet as our backend. */
1168 skb->protocol = ether1394_parse_encap(skb, dev, srcid, destid,
1171 spin_lock_irqsave(&priv->lock, flags);
1173 if (!skb->protocol) {
1174 priv->stats.rx_errors++;
1175 priv->stats.rx_dropped++;
1176 dev_kfree_skb_any(skb);
1180 if (netif_rx(skb) == NET_RX_DROP) {
1181 priv->stats.rx_errors++;
1182 priv->stats.rx_dropped++;
1187 priv->stats.rx_packets++;
1188 priv->stats.rx_bytes += skb->len;
1191 if (netif_queue_stopped(dev))
1192 netif_wake_queue(dev);
1193 spin_unlock_irqrestore(&priv->lock, flags);
1195 dev->last_rx = jiffies;
1200 static int ether1394_write(struct hpsb_host *host, int srcid, int destid,
1201 quadlet_t *data, u64 addr, size_t len, u16 flags)
1203 struct eth1394_host_info *hi;
1205 hi = hpsb_get_hostinfo(ð1394_highlevel, host);
1206 if (unlikely(!hi)) {
1207 ETH1394_PRINT_G(KERN_ERR, "No net device at fw-host%d\n",
1209 return RCODE_ADDRESS_ERROR;
1212 if (ether1394_data_handler(hi->dev, srcid, destid, (char*)data, len))
1213 return RCODE_ADDRESS_ERROR;
1215 return RCODE_COMPLETE;
1218 static void ether1394_iso(struct hpsb_iso *iso)
1222 struct eth1394_host_info *hi;
1223 struct net_device *dev;
1224 struct eth1394_priv *priv;
1231 hi = hpsb_get_hostinfo(ð1394_highlevel, iso->host);
1232 if (unlikely(!hi)) {
1233 ETH1394_PRINT_G(KERN_ERR, "No net device at fw-host%d\n",
1240 nready = hpsb_iso_n_ready(iso);
1241 for (i = 0; i < nready; i++) {
1242 struct hpsb_iso_packet_info *info =
1243 &iso->infos[(iso->first_packet + i) % iso->buf_packets];
1244 data = (quadlet_t *)(iso->data_buf.kvirt + info->offset);
1246 /* skip over GASP header */
1247 buf = (char *)data + 8;
1248 len = info->len - 8;
1250 specifier_id = (be32_to_cpu(data[0]) & 0xffff) << 8 |
1251 (be32_to_cpu(data[1]) & 0xff000000) >> 24;
1252 source_id = be32_to_cpu(data[0]) >> 16;
1254 priv = netdev_priv(dev);
1256 if (info->channel != (iso->host->csr.broadcast_channel & 0x3f)
1257 || specifier_id != ETHER1394_GASP_SPECIFIER_ID) {
1258 /* This packet is not for us */
1261 ether1394_data_handler(dev, source_id, LOCAL_BUS | ALL_NODES,
1265 hpsb_iso_recv_release_packets(iso, i);
1267 dev->last_rx = jiffies;
1270 /******************************************
1271 * Datagram transmission code
1272 ******************************************/
1274 /* Convert a standard ARP packet to 1394 ARP. The first 8 bytes (the entire
1275 * arphdr) is the same format as the ip1394 header, so they overlap. The rest
1276 * needs to be munged a bit. The remainder of the arphdr is formatted based
1277 * on hwaddr len and ipaddr len. We know what they'll be, so it's easy to
1280 * Now that the EUI is used for the hardware address all we need to do to make
1281 * this work for 1394 is to insert 2 quadlets that contain max_rec size,
1282 * speed, and unicast FIFO address information between the sender_unique_id
1283 * and the IP addresses.
1285 static void ether1394_arp_to_1394arp(struct sk_buff *skb,
1286 struct net_device *dev)
1288 struct eth1394_priv *priv = netdev_priv(dev);
1289 struct arphdr *arp = (struct arphdr *)skb->data;
1290 unsigned char *arp_ptr = (unsigned char *)(arp + 1);
1291 struct eth1394_arp *arp1394 = (struct eth1394_arp *)skb->data;
1293 arp1394->hw_addr_len = 16;
1294 arp1394->sip = *(u32*)(arp_ptr + ETH1394_ALEN);
1295 arp1394->max_rec = priv->host->csr.max_rec;
1296 arp1394->sspd = priv->host->csr.lnk_spd;
1297 arp1394->fifo_hi = htons(priv->local_fifo >> 32);
1298 arp1394->fifo_lo = htonl(priv->local_fifo & ~0x0);
1301 /* We need to encapsulate the standard header with our own. We use the
1302 * ethernet header's proto for our own. */
1303 static unsigned int ether1394_encapsulate_prep(unsigned int max_payload,
1305 union eth1394_hdr *hdr,
1306 u16 dg_size, u16 dgl)
1308 unsigned int adj_max_payload =
1309 max_payload - hdr_type_len[ETH1394_HDR_LF_UF];
1311 /* Does it all fit in one packet? */
1312 if (dg_size <= adj_max_payload) {
1313 hdr->uf.lf = ETH1394_HDR_LF_UF;
1314 hdr->uf.ether_type = proto;
1316 hdr->ff.lf = ETH1394_HDR_LF_FF;
1317 hdr->ff.ether_type = proto;
1318 hdr->ff.dg_size = dg_size - 1;
1320 adj_max_payload = max_payload - hdr_type_len[ETH1394_HDR_LF_FF];
1322 return (dg_size + adj_max_payload - 1) / adj_max_payload;
1325 static unsigned int ether1394_encapsulate(struct sk_buff *skb,
1326 unsigned int max_payload,
1327 union eth1394_hdr *hdr)
1329 union eth1394_hdr *bufhdr;
1330 int ftype = hdr->common.lf;
1331 int hdrsz = hdr_type_len[ftype];
1332 unsigned int adj_max_payload = max_payload - hdrsz;
1335 case ETH1394_HDR_LF_UF:
1336 bufhdr = (union eth1394_hdr *)skb_push(skb, hdrsz);
1337 bufhdr->words.word1 = htons(hdr->words.word1);
1338 bufhdr->words.word2 = hdr->words.word2;
1341 case ETH1394_HDR_LF_FF:
1342 bufhdr = (union eth1394_hdr *)skb_push(skb, hdrsz);
1343 bufhdr->words.word1 = htons(hdr->words.word1);
1344 bufhdr->words.word2 = hdr->words.word2;
1345 bufhdr->words.word3 = htons(hdr->words.word3);
1346 bufhdr->words.word4 = 0;
1348 /* Set frag type here for future interior fragments */
1349 hdr->common.lf = ETH1394_HDR_LF_IF;
1354 hdr->sf.fg_off += adj_max_payload;
1355 bufhdr = (union eth1394_hdr *)skb_pull(skb, adj_max_payload);
1356 if (max_payload >= skb->len)
1357 hdr->common.lf = ETH1394_HDR_LF_LF;
1358 bufhdr->words.word1 = htons(hdr->words.word1);
1359 bufhdr->words.word2 = htons(hdr->words.word2);
1360 bufhdr->words.word3 = htons(hdr->words.word3);
1361 bufhdr->words.word4 = 0;
1363 return min(max_payload, skb->len);
1366 static struct hpsb_packet *ether1394_alloc_common_packet(struct hpsb_host *host)
1368 struct hpsb_packet *p;
1370 p = hpsb_alloc_packet(0);
1373 p->generation = get_hpsb_generation(host);
1374 p->type = hpsb_async;
1379 static int ether1394_prep_write_packet(struct hpsb_packet *p,
1380 struct hpsb_host *host, nodeid_t node,
1381 u64 addr, void *data, int tx_len)
1386 p->tcode = TCODE_WRITEB;
1387 p->header[1] = host->node_id << 16 | addr >> 32;
1388 p->header[2] = addr & 0xffffffff;
1390 p->header_size = 16;
1391 p->expect_response = 1;
1393 if (hpsb_get_tlabel(p)) {
1394 ETH1394_PRINT_G(KERN_ERR, "Out of tlabels\n");
1398 p->node_id << 16 | p->tlabel << 10 | 1 << 8 | TCODE_WRITEB << 4;
1400 p->header[3] = tx_len << 16;
1401 p->data_size = (tx_len + 3) & ~3;
1407 static void ether1394_prep_gasp_packet(struct hpsb_packet *p,
1408 struct eth1394_priv *priv,
1409 struct sk_buff *skb, int length)
1412 p->tcode = TCODE_STREAM_DATA;
1414 p->header[0] = length << 16 | 3 << 14 | priv->broadcast_channel << 8 |
1415 TCODE_STREAM_DATA << 4;
1416 p->data_size = length;
1417 p->data = (quadlet_t *)skb->data - 2;
1418 p->data[0] = cpu_to_be32(priv->host->node_id << 16 |
1419 ETHER1394_GASP_SPECIFIER_ID_HI);
1420 p->data[1] = cpu_to_be32(ETHER1394_GASP_SPECIFIER_ID_LO << 24 |
1421 ETHER1394_GASP_VERSION);
1423 /* Setting the node id to ALL_NODES (not LOCAL_BUS | ALL_NODES)
1424 * prevents hpsb_send_packet() from setting the speed to an arbitrary
1425 * value based on packet->node_id if packet->node_id is not set. */
1426 p->node_id = ALL_NODES;
1427 p->speed_code = priv->bc_sspd;
1430 static void ether1394_free_packet(struct hpsb_packet *packet)
1432 if (packet->tcode != TCODE_STREAM_DATA)
1433 hpsb_free_tlabel(packet);
1434 hpsb_free_packet(packet);
1437 static void ether1394_complete_cb(void *__ptask);
1439 static int ether1394_send_packet(struct packet_task *ptask, unsigned int tx_len)
1441 struct eth1394_priv *priv = ptask->priv;
1442 struct hpsb_packet *packet = NULL;
1444 packet = ether1394_alloc_common_packet(priv->host);
1448 if (ptask->tx_type == ETH1394_GASP) {
1449 int length = tx_len + 2 * sizeof(quadlet_t);
1451 ether1394_prep_gasp_packet(packet, priv, ptask->skb, length);
1452 } else if (ether1394_prep_write_packet(packet, priv->host,
1454 ptask->addr, ptask->skb->data,
1456 hpsb_free_packet(packet);
1460 ptask->packet = packet;
1461 hpsb_set_packet_complete_task(ptask->packet, ether1394_complete_cb,
1464 if (hpsb_send_packet(packet) < 0) {
1465 ether1394_free_packet(packet);
1472 /* Task function to be run when a datagram transmission is completed */
1473 static void ether1394_dg_complete(struct packet_task *ptask, int fail)
1475 struct sk_buff *skb = ptask->skb;
1476 struct eth1394_priv *priv = netdev_priv(skb->dev);
1477 unsigned long flags;
1480 spin_lock_irqsave(&priv->lock, flags);
1482 priv->stats.tx_dropped++;
1483 priv->stats.tx_errors++;
1485 priv->stats.tx_bytes += skb->len;
1486 priv->stats.tx_packets++;
1488 spin_unlock_irqrestore(&priv->lock, flags);
1490 dev_kfree_skb_any(skb);
1491 kmem_cache_free(packet_task_cache, ptask);
1494 /* Callback for when a packet has been sent and the status of that packet is
1496 static void ether1394_complete_cb(void *__ptask)
1498 struct packet_task *ptask = (struct packet_task *)__ptask;
1499 struct hpsb_packet *packet = ptask->packet;
1502 if (packet->tcode != TCODE_STREAM_DATA)
1503 fail = hpsb_packet_success(packet);
1505 ether1394_free_packet(packet);
1507 ptask->outstanding_pkts--;
1508 if (ptask->outstanding_pkts > 0 && !fail) {
1511 /* Add the encapsulation header to the fragment */
1512 tx_len = ether1394_encapsulate(ptask->skb, ptask->max_payload,
1514 if (ether1394_send_packet(ptask, tx_len))
1515 ether1394_dg_complete(ptask, 1);
1517 ether1394_dg_complete(ptask, fail);
1521 /* Transmit a packet (called by kernel) */
1522 static int ether1394_tx(struct sk_buff *skb, struct net_device *dev)
1524 struct eth1394hdr *eth;
1525 struct eth1394_priv *priv = netdev_priv(dev);
1527 unsigned long flags;
1529 eth1394_tx_type tx_type;
1530 unsigned int tx_len;
1531 unsigned int max_payload;
1534 struct packet_task *ptask;
1535 struct eth1394_node_ref *node;
1536 struct eth1394_node_info *node_info = NULL;
1538 ptask = kmem_cache_alloc(packet_task_cache, GFP_ATOMIC);
1542 /* XXX Ignore this for now. Noticed that when MacOSX is the IRM,
1543 * it does not set our validity bit. We need to compensate for
1544 * that somewhere else, but not in eth1394. */
1546 if ((priv->host->csr.broadcast_channel & 0xc0000000) != 0xc0000000)
1550 skb = skb_share_check(skb, GFP_ATOMIC);
1554 /* Get rid of the fake eth1394 header, but save a pointer */
1555 eth = (struct eth1394hdr *)skb->data;
1556 skb_pull(skb, ETH1394_HLEN);
1558 proto = eth->h_proto;
1561 /* Set the transmission type for the packet. ARP packets and IP
1562 * broadcast packets are sent via GASP. */
1563 if (memcmp(eth->h_dest, dev->broadcast, ETH1394_ALEN) == 0 ||
1564 proto == htons(ETH_P_ARP) ||
1565 (proto == htons(ETH_P_IP) &&
1566 IN_MULTICAST(ntohl(ip_hdr(skb)->daddr)))) {
1567 tx_type = ETH1394_GASP;
1568 dest_node = LOCAL_BUS | ALL_NODES;
1569 max_payload = priv->bc_maxpayload - ETHER1394_GASP_OVERHEAD;
1570 BUG_ON(max_payload < 512 - ETHER1394_GASP_OVERHEAD);
1572 if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF])
1575 __be64 guid = get_unaligned((u64 *)eth->h_dest);
1577 node = eth1394_find_node_guid(&priv->ip_node_list,
1583 (struct eth1394_node_info *)node->ud->device.driver_data;
1584 if (node_info->fifo == CSR1212_INVALID_ADDR_SPACE)
1587 dest_node = node->ud->ne->nodeid;
1588 max_payload = node_info->maxpayload;
1589 BUG_ON(max_payload < 512 - ETHER1394_GASP_OVERHEAD);
1591 dgl = node_info->dgl;
1592 if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF])
1594 tx_type = ETH1394_WRREQ;
1597 /* If this is an ARP packet, convert it */
1598 if (proto == htons(ETH_P_ARP))
1599 ether1394_arp_to_1394arp(skb, dev);
1601 ptask->hdr.words.word1 = 0;
1602 ptask->hdr.words.word2 = 0;
1603 ptask->hdr.words.word3 = 0;
1604 ptask->hdr.words.word4 = 0;
1607 ptask->tx_type = tx_type;
1609 if (tx_type != ETH1394_GASP) {
1612 spin_lock_irqsave(&priv->lock, flags);
1613 addr = node_info->fifo;
1614 spin_unlock_irqrestore(&priv->lock, flags);
1617 ptask->dest_node = dest_node;
1620 ptask->tx_type = tx_type;
1621 ptask->max_payload = max_payload;
1622 ptask->outstanding_pkts = ether1394_encapsulate_prep(max_payload,
1623 proto, &ptask->hdr, dg_size, dgl);
1625 /* Add the encapsulation header to the fragment */
1626 tx_len = ether1394_encapsulate(skb, max_payload, &ptask->hdr);
1627 dev->trans_start = jiffies;
1628 if (ether1394_send_packet(ptask, tx_len))
1631 netif_wake_queue(dev);
1632 return NETDEV_TX_OK;
1635 kmem_cache_free(packet_task_cache, ptask);
1640 spin_lock_irqsave(&priv->lock, flags);
1641 priv->stats.tx_dropped++;
1642 priv->stats.tx_errors++;
1643 spin_unlock_irqrestore(&priv->lock, flags);
1645 if (netif_queue_stopped(dev))
1646 netif_wake_queue(dev);
1649 * FIXME: According to a patch from 2003-02-26, "returning non-zero
1650 * causes serious problems" here, allegedly. Before that patch,
1651 * -ERRNO was returned which is not appropriate under Linux 2.6.
1652 * Perhaps more needs to be done? Stop the queue in serious
1653 * conditions and restart it elsewhere?
1655 /* return NETDEV_TX_BUSY; */
1656 return NETDEV_TX_OK;
1659 static void ether1394_get_drvinfo(struct net_device *dev,
1660 struct ethtool_drvinfo *info)
1662 strcpy(info->driver, driver_name);
1663 strcpy(info->bus_info, "ieee1394"); /* FIXME provide more detail? */
1666 static struct ethtool_ops ethtool_ops = {
1667 .get_drvinfo = ether1394_get_drvinfo
1670 static int __init ether1394_init_module(void)
1674 packet_task_cache = kmem_cache_create("packet_task",
1675 sizeof(struct packet_task),
1677 if (!packet_task_cache)
1680 hpsb_register_highlevel(ð1394_highlevel);
1681 err = hpsb_register_protocol(ð1394_proto_driver);
1683 hpsb_unregister_highlevel(ð1394_highlevel);
1684 kmem_cache_destroy(packet_task_cache);
1689 static void __exit ether1394_exit_module(void)
1691 hpsb_unregister_protocol(ð1394_proto_driver);
1692 hpsb_unregister_highlevel(ð1394_highlevel);
1693 kmem_cache_destroy(packet_task_cache);
1696 module_init(ether1394_init_module);
1697 module_exit(ether1394_exit_module);