[PATCH] aoe [1/3]: support multiple AoE listeners
[linux-2.6.22.y-op.git] / drivers / block / aoe / aoenet.c
blobfdff774b8ab944421ad0190486e98cc4c5f458a5
1 /* Copyright (c) 2004 Coraid, Inc. See COPYING for GPL terms. */
2 /*
3 * aoenet.c
4 * Ethernet portion of AoE driver
5 */
7 #include <linux/hdreg.h>
8 #include <linux/blkdev.h>
9 #include <linux/netdevice.h>
10 #include <linux/moduleparam.h>
11 #include "aoe.h"
13 #define NECODES 5
15 static char *aoe_errlist[] =
17 "no such error",
18 "unrecognized command code",
19 "bad argument parameter",
20 "device unavailable",
21 "config string present",
22 "unsupported version"
25 enum {
26 IFLISTSZ = 1024,
29 static char aoe_iflist[IFLISTSZ];
30 module_param_string(aoe_iflist, aoe_iflist, IFLISTSZ, 0600);
31 MODULE_PARM_DESC(aoe_iflist, "aoe_iflist=\"dev1 [dev2 ...]\"\n");
33 #ifndef MODULE
34 static int __init aoe_iflist_setup(char *str)
36 strncpy(aoe_iflist, str, IFLISTSZ);
37 aoe_iflist[IFLISTSZ - 1] = '\0';
38 return 1;
41 __setup("aoe_iflist=", aoe_iflist_setup);
42 #endif
44 int
45 is_aoe_netif(struct net_device *ifp)
47 register char *p, *q;
48 register int len;
50 if (aoe_iflist[0] == '\0')
51 return 1;
53 p = aoe_iflist + strspn(aoe_iflist, WHITESPACE);
54 for (; *p; p = q + strspn(q, WHITESPACE)) {
55 q = p + strcspn(p, WHITESPACE);
56 if (q != p)
57 len = q - p;
58 else
59 len = strlen(p); /* last token in aoe_iflist */
61 if (strlen(ifp->name) == len && !strncmp(ifp->name, p, len))
62 return 1;
63 if (q == p)
64 break;
67 return 0;
70 int
71 set_aoe_iflist(const char __user *user_str, size_t size)
73 if (size >= IFLISTSZ)
74 return -EINVAL;
76 if (copy_from_user(aoe_iflist, user_str, size)) {
77 printk(KERN_INFO "aoe: %s: copy from user failed\n", __FUNCTION__);
78 return -EFAULT;
80 aoe_iflist[size] = 0x00;
81 return 0;
84 u64
85 mac_addr(char addr[6])
87 __be64 n = 0;
88 char *p = (char *) &n;
90 memcpy(p + 2, addr, 6); /* (sizeof addr != 6) */
92 return __be64_to_cpu(n);
95 void
96 aoenet_xmit(struct sk_buff *sl)
98 struct sk_buff *skb;
100 while ((skb = sl)) {
101 sl = sl->next;
102 skb->next = skb->prev = NULL;
103 dev_queue_xmit(skb);
108 * (1) len doesn't include the header by default. I want this.
110 static int
111 aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt, struct net_device *orig_dev)
113 struct aoe_hdr *h;
114 u32 n;
116 skb = skb_share_check(skb, GFP_ATOMIC);
117 if (skb == NULL)
118 return 0;
119 if (skb_is_nonlinear(skb))
120 if (skb_linearize(skb, GFP_ATOMIC) < 0)
121 goto exit;
122 if (!is_aoe_netif(ifp))
123 goto exit;
124 skb_push(skb, ETH_HLEN); /* (1) */
126 h = (struct aoe_hdr *) skb->mac.raw;
127 n = be32_to_cpu(h->tag);
128 if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
129 goto exit;
131 if (h->verfl & AOEFL_ERR) {
132 n = h->err;
133 if (n > NECODES)
134 n = 0;
135 if (net_ratelimit())
136 printk(KERN_ERR "aoe: aoenet_rcv: error packet from %d.%d; "
137 "ecode=%d '%s'\n",
138 be16_to_cpu(h->major), h->minor,
139 h->err, aoe_errlist[n]);
140 goto exit;
143 switch (h->cmd) {
144 case AOECMD_ATA:
145 aoecmd_ata_rsp(skb);
146 break;
147 case AOECMD_CFG:
148 aoecmd_cfg_rsp(skb);
149 break;
150 default:
151 printk(KERN_INFO "aoe: aoenet_rcv: unknown cmd %d\n", h->cmd);
153 exit:
154 dev_kfree_skb(skb);
155 return 0;
158 static struct packet_type aoe_pt = {
159 .type = __constant_htons(ETH_P_AOE),
160 .func = aoenet_rcv,
163 int __init
164 aoenet_init(void)
166 dev_add_pack(&aoe_pt);
167 return 0;
170 void
171 aoenet_exit(void)
173 dev_remove_pack(&aoe_pt);