Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * NET3: Fibre Channel device handling subroutines |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 8 | * |
| 9 | * Vineet Abraham <vma@iol.unh.edu> |
| 10 | * v 1.0 03/22/99 |
| 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/uaccess.h> |
| 14 | #include <asm/system.h> |
| 15 | #include <linux/types.h> |
| 16 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/string.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/socket.h> |
| 20 | #include <linux/in.h> |
| 21 | #include <linux/inet.h> |
| 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/fcdevice.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | #include <linux/errno.h> |
| 26 | #include <linux/timer.h> |
| 27 | #include <linux/net.h> |
| 28 | #include <linux/proc_fs.h> |
| 29 | #include <linux/init.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 30 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <net/arp.h> |
| 32 | |
| 33 | /* |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 34 | * Put the headers on a Fibre Channel packet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | */ |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static int fc_header(struct sk_buff *skb, struct net_device *dev, |
| 38 | unsigned short type, |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 39 | const void *daddr, const void *saddr, unsigned len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
| 41 | struct fch_hdr *fch; |
| 42 | int hdr_len; |
| 43 | |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 44 | /* |
| 45 | * Add the 802.2 SNAP header if IP as the IPv4 code calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | * dev->hard_header directly. |
| 47 | */ |
| 48 | if (type == ETH_P_IP || type == ETH_P_ARP) |
| 49 | { |
| 50 | struct fcllc *fcllc; |
| 51 | |
| 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); |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | hdr_len = sizeof(struct fch_hdr); |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 63 | fch = (struct fch_hdr *)skb_push(skb, hdr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | if(saddr) |
| 67 | memcpy(fch->saddr,saddr,dev->addr_len); |
| 68 | else |
| 69 | memcpy(fch->saddr,dev->dev_addr,dev->addr_len); |
| 70 | |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 71 | if(daddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
| 73 | memcpy(fch->daddr,daddr,dev->addr_len); |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 74 | return hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | return -hdr_len; |
| 77 | } |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* |
| 80 | * A neighbour discovery of some species (eg arp) has completed. We |
| 81 | * can now send the packet. |
| 82 | */ |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 83 | |
| 84 | static int fc_rebuild_header(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Manish Katiyar | deb28d9 | 2008-10-15 00:13:53 -0700 | [diff] [blame] | 86 | #ifdef CONFIG_INET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)) { |
Alexey Dobriyan | 57bf145 | 2005-08-25 16:06:19 -0700 | [diff] [blame] | 90 | printk("fc_rebuild_header: Don't know how to resolve type %04X addresses ?\n", ntohs(fcllc->ethertype)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | return 0; |
| 92 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | return arp_find(fch->daddr, skb); |
| 94 | #else |
| 95 | return 0; |
| 96 | #endif |
| 97 | } |
| 98 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 99 | static const struct header_ops fc_header_ops = { |
| 100 | .create = fc_header, |
| 101 | .rebuild = fc_rebuild_header, |
| 102 | }; |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | static void fc_setup(struct net_device *dev) |
| 105 | { |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 106 | dev->header_ops = &fc_header_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | dev->type = ARPHRD_IEEE802; |
| 108 | dev->hard_header_len = FC_HLEN; |
| 109 | dev->mtu = 2024; |
| 110 | dev->addr_len = FC_ALEN; |
| 111 | dev->tx_queue_len = 100; /* Long queues on fc */ |
| 112 | dev->flags = IFF_BROADCAST; |
| 113 | |
| 114 | memset(dev->broadcast, 0xFF, FC_ALEN); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * alloc_fcdev - Register fibre channel device |
| 119 | * @sizeof_priv: Size of additional driver-private structure to be allocated |
| 120 | * for this fibre channel device |
| 121 | * |
| 122 | * Fill in the fields of the device structure with fibre channel-generic values. |
| 123 | * |
| 124 | * Constructs a new net device, complete with a private data area of |
| 125 | * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for |
| 126 | * this private data area. |
| 127 | */ |
| 128 | struct net_device *alloc_fcdev(int sizeof_priv) |
| 129 | { |
| 130 | return alloc_netdev(sizeof_priv, "fc%d", fc_setup); |
| 131 | } |
| 132 | EXPORT_SYMBOL(alloc_fcdev); |