blob: 4d3bc0d49df59394ea550a74c05c4ad0c84c436b [file] [log] [blame]
Ed L. Cashin52e112b2008-02-08 04:20:09 -08001/* Copyright (c) 2007 Coraid, Inc. See COPYING for GPL terms. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * aoenet.c
4 * Ethernet portion of AoE driver
5 */
6
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/hdreg.h>
9#include <linux/blkdev.h>
10#include <linux/netdevice.h>
Ed L Cashin03c41c42005-04-29 10:24:03 -040011#include <linux/moduleparam.h>
Eric W. Biedermane730c152007-09-17 11:53:39 -070012#include <net/net_namespace.h>
David S. Miller43ecf522007-03-01 18:30:08 -080013#include <asm/unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include "aoe.h"
15
16#define NECODES 5
17
18static char *aoe_errlist[] =
19{
20 "no such error",
21 "unrecognized command code",
22 "bad argument parameter",
23 "device unavailable",
24 "config string present",
25 "unsupported version"
26};
27
28enum {
29 IFLISTSZ = 1024,
30};
31
32static char aoe_iflist[IFLISTSZ];
Ed L Cashin03c41c42005-04-29 10:24:03 -040033module_param_string(aoe_iflist, aoe_iflist, IFLISTSZ, 0600);
Niels de Vos61a2d072008-07-31 00:07:23 -070034MODULE_PARM_DESC(aoe_iflist, "aoe_iflist=\"dev1 [dev2 ...]\"");
Ed L Cashin03c41c42005-04-29 10:24:03 -040035
36#ifndef MODULE
37static int __init aoe_iflist_setup(char *str)
38{
39 strncpy(aoe_iflist, str, IFLISTSZ);
40 aoe_iflist[IFLISTSZ - 1] = '\0';
41 return 1;
42}
43
44__setup("aoe_iflist=", aoe_iflist_setup);
45#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47int
48is_aoe_netif(struct net_device *ifp)
49{
50 register char *p, *q;
51 register int len;
52
53 if (aoe_iflist[0] == '\0')
54 return 1;
55
Ed L Cashin03c41c42005-04-29 10:24:03 -040056 p = aoe_iflist + strspn(aoe_iflist, WHITESPACE);
57 for (; *p; p = q + strspn(q, WHITESPACE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 q = p + strcspn(p, WHITESPACE);
59 if (q != p)
60 len = q - p;
61 else
62 len = strlen(p); /* last token in aoe_iflist */
63
64 if (strlen(ifp->name) == len && !strncmp(ifp->name, p, len))
65 return 1;
66 if (q == p)
67 break;
68 }
69
70 return 0;
71}
72
73int
74set_aoe_iflist(const char __user *user_str, size_t size)
75{
76 if (size >= IFLISTSZ)
77 return -EINVAL;
78
79 if (copy_from_user(aoe_iflist, user_str, size)) {
Ed L. Cashina12c93f2006-09-20 14:36:51 -040080 printk(KERN_INFO "aoe: copy from user failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return -EFAULT;
82 }
83 aoe_iflist[size] = 0x00;
84 return 0;
85}
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087void
David S. Millere9bb8fb2008-09-21 22:36:49 -070088aoenet_xmit(struct sk_buff_head *queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
David S. Millere9bb8fb2008-09-21 22:36:49 -070090 struct sk_buff *skb, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
David S. Millerd8779842008-09-23 20:47:22 -070092 skb_queue_walk_safe(queue, skb, tmp) {
93 __skb_unlink(skb, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 dev_queue_xmit(skb);
David S. Millerd8779842008-09-23 20:47:22 -070095 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
98/*
99 * (1) len doesn't include the header by default. I want this.
100 */
101static int
David S. Millerf2ccd8f2005-08-09 19:34:12 -0700102aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt, struct net_device *orig_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 struct aoe_hdr *h;
ecashin@coraid.com63e9cc52005-04-18 22:00:20 -0700105 u32 n;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +0900107 if (dev_net(ifp) != &init_net)
Eric W. Biedermane730c152007-09-17 11:53:39 -0700108 goto exit;
109
Ed L. Cashin5dc401e2006-02-07 11:26:39 -0500110 skb = skb_share_check(skb, GFP_ATOMIC);
111 if (skb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return 0;
Herbert Xu364c6ba2006-06-09 16:10:40 -0700113 if (skb_linearize(skb))
Ed L. Cashin5dc401e2006-02-07 11:26:39 -0500114 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 if (!is_aoe_netif(ifp))
116 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 skb_push(skb, ETH_HLEN); /* (1) */
118
Ed L. Cashinabdbf942007-10-16 23:27:03 -0700119 h = (struct aoe_hdr *) skb_mac_header(skb);
Harvey Harrisonf885f8d2008-04-29 01:03:30 -0700120 n = get_unaligned_be32(&h->tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
122 goto exit;
123
124 if (h->verfl & AOEFL_ERR) {
125 n = h->err;
126 if (n > NECODES)
127 n = 0;
128 if (net_ratelimit())
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800129 printk(KERN_ERR
130 "%s%d.%d@%s; ecode=%d '%s'\n",
131 "aoe: error packet from ",
Harvey Harrisonf885f8d2008-04-29 01:03:30 -0700132 get_unaligned_be16(&h->major),
Ed L. Cashin68e0d422008-02-08 04:20:00 -0800133 h->minor, skb->dev->name,
134 h->err, aoe_errlist[n]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 goto exit;
136 }
137
138 switch (h->cmd) {
139 case AOECMD_ATA:
140 aoecmd_ata_rsp(skb);
141 break;
142 case AOECMD_CFG:
143 aoecmd_cfg_rsp(skb);
144 break;
145 default:
Ed Cashinb6d6c512009-02-18 14:48:13 -0800146 if (h->cmd >= AOECMD_VEND_MIN)
147 break; /* don't complain about vendor commands */
Ed L. Cashina12c93f2006-09-20 14:36:51 -0400148 printk(KERN_INFO "aoe: unknown cmd %d\n", h->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 }
150exit:
151 dev_kfree_skb(skb);
152 return 0;
153}
154
Stephen Hemminger7546dd92009-03-09 08:18:29 +0000155static struct packet_type aoe_pt __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 .type = __constant_htons(ETH_P_AOE),
157 .func = aoenet_rcv,
158};
159
160int __init
161aoenet_init(void)
162{
163 dev_add_pack(&aoe_pt);
164 return 0;
165}
166
167void
168aoenet_exit(void)
169{
170 dev_remove_pack(&aoe_pt);
171}
172