From 501a0fc55c7eb4d5a9feffca7d8a2624f459204e Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 22 Jun 1996 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1996-06-22 --- pc/ether82557.c | 32 ++++++++++++++++---------------- pc/etherif.h | 1 + pc/scsi.c | 37 ++++++++++++++++++++++++++----------- 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/pc/ether82557.c b/pc/ether82557.c index 90eddf20693242c95413ed134494b1b6e0cc09c8..67e3fbac55044d14355370c3c03c209e40e011da 100644 --- a/pc/ether82557.c +++ b/pc/ether82557.c @@ -183,7 +183,7 @@ typedef struct Ctlr { uchar configdata[24]; - Lock rlock; /* registers */ + Lock lock; Block* rfd[Nrfd]; /* receive side */ int rfdl; @@ -193,7 +193,7 @@ typedef struct Ctlr { Block* cbqtail; int cbqbusy; - Lock dlock; /* dump statistical counters */ + Lock dlock; /* dump statistical counters */ ulong dump[17]; } Ctlr; @@ -274,7 +274,7 @@ attach(Ether* ether) Ctlr *ctlr; ctlr = ether->ctlr; - ilock(&ctlr->rlock); + ilock(&ctlr->lock); status = csr16r(ctlr, Status); if((status & RUstatus) == RUidle){ while(csr8r(ctlr, Command)) @@ -282,7 +282,7 @@ attach(Ether* ether) csr32w(ctlr, General, PADDR(ctlr->rfd[ctlr->rfdx]->rp)); csr8w(ctlr, Command, RUstart); } - iunlock(&ctlr->rlock); + iunlock(&ctlr->lock); } static Block* @@ -313,9 +313,9 @@ promiscuous(void* arg, int on) ctlr = ((Ether*)arg)->ctlr; bp = configure(ctlr, on); - ilock(&ctlr->rlock); + ilock(&ctlr->lock); action(ctlr, bp); - iunlock(&ctlr->rlock); + iunlock(&ctlr->lock); } static long @@ -329,11 +329,11 @@ ifstat(Ether* ether, void* a, long n, ulong offset) lock(&ctlr->dlock); ctlr->dump[16] = 0; - ilock(&ctlr->rlock); + ilock(&ctlr->lock); while(csr8r(ctlr, Command)) ; csr8w(ctlr, Command, DumpSC); - iunlock(&ctlr->rlock); + iunlock(&ctlr->lock); /* * Wait for completion status, should be 0xA005. @@ -397,9 +397,9 @@ write(Ether* ether, void* buf, long n) bp->wp += n; ctlr = ether->ctlr; - ilock(&ctlr->rlock); + ilock(&ctlr->lock); action(ctlr, bp); - iunlock(&ctlr->rlock); + iunlock(&ctlr->lock); ether->outpackets++; @@ -418,7 +418,7 @@ interrupt(Ureg*, void* arg) ether = arg; ctlr = ether->ctlr; - ilock(&ctlr->rlock); + ilock(&ctlr->lock); for(;;){ status = csr16r(ctlr, Status); csr8w(ctlr, Ack, (status>>8) & 0xFF); @@ -481,7 +481,7 @@ interrupt(Ureg*, void* arg) if(status & (StatCX|StatFR|StatCNA|StatRNR|StatMDI|StatSWI)) panic("%s#%d: status %uX\n", ctlr->type, ctlr->ctlrno, status); } - iunlock(&ctlr->rlock); + iunlock(&ctlr->lock); } static void @@ -600,7 +600,7 @@ struct Adapter { static Adapter *adapter; static int -i82557(Ether* ether, int* pcidevno) +i82557pci(Ether* ether, int* pcidevno) { PCIcfg pcicfg; static int devno = 0; @@ -666,7 +666,7 @@ reset(Ether* ether) break; } } - if(port == 0 && (port = i82557(ether, &pcidevno)) == 0) + if(port == 0 && (port = i82557pci(ether, &pcidevno)) == 0) return -1; /* @@ -683,7 +683,7 @@ reset(Ether* ether) ctlr->type = ether->type; ctlr->port = port; - ilock(&ctlr->rlock); + ilock(&ctlr->lock); csr32w(ctlr, Port, 0); delay(1); @@ -763,7 +763,7 @@ reset(Ether* ether) memmove(cb->data, ether->ea, Eaddrlen); action(ctlr, bp); - iunlock(&ctlr->rlock); + iunlock(&ctlr->lock); /* * Linkage to the generic ethernet driver. diff --git a/pc/etherif.h b/pc/etherif.h index 39aaafacd6f73416e3917fcad458607f13e522bf..b369578ec9a435fa1482daa46fc63c080b235631 100644 --- a/pc/etherif.h +++ b/pc/etherif.h @@ -54,5 +54,6 @@ extern void *dp8390write(Dp8390*, ulong, void*, ulong); extern void dp8390setea(Ether*); #define NEXT(x, l) (((x)+1)%(l)) +#define PREV(x, l) (((x) == 0) ? (l)-1: (x)-1) #define HOWMANY(x, y) (((x)+((y)-1))/(y)) #define ROUNDUP(x, y) (HOWMANY((x), (y))*(y)) diff --git a/pc/scsi.c b/pc/scsi.c index b452514e70f0389976095a8dd345cfade289b5ea..550fe0bc4a9fb594d0e082712ffbb51aa9b1afe2 100644 --- a/pc/scsi.c +++ b/pc/scsi.c @@ -290,8 +290,8 @@ scsicap(Target *t, char lun, ulong *size, ulong *bsize) s = scsiexec(t, SCSIread, cmd, sizeof(cmd), d, &nbytes); if(s == STok) { - *size = nhgetl(d+0); - *bsize = nhgetl(d+4); + *size = (d[0]<<24)|(d[1]<<16)|(d[2]<<8)|d[3]; + *bsize = (d[4]<<24)|(d[5]<<16)|(d[6]<<8)|d[7]; } scsifree(d); return s; @@ -303,14 +303,15 @@ scsibio(Target *t, char lun, int dir, void *b, long n, long bsize, long bno) uchar cmd[10]; int s, cdbsiz, nbytes; - memset(cmd, 0, sizeof cmd); if(bno <= 0x1fffff && n < 256) { cmd[0] = 0x0A; if(dir == SCSIread) cmd[0] = 0x08; cmd[1] = (lun<<5) | bno >> 16; - hnputs(cmd+2, bno); + cmd[2] = bno>>8; + cmd[3] = bno; cmd[4] = n; + cmd[5] = 0; cdbsiz = 6; } else { @@ -318,8 +319,13 @@ scsibio(Target *t, char lun, int dir, void *b, long n, long bsize, long bno) if(dir == SCSIread) cmd[0] = 0x28; cmd[1] = (lun<<5); - hnputl(cmd+2, bno); - hnputs(cmd+7, n); + cmd[2] = bno>>24; + cmd[3] = bno>>16; + cmd[4] = bno>>8; + cmd[5] = bno; + cmd[7] = n>>8; + cmd[8] = n; + cmd[9] = 0; cdbsiz = 10; } nbytes = n*bsize; @@ -432,7 +438,8 @@ scsidiskinfo(Target *t, char lun, int track, uchar *data) cmd[0] = 0x43; cmd[1] = lun<<5; cmd[6] = track; - hnputs(cmd+7, nbytes); + cmd[7] = nbytes>>8; + cmd[8] = nbytes; d = scsialloc(nbytes); if(d == 0) @@ -457,7 +464,8 @@ scsitrackinfo(Target *t, char lun, int track, uchar *data) cmd[0] = 0xe5; cmd[1] = lun<<5; cmd[5] = track; - hnputs(cmd+7, nbytes); + cmd[7] = nbytes>>8; + cmd[8] = nbytes; d = scsialloc(nbytes); if(d == 0) @@ -491,7 +499,10 @@ scsibufsize(Target *t, char lun, int size) memset(d, 0, nbytes); d[3] = 8; - hnputl(d+8, size); + d[8] = size>>24; + d[9] = size>>16; + d[10] = size>>8; + d[11] = size; s = scsiexec(t, SCSIwrite, cmd, sizeof(cmd), d, &nbytes); scsifree(d); @@ -508,8 +519,12 @@ scsireadcdda(Target *t, char lun, int, void *b, long n, long bsize, long bno) cmd[0] = 0xd8; cmd[1] = (lun<<5); - hnputl(cmd+2, bno); - hnputl(cmd+6, n); + cmd[2] = bno>>24; + cmd[3] = bno>>16; + cmd[4] = bno>>8; + cmd[5] = bno; + cmd[6] = n>>8; + cmd[7] = n; nbytes = n*bsize; s = scsiexec(t, SCSIread, cmd, sizeof(cmd), b, &nbytes);