Ed L. Cashin | 2611464 | 2006-09-20 14:36:48 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2006 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 | 475172f | 2005-09-29 12:47:40 -0400 | [diff] [blame] | 12 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "aoe.h" |
| 14 | |
| 15 | #define TIMERTICK (HZ / 10) |
| 16 | #define MINTIMER (2 * TIMERTICK) |
| 17 | #define MAXTIMER (HZ << 1) |
Ed L. Cashin | b751e8b | 2006-09-20 14:36:50 -0400 | [diff] [blame] | 18 | |
| 19 | static int aoe_deadsecs = 60 * 3; |
| 20 | module_param(aoe_deadsecs, int, 0644); |
| 21 | MODULE_PARM_DESC(aoe_deadsecs, "After aoe_deadsecs seconds, give up and fail dev."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 23 | struct sk_buff * |
| 24 | new_skb(ulong len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { |
| 26 | struct sk_buff *skb; |
| 27 | |
| 28 | skb = alloc_skb(len, GFP_ATOMIC); |
| 29 | if (skb) { |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 30 | skb_reset_mac_header(skb); |
Arnaldo Carvalho de Melo | c1d2bbe | 2007-04-10 20:45:18 -0700 | [diff] [blame] | 31 | skb_reset_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | skb->protocol = __constant_htons(ETH_P_AOE); |
| 33 | skb->priority = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | skb->next = skb->prev = NULL; |
| 35 | |
| 36 | /* tell the network layer not to perform IP checksums |
| 37 | * or to get the NIC to do it |
| 38 | */ |
| 39 | skb->ip_summed = CHECKSUM_NONE; |
| 40 | } |
| 41 | return skb; |
| 42 | } |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | static struct frame * |
| 45 | getframe(struct aoedev *d, int tag) |
| 46 | { |
| 47 | struct frame *f, *e; |
| 48 | |
| 49 | f = d->frames; |
| 50 | e = f + d->nframes; |
| 51 | for (; f<e; f++) |
| 52 | if (f->tag == tag) |
| 53 | return f; |
| 54 | return NULL; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Leave the top bit clear so we have tagspace for userland. |
| 59 | * The bottom 16 bits are the xmit tick for rexmit/rttavg processing. |
| 60 | * This driver reserves tag -1 to mean "unused frame." |
| 61 | */ |
| 62 | static int |
| 63 | newtag(struct aoedev *d) |
| 64 | { |
| 65 | register ulong n; |
| 66 | |
| 67 | n = jiffies & 0xffff; |
| 68 | return n |= (++d->lasttag & 0x7fff) << 16; |
| 69 | } |
| 70 | |
| 71 | static int |
| 72 | aoehdr_atainit(struct aoedev *d, struct aoe_hdr *h) |
| 73 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | u32 host_tag = newtag(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | memcpy(h->src, d->ifp->dev_addr, sizeof h->src); |
| 77 | memcpy(h->dst, d->addr, sizeof h->dst); |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 78 | h->type = __constant_cpu_to_be16(ETH_P_AOE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | h->verfl = AOE_HVER; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 80 | h->major = cpu_to_be16(d->aoemajor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | h->minor = d->aoeminor; |
| 82 | h->cmd = AOECMD_ATA; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 83 | h->tag = cpu_to_be32(host_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | return host_tag; |
| 86 | } |
| 87 | |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 88 | static inline void |
| 89 | put_lba(struct aoe_atahdr *ah, sector_t lba) |
| 90 | { |
| 91 | ah->lba0 = lba; |
| 92 | ah->lba1 = lba >>= 8; |
| 93 | ah->lba2 = lba >>= 8; |
| 94 | ah->lba3 = lba >>= 8; |
| 95 | ah->lba4 = lba >>= 8; |
| 96 | ah->lba5 = lba >>= 8; |
| 97 | } |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | static void |
| 100 | aoecmd_ata_rw(struct aoedev *d, struct frame *f) |
| 101 | { |
| 102 | struct aoe_hdr *h; |
| 103 | struct aoe_atahdr *ah; |
| 104 | struct buf *buf; |
| 105 | struct sk_buff *skb; |
| 106 | ulong bcnt; |
| 107 | register sector_t sector; |
| 108 | char writebit, extbit; |
| 109 | |
| 110 | writebit = 0x10; |
| 111 | extbit = 0x4; |
| 112 | |
| 113 | buf = d->inprocess; |
| 114 | |
| 115 | sector = buf->sector; |
| 116 | bcnt = buf->bv_resid; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 117 | if (bcnt > d->maxbcnt) |
| 118 | bcnt = d->maxbcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | /* initialize the headers & frame */ |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 121 | skb = f->skb; |
Arnaldo Carvalho de Melo | 029720f | 2007-03-10 11:20:07 -0300 | [diff] [blame] | 122 | h = aoe_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | ah = (struct aoe_atahdr *) (h+1); |
Ed L. Cashin | 19900cd | 2006-12-22 01:09:21 -0800 | [diff] [blame] | 124 | skb_put(skb, sizeof *h + sizeof *ah); |
| 125 | memset(h, 0, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | f->tag = aoehdr_atainit(d, h); |
| 127 | f->waited = 0; |
| 128 | f->buf = buf; |
| 129 | f->bufaddr = buf->bufaddr; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 130 | f->bcnt = bcnt; |
| 131 | f->lba = sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | /* set up ata header */ |
| 134 | ah->scnt = bcnt >> 9; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 135 | put_lba(ah, sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | if (d->flags & DEVFL_EXT) { |
| 137 | ah->aflags |= AOEAFL_EXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } else { |
| 139 | extbit = 0; |
| 140 | ah->lba3 &= 0x0f; |
| 141 | ah->lba3 |= 0xe0; /* LBA bit + obsolete 0xa0 */ |
| 142 | } |
| 143 | |
| 144 | if (bio_data_dir(buf->bio) == WRITE) { |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 145 | skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr), |
| 146 | offset_in_page(f->bufaddr), bcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | ah->aflags |= AOEAFL_WRITE; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 148 | skb->len += bcnt; |
| 149 | skb->data_len = bcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } else { |
| 151 | writebit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | ah->cmdstat = WIN_READ | writebit | extbit; |
| 155 | |
| 156 | /* mark all tracking fields and load out */ |
| 157 | buf->nframesout += 1; |
| 158 | buf->bufaddr += bcnt; |
| 159 | buf->bv_resid -= bcnt; |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 160 | /* printk(KERN_DEBUG "aoe: bv_resid=%ld\n", buf->bv_resid); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | buf->resid -= bcnt; |
| 162 | buf->sector += bcnt >> 9; |
| 163 | if (buf->resid == 0) { |
| 164 | d->inprocess = NULL; |
| 165 | } else if (buf->bv_resid == 0) { |
| 166 | buf->bv++; |
Ed L. Cashin | 392e484 | 2006-09-20 14:36:50 -0400 | [diff] [blame] | 167 | WARN_ON(buf->bv->bv_len == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | buf->bv_resid = buf->bv->bv_len; |
| 169 | buf->bufaddr = page_address(buf->bv->bv_page) + buf->bv->bv_offset; |
| 170 | } |
| 171 | |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 172 | skb->dev = d->ifp; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 173 | skb = skb_clone(skb, GFP_ATOMIC); |
| 174 | if (skb == NULL) |
| 175 | return; |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 176 | if (d->sendq_hd) |
| 177 | d->sendq_tl->next = skb; |
| 178 | else |
| 179 | d->sendq_hd = skb; |
| 180 | d->sendq_tl = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 183 | /* some callers cannot sleep, and they can call this function, |
| 184 | * transmitting the packets later, when interrupts are on |
| 185 | */ |
| 186 | static struct sk_buff * |
| 187 | aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail) |
| 188 | { |
| 189 | struct aoe_hdr *h; |
| 190 | struct aoe_cfghdr *ch; |
| 191 | struct sk_buff *skb, *sl, *sl_tail; |
| 192 | struct net_device *ifp; |
| 193 | |
| 194 | sl = sl_tail = NULL; |
| 195 | |
| 196 | read_lock(&dev_base_lock); |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 197 | for_each_netdev(ifp) { |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 198 | dev_hold(ifp); |
| 199 | if (!is_aoe_netif(ifp)) |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 200 | goto cont; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 201 | |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 202 | skb = new_skb(sizeof *h + sizeof *ch); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 203 | if (skb == NULL) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 204 | printk(KERN_INFO "aoe: skb alloc failure\n"); |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 205 | goto cont; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 206 | } |
Ed L. Cashin | 19900cd | 2006-12-22 01:09:21 -0800 | [diff] [blame] | 207 | skb_put(skb, sizeof *h + sizeof *ch); |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 208 | skb->dev = ifp; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 209 | if (sl_tail == NULL) |
| 210 | sl_tail = skb; |
Arnaldo Carvalho de Melo | 029720f | 2007-03-10 11:20:07 -0300 | [diff] [blame] | 211 | h = aoe_hdr(skb); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 212 | memset(h, 0, sizeof *h + sizeof *ch); |
| 213 | |
| 214 | memset(h->dst, 0xff, sizeof h->dst); |
| 215 | memcpy(h->src, ifp->dev_addr, sizeof h->src); |
| 216 | h->type = __constant_cpu_to_be16(ETH_P_AOE); |
| 217 | h->verfl = AOE_HVER; |
| 218 | h->major = cpu_to_be16(aoemajor); |
| 219 | h->minor = aoeminor; |
| 220 | h->cmd = AOECMD_CFG; |
| 221 | |
| 222 | skb->next = sl; |
| 223 | sl = skb; |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 224 | cont: |
| 225 | dev_put(ifp); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 226 | } |
| 227 | read_unlock(&dev_base_lock); |
| 228 | |
| 229 | if (tail != NULL) |
| 230 | *tail = sl_tail; |
| 231 | return sl; |
| 232 | } |
| 233 | |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 234 | static struct frame * |
| 235 | freeframe(struct aoedev *d) |
| 236 | { |
| 237 | struct frame *f, *e; |
| 238 | int n = 0; |
| 239 | |
| 240 | f = d->frames; |
| 241 | e = f + d->nframes; |
| 242 | for (; f<e; f++) { |
| 243 | if (f->tag != FREETAG) |
| 244 | continue; |
| 245 | if (atomic_read(&skb_shinfo(f->skb)->dataref) == 1) { |
| 246 | skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0; |
Ed L. Cashin | 19900cd | 2006-12-22 01:09:21 -0800 | [diff] [blame] | 247 | skb_trim(f->skb, 0); |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 248 | return f; |
| 249 | } |
| 250 | n++; |
| 251 | } |
| 252 | if (n == d->nframes) /* wait for network layer */ |
| 253 | d->flags |= DEVFL_KICKME; |
| 254 | |
| 255 | return NULL; |
| 256 | } |
| 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | /* enters with d->lock held */ |
| 259 | void |
| 260 | aoecmd_work(struct aoedev *d) |
| 261 | { |
| 262 | struct frame *f; |
| 263 | struct buf *buf; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 264 | |
| 265 | if (d->flags & DEVFL_PAUSE) { |
| 266 | if (!aoedev_isbusy(d)) |
| 267 | d->sendq_hd = aoecmd_cfg_pkts(d->aoemajor, |
| 268 | d->aoeminor, &d->sendq_tl); |
| 269 | return; |
| 270 | } |
| 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | loop: |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 273 | f = freeframe(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | if (f == NULL) |
| 275 | return; |
| 276 | if (d->inprocess == NULL) { |
| 277 | if (list_empty(&d->bufq)) |
| 278 | return; |
| 279 | buf = container_of(d->bufq.next, struct buf, bufs); |
| 280 | list_del(d->bufq.next); |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 281 | /*printk(KERN_DEBUG "aoe: bi_size=%ld\n", buf->bio->bi_size); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | d->inprocess = buf; |
| 283 | } |
| 284 | aoecmd_ata_rw(d, f); |
| 285 | goto loop; |
| 286 | } |
| 287 | |
| 288 | static void |
| 289 | rexmit(struct aoedev *d, struct frame *f) |
| 290 | { |
| 291 | struct sk_buff *skb; |
| 292 | struct aoe_hdr *h; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 293 | struct aoe_atahdr *ah; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | char buf[128]; |
| 295 | u32 n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | n = newtag(d); |
| 298 | |
| 299 | snprintf(buf, sizeof buf, |
| 300 | "%15s e%ld.%ld oldtag=%08x@%08lx newtag=%08x\n", |
| 301 | "retransmit", |
| 302 | d->aoemajor, d->aoeminor, f->tag, jiffies, n); |
| 303 | aoechr_error(buf); |
| 304 | |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 305 | skb = f->skb; |
Arnaldo Carvalho de Melo | 029720f | 2007-03-10 11:20:07 -0300 | [diff] [blame] | 306 | h = aoe_hdr(skb); |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 307 | ah = (struct aoe_atahdr *) (h+1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | f->tag = n; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 309 | h->tag = cpu_to_be32(n); |
Ed L. Cashin | 2dd5e42 | 2006-01-19 13:46:25 -0500 | [diff] [blame] | 310 | memcpy(h->dst, d->addr, sizeof h->dst); |
| 311 | memcpy(h->src, d->ifp->dev_addr, sizeof h->src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 313 | n = DEFAULTBCNT / 512; |
| 314 | if (ah->scnt > n) { |
| 315 | ah->scnt = n; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 316 | if (ah->aflags & AOEAFL_WRITE) { |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 317 | skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr), |
| 318 | offset_in_page(f->bufaddr), DEFAULTBCNT); |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 319 | skb->len = sizeof *h + sizeof *ah + DEFAULTBCNT; |
| 320 | skb->data_len = DEFAULTBCNT; |
| 321 | } |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 322 | if (++d->lostjumbo > (d->nframes << 1)) |
| 323 | if (d->maxbcnt != DEFAULTBCNT) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 324 | printk(KERN_INFO "aoe: e%ld.%ld: too many lost jumbo on %s - using 1KB frames.\n", |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 325 | d->aoemajor, d->aoeminor, d->ifp->name); |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 326 | d->maxbcnt = DEFAULTBCNT; |
| 327 | d->flags |= DEVFL_MAXBCNT; |
| 328 | } |
| 329 | } |
| 330 | |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 331 | skb->dev = d->ifp; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 332 | skb = skb_clone(skb, GFP_ATOMIC); |
| 333 | if (skb == NULL) |
| 334 | return; |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 335 | if (d->sendq_hd) |
| 336 | d->sendq_tl->next = skb; |
| 337 | else |
| 338 | d->sendq_hd = skb; |
| 339 | d->sendq_tl = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | static int |
| 343 | tsince(int tag) |
| 344 | { |
| 345 | int n; |
| 346 | |
| 347 | n = jiffies & 0xffff; |
| 348 | n -= tag & 0xffff; |
| 349 | if (n < 0) |
| 350 | n += 1<<16; |
| 351 | return n; |
| 352 | } |
| 353 | |
| 354 | static void |
| 355 | rexmit_timer(ulong vp) |
| 356 | { |
| 357 | struct aoedev *d; |
| 358 | struct frame *f, *e; |
| 359 | struct sk_buff *sl; |
| 360 | register long timeout; |
| 361 | ulong flags, n; |
| 362 | |
| 363 | d = (struct aoedev *) vp; |
| 364 | sl = NULL; |
| 365 | |
| 366 | /* timeout is always ~150% of the moving average */ |
| 367 | timeout = d->rttavg; |
| 368 | timeout += timeout >> 1; |
| 369 | |
| 370 | spin_lock_irqsave(&d->lock, flags); |
| 371 | |
| 372 | if (d->flags & DEVFL_TKILL) { |
Ed L. Cashin | 1c6f3fc | 2006-01-25 13:54:44 -0500 | [diff] [blame] | 373 | spin_unlock_irqrestore(&d->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | return; |
| 375 | } |
| 376 | f = d->frames; |
| 377 | e = f + d->nframes; |
| 378 | for (; f<e; f++) { |
| 379 | if (f->tag != FREETAG && tsince(f->tag) >= timeout) { |
| 380 | n = f->waited += timeout; |
| 381 | n /= HZ; |
Ed L. Cashin | b751e8b | 2006-09-20 14:36:50 -0400 | [diff] [blame] | 382 | if (n > aoe_deadsecs) { /* waited too long for response */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | aoedev_downdev(d); |
Ed L. Cashin | 1c6f3fc | 2006-01-25 13:54:44 -0500 | [diff] [blame] | 384 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | rexmit(d, f); |
| 387 | } |
| 388 | } |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 389 | if (d->flags & DEVFL_KICKME) { |
| 390 | d->flags &= ~DEVFL_KICKME; |
| 391 | aoecmd_work(d); |
| 392 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
ecashin@coraid.com | a4b3836 | 2005-04-18 22:00:22 -0700 | [diff] [blame] | 394 | sl = d->sendq_hd; |
| 395 | d->sendq_hd = d->sendq_tl = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | if (sl) { |
| 397 | n = d->rttavg <<= 1; |
| 398 | if (n > MAXTIMER) |
| 399 | d->rttavg = MAXTIMER; |
| 400 | } |
| 401 | |
| 402 | d->timer.expires = jiffies + TIMERTICK; |
| 403 | add_timer(&d->timer); |
| 404 | |
| 405 | spin_unlock_irqrestore(&d->lock, flags); |
| 406 | |
| 407 | aoenet_xmit(sl); |
| 408 | } |
| 409 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 410 | /* this function performs work that has been deferred until sleeping is OK |
| 411 | */ |
| 412 | void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 413 | aoecmd_sleepwork(struct work_struct *work) |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 414 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 415 | struct aoedev *d = container_of(work, struct aoedev, work); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 416 | |
| 417 | if (d->flags & DEVFL_GDALLOC) |
| 418 | aoeblk_gdalloc(d); |
| 419 | |
| 420 | if (d->flags & DEVFL_NEWSIZE) { |
| 421 | struct block_device *bd; |
| 422 | unsigned long flags; |
| 423 | u64 ssize; |
| 424 | |
| 425 | ssize = d->gd->capacity; |
| 426 | bd = bdget_disk(d->gd, 0); |
| 427 | |
| 428 | if (bd) { |
| 429 | mutex_lock(&bd->bd_inode->i_mutex); |
| 430 | i_size_write(bd->bd_inode, (loff_t)ssize<<9); |
| 431 | mutex_unlock(&bd->bd_inode->i_mutex); |
| 432 | bdput(bd); |
| 433 | } |
| 434 | spin_lock_irqsave(&d->lock, flags); |
| 435 | d->flags |= DEVFL_UP; |
| 436 | d->flags &= ~DEVFL_NEWSIZE; |
| 437 | spin_unlock_irqrestore(&d->lock, flags); |
| 438 | } |
| 439 | } |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | static void |
| 442 | ataid_complete(struct aoedev *d, unsigned char *id) |
| 443 | { |
| 444 | u64 ssize; |
| 445 | u16 n; |
| 446 | |
| 447 | /* word 83: command set supported */ |
Ed L. Cashin | 475172f | 2005-09-29 12:47:40 -0400 | [diff] [blame] | 448 | n = le16_to_cpu(get_unaligned((__le16 *) &id[83<<1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | /* word 86: command set/feature enabled */ |
Ed L. Cashin | 475172f | 2005-09-29 12:47:40 -0400 | [diff] [blame] | 451 | n |= le16_to_cpu(get_unaligned((__le16 *) &id[86<<1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | if (n & (1<<10)) { /* bit 10: LBA 48 */ |
| 454 | d->flags |= DEVFL_EXT; |
| 455 | |
| 456 | /* word 100: number lba48 sectors */ |
Ed L. Cashin | 475172f | 2005-09-29 12:47:40 -0400 | [diff] [blame] | 457 | ssize = le64_to_cpu(get_unaligned((__le64 *) &id[100<<1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | /* set as in ide-disk.c:init_idedisk_capacity */ |
| 460 | d->geo.cylinders = ssize; |
| 461 | d->geo.cylinders /= (255 * 63); |
| 462 | d->geo.heads = 255; |
| 463 | d->geo.sectors = 63; |
| 464 | } else { |
| 465 | d->flags &= ~DEVFL_EXT; |
| 466 | |
| 467 | /* number lba28 sectors */ |
Ed L. Cashin | 475172f | 2005-09-29 12:47:40 -0400 | [diff] [blame] | 468 | ssize = le32_to_cpu(get_unaligned((__le32 *) &id[60<<1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | /* NOTE: obsolete in ATA 6 */ |
Ed L. Cashin | 475172f | 2005-09-29 12:47:40 -0400 | [diff] [blame] | 471 | d->geo.cylinders = le16_to_cpu(get_unaligned((__le16 *) &id[54<<1])); |
| 472 | d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1])); |
| 473 | d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 475 | |
| 476 | if (d->ssize != ssize) |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 477 | printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu sectors\n", |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 478 | (unsigned long long)mac_addr(d->addr), |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 479 | d->aoemajor, d->aoeminor, |
| 480 | d->fw_ver, (long long)ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | d->ssize = ssize; |
| 482 | d->geo.start = 0; |
| 483 | if (d->gd != NULL) { |
| 484 | d->gd->capacity = ssize; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 485 | d->flags |= DEVFL_NEWSIZE; |
| 486 | } else { |
| 487 | if (d->flags & DEVFL_GDALLOC) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 488 | printk(KERN_ERR "aoe: can't schedule work for e%lu.%lu, %s\n", |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 489 | d->aoemajor, d->aoeminor, |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 490 | "it's already on! This shouldn't happen.\n"); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 491 | return; |
| 492 | } |
| 493 | d->flags |= DEVFL_GDALLOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | schedule_work(&d->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static void |
| 499 | calc_rttavg(struct aoedev *d, int rtt) |
| 500 | { |
| 501 | register long n; |
| 502 | |
| 503 | n = rtt; |
Ed L. Cashin | dced3a0 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 504 | if (n < 0) { |
| 505 | n = -rtt; |
| 506 | if (n < MINTIMER) |
| 507 | n = MINTIMER; |
| 508 | else if (n > MAXTIMER) |
| 509 | n = MAXTIMER; |
| 510 | d->mintimer += (n - d->mintimer) >> 1; |
| 511 | } else if (n < d->mintimer) |
| 512 | n = d->mintimer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | else if (n > MAXTIMER) |
| 514 | n = MAXTIMER; |
| 515 | |
| 516 | /* g == .25; cf. Congestion Avoidance and Control, Jacobson & Karels; 1988 */ |
| 517 | n -= d->rttavg; |
| 518 | d->rttavg += n >> 2; |
| 519 | } |
| 520 | |
| 521 | void |
| 522 | aoecmd_ata_rsp(struct sk_buff *skb) |
| 523 | { |
| 524 | struct aoedev *d; |
Ed L. Cashin | ddec63e | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 525 | struct aoe_hdr *hin, *hout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | struct aoe_atahdr *ahin, *ahout; |
| 527 | struct frame *f; |
| 528 | struct buf *buf; |
| 529 | struct sk_buff *sl; |
| 530 | register long n; |
| 531 | ulong flags; |
| 532 | char ebuf[128]; |
ecashin@coraid.com | 32465c6 | 2005-04-18 22:00:18 -0700 | [diff] [blame] | 533 | u16 aoemajor; |
| 534 | |
Arnaldo Carvalho de Melo | 029720f | 2007-03-10 11:20:07 -0300 | [diff] [blame] | 535 | hin = aoe_hdr(skb); |
David S. Miller | 43ecf52 | 2007-03-01 18:30:08 -0800 | [diff] [blame] | 536 | aoemajor = be16_to_cpu(get_unaligned(&hin->major)); |
ecashin@coraid.com | 32465c6 | 2005-04-18 22:00:18 -0700 | [diff] [blame] | 537 | d = aoedev_by_aoeaddr(aoemajor, hin->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | if (d == NULL) { |
| 539 | snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response " |
| 540 | "for unknown device %d.%d\n", |
ecashin@coraid.com | 32465c6 | 2005-04-18 22:00:18 -0700 | [diff] [blame] | 541 | aoemajor, hin->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | aoechr_error(ebuf); |
| 543 | return; |
| 544 | } |
| 545 | |
| 546 | spin_lock_irqsave(&d->lock, flags); |
| 547 | |
David S. Miller | 43ecf52 | 2007-03-01 18:30:08 -0800 | [diff] [blame] | 548 | n = be32_to_cpu(get_unaligned(&hin->tag)); |
Ed L. Cashin | dced3a0 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 549 | f = getframe(d, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | if (f == NULL) { |
Ed L. Cashin | dced3a0 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 551 | calc_rttavg(d, -tsince(n)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | spin_unlock_irqrestore(&d->lock, flags); |
| 553 | snprintf(ebuf, sizeof ebuf, |
| 554 | "%15s e%d.%d tag=%08x@%08lx\n", |
| 555 | "unexpected rsp", |
David S. Miller | 43ecf52 | 2007-03-01 18:30:08 -0800 | [diff] [blame] | 556 | be16_to_cpu(get_unaligned(&hin->major)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | hin->minor, |
David S. Miller | 43ecf52 | 2007-03-01 18:30:08 -0800 | [diff] [blame] | 558 | be32_to_cpu(get_unaligned(&hin->tag)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | jiffies); |
| 560 | aoechr_error(ebuf); |
| 561 | return; |
| 562 | } |
| 563 | |
| 564 | calc_rttavg(d, tsince(f->tag)); |
| 565 | |
| 566 | ahin = (struct aoe_atahdr *) (hin+1); |
Arnaldo Carvalho de Melo | 029720f | 2007-03-10 11:20:07 -0300 | [diff] [blame] | 567 | hout = aoe_hdr(f->skb); |
Ed L. Cashin | ddec63e | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 568 | ahout = (struct aoe_atahdr *) (hout+1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | buf = f->buf; |
| 570 | |
Ed L. Cashin | 9d41965 | 2006-02-07 11:37:24 -0500 | [diff] [blame] | 571 | if (ahout->cmdstat == WIN_IDENTIFY) |
| 572 | d->flags &= ~DEVFL_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | if (ahin->cmdstat & 0xa9) { /* these bits cleared on success */ |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 574 | printk(KERN_ERR |
| 575 | "aoe: ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%ld\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | ahout->cmdstat, ahin->cmdstat, |
| 577 | d->aoemajor, d->aoeminor); |
| 578 | if (buf) |
| 579 | buf->flags |= BUFFL_FAIL; |
| 580 | } else { |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 581 | n = ahout->scnt << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | switch (ahout->cmdstat) { |
| 583 | case WIN_READ: |
| 584 | case WIN_READ_EXT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | if (skb->len - sizeof *hin - sizeof *ahin < n) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 586 | printk(KERN_ERR |
| 587 | "aoe: runt data size in read. skb->len=%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | skb->len); |
| 589 | /* fail frame f? just returning will rexmit. */ |
| 590 | spin_unlock_irqrestore(&d->lock, flags); |
| 591 | return; |
| 592 | } |
| 593 | memcpy(f->bufaddr, ahin+1, n); |
| 594 | case WIN_WRITE: |
| 595 | case WIN_WRITE_EXT: |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 596 | if (f->bcnt -= n) { |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 597 | skb = f->skb; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 598 | f->bufaddr += n; |
| 599 | put_lba(ahout, f->lba += ahout->scnt); |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 600 | n = f->bcnt; |
| 601 | if (n > DEFAULTBCNT) |
| 602 | n = DEFAULTBCNT; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 603 | ahout->scnt = n >> 9; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 604 | if (ahout->aflags & AOEAFL_WRITE) { |
| 605 | skb_fill_page_desc(skb, 0, |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 606 | virt_to_page(f->bufaddr), |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 607 | offset_in_page(f->bufaddr), n); |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 608 | skb->len = sizeof *hout + sizeof *ahout + n; |
| 609 | skb->data_len = n; |
| 610 | } |
Ed L. Cashin | ddec63e | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 611 | f->tag = newtag(d); |
| 612 | hout->tag = cpu_to_be32(f->tag); |
| 613 | skb->dev = d->ifp; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 614 | skb = skb_clone(skb, GFP_ATOMIC); |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 615 | spin_unlock_irqrestore(&d->lock, flags); |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 616 | if (skb) |
| 617 | aoenet_xmit(skb); |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 618 | return; |
| 619 | } |
| 620 | if (n > DEFAULTBCNT) |
| 621 | d->lostjumbo = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | break; |
| 623 | case WIN_IDENTIFY: |
| 624 | if (skb->len - sizeof *hin - sizeof *ahin < 512) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 625 | printk(KERN_INFO |
| 626 | "aoe: runt data size in ataid. skb->len=%d\n", |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 627 | skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | spin_unlock_irqrestore(&d->lock, flags); |
| 629 | return; |
| 630 | } |
| 631 | ataid_complete(d, (char *) (ahin+1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | break; |
| 633 | default: |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 634 | printk(KERN_INFO |
| 635 | "aoe: unrecognized ata command %2.2Xh for %d.%d\n", |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 636 | ahout->cmdstat, |
David S. Miller | 43ecf52 | 2007-03-01 18:30:08 -0800 | [diff] [blame] | 637 | be16_to_cpu(get_unaligned(&hin->major)), |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 638 | hin->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
| 642 | if (buf) { |
| 643 | buf->nframesout -= 1; |
| 644 | if (buf->nframesout == 0 && buf->resid == 0) { |
ecashin@coraid.com | 0c6f0e7 | 2005-04-18 22:00:22 -0700 | [diff] [blame] | 645 | unsigned long duration = jiffies - buf->start_time; |
| 646 | unsigned long n_sect = buf->bio->bi_size >> 9; |
| 647 | struct gendisk *disk = d->gd; |
Jens Axboe | 496456c | 2005-11-01 09:54:23 +0100 | [diff] [blame] | 648 | const int rw = bio_data_dir(buf->bio); |
ecashin@coraid.com | 0c6f0e7 | 2005-04-18 22:00:22 -0700 | [diff] [blame] | 649 | |
Jens Axboe | 496456c | 2005-11-01 09:54:23 +0100 | [diff] [blame] | 650 | disk_stat_inc(disk, ios[rw]); |
| 651 | disk_stat_add(disk, ticks[rw], duration); |
| 652 | disk_stat_add(disk, sectors[rw], n_sect); |
ecashin@coraid.com | 0c6f0e7 | 2005-04-18 22:00:22 -0700 | [diff] [blame] | 653 | disk_stat_add(disk, io_ticks, duration); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | n = (buf->flags & BUFFL_FAIL) ? -EIO : 0; |
| 655 | bio_endio(buf->bio, buf->bio->bi_size, n); |
| 656 | mempool_free(buf, d->bufpool); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | f->buf = NULL; |
| 661 | f->tag = FREETAG; |
| 662 | |
| 663 | aoecmd_work(d); |
ecashin@coraid.com | a4b3836 | 2005-04-18 22:00:22 -0700 | [diff] [blame] | 664 | sl = d->sendq_hd; |
| 665 | d->sendq_hd = d->sendq_tl = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | spin_unlock_irqrestore(&d->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | aoenet_xmit(sl); |
| 669 | } |
| 670 | |
| 671 | void |
| 672 | aoecmd_cfg(ushort aoemajor, unsigned char aoeminor) |
| 673 | { |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 674 | struct sk_buff *sl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 676 | sl = aoecmd_cfg_pkts(aoemajor, aoeminor, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
| 678 | aoenet_xmit(sl); |
| 679 | } |
| 680 | |
| 681 | /* |
| 682 | * Since we only call this in one place (and it only prepares one frame) |
ecashin@coraid.com | a4b3836 | 2005-04-18 22:00:22 -0700 | [diff] [blame] | 683 | * we just return the skb. Usually we'd chain it up to the aoedev sendq. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | */ |
| 685 | static struct sk_buff * |
| 686 | aoecmd_ata_id(struct aoedev *d) |
| 687 | { |
| 688 | struct aoe_hdr *h; |
| 689 | struct aoe_atahdr *ah; |
| 690 | struct frame *f; |
| 691 | struct sk_buff *skb; |
| 692 | |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 693 | f = freeframe(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | if (f == NULL) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 695 | printk(KERN_ERR "aoe: can't get a frame. This shouldn't happen.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | return NULL; |
| 697 | } |
| 698 | |
| 699 | /* initialize the headers & frame */ |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 700 | skb = f->skb; |
Arnaldo Carvalho de Melo | 029720f | 2007-03-10 11:20:07 -0300 | [diff] [blame] | 701 | h = aoe_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | ah = (struct aoe_atahdr *) (h+1); |
Ed L. Cashin | 19900cd | 2006-12-22 01:09:21 -0800 | [diff] [blame] | 703 | skb_put(skb, sizeof *h + sizeof *ah); |
| 704 | memset(h, 0, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | f->tag = aoehdr_atainit(d, h); |
| 706 | f->waited = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | /* set up ata header */ |
| 709 | ah->scnt = 1; |
| 710 | ah->cmdstat = WIN_IDENTIFY; |
| 711 | ah->lba3 = 0xa0; |
| 712 | |
Ed L. Cashin | e407a7f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 713 | skb->dev = d->ifp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 715 | d->rttavg = MAXTIMER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | d->timer.function = rexmit_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 718 | return skb_clone(skb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | void |
| 722 | aoecmd_cfg_rsp(struct sk_buff *skb) |
| 723 | { |
| 724 | struct aoedev *d; |
| 725 | struct aoe_hdr *h; |
| 726 | struct aoe_cfghdr *ch; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 727 | ulong flags, sysminor, aoemajor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | struct sk_buff *sl; |
Ed L. Cashin | eaf0a3c | 2006-01-19 13:46:20 -0500 | [diff] [blame] | 729 | enum { MAXFRAMES = 16 }; |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 730 | u16 n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Arnaldo Carvalho de Melo | 029720f | 2007-03-10 11:20:07 -0300 | [diff] [blame] | 732 | h = aoe_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | ch = (struct aoe_cfghdr *) (h+1); |
| 734 | |
| 735 | /* |
| 736 | * Enough people have their dip switches set backwards to |
| 737 | * warrant a loud message for this special case. |
| 738 | */ |
David S. Miller | 43ecf52 | 2007-03-01 18:30:08 -0800 | [diff] [blame] | 739 | aoemajor = be16_to_cpu(get_unaligned(&h->major)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | if (aoemajor == 0xfff) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 741 | printk(KERN_ERR "aoe: Warning: shelf address is all ones. " |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 742 | "Check shelf dip switches.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | return; |
| 744 | } |
| 745 | |
| 746 | sysminor = SYSMINOR(aoemajor, h->minor); |
ecashin@coraid.com | fc458dc | 2005-04-18 22:00:17 -0700 | [diff] [blame] | 747 | if (sysminor * AOE_PARTITIONS + AOE_PARTITIONS > MINORMASK) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 748 | 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] | 749 | aoemajor, (int) h->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | return; |
| 751 | } |
| 752 | |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 753 | n = be16_to_cpu(ch->bufcnt); |
| 754 | if (n > MAXFRAMES) /* keep it reasonable */ |
| 755 | n = MAXFRAMES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 757 | d = aoedev_by_sysminor_m(sysminor, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | if (d == NULL) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 759 | printk(KERN_INFO "aoe: device sysminor_m failure\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | return; |
| 761 | } |
| 762 | |
| 763 | spin_lock_irqsave(&d->lock, flags); |
| 764 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 765 | /* permit device to migrate mac and network interface */ |
| 766 | d->ifp = skb->dev; |
| 767 | memcpy(d->addr, h->src, sizeof d->addr); |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 768 | if (!(d->flags & DEVFL_MAXBCNT)) { |
| 769 | n = d->ifp->mtu; |
| 770 | n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr); |
| 771 | n /= 512; |
| 772 | if (n > ch->scnt) |
| 773 | n = ch->scnt; |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 774 | n = n ? n * 512 : DEFAULTBCNT; |
| 775 | if (n != d->maxbcnt) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 776 | printk(KERN_INFO |
| 777 | "aoe: e%ld.%ld: setting %d byte data frames on %s\n", |
Ed L. Cashin | 4f51dc5 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 778 | d->aoemajor, d->aoeminor, n, d->ifp->name); |
| 779 | d->maxbcnt = n; |
| 780 | } |
Ed L. Cashin | 19bf263 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 781 | } |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 782 | |
| 783 | /* don't change users' perspective */ |
| 784 | if (d->nopen && !(d->flags & DEVFL_PAUSE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | spin_unlock_irqrestore(&d->lock, flags); |
| 786 | return; |
| 787 | } |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 788 | d->flags |= DEVFL_PAUSE; /* force pause */ |
Ed L. Cashin | dced3a0 | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 789 | d->mintimer = MINTIMER; |
ecashin@coraid.com | 63e9cc5 | 2005-04-18 22:00:20 -0700 | [diff] [blame] | 790 | d->fw_ver = be16_to_cpu(ch->fwver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 792 | /* check for already outstanding ataid */ |
| 793 | sl = aoedev_isbusy(d) == 0 ? aoecmd_ata_id(d) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | spin_unlock_irqrestore(&d->lock, flags); |
| 796 | |
| 797 | aoenet_xmit(sl); |
| 798 | } |
| 799 | |