Linux 2.6.19-rc6
[cris-mirror.git] / net / 802 / fc.c
blob2a27e37bc4cb263869b0e5a20643997064067713
1 /*
2 * NET3: Fibre Channel device handling subroutines
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Vineet Abraham <vma@iol.unh.edu>
10 * v 1.0 03/22/99
13 #include <asm/uaccess.h>
14 #include <asm/system.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/string.h>
19 #include <linux/mm.h>
20 #include <linux/socket.h>
21 #include <linux/in.h>
22 #include <linux/inet.h>
23 #include <linux/netdevice.h>
24 #include <linux/fcdevice.h>
25 #include <linux/skbuff.h>
26 #include <linux/errno.h>
27 #include <linux/timer.h>
28 #include <linux/net.h>
29 #include <linux/proc_fs.h>
30 #include <linux/init.h>
31 #include <net/arp.h>
34 * Put the headers on a Fibre Channel packet.
37 static int fc_header(struct sk_buff *skb, struct net_device *dev,
38 unsigned short type,
39 void *daddr, void *saddr, unsigned len)
41 struct fch_hdr *fch;
42 int hdr_len;
44 /*
45 * Add the 802.2 SNAP header if IP as the IPv4 code calls
46 * dev->hard_header directly.
48 if (type == ETH_P_IP || type == ETH_P_ARP)
50 struct fcllc *fcllc;
52 hdr_len = sizeof(struct fch_hdr) + sizeof(struct fcllc);
53 fch = (struct fch_hdr *)skb_push(skb, hdr_len);
54 fcllc = (struct fcllc *)(fch+1);
55 fcllc->dsap = fcllc->ssap = EXTENDED_SAP;
56 fcllc->llc = UI_CMD;
57 fcllc->protid[0] = fcllc->protid[1] = fcllc->protid[2] = 0x00;
58 fcllc->ethertype = htons(type);
60 else
62 hdr_len = sizeof(struct fch_hdr);
63 fch = (struct fch_hdr *)skb_push(skb, hdr_len);
66 if(saddr)
67 memcpy(fch->saddr,saddr,dev->addr_len);
68 else
69 memcpy(fch->saddr,dev->dev_addr,dev->addr_len);
71 if(daddr)
73 memcpy(fch->daddr,daddr,dev->addr_len);
74 return(hdr_len);
76 return -hdr_len;
80 * A neighbour discovery of some species (eg arp) has completed. We
81 * can now send the packet.
84 static int fc_rebuild_header(struct sk_buff *skb)
86 struct fch_hdr *fch=(struct fch_hdr *)skb->data;
87 struct fcllc *fcllc=(struct fcllc *)(skb->data+sizeof(struct fch_hdr));
88 if(fcllc->ethertype != htons(ETH_P_IP)) {
89 printk("fc_rebuild_header: Don't know how to resolve type %04X addresses ?\n", ntohs(fcllc->ethertype));
90 return 0;
92 #ifdef CONFIG_INET
93 return arp_find(fch->daddr, skb);
94 #else
95 return 0;
96 #endif
99 static void fc_setup(struct net_device *dev)
101 dev->hard_header = fc_header;
102 dev->rebuild_header = fc_rebuild_header;
104 dev->type = ARPHRD_IEEE802;
105 dev->hard_header_len = FC_HLEN;
106 dev->mtu = 2024;
107 dev->addr_len = FC_ALEN;
108 dev->tx_queue_len = 100; /* Long queues on fc */
109 dev->flags = IFF_BROADCAST;
111 memset(dev->broadcast, 0xFF, FC_ALEN);
115 * alloc_fcdev - Register fibre channel device
116 * @sizeof_priv: Size of additional driver-private structure to be allocated
117 * for this fibre channel device
119 * Fill in the fields of the device structure with fibre channel-generic values.
121 * Constructs a new net device, complete with a private data area of
122 * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
123 * this private data area.
125 struct net_device *alloc_fcdev(int sizeof_priv)
127 return alloc_netdev(sizeof_priv, "fc%d", fc_setup);
129 EXPORT_SYMBOL(alloc_fcdev);