xref: /openbmc/linux/drivers/block/aoe/aoecmd.c (revision 19bf26353c50bc2be375109ec73f2f0bbd616ed1)
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>
12475172fbSEd L. Cashin #include <asm/unaligned.h>
131da177e4SLinus Torvalds #include "aoe.h"
141da177e4SLinus Torvalds 
151da177e4SLinus Torvalds #define TIMERTICK (HZ / 10)
161da177e4SLinus Torvalds #define MINTIMER (2 * TIMERTICK)
171da177e4SLinus Torvalds #define MAXTIMER (HZ << 1)
181da177e4SLinus Torvalds #define MAXWAIT (60 * 3)	/* After MAXWAIT seconds, give up and fail dev */
191da177e4SLinus Torvalds 
20e407a7f6SEd L. Cashin struct sk_buff *
21e407a7f6SEd L. Cashin new_skb(ulong len)
221da177e4SLinus Torvalds {
231da177e4SLinus Torvalds 	struct sk_buff *skb;
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds 	skb = alloc_skb(len, GFP_ATOMIC);
261da177e4SLinus Torvalds 	if (skb) {
271da177e4SLinus Torvalds 		skb->nh.raw = skb->mac.raw = skb->data;
281da177e4SLinus Torvalds 		skb->protocol = __constant_htons(ETH_P_AOE);
291da177e4SLinus Torvalds 		skb->priority = 0;
301da177e4SLinus Torvalds 		skb_put(skb, len);
3150bba752SEd L. Cashin 		memset(skb->head, 0, len);
321da177e4SLinus Torvalds 		skb->next = skb->prev = NULL;
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds 		/* tell the network layer not to perform IP checksums
351da177e4SLinus Torvalds 		 * or to get the NIC to do it
361da177e4SLinus Torvalds 		 */
371da177e4SLinus Torvalds 		skb->ip_summed = CHECKSUM_NONE;
381da177e4SLinus Torvalds 	}
391da177e4SLinus Torvalds 	return skb;
401da177e4SLinus Torvalds }
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds static struct frame *
431da177e4SLinus Torvalds getframe(struct aoedev *d, int tag)
441da177e4SLinus Torvalds {
451da177e4SLinus Torvalds 	struct frame *f, *e;
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds 	f = d->frames;
481da177e4SLinus Torvalds 	e = f + d->nframes;
491da177e4SLinus Torvalds 	for (; f<e; f++)
501da177e4SLinus Torvalds 		if (f->tag == tag)
511da177e4SLinus Torvalds 			return f;
521da177e4SLinus Torvalds 	return NULL;
531da177e4SLinus Torvalds }
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds /*
561da177e4SLinus Torvalds  * Leave the top bit clear so we have tagspace for userland.
571da177e4SLinus Torvalds  * The bottom 16 bits are the xmit tick for rexmit/rttavg processing.
581da177e4SLinus Torvalds  * This driver reserves tag -1 to mean "unused frame."
591da177e4SLinus Torvalds  */
601da177e4SLinus Torvalds static int
611da177e4SLinus Torvalds newtag(struct aoedev *d)
621da177e4SLinus Torvalds {
631da177e4SLinus Torvalds 	register ulong n;
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds 	n = jiffies & 0xffff;
661da177e4SLinus Torvalds 	return n |= (++d->lasttag & 0x7fff) << 16;
671da177e4SLinus Torvalds }
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds static int
701da177e4SLinus Torvalds aoehdr_atainit(struct aoedev *d, struct aoe_hdr *h)
711da177e4SLinus Torvalds {
721da177e4SLinus Torvalds 	u32 host_tag = newtag(d);
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds 	memcpy(h->src, d->ifp->dev_addr, sizeof h->src);
751da177e4SLinus Torvalds 	memcpy(h->dst, d->addr, sizeof h->dst);
7663e9cc5dSecashin@coraid.com 	h->type = __constant_cpu_to_be16(ETH_P_AOE);
771da177e4SLinus Torvalds 	h->verfl = AOE_HVER;
7863e9cc5dSecashin@coraid.com 	h->major = cpu_to_be16(d->aoemajor);
791da177e4SLinus Torvalds 	h->minor = d->aoeminor;
801da177e4SLinus Torvalds 	h->cmd = AOECMD_ATA;
8163e9cc5dSecashin@coraid.com 	h->tag = cpu_to_be32(host_tag);
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds 	return host_tag;
841da177e4SLinus Torvalds }
851da177e4SLinus Torvalds 
86*19bf2635SEd L. Cashin static inline void
87*19bf2635SEd L. Cashin put_lba(struct aoe_atahdr *ah, sector_t lba)
88*19bf2635SEd L. Cashin {
89*19bf2635SEd L. Cashin 	ah->lba0 = lba;
90*19bf2635SEd L. Cashin 	ah->lba1 = lba >>= 8;
91*19bf2635SEd L. Cashin 	ah->lba2 = lba >>= 8;
92*19bf2635SEd L. Cashin 	ah->lba3 = lba >>= 8;
93*19bf2635SEd L. Cashin 	ah->lba4 = lba >>= 8;
94*19bf2635SEd L. Cashin 	ah->lba5 = lba >>= 8;
95*19bf2635SEd L. Cashin }
96*19bf2635SEd L. Cashin 
971da177e4SLinus Torvalds static void
981da177e4SLinus Torvalds aoecmd_ata_rw(struct aoedev *d, struct frame *f)
991da177e4SLinus Torvalds {
1001da177e4SLinus Torvalds 	struct aoe_hdr *h;
1011da177e4SLinus Torvalds 	struct aoe_atahdr *ah;
1021da177e4SLinus Torvalds 	struct buf *buf;
1031da177e4SLinus Torvalds 	struct sk_buff *skb;
1041da177e4SLinus Torvalds 	ulong bcnt;
1051da177e4SLinus Torvalds 	register sector_t sector;
1061da177e4SLinus Torvalds 	char writebit, extbit;
1071da177e4SLinus Torvalds 
1081da177e4SLinus Torvalds 	writebit = 0x10;
1091da177e4SLinus Torvalds 	extbit = 0x4;
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds 	buf = d->inprocess;
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds 	sector = buf->sector;
1141da177e4SLinus Torvalds 	bcnt = buf->bv_resid;
115*19bf2635SEd L. Cashin 	if (bcnt > d->maxbcnt)
116*19bf2635SEd L. Cashin 		bcnt = d->maxbcnt;
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds 	/* initialize the headers & frame */
119e407a7f6SEd L. Cashin 	skb = f->skb;
120e407a7f6SEd L. Cashin 	h = (struct aoe_hdr *) skb->mac.raw;
1211da177e4SLinus Torvalds 	ah = (struct aoe_atahdr *) (h+1);
122e407a7f6SEd L. Cashin 	skb->len = sizeof *h + sizeof *ah;
123e407a7f6SEd L. Cashin 	memset(h, 0, skb->len);
1241da177e4SLinus Torvalds 	f->tag = aoehdr_atainit(d, h);
1251da177e4SLinus Torvalds 	f->waited = 0;
1261da177e4SLinus Torvalds 	f->buf = buf;
1271da177e4SLinus Torvalds 	f->bufaddr = buf->bufaddr;
128*19bf2635SEd L. Cashin 	f->bcnt = bcnt;
129*19bf2635SEd L. Cashin 	f->lba = sector;
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds 	/* set up ata header */
1321da177e4SLinus Torvalds 	ah->scnt = bcnt >> 9;
133*19bf2635SEd L. Cashin 	put_lba(ah, sector);
1341da177e4SLinus Torvalds 	if (d->flags & DEVFL_EXT) {
1351da177e4SLinus Torvalds 		ah->aflags |= AOEAFL_EXT;
1361da177e4SLinus Torvalds 	} else {
1371da177e4SLinus Torvalds 		extbit = 0;
1381da177e4SLinus Torvalds 		ah->lba3 &= 0x0f;
1391da177e4SLinus Torvalds 		ah->lba3 |= 0xe0;	/* LBA bit + obsolete 0xa0 */
1401da177e4SLinus Torvalds 	}
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds 	if (bio_data_dir(buf->bio) == WRITE) {
143e407a7f6SEd L. Cashin 		skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr),
144e407a7f6SEd L. Cashin 			offset_in_page(f->bufaddr), bcnt);
1451da177e4SLinus Torvalds 		ah->aflags |= AOEAFL_WRITE;
1461da177e4SLinus Torvalds 	} else {
147e407a7f6SEd L. Cashin 		skb_shinfo(skb)->nr_frags = 0;
148e407a7f6SEd L. Cashin 		skb->len = ETH_ZLEN;
1491da177e4SLinus Torvalds 		writebit = 0;
1501da177e4SLinus Torvalds 	}
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds 	ah->cmdstat = WIN_READ | writebit | extbit;
1531da177e4SLinus Torvalds 
1541da177e4SLinus Torvalds 	/* mark all tracking fields and load out */
1551da177e4SLinus Torvalds 	buf->nframesout += 1;
1561da177e4SLinus Torvalds 	buf->bufaddr += bcnt;
1571da177e4SLinus Torvalds 	buf->bv_resid -= bcnt;
1581da177e4SLinus Torvalds /* printk(KERN_INFO "aoe: bv_resid=%ld\n", buf->bv_resid); */
1591da177e4SLinus Torvalds 	buf->resid -= bcnt;
1601da177e4SLinus Torvalds 	buf->sector += bcnt >> 9;
1611da177e4SLinus Torvalds 	if (buf->resid == 0) {
1621da177e4SLinus Torvalds 		d->inprocess = NULL;
1631da177e4SLinus Torvalds 	} else if (buf->bv_resid == 0) {
1641da177e4SLinus Torvalds 		buf->bv++;
1651da177e4SLinus Torvalds 		buf->bv_resid = buf->bv->bv_len;
1661da177e4SLinus Torvalds 		buf->bufaddr = page_address(buf->bv->bv_page) + buf->bv->bv_offset;
1671da177e4SLinus Torvalds 	}
1681da177e4SLinus Torvalds 
169e407a7f6SEd L. Cashin 	skb->dev = d->ifp;
170e407a7f6SEd L. Cashin 	skb_get(skb);
171a4b38364Secashin@coraid.com 	skb->next = NULL;
172a4b38364Secashin@coraid.com 	if (d->sendq_hd)
173a4b38364Secashin@coraid.com 		d->sendq_tl->next = skb;
174a4b38364Secashin@coraid.com 	else
175a4b38364Secashin@coraid.com 		d->sendq_hd = skb;
176a4b38364Secashin@coraid.com 	d->sendq_tl = skb;
1771da177e4SLinus Torvalds }
1781da177e4SLinus Torvalds 
1793ae1c24eSEd L. Cashin /* some callers cannot sleep, and they can call this function,
1803ae1c24eSEd L. Cashin  * transmitting the packets later, when interrupts are on
1813ae1c24eSEd L. Cashin  */
1823ae1c24eSEd L. Cashin static struct sk_buff *
1833ae1c24eSEd L. Cashin aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail)
1843ae1c24eSEd L. Cashin {
1853ae1c24eSEd L. Cashin 	struct aoe_hdr *h;
1863ae1c24eSEd L. Cashin 	struct aoe_cfghdr *ch;
1873ae1c24eSEd L. Cashin 	struct sk_buff *skb, *sl, *sl_tail;
1883ae1c24eSEd L. Cashin 	struct net_device *ifp;
1893ae1c24eSEd L. Cashin 
1903ae1c24eSEd L. Cashin 	sl = sl_tail = NULL;
1913ae1c24eSEd L. Cashin 
1923ae1c24eSEd L. Cashin 	read_lock(&dev_base_lock);
1933ae1c24eSEd L. Cashin 	for (ifp = dev_base; ifp; dev_put(ifp), ifp = ifp->next) {
1943ae1c24eSEd L. Cashin 		dev_hold(ifp);
1953ae1c24eSEd L. Cashin 		if (!is_aoe_netif(ifp))
1963ae1c24eSEd L. Cashin 			continue;
1973ae1c24eSEd L. Cashin 
198e407a7f6SEd L. Cashin 		skb = new_skb(sizeof *h + sizeof *ch);
1993ae1c24eSEd L. Cashin 		if (skb == NULL) {
2003ae1c24eSEd L. Cashin 			printk(KERN_INFO "aoe: aoecmd_cfg: skb alloc failure\n");
2013ae1c24eSEd L. Cashin 			continue;
2023ae1c24eSEd L. Cashin 		}
203e407a7f6SEd L. Cashin 		skb->dev = ifp;
2043ae1c24eSEd L. Cashin 		if (sl_tail == NULL)
2053ae1c24eSEd L. Cashin 			sl_tail = skb;
2063ae1c24eSEd L. Cashin 		h = (struct aoe_hdr *) skb->mac.raw;
2073ae1c24eSEd L. Cashin 		memset(h, 0, sizeof *h + sizeof *ch);
2083ae1c24eSEd L. Cashin 
2093ae1c24eSEd L. Cashin 		memset(h->dst, 0xff, sizeof h->dst);
2103ae1c24eSEd L. Cashin 		memcpy(h->src, ifp->dev_addr, sizeof h->src);
2113ae1c24eSEd L. Cashin 		h->type = __constant_cpu_to_be16(ETH_P_AOE);
2123ae1c24eSEd L. Cashin 		h->verfl = AOE_HVER;
2133ae1c24eSEd L. Cashin 		h->major = cpu_to_be16(aoemajor);
2143ae1c24eSEd L. Cashin 		h->minor = aoeminor;
2153ae1c24eSEd L. Cashin 		h->cmd = AOECMD_CFG;
2163ae1c24eSEd L. Cashin 
2173ae1c24eSEd L. Cashin 		skb->next = sl;
2183ae1c24eSEd L. Cashin 		sl = skb;
2193ae1c24eSEd L. Cashin 	}
2203ae1c24eSEd L. Cashin 	read_unlock(&dev_base_lock);
2213ae1c24eSEd L. Cashin 
2223ae1c24eSEd L. Cashin 	if (tail != NULL)
2233ae1c24eSEd L. Cashin 		*tail = sl_tail;
2243ae1c24eSEd L. Cashin 	return sl;
2253ae1c24eSEd L. Cashin }
2263ae1c24eSEd L. Cashin 
2271da177e4SLinus Torvalds /* enters with d->lock held */
2281da177e4SLinus Torvalds void
2291da177e4SLinus Torvalds aoecmd_work(struct aoedev *d)
2301da177e4SLinus Torvalds {
2311da177e4SLinus Torvalds 	struct frame *f;
2321da177e4SLinus Torvalds 	struct buf *buf;
2333ae1c24eSEd L. Cashin 
2343ae1c24eSEd L. Cashin 	if (d->flags & DEVFL_PAUSE) {
2353ae1c24eSEd L. Cashin 		if (!aoedev_isbusy(d))
2363ae1c24eSEd L. Cashin 			d->sendq_hd = aoecmd_cfg_pkts(d->aoemajor,
2373ae1c24eSEd L. Cashin 						d->aoeminor, &d->sendq_tl);
2383ae1c24eSEd L. Cashin 		return;
2393ae1c24eSEd L. Cashin 	}
2403ae1c24eSEd L. Cashin 
2411da177e4SLinus Torvalds loop:
2421da177e4SLinus Torvalds 	f = getframe(d, FREETAG);
2431da177e4SLinus Torvalds 	if (f == NULL)
2441da177e4SLinus Torvalds 		return;
2451da177e4SLinus Torvalds 	if (d->inprocess == NULL) {
2461da177e4SLinus Torvalds 		if (list_empty(&d->bufq))
2471da177e4SLinus Torvalds 			return;
2481da177e4SLinus Torvalds 		buf = container_of(d->bufq.next, struct buf, bufs);
2491da177e4SLinus Torvalds 		list_del(d->bufq.next);
2501da177e4SLinus Torvalds /*printk(KERN_INFO "aoecmd_work: bi_size=%ld\n", buf->bio->bi_size); */
2511da177e4SLinus Torvalds 		d->inprocess = buf;
2521da177e4SLinus Torvalds 	}
2531da177e4SLinus Torvalds 	aoecmd_ata_rw(d, f);
2541da177e4SLinus Torvalds 	goto loop;
2551da177e4SLinus Torvalds }
2561da177e4SLinus Torvalds 
2571da177e4SLinus Torvalds static void
2581da177e4SLinus Torvalds rexmit(struct aoedev *d, struct frame *f)
2591da177e4SLinus Torvalds {
2601da177e4SLinus Torvalds 	struct sk_buff *skb;
2611da177e4SLinus Torvalds 	struct aoe_hdr *h;
262*19bf2635SEd L. Cashin 	struct aoe_atahdr *ah;
2631da177e4SLinus Torvalds 	char buf[128];
2641da177e4SLinus Torvalds 	u32 n;
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds 	n = newtag(d);
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds 	snprintf(buf, sizeof buf,
2691da177e4SLinus Torvalds 		"%15s e%ld.%ld oldtag=%08x@%08lx newtag=%08x\n",
2701da177e4SLinus Torvalds 		"retransmit",
2711da177e4SLinus Torvalds 		d->aoemajor, d->aoeminor, f->tag, jiffies, n);
2721da177e4SLinus Torvalds 	aoechr_error(buf);
2731da177e4SLinus Torvalds 
274e407a7f6SEd L. Cashin 	skb = f->skb;
275e407a7f6SEd L. Cashin 	h = (struct aoe_hdr *) skb->mac.raw;
276*19bf2635SEd L. Cashin 	ah = (struct aoe_atahdr *) (h+1);
2771da177e4SLinus Torvalds 	f->tag = n;
27863e9cc5dSecashin@coraid.com 	h->tag = cpu_to_be32(n);
2792dd5e422SEd L. Cashin 	memcpy(h->dst, d->addr, sizeof h->dst);
2802dd5e422SEd L. Cashin 	memcpy(h->src, d->ifp->dev_addr, sizeof h->src);
2811da177e4SLinus Torvalds 
282*19bf2635SEd L. Cashin 	n = DEFAULTBCNT / 512;
283*19bf2635SEd L. Cashin 	if (ah->scnt > n) {
284*19bf2635SEd L. Cashin 		ah->scnt = n;
285*19bf2635SEd L. Cashin 		if (ah->aflags & AOEAFL_WRITE)
286*19bf2635SEd L. Cashin 			skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr),
287*19bf2635SEd L. Cashin 				offset_in_page(f->bufaddr), DEFAULTBCNT);
288*19bf2635SEd L. Cashin 		if (++d->lostjumbo > (d->nframes << 1))
289*19bf2635SEd L. Cashin 		if (d->maxbcnt != DEFAULTBCNT) {
290*19bf2635SEd L. Cashin 			printk(KERN_INFO "aoe: rexmit: too many lost jumbo.  "
291*19bf2635SEd L. Cashin 				"dropping back to 1KB frames.\n");
292*19bf2635SEd L. Cashin 			d->maxbcnt = DEFAULTBCNT;
293*19bf2635SEd L. Cashin 			d->flags |= DEVFL_MAXBCNT;
294*19bf2635SEd L. Cashin 		}
295*19bf2635SEd L. Cashin 	}
296*19bf2635SEd L. Cashin 
297e407a7f6SEd L. Cashin 	skb->dev = d->ifp;
298e407a7f6SEd L. Cashin 	skb_get(skb);
299a4b38364Secashin@coraid.com 	skb->next = NULL;
300a4b38364Secashin@coraid.com 	if (d->sendq_hd)
301a4b38364Secashin@coraid.com 		d->sendq_tl->next = skb;
302a4b38364Secashin@coraid.com 	else
303a4b38364Secashin@coraid.com 		d->sendq_hd = skb;
304a4b38364Secashin@coraid.com 	d->sendq_tl = skb;
3051da177e4SLinus Torvalds }
3061da177e4SLinus Torvalds 
3071da177e4SLinus Torvalds static int
3081da177e4SLinus Torvalds tsince(int tag)
3091da177e4SLinus Torvalds {
3101da177e4SLinus Torvalds 	int n;
3111da177e4SLinus Torvalds 
3121da177e4SLinus Torvalds 	n = jiffies & 0xffff;
3131da177e4SLinus Torvalds 	n -= tag & 0xffff;
3141da177e4SLinus Torvalds 	if (n < 0)
3151da177e4SLinus Torvalds 		n += 1<<16;
3161da177e4SLinus Torvalds 	return n;
3171da177e4SLinus Torvalds }
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds static void
3201da177e4SLinus Torvalds rexmit_timer(ulong vp)
3211da177e4SLinus Torvalds {
3221da177e4SLinus Torvalds 	struct aoedev *d;
3231da177e4SLinus Torvalds 	struct frame *f, *e;
3241da177e4SLinus Torvalds 	struct sk_buff *sl;
3251da177e4SLinus Torvalds 	register long timeout;
3261da177e4SLinus Torvalds 	ulong flags, n;
3271da177e4SLinus Torvalds 
3281da177e4SLinus Torvalds 	d = (struct aoedev *) vp;
3291da177e4SLinus Torvalds 	sl = NULL;
3301da177e4SLinus Torvalds 
3311da177e4SLinus Torvalds 	/* timeout is always ~150% of the moving average */
3321da177e4SLinus Torvalds 	timeout = d->rttavg;
3331da177e4SLinus Torvalds 	timeout += timeout >> 1;
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds 	spin_lock_irqsave(&d->lock, flags);
3361da177e4SLinus Torvalds 
3371da177e4SLinus Torvalds 	if (d->flags & DEVFL_TKILL) {
3381c6f3fcaSEd L. Cashin 		spin_unlock_irqrestore(&d->lock, flags);
3391da177e4SLinus Torvalds 		return;
3401da177e4SLinus Torvalds 	}
3411da177e4SLinus Torvalds 	f = d->frames;
3421da177e4SLinus Torvalds 	e = f + d->nframes;
3431da177e4SLinus Torvalds 	for (; f<e; f++) {
3441da177e4SLinus Torvalds 		if (f->tag != FREETAG && tsince(f->tag) >= timeout) {
3451da177e4SLinus Torvalds 			n = f->waited += timeout;
3461da177e4SLinus Torvalds 			n /= HZ;
3471da177e4SLinus Torvalds 			if (n > MAXWAIT) { /* waited too long.  device failure. */
3481da177e4SLinus Torvalds 				aoedev_downdev(d);
3491c6f3fcaSEd L. Cashin 				break;
3501da177e4SLinus Torvalds 			}
3511da177e4SLinus Torvalds 			rexmit(d, f);
3521da177e4SLinus Torvalds 		}
3531da177e4SLinus Torvalds 	}
3541da177e4SLinus Torvalds 
355a4b38364Secashin@coraid.com 	sl = d->sendq_hd;
356a4b38364Secashin@coraid.com 	d->sendq_hd = d->sendq_tl = NULL;
3571da177e4SLinus Torvalds 	if (sl) {
3581da177e4SLinus Torvalds 		n = d->rttavg <<= 1;
3591da177e4SLinus Torvalds 		if (n > MAXTIMER)
3601da177e4SLinus Torvalds 			d->rttavg = MAXTIMER;
3611da177e4SLinus Torvalds 	}
3621da177e4SLinus Torvalds 
3631da177e4SLinus Torvalds 	d->timer.expires = jiffies + TIMERTICK;
3641da177e4SLinus Torvalds 	add_timer(&d->timer);
3651da177e4SLinus Torvalds 
3661da177e4SLinus Torvalds 	spin_unlock_irqrestore(&d->lock, flags);
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds 	aoenet_xmit(sl);
3691da177e4SLinus Torvalds }
3701da177e4SLinus Torvalds 
3713ae1c24eSEd L. Cashin /* this function performs work that has been deferred until sleeping is OK
3723ae1c24eSEd L. Cashin  */
3733ae1c24eSEd L. Cashin void
3743ae1c24eSEd L. Cashin aoecmd_sleepwork(void *vp)
3753ae1c24eSEd L. Cashin {
3763ae1c24eSEd L. Cashin 	struct aoedev *d = (struct aoedev *) vp;
3773ae1c24eSEd L. Cashin 
3783ae1c24eSEd L. Cashin 	if (d->flags & DEVFL_GDALLOC)
3793ae1c24eSEd L. Cashin 		aoeblk_gdalloc(d);
3803ae1c24eSEd L. Cashin 
3813ae1c24eSEd L. Cashin 	if (d->flags & DEVFL_NEWSIZE) {
3823ae1c24eSEd L. Cashin 		struct block_device *bd;
3833ae1c24eSEd L. Cashin 		unsigned long flags;
3843ae1c24eSEd L. Cashin 		u64 ssize;
3853ae1c24eSEd L. Cashin 
3863ae1c24eSEd L. Cashin 		ssize = d->gd->capacity;
3873ae1c24eSEd L. Cashin 		bd = bdget_disk(d->gd, 0);
3883ae1c24eSEd L. Cashin 
3893ae1c24eSEd L. Cashin 		if (bd) {
3903ae1c24eSEd L. Cashin 			mutex_lock(&bd->bd_inode->i_mutex);
3913ae1c24eSEd L. Cashin 			i_size_write(bd->bd_inode, (loff_t)ssize<<9);
3923ae1c24eSEd L. Cashin 			mutex_unlock(&bd->bd_inode->i_mutex);
3933ae1c24eSEd L. Cashin 			bdput(bd);
3943ae1c24eSEd L. Cashin 		}
3953ae1c24eSEd L. Cashin 		spin_lock_irqsave(&d->lock, flags);
3963ae1c24eSEd L. Cashin 		d->flags |= DEVFL_UP;
3973ae1c24eSEd L. Cashin 		d->flags &= ~DEVFL_NEWSIZE;
3983ae1c24eSEd L. Cashin 		spin_unlock_irqrestore(&d->lock, flags);
3993ae1c24eSEd L. Cashin 	}
4003ae1c24eSEd L. Cashin }
4013ae1c24eSEd L. Cashin 
4021da177e4SLinus Torvalds static void
4031da177e4SLinus Torvalds ataid_complete(struct aoedev *d, unsigned char *id)
4041da177e4SLinus Torvalds {
4051da177e4SLinus Torvalds 	u64 ssize;
4061da177e4SLinus Torvalds 	u16 n;
4071da177e4SLinus Torvalds 
4081da177e4SLinus Torvalds 	/* word 83: command set supported */
409475172fbSEd L. Cashin 	n = le16_to_cpu(get_unaligned((__le16 *) &id[83<<1]));
4101da177e4SLinus Torvalds 
4111da177e4SLinus Torvalds 	/* word 86: command set/feature enabled */
412475172fbSEd L. Cashin 	n |= le16_to_cpu(get_unaligned((__le16 *) &id[86<<1]));
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds 	if (n & (1<<10)) {	/* bit 10: LBA 48 */
4151da177e4SLinus Torvalds 		d->flags |= DEVFL_EXT;
4161da177e4SLinus Torvalds 
4171da177e4SLinus Torvalds 		/* word 100: number lba48 sectors */
418475172fbSEd L. Cashin 		ssize = le64_to_cpu(get_unaligned((__le64 *) &id[100<<1]));
4191da177e4SLinus Torvalds 
4201da177e4SLinus Torvalds 		/* set as in ide-disk.c:init_idedisk_capacity */
4211da177e4SLinus Torvalds 		d->geo.cylinders = ssize;
4221da177e4SLinus Torvalds 		d->geo.cylinders /= (255 * 63);
4231da177e4SLinus Torvalds 		d->geo.heads = 255;
4241da177e4SLinus Torvalds 		d->geo.sectors = 63;
4251da177e4SLinus Torvalds 	} else {
4261da177e4SLinus Torvalds 		d->flags &= ~DEVFL_EXT;
4271da177e4SLinus Torvalds 
4281da177e4SLinus Torvalds 		/* number lba28 sectors */
429475172fbSEd L. Cashin 		ssize = le32_to_cpu(get_unaligned((__le32 *) &id[60<<1]));
4301da177e4SLinus Torvalds 
4311da177e4SLinus Torvalds 		/* NOTE: obsolete in ATA 6 */
432475172fbSEd L. Cashin 		d->geo.cylinders = le16_to_cpu(get_unaligned((__le16 *) &id[54<<1]));
433475172fbSEd L. Cashin 		d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1]));
434475172fbSEd L. Cashin 		d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1]));
4351da177e4SLinus Torvalds 	}
4363ae1c24eSEd L. Cashin 
4373ae1c24eSEd L. Cashin 	if (d->ssize != ssize)
4383ae1c24eSEd L. Cashin 		printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu "
4393ae1c24eSEd L. Cashin 			"sectors\n", (unsigned long long)mac_addr(d->addr),
4403ae1c24eSEd L. Cashin 			d->aoemajor, d->aoeminor,
4413ae1c24eSEd L. Cashin 			d->fw_ver, (long long)ssize);
4421da177e4SLinus Torvalds 	d->ssize = ssize;
4431da177e4SLinus Torvalds 	d->geo.start = 0;
4441da177e4SLinus Torvalds 	if (d->gd != NULL) {
4451da177e4SLinus Torvalds 		d->gd->capacity = ssize;
4463ae1c24eSEd L. Cashin 		d->flags |= DEVFL_NEWSIZE;
4473ae1c24eSEd L. Cashin 	} else {
4483ae1c24eSEd L. Cashin 		if (d->flags & DEVFL_GDALLOC) {
4493ae1c24eSEd L. Cashin 			printk(KERN_INFO "aoe: %s: %s e%lu.%lu, %s\n",
4503ae1c24eSEd L. Cashin 			       __FUNCTION__,
4513ae1c24eSEd L. Cashin 			       "can't schedule work for",
4523ae1c24eSEd L. Cashin 			       d->aoemajor, d->aoeminor,
4533ae1c24eSEd L. Cashin 			       "it's already on! (This really shouldn't happen).\n");
4541da177e4SLinus Torvalds 			return;
4551da177e4SLinus Torvalds 		}
4563ae1c24eSEd L. Cashin 		d->flags |= DEVFL_GDALLOC;
4571da177e4SLinus Torvalds 	}
4581da177e4SLinus Torvalds 	schedule_work(&d->work);
4591da177e4SLinus Torvalds }
4601da177e4SLinus Torvalds 
4611da177e4SLinus Torvalds static void
4621da177e4SLinus Torvalds calc_rttavg(struct aoedev *d, int rtt)
4631da177e4SLinus Torvalds {
4641da177e4SLinus Torvalds 	register long n;
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds 	n = rtt;
4671da177e4SLinus Torvalds 	if (n < MINTIMER)
4681da177e4SLinus Torvalds 		n = MINTIMER;
4691da177e4SLinus Torvalds 	else if (n > MAXTIMER)
4701da177e4SLinus Torvalds 		n = MAXTIMER;
4711da177e4SLinus Torvalds 
4721da177e4SLinus Torvalds 	/* g == .25; cf. Congestion Avoidance and Control, Jacobson & Karels; 1988 */
4731da177e4SLinus Torvalds 	n -= d->rttavg;
4741da177e4SLinus Torvalds 	d->rttavg += n >> 2;
4751da177e4SLinus Torvalds }
4761da177e4SLinus Torvalds 
4771da177e4SLinus Torvalds void
4781da177e4SLinus Torvalds aoecmd_ata_rsp(struct sk_buff *skb)
4791da177e4SLinus Torvalds {
4801da177e4SLinus Torvalds 	struct aoedev *d;
4811da177e4SLinus Torvalds 	struct aoe_hdr *hin;
4821da177e4SLinus Torvalds 	struct aoe_atahdr *ahin, *ahout;
4831da177e4SLinus Torvalds 	struct frame *f;
4841da177e4SLinus Torvalds 	struct buf *buf;
4851da177e4SLinus Torvalds 	struct sk_buff *sl;
4861da177e4SLinus Torvalds 	register long n;
4871da177e4SLinus Torvalds 	ulong flags;
4881da177e4SLinus Torvalds 	char ebuf[128];
48932465c65Secashin@coraid.com 	u16 aoemajor;
4901da177e4SLinus Torvalds 
4911da177e4SLinus Torvalds 	hin = (struct aoe_hdr *) skb->mac.raw;
49263e9cc5dSecashin@coraid.com 	aoemajor = be16_to_cpu(hin->major);
49332465c65Secashin@coraid.com 	d = aoedev_by_aoeaddr(aoemajor, hin->minor);
4941da177e4SLinus Torvalds 	if (d == NULL) {
4951da177e4SLinus Torvalds 		snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response "
4961da177e4SLinus Torvalds 			"for unknown device %d.%d\n",
49732465c65Secashin@coraid.com 			 aoemajor, hin->minor);
4981da177e4SLinus Torvalds 		aoechr_error(ebuf);
4991da177e4SLinus Torvalds 		return;
5001da177e4SLinus Torvalds 	}
5011da177e4SLinus Torvalds 
5021da177e4SLinus Torvalds 	spin_lock_irqsave(&d->lock, flags);
5031da177e4SLinus Torvalds 
50463e9cc5dSecashin@coraid.com 	f = getframe(d, be32_to_cpu(hin->tag));
5051da177e4SLinus Torvalds 	if (f == NULL) {
5061da177e4SLinus Torvalds 		spin_unlock_irqrestore(&d->lock, flags);
5071da177e4SLinus Torvalds 		snprintf(ebuf, sizeof ebuf,
5081da177e4SLinus Torvalds 			"%15s e%d.%d    tag=%08x@%08lx\n",
5091da177e4SLinus Torvalds 			"unexpected rsp",
51063e9cc5dSecashin@coraid.com 			be16_to_cpu(hin->major),
5111da177e4SLinus Torvalds 			hin->minor,
51263e9cc5dSecashin@coraid.com 			be32_to_cpu(hin->tag),
5131da177e4SLinus Torvalds 			jiffies);
5141da177e4SLinus Torvalds 		aoechr_error(ebuf);
5151da177e4SLinus Torvalds 		return;
5161da177e4SLinus Torvalds 	}
5171da177e4SLinus Torvalds 
5181da177e4SLinus Torvalds 	calc_rttavg(d, tsince(f->tag));
5191da177e4SLinus Torvalds 
5201da177e4SLinus Torvalds 	ahin = (struct aoe_atahdr *) (hin+1);
521e407a7f6SEd L. Cashin 	ahout = (struct aoe_atahdr *) (f->skb->mac.raw + sizeof(struct aoe_hdr));
5221da177e4SLinus Torvalds 	buf = f->buf;
5231da177e4SLinus Torvalds 
5249d41965bSEd L. Cashin 	if (ahout->cmdstat == WIN_IDENTIFY)
5259d41965bSEd L. Cashin 		d->flags &= ~DEVFL_PAUSE;
5261da177e4SLinus Torvalds 	if (ahin->cmdstat & 0xa9) {	/* these bits cleared on success */
5271da177e4SLinus Torvalds 		printk(KERN_CRIT "aoe: aoecmd_ata_rsp: ata error cmd=%2.2Xh "
5281da177e4SLinus Torvalds 			"stat=%2.2Xh from e%ld.%ld\n",
5291da177e4SLinus Torvalds 			ahout->cmdstat, ahin->cmdstat,
5301da177e4SLinus Torvalds 			d->aoemajor, d->aoeminor);
5311da177e4SLinus Torvalds 		if (buf)
5321da177e4SLinus Torvalds 			buf->flags |= BUFFL_FAIL;
5331da177e4SLinus Torvalds 	} else {
534*19bf2635SEd L. Cashin 		n = ahout->scnt << 9;
5351da177e4SLinus Torvalds 		switch (ahout->cmdstat) {
5361da177e4SLinus Torvalds 		case WIN_READ:
5371da177e4SLinus Torvalds 		case WIN_READ_EXT:
5381da177e4SLinus Torvalds 			if (skb->len - sizeof *hin - sizeof *ahin < n) {
5391da177e4SLinus Torvalds 				printk(KERN_CRIT "aoe: aoecmd_ata_rsp: runt "
5401da177e4SLinus Torvalds 					"ata data size in read.  skb->len=%d\n",
5411da177e4SLinus Torvalds 					skb->len);
5421da177e4SLinus Torvalds 				/* fail frame f?  just returning will rexmit. */
5431da177e4SLinus Torvalds 				spin_unlock_irqrestore(&d->lock, flags);
5441da177e4SLinus Torvalds 				return;
5451da177e4SLinus Torvalds 			}
5461da177e4SLinus Torvalds 			memcpy(f->bufaddr, ahin+1, n);
5471da177e4SLinus Torvalds 		case WIN_WRITE:
5481da177e4SLinus Torvalds 		case WIN_WRITE_EXT:
549*19bf2635SEd L. Cashin 			if (f->bcnt -= n) {
550*19bf2635SEd L. Cashin 				f->bufaddr += n;
551*19bf2635SEd L. Cashin 				put_lba(ahout, f->lba += ahout->scnt);
552*19bf2635SEd L. Cashin 				n = f->bcnt > DEFAULTBCNT ? DEFAULTBCNT : f->bcnt;
553*19bf2635SEd L. Cashin 				ahout->scnt = n >> 9;
554*19bf2635SEd L. Cashin 				if (ahout->aflags & AOEAFL_WRITE)
555*19bf2635SEd L. Cashin 					skb_fill_page_desc(f->skb, 0, virt_to_page(f->bufaddr),
556*19bf2635SEd L. Cashin 						offset_in_page(f->bufaddr), n);
557*19bf2635SEd L. Cashin 				skb_get(f->skb);
558*19bf2635SEd L. Cashin 				f->skb->next = NULL;
559*19bf2635SEd L. Cashin 				spin_unlock_irqrestore(&d->lock, flags);
560*19bf2635SEd L. Cashin 				aoenet_xmit(f->skb);
561*19bf2635SEd L. Cashin 				return;
562*19bf2635SEd L. Cashin 			}
563*19bf2635SEd L. Cashin 			if (n > DEFAULTBCNT)
564*19bf2635SEd L. Cashin 				d->lostjumbo = 0;
5651da177e4SLinus Torvalds 			break;
5661da177e4SLinus Torvalds 		case WIN_IDENTIFY:
5671da177e4SLinus Torvalds 			if (skb->len - sizeof *hin - sizeof *ahin < 512) {
5681da177e4SLinus Torvalds 				printk(KERN_INFO "aoe: aoecmd_ata_rsp: runt data size "
5691da177e4SLinus Torvalds 					"in ataid.  skb->len=%d\n", skb->len);
5701da177e4SLinus Torvalds 				spin_unlock_irqrestore(&d->lock, flags);
5711da177e4SLinus Torvalds 				return;
5721da177e4SLinus Torvalds 			}
5731da177e4SLinus Torvalds 			ataid_complete(d, (char *) (ahin+1));
5741da177e4SLinus Torvalds 			break;
5751da177e4SLinus Torvalds 		default:
5761da177e4SLinus Torvalds 			printk(KERN_INFO "aoe: aoecmd_ata_rsp: unrecognized "
5771da177e4SLinus Torvalds 			       "outbound ata command %2.2Xh for %d.%d\n",
5781da177e4SLinus Torvalds 			       ahout->cmdstat,
57963e9cc5dSecashin@coraid.com 			       be16_to_cpu(hin->major),
5801da177e4SLinus Torvalds 			       hin->minor);
5811da177e4SLinus Torvalds 		}
5821da177e4SLinus Torvalds 	}
5831da177e4SLinus Torvalds 
5841da177e4SLinus Torvalds 	if (buf) {
5851da177e4SLinus Torvalds 		buf->nframesout -= 1;
5861da177e4SLinus Torvalds 		if (buf->nframesout == 0 && buf->resid == 0) {
5870c6f0e79Secashin@coraid.com 			unsigned long duration = jiffies - buf->start_time;
5880c6f0e79Secashin@coraid.com 			unsigned long n_sect = buf->bio->bi_size >> 9;
5890c6f0e79Secashin@coraid.com 			struct gendisk *disk = d->gd;
590496456c2SJens Axboe 			const int rw = bio_data_dir(buf->bio);
5910c6f0e79Secashin@coraid.com 
592496456c2SJens Axboe 			disk_stat_inc(disk, ios[rw]);
593496456c2SJens Axboe 			disk_stat_add(disk, ticks[rw], duration);
594496456c2SJens Axboe 			disk_stat_add(disk, sectors[rw], n_sect);
5950c6f0e79Secashin@coraid.com 			disk_stat_add(disk, io_ticks, duration);
5961da177e4SLinus Torvalds 			n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
5971da177e4SLinus Torvalds 			bio_endio(buf->bio, buf->bio->bi_size, n);
5981da177e4SLinus Torvalds 			mempool_free(buf, d->bufpool);
5991da177e4SLinus Torvalds 		}
6001da177e4SLinus Torvalds 	}
6011da177e4SLinus Torvalds 
6021da177e4SLinus Torvalds 	f->buf = NULL;
6031da177e4SLinus Torvalds 	f->tag = FREETAG;
6041da177e4SLinus Torvalds 
6051da177e4SLinus Torvalds 	aoecmd_work(d);
606a4b38364Secashin@coraid.com 	sl = d->sendq_hd;
607a4b38364Secashin@coraid.com 	d->sendq_hd = d->sendq_tl = NULL;
6081da177e4SLinus Torvalds 
6091da177e4SLinus Torvalds 	spin_unlock_irqrestore(&d->lock, flags);
6101da177e4SLinus Torvalds 	aoenet_xmit(sl);
6111da177e4SLinus Torvalds }
6121da177e4SLinus Torvalds 
6131da177e4SLinus Torvalds void
6141da177e4SLinus Torvalds aoecmd_cfg(ushort aoemajor, unsigned char aoeminor)
6151da177e4SLinus Torvalds {
6163ae1c24eSEd L. Cashin 	struct sk_buff *sl;
6171da177e4SLinus Torvalds 
6183ae1c24eSEd L. Cashin 	sl = aoecmd_cfg_pkts(aoemajor, aoeminor, NULL);
6191da177e4SLinus Torvalds 
6201da177e4SLinus Torvalds 	aoenet_xmit(sl);
6211da177e4SLinus Torvalds }
6221da177e4SLinus Torvalds 
6231da177e4SLinus Torvalds /*
6241da177e4SLinus Torvalds  * Since we only call this in one place (and it only prepares one frame)
625a4b38364Secashin@coraid.com  * we just return the skb.  Usually we'd chain it up to the aoedev sendq.
6261da177e4SLinus Torvalds  */
6271da177e4SLinus Torvalds static struct sk_buff *
6281da177e4SLinus Torvalds aoecmd_ata_id(struct aoedev *d)
6291da177e4SLinus Torvalds {
6301da177e4SLinus Torvalds 	struct aoe_hdr *h;
6311da177e4SLinus Torvalds 	struct aoe_atahdr *ah;
6321da177e4SLinus Torvalds 	struct frame *f;
6331da177e4SLinus Torvalds 	struct sk_buff *skb;
6341da177e4SLinus Torvalds 
6351da177e4SLinus Torvalds 	f = getframe(d, FREETAG);
6361da177e4SLinus Torvalds 	if (f == NULL) {
6371da177e4SLinus Torvalds 		printk(KERN_CRIT "aoe: aoecmd_ata_id: can't get a frame.  "
6381da177e4SLinus Torvalds 			"This shouldn't happen.\n");
6391da177e4SLinus Torvalds 		return NULL;
6401da177e4SLinus Torvalds 	}
6411da177e4SLinus Torvalds 
6421da177e4SLinus Torvalds 	/* initialize the headers & frame */
643e407a7f6SEd L. Cashin 	skb = f->skb;
644e407a7f6SEd L. Cashin 	h = (struct aoe_hdr *) skb->mac.raw;
6451da177e4SLinus Torvalds 	ah = (struct aoe_atahdr *) (h+1);
646e407a7f6SEd L. Cashin 	skb->len = sizeof *h + sizeof *ah;
647e407a7f6SEd L. Cashin 	memset(h, 0, skb->len);
6481da177e4SLinus Torvalds 	f->tag = aoehdr_atainit(d, h);
6491da177e4SLinus Torvalds 	f->waited = 0;
6501da177e4SLinus Torvalds 
6511da177e4SLinus Torvalds 	/* set up ata header */
6521da177e4SLinus Torvalds 	ah->scnt = 1;
6531da177e4SLinus Torvalds 	ah->cmdstat = WIN_IDENTIFY;
6541da177e4SLinus Torvalds 	ah->lba3 = 0xa0;
6551da177e4SLinus Torvalds 
656e407a7f6SEd L. Cashin 	skb->dev = d->ifp;
657e407a7f6SEd L. Cashin 	skb_get(skb);
6581da177e4SLinus Torvalds 
6593ae1c24eSEd L. Cashin 	d->rttavg = MAXTIMER;
6601da177e4SLinus Torvalds 	d->timer.function = rexmit_timer;
6611da177e4SLinus Torvalds 
6621da177e4SLinus Torvalds 	return skb;
6631da177e4SLinus Torvalds }
6641da177e4SLinus Torvalds 
6651da177e4SLinus Torvalds void
6661da177e4SLinus Torvalds aoecmd_cfg_rsp(struct sk_buff *skb)
6671da177e4SLinus Torvalds {
6681da177e4SLinus Torvalds 	struct aoedev *d;
6691da177e4SLinus Torvalds 	struct aoe_hdr *h;
6701da177e4SLinus Torvalds 	struct aoe_cfghdr *ch;
67163e9cc5dSecashin@coraid.com 	ulong flags, sysminor, aoemajor;
6721da177e4SLinus Torvalds 	struct sk_buff *sl;
673eaf0a3cbSEd L. Cashin 	enum { MAXFRAMES = 16 };
674*19bf2635SEd L. Cashin 	u16 n;
6751da177e4SLinus Torvalds 
6761da177e4SLinus Torvalds 	h = (struct aoe_hdr *) skb->mac.raw;
6771da177e4SLinus Torvalds 	ch = (struct aoe_cfghdr *) (h+1);
6781da177e4SLinus Torvalds 
6791da177e4SLinus Torvalds 	/*
6801da177e4SLinus Torvalds 	 * Enough people have their dip switches set backwards to
6811da177e4SLinus Torvalds 	 * warrant a loud message for this special case.
6821da177e4SLinus Torvalds 	 */
68363e9cc5dSecashin@coraid.com 	aoemajor = be16_to_cpu(h->major);
6841da177e4SLinus Torvalds 	if (aoemajor == 0xfff) {
6851da177e4SLinus Torvalds 		printk(KERN_CRIT "aoe: aoecmd_cfg_rsp: Warning: shelf "
6861da177e4SLinus Torvalds 			"address is all ones.  Check shelf dip switches\n");
6871da177e4SLinus Torvalds 		return;
6881da177e4SLinus Torvalds 	}
6891da177e4SLinus Torvalds 
6901da177e4SLinus Torvalds 	sysminor = SYSMINOR(aoemajor, h->minor);
691fc458dcdSecashin@coraid.com 	if (sysminor * AOE_PARTITIONS + AOE_PARTITIONS > MINORMASK) {
692fc458dcdSecashin@coraid.com 		printk(KERN_INFO
693fc458dcdSecashin@coraid.com 			"aoe: e%ld.%d: minor number too large\n",
694fc458dcdSecashin@coraid.com 			aoemajor, (int) h->minor);
6951da177e4SLinus Torvalds 		return;
6961da177e4SLinus Torvalds 	}
6971da177e4SLinus Torvalds 
698*19bf2635SEd L. Cashin 	n = be16_to_cpu(ch->bufcnt);
699*19bf2635SEd L. Cashin 	if (n > MAXFRAMES)	/* keep it reasonable */
700*19bf2635SEd L. Cashin 		n = MAXFRAMES;
7011da177e4SLinus Torvalds 
702*19bf2635SEd L. Cashin 	d = aoedev_by_sysminor_m(sysminor, n);
7031da177e4SLinus Torvalds 	if (d == NULL) {
7043ae1c24eSEd L. Cashin 		printk(KERN_INFO "aoe: aoecmd_cfg_rsp: device sysminor_m failure\n");
7051da177e4SLinus Torvalds 		return;
7061da177e4SLinus Torvalds 	}
7071da177e4SLinus Torvalds 
7081da177e4SLinus Torvalds 	spin_lock_irqsave(&d->lock, flags);
7091da177e4SLinus Torvalds 
7103ae1c24eSEd L. Cashin 	/* permit device to migrate mac and network interface */
7113ae1c24eSEd L. Cashin 	d->ifp = skb->dev;
7123ae1c24eSEd L. Cashin 	memcpy(d->addr, h->src, sizeof d->addr);
713*19bf2635SEd L. Cashin 	if (!(d->flags & DEVFL_MAXBCNT)) {
714*19bf2635SEd L. Cashin 		n = d->ifp->mtu;
715*19bf2635SEd L. Cashin 		n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr);
716*19bf2635SEd L. Cashin 		n /= 512;
717*19bf2635SEd L. Cashin 		if (n > ch->scnt)
718*19bf2635SEd L. Cashin 			n = ch->scnt;
719*19bf2635SEd L. Cashin 		d->maxbcnt = n ? n * 512 : DEFAULTBCNT;
720*19bf2635SEd L. Cashin 	}
7213ae1c24eSEd L. Cashin 
7223ae1c24eSEd L. Cashin 	/* don't change users' perspective */
7233ae1c24eSEd L. Cashin 	if (d->nopen && !(d->flags & DEVFL_PAUSE)) {
7241da177e4SLinus Torvalds 		spin_unlock_irqrestore(&d->lock, flags);
7251da177e4SLinus Torvalds 		return;
7261da177e4SLinus Torvalds 	}
7273ae1c24eSEd L. Cashin 	d->flags |= DEVFL_PAUSE;	/* force pause */
72863e9cc5dSecashin@coraid.com 	d->fw_ver = be16_to_cpu(ch->fwver);
7291da177e4SLinus Torvalds 
7303ae1c24eSEd L. Cashin 	/* check for already outstanding ataid */
7313ae1c24eSEd L. Cashin 	sl = aoedev_isbusy(d) == 0 ? aoecmd_ata_id(d) : NULL;
7321da177e4SLinus Torvalds 
7331da177e4SLinus Torvalds 	spin_unlock_irqrestore(&d->lock, flags);
7341da177e4SLinus Torvalds 
7351da177e4SLinus Torvalds 	aoenet_xmit(sl);
7361da177e4SLinus Torvalds }
7371da177e4SLinus Torvalds 
738