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