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