blob: 7c174b6750cd654c49d7c1d2f621eb9fc3ed1ef0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * NET3: Fibre Channel device handling subroutines
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +09003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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.
8 *
9 * Vineet Abraham <vma@iol.unh.edu>
10 * v 1.0 03/22/99
11 */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/string.h>
17#include <linux/mm.h>
18#include <linux/socket.h>
19#include <linux/in.h>
20#include <linux/inet.h>
21#include <linux/netdevice.h>
22#include <linux/fcdevice.h>
23#include <linux/skbuff.h>
24#include <linux/errno.h>
25#include <linux/timer.h>
26#include <linux/net.h>
27#include <linux/proc_fs.h>
28#include <linux/init.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040029#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <net/arp.h>
31
32/*
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +090033 * Put the headers on a Fibre Channel packet.
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 */
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +090035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036static int fc_header(struct sk_buff *skb, struct net_device *dev,
37 unsigned short type,
Eric Dumazet95c96172012-04-15 05:58:06 +000038 const void *daddr, const void *saddr, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 struct fch_hdr *fch;
41 int hdr_len;
42
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +090043 /*
44 * Add the 802.2 SNAP header if IP as the IPv4 code calls
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 * dev->hard_header directly.
46 */
47 if (type == ETH_P_IP || type == ETH_P_ARP)
48 {
49 struct fcllc *fcllc;
50
51 hdr_len = sizeof(struct fch_hdr) + sizeof(struct fcllc);
52 fch = (struct fch_hdr *)skb_push(skb, hdr_len);
53 fcllc = (struct fcllc *)(fch+1);
54 fcllc->dsap = fcllc->ssap = EXTENDED_SAP;
55 fcllc->llc = UI_CMD;
56 fcllc->protid[0] = fcllc->protid[1] = fcllc->protid[2] = 0x00;
57 fcllc->ethertype = htons(type);
58 }
59 else
60 {
61 hdr_len = sizeof(struct fch_hdr);
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +090062 fch = (struct fch_hdr *)skb_push(skb, hdr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 }
64
65 if(saddr)
66 memcpy(fch->saddr,saddr,dev->addr_len);
67 else
68 memcpy(fch->saddr,dev->dev_addr,dev->addr_len);
69
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +090070 if(daddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 {
72 memcpy(fch->daddr,daddr,dev->addr_len);
Eric Dumazeta02cec22010-09-22 20:43:57 +000073 return hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 }
75 return -hdr_len;
76}
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +090077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078/*
79 * A neighbour discovery of some species (eg arp) has completed. We
80 * can now send the packet.
81 */
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +090082
83static int fc_rebuild_header(struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Manish Katiyardeb28d92008-10-15 00:13:53 -070085#ifdef CONFIG_INET
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 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)) {
Alexey Dobriyan57bf1452005-08-25 16:06:19 -070089 printk("fc_rebuild_header: Don't know how to resolve type %04X addresses ?\n", ntohs(fcllc->ethertype));
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 return 0;
91 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return arp_find(fch->daddr, skb);
93#else
94 return 0;
95#endif
96}
97
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -070098static const struct header_ops fc_header_ops = {
99 .create = fc_header,
100 .rebuild = fc_rebuild_header,
101};
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103static void fc_setup(struct net_device *dev)
104{
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700105 dev->header_ops = &fc_header_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 dev->type = ARPHRD_IEEE802;
107 dev->hard_header_len = FC_HLEN;
108 dev->mtu = 2024;
109 dev->addr_len = FC_ALEN;
110 dev->tx_queue_len = 100; /* Long queues on fc */
111 dev->flags = IFF_BROADCAST;
112
113 memset(dev->broadcast, 0xFF, FC_ALEN);
114}
115
116/**
117 * alloc_fcdev - Register fibre channel device
118 * @sizeof_priv: Size of additional driver-private structure to be allocated
119 * for this fibre channel device
120 *
121 * Fill in the fields of the device structure with fibre channel-generic values.
122 *
123 * Constructs a new net device, complete with a private data area of
124 * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
125 * this private data area.
126 */
127struct net_device *alloc_fcdev(int sizeof_priv)
128{
Tom Gundersenc835a672014-07-14 16:37:24 +0200129 return alloc_netdev(sizeof_priv, "fc%d", NET_NAME_UNKNOWN, fc_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131EXPORT_SYMBOL(alloc_fcdev);