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, |
| 352 | "%15s e%ld.%d oldtag=%08x@%08lx newtag=%08x " |
| 353 | "s=%012llx d=%012llx nout=%d\n", |
| 354 | "retransmit", d->aoemajor, d->aoeminor, f->tag, jiffies, n, |
Ed L. Cashin | 1eb0da4 | 2008-02-08 04:20:01 -0800 | [diff] [blame] | 355 | mac_addr(h->src), |
| 356 | mac_addr(h->dst), t->nout); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 357 | aoechr_error(buf); |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | f->tag = n; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 360 | h->tag = cpu_to_be32(n); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 361 | memcpy(h->dst, t->addr, sizeof h->dst); |
| 362 | memcpy(h->src, t->ifp->nd->dev_addr, sizeof h->src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 364 | switch (ah->cmdstat) { |
| 365 | default: |
| 366 | break; |
| 367 | case WIN_READ: |
| 368 | case WIN_READ_EXT: |
| 369 | case WIN_WRITE: |
| 370 | case WIN_WRITE_EXT: |
| 371 | put_lba(ah, f->lba); |
| 372 | |
| 373 | n = f->bcnt; |
| 374 | if (n > DEFAULTBCNT) |
| 375 | n = DEFAULTBCNT; |
| 376 | ah->scnt = n >> 9; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 377 | if (ah->aflags & AOEAFL_WRITE) { |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 378 | skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr), |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 379 | offset_in_page(f->bufaddr), n); |
| 380 | skb->len = sizeof *h + sizeof *ah + n; |
| 381 | skb->data_len = n; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 382 | } |
| 383 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 384 | skb->dev = t->ifp->nd; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 385 | skb = skb_clone(skb, GFP_ATOMIC); |
| 386 | if (skb == NULL) |
| 387 | return; |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 388 | __skb_queue_tail(&d->sendq, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static int |
| 392 | tsince(int tag) |
| 393 | { |
| 394 | int n; |
| 395 | |
| 396 | n = jiffies & 0xffff; |
| 397 | n -= tag & 0xffff; |
| 398 | if (n < 0) |
| 399 | n += 1<<16; |
| 400 | return n; |
| 401 | } |
| 402 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 403 | static struct aoeif * |
| 404 | getif(struct aoetgt *t, struct net_device *nd) |
| 405 | { |
| 406 | struct aoeif *p, *e; |
| 407 | |
| 408 | p = t->ifs; |
| 409 | e = p + NAOEIFS; |
| 410 | for (; p < e; p++) |
| 411 | if (p->nd == nd) |
| 412 | return p; |
| 413 | return NULL; |
| 414 | } |
| 415 | |
| 416 | static struct aoeif * |
| 417 | addif(struct aoetgt *t, struct net_device *nd) |
| 418 | { |
| 419 | struct aoeif *p; |
| 420 | |
| 421 | p = getif(t, NULL); |
| 422 | if (!p) |
| 423 | return NULL; |
| 424 | p->nd = nd; |
| 425 | p->maxbcnt = DEFAULTBCNT; |
| 426 | p->lost = 0; |
| 427 | p->lostjumbo = 0; |
| 428 | return p; |
| 429 | } |
| 430 | |
| 431 | static void |
| 432 | ejectif(struct aoetgt *t, struct aoeif *ifp) |
| 433 | { |
| 434 | struct aoeif *e; |
| 435 | ulong n; |
| 436 | |
| 437 | e = t->ifs + NAOEIFS - 1; |
| 438 | n = (e - ifp) * sizeof *ifp; |
| 439 | memmove(ifp, ifp+1, n); |
| 440 | e->nd = NULL; |
| 441 | } |
| 442 | |
| 443 | static int |
| 444 | sthtith(struct aoedev *d) |
| 445 | { |
| 446 | struct frame *f, *e, *nf; |
| 447 | struct sk_buff *skb; |
| 448 | struct aoetgt *ht = *d->htgt; |
| 449 | |
| 450 | f = ht->frames; |
| 451 | e = f + ht->nframes; |
| 452 | for (; f < e; f++) { |
| 453 | if (f->tag == FREETAG) |
| 454 | continue; |
| 455 | nf = freeframe(d); |
| 456 | if (!nf) |
| 457 | return 0; |
| 458 | skb = nf->skb; |
| 459 | *nf = *f; |
| 460 | f->skb = skb; |
| 461 | f->tag = FREETAG; |
| 462 | nf->waited = 0; |
| 463 | ht->nout--; |
| 464 | (*d->tgt)->nout++; |
| 465 | resend(d, *d->tgt, nf); |
| 466 | } |
| 467 | /* he's clean, he's useless. take away his interfaces */ |
| 468 | memset(ht->ifs, 0, sizeof ht->ifs); |
| 469 | d->htgt = NULL; |
| 470 | return 1; |
| 471 | } |
| 472 | |
| 473 | static inline unsigned char |
| 474 | ata_scnt(unsigned char *packet) { |
| 475 | struct aoe_hdr *h; |
| 476 | struct aoe_atahdr *ah; |
| 477 | |
| 478 | h = (struct aoe_hdr *) packet; |
| 479 | ah = (struct aoe_atahdr *) (h+1); |
| 480 | return ah->scnt; |
| 481 | } |
| 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | static void |
| 484 | rexmit_timer(ulong vp) |
| 485 | { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 486 | struct sk_buff_head queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | struct aoedev *d; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 488 | struct aoetgt *t, **tt, **te; |
| 489 | struct aoeif *ifp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | struct frame *f, *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | register long timeout; |
| 492 | ulong flags, n; |
| 493 | |
| 494 | d = (struct aoedev *) vp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | /* timeout is always ~150% of the moving average */ |
| 497 | timeout = d->rttavg; |
| 498 | timeout += timeout >> 1; |
| 499 | |
| 500 | spin_lock_irqsave(&d->lock, flags); |
| 501 | |
| 502 | if (d->flags & DEVFL_TKILL) { |
Ed L. Cashin | 1c6f3fc | 2006-01-25 13:54:44 -0500 | [diff] [blame] | 503 | spin_unlock_irqrestore(&d->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | return; |
| 505 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 506 | tt = d->targets; |
| 507 | te = tt + NTARGETS; |
| 508 | for (; tt < te && *tt; tt++) { |
| 509 | t = *tt; |
| 510 | f = t->frames; |
| 511 | e = f + t->nframes; |
| 512 | for (; f < e; f++) { |
| 513 | if (f->tag == FREETAG |
| 514 | || tsince(f->tag) < timeout) |
| 515 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | n = f->waited += timeout; |
| 517 | n /= HZ; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 518 | if (n > aoe_deadsecs) { |
| 519 | /* waited too long. device failure. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | aoedev_downdev(d); |
Ed L. Cashin | 1c6f3fc | 2006-01-25 13:54:44 -0500 | [diff] [blame] | 521 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 523 | |
| 524 | if (n > HELPWAIT /* see if another target can help */ |
| 525 | && (tt != d->targets || d->targets[1])) |
| 526 | d->htgt = tt; |
| 527 | |
| 528 | if (t->nout == t->maxout) { |
| 529 | if (t->maxout > 1) |
| 530 | t->maxout--; |
| 531 | t->lastwadj = jiffies; |
| 532 | } |
| 533 | |
| 534 | ifp = getif(t, f->skb->dev); |
| 535 | if (ifp && ++ifp->lost > (t->nframes << 1) |
| 536 | && (ifp != t->ifs || t->ifs[1].nd)) { |
| 537 | ejectif(t, ifp); |
| 538 | ifp = NULL; |
| 539 | } |
| 540 | |
| 541 | if (ata_scnt(skb_mac_header(f->skb)) > DEFAULTBCNT / 512 |
| 542 | && ifp && ++ifp->lostjumbo > (t->nframes << 1) |
| 543 | && ifp->maxbcnt != DEFAULTBCNT) { |
| 544 | printk(KERN_INFO |
| 545 | "aoe: e%ld.%d: " |
| 546 | "too many lost jumbo on " |
| 547 | "%s:%012llx - " |
| 548 | "falling back to %d frames.\n", |
| 549 | d->aoemajor, d->aoeminor, |
| 550 | ifp->nd->name, mac_addr(t->addr), |
| 551 | DEFAULTBCNT); |
| 552 | ifp->maxbcnt = 0; |
| 553 | } |
| 554 | resend(d, t, f); |
| 555 | } |
| 556 | |
| 557 | /* window check */ |
| 558 | if (t->nout == t->maxout |
| 559 | && t->maxout < t->nframes |
| 560 | && (jiffies - t->lastwadj)/HZ > 10) { |
| 561 | t->maxout++; |
| 562 | t->lastwadj = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 565 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 566 | if (!skb_queue_empty(&d->sendq)) { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 567 | n = d->rttavg <<= 1; |
| 568 | if (n > MAXTIMER) |
| 569 | d->rttavg = MAXTIMER; |
| 570 | } |
| 571 | |
| 572 | if (d->flags & DEVFL_KICKME || d->htgt) { |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 573 | d->flags &= ~DEVFL_KICKME; |
| 574 | aoecmd_work(d); |
| 575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 577 | __skb_queue_head_init(&queue); |
| 578 | skb_queue_splice_init(&d->sendq, &queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
| 580 | d->timer.expires = jiffies + TIMERTICK; |
| 581 | add_timer(&d->timer); |
| 582 | |
| 583 | spin_unlock_irqrestore(&d->lock, flags); |
| 584 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 585 | aoenet_xmit(&queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 588 | /* enters with d->lock held */ |
| 589 | void |
| 590 | aoecmd_work(struct aoedev *d) |
| 591 | { |
| 592 | struct buf *buf; |
| 593 | loop: |
| 594 | if (d->htgt && !sthtith(d)) |
| 595 | return; |
| 596 | if (d->inprocess == NULL) { |
| 597 | if (list_empty(&d->bufq)) |
| 598 | return; |
| 599 | buf = container_of(d->bufq.next, struct buf, bufs); |
| 600 | list_del(d->bufq.next); |
| 601 | d->inprocess = buf; |
| 602 | } |
| 603 | if (aoecmd_ata_rw(d)) |
| 604 | goto loop; |
| 605 | } |
| 606 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 607 | /* this function performs work that has been deferred until sleeping is OK |
| 608 | */ |
| 609 | void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 610 | aoecmd_sleepwork(struct work_struct *work) |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 611 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 612 | struct aoedev *d = container_of(work, struct aoedev, work); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 613 | |
| 614 | if (d->flags & DEVFL_GDALLOC) |
| 615 | aoeblk_gdalloc(d); |
| 616 | |
| 617 | if (d->flags & DEVFL_NEWSIZE) { |
| 618 | struct block_device *bd; |
| 619 | unsigned long flags; |
| 620 | u64 ssize; |
| 621 | |
| 622 | ssize = d->gd->capacity; |
| 623 | bd = bdget_disk(d->gd, 0); |
| 624 | |
| 625 | if (bd) { |
| 626 | mutex_lock(&bd->bd_inode->i_mutex); |
| 627 | i_size_write(bd->bd_inode, (loff_t)ssize<<9); |
| 628 | mutex_unlock(&bd->bd_inode->i_mutex); |
| 629 | bdput(bd); |
| 630 | } |
| 631 | spin_lock_irqsave(&d->lock, flags); |
| 632 | d->flags |= DEVFL_UP; |
| 633 | d->flags &= ~DEVFL_NEWSIZE; |
| 634 | spin_unlock_irqrestore(&d->lock, flags); |
| 635 | } |
| 636 | } |
| 637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | static void |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 639 | ataid_complete(struct aoedev *d, struct aoetgt *t, unsigned char *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
| 641 | u64 ssize; |
| 642 | u16 n; |
| 643 | |
| 644 | /* word 83: command set supported */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 645 | n = get_unaligned_le16(&id[83 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
| 647 | /* word 86: command set/feature enabled */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 648 | n |= get_unaligned_le16(&id[86 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
| 650 | if (n & (1<<10)) { /* bit 10: LBA 48 */ |
| 651 | d->flags |= DEVFL_EXT; |
| 652 | |
| 653 | /* word 100: number lba48 sectors */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 654 | ssize = get_unaligned_le64(&id[100 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
| 656 | /* set as in ide-disk.c:init_idedisk_capacity */ |
| 657 | d->geo.cylinders = ssize; |
| 658 | d->geo.cylinders /= (255 * 63); |
| 659 | d->geo.heads = 255; |
| 660 | d->geo.sectors = 63; |
| 661 | } else { |
| 662 | d->flags &= ~DEVFL_EXT; |
| 663 | |
| 664 | /* number lba28 sectors */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 665 | ssize = get_unaligned_le32(&id[60 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | /* NOTE: obsolete in ATA 6 */ |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 668 | d->geo.cylinders = get_unaligned_le16(&id[54 << 1]); |
| 669 | d->geo.heads = get_unaligned_le16(&id[55 << 1]); |
| 670 | d->geo.sectors = get_unaligned_le16(&id[56 << 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | } |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 672 | |
| 673 | if (d->ssize != ssize) |
Ed L. Cashin | 1d75981 | 2008-02-08 04:20:08 -0800 | [diff] [blame] | 674 | printk(KERN_INFO |
| 675 | "aoe: %012llx e%ld.%d v%04x has %llu sectors\n", |
Ed L. Cashin | 1eb0da4 | 2008-02-08 04:20:01 -0800 | [diff] [blame] | 676 | mac_addr(t->addr), |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 677 | d->aoemajor, d->aoeminor, |
| 678 | d->fw_ver, (long long)ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | d->ssize = ssize; |
| 680 | d->geo.start = 0; |
Ed L. Cashin | 6b9699b | 2008-02-08 04:20:06 -0800 | [diff] [blame] | 681 | if (d->flags & (DEVFL_GDALLOC|DEVFL_NEWSIZE)) |
| 682 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | if (d->gd != NULL) { |
| 684 | d->gd->capacity = ssize; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 685 | d->flags |= DEVFL_NEWSIZE; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 686 | } else |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 687 | d->flags |= DEVFL_GDALLOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | schedule_work(&d->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | static void |
| 692 | calc_rttavg(struct aoedev *d, int rtt) |
| 693 | { |
| 694 | register long n; |
| 695 | |
| 696 | n = rtt; |
Ed L. Cashin | dced3a0 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 697 | if (n < 0) { |
| 698 | n = -rtt; |
| 699 | if (n < MINTIMER) |
| 700 | n = MINTIMER; |
| 701 | else if (n > MAXTIMER) |
| 702 | n = MAXTIMER; |
| 703 | d->mintimer += (n - d->mintimer) >> 1; |
| 704 | } else if (n < d->mintimer) |
| 705 | n = d->mintimer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | else if (n > MAXTIMER) |
| 707 | n = MAXTIMER; |
| 708 | |
| 709 | /* g == .25; cf. Congestion Avoidance and Control, Jacobson & Karels; 1988 */ |
| 710 | n -= d->rttavg; |
| 711 | d->rttavg += n >> 2; |
| 712 | } |
| 713 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 714 | static struct aoetgt * |
| 715 | gettgt(struct aoedev *d, char *addr) |
| 716 | { |
| 717 | struct aoetgt **t, **e; |
| 718 | |
| 719 | t = d->targets; |
| 720 | e = t + NTARGETS; |
| 721 | for (; t < e && *t; t++) |
| 722 | if (memcmp((*t)->addr, addr, sizeof((*t)->addr)) == 0) |
| 723 | return *t; |
| 724 | return NULL; |
| 725 | } |
| 726 | |
| 727 | static inline void |
Linus Torvalds | 03054de | 2008-02-08 09:42:46 -0800 | [diff] [blame] | 728 | 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] | 729 | { |
| 730 | unsigned long n_sect = bio->bi_size >> 9; |
| 731 | const int rw = bio_data_dir(bio); |
Jens Axboe | 28f1370 | 2008-05-07 10:15:46 +0200 | [diff] [blame] | 732 | struct hd_struct *part; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 733 | |
Jens Axboe | 28f1370 | 2008-05-07 10:15:46 +0200 | [diff] [blame] | 734 | part = get_part(disk, sector); |
| 735 | all_stat_inc(disk, part, ios[rw], sector); |
| 736 | all_stat_add(disk, part, ticks[rw], duration, sector); |
| 737 | all_stat_add(disk, part, sectors[rw], n_sect, sector); |
| 738 | all_stat_add(disk, part, io_ticks, duration, sector); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | void |
| 742 | aoecmd_ata_rsp(struct sk_buff *skb) |
| 743 | { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 744 | struct sk_buff_head queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | struct aoedev *d; |
Ed L. Cashin | ddec63e | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 746 | struct aoe_hdr *hin, *hout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | struct aoe_atahdr *ahin, *ahout; |
| 748 | struct frame *f; |
| 749 | struct buf *buf; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 750 | struct aoetgt *t; |
| 751 | struct aoeif *ifp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | register long n; |
| 753 | ulong flags; |
| 754 | char ebuf[128]; |
ecashin@coraid.com | 32465c6 | 2005-04-18 22:00:18 -0700 | [diff] [blame] | 755 | u16 aoemajor; |
| 756 | |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 757 | hin = (struct aoe_hdr *) skb_mac_header(skb); |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 758 | aoemajor = get_unaligned_be16(&hin->major); |
ecashin@coraid.com | 32465c6 | 2005-04-18 22:00:18 -0700 | [diff] [blame] | 759 | d = aoedev_by_aoeaddr(aoemajor, hin->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | if (d == NULL) { |
| 761 | snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response " |
| 762 | "for unknown device %d.%d\n", |
ecashin@coraid.com | 32465c6 | 2005-04-18 22:00:18 -0700 | [diff] [blame] | 763 | aoemajor, hin->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | aoechr_error(ebuf); |
| 765 | return; |
| 766 | } |
| 767 | |
| 768 | spin_lock_irqsave(&d->lock, flags); |
| 769 | |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 770 | n = get_unaligned_be32(&hin->tag); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 771 | t = gettgt(d, hin->src); |
| 772 | if (t == NULL) { |
| 773 | printk(KERN_INFO "aoe: can't find target e%ld.%d:%012llx\n", |
Ed L. Cashin | 1eb0da4 | 2008-02-08 04:20:01 -0800 | [diff] [blame] | 774 | d->aoemajor, d->aoeminor, mac_addr(hin->src)); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 775 | spin_unlock_irqrestore(&d->lock, flags); |
| 776 | return; |
| 777 | } |
| 778 | f = getframe(t, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | if (f == NULL) { |
Ed L. Cashin | dced3a0 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 780 | calc_rttavg(d, -tsince(n)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | spin_unlock_irqrestore(&d->lock, flags); |
| 782 | snprintf(ebuf, sizeof ebuf, |
| 783 | "%15s e%d.%d tag=%08x@%08lx\n", |
| 784 | "unexpected rsp", |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 785 | get_unaligned_be16(&hin->major), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | hin->minor, |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 787 | get_unaligned_be32(&hin->tag), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | jiffies); |
| 789 | aoechr_error(ebuf); |
| 790 | return; |
| 791 | } |
| 792 | |
| 793 | calc_rttavg(d, tsince(f->tag)); |
| 794 | |
| 795 | ahin = (struct aoe_atahdr *) (hin+1); |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 796 | hout = (struct aoe_hdr *) skb_mac_header(f->skb); |
Ed L. Cashin | ddec63e | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 797 | ahout = (struct aoe_atahdr *) (hout+1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | buf = f->buf; |
| 799 | |
| 800 | if (ahin->cmdstat & 0xa9) { /* these bits cleared on success */ |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 801 | printk(KERN_ERR |
Ed L. Cashin | 1d75981 | 2008-02-08 04:20:08 -0800 | [diff] [blame] | 802 | "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] | 803 | ahout->cmdstat, ahin->cmdstat, |
| 804 | d->aoemajor, d->aoeminor); |
| 805 | if (buf) |
| 806 | buf->flags |= BUFFL_FAIL; |
| 807 | } else { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 808 | if (d->htgt && t == *d->htgt) /* I'll help myself, thank you. */ |
| 809 | d->htgt = NULL; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 810 | n = ahout->scnt << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | switch (ahout->cmdstat) { |
| 812 | case WIN_READ: |
| 813 | case WIN_READ_EXT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | if (skb->len - sizeof *hin - sizeof *ahin < n) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 815 | printk(KERN_ERR |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 816 | "aoe: %s. skb->len=%d need=%ld\n", |
| 817 | "runt data size in read", skb->len, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | /* fail frame f? just returning will rexmit. */ |
| 819 | spin_unlock_irqrestore(&d->lock, flags); |
| 820 | return; |
| 821 | } |
| 822 | memcpy(f->bufaddr, ahin+1, n); |
| 823 | case WIN_WRITE: |
| 824 | case WIN_WRITE_EXT: |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 825 | ifp = getif(t, skb->dev); |
| 826 | if (ifp) { |
| 827 | ifp->lost = 0; |
Ed L. Cashin | 6bb6285 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 828 | if (n > DEFAULTBCNT) |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 829 | ifp->lostjumbo = 0; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 830 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 831 | if (f->bcnt -= n) { |
| 832 | f->lba += n >> 9; |
| 833 | f->bufaddr += n; |
| 834 | resend(d, t, f); |
| 835 | goto xmit; |
| 836 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | break; |
| 838 | case WIN_IDENTIFY: |
| 839 | if (skb->len - sizeof *hin - sizeof *ahin < 512) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 840 | printk(KERN_INFO |
| 841 | "aoe: runt data size in ataid. skb->len=%d\n", |
Ed L. Cashin | 6bb6285 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 842 | skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | spin_unlock_irqrestore(&d->lock, flags); |
| 844 | return; |
| 845 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 846 | ataid_complete(d, t, (char *) (ahin+1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | break; |
| 848 | default: |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 849 | printk(KERN_INFO |
| 850 | "aoe: unrecognized ata command %2.2Xh for %d.%d\n", |
Ed L. Cashin | 6bb6285 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 851 | ahout->cmdstat, |
Harvey Harrison | f885f8d | 2008-04-29 01:03:30 -0700 | [diff] [blame] | 852 | get_unaligned_be16(&hin->major), |
Ed L. Cashin | 6bb6285 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 853 | hin->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 857 | if (buf && --buf->nframesout == 0 && buf->resid == 0) { |
Linus Torvalds | 03054de | 2008-02-08 09:42:46 -0800 | [diff] [blame] | 858 | diskstats(d->gd, buf->bio, jiffies - buf->stime, buf->sector); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 859 | n = (buf->flags & BUFFL_FAIL) ? -EIO : 0; |
| 860 | bio_endio(buf->bio, n); |
| 861 | mempool_free(buf, d->bufpool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | f->buf = NULL; |
| 865 | f->tag = FREETAG; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 866 | t->nout--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
| 868 | aoecmd_work(d); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 869 | xmit: |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 870 | __skb_queue_head_init(&queue); |
| 871 | skb_queue_splice_init(&d->sendq, &queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
| 873 | spin_unlock_irqrestore(&d->lock, flags); |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 874 | aoenet_xmit(&queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | void |
| 878 | aoecmd_cfg(ushort aoemajor, unsigned char aoeminor) |
| 879 | { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 880 | struct sk_buff_head queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 882 | __skb_queue_head_init(&queue); |
| 883 | aoecmd_cfg_pkts(aoemajor, aoeminor, &queue); |
| 884 | aoenet_xmit(&queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 887 | struct sk_buff * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | aoecmd_ata_id(struct aoedev *d) |
| 889 | { |
| 890 | struct aoe_hdr *h; |
| 891 | struct aoe_atahdr *ah; |
| 892 | struct frame *f; |
| 893 | struct sk_buff *skb; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 894 | struct aoetgt *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 896 | f = freeframe(d); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 897 | if (f == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | return NULL; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 899 | |
| 900 | t = *d->tgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
| 902 | /* initialize the headers & frame */ |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 903 | skb = f->skb; |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 904 | h = (struct aoe_hdr *) skb_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | ah = (struct aoe_atahdr *) (h+1); |
Ed L. Cashin | 19900cd | 2006-12-22 01:09:21 -0800 | [diff] [blame] | 906 | skb_put(skb, sizeof *h + sizeof *ah); |
| 907 | memset(h, 0, skb->len); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 908 | f->tag = aoehdr_atainit(d, t, h); |
| 909 | t->nout++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | f->waited = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | /* set up ata header */ |
| 913 | ah->scnt = 1; |
| 914 | ah->cmdstat = WIN_IDENTIFY; |
| 915 | ah->lba3 = 0xa0; |
| 916 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 917 | skb->dev = t->ifp->nd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 919 | d->rttavg = MAXTIMER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | d->timer.function = rexmit_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 922 | return skb_clone(skb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 925 | static struct aoetgt * |
| 926 | addtgt(struct aoedev *d, char *addr, ulong nframes) |
| 927 | { |
| 928 | struct aoetgt *t, **tt, **te; |
| 929 | struct frame *f, *e; |
| 930 | |
| 931 | tt = d->targets; |
| 932 | te = tt + NTARGETS; |
| 933 | for (; tt < te && *tt; tt++) |
| 934 | ; |
| 935 | |
Ed L. Cashin | 578c4aa | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 936 | if (tt == te) { |
| 937 | printk(KERN_INFO |
| 938 | "aoe: device addtgt failure; too many targets\n"); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 939 | return NULL; |
Ed L. Cashin | 578c4aa | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 940 | } |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 941 | t = kcalloc(1, sizeof *t, GFP_ATOMIC); |
| 942 | f = kcalloc(nframes, sizeof *f, GFP_ATOMIC); |
Ed L. Cashin | 578c4aa | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 943 | if (!t || !f) { |
| 944 | kfree(f); |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 945 | kfree(t); |
Ed L. Cashin | 578c4aa | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 946 | printk(KERN_INFO "aoe: cannot allocate memory to add target\n"); |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 947 | return NULL; |
| 948 | } |
| 949 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 950 | t->nframes = nframes; |
| 951 | t->frames = f; |
| 952 | e = f + nframes; |
Ed L. Cashin | 9bb237b | 2008-02-08 04:20:05 -0800 | [diff] [blame] | 953 | for (; f < e; f++) |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 954 | f->tag = FREETAG; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 955 | memcpy(t->addr, addr, sizeof t->addr); |
| 956 | t->ifp = t->ifs; |
| 957 | t->maxout = t->nframes; |
| 958 | return *tt = t; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 959 | } |
| 960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | void |
| 962 | aoecmd_cfg_rsp(struct sk_buff *skb) |
| 963 | { |
| 964 | struct aoedev *d; |
| 965 | struct aoe_hdr *h; |
| 966 | struct aoe_cfghdr *ch; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 967 | struct aoetgt *t; |
| 968 | struct aoeif *ifp; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 969 | ulong flags, sysminor, aoemajor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | struct sk_buff *sl; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 971 | u16 n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
Ed L. Cashin | abdbf94 | 2007-10-16 23:27:03 -0700 | [diff] [blame] | 973 | h = (struct aoe_hdr *) skb_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | ch = (struct aoe_cfghdr *) (h+1); |
| 975 | |
| 976 | /* |
| 977 | * Enough people have their dip switches set backwards to |
| 978 | * warrant a loud message for this special case. |
| 979 | */ |
Harvey Harrison | 823ed72 | 2008-07-04 09:28:32 +0200 | [diff] [blame] | 980 | aoemajor = get_unaligned_be16(&h->major); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | if (aoemajor == 0xfff) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 982 | printk(KERN_ERR "aoe: Warning: shelf address is all ones. " |
Ed L. Cashin | 6bb6285 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 983 | "Check shelf dip switches.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | return; |
| 985 | } |
| 986 | |
| 987 | sysminor = SYSMINOR(aoemajor, h->minor); |
ecashin@coraid.com | fc458dc | 2005-04-18 22:00:17 -0700 | [diff] [blame] | 988 | if (sysminor * AOE_PARTITIONS + AOE_PARTITIONS > MINORMASK) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 989 | 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] | 990 | aoemajor, (int) h->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | return; |
| 992 | } |
| 993 | |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 994 | n = be16_to_cpu(ch->bufcnt); |
Ed L. Cashin | 7df620d | 2008-02-08 04:20:07 -0800 | [diff] [blame] | 995 | if (n > aoe_maxout) /* keep it reasonable */ |
| 996 | n = aoe_maxout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 998 | d = aoedev_by_sysminor_m(sysminor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | if (d == NULL) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 1000 | printk(KERN_INFO "aoe: device sysminor_m failure\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | spin_lock_irqsave(&d->lock, flags); |
| 1005 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1006 | t = gettgt(d, h->src); |
| 1007 | if (!t) { |
| 1008 | t = addtgt(d, h->src, n); |
| 1009 | if (!t) { |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1010 | spin_unlock_irqrestore(&d->lock, flags); |
| 1011 | return; |
| 1012 | } |
| 1013 | } |
| 1014 | ifp = getif(t, skb->dev); |
| 1015 | if (!ifp) { |
| 1016 | ifp = addif(t, skb->dev); |
| 1017 | if (!ifp) { |
| 1018 | printk(KERN_INFO |
| 1019 | "aoe: device addif failure; " |
| 1020 | "too many interfaces?\n"); |
| 1021 | spin_unlock_irqrestore(&d->lock, flags); |
| 1022 | return; |
| 1023 | } |
| 1024 | } |
| 1025 | if (ifp->maxbcnt) { |
| 1026 | n = ifp->nd->mtu; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 1027 | n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr); |
| 1028 | n /= 512; |
| 1029 | if (n > ch->scnt) |
| 1030 | n = ch->scnt; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 1031 | n = n ? n * 512 : DEFAULTBCNT; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1032 | if (n != ifp->maxbcnt) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 1033 | printk(KERN_INFO |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1034 | "aoe: e%ld.%d: setting %d%s%s:%012llx\n", |
| 1035 | d->aoemajor, d->aoeminor, n, |
| 1036 | " byte data frames on ", ifp->nd->name, |
Ed L. Cashin | 1eb0da4 | 2008-02-08 04:20:01 -0800 | [diff] [blame] | 1037 | mac_addr(t->addr)); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1038 | ifp->maxbcnt = n; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 1039 | } |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 1040 | } |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 1041 | |
| 1042 | /* don't change users' perspective */ |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1043 | if (d->nopen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | spin_unlock_irqrestore(&d->lock, flags); |
| 1045 | return; |
| 1046 | } |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 1047 | d->fw_ver = be16_to_cpu(ch->fwver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1049 | sl = aoecmd_ata_id(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
| 1051 | spin_unlock_irqrestore(&d->lock, flags); |
| 1052 | |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 1053 | if (sl) { |
| 1054 | struct sk_buff_head queue; |
| 1055 | __skb_queue_head_init(&queue); |
| 1056 | __skb_queue_tail(&queue, sl); |
| 1057 | aoenet_xmit(&queue); |
| 1058 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 1061 | void |
| 1062 | aoecmd_cleanslate(struct aoedev *d) |
| 1063 | { |
| 1064 | struct aoetgt **t, **te; |
| 1065 | struct aoeif *p, *e; |
| 1066 | |
| 1067 | d->mintimer = MINTIMER; |
| 1068 | |
| 1069 | t = d->targets; |
| 1070 | te = t + NTARGETS; |
| 1071 | for (; t < te && *t; t++) { |
| 1072 | (*t)->maxout = (*t)->nframes; |
| 1073 | p = (*t)->ifs; |
| 1074 | e = p + NAOEIFS; |
| 1075 | for (; p < e; p++) { |
| 1076 | p->lostjumbo = 0; |
| 1077 | p->lost = 0; |
| 1078 | p->maxbcnt = DEFAULTBCNT; |
| 1079 | } |
| 1080 | } |
| 1081 | } |