1 /* Copyright (c) 2013 Coraid, Inc. See COPYING for GPL terms. */
4 * Ethernet portion of AoE driver
8 #include <linux/hdreg.h>
9 #include <linux/blkdev.h>
10 #include <linux/netdevice.h>
11 #include <linux/moduleparam.h>
12 #include <net/net_namespace.h>
13 #include <asm/unaligned.h>
18 static char *aoe_errlist[] =
21 "unrecognized command code",
22 "bad argument parameter",
24 "config string present",
32 static char aoe_iflist[IFLISTSZ];
33 module_param_string(aoe_iflist, aoe_iflist, IFLISTSZ, 0600);
34 MODULE_PARM_DESC(aoe_iflist, "aoe_iflist=dev1[,dev2...]");
36 static wait_queue_head_t txwq;
37 static struct ktstate kts;
40 static int __init aoe_iflist_setup(char *str)
42 strncpy(aoe_iflist, str, IFLISTSZ);
43 aoe_iflist[IFLISTSZ - 1] = '\0';
47 __setup("aoe_iflist=", aoe_iflist_setup);
50 static spinlock_t txlock;
51 static struct sk_buff_head skbtxq;
53 /* enters with txlock held */
55 tx(int id) __must_hold(&txlock)
58 struct net_device *ifp;
60 while ((skb = skb_dequeue(&skbtxq))) {
61 spin_unlock_irq(&txlock);
63 if (dev_queue_xmit(skb) == NET_XMIT_DROP && net_ratelimit())
64 pr_warn("aoe: packet could not be sent on %s. %s\n",
65 ifp ? ifp->name : "netif",
66 "consider increasing tx_queue_len");
68 spin_lock_irq(&txlock);
74 is_aoe_netif(struct net_device *ifp)
79 if (aoe_iflist[0] == '\0')
82 p = aoe_iflist + strspn(aoe_iflist, WHITESPACE);
83 for (; *p; p = q + strspn(q, WHITESPACE)) {
84 q = p + strcspn(p, WHITESPACE);
88 len = strlen(p); /* last token in aoe_iflist */
90 if (strlen(ifp->name) == len && !strncmp(ifp->name, p, len))
100 set_aoe_iflist(const char __user *user_str, size_t size)
102 if (size >= IFLISTSZ)
105 if (copy_from_user(aoe_iflist, user_str, size)) {
106 printk(KERN_INFO "aoe: copy from user failed\n");
109 aoe_iflist[size] = 0x00;
114 aoenet_xmit(struct sk_buff_head *queue)
116 struct sk_buff *skb, *tmp;
119 skb_queue_walk_safe(queue, skb, tmp) {
120 __skb_unlink(skb, queue);
121 spin_lock_irqsave(&txlock, flags);
122 skb_queue_tail(&skbtxq, skb);
123 spin_unlock_irqrestore(&txlock, flags);
129 * (1) len doesn't include the header by default. I want this.
132 aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt, struct net_device *orig_dev)
135 struct aoe_atahdr *ah;
139 if (dev_net(ifp) != &init_net)
142 skb = skb_share_check(skb, GFP_ATOMIC);
145 if (!is_aoe_netif(ifp))
147 skb_push(skb, ETH_HLEN); /* (1) */
148 sn = sizeof(*h) + sizeof(*ah);
149 if (skb->len >= sn) {
150 sn -= skb_headlen(skb);
151 if (sn > 0 && !__pskb_pull_tail(skb, sn))
154 h = (struct aoe_hdr *) skb->data;
155 n = get_unaligned_be32(&h->tag);
156 if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
159 if (h->verfl & AOEFL_ERR) {
165 "%s%d.%d@%s; ecode=%d '%s'\n",
166 "aoe: error packet from ",
167 get_unaligned_be16(&h->major),
168 h->minor, skb->dev->name,
169 h->err, aoe_errlist[n]);
175 /* ata_rsp may keep skb for later processing or give it back */
176 skb = aoecmd_ata_rsp(skb);
182 if (h->cmd >= AOECMD_VEND_MIN)
183 break; /* don't complain about vendor commands */
184 pr_info("aoe: unknown AoE command type 0x%02x\n", h->cmd);
195 static struct packet_type aoe_pt __read_mostly = {
196 .type = __constant_htons(ETH_P_AOE),
203 skb_queue_head_init(&skbtxq);
204 init_waitqueue_head(&txwq);
205 spin_lock_init(&txlock);
210 snprintf(kts.name, sizeof(kts.name), "aoe_tx%d", kts.id);
211 if (aoe_ktstart(&kts))
213 dev_add_pack(&aoe_pt);
221 skb_queue_purge(&skbtxq);
222 dev_remove_pack(&aoe_pt);