1 /* Copyright (c) 2004 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>
15 static char *aoe_errlist
[] =
18 "unrecognized command code",
19 "bad argument parameter",
21 "config string present",
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");
34 static int __init
aoe_iflist_setup(char *str
)
36 strncpy(aoe_iflist
, str
, IFLISTSZ
);
37 aoe_iflist
[IFLISTSZ
- 1] = '\0';
41 __setup("aoe_iflist=", aoe_iflist_setup
);
45 is_aoe_netif(struct net_device
*ifp
)
50 if (aoe_iflist
[0] == '\0')
53 p
= aoe_iflist
+ strspn(aoe_iflist
, WHITESPACE
);
54 for (; *p
; p
= q
+ strspn(q
, WHITESPACE
)) {
55 q
= p
+ strcspn(p
, WHITESPACE
);
59 len
= strlen(p
); /* last token in aoe_iflist */
61 if (strlen(ifp
->name
) == len
&& !strncmp(ifp
->name
, p
, len
))
71 set_aoe_iflist(const char __user
*user_str
, size_t size
)
76 if (copy_from_user(aoe_iflist
, user_str
, size
)) {
77 printk(KERN_INFO
"aoe: %s: copy from user failed\n", __FUNCTION__
);
80 aoe_iflist
[size
] = 0x00;
85 mac_addr(char addr
[6])
88 char *p
= (char *) &n
;
90 memcpy(p
+ 2, addr
, 6); /* (sizeof addr != 6) */
92 return __be64_to_cpu(n
);
96 aoenet_xmit(struct sk_buff
*sl
)
102 skb
->next
= skb
->prev
= NULL
;
108 * (1) len doesn't include the header by default. I want this.
111 aoenet_rcv(struct sk_buff
*skb
, struct net_device
*ifp
, struct packet_type
*pt
, struct net_device
*orig_dev
)
116 skb
= skb_share_check(skb
, GFP_ATOMIC
);
119 if (skb_is_nonlinear(skb
))
120 if (skb_linearize(skb
, GFP_ATOMIC
) < 0)
122 if (!is_aoe_netif(ifp
))
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))
131 if (h
->verfl
& AOEFL_ERR
) {
136 printk(KERN_ERR
"aoe: aoenet_rcv: error packet from %d.%d; "
138 be16_to_cpu(h
->major
), h
->minor
,
139 h
->err
, aoe_errlist
[n
]);
151 printk(KERN_INFO
"aoe: aoenet_rcv: unknown cmd %d\n", h
->cmd
);
158 static struct packet_type aoe_pt
= {
159 .type
= __constant_htons(ETH_P_AOE
),
166 dev_add_pack(&aoe_pt
);
173 dev_remove_pack(&aoe_pt
);