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