2 * NET3: Fibre Channel device handling subroutines
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>
13 #include <linux/config.h>
14 #include <asm/uaccess.h>
15 #include <asm/system.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/string.h>
21 #include <linux/socket.h>
23 #include <linux/inet.h>
24 #include <linux/netdevice.h>
25 #include <linux/fcdevice.h>
26 #include <linux/skbuff.h>
27 #include <linux/errno.h>
28 #include <linux/timer.h>
29 #include <linux/net.h>
30 #include <linux/proc_fs.h>
31 #include <linux/init.h>
35 * Put the headers on a Fibre Channel packet.
38 static int fc_header(struct sk_buff *skb, struct net_device *dev,
40 void *daddr, void *saddr, unsigned len)
46 * Add the 802.2 SNAP header if IP as the IPv4 code calls
47 * dev->hard_header directly.
49 if (type == ETH_P_IP || type == ETH_P_ARP)
53 hdr_len = sizeof(struct fch_hdr) + sizeof(struct fcllc);
54 fch = (struct fch_hdr *)skb_push(skb, hdr_len);
55 fcllc = (struct fcllc *)(fch+1);
56 fcllc->dsap = fcllc->ssap = EXTENDED_SAP;
58 fcllc->protid[0] = fcllc->protid[1] = fcllc->protid[2] = 0x00;
59 fcllc->ethertype = htons(type);
63 hdr_len = sizeof(struct fch_hdr);
64 fch = (struct fch_hdr *)skb_push(skb, hdr_len);
68 memcpy(fch->saddr,saddr,dev->addr_len);
70 memcpy(fch->saddr,dev->dev_addr,dev->addr_len);
74 memcpy(fch->daddr,daddr,dev->addr_len);
81 * A neighbour discovery of some species (eg arp) has completed. We
82 * can now send the packet.
85 static int fc_rebuild_header(struct sk_buff *skb)
87 struct fch_hdr *fch=(struct fch_hdr *)skb->data;
88 struct fcllc *fcllc=(struct fcllc *)(skb->data+sizeof(struct fch_hdr));
89 if(fcllc->ethertype != htons(ETH_P_IP)) {
90 printk("fc_rebuild_header: Don't know how to resolve type %04X addresses ?\n",(unsigned int)htons(fcllc->ethertype));
94 return arp_find(fch->daddr, skb);
101 fc_type_trans(struct sk_buff *skb, struct net_device *dev)
103 struct fch_hdr *fch = (struct fch_hdr *)skb->data;
106 skb->mac.raw = skb->data;
107 fcllc = (struct fcllc *)(skb->data + sizeof (struct fch_hdr) + 2);
108 skb_pull(skb, sizeof (struct fch_hdr) + 2);
110 if (*fch->daddr & 1) {
111 if (!memcmp(fch->daddr, dev->broadcast, FC_ALEN))
112 skb->pkt_type = PACKET_BROADCAST;
114 skb->pkt_type = PACKET_MULTICAST;
115 } else if (dev->flags & IFF_PROMISC) {
116 if (memcmp(fch->daddr, dev->dev_addr, FC_ALEN))
117 skb->pkt_type = PACKET_OTHERHOST;
121 * Strip the SNAP header from ARP packets since we don't pass
122 * them through to the 802.2/SNAP layers.
124 if (fcllc->dsap == EXTENDED_SAP &&
125 (fcllc->ethertype == ntohs(ETH_P_IP) ||
126 fcllc->ethertype == ntohs(ETH_P_ARP))) {
127 skb_pull(skb, sizeof (struct fcllc));
128 return fcllc->ethertype;
131 return ntohs(ETH_P_802_2);
134 static void fc_setup(struct net_device *dev)
136 dev->hard_header = fc_header;
137 dev->rebuild_header = fc_rebuild_header;
139 dev->type = ARPHRD_IEEE802;
140 dev->hard_header_len = FC_HLEN;
142 dev->addr_len = FC_ALEN;
143 dev->tx_queue_len = 100; /* Long queues on fc */
144 dev->flags = IFF_BROADCAST;
146 memset(dev->broadcast, 0xFF, FC_ALEN);
150 * alloc_fcdev - Register fibre channel device
151 * @sizeof_priv: Size of additional driver-private structure to be allocated
152 * for this fibre channel device
154 * Fill in the fields of the device structure with fibre channel-generic values.
156 * Constructs a new net device, complete with a private data area of
157 * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
158 * this private data area.
160 struct net_device *alloc_fcdev(int sizeof_priv)
162 return alloc_netdev(sizeof_priv, "fc%d", fc_setup);
164 EXPORT_SYMBOL(alloc_fcdev);