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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/types.h> |
| 15 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #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 Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 29 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <net/arp.h> |
| 31 | |
| 32 | /* |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 33 | * Put the headers on a Fibre Channel packet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | */ |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static int fc_header(struct sk_buff *skb, struct net_device *dev, |
| 37 | unsigned short type, |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 38 | const void *daddr, const void *saddr, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
| 40 | struct fch_hdr *fch; |
| 41 | int hdr_len; |
| 42 | |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 43 | /* |
| 44 | * 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] | 45 | * 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 Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 62 | fch = (struct fch_hdr *)skb_push(skb, hdr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 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 Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 70 | if(daddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
| 72 | memcpy(fch->daddr,daddr,dev->addr_len); |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 73 | return hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | return -hdr_len; |
| 76 | } |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 77 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 78 | static const struct header_ops fc_header_ops = { |
| 79 | .create = fc_header, |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | static void fc_setup(struct net_device *dev) |
| 83 | { |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 84 | dev->header_ops = &fc_header_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | dev->type = ARPHRD_IEEE802; |
| 86 | dev->hard_header_len = FC_HLEN; |
| 87 | dev->mtu = 2024; |
| 88 | dev->addr_len = FC_ALEN; |
| 89 | dev->tx_queue_len = 100; /* Long queues on fc */ |
| 90 | dev->flags = IFF_BROADCAST; |
| 91 | |
| 92 | memset(dev->broadcast, 0xFF, FC_ALEN); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * alloc_fcdev - Register fibre channel device |
| 97 | * @sizeof_priv: Size of additional driver-private structure to be allocated |
| 98 | * for this fibre channel device |
| 99 | * |
| 100 | * Fill in the fields of the device structure with fibre channel-generic values. |
| 101 | * |
| 102 | * Constructs a new net device, complete with a private data area of |
| 103 | * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for |
| 104 | * this private data area. |
| 105 | */ |
| 106 | struct net_device *alloc_fcdev(int sizeof_priv) |
| 107 | { |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 108 | return alloc_netdev(sizeof_priv, "fc%d", NET_NAME_UNKNOWN, fc_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | EXPORT_SYMBOL(alloc_fcdev); |