2013-07-03 15:09:06 -07:00
|
|
|
/* Copyright (c) 2013 Coraid, Inc. See COPYING for GPL terms. */
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
|
* aoenet.c
|
|
|
|
|
* Ethernet portion of AoE driver
|
|
|
|
|
*/
|
|
|
|
|
|
2010-03-24 17:04:11 +09:00
|
|
|
#include <linux/gfp.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/hdreg.h>
|
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
|
#include <linux/netdevice.h>
|
2005-04-29 10:24:03 -04:00
|
|
|
#include <linux/moduleparam.h>
|
2007-09-17 11:53:39 -07:00
|
|
|
#include <net/net_namespace.h>
|
2007-03-01 18:30:08 -08:00
|
|
|
#include <asm/unaligned.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include "aoe.h"
|
|
|
|
|
|
|
|
|
|
#define NECODES 5
|
|
|
|
|
|
|
|
|
|
static char *aoe_errlist[] =
|
|
|
|
|
{
|
|
|
|
|
"no such error",
|
|
|
|
|
"unrecognized command code",
|
|
|
|
|
"bad argument parameter",
|
|
|
|
|
"device unavailable",
|
|
|
|
|
"config string present",
|
|
|
|
|
"unsupported version"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
IFLISTSZ = 1024,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static char aoe_iflist[IFLISTSZ];
|
2005-04-29 10:24:03 -04:00
|
|
|
module_param_string(aoe_iflist, aoe_iflist, IFLISTSZ, 0600);
|
2012-12-17 16:04:15 -08:00
|
|
|
MODULE_PARM_DESC(aoe_iflist, "aoe_iflist=dev1[,dev2...]");
|
2005-04-29 10:24:03 -04:00
|
|
|
|
2012-10-04 17:16:25 -07:00
|
|
|
static wait_queue_head_t txwq;
|
|
|
|
|
static struct ktstate kts;
|
|
|
|
|
|
2005-04-29 10:24:03 -04:00
|
|
|
#ifndef MODULE
|
|
|
|
|
static int __init aoe_iflist_setup(char *str)
|
|
|
|
|
{
|
|
|
|
|
strncpy(aoe_iflist, str, IFLISTSZ);
|
|
|
|
|
aoe_iflist[IFLISTSZ - 1] = '\0';
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__setup("aoe_iflist=", aoe_iflist_setup);
|
|
|
|
|
#endif
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2012-10-04 17:16:25 -07:00
|
|
|
static spinlock_t txlock;
|
|
|
|
|
static struct sk_buff_head skbtxq;
|
|
|
|
|
|
|
|
|
|
/* enters with txlock held */
|
|
|
|
|
static int
|
2013-07-03 15:09:05 -07:00
|
|
|
tx(int id) __must_hold(&txlock)
|
2012-10-04 17:16:25 -07:00
|
|
|
{
|
|
|
|
|
struct sk_buff *skb;
|
2012-12-17 16:03:28 -08:00
|
|
|
struct net_device *ifp;
|
2012-10-04 17:16:25 -07:00
|
|
|
|
|
|
|
|
while ((skb = skb_dequeue(&skbtxq))) {
|
|
|
|
|
spin_unlock_irq(&txlock);
|
2012-12-17 16:03:28 -08:00
|
|
|
ifp = skb->dev;
|
|
|
|
|
if (dev_queue_xmit(skb) == NET_XMIT_DROP && net_ratelimit())
|
|
|
|
|
pr_warn("aoe: packet could not be sent on %s. %s\n",
|
|
|
|
|
ifp ? ifp->name : "netif",
|
|
|
|
|
"consider increasing tx_queue_len");
|
2012-10-04 17:16:25 -07:00
|
|
|
spin_lock_irq(&txlock);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
int
|
|
|
|
|
is_aoe_netif(struct net_device *ifp)
|
|
|
|
|
{
|
|
|
|
|
register char *p, *q;
|
|
|
|
|
register int len;
|
|
|
|
|
|
|
|
|
|
if (aoe_iflist[0] == '\0')
|
|
|
|
|
return 1;
|
|
|
|
|
|
2005-04-29 10:24:03 -04:00
|
|
|
p = aoe_iflist + strspn(aoe_iflist, WHITESPACE);
|
|
|
|
|
for (; *p; p = q + strspn(q, WHITESPACE)) {
|
2005-04-16 15:20:36 -07:00
|
|
|
q = p + strcspn(p, WHITESPACE);
|
|
|
|
|
if (q != p)
|
|
|
|
|
len = q - p;
|
|
|
|
|
else
|
|
|
|
|
len = strlen(p); /* last token in aoe_iflist */
|
|
|
|
|
|
|
|
|
|
if (strlen(ifp->name) == len && !strncmp(ifp->name, p, len))
|
|
|
|
|
return 1;
|
|
|
|
|
if (q == p)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
set_aoe_iflist(const char __user *user_str, size_t size)
|
|
|
|
|
{
|
|
|
|
|
if (size >= IFLISTSZ)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
if (copy_from_user(aoe_iflist, user_str, size)) {
|
2006-09-20 14:36:51 -04:00
|
|
|
printk(KERN_INFO "aoe: copy from user failed\n");
|
2005-04-16 15:20:36 -07:00
|
|
|
return -EFAULT;
|
|
|
|
|
}
|
|
|
|
|
aoe_iflist[size] = 0x00;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2008-09-21 22:36:49 -07:00
|
|
|
aoenet_xmit(struct sk_buff_head *queue)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2008-09-21 22:36:49 -07:00
|
|
|
struct sk_buff *skb, *tmp;
|
2012-10-04 17:16:25 -07:00
|
|
|
ulong flags;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-09-23 20:47:22 -07:00
|
|
|
skb_queue_walk_safe(queue, skb, tmp) {
|
|
|
|
|
__skb_unlink(skb, queue);
|
2012-10-04 17:16:25 -07:00
|
|
|
spin_lock_irqsave(&txlock, flags);
|
|
|
|
|
skb_queue_tail(&skbtxq, skb);
|
|
|
|
|
spin_unlock_irqrestore(&txlock, flags);
|
|
|
|
|
wake_up(&txwq);
|
2008-09-23 20:47:22 -07:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
2012-12-17 16:03:39 -08:00
|
|
|
/*
|
|
|
|
|
* (1) len doesn't include the header by default. I want this.
|
2005-04-16 15:20:36 -07:00
|
|
|
*/
|
|
|
|
|
static int
|
2005-08-09 19:34:12 -07:00
|
|
|
aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt, struct net_device *orig_dev)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
|
struct aoe_hdr *h;
|
2012-10-04 17:16:20 -07:00
|
|
|
struct aoe_atahdr *ah;
|
2005-04-18 22:00:20 -07:00
|
|
|
u32 n;
|
2012-10-04 17:16:20 -07:00
|
|
|
int sn;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-03-25 21:47:49 +09:00
|
|
|
if (dev_net(ifp) != &init_net)
|
2007-09-17 11:53:39 -07:00
|
|
|
goto exit;
|
|
|
|
|
|
2006-02-07 11:26:39 -05:00
|
|
|
skb = skb_share_check(skb, GFP_ATOMIC);
|
|
|
|
|
if (skb == NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
|
if (!is_aoe_netif(ifp))
|
|
|
|
|
goto exit;
|
|
|
|
|
skb_push(skb, ETH_HLEN); /* (1) */
|
2012-10-04 17:16:20 -07:00
|
|
|
sn = sizeof(*h) + sizeof(*ah);
|
|
|
|
|
if (skb->len >= sn) {
|
|
|
|
|
sn -= skb_headlen(skb);
|
|
|
|
|
if (sn > 0 && !__pskb_pull_tail(skb, sn))
|
|
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
h = (struct aoe_hdr *) skb->data;
|
2008-04-29 01:03:30 -07:00
|
|
|
n = get_unaligned_be32(&h->tag);
|
2005-04-16 15:20:36 -07:00
|
|
|
if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
|
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
|
|
if (h->verfl & AOEFL_ERR) {
|
|
|
|
|
n = h->err;
|
|
|
|
|
if (n > NECODES)
|
|
|
|
|
n = 0;
|
|
|
|
|
if (net_ratelimit())
|
2008-02-08 04:20:00 -08:00
|
|
|
printk(KERN_ERR
|
|
|
|
|
"%s%d.%d@%s; ecode=%d '%s'\n",
|
|
|
|
|
"aoe: error packet from ",
|
2008-04-29 01:03:30 -07:00
|
|
|
get_unaligned_be16(&h->major),
|
2008-02-08 04:20:00 -08:00
|
|
|
h->minor, skb->dev->name,
|
|
|
|
|
h->err, aoe_errlist[n]);
|
2005-04-16 15:20:36 -07:00
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (h->cmd) {
|
|
|
|
|
case AOECMD_ATA:
|
2012-10-04 17:16:21 -07:00
|
|
|
/* ata_rsp may keep skb for later processing or give it back */
|
|
|
|
|
skb = aoecmd_ata_rsp(skb);
|
2005-04-16 15:20:36 -07:00
|
|
|
break;
|
|
|
|
|
case AOECMD_CFG:
|
|
|
|
|
aoecmd_cfg_rsp(skb);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2009-02-18 14:48:13 -08:00
|
|
|
if (h->cmd >= AOECMD_VEND_MIN)
|
|
|
|
|
break; /* don't complain about vendor commands */
|
2012-10-04 17:16:35 -07:00
|
|
|
pr_info("aoe: unknown AoE command type 0x%02x\n", h->cmd);
|
|
|
|
|
break;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2012-10-04 17:16:21 -07:00
|
|
|
|
|
|
|
|
if (!skb)
|
|
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
exit:
|
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 08:18:29 +00:00
|
|
|
static struct packet_type aoe_pt __read_mostly = {
|
2005-04-16 15:20:36 -07:00
|
|
|
.type = __constant_htons(ETH_P_AOE),
|
|
|
|
|
.func = aoenet_rcv,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int __init
|
|
|
|
|
aoenet_init(void)
|
|
|
|
|
{
|
2012-10-04 17:16:25 -07:00
|
|
|
skb_queue_head_init(&skbtxq);
|
|
|
|
|
init_waitqueue_head(&txwq);
|
|
|
|
|
spin_lock_init(&txlock);
|
|
|
|
|
kts.lock = &txlock;
|
|
|
|
|
kts.fn = tx;
|
|
|
|
|
kts.waitq = &txwq;
|
2013-07-03 15:09:05 -07:00
|
|
|
kts.id = 0;
|
|
|
|
|
snprintf(kts.name, sizeof(kts.name), "aoe_tx%d", kts.id);
|
2012-10-04 17:16:25 -07:00
|
|
|
if (aoe_ktstart(&kts))
|
|
|
|
|
return -EAGAIN;
|
2005-04-16 15:20:36 -07:00
|
|
|
dev_add_pack(&aoe_pt);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
aoenet_exit(void)
|
|
|
|
|
{
|
2012-10-04 17:16:25 -07:00
|
|
|
aoe_ktstop(&kts);
|
|
|
|
|
skb_queue_purge(&skbtxq);
|
2005-04-16 15:20:36 -07:00
|
|
|
dev_remove_pack(&aoe_pt);
|
|
|
|
|
}
|
|
|
|
|
|