1 /* Copyright (c) 2006 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 <asm/unaligned.h>
16 static char *aoe_errlist[] =
19 "unrecognized command code",
20 "bad argument parameter",
22 "config string present",
30 static char aoe_iflist[IFLISTSZ];
31 module_param_string(aoe_iflist, aoe_iflist, IFLISTSZ, 0600);
32 MODULE_PARM_DESC(aoe_iflist, "aoe_iflist=\"dev1 [dev2 ...]\"\n");
35 static int __init aoe_iflist_setup(char *str)
37 strncpy(aoe_iflist, str, IFLISTSZ);
38 aoe_iflist[IFLISTSZ - 1] = '\0';
42 __setup("aoe_iflist=", aoe_iflist_setup);
46 is_aoe_netif(struct net_device *ifp)
51 if (aoe_iflist[0] == '\0')
54 p = aoe_iflist + strspn(aoe_iflist, WHITESPACE);
55 for (; *p; p = q + strspn(q, WHITESPACE)) {
56 q = p + strcspn(p, WHITESPACE);
60 len = strlen(p); /* last token in aoe_iflist */
62 if (strlen(ifp->name) == len && !strncmp(ifp->name, p, len))
72 set_aoe_iflist(const char __user *user_str, size_t size)
77 if (copy_from_user(aoe_iflist, user_str, size)) {
78 printk(KERN_INFO "aoe: copy from user failed\n");
81 aoe_iflist[size] = 0x00;
86 mac_addr(char addr[6])
89 char *p = (char *) &n;
91 memcpy(p + 2, addr, 6); /* (sizeof addr != 6) */
93 return __be64_to_cpu(n);
97 aoenet_xmit(struct sk_buff *sl)
103 skb->next = skb->prev = NULL;
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 skb = skb_share_check(skb, GFP_ATOMIC);
120 if (skb_linearize(skb))
122 if (!is_aoe_netif(ifp))
124 skb_push(skb, ETH_HLEN); /* (1) */
127 n = be32_to_cpu(get_unaligned(&h->tag));
128 if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
131 if (h->verfl & AOEFL_ERR) {
136 printk(KERN_ERR "aoe: error packet from %d.%d; ecode=%d '%s'\n",
137 be16_to_cpu(get_unaligned(&h->major)), h->minor,
138 h->err, aoe_errlist[n]);
150 printk(KERN_INFO "aoe: unknown cmd %d\n", h->cmd);
157 static struct packet_type aoe_pt = {
158 .type = __constant_htons(ETH_P_AOE),
165 dev_add_pack(&aoe_pt);
172 dev_remove_pack(&aoe_pt);