Ed L. Cashin | 52e112b | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2007 Coraid, Inc. See COPYING for GPL terms. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Ed L Cashin | 03c41c4 | 2005-04-29 10:24:03 -0400 | [diff] [blame] | 10 | #include <linux/moduleparam.h> |
Eric W. Biederman | e730c15 | 2007-09-17 11:53:39 -0700 | [diff] [blame] | 11 | #include <net/net_namespace.h> |
David S. Miller | 43ecf52 | 2007-03-01 18:30:08 -0800 | [diff] [blame] | 12 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "aoe.h" |
| 14 | |
| 15 | #define NECODES 5 |
| 16 | |
| 17 | static char *aoe_errlist[] = |
| 18 | { |
| 19 | "no such error", |
| 20 | "unrecognized command code", |
| 21 | "bad argument parameter", |
| 22 | "device unavailable", |
| 23 | "config string present", |
| 24 | "unsupported version" |
| 25 | }; |
| 26 | |
| 27 | enum { |
| 28 | IFLISTSZ = 1024, |
| 29 | }; |
| 30 | |
| 31 | static char aoe_iflist[IFLISTSZ]; |
Ed L Cashin | 03c41c4 | 2005-04-29 10:24:03 -0400 | [diff] [blame] | 32 | module_param_string(aoe_iflist, aoe_iflist, IFLISTSZ, 0600); |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 33 | MODULE_PARM_DESC(aoe_iflist, "aoe_iflist=\"dev1 [dev2 ...]\""); |
Ed L Cashin | 03c41c4 | 2005-04-29 10:24:03 -0400 | [diff] [blame] | 34 | |
| 35 | #ifndef MODULE |
| 36 | static int __init aoe_iflist_setup(char *str) |
| 37 | { |
| 38 | strncpy(aoe_iflist, str, IFLISTSZ); |
| 39 | aoe_iflist[IFLISTSZ - 1] = '\0'; |
| 40 | return 1; |
| 41 | } |
| 42 | |
| 43 | __setup("aoe_iflist=", aoe_iflist_setup); |
| 44 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | int |
| 47 | is_aoe_netif(struct net_device *ifp) |
| 48 | { |
| 49 | register char *p, *q; |
| 50 | register int len; |
| 51 | |
| 52 | if (aoe_iflist[0] == '\0') |
| 53 | return 1; |
| 54 | |
Ed L Cashin | 03c41c4 | 2005-04-29 10:24:03 -0400 | [diff] [blame] | 55 | p = aoe_iflist + strspn(aoe_iflist, WHITESPACE); |
| 56 | for (; *p; p = q + strspn(q, WHITESPACE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | q = p + strcspn(p, WHITESPACE); |
| 58 | if (q != p) |
| 59 | len = q - p; |
| 60 | else |
| 61 | len = strlen(p); /* last token in aoe_iflist */ |
| 62 | |
| 63 | if (strlen(ifp->name) == len && !strncmp(ifp->name, p, len)) |
| 64 | return 1; |
| 65 | if (q == p) |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | int |
| 73 | set_aoe_iflist(const char __user *user_str, size_t size) |
| 74 | { |
| 75 | if (size >= IFLISTSZ) |
| 76 | return -EINVAL; |
| 77 | |
| 78 | if (copy_from_user(aoe_iflist, user_str, size)) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 79 | printk(KERN_INFO "aoe: copy from user failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return -EFAULT; |
| 81 | } |
| 82 | aoe_iflist[size] = 0x00; |
| 83 | return 0; |
| 84 | } |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | void |
David S. Miller | e9bb8fb0 | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 87 | aoenet_xmit(struct sk_buff_head *queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
David S. Miller | e9bb8fb0 | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 89 | struct sk_buff *skb, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
David S. Miller | d877984 | 2008-09-23 20:47:22 -0700 | [diff] [blame] | 91 | skb_queue_walk_safe(queue, skb, tmp) { |
| 92 | __skb_unlink(skb, queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | dev_queue_xmit(skb); |
David S. Miller | d877984 | 2008-09-23 20:47:22 -0700 | [diff] [blame] | 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* |
| 98 | * (1) len doesn't include the header by default. I want this. |
| 99 | */ |
| 100 | static int |
David S. Miller | f2ccd8f | 2005-08-09 19:34:12 -0700 | [diff] [blame] | 101 | aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt, struct net_device *orig_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | struct aoe_hdr *h; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 104 | u32 n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 106 | if (dev_net(ifp) != &init_net) |
Eric W. Biederman | e730c15 | 2007-09-17 11:53:39 -0700 | [diff] [blame] | 107 | goto exit; |
| 108 | |
Ed L. Cashin | 5dc401e | 2006-02-07 11:26:39 -0500 | [diff] [blame] | 109 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 110 | if (skb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | return 0; |
Herbert Xu | 364c6ba | 2006-06-09 16:10:40 -0700 | [diff] [blame] | 112 | if (skb_linearize(skb)) |
Ed L. Cashin | 5dc401e | 2006-02-07 11:26:39 -0500 | [diff] [blame] | 113 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | if (!is_aoe_netif(ifp)) |
| 115 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | skb_push(skb, ETH_HLEN); /* (1) */ |
| 117 | |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 118 | h = (struct aoe_hdr *) skb_mac_header(skb); |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 119 | n = get_unaligned_be32(&h->tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31)) |
| 121 | goto exit; |
| 122 | |
| 123 | if (h->verfl & AOEFL_ERR) { |
| 124 | n = h->err; |
| 125 | if (n > NECODES) |
| 126 | n = 0; |
| 127 | if (net_ratelimit()) |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 128 | printk(KERN_ERR |
| 129 | "%s%d.%d@%s; ecode=%d '%s'\n", |
| 130 | "aoe: error packet from ", |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 131 | get_unaligned_be16(&h->major), |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 132 | h->minor, skb->dev->name, |
| 133 | h->err, aoe_errlist[n]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | goto exit; |
| 135 | } |
| 136 | |
| 137 | switch (h->cmd) { |
| 138 | case AOECMD_ATA: |
| 139 | aoecmd_ata_rsp(skb); |
| 140 | break; |
| 141 | case AOECMD_CFG: |
| 142 | aoecmd_cfg_rsp(skb); |
| 143 | break; |
| 144 | default: |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 145 | printk(KERN_INFO "aoe: unknown cmd %d\n", h->cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | exit: |
| 148 | dev_kfree_skb(skb); |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static struct packet_type aoe_pt = { |
| 153 | .type = __constant_htons(ETH_P_AOE), |
| 154 | .func = aoenet_rcv, |
| 155 | }; |
| 156 | |
| 157 | int __init |
| 158 | aoenet_init(void) |
| 159 | { |
| 160 | dev_add_pack(&aoe_pt); |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | void |
| 165 | aoenet_exit(void) |
| 166 | { |
| 167 | dev_remove_pack(&aoe_pt); |
| 168 | } |
| 169 | |