1: /*
   2:  * Copyright (c) 1986 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)if_css.c	1.2 (2.11BSD) 1997/1/18
   7:  */
   8: 
   9: #include "css.h"
  10: #if NCSS > 0
  11: 
  12: /*
  13:  * DEC/CSS IMP11-A ARPAnet IMP interface driver.
  14:  * Since "imp11a" is such a mouthful, it is called
  15:  * "css" after the LH/DH being called "acc".
  16:  *
  17:  * Configuration notes:
  18:  *
  19:  * As delivered from DEC/CSS, it
  20:  * is addressed and vectored as two DR11-B's.  This makes
  21:  * Autoconfig almost IMPOSSIBLE.  To make it work, the
  22:  * interrupt vectors must be restrapped to make the vectors
  23:  * consecutive.  The 020 hole between the CSR addresses is
  24:  * tolerated, althought that could be cleaned-up also.
  25:  *
  26:  * Additionally, the TRANSMIT side of the IMP11-A has the
  27:  * lower address of the two subunits, so the vector ordering
  28:  * in the CONFIG file is reversed from most other devices.
  29:  * It should be:
  30:  *
  31:  * device css0 ....  cssxint cssrint
  32:  *
  33:  * If you get it wrong, it will still autoconfig, but will just
  34:  * sit there with RECIEVE IDLE indicated on the front panel.
  35:  */
  36: 
  37: #include "param.h"
  38: #include "../machine/seg.h"
  39: 
  40: #include "systm.h"
  41: #include "mbuf.h"
  42: #include "buf.h"
  43: #include "domain.h"
  44: #include "protosw.h"
  45: #include "socket.h"
  46: #include "pdpuba/ubavar.h"
  47: 
  48: #include "../net/if.h"
  49: 
  50: #include "../netinet/in.h"
  51: #include "../netinet/in_systm.h"
  52: #include "../netimp/if_imp.h"
  53: 
  54: #include "if_css.h"
  55: #include "if_uba.h"
  56: 
  57: int cssprobe(), cssattach(), cssrint(), cssxint();
  58: int cssinit(), cssstart(), cssreset();
  59: 
  60: struct uba_device *cssinfo[NCSS];
  61: u_short cssstd[] = { 0 };
  62: struct  uba_driver cssdriver =
  63:     { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo };
  64: #define CSSUNIT(x)  minor(x)
  65: 
  66: /*
  67:  * "Lower half" of IMP interface driver.
  68:  *
  69:  * Each IMP interface is handled by a common module which handles
  70:  * the IMP-host protocol and a hardware driver which manages the
  71:  * hardware specific details of talking with the IMP.
  72:  *
  73:  * The hardware portion of the IMP driver handles DMA and related
  74:  * management of UNIBUS resources.  The IMP protocol module interprets
  75:  * contents of these messages and "controls" the actions of the
  76:  * hardware module during IMP resets, but not, for instance, during
  77:  * UNIBUS resets.
  78:  *
  79:  * The two modules are coupled at "attach time", and ever after,
  80:  * through the imp interface structure.  Higher level protocols,
  81:  * e.g. IP, interact with the IMP driver, rather than the CSS.
  82:  */
  83: struct  css_softc {
  84:     struct  ifnet *css_if;      /* pointer to IMP's ifnet struct */
  85:     struct  impcb *css_ic;      /* data structure shared with IMP */
  86:     struct  ifuba css_ifuba;    /* UNIBUS resources */
  87:     struct  mbuf *css_iq;       /* input reassembly queue */
  88:     short   css_olen;       /* size of last message sent */
  89:     char    css_flush;      /* flush remainder of message */
  90: } css_softc[NCSS];
  91: 
  92: /*
  93:  * Reset the IMP and cause a transmitter interrupt by
  94:  * performing a null DMA.
  95:  */
  96: cssprobe(reg)
  97:     caddr_t reg;
  98: {
  99: #if !pdp11
 100:     register int br, cvec;    /* r11, r10 value-result */
 101:     register struct cssdevice *addr = (struct cssdevice *)reg;
 102: 
 103: #ifdef lint
 104:     br = 0; cvec = br; br = cvec;
 105:     cssrint(0); cssxint(0);
 106: #endif
 107: 
 108:     addr->css_icsr = CSS_CLR;
 109:     addr->css_ocsr = CSS_CLR;
 110:     DELAY(50000L);
 111:     addr->css_icsr = 0;
 112:     addr->css_ocsr = 0;
 113:     DELAY(50000L);
 114: 
 115:     addr->css_oba = 0;
 116:     addr->css_owc = -1;
 117:     addr->css_ocsr = CSS_IE | CSS_GO;   /* enable interrupts */
 118:     DELAY(50000L);
 119:     addr->css_ocsr = 0;
 120: 
 121:     return (1);
 122: #endif !pdp11
 123: }
 124: 
 125: /*
 126:  * Call the IMP module to allow it to set up its internal
 127:  * state, then tie the two modules together by setting up
 128:  * the back pointers to common data structures.
 129:  */
 130: cssattach(ui)
 131:     struct uba_device *ui;
 132: {
 133:     register struct css_softc *sc = &css_softc[ui->ui_unit];
 134:     register struct impcb *ip;
 135:     struct ifimpcb {
 136:         struct  ifnet ifimp_if;
 137:         struct  impcb ifimp_impcb;
 138:     } *ifimp;
 139:     if ((ifimp = (struct ifimpcb *)impattach(ui, cssreset)) == 0)
 140:         panic("cssattach");      /* XXX */
 141:     sc->css_if = &ifimp->ifimp_if;
 142:     ip = &ifimp->ifimp_impcb;
 143:     sc->css_ic = ip;
 144:     ip->ic_init = cssinit;
 145:     ip->ic_start = cssstart;
 146:     sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16;
 147: #ifdef notdef
 148:     sc->css_ifuba.ifu_flags |= UBA_NEEDBDP;
 149: #endif
 150: }
 151: 
 152: /*
 153:  * Reset interface after UNIBUS reset.
 154:  * If interface is on specified uba, reset its state.
 155:  */
 156: cssreset(unit, uban)
 157:     int unit, uban;
 158: {
 159:     register struct uba_device *ui;
 160:     struct css_softc *sc;
 161: 
 162:     if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 ||
 163:         ui->ui_ubanum != uban)
 164:         return;
 165:     printf(" css%d", unit);
 166:     sc = &css_softc[unit];
 167:     /* must go through IMP to allow it to set state */
 168:     (*sc->css_if->if_init)(unit);
 169: }
 170: 
 171: /*
 172:  * Initialize interface: clear recorded pending operations,
 173:  * and retrieve, and reinitialize UNIBUS resources.
 174:  */
 175: cssinit(unit)
 176:     int unit;
 177: {
 178:     register struct css_softc *sc;
 179:     register struct uba_device *ui;
 180:     register struct cssdevice *addr;
 181:     int x;
 182:     long info;
 183: 
 184:     if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) {
 185:         printf("css%d: not alive\n", unit);
 186:         return(0);
 187:     }
 188:     sc = &css_softc[unit];
 189: 
 190:     /*
 191: 	 * Header length is 0 to if_ubainit since we have to pass
 192: 	 * the IMP leader up to the protocol interpretaion
 193: 	 * routines.  If we had the deader length as
 194: 	 * sizeof(struct imp_leader), then the if_ routines
 195: 	 * would assume we handle it on input and output.
 196: 	 */
 197: 
 198:     if (if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,(int)btoc(IMPMTU)) == 0) {
 199:         printf("css%d: can't initialize\n", unit);
 200:         ui->ui_alive = 0;
 201:         return(0);
 202:     }
 203:     addr = (struct cssdevice *)ui->ui_addr;
 204: 
 205:     /* reset the imp interface. */
 206:     x = splimp();
 207:     addr->css_icsr = CSS_CLR;
 208:     addr->css_ocsr = CSS_CLR;
 209:     DELAY(100L);
 210:     addr->css_icsr = 0;
 211:     addr->css_ocsr = 0;
 212:     addr->css_icsr = IN_HRDY;       /* close the relay */
 213:     DELAY(5000L);
 214:     splx(x);
 215: 
 216:     /*
 217: 	 * This may hang if the imp isn't really there.
 218: 	 * Will test and verify safe operation.
 219: 	 */
 220: 
 221:     x = 5;
 222:     while (x-- > 0) {
 223:         if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY)
 224:             break;
 225:         addr->css_icsr = IN_HRDY;   /* close the relay */
 226:         DELAY(5000L);
 227:     }
 228: 
 229:     if (x <= 0) {
 230: /*
 231: 		printf("css%d: imp doesn't respond, icsr=%b\n", unit,
 232: 			CSS_INBITS, addr->css_icsr);
 233: */
 234:         goto down;
 235:     }
 236: 
 237:     /*
 238: 	 * Put up a read.  We can't restart any outstanding writes
 239: 	 * until we're back in synch with the IMP (i.e. we've flushed
 240: 	 * the NOOPs it throws at us).
 241: 	 * Note: IMPMTU includes the leader.
 242: 	 */
 243: 
 244:     x = splimp();
 245:     info = sc->css_ifuba.ifu_r.ifrw_info;
 246:     addr->css_iba = (u_short)info;
 247:     addr->css_iwc = -(IMPMTU >> 1);
 248:     addr->css_icsr =
 249:         IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
 250:     splx(x);
 251:     return(1);
 252: 
 253: down:
 254:     ui->ui_alive = 0;
 255:     return(0);
 256: }
 257: 
 258: /*
 259:  * Start output on an interface.
 260:  */
 261: cssstart(dev)
 262:     dev_t dev;
 263: {
 264:     int unit = CSSUNIT(dev);
 265:     long info;
 266:     struct uba_device *ui = cssinfo[unit];
 267:     register struct css_softc *sc = &css_softc[unit];
 268:     register struct cssdevice *addr;
 269:     struct mbuf *m;
 270:     u_short cmd;
 271: 
 272:     if (sc->css_ic->ic_oactive)
 273:         goto restart;
 274: 
 275:     /*
 276: 	 * Not already active, deqeue a request and
 277: 	 * map it onto the UNIBUS.  If no more
 278: 	 * requeusts, just return.
 279: 	 */
 280:     IF_DEQUEUE(&sc->css_if->if_snd, m);
 281:     if (m == 0) {
 282:         sc->css_ic->ic_oactive = 0;
 283:         return;
 284:     }
 285:     sc->css_olen = if_wubaput(&sc->css_ifuba, m);
 286: 
 287: restart:
 288:     addr = (struct cssdevice *)ui->ui_addr;
 289:     info = sc->css_ifuba.ifu_w.ifrw_info;
 290:     addr->css_oba = (u_short)info;
 291:     addr->css_owc = -((sc->css_olen + 1) >> 1);
 292:     cmd = CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO;
 293:     addr->css_ocsr = cmd;
 294:     sc->css_ic->ic_oactive = 1;
 295: }
 296: 
 297: /*
 298:  * Output interrupt handler.
 299:  */
 300: cssxint(unit)
 301: {
 302:     register struct uba_device *ui = cssinfo[unit];
 303:     register struct css_softc *sc = &css_softc[unit];
 304:     register struct cssdevice *addr;
 305: 
 306:     addr = (struct cssdevice *)ui->ui_addr;
 307:     if (sc->css_ic->ic_oactive == 0) {
 308:         printf("css%d: stray output interrupt csr=%b\n",
 309:             unit, addr->css_ocsr, CSS_OUTBITS);
 310:         goto out;
 311:     }
 312:     sc->css_if->if_opackets++;
 313:     sc->css_ic->ic_oactive = 0;
 314:     if (addr->css_ocsr & CSS_ERR){
 315:         sc->css_if->if_oerrors++;
 316:         printf("css%d: output error, ocsr=%b icsr=%b\n", unit,
 317:             addr->css_ocsr, CSS_OUTBITS,
 318:             addr->css_icsr, CSS_INBITS);
 319:     }
 320:     if (sc->css_ifuba.ifu_xtofree) {
 321:         m_freem(sc->css_ifuba.ifu_xtofree);
 322:         sc->css_ifuba.ifu_xtofree = 0;
 323:     }
 324:     if (sc->css_if->if_snd.ifq_head)
 325:         cssstart(unit);
 326: out:
 327:     return;
 328: }
 329: 
 330: /*
 331:  * Input interrupt handler
 332:  */
 333: cssrint(unit)
 334: {
 335:     register struct css_softc *sc = &css_softc[unit];
 336:     register struct cssdevice *addr;
 337:     register struct ifqueue *inq;
 338:     struct mbuf *m;
 339:     int len;
 340:     long info;
 341: 
 342:     sc->css_if->if_ipackets++;
 343: 
 344:     addr = (struct cssdevice *)cssinfo[unit]->ui_addr;
 345:     if (addr->css_icsr & CSS_ERR) {
 346:         printf("css%d: recv error, csr=%b\n", unit,
 347:             addr->css_icsr, CSS_INBITS);
 348:         sc->css_if->if_ierrors++;
 349:         sc->css_flush = 1;
 350:         if (addr->css_icsr & IN_IMPNR) {
 351:             impinput(unit,(struct mbuf *)0);
 352:             goto out;
 353:         }
 354:     }
 355: 
 356:     if (sc->css_flush) {
 357:         if (addr->css_icsr & IN_EOM)
 358:             sc->css_flush = 0;
 359:         goto setup;
 360:     }
 361: 
 362:     len = IMPMTU + (addr->css_iwc << 1);
 363:     if (len < 0 || len > IMPMTU) {
 364:         printf("css%d: bad length=%d\n", len);
 365:         sc->css_if->if_ierrors++;
 366:         goto setup;
 367:     }
 368: 
 369:     /*
 370: 	 * The next to last parameter is always 0 since using
 371: 	 * trailers on the ARPAnet is insane.
 372: 	 */
 373:     m = if_rubaget(&sc->css_ifuba, len, 0, &sc->css_if);
 374:     if (m == 0)
 375:         goto setup;
 376:     if ((addr->css_icsr & IN_EOM) == 0) {
 377:         if (sc->css_iq)
 378:             m_cat(sc->css_iq, m);
 379:         else
 380:             sc->css_iq = m;
 381:         goto setup;
 382:     }
 383:     if (sc->css_iq) {
 384:         m_cat(sc->css_iq, m);
 385:         m = sc->css_iq;
 386:         sc->css_iq = 0;
 387:     }
 388:     impinput(unit, m);
 389: 
 390: setup:
 391:     /*
 392: 	 * Setup for next message.
 393: 	 */
 394:     info = sc->css_ifuba.ifu_r.ifrw_info;
 395:     addr->css_iba = (u_short)info;
 396:     addr->css_iwc = - (IMPMTU >> 1);
 397:     addr->css_icsr =
 398:         IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
 399: out:
 400:     return;
 401: }
 402: #endif NCSS

Defined functions

cssattach defined in line 130; used 2 times
cssinit defined in line 175; used 2 times
cssprobe defined in line 96; used 2 times
cssreset defined in line 156; used 2 times
cssrint defined in line 333; used 2 times
cssstart defined in line 261; used 3 times
cssxint defined in line 300; used 2 times

Defined variables

css_softc defined in line 90; used 6 times
cssdriver defined in line 62; never used
cssinfo defined in line 60; used 6 times
cssstd defined in line 61; used 1 times
  • in line 63

Defined struct's

css_softc defined in line 83; used 12 times
ifimpcb defined in line 135; used 2 times
  • in line 139(2)

Defined macros

CSSUNIT defined in line 64; used 1 times
Last modified: 1997-01-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3589
Valid CSS Valid XHTML 1.0 Strict