--- aoecmd.c.orig 2006-05-25 17:13:09 UTC +++ aoecmd.c @@ -44,9 +44,32 @@ #include #include #include +#include #include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include + + #define TIMERTICK (hz / 10) #define MINTIMER (2 * TIMERTICK) #define MAXTIMER (hz << 1) @@ -147,10 +170,12 @@ */ bcnt = bp->bio_resid; - dsz = aoenet_maxsize(d->ad_ifp); + dsz = aoenet_maxsize(d->ad_ifp); if (bcnt > dsz) bcnt = dsz; + + /* Initialize the headers & frame. */ h = (struct aoe_hdr *) f->f_hdr; ah = (struct aoe_atahdr *) (h+1); @@ -188,8 +213,7 @@ if (bp->bio_resid == 0) /* We have satisfied strategy bio. */ d->ad_inprocess = NULL; - if(aoenet_xmitframe(d, f)) - IPRINTK("Could not send frame\n"); + aoenet_xmitframe(d, f); } static void @@ -217,8 +241,7 @@ f->f_tag = newtag(d); h->ah_tag = htonl(f->f_tag); - if (aoenet_xmitframe(d, f)) - IPRINTK("Could not send frame\n"); + aoenet_xmitframe(d, f); } /* How long since we sent this tag? */ @@ -306,8 +329,7 @@ ah->aa_errfeat = aoe_wc ? ATA_SF_ENAB_WCACHE : ATA_SF_DIS_WCACHE; ah->aa_lba3 = 0xa0; /* Obsolete bits per ATA6. */ - if (aoenet_xmitframe(d, f)) - IPRINTK("Could not send frame\n"); + aoenet_xmitframe(d, f); } /* Command to send an ATA identify. */ @@ -343,7 +365,6 @@ ah->aa_lba3 = 0xa0; if (aoenet_xmitframe(d, f)) { - IPRINTK("Could not send frame\n"); return; } @@ -358,17 +379,26 @@ struct aoe_hdr *h; struct aoe_cfghdr *ch; u_long unit, bufcnt; - enum { MAXFRAMES = 8 }; - + enum { MAXFRAMES = 256 }; + h = mtod(m, struct aoe_hdr *); ch = (struct aoe_cfghdr *) (h+1); - unit = AOEUNIT(ntohs(h->ah_major), h->ah_minor); + if(h->ah_minor>MINPERMAJ-1) { + EPRINTK("AoE minor id %d > %d (maximum allowed), ignoring\n", + h->ah_minor, + MINPERMAJ-1); + return; + } bufcnt = ntohs(ch->ac_bufcnt); - if (bufcnt > MAXFRAMES) /* Let's keep it reasonable. */ + if (bufcnt > MAXFRAMES) { /* Let's keep it reasonable. */ + EPRINTK("bufcnt=%ld > %d, truncated.\n",bufcnt,MAXFRAMES); bufcnt = MAXFRAMES; - + } + + unit = AOEUNIT(ntohs(h->ah_major), h->ah_minor); + d = aoedev_set(unit, h->ah_src, m->m_pkthdr.rcvif, bufcnt); if (d == NULL) { IPRINTK("failure setting device\n"); @@ -427,43 +457,20 @@ goto loop; } -static u_short -lhget16(u_char *p) -{ - u_short n; - - n = p[1]; - n <<= 8; - n |= p[0]; - return (n); -} - -static u_long -lhget32(u_char *p) -{ - u_long n; - - n = lhget16(p+2); - n <<= 16; - n |= lhget16(p); - return (n); -} - - static void ataid_complete(struct aoedev *d, char *id) { int n; - + memcpy(d->ad_ident, id, sizeof d->ad_ident); - n = lhget16(id + (83<<1)); /* Command set supported. */ + n = le16toh(*(uint16_t *) (id + (83<<1))); /* Command set supported. */ if (n & (1<<10)) { /* Lba48 */ atomic_set_32(&d->ad_flags, DEVFL_EXT); - d->ad_nsectors = lhget32(id + (100<<1)); /* n lba48 sectors. */ + d->ad_nsectors = le64toh(*(uint64_t *) (id + (100<<1))); /* n lba48 sectors. */ } else { atomic_clear_32(&d->ad_flags, DEVFL_EXT); - d->ad_nsectors = lhget32(id + (60<<1)); /* n lba28 sectors. */ + d->ad_nsectors = le32toh(*(uint32_t *) (id + (60<<1))); /* n lba28 sectors. */ } if (aoeblk_register(d) != 0) IPRINTK("could not register disk\n"); @@ -519,8 +526,8 @@ if (f == NULL) { calc_rttavg(d, -tsince(n)); mtx_unlock(&d->ad_mtx); - IPRINTK("unsolicited response from %d.%d\n", - ntohs(hin->ah_major), hin->ah_minor); + //IPRINTK("unsolicited response from %d.%d\n", + // ntohs(hin->ah_major), hin->ah_minor); return; } @@ -642,8 +649,7 @@ lba = iocmd->ata_ioc_request_ata.lba; put_lba(ah, lba); - if (aoenet_xmitframe(d, f)) - IPRINTK("Could not send frame\n"); + aoenet_xmitframe(d, f); if (msleep(d, &d->ad_mtx, 0, "aoesmt", timeout) == EWOULDBLOCK) { f->f_tag = FREETAG;