xref: /openbmc/linux/drivers/block/aoe/aoecmd.c (revision 68e0d42f39d85b334d3867a4e5fc2e0e775c1a6c)
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>
12*68e0d42fSEd L. Cashin #include <linux/moduleparam.h>
13881d966bSEric W. Biederman #include <net/net_namespace.h>
14475172fbSEd L. Cashin #include <asm/unaligned.h>
151da177e4SLinus Torvalds #include "aoe.h"
161da177e4SLinus Torvalds 
17b751e8b6SEd L. Cashin static int aoe_deadsecs = 60 * 3;
18b751e8b6SEd L. Cashin module_param(aoe_deadsecs, int, 0644);
19b751e8b6SEd L. Cashin MODULE_PARM_DESC(aoe_deadsecs, "After aoe_deadsecs seconds, give up and fail dev.");
201da177e4SLinus Torvalds 
21*68e0d42fSEd L. Cashin static struct sk_buff *
22e407a7f6SEd L. Cashin new_skb(ulong len)
231da177e4SLinus Torvalds {
241da177e4SLinus Torvalds 	struct sk_buff *skb;
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds 	skb = alloc_skb(len, GFP_ATOMIC);
271da177e4SLinus Torvalds 	if (skb) {
28459a98edSArnaldo Carvalho de Melo 		skb_reset_mac_header(skb);
29c1d2bbe1SArnaldo Carvalho de Melo 		skb_reset_network_header(skb);
301da177e4SLinus Torvalds 		skb->protocol = __constant_htons(ETH_P_AOE);
311da177e4SLinus Torvalds 		skb->priority = 0;
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 *
43*68e0d42fSEd L. Cashin getframe(struct aoetgt *t, int tag)
441da177e4SLinus Torvalds {
451da177e4SLinus Torvalds 	struct frame *f, *e;
461da177e4SLinus Torvalds 
47*68e0d42fSEd L. Cashin 	f = t->frames;
48*68e0d42fSEd L. Cashin 	e = f + t->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
61*68e0d42fSEd L. Cashin newtag(struct aoetgt *t)
621da177e4SLinus Torvalds {
631da177e4SLinus Torvalds 	register ulong n;
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds 	n = jiffies & 0xffff;
66*68e0d42fSEd L. Cashin 	return n |= (++t->lasttag & 0x7fff) << 16;
671da177e4SLinus Torvalds }
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds static int
70*68e0d42fSEd L. Cashin aoehdr_atainit(struct aoedev *d, struct aoetgt *t, struct aoe_hdr *h)
711da177e4SLinus Torvalds {
72*68e0d42fSEd L. Cashin 	u32 host_tag = newtag(t);
731da177e4SLinus Torvalds 
74*68e0d42fSEd L. Cashin 	memcpy(h->src, t->ifp->nd->dev_addr, sizeof h->src);
75*68e0d42fSEd L. Cashin 	memcpy(h->dst, t->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 
8619bf2635SEd L. Cashin static inline void
8719bf2635SEd L. Cashin put_lba(struct aoe_atahdr *ah, sector_t lba)
8819bf2635SEd L. Cashin {
8919bf2635SEd L. Cashin 	ah->lba0 = lba;
9019bf2635SEd L. Cashin 	ah->lba1 = lba >>= 8;
9119bf2635SEd L. Cashin 	ah->lba2 = lba >>= 8;
9219bf2635SEd L. Cashin 	ah->lba3 = lba >>= 8;
9319bf2635SEd L. Cashin 	ah->lba4 = lba >>= 8;
9419bf2635SEd L. Cashin 	ah->lba5 = lba >>= 8;
9519bf2635SEd L. Cashin }
9619bf2635SEd L. Cashin 
971da177e4SLinus Torvalds static void
98*68e0d42fSEd L. Cashin ifrotate(struct aoetgt *t)
991da177e4SLinus Torvalds {
100*68e0d42fSEd L. Cashin 	t->ifp++;
101*68e0d42fSEd L. Cashin 	if (t->ifp >= &t->ifs[NAOEIFS] || t->ifp->nd == NULL)
102*68e0d42fSEd L. Cashin 		t->ifp = t->ifs;
103*68e0d42fSEd L. Cashin 	if (t->ifp->nd == NULL) {
104*68e0d42fSEd L. Cashin 		printk(KERN_INFO "aoe: no interface to rotate to\n");
105*68e0d42fSEd L. Cashin 		BUG();
106*68e0d42fSEd L. Cashin 	}
107*68e0d42fSEd L. Cashin }
108*68e0d42fSEd L. Cashin 
109*68e0d42fSEd L. Cashin static struct frame *
110*68e0d42fSEd L. Cashin freeframe(struct aoedev *d)
111*68e0d42fSEd L. Cashin {
112*68e0d42fSEd L. Cashin 	struct frame *f, *e;
113*68e0d42fSEd L. Cashin 	struct aoetgt **t;
114*68e0d42fSEd L. Cashin 	ulong n;
115*68e0d42fSEd L. Cashin 
116*68e0d42fSEd L. Cashin 	if (d->targets[0] == NULL) {	/* shouldn't happen, but I'm paranoid */
117*68e0d42fSEd L. Cashin 		printk(KERN_ERR "aoe: NULL TARGETS!\n");
118*68e0d42fSEd L. Cashin 		return NULL;
119*68e0d42fSEd L. Cashin 	}
120*68e0d42fSEd L. Cashin 	t = d->targets;
121*68e0d42fSEd L. Cashin 	do {
122*68e0d42fSEd L. Cashin 		if (t != d->htgt
123*68e0d42fSEd L. Cashin 		&& (*t)->ifp->nd
124*68e0d42fSEd L. Cashin 		&& (*t)->nout < (*t)->maxout) {
125*68e0d42fSEd L. Cashin 			n = (*t)->nframes;
126*68e0d42fSEd L. Cashin 			f = (*t)->frames;
127*68e0d42fSEd L. Cashin 			e = f + n;
128*68e0d42fSEd L. Cashin 			for (; f < e; f++) {
129*68e0d42fSEd L. Cashin 				if (f->tag != FREETAG)
130*68e0d42fSEd L. Cashin 					continue;
131*68e0d42fSEd L. Cashin 				if (atomic_read(&skb_shinfo(f->skb)->dataref)
132*68e0d42fSEd L. Cashin 					!= 1) {
133*68e0d42fSEd L. Cashin 					n--;
134*68e0d42fSEd L. Cashin 					continue;
135*68e0d42fSEd L. Cashin 				}
136*68e0d42fSEd L. Cashin 				skb_shinfo(f->skb)->nr_frags = 0;
137*68e0d42fSEd L. Cashin 				f->skb->data_len = 0;
138*68e0d42fSEd L. Cashin 				skb_trim(f->skb, 0);
139*68e0d42fSEd L. Cashin 				d->tgt = t;
140*68e0d42fSEd L. Cashin 				ifrotate(*t);
141*68e0d42fSEd L. Cashin 				return f;
142*68e0d42fSEd L. Cashin 			}
143*68e0d42fSEd L. Cashin 			if (n == 0)	/* slow polling network card */
144*68e0d42fSEd L. Cashin 				d->flags |= DEVFL_KICKME;
145*68e0d42fSEd L. Cashin 		}
146*68e0d42fSEd L. Cashin 		t++;
147*68e0d42fSEd L. Cashin 	} while (t < &d->targets[NTARGETS] && *t);
148*68e0d42fSEd L. Cashin 	return NULL;
149*68e0d42fSEd L. Cashin }
150*68e0d42fSEd L. Cashin 
151*68e0d42fSEd L. Cashin static int
152*68e0d42fSEd L. Cashin aoecmd_ata_rw(struct aoedev *d)
153*68e0d42fSEd L. Cashin {
154*68e0d42fSEd L. Cashin 	struct frame *f;
1551da177e4SLinus Torvalds 	struct aoe_hdr *h;
1561da177e4SLinus Torvalds 	struct aoe_atahdr *ah;
1571da177e4SLinus Torvalds 	struct buf *buf;
158*68e0d42fSEd L. Cashin 	struct bio_vec *bv;
159*68e0d42fSEd L. Cashin 	struct aoetgt *t;
1601da177e4SLinus Torvalds 	struct sk_buff *skb;
1611da177e4SLinus Torvalds 	ulong bcnt;
1621da177e4SLinus Torvalds 	char writebit, extbit;
1631da177e4SLinus Torvalds 
1641da177e4SLinus Torvalds 	writebit = 0x10;
1651da177e4SLinus Torvalds 	extbit = 0x4;
1661da177e4SLinus Torvalds 
167*68e0d42fSEd L. Cashin 	f = freeframe(d);
168*68e0d42fSEd L. Cashin 	if (f == NULL)
169*68e0d42fSEd L. Cashin 		return 0;
170*68e0d42fSEd L. Cashin 	t = *d->tgt;
1711da177e4SLinus Torvalds 	buf = d->inprocess;
172*68e0d42fSEd L. Cashin 	bv = buf->bv;
173*68e0d42fSEd L. Cashin 	bcnt = t->ifp->maxbcnt;
174*68e0d42fSEd L. Cashin 	if (bcnt == 0)
175*68e0d42fSEd L. Cashin 		bcnt = DEFAULTBCNT;
176*68e0d42fSEd L. Cashin 	if (bcnt > buf->bv_resid)
1771da177e4SLinus Torvalds 		bcnt = buf->bv_resid;
1781da177e4SLinus Torvalds 	/* initialize the headers & frame */
179e407a7f6SEd L. Cashin 	skb = f->skb;
180abdbf94dSEd L. Cashin 	h = (struct aoe_hdr *) skb_mac_header(skb);
1811da177e4SLinus Torvalds 	ah = (struct aoe_atahdr *) (h+1);
18219900cdeSEd L. Cashin 	skb_put(skb, sizeof *h + sizeof *ah);
18319900cdeSEd L. Cashin 	memset(h, 0, skb->len);
184*68e0d42fSEd L. Cashin 	f->tag = aoehdr_atainit(d, t, h);
185*68e0d42fSEd L. Cashin 	t->nout++;
1861da177e4SLinus Torvalds 	f->waited = 0;
1871da177e4SLinus Torvalds 	f->buf = buf;
188*68e0d42fSEd L. Cashin 	f->bufaddr = page_address(bv->bv_page) + buf->bv_off;
18919bf2635SEd L. Cashin 	f->bcnt = bcnt;
190*68e0d42fSEd L. Cashin 	f->lba = buf->sector;
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds 	/* set up ata header */
1931da177e4SLinus Torvalds 	ah->scnt = bcnt >> 9;
194*68e0d42fSEd L. Cashin 	put_lba(ah, buf->sector);
1951da177e4SLinus Torvalds 	if (d->flags & DEVFL_EXT) {
1961da177e4SLinus Torvalds 		ah->aflags |= AOEAFL_EXT;
1971da177e4SLinus Torvalds 	} else {
1981da177e4SLinus Torvalds 		extbit = 0;
1991da177e4SLinus Torvalds 		ah->lba3 &= 0x0f;
2001da177e4SLinus Torvalds 		ah->lba3 |= 0xe0;	/* LBA bit + obsolete 0xa0 */
2011da177e4SLinus Torvalds 	}
2021da177e4SLinus Torvalds 	if (bio_data_dir(buf->bio) == WRITE) {
203*68e0d42fSEd L. Cashin 		skb_fill_page_desc(skb, 0, bv->bv_page, buf->bv_off, bcnt);
2041da177e4SLinus Torvalds 		ah->aflags |= AOEAFL_WRITE;
2054f51dc5eSEd L. Cashin 		skb->len += bcnt;
2064f51dc5eSEd L. Cashin 		skb->data_len = bcnt;
207*68e0d42fSEd L. Cashin 		t->wpkts++;
2081da177e4SLinus Torvalds 	} else {
209*68e0d42fSEd L. Cashin 		t->rpkts++;
2101da177e4SLinus Torvalds 		writebit = 0;
2111da177e4SLinus Torvalds 	}
2121da177e4SLinus Torvalds 
2131da177e4SLinus Torvalds 	ah->cmdstat = WIN_READ | writebit | extbit;
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds 	/* mark all tracking fields and load out */
2161da177e4SLinus Torvalds 	buf->nframesout += 1;
217*68e0d42fSEd L. Cashin 	buf->bv_off += bcnt;
2181da177e4SLinus Torvalds 	buf->bv_resid -= bcnt;
2191da177e4SLinus Torvalds 	buf->resid -= bcnt;
2201da177e4SLinus Torvalds 	buf->sector += bcnt >> 9;
2211da177e4SLinus Torvalds 	if (buf->resid == 0) {
2221da177e4SLinus Torvalds 		d->inprocess = NULL;
2231da177e4SLinus Torvalds 	} else if (buf->bv_resid == 0) {
224*68e0d42fSEd L. Cashin 		buf->bv = ++bv;
225*68e0d42fSEd L. Cashin 		buf->bv_resid = bv->bv_len;
226*68e0d42fSEd L. Cashin 		WARN_ON(buf->bv_resid == 0);
227*68e0d42fSEd L. Cashin 		buf->bv_off = bv->bv_offset;
2281da177e4SLinus Torvalds 	}
2291da177e4SLinus Torvalds 
230*68e0d42fSEd L. Cashin 	skb->dev = t->ifp->nd;
2314f51dc5eSEd L. Cashin 	skb = skb_clone(skb, GFP_ATOMIC);
232*68e0d42fSEd L. Cashin 	if (skb) {
233a4b38364Secashin@coraid.com 		if (d->sendq_hd)
234a4b38364Secashin@coraid.com 			d->sendq_tl->next = skb;
235a4b38364Secashin@coraid.com 		else
236a4b38364Secashin@coraid.com 			d->sendq_hd = skb;
237a4b38364Secashin@coraid.com 		d->sendq_tl = skb;
2381da177e4SLinus Torvalds 	}
239*68e0d42fSEd L. Cashin 	return 1;
240*68e0d42fSEd L. Cashin }
2411da177e4SLinus Torvalds 
2423ae1c24eSEd L. Cashin /* some callers cannot sleep, and they can call this function,
2433ae1c24eSEd L. Cashin  * transmitting the packets later, when interrupts are on
2443ae1c24eSEd L. Cashin  */
2453ae1c24eSEd L. Cashin static struct sk_buff *
2463ae1c24eSEd L. Cashin aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail)
2473ae1c24eSEd L. Cashin {
2483ae1c24eSEd L. Cashin 	struct aoe_hdr *h;
2493ae1c24eSEd L. Cashin 	struct aoe_cfghdr *ch;
2503ae1c24eSEd L. Cashin 	struct sk_buff *skb, *sl, *sl_tail;
2513ae1c24eSEd L. Cashin 	struct net_device *ifp;
2523ae1c24eSEd L. Cashin 
2533ae1c24eSEd L. Cashin 	sl = sl_tail = NULL;
2543ae1c24eSEd L. Cashin 
2553ae1c24eSEd L. Cashin 	read_lock(&dev_base_lock);
256881d966bSEric W. Biederman 	for_each_netdev(&init_net, ifp) {
2573ae1c24eSEd L. Cashin 		dev_hold(ifp);
2583ae1c24eSEd L. Cashin 		if (!is_aoe_netif(ifp))
2597562f876SPavel Emelianov 			goto cont;
2603ae1c24eSEd L. Cashin 
261e407a7f6SEd L. Cashin 		skb = new_skb(sizeof *h + sizeof *ch);
2623ae1c24eSEd L. Cashin 		if (skb == NULL) {
263a12c93f0SEd L. Cashin 			printk(KERN_INFO "aoe: skb alloc failure\n");
2647562f876SPavel Emelianov 			goto cont;
2653ae1c24eSEd L. Cashin 		}
26619900cdeSEd L. Cashin 		skb_put(skb, sizeof *h + sizeof *ch);
267e407a7f6SEd L. Cashin 		skb->dev = ifp;
2683ae1c24eSEd L. Cashin 		if (sl_tail == NULL)
2693ae1c24eSEd L. Cashin 			sl_tail = skb;
270abdbf94dSEd L. Cashin 		h = (struct aoe_hdr *) skb_mac_header(skb);
2713ae1c24eSEd L. Cashin 		memset(h, 0, sizeof *h + sizeof *ch);
2723ae1c24eSEd L. Cashin 
2733ae1c24eSEd L. Cashin 		memset(h->dst, 0xff, sizeof h->dst);
2743ae1c24eSEd L. Cashin 		memcpy(h->src, ifp->dev_addr, sizeof h->src);
2753ae1c24eSEd L. Cashin 		h->type = __constant_cpu_to_be16(ETH_P_AOE);
2763ae1c24eSEd L. Cashin 		h->verfl = AOE_HVER;
2773ae1c24eSEd L. Cashin 		h->major = cpu_to_be16(aoemajor);
2783ae1c24eSEd L. Cashin 		h->minor = aoeminor;
2793ae1c24eSEd L. Cashin 		h->cmd = AOECMD_CFG;
2803ae1c24eSEd L. Cashin 
2813ae1c24eSEd L. Cashin 		skb->next = sl;
2823ae1c24eSEd L. Cashin 		sl = skb;
2837562f876SPavel Emelianov cont:
2847562f876SPavel Emelianov 		dev_put(ifp);
2853ae1c24eSEd L. Cashin 	}
2863ae1c24eSEd L. Cashin 	read_unlock(&dev_base_lock);
2873ae1c24eSEd L. Cashin 
2883ae1c24eSEd L. Cashin 	if (tail != NULL)
2893ae1c24eSEd L. Cashin 		*tail = sl_tail;
2903ae1c24eSEd L. Cashin 	return sl;
2913ae1c24eSEd L. Cashin }
2923ae1c24eSEd L. Cashin 
2931da177e4SLinus Torvalds static void
294*68e0d42fSEd L. Cashin resend(struct aoedev *d, struct aoetgt *t, struct frame *f)
2951da177e4SLinus Torvalds {
2961da177e4SLinus Torvalds 	struct sk_buff *skb;
2971da177e4SLinus Torvalds 	struct aoe_hdr *h;
29819bf2635SEd L. Cashin 	struct aoe_atahdr *ah;
2991da177e4SLinus Torvalds 	char buf[128];
3001da177e4SLinus Torvalds 	u32 n;
3011da177e4SLinus Torvalds 
302*68e0d42fSEd L. Cashin 	ifrotate(t);
303*68e0d42fSEd L. Cashin 	n = newtag(t);
304e407a7f6SEd L. Cashin 	skb = f->skb;
305abdbf94dSEd L. Cashin 	h = (struct aoe_hdr *) skb_mac_header(skb);
30619bf2635SEd L. Cashin 	ah = (struct aoe_atahdr *) (h+1);
307*68e0d42fSEd L. Cashin 
308*68e0d42fSEd L. Cashin 	snprintf(buf, sizeof buf,
309*68e0d42fSEd L. Cashin 		"%15s e%ld.%d oldtag=%08x@%08lx newtag=%08x "
310*68e0d42fSEd L. Cashin 		"s=%012llx d=%012llx nout=%d\n",
311*68e0d42fSEd L. Cashin 		"retransmit", d->aoemajor, d->aoeminor, f->tag, jiffies, n,
312*68e0d42fSEd L. Cashin 		mac_addr(h->src), mac_addr(h->dst), t->nout);
313*68e0d42fSEd L. Cashin 	aoechr_error(buf);
314*68e0d42fSEd L. Cashin 
3151da177e4SLinus Torvalds 	f->tag = n;
31663e9cc5dSecashin@coraid.com 	h->tag = cpu_to_be32(n);
317*68e0d42fSEd L. Cashin 	memcpy(h->dst, t->addr, sizeof h->dst);
318*68e0d42fSEd L. Cashin 	memcpy(h->src, t->ifp->nd->dev_addr, sizeof h->src);
3191da177e4SLinus Torvalds 
320*68e0d42fSEd L. Cashin 	switch (ah->cmdstat) {
321*68e0d42fSEd L. Cashin 	default:
322*68e0d42fSEd L. Cashin 		break;
323*68e0d42fSEd L. Cashin 	case WIN_READ:
324*68e0d42fSEd L. Cashin 	case WIN_READ_EXT:
325*68e0d42fSEd L. Cashin 	case WIN_WRITE:
326*68e0d42fSEd L. Cashin 	case WIN_WRITE_EXT:
327*68e0d42fSEd L. Cashin 		put_lba(ah, f->lba);
328*68e0d42fSEd L. Cashin 
329*68e0d42fSEd L. Cashin 		n = f->bcnt;
330*68e0d42fSEd L. Cashin 		if (n > DEFAULTBCNT)
331*68e0d42fSEd L. Cashin 			n = DEFAULTBCNT;
332*68e0d42fSEd L. Cashin 		ah->scnt = n >> 9;
3334f51dc5eSEd L. Cashin 		if (ah->aflags & AOEAFL_WRITE) {
33419bf2635SEd L. Cashin 			skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr),
335*68e0d42fSEd L. Cashin 				offset_in_page(f->bufaddr), n);
336*68e0d42fSEd L. Cashin 			skb->len = sizeof *h + sizeof *ah + n;
337*68e0d42fSEd L. Cashin 			skb->data_len = n;
33819bf2635SEd L. Cashin 		}
33919bf2635SEd L. Cashin 	}
340*68e0d42fSEd L. Cashin 	skb->dev = t->ifp->nd;
3414f51dc5eSEd L. Cashin 	skb = skb_clone(skb, GFP_ATOMIC);
3424f51dc5eSEd L. Cashin 	if (skb == NULL)
3434f51dc5eSEd L. Cashin 		return;
344a4b38364Secashin@coraid.com 	if (d->sendq_hd)
345a4b38364Secashin@coraid.com 		d->sendq_tl->next = skb;
346a4b38364Secashin@coraid.com 	else
347a4b38364Secashin@coraid.com 		d->sendq_hd = skb;
348a4b38364Secashin@coraid.com 	d->sendq_tl = skb;
3491da177e4SLinus Torvalds }
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds static int
3521da177e4SLinus Torvalds tsince(int tag)
3531da177e4SLinus Torvalds {
3541da177e4SLinus Torvalds 	int n;
3551da177e4SLinus Torvalds 
3561da177e4SLinus Torvalds 	n = jiffies & 0xffff;
3571da177e4SLinus Torvalds 	n -= tag & 0xffff;
3581da177e4SLinus Torvalds 	if (n < 0)
3591da177e4SLinus Torvalds 		n += 1<<16;
3601da177e4SLinus Torvalds 	return n;
3611da177e4SLinus Torvalds }
3621da177e4SLinus Torvalds 
363*68e0d42fSEd L. Cashin static struct aoeif *
364*68e0d42fSEd L. Cashin getif(struct aoetgt *t, struct net_device *nd)
365*68e0d42fSEd L. Cashin {
366*68e0d42fSEd L. Cashin 	struct aoeif *p, *e;
367*68e0d42fSEd L. Cashin 
368*68e0d42fSEd L. Cashin 	p = t->ifs;
369*68e0d42fSEd L. Cashin 	e = p + NAOEIFS;
370*68e0d42fSEd L. Cashin 	for (; p < e; p++)
371*68e0d42fSEd L. Cashin 		if (p->nd == nd)
372*68e0d42fSEd L. Cashin 			return p;
373*68e0d42fSEd L. Cashin 	return NULL;
374*68e0d42fSEd L. Cashin }
375*68e0d42fSEd L. Cashin 
376*68e0d42fSEd L. Cashin static struct aoeif *
377*68e0d42fSEd L. Cashin addif(struct aoetgt *t, struct net_device *nd)
378*68e0d42fSEd L. Cashin {
379*68e0d42fSEd L. Cashin 	struct aoeif *p;
380*68e0d42fSEd L. Cashin 
381*68e0d42fSEd L. Cashin 	p = getif(t, NULL);
382*68e0d42fSEd L. Cashin 	if (!p)
383*68e0d42fSEd L. Cashin 		return NULL;
384*68e0d42fSEd L. Cashin 	p->nd = nd;
385*68e0d42fSEd L. Cashin 	p->maxbcnt = DEFAULTBCNT;
386*68e0d42fSEd L. Cashin 	p->lost = 0;
387*68e0d42fSEd L. Cashin 	p->lostjumbo = 0;
388*68e0d42fSEd L. Cashin 	return p;
389*68e0d42fSEd L. Cashin }
390*68e0d42fSEd L. Cashin 
391*68e0d42fSEd L. Cashin static void
392*68e0d42fSEd L. Cashin ejectif(struct aoetgt *t, struct aoeif *ifp)
393*68e0d42fSEd L. Cashin {
394*68e0d42fSEd L. Cashin 	struct aoeif *e;
395*68e0d42fSEd L. Cashin 	ulong n;
396*68e0d42fSEd L. Cashin 
397*68e0d42fSEd L. Cashin 	e = t->ifs + NAOEIFS - 1;
398*68e0d42fSEd L. Cashin 	n = (e - ifp) * sizeof *ifp;
399*68e0d42fSEd L. Cashin 	memmove(ifp, ifp+1, n);
400*68e0d42fSEd L. Cashin 	e->nd = NULL;
401*68e0d42fSEd L. Cashin }
402*68e0d42fSEd L. Cashin 
403*68e0d42fSEd L. Cashin static int
404*68e0d42fSEd L. Cashin sthtith(struct aoedev *d)
405*68e0d42fSEd L. Cashin {
406*68e0d42fSEd L. Cashin 	struct frame *f, *e, *nf;
407*68e0d42fSEd L. Cashin 	struct sk_buff *skb;
408*68e0d42fSEd L. Cashin 	struct aoetgt *ht = *d->htgt;
409*68e0d42fSEd L. Cashin 
410*68e0d42fSEd L. Cashin 	f = ht->frames;
411*68e0d42fSEd L. Cashin 	e = f + ht->nframes;
412*68e0d42fSEd L. Cashin 	for (; f < e; f++) {
413*68e0d42fSEd L. Cashin 		if (f->tag == FREETAG)
414*68e0d42fSEd L. Cashin 			continue;
415*68e0d42fSEd L. Cashin 		nf = freeframe(d);
416*68e0d42fSEd L. Cashin 		if (!nf)
417*68e0d42fSEd L. Cashin 			return 0;
418*68e0d42fSEd L. Cashin 		skb = nf->skb;
419*68e0d42fSEd L. Cashin 		*nf = *f;
420*68e0d42fSEd L. Cashin 		f->skb = skb;
421*68e0d42fSEd L. Cashin 		f->tag = FREETAG;
422*68e0d42fSEd L. Cashin 		nf->waited = 0;
423*68e0d42fSEd L. Cashin 		ht->nout--;
424*68e0d42fSEd L. Cashin 		(*d->tgt)->nout++;
425*68e0d42fSEd L. Cashin 		resend(d, *d->tgt, nf);
426*68e0d42fSEd L. Cashin 	}
427*68e0d42fSEd L. Cashin 	/* he's clean, he's useless.  take away his interfaces */
428*68e0d42fSEd L. Cashin 	memset(ht->ifs, 0, sizeof ht->ifs);
429*68e0d42fSEd L. Cashin 	d->htgt = NULL;
430*68e0d42fSEd L. Cashin 	return 1;
431*68e0d42fSEd L. Cashin }
432*68e0d42fSEd L. Cashin 
433*68e0d42fSEd L. Cashin static inline unsigned char
434*68e0d42fSEd L. Cashin ata_scnt(unsigned char *packet) {
435*68e0d42fSEd L. Cashin 	struct aoe_hdr *h;
436*68e0d42fSEd L. Cashin 	struct aoe_atahdr *ah;
437*68e0d42fSEd L. Cashin 
438*68e0d42fSEd L. Cashin 	h = (struct aoe_hdr *) packet;
439*68e0d42fSEd L. Cashin 	ah = (struct aoe_atahdr *) (h+1);
440*68e0d42fSEd L. Cashin 	return ah->scnt;
441*68e0d42fSEd L. Cashin }
442*68e0d42fSEd L. Cashin 
4431da177e4SLinus Torvalds static void
4441da177e4SLinus Torvalds rexmit_timer(ulong vp)
4451da177e4SLinus Torvalds {
4461da177e4SLinus Torvalds 	struct aoedev *d;
447*68e0d42fSEd L. Cashin 	struct aoetgt *t, **tt, **te;
448*68e0d42fSEd L. Cashin 	struct aoeif *ifp;
4491da177e4SLinus Torvalds 	struct frame *f, *e;
4501da177e4SLinus Torvalds 	struct sk_buff *sl;
4511da177e4SLinus Torvalds 	register long timeout;
4521da177e4SLinus Torvalds 	ulong flags, n;
4531da177e4SLinus Torvalds 
4541da177e4SLinus Torvalds 	d = (struct aoedev *) vp;
4551da177e4SLinus Torvalds 	sl = NULL;
4561da177e4SLinus Torvalds 
4571da177e4SLinus Torvalds 	/* timeout is always ~150% of the moving average */
4581da177e4SLinus Torvalds 	timeout = d->rttavg;
4591da177e4SLinus Torvalds 	timeout += timeout >> 1;
4601da177e4SLinus Torvalds 
4611da177e4SLinus Torvalds 	spin_lock_irqsave(&d->lock, flags);
4621da177e4SLinus Torvalds 
4631da177e4SLinus Torvalds 	if (d->flags & DEVFL_TKILL) {
4641c6f3fcaSEd L. Cashin 		spin_unlock_irqrestore(&d->lock, flags);
4651da177e4SLinus Torvalds 		return;
4661da177e4SLinus Torvalds 	}
467*68e0d42fSEd L. Cashin 	tt = d->targets;
468*68e0d42fSEd L. Cashin 	te = tt + NTARGETS;
469*68e0d42fSEd L. Cashin 	for (; tt < te && *tt; tt++) {
470*68e0d42fSEd L. Cashin 		t = *tt;
471*68e0d42fSEd L. Cashin 		f = t->frames;
472*68e0d42fSEd L. Cashin 		e = f + t->nframes;
4731da177e4SLinus Torvalds 		for (; f < e; f++) {
474*68e0d42fSEd L. Cashin 			if (f->tag == FREETAG
475*68e0d42fSEd L. Cashin 			|| tsince(f->tag) < timeout)
476*68e0d42fSEd L. Cashin 				continue;
4771da177e4SLinus Torvalds 			n = f->waited += timeout;
4781da177e4SLinus Torvalds 			n /= HZ;
479*68e0d42fSEd L. Cashin 			if (n > aoe_deadsecs) {
480*68e0d42fSEd L. Cashin 				/* waited too long.  device failure. */
4811da177e4SLinus Torvalds 				aoedev_downdev(d);
4821c6f3fcaSEd L. Cashin 				break;
4831da177e4SLinus Torvalds 			}
484*68e0d42fSEd L. Cashin 
485*68e0d42fSEd L. Cashin 			if (n > HELPWAIT /* see if another target can help */
486*68e0d42fSEd L. Cashin 			&& (tt != d->targets || d->targets[1]))
487*68e0d42fSEd L. Cashin 				d->htgt = tt;
488*68e0d42fSEd L. Cashin 
489*68e0d42fSEd L. Cashin 			if (t->nout == t->maxout) {
490*68e0d42fSEd L. Cashin 				if (t->maxout > 1)
491*68e0d42fSEd L. Cashin 					t->maxout--;
492*68e0d42fSEd L. Cashin 				t->lastwadj = jiffies;
493*68e0d42fSEd L. Cashin 			}
494*68e0d42fSEd L. Cashin 
495*68e0d42fSEd L. Cashin 			ifp = getif(t, f->skb->dev);
496*68e0d42fSEd L. Cashin 			if (ifp && ++ifp->lost > (t->nframes << 1)
497*68e0d42fSEd L. Cashin 			&& (ifp != t->ifs || t->ifs[1].nd)) {
498*68e0d42fSEd L. Cashin 				ejectif(t, ifp);
499*68e0d42fSEd L. Cashin 				ifp = NULL;
500*68e0d42fSEd L. Cashin 			}
501*68e0d42fSEd L. Cashin 
502*68e0d42fSEd L. Cashin 			if (ata_scnt(skb_mac_header(f->skb)) > DEFAULTBCNT / 512
503*68e0d42fSEd L. Cashin 			&& ifp && ++ifp->lostjumbo > (t->nframes << 1)
504*68e0d42fSEd L. Cashin 			&& ifp->maxbcnt != DEFAULTBCNT) {
505*68e0d42fSEd L. Cashin 				printk(KERN_INFO
506*68e0d42fSEd L. Cashin 					"aoe: e%ld.%d: "
507*68e0d42fSEd L. Cashin 					"too many lost jumbo on "
508*68e0d42fSEd L. Cashin 					"%s:%012llx - "
509*68e0d42fSEd L. Cashin 					"falling back to %d frames.\n",
510*68e0d42fSEd L. Cashin 					d->aoemajor, d->aoeminor,
511*68e0d42fSEd L. Cashin 					ifp->nd->name, mac_addr(t->addr),
512*68e0d42fSEd L. Cashin 					DEFAULTBCNT);
513*68e0d42fSEd L. Cashin 				ifp->maxbcnt = 0;
514*68e0d42fSEd L. Cashin 			}
515*68e0d42fSEd L. Cashin 			resend(d, t, f);
516*68e0d42fSEd L. Cashin 		}
517*68e0d42fSEd L. Cashin 
518*68e0d42fSEd L. Cashin 		/* window check */
519*68e0d42fSEd L. Cashin 		if (t->nout == t->maxout
520*68e0d42fSEd L. Cashin 		&& t->maxout < t->nframes
521*68e0d42fSEd L. Cashin 		&& (jiffies - t->lastwadj)/HZ > 10) {
522*68e0d42fSEd L. Cashin 			t->maxout++;
523*68e0d42fSEd L. Cashin 			t->lastwadj = jiffies;
5241da177e4SLinus Torvalds 		}
5251da177e4SLinus Torvalds 	}
526*68e0d42fSEd L. Cashin 
527*68e0d42fSEd L. Cashin 	if (d->sendq_hd) {
528*68e0d42fSEd L. Cashin 		n = d->rttavg <<= 1;
529*68e0d42fSEd L. Cashin 		if (n > MAXTIMER)
530*68e0d42fSEd L. Cashin 			d->rttavg = MAXTIMER;
531*68e0d42fSEd L. Cashin 	}
532*68e0d42fSEd L. Cashin 
533*68e0d42fSEd L. Cashin 	if (d->flags & DEVFL_KICKME || d->htgt) {
5344f51dc5eSEd L. Cashin 		d->flags &= ~DEVFL_KICKME;
5354f51dc5eSEd L. Cashin 		aoecmd_work(d);
5364f51dc5eSEd L. Cashin 	}
5371da177e4SLinus Torvalds 
538a4b38364Secashin@coraid.com 	sl = d->sendq_hd;
539a4b38364Secashin@coraid.com 	d->sendq_hd = d->sendq_tl = NULL;
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds 	d->timer.expires = jiffies + TIMERTICK;
5421da177e4SLinus Torvalds 	add_timer(&d->timer);
5431da177e4SLinus Torvalds 
5441da177e4SLinus Torvalds 	spin_unlock_irqrestore(&d->lock, flags);
5451da177e4SLinus Torvalds 
5461da177e4SLinus Torvalds 	aoenet_xmit(sl);
5471da177e4SLinus Torvalds }
5481da177e4SLinus Torvalds 
549*68e0d42fSEd L. Cashin /* enters with d->lock held */
550*68e0d42fSEd L. Cashin void
551*68e0d42fSEd L. Cashin aoecmd_work(struct aoedev *d)
552*68e0d42fSEd L. Cashin {
553*68e0d42fSEd L. Cashin 	struct buf *buf;
554*68e0d42fSEd L. Cashin loop:
555*68e0d42fSEd L. Cashin 	if (d->htgt && !sthtith(d))
556*68e0d42fSEd L. Cashin 		return;
557*68e0d42fSEd L. Cashin 	if (d->inprocess == NULL) {
558*68e0d42fSEd L. Cashin 		if (list_empty(&d->bufq))
559*68e0d42fSEd L. Cashin 			return;
560*68e0d42fSEd L. Cashin 		buf = container_of(d->bufq.next, struct buf, bufs);
561*68e0d42fSEd L. Cashin 		list_del(d->bufq.next);
562*68e0d42fSEd L. Cashin 		d->inprocess = buf;
563*68e0d42fSEd L. Cashin 	}
564*68e0d42fSEd L. Cashin 	if (aoecmd_ata_rw(d))
565*68e0d42fSEd L. Cashin 		goto loop;
566*68e0d42fSEd L. Cashin }
567*68e0d42fSEd L. Cashin 
5683ae1c24eSEd L. Cashin /* this function performs work that has been deferred until sleeping is OK
5693ae1c24eSEd L. Cashin  */
5703ae1c24eSEd L. Cashin void
571c4028958SDavid Howells aoecmd_sleepwork(struct work_struct *work)
5723ae1c24eSEd L. Cashin {
573c4028958SDavid Howells 	struct aoedev *d = container_of(work, struct aoedev, work);
5743ae1c24eSEd L. Cashin 
5753ae1c24eSEd L. Cashin 	if (d->flags & DEVFL_GDALLOC)
5763ae1c24eSEd L. Cashin 		aoeblk_gdalloc(d);
5773ae1c24eSEd L. Cashin 
5783ae1c24eSEd L. Cashin 	if (d->flags & DEVFL_NEWSIZE) {
5793ae1c24eSEd L. Cashin 		struct block_device *bd;
5803ae1c24eSEd L. Cashin 		unsigned long flags;
5813ae1c24eSEd L. Cashin 		u64 ssize;
5823ae1c24eSEd L. Cashin 
5833ae1c24eSEd L. Cashin 		ssize = d->gd->capacity;
5843ae1c24eSEd L. Cashin 		bd = bdget_disk(d->gd, 0);
5853ae1c24eSEd L. Cashin 
5863ae1c24eSEd L. Cashin 		if (bd) {
5873ae1c24eSEd L. Cashin 			mutex_lock(&bd->bd_inode->i_mutex);
5883ae1c24eSEd L. Cashin 			i_size_write(bd->bd_inode, (loff_t)ssize<<9);
5893ae1c24eSEd L. Cashin 			mutex_unlock(&bd->bd_inode->i_mutex);
5903ae1c24eSEd L. Cashin 			bdput(bd);
5913ae1c24eSEd L. Cashin 		}
5923ae1c24eSEd L. Cashin 		spin_lock_irqsave(&d->lock, flags);
5933ae1c24eSEd L. Cashin 		d->flags |= DEVFL_UP;
5943ae1c24eSEd L. Cashin 		d->flags &= ~DEVFL_NEWSIZE;
5953ae1c24eSEd L. Cashin 		spin_unlock_irqrestore(&d->lock, flags);
5963ae1c24eSEd L. Cashin 	}
5973ae1c24eSEd L. Cashin }
5983ae1c24eSEd L. Cashin 
5991da177e4SLinus Torvalds static void
600*68e0d42fSEd L. Cashin ataid_complete(struct aoedev *d, struct aoetgt *t, unsigned char *id)
6011da177e4SLinus Torvalds {
6021da177e4SLinus Torvalds 	u64 ssize;
6031da177e4SLinus Torvalds 	u16 n;
6041da177e4SLinus Torvalds 
6051da177e4SLinus Torvalds 	/* word 83: command set supported */
606475172fbSEd L. Cashin 	n = le16_to_cpu(get_unaligned((__le16 *) &id[83<<1]));
6071da177e4SLinus Torvalds 
6081da177e4SLinus Torvalds 	/* word 86: command set/feature enabled */
609475172fbSEd L. Cashin 	n |= le16_to_cpu(get_unaligned((__le16 *) &id[86<<1]));
6101da177e4SLinus Torvalds 
6111da177e4SLinus Torvalds 	if (n & (1<<10)) {	/* bit 10: LBA 48 */
6121da177e4SLinus Torvalds 		d->flags |= DEVFL_EXT;
6131da177e4SLinus Torvalds 
6141da177e4SLinus Torvalds 		/* word 100: number lba48 sectors */
615475172fbSEd L. Cashin 		ssize = le64_to_cpu(get_unaligned((__le64 *) &id[100<<1]));
6161da177e4SLinus Torvalds 
6171da177e4SLinus Torvalds 		/* set as in ide-disk.c:init_idedisk_capacity */
6181da177e4SLinus Torvalds 		d->geo.cylinders = ssize;
6191da177e4SLinus Torvalds 		d->geo.cylinders /= (255 * 63);
6201da177e4SLinus Torvalds 		d->geo.heads = 255;
6211da177e4SLinus Torvalds 		d->geo.sectors = 63;
6221da177e4SLinus Torvalds 	} else {
6231da177e4SLinus Torvalds 		d->flags &= ~DEVFL_EXT;
6241da177e4SLinus Torvalds 
6251da177e4SLinus Torvalds 		/* number lba28 sectors */
626475172fbSEd L. Cashin 		ssize = le32_to_cpu(get_unaligned((__le32 *) &id[60<<1]));
6271da177e4SLinus Torvalds 
6281da177e4SLinus Torvalds 		/* NOTE: obsolete in ATA 6 */
629475172fbSEd L. Cashin 		d->geo.cylinders = le16_to_cpu(get_unaligned((__le16 *) &id[54<<1]));
630475172fbSEd L. Cashin 		d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1]));
631475172fbSEd L. Cashin 		d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1]));
6321da177e4SLinus Torvalds 	}
6333ae1c24eSEd L. Cashin 
6343ae1c24eSEd L. Cashin 	if (d->ssize != ssize)
635a12c93f0SEd L. Cashin 		printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu sectors\n",
636*68e0d42fSEd L. Cashin 			(unsigned long long)mac_addr(t->addr),
6373ae1c24eSEd L. Cashin 			d->aoemajor, d->aoeminor,
6383ae1c24eSEd L. Cashin 			d->fw_ver, (long long)ssize);
6391da177e4SLinus Torvalds 	d->ssize = ssize;
6401da177e4SLinus Torvalds 	d->geo.start = 0;
6411da177e4SLinus Torvalds 	if (d->gd != NULL) {
6421da177e4SLinus Torvalds 		d->gd->capacity = ssize;
6433ae1c24eSEd L. Cashin 		d->flags |= DEVFL_NEWSIZE;
644*68e0d42fSEd L. Cashin 	} else
6453ae1c24eSEd L. Cashin 		d->flags |= DEVFL_GDALLOC;
6461da177e4SLinus Torvalds 	schedule_work(&d->work);
6471da177e4SLinus Torvalds }
6481da177e4SLinus Torvalds 
6491da177e4SLinus Torvalds static void
6501da177e4SLinus Torvalds calc_rttavg(struct aoedev *d, int rtt)
6511da177e4SLinus Torvalds {
6521da177e4SLinus Torvalds 	register long n;
6531da177e4SLinus Torvalds 
6541da177e4SLinus Torvalds 	n = rtt;
655dced3a05SEd L. Cashin 	if (n < 0) {
656dced3a05SEd L. Cashin 		n = -rtt;
6571da177e4SLinus Torvalds 		if (n < MINTIMER)
6581da177e4SLinus Torvalds 			n = MINTIMER;
6591da177e4SLinus Torvalds 		else if (n > MAXTIMER)
6601da177e4SLinus Torvalds 			n = MAXTIMER;
661dced3a05SEd L. Cashin 		d->mintimer += (n - d->mintimer) >> 1;
662dced3a05SEd L. Cashin 	} else if (n < d->mintimer)
663dced3a05SEd L. Cashin 		n = d->mintimer;
664dced3a05SEd L. Cashin 	else if (n > MAXTIMER)
665dced3a05SEd L. Cashin 		n = MAXTIMER;
6661da177e4SLinus Torvalds 
6671da177e4SLinus Torvalds 	/* g == .25; cf. Congestion Avoidance and Control, Jacobson & Karels; 1988 */
6681da177e4SLinus Torvalds 	n -= d->rttavg;
6691da177e4SLinus Torvalds 	d->rttavg += n >> 2;
6701da177e4SLinus Torvalds }
6711da177e4SLinus Torvalds 
672*68e0d42fSEd L. Cashin static struct aoetgt *
673*68e0d42fSEd L. Cashin gettgt(struct aoedev *d, char *addr)
674*68e0d42fSEd L. Cashin {
675*68e0d42fSEd L. Cashin 	struct aoetgt **t, **e;
676*68e0d42fSEd L. Cashin 
677*68e0d42fSEd L. Cashin 	t = d->targets;
678*68e0d42fSEd L. Cashin 	e = t + NTARGETS;
679*68e0d42fSEd L. Cashin 	for (; t < e && *t; t++)
680*68e0d42fSEd L. Cashin 		if (memcmp((*t)->addr, addr, sizeof((*t)->addr)) == 0)
681*68e0d42fSEd L. Cashin 			return *t;
682*68e0d42fSEd L. Cashin 	return NULL;
683*68e0d42fSEd L. Cashin }
684*68e0d42fSEd L. Cashin 
685*68e0d42fSEd L. Cashin static inline void
686*68e0d42fSEd L. Cashin diskstats(struct gendisk *disk, struct bio *bio, ulong duration)
687*68e0d42fSEd L. Cashin {
688*68e0d42fSEd L. Cashin 	unsigned long n_sect = bio->bi_size >> 9;
689*68e0d42fSEd L. Cashin 	const int rw = bio_data_dir(bio);
690*68e0d42fSEd L. Cashin 
691*68e0d42fSEd L. Cashin 	disk_stat_inc(disk, ios[rw]);
692*68e0d42fSEd L. Cashin 	disk_stat_add(disk, ticks[rw], duration);
693*68e0d42fSEd L. Cashin 	disk_stat_add(disk, sectors[rw], n_sect);
694*68e0d42fSEd L. Cashin 	disk_stat_add(disk, io_ticks, duration);
695*68e0d42fSEd L. Cashin }
696*68e0d42fSEd L. Cashin 
6971da177e4SLinus Torvalds void
6981da177e4SLinus Torvalds aoecmd_ata_rsp(struct sk_buff *skb)
6991da177e4SLinus Torvalds {
7001da177e4SLinus Torvalds 	struct aoedev *d;
701ddec63e8SEd L. Cashin 	struct aoe_hdr *hin, *hout;
7021da177e4SLinus Torvalds 	struct aoe_atahdr *ahin, *ahout;
7031da177e4SLinus Torvalds 	struct frame *f;
7041da177e4SLinus Torvalds 	struct buf *buf;
7051da177e4SLinus Torvalds 	struct sk_buff *sl;
706*68e0d42fSEd L. Cashin 	struct aoetgt *t;
707*68e0d42fSEd L. Cashin 	struct aoeif *ifp;
7081da177e4SLinus Torvalds 	register long n;
7091da177e4SLinus Torvalds 	ulong flags;
7101da177e4SLinus Torvalds 	char ebuf[128];
71132465c65Secashin@coraid.com 	u16 aoemajor;
7121da177e4SLinus Torvalds 
713abdbf94dSEd L. Cashin 	hin = (struct aoe_hdr *) skb_mac_header(skb);
71443ecf529SDavid S. Miller 	aoemajor = be16_to_cpu(get_unaligned(&hin->major));
71532465c65Secashin@coraid.com 	d = aoedev_by_aoeaddr(aoemajor, hin->minor);
7161da177e4SLinus Torvalds 	if (d == NULL) {
7171da177e4SLinus Torvalds 		snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response "
7181da177e4SLinus Torvalds 			"for unknown device %d.%d\n",
71932465c65Secashin@coraid.com 			 aoemajor, hin->minor);
7201da177e4SLinus Torvalds 		aoechr_error(ebuf);
7211da177e4SLinus Torvalds 		return;
7221da177e4SLinus Torvalds 	}
7231da177e4SLinus Torvalds 
7241da177e4SLinus Torvalds 	spin_lock_irqsave(&d->lock, flags);
7251da177e4SLinus Torvalds 
72643ecf529SDavid S. Miller 	n = be32_to_cpu(get_unaligned(&hin->tag));
727*68e0d42fSEd L. Cashin 	t = gettgt(d, hin->src);
728*68e0d42fSEd L. Cashin 	if (t == NULL) {
729*68e0d42fSEd L. Cashin 		printk(KERN_INFO "aoe: can't find target e%ld.%d:%012llx\n",
730*68e0d42fSEd L. Cashin 			d->aoemajor, d->aoeminor,
731*68e0d42fSEd L. Cashin 			(unsigned long long) mac_addr(hin->src));
732*68e0d42fSEd L. Cashin 		spin_unlock_irqrestore(&d->lock, flags);
733*68e0d42fSEd L. Cashin 		return;
734*68e0d42fSEd L. Cashin 	}
735*68e0d42fSEd L. Cashin 	f = getframe(t, n);
7361da177e4SLinus Torvalds 	if (f == NULL) {
737dced3a05SEd L. Cashin 		calc_rttavg(d, -tsince(n));
7381da177e4SLinus Torvalds 		spin_unlock_irqrestore(&d->lock, flags);
7391da177e4SLinus Torvalds 		snprintf(ebuf, sizeof ebuf,
7401da177e4SLinus Torvalds 			"%15s e%d.%d    tag=%08x@%08lx\n",
7411da177e4SLinus Torvalds 			"unexpected rsp",
74243ecf529SDavid S. Miller 			be16_to_cpu(get_unaligned(&hin->major)),
7431da177e4SLinus Torvalds 			hin->minor,
74443ecf529SDavid S. Miller 			be32_to_cpu(get_unaligned(&hin->tag)),
7451da177e4SLinus Torvalds 			jiffies);
7461da177e4SLinus Torvalds 		aoechr_error(ebuf);
7471da177e4SLinus Torvalds 		return;
7481da177e4SLinus Torvalds 	}
7491da177e4SLinus Torvalds 
7501da177e4SLinus Torvalds 	calc_rttavg(d, tsince(f->tag));
7511da177e4SLinus Torvalds 
7521da177e4SLinus Torvalds 	ahin = (struct aoe_atahdr *) (hin+1);
753abdbf94dSEd L. Cashin 	hout = (struct aoe_hdr *) skb_mac_header(f->skb);
754ddec63e8SEd L. Cashin 	ahout = (struct aoe_atahdr *) (hout+1);
7551da177e4SLinus Torvalds 	buf = f->buf;
7561da177e4SLinus Torvalds 
7571da177e4SLinus Torvalds 	if (ahin->cmdstat & 0xa9) {	/* these bits cleared on success */
758a12c93f0SEd L. Cashin 		printk(KERN_ERR
759a12c93f0SEd L. Cashin 			"aoe: ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%ld\n",
7601da177e4SLinus Torvalds 			ahout->cmdstat, ahin->cmdstat,
7611da177e4SLinus Torvalds 			d->aoemajor, d->aoeminor);
7621da177e4SLinus Torvalds 		if (buf)
7631da177e4SLinus Torvalds 			buf->flags |= BUFFL_FAIL;
7641da177e4SLinus Torvalds 	} else {
765*68e0d42fSEd L. Cashin 		if (d->htgt && t == *d->htgt) /* I'll help myself, thank you. */
766*68e0d42fSEd L. Cashin 			d->htgt = NULL;
76719bf2635SEd L. Cashin 		n = ahout->scnt << 9;
7681da177e4SLinus Torvalds 		switch (ahout->cmdstat) {
7691da177e4SLinus Torvalds 		case WIN_READ:
7701da177e4SLinus Torvalds 		case WIN_READ_EXT:
7711da177e4SLinus Torvalds 			if (skb->len - sizeof *hin - sizeof *ahin < n) {
772a12c93f0SEd L. Cashin 				printk(KERN_ERR
773*68e0d42fSEd L. Cashin 					"aoe: %s.  skb->len=%d need=%ld\n",
774*68e0d42fSEd L. Cashin 					"runt data size in read", skb->len, n);
7751da177e4SLinus Torvalds 				/* fail frame f?  just returning will rexmit. */
7761da177e4SLinus Torvalds 				spin_unlock_irqrestore(&d->lock, flags);
7771da177e4SLinus Torvalds 				return;
7781da177e4SLinus Torvalds 			}
7791da177e4SLinus Torvalds 			memcpy(f->bufaddr, ahin+1, n);
7801da177e4SLinus Torvalds 		case WIN_WRITE:
7811da177e4SLinus Torvalds 		case WIN_WRITE_EXT:
782*68e0d42fSEd L. Cashin 			ifp = getif(t, skb->dev);
783*68e0d42fSEd L. Cashin 			if (ifp) {
784*68e0d42fSEd L. Cashin 				ifp->lost = 0;
785*68e0d42fSEd L. Cashin 				if (n > DEFAULTBCNT)
786*68e0d42fSEd L. Cashin 					ifp->lostjumbo = 0;
787*68e0d42fSEd L. Cashin 			}
78819bf2635SEd L. Cashin 			if (f->bcnt -= n) {
789*68e0d42fSEd L. Cashin 				f->lba += n >> 9;
79019bf2635SEd L. Cashin 				f->bufaddr += n;
791*68e0d42fSEd L. Cashin 				resend(d, t, f);
792*68e0d42fSEd L. Cashin 				goto xmit;
7934f51dc5eSEd L. Cashin 			}
7941da177e4SLinus Torvalds 			break;
7951da177e4SLinus Torvalds 		case WIN_IDENTIFY:
7961da177e4SLinus Torvalds 			if (skb->len - sizeof *hin - sizeof *ahin < 512) {
797a12c93f0SEd L. Cashin 				printk(KERN_INFO
798a12c93f0SEd L. Cashin 					"aoe: runt data size in ataid.  skb->len=%d\n",
7996bb6285fSEd L. Cashin 					skb->len);
8001da177e4SLinus Torvalds 				spin_unlock_irqrestore(&d->lock, flags);
8011da177e4SLinus Torvalds 				return;
8021da177e4SLinus Torvalds 			}
803*68e0d42fSEd L. Cashin 			ataid_complete(d, t, (char *) (ahin+1));
8041da177e4SLinus Torvalds 			break;
8051da177e4SLinus Torvalds 		default:
806a12c93f0SEd L. Cashin 			printk(KERN_INFO
807a12c93f0SEd L. Cashin 				"aoe: unrecognized ata command %2.2Xh for %d.%d\n",
8081da177e4SLinus Torvalds 				ahout->cmdstat,
80943ecf529SDavid S. Miller 				be16_to_cpu(get_unaligned(&hin->major)),
8101da177e4SLinus Torvalds 				hin->minor);
8111da177e4SLinus Torvalds 		}
8121da177e4SLinus Torvalds 	}
8131da177e4SLinus Torvalds 
814*68e0d42fSEd L. Cashin 	if (buf && --buf->nframesout == 0 && buf->resid == 0) {
815*68e0d42fSEd L. Cashin 		diskstats(d->gd, buf->bio, jiffies - buf->stime);
8161da177e4SLinus Torvalds 		n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
8176712ecf8SNeilBrown 		bio_endio(buf->bio, n);
8181da177e4SLinus Torvalds 		mempool_free(buf, d->bufpool);
8191da177e4SLinus Torvalds 	}
8201da177e4SLinus Torvalds 
8211da177e4SLinus Torvalds 	f->buf = NULL;
8221da177e4SLinus Torvalds 	f->tag = FREETAG;
823*68e0d42fSEd L. Cashin 	t->nout--;
8241da177e4SLinus Torvalds 
8251da177e4SLinus Torvalds 	aoecmd_work(d);
826*68e0d42fSEd L. Cashin xmit:
827a4b38364Secashin@coraid.com 	sl = d->sendq_hd;
828a4b38364Secashin@coraid.com 	d->sendq_hd = d->sendq_tl = NULL;
8291da177e4SLinus Torvalds 
8301da177e4SLinus Torvalds 	spin_unlock_irqrestore(&d->lock, flags);
8311da177e4SLinus Torvalds 	aoenet_xmit(sl);
8321da177e4SLinus Torvalds }
8331da177e4SLinus Torvalds 
8341da177e4SLinus Torvalds void
8351da177e4SLinus Torvalds aoecmd_cfg(ushort aoemajor, unsigned char aoeminor)
8361da177e4SLinus Torvalds {
8373ae1c24eSEd L. Cashin 	struct sk_buff *sl;
8381da177e4SLinus Torvalds 
8393ae1c24eSEd L. Cashin 	sl = aoecmd_cfg_pkts(aoemajor, aoeminor, NULL);
8401da177e4SLinus Torvalds 
8411da177e4SLinus Torvalds 	aoenet_xmit(sl);
8421da177e4SLinus Torvalds }
8431da177e4SLinus Torvalds 
844*68e0d42fSEd L. Cashin struct sk_buff *
8451da177e4SLinus Torvalds aoecmd_ata_id(struct aoedev *d)
8461da177e4SLinus Torvalds {
8471da177e4SLinus Torvalds 	struct aoe_hdr *h;
8481da177e4SLinus Torvalds 	struct aoe_atahdr *ah;
8491da177e4SLinus Torvalds 	struct frame *f;
8501da177e4SLinus Torvalds 	struct sk_buff *skb;
851*68e0d42fSEd L. Cashin 	struct aoetgt *t;
8521da177e4SLinus Torvalds 
8534f51dc5eSEd L. Cashin 	f = freeframe(d);
854*68e0d42fSEd L. Cashin 	if (f == NULL)
8551da177e4SLinus Torvalds 		return NULL;
856*68e0d42fSEd L. Cashin 
857*68e0d42fSEd L. Cashin 	t = *d->tgt;
8581da177e4SLinus Torvalds 
8591da177e4SLinus Torvalds 	/* initialize the headers & frame */
860e407a7f6SEd L. Cashin 	skb = f->skb;
861abdbf94dSEd L. Cashin 	h = (struct aoe_hdr *) skb_mac_header(skb);
8621da177e4SLinus Torvalds 	ah = (struct aoe_atahdr *) (h+1);
86319900cdeSEd L. Cashin 	skb_put(skb, sizeof *h + sizeof *ah);
86419900cdeSEd L. Cashin 	memset(h, 0, skb->len);
865*68e0d42fSEd L. Cashin 	f->tag = aoehdr_atainit(d, t, h);
866*68e0d42fSEd L. Cashin 	t->nout++;
8671da177e4SLinus Torvalds 	f->waited = 0;
8681da177e4SLinus Torvalds 
8691da177e4SLinus Torvalds 	/* set up ata header */
8701da177e4SLinus Torvalds 	ah->scnt = 1;
8711da177e4SLinus Torvalds 	ah->cmdstat = WIN_IDENTIFY;
8721da177e4SLinus Torvalds 	ah->lba3 = 0xa0;
8731da177e4SLinus Torvalds 
874*68e0d42fSEd L. Cashin 	skb->dev = t->ifp->nd;
8751da177e4SLinus Torvalds 
8763ae1c24eSEd L. Cashin 	d->rttavg = MAXTIMER;
8771da177e4SLinus Torvalds 	d->timer.function = rexmit_timer;
8781da177e4SLinus Torvalds 
8794f51dc5eSEd L. Cashin 	return skb_clone(skb, GFP_ATOMIC);
8801da177e4SLinus Torvalds }
8811da177e4SLinus Torvalds 
882*68e0d42fSEd L. Cashin static struct aoetgt *
883*68e0d42fSEd L. Cashin addtgt(struct aoedev *d, char *addr, ulong nframes)
884*68e0d42fSEd L. Cashin {
885*68e0d42fSEd L. Cashin 	struct aoetgt *t, **tt, **te;
886*68e0d42fSEd L. Cashin 	struct frame *f, *e;
887*68e0d42fSEd L. Cashin 
888*68e0d42fSEd L. Cashin 	tt = d->targets;
889*68e0d42fSEd L. Cashin 	te = tt + NTARGETS;
890*68e0d42fSEd L. Cashin 	for (; tt < te && *tt; tt++)
891*68e0d42fSEd L. Cashin 		;
892*68e0d42fSEd L. Cashin 
893*68e0d42fSEd L. Cashin 	if (tt == te)
894*68e0d42fSEd L. Cashin 		return NULL;
895*68e0d42fSEd L. Cashin 
896*68e0d42fSEd L. Cashin 	t = kcalloc(1, sizeof *t, GFP_ATOMIC);
897*68e0d42fSEd L. Cashin 	f = kcalloc(nframes, sizeof *f, GFP_ATOMIC);
898*68e0d42fSEd L. Cashin 	if (!t || !f)
899*68e0d42fSEd L. Cashin 		goto bail;
900*68e0d42fSEd L. Cashin 	t->nframes = nframes;
901*68e0d42fSEd L. Cashin 	t->frames = f;
902*68e0d42fSEd L. Cashin 	e = f + nframes;
903*68e0d42fSEd L. Cashin 	for (; f < e; f++) {
904*68e0d42fSEd L. Cashin 		f->tag = FREETAG;
905*68e0d42fSEd L. Cashin 		f->skb = new_skb(ETH_ZLEN);
906*68e0d42fSEd L. Cashin 		if (!f->skb)
907*68e0d42fSEd L. Cashin 			break;
908*68e0d42fSEd L. Cashin 	}
909*68e0d42fSEd L. Cashin 	if (f != e) {
910*68e0d42fSEd L. Cashin 		while (f > t->frames) {
911*68e0d42fSEd L. Cashin 			f--;
912*68e0d42fSEd L. Cashin 			dev_kfree_skb(f->skb);
913*68e0d42fSEd L. Cashin 		}
914*68e0d42fSEd L. Cashin 		goto bail;
915*68e0d42fSEd L. Cashin 	}
916*68e0d42fSEd L. Cashin 	memcpy(t->addr, addr, sizeof t->addr);
917*68e0d42fSEd L. Cashin 	t->ifp = t->ifs;
918*68e0d42fSEd L. Cashin 	t->maxout = t->nframes;
919*68e0d42fSEd L. Cashin 	return *tt = t;
920*68e0d42fSEd L. Cashin bail:
921*68e0d42fSEd L. Cashin 	kfree(t);
922*68e0d42fSEd L. Cashin 	kfree(f);
923*68e0d42fSEd L. Cashin 	return NULL;
924*68e0d42fSEd L. Cashin }
925*68e0d42fSEd L. Cashin 
9261da177e4SLinus Torvalds void
9271da177e4SLinus Torvalds aoecmd_cfg_rsp(struct sk_buff *skb)
9281da177e4SLinus Torvalds {
9291da177e4SLinus Torvalds 	struct aoedev *d;
9301da177e4SLinus Torvalds 	struct aoe_hdr *h;
9311da177e4SLinus Torvalds 	struct aoe_cfghdr *ch;
932*68e0d42fSEd L. Cashin 	struct aoetgt *t;
933*68e0d42fSEd L. Cashin 	struct aoeif *ifp;
93463e9cc5dSecashin@coraid.com 	ulong flags, sysminor, aoemajor;
9351da177e4SLinus Torvalds 	struct sk_buff *sl;
936eaf0a3cbSEd L. Cashin 	enum { MAXFRAMES = 16 };
93719bf2635SEd L. Cashin 	u16 n;
9381da177e4SLinus Torvalds 
939abdbf94dSEd L. Cashin 	h = (struct aoe_hdr *) skb_mac_header(skb);
9401da177e4SLinus Torvalds 	ch = (struct aoe_cfghdr *) (h+1);
9411da177e4SLinus Torvalds 
9421da177e4SLinus Torvalds 	/*
9431da177e4SLinus Torvalds 	 * Enough people have their dip switches set backwards to
9441da177e4SLinus Torvalds 	 * warrant a loud message for this special case.
9451da177e4SLinus Torvalds 	 */
94643ecf529SDavid S. Miller 	aoemajor = be16_to_cpu(get_unaligned(&h->major));
9471da177e4SLinus Torvalds 	if (aoemajor == 0xfff) {
948a12c93f0SEd L. Cashin 		printk(KERN_ERR "aoe: Warning: shelf address is all ones.  "
9496bb6285fSEd L. Cashin 			"Check shelf dip switches.\n");
9501da177e4SLinus Torvalds 		return;
9511da177e4SLinus Torvalds 	}
9521da177e4SLinus Torvalds 
9531da177e4SLinus Torvalds 	sysminor = SYSMINOR(aoemajor, h->minor);
954fc458dcdSecashin@coraid.com 	if (sysminor * AOE_PARTITIONS + AOE_PARTITIONS > MINORMASK) {
955a12c93f0SEd L. Cashin 		printk(KERN_INFO "aoe: e%ld.%d: minor number too large\n",
956fc458dcdSecashin@coraid.com 			aoemajor, (int) h->minor);
9571da177e4SLinus Torvalds 		return;
9581da177e4SLinus Torvalds 	}
9591da177e4SLinus Torvalds 
96019bf2635SEd L. Cashin 	n = be16_to_cpu(ch->bufcnt);
96119bf2635SEd L. Cashin 	if (n > MAXFRAMES)	/* keep it reasonable */
96219bf2635SEd L. Cashin 		n = MAXFRAMES;
9631da177e4SLinus Torvalds 
964*68e0d42fSEd L. Cashin 	d = aoedev_by_sysminor_m(sysminor);
9651da177e4SLinus Torvalds 	if (d == NULL) {
966a12c93f0SEd L. Cashin 		printk(KERN_INFO "aoe: device sysminor_m failure\n");
9671da177e4SLinus Torvalds 		return;
9681da177e4SLinus Torvalds 	}
9691da177e4SLinus Torvalds 
9701da177e4SLinus Torvalds 	spin_lock_irqsave(&d->lock, flags);
9711da177e4SLinus Torvalds 
972*68e0d42fSEd L. Cashin 	t = gettgt(d, h->src);
973*68e0d42fSEd L. Cashin 	if (!t) {
974*68e0d42fSEd L. Cashin 		t = addtgt(d, h->src, n);
975*68e0d42fSEd L. Cashin 		if (!t) {
976*68e0d42fSEd L. Cashin 			printk(KERN_INFO
977*68e0d42fSEd L. Cashin 				"aoe: device addtgt failure; "
978*68e0d42fSEd L. Cashin 				"too many targets?\n");
979*68e0d42fSEd L. Cashin 			spin_unlock_irqrestore(&d->lock, flags);
980*68e0d42fSEd L. Cashin 			return;
981*68e0d42fSEd L. Cashin 		}
982*68e0d42fSEd L. Cashin 	}
983*68e0d42fSEd L. Cashin 	ifp = getif(t, skb->dev);
984*68e0d42fSEd L. Cashin 	if (!ifp) {
985*68e0d42fSEd L. Cashin 		ifp = addif(t, skb->dev);
986*68e0d42fSEd L. Cashin 		if (!ifp) {
987*68e0d42fSEd L. Cashin 			printk(KERN_INFO
988*68e0d42fSEd L. Cashin 				"aoe: device addif failure; "
989*68e0d42fSEd L. Cashin 				"too many interfaces?\n");
990*68e0d42fSEd L. Cashin 			spin_unlock_irqrestore(&d->lock, flags);
991*68e0d42fSEd L. Cashin 			return;
992*68e0d42fSEd L. Cashin 		}
993*68e0d42fSEd L. Cashin 	}
994*68e0d42fSEd L. Cashin 	if (ifp->maxbcnt) {
995*68e0d42fSEd L. Cashin 		n = ifp->nd->mtu;
99619bf2635SEd L. Cashin 		n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr);
99719bf2635SEd L. Cashin 		n /= 512;
99819bf2635SEd L. Cashin 		if (n > ch->scnt)
99919bf2635SEd L. Cashin 			n = ch->scnt;
10004f51dc5eSEd L. Cashin 		n = n ? n * 512 : DEFAULTBCNT;
1001*68e0d42fSEd L. Cashin 		if (n != ifp->maxbcnt) {
1002a12c93f0SEd L. Cashin 			printk(KERN_INFO
1003*68e0d42fSEd L. Cashin 				"aoe: e%ld.%d: setting %d%s%s:%012llx\n",
1004*68e0d42fSEd L. Cashin 				d->aoemajor, d->aoeminor, n,
1005*68e0d42fSEd L. Cashin 				" byte data frames on ", ifp->nd->name,
1006*68e0d42fSEd L. Cashin 				(unsigned long long) mac_addr(t->addr));
1007*68e0d42fSEd L. Cashin 			ifp->maxbcnt = n;
10084f51dc5eSEd L. Cashin 		}
100919bf2635SEd L. Cashin 	}
10103ae1c24eSEd L. Cashin 
10113ae1c24eSEd L. Cashin 	/* don't change users' perspective */
1012*68e0d42fSEd L. Cashin 	if (d->nopen) {
10131da177e4SLinus Torvalds 		spin_unlock_irqrestore(&d->lock, flags);
10141da177e4SLinus Torvalds 		return;
10151da177e4SLinus Torvalds 	}
101663e9cc5dSecashin@coraid.com 	d->fw_ver = be16_to_cpu(ch->fwver);
10171da177e4SLinus Torvalds 
1018*68e0d42fSEd L. Cashin 	sl = aoecmd_ata_id(d);
10191da177e4SLinus Torvalds 
10201da177e4SLinus Torvalds 	spin_unlock_irqrestore(&d->lock, flags);
10211da177e4SLinus Torvalds 
10221da177e4SLinus Torvalds 	aoenet_xmit(sl);
10231da177e4SLinus Torvalds }
10241da177e4SLinus Torvalds 
1025*68e0d42fSEd L. Cashin void
1026*68e0d42fSEd L. Cashin aoecmd_cleanslate(struct aoedev *d)
1027*68e0d42fSEd L. Cashin {
1028*68e0d42fSEd L. Cashin 	struct aoetgt **t, **te;
1029*68e0d42fSEd L. Cashin 	struct aoeif *p, *e;
1030*68e0d42fSEd L. Cashin 
1031*68e0d42fSEd L. Cashin 	d->mintimer = MINTIMER;
1032*68e0d42fSEd L. Cashin 
1033*68e0d42fSEd L. Cashin 	t = d->targets;
1034*68e0d42fSEd L. Cashin 	te = t + NTARGETS;
1035*68e0d42fSEd L. Cashin 	for (; t < te && *t; t++) {
1036*68e0d42fSEd L. Cashin 		(*t)->maxout = (*t)->nframes;
1037*68e0d42fSEd L. Cashin 		p = (*t)->ifs;
1038*68e0d42fSEd L. Cashin 		e = p + NAOEIFS;
1039*68e0d42fSEd L. Cashin 		for (; p < e; p++) {
1040*68e0d42fSEd L. Cashin 			p->lostjumbo = 0;
1041*68e0d42fSEd L. Cashin 			p->lost = 0;
1042*68e0d42fSEd L. Cashin 			p->maxbcnt = DEFAULTBCNT;
1043*68e0d42fSEd L. Cashin 		}
1044*68e0d42fSEd L. Cashin 	}
1045*68e0d42fSEd L. Cashin }
1046