1 /* Copyright (c) 2007 Coraid, Inc. See COPYING for GPL terms. */
4 * Ethernet portion of AoE driver
7 #include <linux/hdreg.h>
8 #include <linux/blkdev.h>
9 #include <linux/netdevice.h>
10 #include <linux/moduleparam.h>
11 #include <net/net_namespace.h>
12 #include <asm/unaligned.h>
17 static char *aoe_errlist[] =
20 "unrecognized command code",
21 "bad argument parameter",
23 "config string present",
31 static char aoe_iflist[IFLISTSZ];
32 module_param_string(aoe_iflist, aoe_iflist, IFLISTSZ, 0600);
33 MODULE_PARM_DESC(aoe_iflist, "aoe_iflist=\"dev1 [dev2 ...]\"");
36 static int __init aoe_iflist_setup(char *str)
38 strncpy(aoe_iflist, str, IFLISTSZ);
39 aoe_iflist[IFLISTSZ - 1] = '\0';
43 __setup("aoe_iflist=", aoe_iflist_setup);
47 is_aoe_netif(struct net_device *ifp)
52 if (aoe_iflist[0] == '\0')
55 p = aoe_iflist + strspn(aoe_iflist, WHITESPACE);
56 for (; *p; p = q + strspn(q, WHITESPACE)) {
57 q = p + strcspn(p, WHITESPACE);
61 len = strlen(p); /* last token in aoe_iflist */
63 if (strlen(ifp->name) == len && !strncmp(ifp->name, p, len))
73 set_aoe_iflist(const char __user *user_str, size_t size)
78 if (copy_from_user(aoe_iflist, user_str, size)) {
79 printk(KERN_INFO "aoe: copy from user failed\n");
82 aoe_iflist[size] = 0x00;
87 mac_addr(char addr[6])
90 char *p = (char *) &n;
92 memcpy(p + 2, addr, 6); /* (sizeof addr != 6) */
94 return (unsigned long long) __be64_to_cpu(n);
98 aoenet_xmit(struct sk_buff_head *queue)
100 struct sk_buff *skb, *tmp;
102 skb_queue_walk_safe(queue, skb, tmp) {
103 __skb_unlink(skb, queue);
109 * (1) len doesn't include the header by default. I want this.
112 aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt, struct net_device *orig_dev)
117 if (dev_net(ifp) != &init_net)
120 skb = skb_share_check(skb, GFP_ATOMIC);
123 if (skb_linearize(skb))
125 if (!is_aoe_netif(ifp))
127 skb_push(skb, ETH_HLEN); /* (1) */
129 h = (struct aoe_hdr *) skb_mac_header(skb);
130 n = get_unaligned_be32(&h->tag);
131 if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
134 if (h->verfl & AOEFL_ERR) {
140 "%s%d.%d@%s; ecode=%d '%s'\n",
141 "aoe: error packet from ",
142 get_unaligned_be16(&h->major),
143 h->minor, skb->dev->name,
144 h->err, aoe_errlist[n]);
156 printk(KERN_INFO "aoe: unknown cmd %d\n", h->cmd);
163 static struct packet_type aoe_pt = {
164 .type = __constant_htons(ETH_P_AOE),
171 dev_add_pack(&aoe_pt);
178 dev_remove_pack(&aoe_pt);