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 | * aoecmd.c |
| 4 | * Filesystem request handling methods |
| 5 | */ |
| 6 | |
Bartlomiej Zolnierkiewicz | 04b3ab5 | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 7 | #include <linux/ata.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/hdreg.h> |
| 10 | #include <linux/blkdev.h> |
| 11 | #include <linux/skbuff.h> |
| 12 | #include <linux/netdevice.h> |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 13 | #include <linux/genhd.h> |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 14 | #include <linux/moduleparam.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 15 | #include <net/net_namespace.h> |
Ed L. Cashin | 475172f | 2005-09-29 12:47:40 -0400 | [diff] [blame] | 16 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include "aoe.h" |
| 18 | |
Ed L. Cashin | b751e8b | 2006-09-20 14:36:50 -0400 | [diff] [blame] | 19 | static int aoe_deadsecs = 60 * 3; |
| 20 | module_param(aoe_deadsecs, int, 0644); |
| 21 | MODULE_PARM_DESC(aoe_deadsecs, "After aoe_deadsecs seconds, give up and fail dev."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Ed L. Cashin | 7df620d | 2008-02-08 04:20:07 -0800 | [diff] [blame] | 23 | static int aoe_maxout = 16; |
| 24 | module_param(aoe_maxout, int, 0644); |
| 25 | MODULE_PARM_DESC(aoe_maxout, |
| 26 | "Only aoe_maxout outstanding packets for every MAC on eX.Y."); |
| 27 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 28 | static struct sk_buff * |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 29 | new_skb(ulong len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
| 31 | struct sk_buff *skb; |
| 32 | |
| 33 | skb = alloc_skb(len, GFP_ATOMIC); |
| 34 | if (skb) { |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 35 | skb_reset_mac_header(skb); |
Arnaldo Carvalho de Melo | c1d2bbe | 2007-04-10 20:45:18 -0700 | [diff] [blame] | 36 | skb_reset_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | skb->protocol = __constant_htons(ETH_P_AOE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } |
| 39 | return skb; |
| 40 | } |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | static struct frame * |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 43 | getframe(struct aoetgt *t, int tag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
| 45 | struct frame *f, *e; |
| 46 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 47 | f = t->frames; |
| 48 | e = f + t->nframes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | for (; f<e; f++) |
| 50 | if (f->tag == tag) |
| 51 | return f; |
| 52 | return NULL; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Leave the top bit clear so we have tagspace for userland. |
| 57 | * The bottom 16 bits are the xmit tick for rexmit/rttavg processing. |
| 58 | * This driver reserves tag -1 to mean "unused frame." |
| 59 | */ |
| 60 | static int |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 61 | newtag(struct aoetgt *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
| 63 | register ulong n; |
| 64 | |
| 65 | n = jiffies & 0xffff; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 66 | return n |= (++t->lasttag & 0x7fff) << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static int |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 70 | aoehdr_atainit(struct aoedev *d, struct aoetgt *t, struct aoe_hdr *h) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 72 | u32 host_tag = newtag(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 74 | memcpy(h->src, t->ifp->nd->dev_addr, sizeof h->src); |
| 75 | memcpy(h->dst, t->addr, sizeof h->dst); |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 76 | h->type = __constant_cpu_to_be16(ETH_P_AOE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | h->verfl = AOE_HVER; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 78 | h->major = cpu_to_be16(d->aoemajor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | h->minor = d->aoeminor; |
| 80 | h->cmd = AOECMD_ATA; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 81 | h->tag = cpu_to_be32(host_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | return host_tag; |
| 84 | } |
| 85 | |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 86 | static inline void |
| 87 | put_lba(struct aoe_atahdr *ah, sector_t lba) |
| 88 | { |
| 89 | ah->lba0 = lba; |
| 90 | ah->lba1 = lba >>= 8; |
| 91 | ah->lba2 = lba >>= 8; |
| 92 | ah->lba3 = lba >>= 8; |
| 93 | ah->lba4 = lba >>= 8; |
| 94 | ah->lba5 = lba >>= 8; |
| 95 | } |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static void |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 98 | ifrotate(struct aoetgt *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 100 | t->ifp++; |
| 101 | if (t->ifp >= &t->ifs[NAOEIFS] || t->ifp->nd == NULL) |
| 102 | t->ifp = t->ifs; |
| 103 | if (t->ifp->nd == NULL) { |
| 104 | printk(KERN_INFO "aoe: no interface to rotate to\n"); |
| 105 | BUG(); |
| 106 | } |
| 107 | } |
| 108 | |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 109 | static void |
| 110 | skb_pool_put(struct aoedev *d, struct sk_buff *skb) |
| 111 | { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 112 | __skb_queue_tail(&d->skbpool, skb); |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static struct sk_buff * |
| 116 | skb_pool_get(struct aoedev *d) |
| 117 | { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 118 | struct sk_buff *skb = skb_peek(&d->skbpool); |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 119 | |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 120 | if (skb && atomic_read(&skb_shinfo(skb)->dataref) == 1) { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 121 | __skb_unlink(skb, &d->skbpool); |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 122 | return skb; |
| 123 | } |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 124 | if (skb_queue_len(&d->skbpool) < NSKBPOOLMAX && |
| 125 | (skb = new_skb(ETH_ZLEN))) |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 126 | return skb; |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 127 | |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 128 | return NULL; |
| 129 | } |
| 130 | |
| 131 | /* freeframe is where we do our load balancing so it's a little hairy. */ |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 132 | static struct frame * |
| 133 | freeframe(struct aoedev *d) |
| 134 | { |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 135 | struct frame *f, *e, *rf; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 136 | struct aoetgt **t; |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 137 | struct sk_buff *skb; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 138 | |
| 139 | if (d->targets[0] == NULL) { /* shouldn't happen, but I'm paranoid */ |
| 140 | printk(KERN_ERR "aoe: NULL TARGETS!\n"); |
| 141 | return NULL; |
| 142 | } |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 143 | t = d->tgt; |
| 144 | t++; |
| 145 | if (t >= &d->targets[NTARGETS] || !*t) |
| 146 | t = d->targets; |
| 147 | for (;;) { |
| 148 | if ((*t)->nout < (*t)->maxout |
| 149 | && t != d->htgt |
| 150 | && (*t)->ifp->nd) { |
| 151 | rf = NULL; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 152 | f = (*t)->frames; |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 153 | e = f + (*t)->nframes; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 154 | for (; f < e; f++) { |
| 155 | if (f->tag != FREETAG) |
| 156 | continue; |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 157 | skb = f->skb; |
| 158 | if (!skb |
| 159 | && !(f->skb = skb = new_skb(ETH_ZLEN))) |
| 160 | continue; |
| 161 | if (atomic_read(&skb_shinfo(skb)->dataref) |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 162 | != 1) { |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 163 | if (!rf) |
| 164 | rf = f; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 165 | continue; |
| 166 | } |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 167 | gotone: skb_shinfo(skb)->nr_frags = skb->data_len = 0; |
| 168 | skb_trim(skb, 0); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 169 | d->tgt = t; |
| 170 | ifrotate(*t); |
| 171 | return f; |
| 172 | } |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 173 | /* Work can be done, but the network layer is |
| 174 | holding our precious packets. Try to grab |
| 175 | one from the pool. */ |
| 176 | f = rf; |
| 177 | if (f == NULL) { /* more paranoia */ |
| 178 | printk(KERN_ERR |
| 179 | "aoe: freeframe: %s.\n", |
| 180 | "unexpected null rf"); |
| 181 | d->flags |= DEVFL_KICKME; |
| 182 | return NULL; |
| 183 | } |
| 184 | skb = skb_pool_get(d); |
| 185 | if (skb) { |
| 186 | skb_pool_put(d, f->skb); |
| 187 | f->skb = skb; |
| 188 | goto gotone; |
| 189 | } |
| 190 | (*t)->dataref++; |
| 191 | if ((*t)->nout == 0) |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 192 | d->flags |= DEVFL_KICKME; |
| 193 | } |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 194 | if (t == d->tgt) /* we've looped and found nada */ |
| 195 | break; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 196 | t++; |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 197 | if (t >= &d->targets[NTARGETS] || !*t) |
| 198 | t = d->targets; |
| 199 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 200 | return NULL; |
| 201 | } |
| 202 | |
| 203 | static int |
| 204 | aoecmd_ata_rw(struct aoedev *d) |
| 205 | { |
| 206 | struct frame *f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | struct aoe_hdr *h; |
| 208 | struct aoe_atahdr *ah; |
| 209 | struct buf *buf; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 210 | struct bio_vec *bv; |
| 211 | struct aoetgt *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | struct sk_buff *skb; |
| 213 | ulong bcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | char writebit, extbit; |
| 215 | |
| 216 | writebit = 0x10; |
| 217 | extbit = 0x4; |
| 218 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 219 | f = freeframe(d); |
| 220 | if (f == NULL) |
| 221 | return 0; |
| 222 | t = *d->tgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | buf = d->inprocess; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 224 | bv = buf->bv; |
| 225 | bcnt = t->ifp->maxbcnt; |
| 226 | if (bcnt == 0) |
| 227 | bcnt = DEFAULTBCNT; |
| 228 | if (bcnt > buf->bv_resid) |
| 229 | bcnt = buf->bv_resid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | /* initialize the headers & frame */ |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 231 | skb = f->skb; |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 232 | h = (struct aoe_hdr *) skb_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | ah = (struct aoe_atahdr *) (h+1); |
Ed L. Cashin | 19900cd | 2006-12-22 01:09:21 -0800 | [diff] [blame] | 234 | skb_put(skb, sizeof *h + sizeof *ah); |
| 235 | memset(h, 0, skb->len); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 236 | f->tag = aoehdr_atainit(d, t, h); |
| 237 | t->nout++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | f->waited = 0; |
| 239 | f->buf = buf; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 240 | f->bufaddr = page_address(bv->bv_page) + buf->bv_off; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 241 | f->bcnt = bcnt; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 242 | f->lba = buf->sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | /* set up ata header */ |
| 245 | ah->scnt = bcnt >> 9; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 246 | put_lba(ah, buf->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | if (d->flags & DEVFL_EXT) { |
| 248 | ah->aflags |= AOEAFL_EXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } else { |
| 250 | extbit = 0; |
| 251 | ah->lba3 &= 0x0f; |
| 252 | ah->lba3 |= 0xe0; /* LBA bit + obsolete 0xa0 */ |
| 253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | if (bio_data_dir(buf->bio) == WRITE) { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 255 | skb_fill_page_desc(skb, 0, bv->bv_page, buf->bv_off, bcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | ah->aflags |= AOEAFL_WRITE; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 257 | skb->len += bcnt; |
| 258 | skb->data_len = bcnt; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 259 | t->wpkts++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } else { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 261 | t->rpkts++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | writebit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Bartlomiej Zolnierkiewicz | 04b3ab5 | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 265 | ah->cmdstat = ATA_CMD_PIO_READ | writebit | extbit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | /* mark all tracking fields and load out */ |
| 268 | buf->nframesout += 1; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 269 | buf->bv_off += bcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | buf->bv_resid -= bcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | buf->resid -= bcnt; |
| 272 | buf->sector += bcnt >> 9; |
| 273 | if (buf->resid == 0) { |
| 274 | d->inprocess = NULL; |
| 275 | } else if (buf->bv_resid == 0) { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 276 | buf->bv = ++bv; |
| 277 | buf->bv_resid = bv->bv_len; |
| 278 | WARN_ON(buf->bv_resid == 0); |
| 279 | buf->bv_off = bv->bv_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 282 | skb->dev = t->ifp->nd; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 283 | skb = skb_clone(skb, GFP_ATOMIC); |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 284 | if (skb) |
| 285 | __skb_queue_tail(&d->sendq, skb); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 286 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 289 | /* some callers cannot sleep, and they can call this function, |
| 290 | * transmitting the packets later, when interrupts are on |
| 291 | */ |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 292 | static void |
| 293 | aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff_head *queue) |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 294 | { |
| 295 | struct aoe_hdr *h; |
| 296 | struct aoe_cfghdr *ch; |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 297 | struct sk_buff *skb; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 298 | struct net_device *ifp; |
| 299 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 300 | read_lock(&dev_base_lock); |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 301 | for_each_netdev(&init_net, ifp) { |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 302 | dev_hold(ifp); |
| 303 | if (!is_aoe_netif(ifp)) |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 304 | goto cont; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 305 | |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 306 | skb = new_skb(sizeof *h + sizeof *ch); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 307 | if (skb == NULL) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 308 | printk(KERN_INFO "aoe: skb alloc failure\n"); |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 309 | goto cont; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 310 | } |
Ed L. Cashin | 19900cd | 2006-12-22 01:09:21 -0800 | [diff] [blame] | 311 | skb_put(skb, sizeof *h + sizeof *ch); |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 312 | skb->dev = ifp; |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 313 | __skb_queue_tail(queue, skb); |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 314 | h = (struct aoe_hdr *) skb_mac_header(skb); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 315 | memset(h, 0, sizeof *h + sizeof *ch); |
| 316 | |
| 317 | memset(h->dst, 0xff, sizeof h->dst); |
| 318 | memcpy(h->src, ifp->dev_addr, sizeof h->src); |
| 319 | h->type = __constant_cpu_to_be16(ETH_P_AOE); |
| 320 | h->verfl = AOE_HVER; |
| 321 | h->major = cpu_to_be16(aoemajor); |
| 322 | h->minor = aoeminor; |
| 323 | h->cmd = AOECMD_CFG; |
| 324 | |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 325 | cont: |
| 326 | dev_put(ifp); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 327 | } |
| 328 | read_unlock(&dev_base_lock); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 329 | } |
| 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | static void |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 332 | resend(struct aoedev *d, struct aoetgt *t, struct frame *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
| 334 | struct sk_buff *skb; |
| 335 | struct aoe_hdr *h; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 336 | struct aoe_atahdr *ah; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | char buf[128]; |
| 338 | u32 n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 340 | ifrotate(t); |
| 341 | n = newtag(t); |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 342 | skb = f->skb; |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 343 | h = (struct aoe_hdr *) skb_mac_header(skb); |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 344 | ah = (struct aoe_atahdr *) (h+1); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 345 | |
| 346 | snprintf(buf, sizeof buf, |
Harvey Harrison | 411c41e | 2008-11-25 00:40:37 -0800 | [diff] [blame] | 347 | "%15s e%ld.%d oldtag=%08x@%08lx newtag=%08x s=%pm d=%pm nout=%d\n", |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 348 | "retransmit", d->aoemajor, d->aoeminor, f->tag, jiffies, n, |
Harvey Harrison | 411c41e | 2008-11-25 00:40:37 -0800 | [diff] [blame] | 349 | h->src, h->dst, t->nout); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 350 | aoechr_error(buf); |
| 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | f->tag = n; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 353 | h->tag = cpu_to_be32(n); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 354 | memcpy(h->dst, t->addr, sizeof h->dst); |
| 355 | memcpy(h->src, t->ifp->nd->dev_addr, sizeof h->src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 357 | switch (ah->cmdstat) { |
| 358 | default: |
| 359 | break; |
Bartlomiej Zolnierkiewicz | 04b3ab5 | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 360 | case ATA_CMD_PIO_READ: |
| 361 | case ATA_CMD_PIO_READ_EXT: |
| 362 | case ATA_CMD_PIO_WRITE: |
| 363 | case ATA_CMD_PIO_WRITE_EXT: |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 364 | put_lba(ah, f->lba); |
| 365 | |
| 366 | n = f->bcnt; |
| 367 | if (n > DEFAULTBCNT) |
| 368 | n = DEFAULTBCNT; |
| 369 | ah->scnt = n >> 9; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 370 | if (ah->aflags & AOEAFL_WRITE) { |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 371 | skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr), |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 372 | offset_in_page(f->bufaddr), n); |
| 373 | skb->len = sizeof *h + sizeof *ah + n; |
| 374 | skb->data_len = n; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 375 | } |
| 376 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 377 | skb->dev = t->ifp->nd; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 378 | skb = skb_clone(skb, GFP_ATOMIC); |
| 379 | if (skb == NULL) |
| 380 | return; |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 381 | __skb_queue_tail(&d->sendq, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static int |
| 385 | tsince(int tag) |
| 386 | { |
| 387 | int n; |
| 388 | |
| 389 | n = jiffies & 0xffff; |
| 390 | n -= tag & 0xffff; |
| 391 | if (n < 0) |
| 392 | n += 1<<16; |
| 393 | return n; |
| 394 | } |
| 395 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 396 | static struct aoeif * |
| 397 | getif(struct aoetgt *t, struct net_device *nd) |
| 398 | { |
| 399 | struct aoeif *p, *e; |
| 400 | |
| 401 | p = t->ifs; |
| 402 | e = p + NAOEIFS; |
| 403 | for (; p < e; p++) |
| 404 | if (p->nd == nd) |
| 405 | return p; |
| 406 | return NULL; |
| 407 | } |
| 408 | |
| 409 | static struct aoeif * |
| 410 | addif(struct aoetgt *t, struct net_device *nd) |
| 411 | { |
| 412 | struct aoeif *p; |
| 413 | |
| 414 | p = getif(t, NULL); |
| 415 | if (!p) |
| 416 | return NULL; |
| 417 | p->nd = nd; |
| 418 | p->maxbcnt = DEFAULTBCNT; |
| 419 | p->lost = 0; |
| 420 | p->lostjumbo = 0; |
| 421 | return p; |
| 422 | } |
| 423 | |
| 424 | static void |
| 425 | ejectif(struct aoetgt *t, struct aoeif *ifp) |
| 426 | { |
| 427 | struct aoeif *e; |
| 428 | ulong n; |
| 429 | |
| 430 | e = t->ifs + NAOEIFS - 1; |
| 431 | n = (e - ifp) * sizeof *ifp; |
| 432 | memmove(ifp, ifp+1, n); |
| 433 | e->nd = NULL; |
| 434 | } |
| 435 | |
| 436 | static int |
| 437 | sthtith(struct aoedev *d) |
| 438 | { |
| 439 | struct frame *f, *e, *nf; |
| 440 | struct sk_buff *skb; |
| 441 | struct aoetgt *ht = *d->htgt; |
| 442 | |
| 443 | f = ht->frames; |
| 444 | e = f + ht->nframes; |
| 445 | for (; f < e; f++) { |
| 446 | if (f->tag == FREETAG) |
| 447 | continue; |
| 448 | nf = freeframe(d); |
| 449 | if (!nf) |
| 450 | return 0; |
| 451 | skb = nf->skb; |
| 452 | *nf = *f; |
| 453 | f->skb = skb; |
| 454 | f->tag = FREETAG; |
| 455 | nf->waited = 0; |
| 456 | ht->nout--; |
| 457 | (*d->tgt)->nout++; |
| 458 | resend(d, *d->tgt, nf); |
| 459 | } |
| 460 | /* he's clean, he's useless. take away his interfaces */ |
| 461 | memset(ht->ifs, 0, sizeof ht->ifs); |
| 462 | d->htgt = NULL; |
| 463 | return 1; |
| 464 | } |
| 465 | |
| 466 | static inline unsigned char |
| 467 | ata_scnt(unsigned char *packet) { |
| 468 | struct aoe_hdr *h; |
| 469 | struct aoe_atahdr *ah; |
| 470 | |
| 471 | h = (struct aoe_hdr *) packet; |
| 472 | ah = (struct aoe_atahdr *) (h+1); |
| 473 | return ah->scnt; |
| 474 | } |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | static void |
| 477 | rexmit_timer(ulong vp) |
| 478 | { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 479 | struct sk_buff_head queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | struct aoedev *d; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 481 | struct aoetgt *t, **tt, **te; |
| 482 | struct aoeif *ifp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | struct frame *f, *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | register long timeout; |
| 485 | ulong flags, n; |
| 486 | |
| 487 | d = (struct aoedev *) vp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | /* timeout is always ~150% of the moving average */ |
| 490 | timeout = d->rttavg; |
| 491 | timeout += timeout >> 1; |
| 492 | |
| 493 | spin_lock_irqsave(&d->lock, flags); |
| 494 | |
| 495 | if (d->flags & DEVFL_TKILL) { |
Ed L. Cashin | 1c6f3fc | 2006-01-25 13:54:44 -0500 | [diff] [blame] | 496 | spin_unlock_irqrestore(&d->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return; |
| 498 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 499 | tt = d->targets; |
| 500 | te = tt + NTARGETS; |
| 501 | for (; tt < te && *tt; tt++) { |
| 502 | t = *tt; |
| 503 | f = t->frames; |
| 504 | e = f + t->nframes; |
| 505 | for (; f < e; f++) { |
| 506 | if (f->tag == FREETAG |
| 507 | || tsince(f->tag) < timeout) |
| 508 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | n = f->waited += timeout; |
| 510 | n /= HZ; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 511 | if (n > aoe_deadsecs) { |
| 512 | /* waited too long. device failure. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | aoedev_downdev(d); |
Ed L. Cashin | 1c6f3fc | 2006-01-25 13:54:44 -0500 | [diff] [blame] | 514 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 516 | |
| 517 | if (n > HELPWAIT /* see if another target can help */ |
| 518 | && (tt != d->targets || d->targets[1])) |
| 519 | d->htgt = tt; |
| 520 | |
| 521 | if (t->nout == t->maxout) { |
| 522 | if (t->maxout > 1) |
| 523 | t->maxout--; |
| 524 | t->lastwadj = jiffies; |
| 525 | } |
| 526 | |
| 527 | ifp = getif(t, f->skb->dev); |
| 528 | if (ifp && ++ifp->lost > (t->nframes << 1) |
| 529 | && (ifp != t->ifs || t->ifs[1].nd)) { |
| 530 | ejectif(t, ifp); |
| 531 | ifp = NULL; |
| 532 | } |
| 533 | |
| 534 | if (ata_scnt(skb_mac_header(f->skb)) > DEFAULTBCNT / 512 |
| 535 | && ifp && ++ifp->lostjumbo > (t->nframes << 1) |
| 536 | && ifp->maxbcnt != DEFAULTBCNT) { |
| 537 | printk(KERN_INFO |
| 538 | "aoe: e%ld.%d: " |
| 539 | "too many lost jumbo on " |
Harvey Harrison | 411c41e | 2008-11-25 00:40:37 -0800 | [diff] [blame] | 540 | "%s:%pm - " |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 541 | "falling back to %d frames.\n", |
| 542 | d->aoemajor, d->aoeminor, |
Harvey Harrison | 411c41e | 2008-11-25 00:40:37 -0800 | [diff] [blame] | 543 | ifp->nd->name, t->addr, |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 544 | DEFAULTBCNT); |
| 545 | ifp->maxbcnt = 0; |
| 546 | } |
| 547 | resend(d, t, f); |
| 548 | } |
| 549 | |
| 550 | /* window check */ |
| 551 | if (t->nout == t->maxout |
| 552 | && t->maxout < t->nframes |
| 553 | && (jiffies - t->lastwadj)/HZ > 10) { |
| 554 | t->maxout++; |
| 555 | t->lastwadj = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
| 557 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 558 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 559 | if (!skb_queue_empty(&d->sendq)) { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 560 | n = d->rttavg <<= 1; |
| 561 | if (n > MAXTIMER) |
| 562 | d->rttavg = MAXTIMER; |
| 563 | } |
| 564 | |
| 565 | if (d->flags & DEVFL_KICKME || d->htgt) { |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 566 | d->flags &= ~DEVFL_KICKME; |
| 567 | aoecmd_work(d); |
| 568 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 570 | __skb_queue_head_init(&queue); |
| 571 | skb_queue_splice_init(&d->sendq, &queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
| 573 | d->timer.expires = jiffies + TIMERTICK; |
| 574 | add_timer(&d->timer); |
| 575 | |
| 576 | spin_unlock_irqrestore(&d->lock, flags); |
| 577 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 578 | aoenet_xmit(&queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 581 | /* enters with d->lock held */ |
| 582 | void |
| 583 | aoecmd_work(struct aoedev *d) |
| 584 | { |
| 585 | struct buf *buf; |
| 586 | loop: |
| 587 | if (d->htgt && !sthtith(d)) |
| 588 | return; |
| 589 | if (d->inprocess == NULL) { |
| 590 | if (list_empty(&d->bufq)) |
| 591 | return; |
| 592 | buf = container_of(d->bufq.next, struct buf, bufs); |
| 593 | list_del(d->bufq.next); |
| 594 | d->inprocess = buf; |
| 595 | } |
| 596 | if (aoecmd_ata_rw(d)) |
| 597 | goto loop; |
| 598 | } |
| 599 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 600 | /* this function performs work that has been deferred until sleeping is OK |
| 601 | */ |
| 602 | void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 603 | aoecmd_sleepwork(struct work_struct *work) |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 604 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 605 | struct aoedev *d = container_of(work, struct aoedev, work); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 606 | |
| 607 | if (d->flags & DEVFL_GDALLOC) |
| 608 | aoeblk_gdalloc(d); |
| 609 | |
| 610 | if (d->flags & DEVFL_NEWSIZE) { |
| 611 | struct block_device *bd; |
| 612 | unsigned long flags; |
| 613 | u64 ssize; |
| 614 | |
Tejun Heo | 80795ae | 2008-08-25 19:56:07 +0900 | [diff] [blame] | 615 | ssize = get_capacity(d->gd); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 616 | bd = bdget_disk(d->gd, 0); |
| 617 | |
| 618 | if (bd) { |
| 619 | mutex_lock(&bd->bd_inode->i_mutex); |
| 620 | i_size_write(bd->bd_inode, (loff_t)ssize<<9); |
| 621 | mutex_unlock(&bd->bd_inode->i_mutex); |
| 622 | bdput(bd); |
| 623 | } |
| 624 | spin_lock_irqsave(&d->lock, flags); |
| 625 | d->flags |= DEVFL_UP; |
| 626 | d->flags &= ~DEVFL_NEWSIZE; |
| 627 | spin_unlock_irqrestore(&d->lock, flags); |
| 628 | } |
| 629 | } |
| 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | static void |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 632 | ataid_complete(struct aoedev *d, struct aoetgt *t, unsigned char *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
| 634 | u64 ssize; |
| 635 | u16 n; |
| 636 | |
| 637 | /* word 83: command set supported */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 638 | n = get_unaligned_le16(&id[83 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
| 640 | /* word 86: command set/feature enabled */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 641 | n |= get_unaligned_le16(&id[86 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | if (n & (1<<10)) { /* bit 10: LBA 48 */ |
| 644 | d->flags |= DEVFL_EXT; |
| 645 | |
| 646 | /* word 100: number lba48 sectors */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 647 | ssize = get_unaligned_le64(&id[100 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
| 649 | /* set as in ide-disk.c:init_idedisk_capacity */ |
| 650 | d->geo.cylinders = ssize; |
| 651 | d->geo.cylinders /= (255 * 63); |
| 652 | d->geo.heads = 255; |
| 653 | d->geo.sectors = 63; |
| 654 | } else { |
| 655 | d->flags &= ~DEVFL_EXT; |
| 656 | |
| 657 | /* number lba28 sectors */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 658 | ssize = get_unaligned_le32(&id[60 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | /* NOTE: obsolete in ATA 6 */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 661 | d->geo.cylinders = get_unaligned_le16(&id[54 << 1]); |
| 662 | d->geo.heads = get_unaligned_le16(&id[55 << 1]); |
| 663 | d->geo.sectors = get_unaligned_le16(&id[56 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 665 | |
| 666 | if (d->ssize != ssize) |
Ed L. Cashin | 1d75981 | 2008-02-08 04:20:08 -0800 | [diff] [blame] | 667 | printk(KERN_INFO |
Harvey Harrison | 411c41e | 2008-11-25 00:40:37 -0800 | [diff] [blame] | 668 | "aoe: %pm e%ld.%d v%04x has %llu sectors\n", |
| 669 | t->addr, |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 670 | d->aoemajor, d->aoeminor, |
| 671 | d->fw_ver, (long long)ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | d->ssize = ssize; |
| 673 | d->geo.start = 0; |
Ed L. Cashin | 6b9699b | 2008-02-08 04:20:06 -0800 | [diff] [blame] | 674 | if (d->flags & (DEVFL_GDALLOC|DEVFL_NEWSIZE)) |
| 675 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | if (d->gd != NULL) { |
Tejun Heo | 80795ae | 2008-08-25 19:56:07 +0900 | [diff] [blame] | 677 | set_capacity(d->gd, ssize); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 678 | d->flags |= DEVFL_NEWSIZE; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 679 | } else |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 680 | d->flags |= DEVFL_GDALLOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | schedule_work(&d->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | static void |
| 685 | calc_rttavg(struct aoedev *d, int rtt) |
| 686 | { |
| 687 | register long n; |
| 688 | |
| 689 | n = rtt; |
Ed L. Cashin | dced3a0 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 690 | if (n < 0) { |
| 691 | n = -rtt; |
| 692 | if (n < MINTIMER) |
| 693 | n = MINTIMER; |
| 694 | else if (n > MAXTIMER) |
| 695 | n = MAXTIMER; |
| 696 | d->mintimer += (n - d->mintimer) >> 1; |
| 697 | } else if (n < d->mintimer) |
| 698 | n = d->mintimer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | else if (n > MAXTIMER) |
| 700 | n = MAXTIMER; |
| 701 | |
| 702 | /* g == .25; cf. Congestion Avoidance and Control, Jacobson & Karels; 1988 */ |
| 703 | n -= d->rttavg; |
| 704 | d->rttavg += n >> 2; |
| 705 | } |
| 706 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 707 | static struct aoetgt * |
| 708 | gettgt(struct aoedev *d, char *addr) |
| 709 | { |
| 710 | struct aoetgt **t, **e; |
| 711 | |
| 712 | t = d->targets; |
| 713 | e = t + NTARGETS; |
| 714 | for (; t < e && *t; t++) |
| 715 | if (memcmp((*t)->addr, addr, sizeof((*t)->addr)) == 0) |
| 716 | return *t; |
| 717 | return NULL; |
| 718 | } |
| 719 | |
| 720 | static inline void |
Linus Torvalds | 03054de | 2008-02-08 09:42:46 -0800 | [diff] [blame] | 721 | diskstats(struct gendisk *disk, struct bio *bio, ulong duration, sector_t sector) |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 722 | { |
| 723 | unsigned long n_sect = bio->bi_size >> 9; |
| 724 | const int rw = bio_data_dir(bio); |
Jens Axboe | 28f1370 | 2008-05-07 10:15:46 +0200 | [diff] [blame] | 725 | struct hd_struct *part; |
Tejun Heo | c995905 | 2008-08-25 19:47:21 +0900 | [diff] [blame] | 726 | int cpu; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 727 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 728 | cpu = part_stat_lock(); |
Tejun Heo | e71bf0d | 2008-09-03 09:03:02 +0200 | [diff] [blame] | 729 | part = disk_map_sector_rcu(disk, sector); |
Tejun Heo | e71bf0d | 2008-09-03 09:03:02 +0200 | [diff] [blame] | 730 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 731 | part_stat_inc(cpu, part, ios[rw]); |
| 732 | part_stat_add(cpu, part, ticks[rw], duration); |
| 733 | part_stat_add(cpu, part, sectors[rw], n_sect); |
| 734 | part_stat_add(cpu, part, io_ticks, duration); |
Tejun Heo | c995905 | 2008-08-25 19:47:21 +0900 | [diff] [blame] | 735 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 736 | part_stat_unlock(); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 737 | } |
| 738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | void |
| 740 | aoecmd_ata_rsp(struct sk_buff *skb) |
| 741 | { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 742 | struct sk_buff_head queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | struct aoedev *d; |
Ed L. Cashin | ddec63e | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 744 | struct aoe_hdr *hin, *hout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | struct aoe_atahdr *ahin, *ahout; |
| 746 | struct frame *f; |
| 747 | struct buf *buf; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 748 | struct aoetgt *t; |
| 749 | struct aoeif *ifp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | register long n; |
| 751 | ulong flags; |
| 752 | char ebuf[128]; |
ecashin@coraid.com | 32465c6 | 2005-04-18 22:00:18 -0700 | [diff] [blame] | 753 | u16 aoemajor; |
| 754 | |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 755 | hin = (struct aoe_hdr *) skb_mac_header(skb); |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 756 | aoemajor = get_unaligned_be16(&hin->major); |
ecashin@coraid.com | 32465c6 | 2005-04-18 22:00:18 -0700 | [diff] [blame] | 757 | d = aoedev_by_aoeaddr(aoemajor, hin->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | if (d == NULL) { |
| 759 | snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response " |
| 760 | "for unknown device %d.%d\n", |
ecashin@coraid.com | 32465c6 | 2005-04-18 22:00:18 -0700 | [diff] [blame] | 761 | aoemajor, hin->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | aoechr_error(ebuf); |
| 763 | return; |
| 764 | } |
| 765 | |
| 766 | spin_lock_irqsave(&d->lock, flags); |
| 767 | |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 768 | n = get_unaligned_be32(&hin->tag); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 769 | t = gettgt(d, hin->src); |
| 770 | if (t == NULL) { |
Harvey Harrison | 411c41e | 2008-11-25 00:40:37 -0800 | [diff] [blame] | 771 | printk(KERN_INFO "aoe: can't find target e%ld.%d:%pm\n", |
| 772 | d->aoemajor, d->aoeminor, hin->src); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 773 | spin_unlock_irqrestore(&d->lock, flags); |
| 774 | return; |
| 775 | } |
| 776 | f = getframe(t, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | if (f == NULL) { |
Ed L. Cashin | dced3a0 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 778 | calc_rttavg(d, -tsince(n)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | spin_unlock_irqrestore(&d->lock, flags); |
| 780 | snprintf(ebuf, sizeof ebuf, |
| 781 | "%15s e%d.%d tag=%08x@%08lx\n", |
| 782 | "unexpected rsp", |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 783 | get_unaligned_be16(&hin->major), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | hin->minor, |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 785 | get_unaligned_be32(&hin->tag), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | jiffies); |
| 787 | aoechr_error(ebuf); |
| 788 | return; |
| 789 | } |
| 790 | |
| 791 | calc_rttavg(d, tsince(f->tag)); |
| 792 | |
| 793 | ahin = (struct aoe_atahdr *) (hin+1); |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 794 | hout = (struct aoe_hdr *) skb_mac_header(f->skb); |
Ed L. Cashin | ddec63e | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 795 | ahout = (struct aoe_atahdr *) (hout+1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | buf = f->buf; |
| 797 | |
| 798 | if (ahin->cmdstat & 0xa9) { /* these bits cleared on success */ |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 799 | printk(KERN_ERR |
Ed L. Cashin | 1d75981 | 2008-02-08 04:20:08 -0800 | [diff] [blame] | 800 | "aoe: ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | ahout->cmdstat, ahin->cmdstat, |
| 802 | d->aoemajor, d->aoeminor); |
| 803 | if (buf) |
| 804 | buf->flags |= BUFFL_FAIL; |
| 805 | } else { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 806 | if (d->htgt && t == *d->htgt) /* I'll help myself, thank you. */ |
| 807 | d->htgt = NULL; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 808 | n = ahout->scnt << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | switch (ahout->cmdstat) { |
Bartlomiej Zolnierkiewicz | 04b3ab5 | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 810 | case ATA_CMD_PIO_READ: |
| 811 | case ATA_CMD_PIO_READ_EXT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | if (skb->len - sizeof *hin - sizeof *ahin < n) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 813 | printk(KERN_ERR |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 814 | "aoe: %s. skb->len=%d need=%ld\n", |
| 815 | "runt data size in read", skb->len, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | /* fail frame f? just returning will rexmit. */ |
| 817 | spin_unlock_irqrestore(&d->lock, flags); |
| 818 | return; |
| 819 | } |
| 820 | memcpy(f->bufaddr, ahin+1, n); |
Bartlomiej Zolnierkiewicz | 04b3ab5 | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 821 | case ATA_CMD_PIO_WRITE: |
| 822 | case ATA_CMD_PIO_WRITE_EXT: |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 823 | ifp = getif(t, skb->dev); |
| 824 | if (ifp) { |
| 825 | ifp->lost = 0; |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 826 | if (n > DEFAULTBCNT) |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 827 | ifp->lostjumbo = 0; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 828 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 829 | if (f->bcnt -= n) { |
| 830 | f->lba += n >> 9; |
| 831 | f->bufaddr += n; |
| 832 | resend(d, t, f); |
| 833 | goto xmit; |
| 834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | break; |
Bartlomiej Zolnierkiewicz | 04b3ab5 | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 836 | case ATA_CMD_ID_ATA: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | if (skb->len - sizeof *hin - sizeof *ahin < 512) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 838 | printk(KERN_INFO |
| 839 | "aoe: runt data size in ataid. skb->len=%d\n", |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 840 | skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | spin_unlock_irqrestore(&d->lock, flags); |
| 842 | return; |
| 843 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 844 | ataid_complete(d, t, (char *) (ahin+1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | break; |
| 846 | default: |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 847 | printk(KERN_INFO |
| 848 | "aoe: unrecognized ata command %2.2Xh for %d.%d\n", |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 849 | ahout->cmdstat, |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 850 | get_unaligned_be16(&hin->major), |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 851 | hin->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 855 | if (buf && --buf->nframesout == 0 && buf->resid == 0) { |
Linus Torvalds | 03054de | 2008-02-08 09:42:46 -0800 | [diff] [blame] | 856 | diskstats(d->gd, buf->bio, jiffies - buf->stime, buf->sector); |
Peter Horton | 0a1f127 | 2009-12-01 13:17:46 -0800 | [diff] [blame] | 857 | if (buf->flags & BUFFL_FAIL) |
| 858 | bio_endio(buf->bio, -EIO); |
| 859 | else { |
Andrew Morton | 6ec1480 | 2009-12-21 16:27:50 -0800 | [diff] [blame] | 860 | bio_flush_dcache_pages(buf->bio); |
Peter Horton | 0a1f127 | 2009-12-01 13:17:46 -0800 | [diff] [blame] | 861 | bio_endio(buf->bio, 0); |
| 862 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 863 | mempool_free(buf, d->bufpool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | f->buf = NULL; |
| 867 | f->tag = FREETAG; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 868 | t->nout--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | aoecmd_work(d); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 871 | xmit: |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 872 | __skb_queue_head_init(&queue); |
| 873 | skb_queue_splice_init(&d->sendq, &queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | spin_unlock_irqrestore(&d->lock, flags); |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 876 | aoenet_xmit(&queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | void |
| 880 | aoecmd_cfg(ushort aoemajor, unsigned char aoeminor) |
| 881 | { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 882 | struct sk_buff_head queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 884 | __skb_queue_head_init(&queue); |
| 885 | aoecmd_cfg_pkts(aoemajor, aoeminor, &queue); |
| 886 | aoenet_xmit(&queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 889 | struct sk_buff * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | aoecmd_ata_id(struct aoedev *d) |
| 891 | { |
| 892 | struct aoe_hdr *h; |
| 893 | struct aoe_atahdr *ah; |
| 894 | struct frame *f; |
| 895 | struct sk_buff *skb; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 896 | struct aoetgt *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 898 | f = freeframe(d); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 899 | if (f == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | return NULL; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 901 | |
| 902 | t = *d->tgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | /* initialize the headers & frame */ |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 905 | skb = f->skb; |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 906 | h = (struct aoe_hdr *) skb_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | ah = (struct aoe_atahdr *) (h+1); |
Ed L. Cashin | 19900cd | 2006-12-22 01:09:21 -0800 | [diff] [blame] | 908 | skb_put(skb, sizeof *h + sizeof *ah); |
| 909 | memset(h, 0, skb->len); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 910 | f->tag = aoehdr_atainit(d, t, h); |
| 911 | t->nout++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | f->waited = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | /* set up ata header */ |
| 915 | ah->scnt = 1; |
Bartlomiej Zolnierkiewicz | 04b3ab5 | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 916 | ah->cmdstat = ATA_CMD_ID_ATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | ah->lba3 = 0xa0; |
| 918 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 919 | skb->dev = t->ifp->nd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 921 | d->rttavg = MAXTIMER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | d->timer.function = rexmit_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 924 | return skb_clone(skb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | } |
| 926 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 927 | static struct aoetgt * |
| 928 | addtgt(struct aoedev *d, char *addr, ulong nframes) |
| 929 | { |
| 930 | struct aoetgt *t, **tt, **te; |
| 931 | struct frame *f, *e; |
| 932 | |
| 933 | tt = d->targets; |
| 934 | te = tt + NTARGETS; |
| 935 | for (; tt < te && *tt; tt++) |
| 936 | ; |
| 937 | |
Ed L. Cashin | 578c4aa | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 938 | if (tt == te) { |
| 939 | printk(KERN_INFO |
| 940 | "aoe: device addtgt failure; too many targets\n"); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 941 | return NULL; |
Ed L. Cashin | 578c4aa | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 942 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 943 | t = kcalloc(1, sizeof *t, GFP_ATOMIC); |
| 944 | f = kcalloc(nframes, sizeof *f, GFP_ATOMIC); |
Ed L. Cashin | 578c4aa | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 945 | if (!t || !f) { |
| 946 | kfree(f); |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 947 | kfree(t); |
Ed L. Cashin | 578c4aa | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 948 | printk(KERN_INFO "aoe: cannot allocate memory to add target\n"); |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 949 | return NULL; |
| 950 | } |
| 951 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 952 | t->nframes = nframes; |
| 953 | t->frames = f; |
| 954 | e = f + nframes; |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 955 | for (; f < e; f++) |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 956 | f->tag = FREETAG; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 957 | memcpy(t->addr, addr, sizeof t->addr); |
| 958 | t->ifp = t->ifs; |
| 959 | t->maxout = t->nframes; |
| 960 | return *tt = t; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | void |
| 964 | aoecmd_cfg_rsp(struct sk_buff *skb) |
| 965 | { |
| 966 | struct aoedev *d; |
| 967 | struct aoe_hdr *h; |
| 968 | struct aoe_cfghdr *ch; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 969 | struct aoetgt *t; |
| 970 | struct aoeif *ifp; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 971 | ulong flags, sysminor, aoemajor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | struct sk_buff *sl; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 973 | u16 n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 975 | h = (struct aoe_hdr *) skb_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | ch = (struct aoe_cfghdr *) (h+1); |
| 977 | |
| 978 | /* |
| 979 | * Enough people have their dip switches set backwards to |
| 980 | * warrant a loud message for this special case. |
| 981 | */ |
Harvey Harrison | 823ed72 | 2008-07-04 09:28:32 +0200 | [diff] [blame] | 982 | aoemajor = get_unaligned_be16(&h->major); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | if (aoemajor == 0xfff) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 984 | printk(KERN_ERR "aoe: Warning: shelf address is all ones. " |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 985 | "Check shelf dip switches.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | return; |
| 987 | } |
| 988 | |
| 989 | sysminor = SYSMINOR(aoemajor, h->minor); |
ecashin@coraid.com | fc458dc | 2005-04-18 22:00:17 -0700 | [diff] [blame] | 990 | if (sysminor * AOE_PARTITIONS + AOE_PARTITIONS > MINORMASK) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 991 | printk(KERN_INFO "aoe: e%ld.%d: minor number too large\n", |
ecashin@coraid.com | fc458dc | 2005-04-18 22:00:17 -0700 | [diff] [blame] | 992 | aoemajor, (int) h->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | return; |
| 994 | } |
| 995 | |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 996 | n = be16_to_cpu(ch->bufcnt); |
Ed L. Cashin | 7df620d | 2008-02-08 04:20:07 -0800 | [diff] [blame] | 997 | if (n > aoe_maxout) /* keep it reasonable */ |
| 998 | n = aoe_maxout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1000 | d = aoedev_by_sysminor_m(sysminor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | if (d == NULL) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 1002 | printk(KERN_INFO "aoe: device sysminor_m failure\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | return; |
| 1004 | } |
| 1005 | |
| 1006 | spin_lock_irqsave(&d->lock, flags); |
| 1007 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1008 | t = gettgt(d, h->src); |
| 1009 | if (!t) { |
| 1010 | t = addtgt(d, h->src, n); |
| 1011 | if (!t) { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1012 | spin_unlock_irqrestore(&d->lock, flags); |
| 1013 | return; |
| 1014 | } |
| 1015 | } |
| 1016 | ifp = getif(t, skb->dev); |
| 1017 | if (!ifp) { |
| 1018 | ifp = addif(t, skb->dev); |
| 1019 | if (!ifp) { |
| 1020 | printk(KERN_INFO |
| 1021 | "aoe: device addif failure; " |
| 1022 | "too many interfaces?\n"); |
| 1023 | spin_unlock_irqrestore(&d->lock, flags); |
| 1024 | return; |
| 1025 | } |
| 1026 | } |
| 1027 | if (ifp->maxbcnt) { |
| 1028 | n = ifp->nd->mtu; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 1029 | n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr); |
| 1030 | n /= 512; |
| 1031 | if (n > ch->scnt) |
| 1032 | n = ch->scnt; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 1033 | n = n ? n * 512 : DEFAULTBCNT; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1034 | if (n != ifp->maxbcnt) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 1035 | printk(KERN_INFO |
Harvey Harrison | 411c41e | 2008-11-25 00:40:37 -0800 | [diff] [blame] | 1036 | "aoe: e%ld.%d: setting %d%s%s:%pm\n", |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1037 | d->aoemajor, d->aoeminor, n, |
| 1038 | " byte data frames on ", ifp->nd->name, |
Harvey Harrison | 411c41e | 2008-11-25 00:40:37 -0800 | [diff] [blame] | 1039 | t->addr); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1040 | ifp->maxbcnt = n; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 1041 | } |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 1042 | } |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 1043 | |
| 1044 | /* don't change users' perspective */ |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1045 | if (d->nopen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | spin_unlock_irqrestore(&d->lock, flags); |
| 1047 | return; |
| 1048 | } |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 1049 | d->fw_ver = be16_to_cpu(ch->fwver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1051 | sl = aoecmd_ata_id(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
| 1053 | spin_unlock_irqrestore(&d->lock, flags); |
| 1054 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 1055 | if (sl) { |
| 1056 | struct sk_buff_head queue; |
| 1057 | __skb_queue_head_init(&queue); |
| 1058 | __skb_queue_tail(&queue, sl); |
| 1059 | aoenet_xmit(&queue); |
| 1060 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1063 | void |
| 1064 | aoecmd_cleanslate(struct aoedev *d) |
| 1065 | { |
| 1066 | struct aoetgt **t, **te; |
| 1067 | struct aoeif *p, *e; |
| 1068 | |
| 1069 | d->mintimer = MINTIMER; |
| 1070 | |
| 1071 | t = d->targets; |
| 1072 | te = t + NTARGETS; |
| 1073 | for (; t < te && *t; t++) { |
| 1074 | (*t)->maxout = (*t)->nframes; |
| 1075 | p = (*t)->ifs; |
| 1076 | e = p + NAOEIFS; |
| 1077 | for (; p < e; p++) { |
| 1078 | p->lostjumbo = 0; |
| 1079 | p->lost = 0; |
| 1080 | p->maxbcnt = DEFAULTBCNT; |
| 1081 | } |
| 1082 | } |
| 1083 | } |