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