12611464dSEd L. Cashin /* Copyright (c) 2006 Coraid, Inc. See COPYING for GPL terms. */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * aoecmd.c 41da177e4SLinus Torvalds * Filesystem request handling methods 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds #include <linux/hdreg.h> 81da177e4SLinus Torvalds #include <linux/blkdev.h> 91da177e4SLinus Torvalds #include <linux/skbuff.h> 101da177e4SLinus Torvalds #include <linux/netdevice.h> 113ae1c24eSEd L. Cashin #include <linux/genhd.h> 12881d966bSEric W. Biederman #include <net/net_namespace.h> 13475172fbSEd L. Cashin #include <asm/unaligned.h> 141da177e4SLinus Torvalds #include "aoe.h" 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #define TIMERTICK (HZ / 10) 171da177e4SLinus Torvalds #define MINTIMER (2 * TIMERTICK) 181da177e4SLinus Torvalds #define MAXTIMER (HZ << 1) 19b751e8b6SEd L. Cashin 20b751e8b6SEd L. Cashin static int aoe_deadsecs = 60 * 3; 21b751e8b6SEd L. Cashin module_param(aoe_deadsecs, int, 0644); 22b751e8b6SEd L. Cashin MODULE_PARM_DESC(aoe_deadsecs, "After aoe_deadsecs seconds, give up and fail dev."); 231da177e4SLinus Torvalds 24e407a7f6SEd L. Cashin struct sk_buff * 25e407a7f6SEd L. Cashin new_skb(ulong len) 261da177e4SLinus Torvalds { 271da177e4SLinus Torvalds struct sk_buff *skb; 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds skb = alloc_skb(len, GFP_ATOMIC); 301da177e4SLinus Torvalds if (skb) { 31459a98edSArnaldo Carvalho de Melo skb_reset_mac_header(skb); 32c1d2bbe1SArnaldo Carvalho de Melo skb_reset_network_header(skb); 331da177e4SLinus Torvalds skb->protocol = __constant_htons(ETH_P_AOE); 341da177e4SLinus Torvalds skb->priority = 0; 351da177e4SLinus Torvalds skb->next = skb->prev = NULL; 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds /* tell the network layer not to perform IP checksums 381da177e4SLinus Torvalds * or to get the NIC to do it 391da177e4SLinus Torvalds */ 401da177e4SLinus Torvalds skb->ip_summed = CHECKSUM_NONE; 411da177e4SLinus Torvalds } 421da177e4SLinus Torvalds return skb; 431da177e4SLinus Torvalds } 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds static struct frame * 461da177e4SLinus Torvalds getframe(struct aoedev *d, int tag) 471da177e4SLinus Torvalds { 481da177e4SLinus Torvalds struct frame *f, *e; 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds f = d->frames; 511da177e4SLinus Torvalds e = f + d->nframes; 521da177e4SLinus Torvalds for (; f<e; f++) 531da177e4SLinus Torvalds if (f->tag == tag) 541da177e4SLinus Torvalds return f; 551da177e4SLinus Torvalds return NULL; 561da177e4SLinus Torvalds } 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds /* 591da177e4SLinus Torvalds * Leave the top bit clear so we have tagspace for userland. 601da177e4SLinus Torvalds * The bottom 16 bits are the xmit tick for rexmit/rttavg processing. 611da177e4SLinus Torvalds * This driver reserves tag -1 to mean "unused frame." 621da177e4SLinus Torvalds */ 631da177e4SLinus Torvalds static int 641da177e4SLinus Torvalds newtag(struct aoedev *d) 651da177e4SLinus Torvalds { 661da177e4SLinus Torvalds register ulong n; 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds n = jiffies & 0xffff; 691da177e4SLinus Torvalds return n |= (++d->lasttag & 0x7fff) << 16; 701da177e4SLinus Torvalds } 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds static int 731da177e4SLinus Torvalds aoehdr_atainit(struct aoedev *d, struct aoe_hdr *h) 741da177e4SLinus Torvalds { 751da177e4SLinus Torvalds u32 host_tag = newtag(d); 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds memcpy(h->src, d->ifp->dev_addr, sizeof h->src); 781da177e4SLinus Torvalds memcpy(h->dst, d->addr, sizeof h->dst); 7963e9cc5dSecashin@coraid.com h->type = __constant_cpu_to_be16(ETH_P_AOE); 801da177e4SLinus Torvalds h->verfl = AOE_HVER; 8163e9cc5dSecashin@coraid.com h->major = cpu_to_be16(d->aoemajor); 821da177e4SLinus Torvalds h->minor = d->aoeminor; 831da177e4SLinus Torvalds h->cmd = AOECMD_ATA; 8463e9cc5dSecashin@coraid.com h->tag = cpu_to_be32(host_tag); 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds return host_tag; 871da177e4SLinus Torvalds } 881da177e4SLinus Torvalds 8919bf2635SEd L. Cashin static inline void 9019bf2635SEd L. Cashin put_lba(struct aoe_atahdr *ah, sector_t lba) 9119bf2635SEd L. Cashin { 9219bf2635SEd L. Cashin ah->lba0 = lba; 9319bf2635SEd L. Cashin ah->lba1 = lba >>= 8; 9419bf2635SEd L. Cashin ah->lba2 = lba >>= 8; 9519bf2635SEd L. Cashin ah->lba3 = lba >>= 8; 9619bf2635SEd L. Cashin ah->lba4 = lba >>= 8; 9719bf2635SEd L. Cashin ah->lba5 = lba >>= 8; 9819bf2635SEd L. Cashin } 9919bf2635SEd L. Cashin 1001da177e4SLinus Torvalds static void 1011da177e4SLinus Torvalds aoecmd_ata_rw(struct aoedev *d, struct frame *f) 1021da177e4SLinus Torvalds { 1031da177e4SLinus Torvalds struct aoe_hdr *h; 1041da177e4SLinus Torvalds struct aoe_atahdr *ah; 1051da177e4SLinus Torvalds struct buf *buf; 1061da177e4SLinus Torvalds struct sk_buff *skb; 1071da177e4SLinus Torvalds ulong bcnt; 1081da177e4SLinus Torvalds register sector_t sector; 1091da177e4SLinus Torvalds char writebit, extbit; 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds writebit = 0x10; 1121da177e4SLinus Torvalds extbit = 0x4; 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds buf = d->inprocess; 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds sector = buf->sector; 1171da177e4SLinus Torvalds bcnt = buf->bv_resid; 11819bf2635SEd L. Cashin if (bcnt > d->maxbcnt) 11919bf2635SEd L. Cashin bcnt = d->maxbcnt; 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds /* initialize the headers & frame */ 122e407a7f6SEd L. Cashin skb = f->skb; 123*abdbf94dSEd L. Cashin h = (struct aoe_hdr *) skb_mac_header(skb); 1241da177e4SLinus Torvalds ah = (struct aoe_atahdr *) (h+1); 12519900cdeSEd L. Cashin skb_put(skb, sizeof *h + sizeof *ah); 12619900cdeSEd L. Cashin memset(h, 0, skb->len); 1271da177e4SLinus Torvalds f->tag = aoehdr_atainit(d, h); 1281da177e4SLinus Torvalds f->waited = 0; 1291da177e4SLinus Torvalds f->buf = buf; 1301da177e4SLinus Torvalds f->bufaddr = buf->bufaddr; 13119bf2635SEd L. Cashin f->bcnt = bcnt; 13219bf2635SEd L. Cashin f->lba = sector; 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds /* set up ata header */ 1351da177e4SLinus Torvalds ah->scnt = bcnt >> 9; 13619bf2635SEd L. Cashin put_lba(ah, sector); 1371da177e4SLinus Torvalds if (d->flags & DEVFL_EXT) { 1381da177e4SLinus Torvalds ah->aflags |= AOEAFL_EXT; 1391da177e4SLinus Torvalds } else { 1401da177e4SLinus Torvalds extbit = 0; 1411da177e4SLinus Torvalds ah->lba3 &= 0x0f; 1421da177e4SLinus Torvalds ah->lba3 |= 0xe0; /* LBA bit + obsolete 0xa0 */ 1431da177e4SLinus Torvalds } 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds if (bio_data_dir(buf->bio) == WRITE) { 146e407a7f6SEd L. Cashin skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr), 147e407a7f6SEd L. Cashin offset_in_page(f->bufaddr), bcnt); 1481da177e4SLinus Torvalds ah->aflags |= AOEAFL_WRITE; 1494f51dc5eSEd L. Cashin skb->len += bcnt; 1504f51dc5eSEd L. Cashin skb->data_len = bcnt; 1511da177e4SLinus Torvalds } else { 1521da177e4SLinus Torvalds writebit = 0; 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds ah->cmdstat = WIN_READ | writebit | extbit; 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds /* mark all tracking fields and load out */ 1581da177e4SLinus Torvalds buf->nframesout += 1; 1591da177e4SLinus Torvalds buf->bufaddr += bcnt; 1601da177e4SLinus Torvalds buf->bv_resid -= bcnt; 161a12c93f0SEd L. Cashin /* printk(KERN_DEBUG "aoe: bv_resid=%ld\n", buf->bv_resid); */ 1621da177e4SLinus Torvalds buf->resid -= bcnt; 1631da177e4SLinus Torvalds buf->sector += bcnt >> 9; 1641da177e4SLinus Torvalds if (buf->resid == 0) { 1651da177e4SLinus Torvalds d->inprocess = NULL; 1661da177e4SLinus Torvalds } else if (buf->bv_resid == 0) { 1671da177e4SLinus Torvalds buf->bv++; 168392e4845SEd L. Cashin WARN_ON(buf->bv->bv_len == 0); 1691da177e4SLinus Torvalds buf->bv_resid = buf->bv->bv_len; 1701da177e4SLinus Torvalds buf->bufaddr = page_address(buf->bv->bv_page) + buf->bv->bv_offset; 1711da177e4SLinus Torvalds } 1721da177e4SLinus Torvalds 173e407a7f6SEd L. Cashin skb->dev = d->ifp; 1744f51dc5eSEd L. Cashin skb = skb_clone(skb, GFP_ATOMIC); 1754f51dc5eSEd L. Cashin if (skb == NULL) 1764f51dc5eSEd L. Cashin return; 177a4b38364Secashin@coraid.com if (d->sendq_hd) 178a4b38364Secashin@coraid.com d->sendq_tl->next = skb; 179a4b38364Secashin@coraid.com else 180a4b38364Secashin@coraid.com d->sendq_hd = skb; 181a4b38364Secashin@coraid.com d->sendq_tl = skb; 1821da177e4SLinus Torvalds } 1831da177e4SLinus Torvalds 1843ae1c24eSEd L. Cashin /* some callers cannot sleep, and they can call this function, 1853ae1c24eSEd L. Cashin * transmitting the packets later, when interrupts are on 1863ae1c24eSEd L. Cashin */ 1873ae1c24eSEd L. Cashin static struct sk_buff * 1883ae1c24eSEd L. Cashin aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail) 1893ae1c24eSEd L. Cashin { 1903ae1c24eSEd L. Cashin struct aoe_hdr *h; 1913ae1c24eSEd L. Cashin struct aoe_cfghdr *ch; 1923ae1c24eSEd L. Cashin struct sk_buff *skb, *sl, *sl_tail; 1933ae1c24eSEd L. Cashin struct net_device *ifp; 1943ae1c24eSEd L. Cashin 1953ae1c24eSEd L. Cashin sl = sl_tail = NULL; 1963ae1c24eSEd L. Cashin 1973ae1c24eSEd L. Cashin read_lock(&dev_base_lock); 198881d966bSEric W. Biederman for_each_netdev(&init_net, ifp) { 1993ae1c24eSEd L. Cashin dev_hold(ifp); 2003ae1c24eSEd L. Cashin if (!is_aoe_netif(ifp)) 2017562f876SPavel Emelianov goto cont; 2023ae1c24eSEd L. Cashin 203e407a7f6SEd L. Cashin skb = new_skb(sizeof *h + sizeof *ch); 2043ae1c24eSEd L. Cashin if (skb == NULL) { 205a12c93f0SEd L. Cashin printk(KERN_INFO "aoe: skb alloc failure\n"); 2067562f876SPavel Emelianov goto cont; 2073ae1c24eSEd L. Cashin } 20819900cdeSEd L. Cashin skb_put(skb, sizeof *h + sizeof *ch); 209e407a7f6SEd L. Cashin skb->dev = ifp; 2103ae1c24eSEd L. Cashin if (sl_tail == NULL) 2113ae1c24eSEd L. Cashin sl_tail = skb; 212*abdbf94dSEd L. Cashin h = (struct aoe_hdr *) skb_mac_header(skb); 2133ae1c24eSEd L. Cashin memset(h, 0, sizeof *h + sizeof *ch); 2143ae1c24eSEd L. Cashin 2153ae1c24eSEd L. Cashin memset(h->dst, 0xff, sizeof h->dst); 2163ae1c24eSEd L. Cashin memcpy(h->src, ifp->dev_addr, sizeof h->src); 2173ae1c24eSEd L. Cashin h->type = __constant_cpu_to_be16(ETH_P_AOE); 2183ae1c24eSEd L. Cashin h->verfl = AOE_HVER; 2193ae1c24eSEd L. Cashin h->major = cpu_to_be16(aoemajor); 2203ae1c24eSEd L. Cashin h->minor = aoeminor; 2213ae1c24eSEd L. Cashin h->cmd = AOECMD_CFG; 2223ae1c24eSEd L. Cashin 2233ae1c24eSEd L. Cashin skb->next = sl; 2243ae1c24eSEd L. Cashin sl = skb; 2257562f876SPavel Emelianov cont: 2267562f876SPavel Emelianov dev_put(ifp); 2273ae1c24eSEd L. Cashin } 2283ae1c24eSEd L. Cashin read_unlock(&dev_base_lock); 2293ae1c24eSEd L. Cashin 2303ae1c24eSEd L. Cashin if (tail != NULL) 2313ae1c24eSEd L. Cashin *tail = sl_tail; 2323ae1c24eSEd L. Cashin return sl; 2333ae1c24eSEd L. Cashin } 2343ae1c24eSEd L. Cashin 2354f51dc5eSEd L. Cashin static struct frame * 2364f51dc5eSEd L. Cashin freeframe(struct aoedev *d) 2374f51dc5eSEd L. Cashin { 2384f51dc5eSEd L. Cashin struct frame *f, *e; 2394f51dc5eSEd L. Cashin int n = 0; 2404f51dc5eSEd L. Cashin 2414f51dc5eSEd L. Cashin f = d->frames; 2424f51dc5eSEd L. Cashin e = f + d->nframes; 2434f51dc5eSEd L. Cashin for (; f<e; f++) { 2444f51dc5eSEd L. Cashin if (f->tag != FREETAG) 2454f51dc5eSEd L. Cashin continue; 2464f51dc5eSEd L. Cashin if (atomic_read(&skb_shinfo(f->skb)->dataref) == 1) { 2474f51dc5eSEd L. Cashin skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0; 24819900cdeSEd L. Cashin skb_trim(f->skb, 0); 2494f51dc5eSEd L. Cashin return f; 2504f51dc5eSEd L. Cashin } 2514f51dc5eSEd L. Cashin n++; 2524f51dc5eSEd L. Cashin } 2534f51dc5eSEd L. Cashin if (n == d->nframes) /* wait for network layer */ 2544f51dc5eSEd L. Cashin d->flags |= DEVFL_KICKME; 2554f51dc5eSEd L. Cashin 2564f51dc5eSEd L. Cashin return NULL; 2574f51dc5eSEd L. Cashin } 2584f51dc5eSEd L. Cashin 2591da177e4SLinus Torvalds /* enters with d->lock held */ 2601da177e4SLinus Torvalds void 2611da177e4SLinus Torvalds aoecmd_work(struct aoedev *d) 2621da177e4SLinus Torvalds { 2631da177e4SLinus Torvalds struct frame *f; 2641da177e4SLinus Torvalds struct buf *buf; 2653ae1c24eSEd L. Cashin 2663ae1c24eSEd L. Cashin if (d->flags & DEVFL_PAUSE) { 2673ae1c24eSEd L. Cashin if (!aoedev_isbusy(d)) 2683ae1c24eSEd L. Cashin d->sendq_hd = aoecmd_cfg_pkts(d->aoemajor, 2693ae1c24eSEd L. Cashin d->aoeminor, &d->sendq_tl); 2703ae1c24eSEd L. Cashin return; 2713ae1c24eSEd L. Cashin } 2723ae1c24eSEd L. Cashin 2731da177e4SLinus Torvalds loop: 2744f51dc5eSEd L. Cashin f = freeframe(d); 2751da177e4SLinus Torvalds if (f == NULL) 2761da177e4SLinus Torvalds return; 2771da177e4SLinus Torvalds if (d->inprocess == NULL) { 2781da177e4SLinus Torvalds if (list_empty(&d->bufq)) 2791da177e4SLinus Torvalds return; 2801da177e4SLinus Torvalds buf = container_of(d->bufq.next, struct buf, bufs); 2811da177e4SLinus Torvalds list_del(d->bufq.next); 282a12c93f0SEd L. Cashin /*printk(KERN_DEBUG "aoe: bi_size=%ld\n", buf->bio->bi_size); */ 2831da177e4SLinus Torvalds d->inprocess = buf; 2841da177e4SLinus Torvalds } 2851da177e4SLinus Torvalds aoecmd_ata_rw(d, f); 2861da177e4SLinus Torvalds goto loop; 2871da177e4SLinus Torvalds } 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds static void 2901da177e4SLinus Torvalds rexmit(struct aoedev *d, struct frame *f) 2911da177e4SLinus Torvalds { 2921da177e4SLinus Torvalds struct sk_buff *skb; 2931da177e4SLinus Torvalds struct aoe_hdr *h; 29419bf2635SEd L. Cashin struct aoe_atahdr *ah; 2951da177e4SLinus Torvalds char buf[128]; 2961da177e4SLinus Torvalds u32 n; 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds n = newtag(d); 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds snprintf(buf, sizeof buf, 3011da177e4SLinus Torvalds "%15s e%ld.%ld oldtag=%08x@%08lx newtag=%08x\n", 3021da177e4SLinus Torvalds "retransmit", 3031da177e4SLinus Torvalds d->aoemajor, d->aoeminor, f->tag, jiffies, n); 3041da177e4SLinus Torvalds aoechr_error(buf); 3051da177e4SLinus Torvalds 306e407a7f6SEd L. Cashin skb = f->skb; 307*abdbf94dSEd L. Cashin h = (struct aoe_hdr *) skb_mac_header(skb); 30819bf2635SEd L. Cashin ah = (struct aoe_atahdr *) (h+1); 3091da177e4SLinus Torvalds f->tag = n; 31063e9cc5dSecashin@coraid.com h->tag = cpu_to_be32(n); 3112dd5e422SEd L. Cashin memcpy(h->dst, d->addr, sizeof h->dst); 3122dd5e422SEd L. Cashin memcpy(h->src, d->ifp->dev_addr, sizeof h->src); 3131da177e4SLinus Torvalds 31419bf2635SEd L. Cashin n = DEFAULTBCNT / 512; 31519bf2635SEd L. Cashin if (ah->scnt > n) { 31619bf2635SEd L. Cashin ah->scnt = n; 3174f51dc5eSEd L. Cashin if (ah->aflags & AOEAFL_WRITE) { 31819bf2635SEd L. Cashin skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr), 31919bf2635SEd L. Cashin offset_in_page(f->bufaddr), DEFAULTBCNT); 3204f51dc5eSEd L. Cashin skb->len = sizeof *h + sizeof *ah + DEFAULTBCNT; 3214f51dc5eSEd L. Cashin skb->data_len = DEFAULTBCNT; 3224f51dc5eSEd L. Cashin } 32319bf2635SEd L. Cashin if (++d->lostjumbo > (d->nframes << 1)) 32419bf2635SEd L. Cashin if (d->maxbcnt != DEFAULTBCNT) { 325a12c93f0SEd L. Cashin printk(KERN_INFO "aoe: e%ld.%ld: too many lost jumbo on %s - using 1KB frames.\n", 3264f51dc5eSEd L. Cashin d->aoemajor, d->aoeminor, d->ifp->name); 32719bf2635SEd L. Cashin d->maxbcnt = DEFAULTBCNT; 32819bf2635SEd L. Cashin d->flags |= DEVFL_MAXBCNT; 32919bf2635SEd L. Cashin } 33019bf2635SEd L. Cashin } 33119bf2635SEd L. Cashin 332e407a7f6SEd L. Cashin skb->dev = d->ifp; 3334f51dc5eSEd L. Cashin skb = skb_clone(skb, GFP_ATOMIC); 3344f51dc5eSEd L. Cashin if (skb == NULL) 3354f51dc5eSEd L. Cashin return; 336a4b38364Secashin@coraid.com if (d->sendq_hd) 337a4b38364Secashin@coraid.com d->sendq_tl->next = skb; 338a4b38364Secashin@coraid.com else 339a4b38364Secashin@coraid.com d->sendq_hd = skb; 340a4b38364Secashin@coraid.com d->sendq_tl = skb; 3411da177e4SLinus Torvalds } 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvalds static int 3441da177e4SLinus Torvalds tsince(int tag) 3451da177e4SLinus Torvalds { 3461da177e4SLinus Torvalds int n; 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds n = jiffies & 0xffff; 3491da177e4SLinus Torvalds n -= tag & 0xffff; 3501da177e4SLinus Torvalds if (n < 0) 3511da177e4SLinus Torvalds n += 1<<16; 3521da177e4SLinus Torvalds return n; 3531da177e4SLinus Torvalds } 3541da177e4SLinus Torvalds 3551da177e4SLinus Torvalds static void 3561da177e4SLinus Torvalds rexmit_timer(ulong vp) 3571da177e4SLinus Torvalds { 3581da177e4SLinus Torvalds struct aoedev *d; 3591da177e4SLinus Torvalds struct frame *f, *e; 3601da177e4SLinus Torvalds struct sk_buff *sl; 3611da177e4SLinus Torvalds register long timeout; 3621da177e4SLinus Torvalds ulong flags, n; 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds d = (struct aoedev *) vp; 3651da177e4SLinus Torvalds sl = NULL; 3661da177e4SLinus Torvalds 3671da177e4SLinus Torvalds /* timeout is always ~150% of the moving average */ 3681da177e4SLinus Torvalds timeout = d->rttavg; 3691da177e4SLinus Torvalds timeout += timeout >> 1; 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds spin_lock_irqsave(&d->lock, flags); 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds if (d->flags & DEVFL_TKILL) { 3741c6f3fcaSEd L. Cashin spin_unlock_irqrestore(&d->lock, flags); 3751da177e4SLinus Torvalds return; 3761da177e4SLinus Torvalds } 3771da177e4SLinus Torvalds f = d->frames; 3781da177e4SLinus Torvalds e = f + d->nframes; 3791da177e4SLinus Torvalds for (; f<e; f++) { 3801da177e4SLinus Torvalds if (f->tag != FREETAG && tsince(f->tag) >= timeout) { 3811da177e4SLinus Torvalds n = f->waited += timeout; 3821da177e4SLinus Torvalds n /= HZ; 383b751e8b6SEd L. Cashin if (n > aoe_deadsecs) { /* waited too long for response */ 3841da177e4SLinus Torvalds aoedev_downdev(d); 3851c6f3fcaSEd L. Cashin break; 3861da177e4SLinus Torvalds } 3871da177e4SLinus Torvalds rexmit(d, f); 3881da177e4SLinus Torvalds } 3891da177e4SLinus Torvalds } 3904f51dc5eSEd L. Cashin if (d->flags & DEVFL_KICKME) { 3914f51dc5eSEd L. Cashin d->flags &= ~DEVFL_KICKME; 3924f51dc5eSEd L. Cashin aoecmd_work(d); 3934f51dc5eSEd L. Cashin } 3941da177e4SLinus Torvalds 395a4b38364Secashin@coraid.com sl = d->sendq_hd; 396a4b38364Secashin@coraid.com d->sendq_hd = d->sendq_tl = NULL; 3971da177e4SLinus Torvalds if (sl) { 3981da177e4SLinus Torvalds n = d->rttavg <<= 1; 3991da177e4SLinus Torvalds if (n > MAXTIMER) 4001da177e4SLinus Torvalds d->rttavg = MAXTIMER; 4011da177e4SLinus Torvalds } 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvalds d->timer.expires = jiffies + TIMERTICK; 4041da177e4SLinus Torvalds add_timer(&d->timer); 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds spin_unlock_irqrestore(&d->lock, flags); 4071da177e4SLinus Torvalds 4081da177e4SLinus Torvalds aoenet_xmit(sl); 4091da177e4SLinus Torvalds } 4101da177e4SLinus Torvalds 4113ae1c24eSEd L. Cashin /* this function performs work that has been deferred until sleeping is OK 4123ae1c24eSEd L. Cashin */ 4133ae1c24eSEd L. Cashin void 414c4028958SDavid Howells aoecmd_sleepwork(struct work_struct *work) 4153ae1c24eSEd L. Cashin { 416c4028958SDavid Howells struct aoedev *d = container_of(work, struct aoedev, work); 4173ae1c24eSEd L. Cashin 4183ae1c24eSEd L. Cashin if (d->flags & DEVFL_GDALLOC) 4193ae1c24eSEd L. Cashin aoeblk_gdalloc(d); 4203ae1c24eSEd L. Cashin 4213ae1c24eSEd L. Cashin if (d->flags & DEVFL_NEWSIZE) { 4223ae1c24eSEd L. Cashin struct block_device *bd; 4233ae1c24eSEd L. Cashin unsigned long flags; 4243ae1c24eSEd L. Cashin u64 ssize; 4253ae1c24eSEd L. Cashin 4263ae1c24eSEd L. Cashin ssize = d->gd->capacity; 4273ae1c24eSEd L. Cashin bd = bdget_disk(d->gd, 0); 4283ae1c24eSEd L. Cashin 4293ae1c24eSEd L. Cashin if (bd) { 4303ae1c24eSEd L. Cashin mutex_lock(&bd->bd_inode->i_mutex); 4313ae1c24eSEd L. Cashin i_size_write(bd->bd_inode, (loff_t)ssize<<9); 4323ae1c24eSEd L. Cashin mutex_unlock(&bd->bd_inode->i_mutex); 4333ae1c24eSEd L. Cashin bdput(bd); 4343ae1c24eSEd L. Cashin } 4353ae1c24eSEd L. Cashin spin_lock_irqsave(&d->lock, flags); 4363ae1c24eSEd L. Cashin d->flags |= DEVFL_UP; 4373ae1c24eSEd L. Cashin d->flags &= ~DEVFL_NEWSIZE; 4383ae1c24eSEd L. Cashin spin_unlock_irqrestore(&d->lock, flags); 4393ae1c24eSEd L. Cashin } 4403ae1c24eSEd L. Cashin } 4413ae1c24eSEd L. Cashin 4421da177e4SLinus Torvalds static void 4431da177e4SLinus Torvalds ataid_complete(struct aoedev *d, unsigned char *id) 4441da177e4SLinus Torvalds { 4451da177e4SLinus Torvalds u64 ssize; 4461da177e4SLinus Torvalds u16 n; 4471da177e4SLinus Torvalds 4481da177e4SLinus Torvalds /* word 83: command set supported */ 449475172fbSEd L. Cashin n = le16_to_cpu(get_unaligned((__le16 *) &id[83<<1])); 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds /* word 86: command set/feature enabled */ 452475172fbSEd L. Cashin n |= le16_to_cpu(get_unaligned((__le16 *) &id[86<<1])); 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds if (n & (1<<10)) { /* bit 10: LBA 48 */ 4551da177e4SLinus Torvalds d->flags |= DEVFL_EXT; 4561da177e4SLinus Torvalds 4571da177e4SLinus Torvalds /* word 100: number lba48 sectors */ 458475172fbSEd L. Cashin ssize = le64_to_cpu(get_unaligned((__le64 *) &id[100<<1])); 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds /* set as in ide-disk.c:init_idedisk_capacity */ 4611da177e4SLinus Torvalds d->geo.cylinders = ssize; 4621da177e4SLinus Torvalds d->geo.cylinders /= (255 * 63); 4631da177e4SLinus Torvalds d->geo.heads = 255; 4641da177e4SLinus Torvalds d->geo.sectors = 63; 4651da177e4SLinus Torvalds } else { 4661da177e4SLinus Torvalds d->flags &= ~DEVFL_EXT; 4671da177e4SLinus Torvalds 4681da177e4SLinus Torvalds /* number lba28 sectors */ 469475172fbSEd L. Cashin ssize = le32_to_cpu(get_unaligned((__le32 *) &id[60<<1])); 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds /* NOTE: obsolete in ATA 6 */ 472475172fbSEd L. Cashin d->geo.cylinders = le16_to_cpu(get_unaligned((__le16 *) &id[54<<1])); 473475172fbSEd L. Cashin d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1])); 474475172fbSEd L. Cashin d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1])); 4751da177e4SLinus Torvalds } 4763ae1c24eSEd L. Cashin 4773ae1c24eSEd L. Cashin if (d->ssize != ssize) 478a12c93f0SEd L. Cashin printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu sectors\n", 4796bb6285fSEd L. Cashin (unsigned long long)mac_addr(d->addr), 4803ae1c24eSEd L. Cashin d->aoemajor, d->aoeminor, 4813ae1c24eSEd L. Cashin d->fw_ver, (long long)ssize); 4821da177e4SLinus Torvalds d->ssize = ssize; 4831da177e4SLinus Torvalds d->geo.start = 0; 4841da177e4SLinus Torvalds if (d->gd != NULL) { 4851da177e4SLinus Torvalds d->gd->capacity = ssize; 4863ae1c24eSEd L. Cashin d->flags |= DEVFL_NEWSIZE; 4873ae1c24eSEd L. Cashin } else { 4883ae1c24eSEd L. Cashin if (d->flags & DEVFL_GDALLOC) { 489a12c93f0SEd L. Cashin printk(KERN_ERR "aoe: can't schedule work for e%lu.%lu, %s\n", 4903ae1c24eSEd L. Cashin d->aoemajor, d->aoeminor, 4916bb6285fSEd L. Cashin "it's already on! This shouldn't happen.\n"); 4921da177e4SLinus Torvalds return; 4931da177e4SLinus Torvalds } 4943ae1c24eSEd L. Cashin d->flags |= DEVFL_GDALLOC; 4951da177e4SLinus Torvalds } 4961da177e4SLinus Torvalds schedule_work(&d->work); 4971da177e4SLinus Torvalds } 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds static void 5001da177e4SLinus Torvalds calc_rttavg(struct aoedev *d, int rtt) 5011da177e4SLinus Torvalds { 5021da177e4SLinus Torvalds register long n; 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvalds n = rtt; 505dced3a05SEd L. Cashin if (n < 0) { 506dced3a05SEd L. Cashin n = -rtt; 5071da177e4SLinus Torvalds if (n < MINTIMER) 5081da177e4SLinus Torvalds n = MINTIMER; 5091da177e4SLinus Torvalds else if (n > MAXTIMER) 5101da177e4SLinus Torvalds n = MAXTIMER; 511dced3a05SEd L. Cashin d->mintimer += (n - d->mintimer) >> 1; 512dced3a05SEd L. Cashin } else if (n < d->mintimer) 513dced3a05SEd L. Cashin n = d->mintimer; 514dced3a05SEd L. Cashin else if (n > MAXTIMER) 515dced3a05SEd L. Cashin n = MAXTIMER; 5161da177e4SLinus Torvalds 5171da177e4SLinus Torvalds /* g == .25; cf. Congestion Avoidance and Control, Jacobson & Karels; 1988 */ 5181da177e4SLinus Torvalds n -= d->rttavg; 5191da177e4SLinus Torvalds d->rttavg += n >> 2; 5201da177e4SLinus Torvalds } 5211da177e4SLinus Torvalds 5221da177e4SLinus Torvalds void 5231da177e4SLinus Torvalds aoecmd_ata_rsp(struct sk_buff *skb) 5241da177e4SLinus Torvalds { 5251da177e4SLinus Torvalds struct aoedev *d; 526ddec63e8SEd L. Cashin struct aoe_hdr *hin, *hout; 5271da177e4SLinus Torvalds struct aoe_atahdr *ahin, *ahout; 5281da177e4SLinus Torvalds struct frame *f; 5291da177e4SLinus Torvalds struct buf *buf; 5301da177e4SLinus Torvalds struct sk_buff *sl; 5311da177e4SLinus Torvalds register long n; 5321da177e4SLinus Torvalds ulong flags; 5331da177e4SLinus Torvalds char ebuf[128]; 53432465c65Secashin@coraid.com u16 aoemajor; 5351da177e4SLinus Torvalds 536*abdbf94dSEd L. Cashin hin = (struct aoe_hdr *) skb_mac_header(skb); 53743ecf529SDavid S. Miller aoemajor = be16_to_cpu(get_unaligned(&hin->major)); 53832465c65Secashin@coraid.com d = aoedev_by_aoeaddr(aoemajor, hin->minor); 5391da177e4SLinus Torvalds if (d == NULL) { 5401da177e4SLinus Torvalds snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response " 5411da177e4SLinus Torvalds "for unknown device %d.%d\n", 54232465c65Secashin@coraid.com aoemajor, hin->minor); 5431da177e4SLinus Torvalds aoechr_error(ebuf); 5441da177e4SLinus Torvalds return; 5451da177e4SLinus Torvalds } 5461da177e4SLinus Torvalds 5471da177e4SLinus Torvalds spin_lock_irqsave(&d->lock, flags); 5481da177e4SLinus Torvalds 54943ecf529SDavid S. Miller n = be32_to_cpu(get_unaligned(&hin->tag)); 550dced3a05SEd L. Cashin f = getframe(d, n); 5511da177e4SLinus Torvalds if (f == NULL) { 552dced3a05SEd L. Cashin calc_rttavg(d, -tsince(n)); 5531da177e4SLinus Torvalds spin_unlock_irqrestore(&d->lock, flags); 5541da177e4SLinus Torvalds snprintf(ebuf, sizeof ebuf, 5551da177e4SLinus Torvalds "%15s e%d.%d tag=%08x@%08lx\n", 5561da177e4SLinus Torvalds "unexpected rsp", 55743ecf529SDavid S. Miller be16_to_cpu(get_unaligned(&hin->major)), 5581da177e4SLinus Torvalds hin->minor, 55943ecf529SDavid S. Miller be32_to_cpu(get_unaligned(&hin->tag)), 5601da177e4SLinus Torvalds jiffies); 5611da177e4SLinus Torvalds aoechr_error(ebuf); 5621da177e4SLinus Torvalds return; 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds calc_rttavg(d, tsince(f->tag)); 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds ahin = (struct aoe_atahdr *) (hin+1); 568*abdbf94dSEd L. Cashin hout = (struct aoe_hdr *) skb_mac_header(f->skb); 569ddec63e8SEd L. Cashin ahout = (struct aoe_atahdr *) (hout+1); 5701da177e4SLinus Torvalds buf = f->buf; 5711da177e4SLinus Torvalds 5729d41965bSEd L. Cashin if (ahout->cmdstat == WIN_IDENTIFY) 5739d41965bSEd L. Cashin d->flags &= ~DEVFL_PAUSE; 5741da177e4SLinus Torvalds if (ahin->cmdstat & 0xa9) { /* these bits cleared on success */ 575a12c93f0SEd L. Cashin printk(KERN_ERR 576a12c93f0SEd L. Cashin "aoe: ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%ld\n", 5771da177e4SLinus Torvalds ahout->cmdstat, ahin->cmdstat, 5781da177e4SLinus Torvalds d->aoemajor, d->aoeminor); 5791da177e4SLinus Torvalds if (buf) 5801da177e4SLinus Torvalds buf->flags |= BUFFL_FAIL; 5811da177e4SLinus Torvalds } else { 58219bf2635SEd L. Cashin n = ahout->scnt << 9; 5831da177e4SLinus Torvalds switch (ahout->cmdstat) { 5841da177e4SLinus Torvalds case WIN_READ: 5851da177e4SLinus Torvalds case WIN_READ_EXT: 5861da177e4SLinus Torvalds if (skb->len - sizeof *hin - sizeof *ahin < n) { 587a12c93f0SEd L. Cashin printk(KERN_ERR 588a12c93f0SEd L. Cashin "aoe: runt data size in read. skb->len=%d\n", 5891da177e4SLinus Torvalds skb->len); 5901da177e4SLinus Torvalds /* fail frame f? just returning will rexmit. */ 5911da177e4SLinus Torvalds spin_unlock_irqrestore(&d->lock, flags); 5921da177e4SLinus Torvalds return; 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds memcpy(f->bufaddr, ahin+1, n); 5951da177e4SLinus Torvalds case WIN_WRITE: 5961da177e4SLinus Torvalds case WIN_WRITE_EXT: 59719bf2635SEd L. Cashin if (f->bcnt -= n) { 5984f51dc5eSEd L. Cashin skb = f->skb; 59919bf2635SEd L. Cashin f->bufaddr += n; 60019bf2635SEd L. Cashin put_lba(ahout, f->lba += ahout->scnt); 6016bb6285fSEd L. Cashin n = f->bcnt; 6026bb6285fSEd L. Cashin if (n > DEFAULTBCNT) 6036bb6285fSEd L. Cashin n = DEFAULTBCNT; 60419bf2635SEd L. Cashin ahout->scnt = n >> 9; 6054f51dc5eSEd L. Cashin if (ahout->aflags & AOEAFL_WRITE) { 6064f51dc5eSEd L. Cashin skb_fill_page_desc(skb, 0, 6076bb6285fSEd L. Cashin virt_to_page(f->bufaddr), 60819bf2635SEd L. Cashin offset_in_page(f->bufaddr), n); 6094f51dc5eSEd L. Cashin skb->len = sizeof *hout + sizeof *ahout + n; 6104f51dc5eSEd L. Cashin skb->data_len = n; 6114f51dc5eSEd L. Cashin } 612ddec63e8SEd L. Cashin f->tag = newtag(d); 613ddec63e8SEd L. Cashin hout->tag = cpu_to_be32(f->tag); 614ddec63e8SEd L. Cashin skb->dev = d->ifp; 6154f51dc5eSEd L. Cashin skb = skb_clone(skb, GFP_ATOMIC); 61619bf2635SEd L. Cashin spin_unlock_irqrestore(&d->lock, flags); 6174f51dc5eSEd L. Cashin if (skb) 6184f51dc5eSEd L. Cashin aoenet_xmit(skb); 61919bf2635SEd L. Cashin return; 62019bf2635SEd L. Cashin } 62119bf2635SEd L. Cashin if (n > DEFAULTBCNT) 62219bf2635SEd L. Cashin d->lostjumbo = 0; 6231da177e4SLinus Torvalds break; 6241da177e4SLinus Torvalds case WIN_IDENTIFY: 6251da177e4SLinus Torvalds if (skb->len - sizeof *hin - sizeof *ahin < 512) { 626a12c93f0SEd L. Cashin printk(KERN_INFO 627a12c93f0SEd L. Cashin "aoe: runt data size in ataid. skb->len=%d\n", 6286bb6285fSEd L. Cashin skb->len); 6291da177e4SLinus Torvalds spin_unlock_irqrestore(&d->lock, flags); 6301da177e4SLinus Torvalds return; 6311da177e4SLinus Torvalds } 6321da177e4SLinus Torvalds ataid_complete(d, (char *) (ahin+1)); 6331da177e4SLinus Torvalds break; 6341da177e4SLinus Torvalds default: 635a12c93f0SEd L. Cashin printk(KERN_INFO 636a12c93f0SEd L. Cashin "aoe: unrecognized ata command %2.2Xh for %d.%d\n", 6371da177e4SLinus Torvalds ahout->cmdstat, 63843ecf529SDavid S. Miller be16_to_cpu(get_unaligned(&hin->major)), 6391da177e4SLinus Torvalds hin->minor); 6401da177e4SLinus Torvalds } 6411da177e4SLinus Torvalds } 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds if (buf) { 6441da177e4SLinus Torvalds buf->nframesout -= 1; 6451da177e4SLinus Torvalds if (buf->nframesout == 0 && buf->resid == 0) { 6460c6f0e79Secashin@coraid.com unsigned long duration = jiffies - buf->start_time; 6470c6f0e79Secashin@coraid.com unsigned long n_sect = buf->bio->bi_size >> 9; 6480c6f0e79Secashin@coraid.com struct gendisk *disk = d->gd; 649496456c2SJens Axboe const int rw = bio_data_dir(buf->bio); 6500c6f0e79Secashin@coraid.com 651496456c2SJens Axboe disk_stat_inc(disk, ios[rw]); 652496456c2SJens Axboe disk_stat_add(disk, ticks[rw], duration); 653496456c2SJens Axboe disk_stat_add(disk, sectors[rw], n_sect); 6540c6f0e79Secashin@coraid.com disk_stat_add(disk, io_ticks, duration); 6551da177e4SLinus Torvalds n = (buf->flags & BUFFL_FAIL) ? -EIO : 0; 6566712ecf8SNeilBrown bio_endio(buf->bio, n); 6571da177e4SLinus Torvalds mempool_free(buf, d->bufpool); 6581da177e4SLinus Torvalds } 6591da177e4SLinus Torvalds } 6601da177e4SLinus Torvalds 6611da177e4SLinus Torvalds f->buf = NULL; 6621da177e4SLinus Torvalds f->tag = FREETAG; 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds aoecmd_work(d); 665a4b38364Secashin@coraid.com sl = d->sendq_hd; 666a4b38364Secashin@coraid.com d->sendq_hd = d->sendq_tl = NULL; 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds spin_unlock_irqrestore(&d->lock, flags); 6691da177e4SLinus Torvalds aoenet_xmit(sl); 6701da177e4SLinus Torvalds } 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds void 6731da177e4SLinus Torvalds aoecmd_cfg(ushort aoemajor, unsigned char aoeminor) 6741da177e4SLinus Torvalds { 6753ae1c24eSEd L. Cashin struct sk_buff *sl; 6761da177e4SLinus Torvalds 6773ae1c24eSEd L. Cashin sl = aoecmd_cfg_pkts(aoemajor, aoeminor, NULL); 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds aoenet_xmit(sl); 6801da177e4SLinus Torvalds } 6811da177e4SLinus Torvalds 6821da177e4SLinus Torvalds /* 6831da177e4SLinus Torvalds * Since we only call this in one place (and it only prepares one frame) 684a4b38364Secashin@coraid.com * we just return the skb. Usually we'd chain it up to the aoedev sendq. 6851da177e4SLinus Torvalds */ 6861da177e4SLinus Torvalds static struct sk_buff * 6871da177e4SLinus Torvalds aoecmd_ata_id(struct aoedev *d) 6881da177e4SLinus Torvalds { 6891da177e4SLinus Torvalds struct aoe_hdr *h; 6901da177e4SLinus Torvalds struct aoe_atahdr *ah; 6911da177e4SLinus Torvalds struct frame *f; 6921da177e4SLinus Torvalds struct sk_buff *skb; 6931da177e4SLinus Torvalds 6944f51dc5eSEd L. Cashin f = freeframe(d); 6951da177e4SLinus Torvalds if (f == NULL) { 696a12c93f0SEd L. Cashin printk(KERN_ERR "aoe: can't get a frame. This shouldn't happen.\n"); 6971da177e4SLinus Torvalds return NULL; 6981da177e4SLinus Torvalds } 6991da177e4SLinus Torvalds 7001da177e4SLinus Torvalds /* initialize the headers & frame */ 701e407a7f6SEd L. Cashin skb = f->skb; 702*abdbf94dSEd L. Cashin h = (struct aoe_hdr *) skb_mac_header(skb); 7031da177e4SLinus Torvalds ah = (struct aoe_atahdr *) (h+1); 70419900cdeSEd L. Cashin skb_put(skb, sizeof *h + sizeof *ah); 70519900cdeSEd L. Cashin memset(h, 0, skb->len); 7061da177e4SLinus Torvalds f->tag = aoehdr_atainit(d, h); 7071da177e4SLinus Torvalds f->waited = 0; 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds /* set up ata header */ 7101da177e4SLinus Torvalds ah->scnt = 1; 7111da177e4SLinus Torvalds ah->cmdstat = WIN_IDENTIFY; 7121da177e4SLinus Torvalds ah->lba3 = 0xa0; 7131da177e4SLinus Torvalds 714e407a7f6SEd L. Cashin skb->dev = d->ifp; 7151da177e4SLinus Torvalds 7163ae1c24eSEd L. Cashin d->rttavg = MAXTIMER; 7171da177e4SLinus Torvalds d->timer.function = rexmit_timer; 7181da177e4SLinus Torvalds 7194f51dc5eSEd L. Cashin return skb_clone(skb, GFP_ATOMIC); 7201da177e4SLinus Torvalds } 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds void 7231da177e4SLinus Torvalds aoecmd_cfg_rsp(struct sk_buff *skb) 7241da177e4SLinus Torvalds { 7251da177e4SLinus Torvalds struct aoedev *d; 7261da177e4SLinus Torvalds struct aoe_hdr *h; 7271da177e4SLinus Torvalds struct aoe_cfghdr *ch; 72863e9cc5dSecashin@coraid.com ulong flags, sysminor, aoemajor; 7291da177e4SLinus Torvalds struct sk_buff *sl; 730eaf0a3cbSEd L. Cashin enum { MAXFRAMES = 16 }; 73119bf2635SEd L. Cashin u16 n; 7321da177e4SLinus Torvalds 733*abdbf94dSEd L. Cashin h = (struct aoe_hdr *) skb_mac_header(skb); 7341da177e4SLinus Torvalds ch = (struct aoe_cfghdr *) (h+1); 7351da177e4SLinus Torvalds 7361da177e4SLinus Torvalds /* 7371da177e4SLinus Torvalds * Enough people have their dip switches set backwards to 7381da177e4SLinus Torvalds * warrant a loud message for this special case. 7391da177e4SLinus Torvalds */ 74043ecf529SDavid S. Miller aoemajor = be16_to_cpu(get_unaligned(&h->major)); 7411da177e4SLinus Torvalds if (aoemajor == 0xfff) { 742a12c93f0SEd L. Cashin printk(KERN_ERR "aoe: Warning: shelf address is all ones. " 7436bb6285fSEd L. Cashin "Check shelf dip switches.\n"); 7441da177e4SLinus Torvalds return; 7451da177e4SLinus Torvalds } 7461da177e4SLinus Torvalds 7471da177e4SLinus Torvalds sysminor = SYSMINOR(aoemajor, h->minor); 748fc458dcdSecashin@coraid.com if (sysminor * AOE_PARTITIONS + AOE_PARTITIONS > MINORMASK) { 749a12c93f0SEd L. Cashin printk(KERN_INFO "aoe: e%ld.%d: minor number too large\n", 750fc458dcdSecashin@coraid.com aoemajor, (int) h->minor); 7511da177e4SLinus Torvalds return; 7521da177e4SLinus Torvalds } 7531da177e4SLinus Torvalds 75419bf2635SEd L. Cashin n = be16_to_cpu(ch->bufcnt); 75519bf2635SEd L. Cashin if (n > MAXFRAMES) /* keep it reasonable */ 75619bf2635SEd L. Cashin n = MAXFRAMES; 7571da177e4SLinus Torvalds 75819bf2635SEd L. Cashin d = aoedev_by_sysminor_m(sysminor, n); 7591da177e4SLinus Torvalds if (d == NULL) { 760a12c93f0SEd L. Cashin printk(KERN_INFO "aoe: device sysminor_m failure\n"); 7611da177e4SLinus Torvalds return; 7621da177e4SLinus Torvalds } 7631da177e4SLinus Torvalds 7641da177e4SLinus Torvalds spin_lock_irqsave(&d->lock, flags); 7651da177e4SLinus Torvalds 7663ae1c24eSEd L. Cashin /* permit device to migrate mac and network interface */ 7673ae1c24eSEd L. Cashin d->ifp = skb->dev; 7683ae1c24eSEd L. Cashin memcpy(d->addr, h->src, sizeof d->addr); 76919bf2635SEd L. Cashin if (!(d->flags & DEVFL_MAXBCNT)) { 77019bf2635SEd L. Cashin n = d->ifp->mtu; 77119bf2635SEd L. Cashin n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr); 77219bf2635SEd L. Cashin n /= 512; 77319bf2635SEd L. Cashin if (n > ch->scnt) 77419bf2635SEd L. Cashin n = ch->scnt; 7754f51dc5eSEd L. Cashin n = n ? n * 512 : DEFAULTBCNT; 7764f51dc5eSEd L. Cashin if (n != d->maxbcnt) { 777a12c93f0SEd L. Cashin printk(KERN_INFO 778a12c93f0SEd L. Cashin "aoe: e%ld.%ld: setting %d byte data frames on %s\n", 7794f51dc5eSEd L. Cashin d->aoemajor, d->aoeminor, n, d->ifp->name); 7804f51dc5eSEd L. Cashin d->maxbcnt = n; 7814f51dc5eSEd L. Cashin } 78219bf2635SEd L. Cashin } 7833ae1c24eSEd L. Cashin 7843ae1c24eSEd L. Cashin /* don't change users' perspective */ 7853ae1c24eSEd L. Cashin if (d->nopen && !(d->flags & DEVFL_PAUSE)) { 7861da177e4SLinus Torvalds spin_unlock_irqrestore(&d->lock, flags); 7871da177e4SLinus Torvalds return; 7881da177e4SLinus Torvalds } 7893ae1c24eSEd L. Cashin d->flags |= DEVFL_PAUSE; /* force pause */ 790dced3a05SEd L. Cashin d->mintimer = MINTIMER; 79163e9cc5dSecashin@coraid.com d->fw_ver = be16_to_cpu(ch->fwver); 7921da177e4SLinus Torvalds 7933ae1c24eSEd L. Cashin /* check for already outstanding ataid */ 7943ae1c24eSEd L. Cashin sl = aoedev_isbusy(d) == 0 ? aoecmd_ata_id(d) : NULL; 7951da177e4SLinus Torvalds 7961da177e4SLinus Torvalds spin_unlock_irqrestore(&d->lock, flags); 7971da177e4SLinus Torvalds 7981da177e4SLinus Torvalds aoenet_xmit(sl); 7991da177e4SLinus Torvalds } 8001da177e4SLinus Torvalds 801