diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/block/aoe/aoenet.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/block/aoe/aoenet.c')
-rw-r--r-- | drivers/block/aoe/aoenet.c | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/drivers/block/aoe/aoenet.c b/drivers/block/aoe/aoenet.c new file mode 100644 index 000000000000..cc1945b8d52b --- /dev/null +++ b/drivers/block/aoe/aoenet.c | |||
@@ -0,0 +1,172 @@ | |||
1 | /* Copyright (c) 2004 Coraid, Inc. See COPYING for GPL terms. */ | ||
2 | /* | ||
3 | * aoenet.c | ||
4 | * Ethernet portion of AoE driver | ||
5 | */ | ||
6 | |||
7 | #include <linux/hdreg.h> | ||
8 | #include <linux/blkdev.h> | ||
9 | #include <linux/netdevice.h> | ||
10 | #include "aoe.h" | ||
11 | |||
12 | #define NECODES 5 | ||
13 | |||
14 | static char *aoe_errlist[] = | ||
15 | { | ||
16 | "no such error", | ||
17 | "unrecognized command code", | ||
18 | "bad argument parameter", | ||
19 | "device unavailable", | ||
20 | "config string present", | ||
21 | "unsupported version" | ||
22 | }; | ||
23 | |||
24 | enum { | ||
25 | IFLISTSZ = 1024, | ||
26 | }; | ||
27 | |||
28 | static char aoe_iflist[IFLISTSZ]; | ||
29 | |||
30 | int | ||
31 | is_aoe_netif(struct net_device *ifp) | ||
32 | { | ||
33 | register char *p, *q; | ||
34 | register int len; | ||
35 | |||
36 | if (aoe_iflist[0] == '\0') | ||
37 | return 1; | ||
38 | |||
39 | for (p = aoe_iflist; *p; p = q + strspn(q, WHITESPACE)) { | ||
40 | q = p + strcspn(p, WHITESPACE); | ||
41 | if (q != p) | ||
42 | len = q - p; | ||
43 | else | ||
44 | len = strlen(p); /* last token in aoe_iflist */ | ||
45 | |||
46 | if (strlen(ifp->name) == len && !strncmp(ifp->name, p, len)) | ||
47 | return 1; | ||
48 | if (q == p) | ||
49 | break; | ||
50 | } | ||
51 | |||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | int | ||
56 | set_aoe_iflist(const char __user *user_str, size_t size) | ||
57 | { | ||
58 | if (size >= IFLISTSZ) | ||
59 | return -EINVAL; | ||
60 | |||
61 | if (copy_from_user(aoe_iflist, user_str, size)) { | ||
62 | printk(KERN_INFO "aoe: %s: copy from user failed\n", __FUNCTION__); | ||
63 | return -EFAULT; | ||
64 | } | ||
65 | aoe_iflist[size] = 0x00; | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | u64 | ||
70 | mac_addr(char addr[6]) | ||
71 | { | ||
72 | u64 n = 0; | ||
73 | char *p = (char *) &n; | ||
74 | |||
75 | memcpy(p + 2, addr, 6); /* (sizeof addr != 6) */ | ||
76 | |||
77 | return __be64_to_cpu(n); | ||
78 | } | ||
79 | |||
80 | static struct sk_buff * | ||
81 | skb_check(struct sk_buff *skb) | ||
82 | { | ||
83 | if (skb_is_nonlinear(skb)) | ||
84 | if ((skb = skb_share_check(skb, GFP_ATOMIC))) | ||
85 | if (skb_linearize(skb, GFP_ATOMIC) < 0) { | ||
86 | dev_kfree_skb(skb); | ||
87 | return NULL; | ||
88 | } | ||
89 | return skb; | ||
90 | } | ||
91 | |||
92 | void | ||
93 | aoenet_xmit(struct sk_buff *sl) | ||
94 | { | ||
95 | struct sk_buff *skb; | ||
96 | |||
97 | while ((skb = sl)) { | ||
98 | sl = sl->next; | ||
99 | skb->next = skb->prev = NULL; | ||
100 | dev_queue_xmit(skb); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | /* | ||
105 | * (1) len doesn't include the header by default. I want this. | ||
106 | */ | ||
107 | static int | ||
108 | aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt) | ||
109 | { | ||
110 | struct aoe_hdr *h; | ||
111 | ulong n; | ||
112 | |||
113 | skb = skb_check(skb); | ||
114 | if (!skb) | ||
115 | return 0; | ||
116 | |||
117 | if (!is_aoe_netif(ifp)) | ||
118 | goto exit; | ||
119 | |||
120 | //skb->len += ETH_HLEN; /* (1) */ | ||
121 | skb_push(skb, ETH_HLEN); /* (1) */ | ||
122 | |||
123 | h = (struct aoe_hdr *) skb->mac.raw; | ||
124 | n = __be32_to_cpu(*((u32 *) h->tag)); | ||
125 | if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31)) | ||
126 | goto exit; | ||
127 | |||
128 | if (h->verfl & AOEFL_ERR) { | ||
129 | n = h->err; | ||
130 | if (n > NECODES) | ||
131 | n = 0; | ||
132 | if (net_ratelimit()) | ||
133 | printk(KERN_ERR "aoe: aoenet_rcv: error packet from %d.%d; " | ||
134 | "ecode=%d '%s'\n", | ||
135 | __be16_to_cpu(*((u16 *) h->major)), h->minor, | ||
136 | h->err, aoe_errlist[n]); | ||
137 | goto exit; | ||
138 | } | ||
139 | |||
140 | switch (h->cmd) { | ||
141 | case AOECMD_ATA: | ||
142 | aoecmd_ata_rsp(skb); | ||
143 | break; | ||
144 | case AOECMD_CFG: | ||
145 | aoecmd_cfg_rsp(skb); | ||
146 | break; | ||
147 | default: | ||
148 | printk(KERN_INFO "aoe: aoenet_rcv: unknown cmd %d\n", h->cmd); | ||
149 | } | ||
150 | exit: | ||
151 | dev_kfree_skb(skb); | ||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | static struct packet_type aoe_pt = { | ||
156 | .type = __constant_htons(ETH_P_AOE), | ||
157 | .func = aoenet_rcv, | ||
158 | }; | ||
159 | |||
160 | int __init | ||
161 | aoenet_init(void) | ||
162 | { | ||
163 | dev_add_pack(&aoe_pt); | ||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | void | ||
168 | aoenet_exit(void) | ||
169 | { | ||
170 | dev_remove_pack(&aoe_pt); | ||
171 | } | ||
172 | |||