istallion.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:141k
- * calculated on the fly, and irrelevant ports are skipped.
- */
- for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
- brdp = stli_brds[brdnr];
- if (brdp == (stlibrd_t *) NULL)
- continue;
- if (brdp->state == 0)
- continue;
- maxoff = curoff + (brdp->nrports * MAXLINE);
- if (off >= maxoff) {
- curoff = maxoff;
- continue;
- }
- totalport = brdnr * STL_MAXPORTS;
- for (portnr = 0; (portnr < brdp->nrports); portnr++,
- totalport++) {
- portp = brdp->ports[portnr];
- if (portp == (stliport_t *) NULL)
- continue;
- if (off >= (curoff += MAXLINE))
- continue;
- if ((pos - page + MAXLINE) > count)
- goto stli_readdone;
- pos += stli_portinfo(brdp, portp, totalport, pos);
- }
- }
- *eof = 1;
- stli_readdone:
- *start = page;
- return(pos - page);
- }
- /*****************************************************************************/
- /*
- * Generic send command routine. This will send a message to the slave,
- * of the specified type with the specified argument. Must be very
- * careful of data that will be copied out from shared memory -
- * containing command results. The command completion is all done from
- * a poll routine that does not have user context. Therefore you cannot
- * copy back directly into user space, or to the kernel stack of a
- * process. This routine does not sleep, so can be called from anywhere.
- */
- static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
- {
- volatile cdkhdr_t *hdrp;
- volatile cdkctrl_t *cp;
- volatile unsigned char *bits;
- unsigned long flags;
- #if DEBUG
- printk(KERN_DEBUG "stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
- "copyback=%d)n", (int) brdp, (int) portp, (int) cmd,
- (int) arg, size, copyback);
- #endif
- save_flags(flags);
- cli();
- if (test_bit(ST_CMDING, &portp->state)) {
- printk(KERN_ERR "STALLION: command already busy, cmd=%x!n",
- (int) cmd);
- restore_flags(flags);
- return;
- }
- EBRDENABLE(brdp);
- cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
- if (size > 0) {
- memcpy((void *) &(cp->args[0]), arg, size);
- if (copyback) {
- portp->argp = arg;
- portp->argsize = size;
- }
- }
- cp->status = 0;
- cp->cmd = cmd;
- hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
- bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
- portp->portidx;
- *bits |= portp->portbit;
- set_bit(ST_CMDING, &portp->state);
- EBRDDISABLE(brdp);
- restore_flags(flags);
- }
- /*****************************************************************************/
- /*
- * Read data from shared memory. This assumes that the shared memory
- * is enabled and that interrupts are off. Basically we just empty out
- * the shared memory buffer into the tty buffer. Must be careful to
- * handle the case where we fill up the tty buffer, but still have
- * more chars to unload.
- */
- static inline void stli_read(stlibrd_t *brdp, stliport_t *portp)
- {
- volatile cdkasyrq_t *rp;
- volatile char *shbuf;
- struct tty_struct *tty;
- unsigned int head, tail, size;
- unsigned int len, stlen;
- #if DEBUG
- printk(KERN_DEBUG "stli_read(brdp=%x,portp=%d)n",
- (int) brdp, (int) portp);
- #endif
- if (test_bit(ST_RXSTOP, &portp->state))
- return;
- tty = portp->tty;
- if (tty == (struct tty_struct *) NULL)
- return;
- rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
- head = (unsigned int) rp->head;
- if (head != ((unsigned int) rp->head))
- head = (unsigned int) rp->head;
- tail = (unsigned int) rp->tail;
- size = portp->rxsize;
- if (head >= tail) {
- len = head - tail;
- stlen = len;
- } else {
- len = size - (tail - head);
- stlen = size - tail;
- }
- len = MIN(len, (TTY_FLIPBUF_SIZE - tty->flip.count));
- shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
- while (len > 0) {
- stlen = MIN(len, stlen);
- memcpy(tty->flip.char_buf_ptr, (char *) (shbuf + tail), stlen);
- memset(tty->flip.flag_buf_ptr, 0, stlen);
- tty->flip.char_buf_ptr += stlen;
- tty->flip.flag_buf_ptr += stlen;
- tty->flip.count += stlen;
- len -= stlen;
- tail += stlen;
- if (tail >= size) {
- tail = 0;
- stlen = head;
- }
- }
- rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
- rp->tail = tail;
- if (head != tail)
- set_bit(ST_RXING, &portp->state);
- tty_schedule_flip(tty);
- }
- /*****************************************************************************/
- /*
- * Set up and carry out any delayed commands. There is only a small set
- * of slave commands that can be done "off-level". So it is not too
- * difficult to deal with them here.
- */
- static inline void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
- {
- int cmd;
- if (test_bit(ST_DOSIGS, &portp->state)) {
- if (test_bit(ST_DOFLUSHTX, &portp->state) &&
- test_bit(ST_DOFLUSHRX, &portp->state))
- cmd = A_SETSIGNALSF;
- else if (test_bit(ST_DOFLUSHTX, &portp->state))
- cmd = A_SETSIGNALSFTX;
- else if (test_bit(ST_DOFLUSHRX, &portp->state))
- cmd = A_SETSIGNALSFRX;
- else
- cmd = A_SETSIGNALS;
- clear_bit(ST_DOFLUSHTX, &portp->state);
- clear_bit(ST_DOFLUSHRX, &portp->state);
- clear_bit(ST_DOSIGS, &portp->state);
- memcpy((void *) &(cp->args[0]), (void *) &portp->asig,
- sizeof(asysigs_t));
- cp->status = 0;
- cp->cmd = cmd;
- set_bit(ST_CMDING, &portp->state);
- } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
- test_bit(ST_DOFLUSHRX, &portp->state)) {
- cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
- cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
- clear_bit(ST_DOFLUSHTX, &portp->state);
- clear_bit(ST_DOFLUSHRX, &portp->state);
- memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
- cp->status = 0;
- cp->cmd = A_FLUSH;
- set_bit(ST_CMDING, &portp->state);
- }
- }
- /*****************************************************************************/
- /*
- * Host command service checking. This handles commands or messages
- * coming from the slave to the host. Must have board shared memory
- * enabled and interrupts off when called. Notice that by servicing the
- * read data last we don't need to change the shared memory pointer
- * during processing (which is a slow IO operation).
- * Return value indicates if this port is still awaiting actions from
- * the slave (like open, command, or even TX data being sent). If 0
- * then port is still busy, otherwise no longer busy.
- */
- static inline int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
- {
- volatile cdkasy_t *ap;
- volatile cdkctrl_t *cp;
- struct tty_struct *tty;
- asynotify_t nt;
- unsigned long oldsigs;
- int rc, donerx;
- #if DEBUG
- printk(KERN_DEBUG "stli_hostcmd(brdp=%x,channr=%d)n",
- (int) brdp, channr);
- #endif
- ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
- cp = &ap->ctrl;
- /*
- * Check if we are waiting for an open completion message.
- */
- if (test_bit(ST_OPENING, &portp->state)) {
- rc = (int) cp->openarg;
- if ((cp->open == 0) && (rc != 0)) {
- if (rc > 0)
- rc--;
- cp->openarg = 0;
- portp->rc = rc;
- clear_bit(ST_OPENING, &portp->state);
- wake_up_interruptible(&portp->raw_wait);
- }
- }
- /*
- * Check if we are waiting for a close completion message.
- */
- if (test_bit(ST_CLOSING, &portp->state)) {
- rc = (int) cp->closearg;
- if ((cp->close == 0) && (rc != 0)) {
- if (rc > 0)
- rc--;
- cp->closearg = 0;
- portp->rc = rc;
- clear_bit(ST_CLOSING, &portp->state);
- wake_up_interruptible(&portp->raw_wait);
- }
- }
- /*
- * Check if we are waiting for a command completion message. We may
- * need to copy out the command results associated with this command.
- */
- if (test_bit(ST_CMDING, &portp->state)) {
- rc = cp->status;
- if ((cp->cmd == 0) && (rc != 0)) {
- if (rc > 0)
- rc--;
- if (portp->argp != (void *) NULL) {
- memcpy(portp->argp, (void *) &(cp->args[0]),
- portp->argsize);
- portp->argp = (void *) NULL;
- }
- cp->status = 0;
- portp->rc = rc;
- clear_bit(ST_CMDING, &portp->state);
- stli_dodelaycmd(portp, cp);
- wake_up_interruptible(&portp->raw_wait);
- }
- }
- /*
- * Check for any notification messages ready. This includes lots of
- * different types of events - RX chars ready, RX break received,
- * TX data low or empty in the slave, modem signals changed state.
- */
- donerx = 0;
- if (ap->notify) {
- nt = ap->changed;
- ap->notify = 0;
- tty = portp->tty;
- if (nt.signal & SG_DCD) {
- oldsigs = portp->sigs;
- portp->sigs = stli_mktiocm(nt.sigvalue);
- clear_bit(ST_GETSIGS, &portp->state);
- if ((portp->sigs & TIOCM_CD) &&
- ((oldsigs & TIOCM_CD) == 0))
- wake_up_interruptible(&portp->open_wait);
- if ((oldsigs & TIOCM_CD) &&
- ((portp->sigs & TIOCM_CD) == 0)) {
- if (portp->flags & ASYNC_CHECK_CD) {
- if (! ((portp->flags & ASYNC_CALLOUT_ACTIVE) &&
- (portp->flags & ASYNC_CALLOUT_NOHUP))) {
- if (tty != (struct tty_struct *) NULL) {
- MOD_INC_USE_COUNT;
- if (schedule_task(&portp->tqhangup) == 0)
- MOD_DEC_USE_COUNT;
- }
- }
- }
- }
- }
- if (nt.data & DT_TXEMPTY)
- clear_bit(ST_TXBUSY, &portp->state);
- if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
- if (tty != (struct tty_struct *) NULL) {
- if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
- tty->ldisc.write_wakeup) {
- (tty->ldisc.write_wakeup)(tty);
- EBRDENABLE(brdp);
- }
- wake_up_interruptible(&tty->write_wait);
- }
- }
- if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
- if (tty != (struct tty_struct *) NULL) {
- if (tty->flip.count < TTY_FLIPBUF_SIZE) {
- tty->flip.count++;
- *tty->flip.flag_buf_ptr++ = TTY_BREAK;
- *tty->flip.char_buf_ptr++ = 0;
- if (portp->flags & ASYNC_SAK) {
- do_SAK(tty);
- EBRDENABLE(brdp);
- }
- tty_schedule_flip(tty);
- }
- }
- }
- if (nt.data & DT_RXBUSY) {
- donerx++;
- stli_read(brdp, portp);
- }
- }
- /*
- * It might seem odd that we are checking for more RX chars here.
- * But, we need to handle the case where the tty buffer was previously
- * filled, but we had more characters to pass up. The slave will not
- * send any more RX notify messages until the RX buffer has been emptied.
- * But it will leave the service bits on (since the buffer is not empty).
- * So from here we can try to process more RX chars.
- */
- if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
- clear_bit(ST_RXING, &portp->state);
- stli_read(brdp, portp);
- }
- return((test_bit(ST_OPENING, &portp->state) ||
- test_bit(ST_CLOSING, &portp->state) ||
- test_bit(ST_CMDING, &portp->state) ||
- test_bit(ST_TXBUSY, &portp->state) ||
- test_bit(ST_RXING, &portp->state)) ? 0 : 1);
- }
- /*****************************************************************************/
- /*
- * Service all ports on a particular board. Assumes that the boards
- * shared memory is enabled, and that the page pointer is pointed
- * at the cdk header structure.
- */
- static inline void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
- {
- stliport_t *portp;
- unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
- unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
- unsigned char *slavep;
- int bitpos, bitat, bitsize;
- int channr, nrdevs, slavebitchange;
- bitsize = brdp->bitsize;
- nrdevs = brdp->nrdevs;
- /*
- * Check if slave wants any service. Basically we try to do as
- * little work as possible here. There are 2 levels of service
- * bits. So if there is nothing to do we bail early. We check
- * 8 service bits at a time in the inner loop, so we can bypass
- * the lot if none of them want service.
- */
- memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset),
- bitsize);
- memset(&slavebits[0], 0, bitsize);
- slavebitchange = 0;
- for (bitpos = 0; (bitpos < bitsize); bitpos++) {
- if (hostbits[bitpos] == 0)
- continue;
- channr = bitpos * 8;
- for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
- if (hostbits[bitpos] & bitat) {
- portp = brdp->ports[(channr - 1)];
- if (stli_hostcmd(brdp, portp)) {
- slavebitchange++;
- slavebits[bitpos] |= bitat;
- }
- }
- }
- }
- /*
- * If any of the ports are no longer busy then update them in the
- * slave request bits. We need to do this after, since a host port
- * service may initiate more slave requests.
- */
- if (slavebitchange) {
- hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
- slavep = ((unsigned char *) hdrp) + brdp->slaveoffset;
- for (bitpos = 0; (bitpos < bitsize); bitpos++) {
- if (slavebits[bitpos])
- slavep[bitpos] &= ~slavebits[bitpos];
- }
- }
- }
- /*****************************************************************************/
- /*
- * Driver poll routine. This routine polls the boards in use and passes
- * messages back up to host when necessary. This is actually very
- * CPU efficient, since we will always have the kernel poll clock, it
- * adds only a few cycles when idle (since board service can be
- * determined very easily), but when loaded generates no interrupts
- * (with their expensive associated context change).
- */
- static void stli_poll(unsigned long arg)
- {
- volatile cdkhdr_t *hdrp;
- stlibrd_t *brdp;
- int brdnr;
- stli_timerlist.expires = STLI_TIMEOUT;
- add_timer(&stli_timerlist);
- /*
- * Check each board and do any servicing required.
- */
- for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
- brdp = stli_brds[brdnr];
- if (brdp == (stlibrd_t *) NULL)
- continue;
- if ((brdp->state & BST_STARTED) == 0)
- continue;
- EBRDENABLE(brdp);
- hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
- if (hdrp->hostreq)
- stli_brdpoll(brdp, hdrp);
- EBRDDISABLE(brdp);
- }
- }
- /*****************************************************************************/
- /*
- * Translate the termios settings into the port setting structure of
- * the slave.
- */
- static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_mkasyport(portp=%x,pp=%x,tiosp=%d)n",
- (int) portp, (int) pp, (int) tiosp);
- #endif
- memset(pp, 0, sizeof(asyport_t));
- /*
- * Start of by setting the baud, char size, parity and stop bit info.
- */
- pp->baudout = tiosp->c_cflag & CBAUD;
- if (pp->baudout & CBAUDEX) {
- pp->baudout &= ~CBAUDEX;
- if ((pp->baudout < 1) || (pp->baudout > 4))
- tiosp->c_cflag &= ~CBAUDEX;
- else
- pp->baudout += 15;
- }
- pp->baudout = stli_baudrates[pp->baudout];
- if ((tiosp->c_cflag & CBAUD) == B38400) {
- if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
- pp->baudout = 57600;
- else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
- pp->baudout = 115200;
- else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
- pp->baudout = 230400;
- else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
- pp->baudout = 460800;
- else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
- pp->baudout = (portp->baud_base / portp->custom_divisor);
- }
- if (pp->baudout > STL_MAXBAUD)
- pp->baudout = STL_MAXBAUD;
- pp->baudin = pp->baudout;
- switch (tiosp->c_cflag & CSIZE) {
- case CS5:
- pp->csize = 5;
- break;
- case CS6:
- pp->csize = 6;
- break;
- case CS7:
- pp->csize = 7;
- break;
- default:
- pp->csize = 8;
- break;
- }
- if (tiosp->c_cflag & CSTOPB)
- pp->stopbs = PT_STOP2;
- else
- pp->stopbs = PT_STOP1;
- if (tiosp->c_cflag & PARENB) {
- if (tiosp->c_cflag & PARODD)
- pp->parity = PT_ODDPARITY;
- else
- pp->parity = PT_EVENPARITY;
- } else {
- pp->parity = PT_NOPARITY;
- }
- /*
- * Set up any flow control options enabled.
- */
- if (tiosp->c_iflag & IXON) {
- pp->flow |= F_IXON;
- if (tiosp->c_iflag & IXANY)
- pp->flow |= F_IXANY;
- }
- if (tiosp->c_cflag & CRTSCTS)
- pp->flow |= (F_RTSFLOW | F_CTSFLOW);
- pp->startin = tiosp->c_cc[VSTART];
- pp->stopin = tiosp->c_cc[VSTOP];
- pp->startout = tiosp->c_cc[VSTART];
- pp->stopout = tiosp->c_cc[VSTOP];
- /*
- * Set up the RX char marking mask with those RX error types we must
- * catch. We can get the slave to help us out a little here, it will
- * ignore parity errors and breaks for us, and mark parity errors in
- * the data stream.
- */
- if (tiosp->c_iflag & IGNPAR)
- pp->iflag |= FI_IGNRXERRS;
- if (tiosp->c_iflag & IGNBRK)
- pp->iflag |= FI_IGNBREAK;
- portp->rxmarkmsk = 0;
- if (tiosp->c_iflag & (INPCK | PARMRK))
- pp->iflag |= FI_1MARKRXERRS;
- if (tiosp->c_iflag & BRKINT)
- portp->rxmarkmsk |= BRKINT;
- /*
- * Set up clocal processing as required.
- */
- if (tiosp->c_cflag & CLOCAL)
- portp->flags &= ~ASYNC_CHECK_CD;
- else
- portp->flags |= ASYNC_CHECK_CD;
- /*
- * Transfer any persistent flags into the asyport structure.
- */
- pp->pflag = (portp->pflag & 0xffff);
- pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
- pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
- pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
- }
- /*****************************************************************************/
- /*
- * Construct a slave signals structure for setting the DTR and RTS
- * signals as specified.
- */
- static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_mkasysigs(sp=%x,dtr=%d,rts=%d)n",
- (int) sp, dtr, rts);
- #endif
- memset(sp, 0, sizeof(asysigs_t));
- if (dtr >= 0) {
- sp->signal |= SG_DTR;
- sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
- }
- if (rts >= 0) {
- sp->signal |= SG_RTS;
- sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
- }
- }
- /*****************************************************************************/
- /*
- * Convert the signals returned from the slave into a local TIOCM type
- * signals value. We keep them locally in TIOCM format.
- */
- static long stli_mktiocm(unsigned long sigvalue)
- {
- long tiocm;
- #if DEBUG
- printk(KERN_DEBUG "stli_mktiocm(sigvalue=%x)n", (int) sigvalue);
- #endif
- tiocm = 0;
- tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
- tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
- tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
- tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
- tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
- tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
- return(tiocm);
- }
- /*****************************************************************************/
- /*
- * All panels and ports actually attached have been worked out. All
- * we need to do here is set up the appropriate per port data structures.
- */
- static inline int stli_initports(stlibrd_t *brdp)
- {
- stliport_t *portp;
- int i, panelnr, panelport;
- #if DEBUG
- printk(KERN_DEBUG "stli_initports(brdp=%x)n", (int) brdp);
- #endif
- for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
- portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
- if (portp == (stliport_t *) NULL) {
- printk("STALLION: failed to allocate port structuren");
- continue;
- }
- memset(portp, 0, sizeof(stliport_t));
- portp->magic = STLI_PORTMAGIC;
- portp->portnr = i;
- portp->brdnr = brdp->brdnr;
- portp->panelnr = panelnr;
- portp->baud_base = STL_BAUDBASE;
- portp->close_delay = STL_CLOSEDELAY;
- portp->closing_wait = 30 * HZ;
- portp->tqhangup.routine = stli_dohangup;
- portp->tqhangup.data = portp;
- init_waitqueue_head(&portp->open_wait);
- init_waitqueue_head(&portp->close_wait);
- init_waitqueue_head(&portp->raw_wait);
- portp->normaltermios = stli_deftermios;
- portp->callouttermios = stli_deftermios;
- panelport++;
- if (panelport >= brdp->panels[panelnr]) {
- panelport = 0;
- panelnr++;
- }
- brdp->ports[i] = portp;
- }
- return(0);
- }
- /*****************************************************************************/
- /*
- * All the following routines are board specific hardware operations.
- */
- static void stli_ecpinit(stlibrd_t *brdp)
- {
- unsigned long memconf;
- #if DEBUG
- printk(KERN_DEBUG "stli_ecpinit(brdp=%d)n", (int) brdp);
- #endif
- outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
- udelay(10);
- outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
- udelay(100);
- memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
- outb(memconf, (brdp->iobase + ECP_ATMEMAR));
- }
- /*****************************************************************************/
- static void stli_ecpenable(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_ecpenable(brdp=%x)n", (int) brdp);
- #endif
- outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
- }
- /*****************************************************************************/
- static void stli_ecpdisable(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_ecpdisable(brdp=%x)n", (int) brdp);
- #endif
- outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
- }
- /*****************************************************************************/
- static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
- {
- void *ptr;
- unsigned char val;
- #if DEBUG
- printk(KERN_DEBUG "stli_ecpgetmemptr(brdp=%x,offset=%x)n", (int) brdp,
- (int) offset);
- #endif
- if (offset > brdp->memsize) {
- printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
- "range at line=%d(%d), brd=%dn",
- (int) offset, line, __LINE__, brdp->brdnr);
- ptr = 0;
- val = 0;
- } else {
- ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
- val = (unsigned char) (offset / ECP_ATPAGESIZE);
- }
- outb(val, (brdp->iobase + ECP_ATMEMPR));
- return(ptr);
- }
- /*****************************************************************************/
- static void stli_ecpreset(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_ecpreset(brdp=%x)n", (int) brdp);
- #endif
- outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
- udelay(10);
- outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
- udelay(500);
- }
- /*****************************************************************************/
- static void stli_ecpintr(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_ecpintr(brdp=%x)n", (int) brdp);
- #endif
- outb(0x1, brdp->iobase);
- }
- /*****************************************************************************/
- /*
- * The following set of functions act on ECP EISA boards.
- */
- static void stli_ecpeiinit(stlibrd_t *brdp)
- {
- unsigned long memconf;
- #if DEBUG
- printk(KERN_DEBUG "stli_ecpeiinit(brdp=%x)n", (int) brdp);
- #endif
- outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
- outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
- udelay(10);
- outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
- udelay(500);
- memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
- outb(memconf, (brdp->iobase + ECP_EIMEMARL));
- memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
- outb(memconf, (brdp->iobase + ECP_EIMEMARH));
- }
- /*****************************************************************************/
- static void stli_ecpeienable(stlibrd_t *brdp)
- {
- outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
- }
- /*****************************************************************************/
- static void stli_ecpeidisable(stlibrd_t *brdp)
- {
- outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
- }
- /*****************************************************************************/
- static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
- {
- void *ptr;
- unsigned char val;
- #if DEBUG
- printk(KERN_DEBUG "stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)n",
- (int) brdp, (int) offset, line);
- #endif
- if (offset > brdp->memsize) {
- printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
- "range at line=%d(%d), brd=%dn",
- (int) offset, line, __LINE__, brdp->brdnr);
- ptr = 0;
- val = 0;
- } else {
- ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
- if (offset < ECP_EIPAGESIZE)
- val = ECP_EIENABLE;
- else
- val = ECP_EIENABLE | 0x40;
- }
- outb(val, (brdp->iobase + ECP_EICONFR));
- return(ptr);
- }
- /*****************************************************************************/
- static void stli_ecpeireset(stlibrd_t *brdp)
- {
- outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
- udelay(10);
- outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
- udelay(500);
- }
- /*****************************************************************************/
- /*
- * The following set of functions act on ECP MCA boards.
- */
- static void stli_ecpmcenable(stlibrd_t *brdp)
- {
- outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
- }
- /*****************************************************************************/
- static void stli_ecpmcdisable(stlibrd_t *brdp)
- {
- outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
- }
- /*****************************************************************************/
- static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
- {
- void *ptr;
- unsigned char val;
- if (offset > brdp->memsize) {
- printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
- "range at line=%d(%d), brd=%dn",
- (int) offset, line, __LINE__, brdp->brdnr);
- ptr = 0;
- val = 0;
- } else {
- ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
- val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
- }
- outb(val, (brdp->iobase + ECP_MCCONFR));
- return(ptr);
- }
- /*****************************************************************************/
- static void stli_ecpmcreset(stlibrd_t *brdp)
- {
- outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
- udelay(10);
- outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
- udelay(500);
- }
- /*****************************************************************************/
- /*
- * The following set of functions act on ECP PCI boards.
- */
- static void stli_ecppciinit(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_ecppciinit(brdp=%x)n", (int) brdp);
- #endif
- outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
- udelay(10);
- outb(0, (brdp->iobase + ECP_PCICONFR));
- udelay(500);
- }
- /*****************************************************************************/
- static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
- {
- void *ptr;
- unsigned char val;
- #if DEBUG
- printk(KERN_DEBUG "stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)n",
- (int) brdp, (int) offset, line);
- #endif
- if (offset > brdp->memsize) {
- printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
- "range at line=%d(%d), board=%dn",
- (int) offset, line, __LINE__, brdp->brdnr);
- ptr = 0;
- val = 0;
- } else {
- ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
- val = (offset / ECP_PCIPAGESIZE) << 1;
- }
- outb(val, (brdp->iobase + ECP_PCICONFR));
- return(ptr);
- }
- /*****************************************************************************/
- static void stli_ecppcireset(stlibrd_t *brdp)
- {
- outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
- udelay(10);
- outb(0, (brdp->iobase + ECP_PCICONFR));
- udelay(500);
- }
- /*****************************************************************************/
- /*
- * The following routines act on ONboards.
- */
- static void stli_onbinit(stlibrd_t *brdp)
- {
- unsigned long memconf;
- #if DEBUG
- printk(KERN_DEBUG "stli_onbinit(brdp=%d)n", (int) brdp);
- #endif
- outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
- udelay(10);
- outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
- mdelay(1000);
- memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
- outb(memconf, (brdp->iobase + ONB_ATMEMAR));
- outb(0x1, brdp->iobase);
- mdelay(1);
- }
- /*****************************************************************************/
- static void stli_onbenable(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_onbenable(brdp=%x)n", (int) brdp);
- #endif
- outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
- }
- /*****************************************************************************/
- static void stli_onbdisable(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_onbdisable(brdp=%x)n", (int) brdp);
- #endif
- outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
- }
- /*****************************************************************************/
- static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
- {
- void *ptr;
- #if DEBUG
- printk(KERN_DEBUG "stli_onbgetmemptr(brdp=%x,offset=%x)n", (int) brdp,
- (int) offset);
- #endif
- if (offset > brdp->memsize) {
- printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
- "range at line=%d(%d), brd=%dn",
- (int) offset, line, __LINE__, brdp->brdnr);
- ptr = 0;
- } else {
- ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
- }
- return(ptr);
- }
- /*****************************************************************************/
- static void stli_onbreset(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_onbreset(brdp=%x)n", (int) brdp);
- #endif
- outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
- udelay(10);
- outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
- mdelay(1000);
- }
- /*****************************************************************************/
- /*
- * The following routines act on ONboard EISA.
- */
- static void stli_onbeinit(stlibrd_t *brdp)
- {
- unsigned long memconf;
- #if DEBUG
- printk(KERN_DEBUG "stli_onbeinit(brdp=%d)n", (int) brdp);
- #endif
- outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
- outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
- udelay(10);
- outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
- mdelay(1000);
- memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
- outb(memconf, (brdp->iobase + ONB_EIMEMARL));
- memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
- outb(memconf, (brdp->iobase + ONB_EIMEMARH));
- outb(0x1, brdp->iobase);
- mdelay(1);
- }
- /*****************************************************************************/
- static void stli_onbeenable(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_onbeenable(brdp=%x)n", (int) brdp);
- #endif
- outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
- }
- /*****************************************************************************/
- static void stli_onbedisable(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_onbedisable(brdp=%x)n", (int) brdp);
- #endif
- outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
- }
- /*****************************************************************************/
- static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
- {
- void *ptr;
- unsigned char val;
- #if DEBUG
- printk(KERN_DEBUG "stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)n",
- (int) brdp, (int) offset, line);
- #endif
- if (offset > brdp->memsize) {
- printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
- "range at line=%d(%d), brd=%dn",
- (int) offset, line, __LINE__, brdp->brdnr);
- ptr = 0;
- val = 0;
- } else {
- ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
- if (offset < ONB_EIPAGESIZE)
- val = ONB_EIENABLE;
- else
- val = ONB_EIENABLE | 0x40;
- }
- outb(val, (brdp->iobase + ONB_EICONFR));
- return(ptr);
- }
- /*****************************************************************************/
- static void stli_onbereset(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_ERR "stli_onbereset(brdp=%x)n", (int) brdp);
- #endif
- outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
- udelay(10);
- outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
- mdelay(1000);
- }
- /*****************************************************************************/
- /*
- * The following routines act on Brumby boards.
- */
- static void stli_bbyinit(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_ERR "stli_bbyinit(brdp=%d)n", (int) brdp);
- #endif
- outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
- udelay(10);
- outb(0, (brdp->iobase + BBY_ATCONFR));
- mdelay(1000);
- outb(0x1, brdp->iobase);
- mdelay(1);
- }
- /*****************************************************************************/
- static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
- {
- void *ptr;
- unsigned char val;
- #if DEBUG
- printk(KERN_ERR "stli_bbygetmemptr(brdp=%x,offset=%x)n", (int) brdp,
- (int) offset);
- #endif
- if (offset > brdp->memsize) {
- printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
- "range at line=%d(%d), brd=%dn",
- (int) offset, line, __LINE__, brdp->brdnr);
- ptr = 0;
- val = 0;
- } else {
- ptr = brdp->membase + (offset % BBY_PAGESIZE);
- val = (unsigned char) (offset / BBY_PAGESIZE);
- }
- outb(val, (brdp->iobase + BBY_ATCONFR));
- return(ptr);
- }
- /*****************************************************************************/
- static void stli_bbyreset(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_bbyreset(brdp=%x)n", (int) brdp);
- #endif
- outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
- udelay(10);
- outb(0, (brdp->iobase + BBY_ATCONFR));
- mdelay(1000);
- }
- /*****************************************************************************/
- /*
- * The following routines act on original old Stallion boards.
- */
- static void stli_stalinit(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_stalinit(brdp=%d)n", (int) brdp);
- #endif
- outb(0x1, brdp->iobase);
- mdelay(1000);
- }
- /*****************************************************************************/
- static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
- {
- void *ptr;
- #if DEBUG
- printk(KERN_DEBUG "stli_stalgetmemptr(brdp=%x,offset=%x)n", (int) brdp,
- (int) offset);
- #endif
- if (offset > brdp->memsize) {
- printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
- "range at line=%d(%d), brd=%dn",
- (int) offset, line, __LINE__, brdp->brdnr);
- ptr = 0;
- } else {
- ptr = brdp->membase + (offset % STAL_PAGESIZE);
- }
- return(ptr);
- }
- /*****************************************************************************/
- static void stli_stalreset(stlibrd_t *brdp)
- {
- volatile unsigned long *vecp;
- #if DEBUG
- printk(KERN_DEBUG "stli_stalreset(brdp=%x)n", (int) brdp);
- #endif
- vecp = (volatile unsigned long *) (brdp->membase + 0x30);
- *vecp = 0xffff0000;
- outb(0, brdp->iobase);
- mdelay(1000);
- }
- /*****************************************************************************/
- /*
- * Try to find an ECP board and initialize it. This handles only ECP
- * board types.
- */
- static inline int stli_initecp(stlibrd_t *brdp)
- {
- cdkecpsig_t sig;
- cdkecpsig_t *sigsp;
- unsigned int status, nxtid;
- char *name;
- int panelnr, nrports;
- #if DEBUG
- printk(KERN_DEBUG "stli_initecp(brdp=%x)n", (int) brdp);
- #endif
- /*
- * Do a basic sanity check on the IO and memory addresses.
- */
- if ((brdp->iobase == 0) || (brdp->memaddr == 0))
- return(-ENODEV);
- brdp->iosize = ECP_IOSIZE;
- if (check_region(brdp->iobase, brdp->iosize))
- printk(KERN_ERR "STALLION: Warning, board %d I/O address %x "
- "conflicts with another devicen",
- brdp->brdnr, brdp->iobase);
- /*
- * Based on the specific board type setup the common vars to access
- * and enable shared memory. Set all board specific information now
- * as well.
- */
- switch (brdp->brdtype) {
- case BRD_ECP:
- brdp->membase = (void *) brdp->memaddr;
- brdp->memsize = ECP_MEMSIZE;
- brdp->pagesize = ECP_ATPAGESIZE;
- brdp->init = stli_ecpinit;
- brdp->enable = stli_ecpenable;
- brdp->reenable = stli_ecpenable;
- brdp->disable = stli_ecpdisable;
- brdp->getmemptr = stli_ecpgetmemptr;
- brdp->intr = stli_ecpintr;
- brdp->reset = stli_ecpreset;
- name = "serial(EC8/64)";
- break;
- case BRD_ECPE:
- brdp->membase = (void *) brdp->memaddr;
- brdp->memsize = ECP_MEMSIZE;
- brdp->pagesize = ECP_EIPAGESIZE;
- brdp->init = stli_ecpeiinit;
- brdp->enable = stli_ecpeienable;
- brdp->reenable = stli_ecpeienable;
- brdp->disable = stli_ecpeidisable;
- brdp->getmemptr = stli_ecpeigetmemptr;
- brdp->intr = stli_ecpintr;
- brdp->reset = stli_ecpeireset;
- name = "serial(EC8/64-EI)";
- break;
- case BRD_ECPMC:
- brdp->membase = (void *) brdp->memaddr;
- brdp->memsize = ECP_MEMSIZE;
- brdp->pagesize = ECP_MCPAGESIZE;
- brdp->init = NULL;
- brdp->enable = stli_ecpmcenable;
- brdp->reenable = stli_ecpmcenable;
- brdp->disable = stli_ecpmcdisable;
- brdp->getmemptr = stli_ecpmcgetmemptr;
- brdp->intr = stli_ecpintr;
- brdp->reset = stli_ecpmcreset;
- name = "serial(EC8/64-MCA)";
- break;
- case BRD_ECPPCI:
- brdp->membase = (void *) brdp->memaddr;
- brdp->memsize = ECP_PCIMEMSIZE;
- brdp->pagesize = ECP_PCIPAGESIZE;
- brdp->init = stli_ecppciinit;
- brdp->enable = NULL;
- brdp->reenable = NULL;
- brdp->disable = NULL;
- brdp->getmemptr = stli_ecppcigetmemptr;
- brdp->intr = stli_ecpintr;
- brdp->reset = stli_ecppcireset;
- name = "serial(EC/RA-PCI)";
- break;
- default:
- return(-EINVAL);
- }
- /*
- * The per-board operations structure is all set up, so now let's go
- * and get the board operational. Firstly initialize board configuration
- * registers. Set the memory mapping info so we can get at the boards
- * shared memory.
- */
- EBRDINIT(brdp);
- brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
- if (brdp->membase == (void *) NULL)
- return(-ENOMEM);
- /*
- * Now that all specific code is set up, enable the shared memory and
- * look for the a signature area that will tell us exactly what board
- * this is, and what it is connected to it.
- */
- EBRDENABLE(brdp);
- sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
- memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
- EBRDDISABLE(brdp);
- #if 0
- printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%xn",
- __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
- (int) sig.panelid[1], (int) sig.panelid[2],
- (int) sig.panelid[3], (int) sig.panelid[4],
- (int) sig.panelid[5], (int) sig.panelid[6],
- (int) sig.panelid[7]);
- #endif
- if (sig.magic != ECP_MAGIC)
- return(-ENODEV);
- /*
- * Scan through the signature looking at the panels connected to the
- * board. Calculate the total number of ports as we go.
- */
- for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
- status = sig.panelid[nxtid];
- if ((status & ECH_PNLIDMASK) != nxtid)
- break;
- brdp->panelids[panelnr] = status;
- nrports = (status & ECH_PNL16PORT) ? 16 : 8;
- if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
- nxtid++;
- brdp->panels[panelnr] = nrports;
- brdp->nrports += nrports;
- nxtid++;
- brdp->nrpanels++;
- }
- request_region(brdp->iobase, brdp->iosize, name);
- brdp->state |= BST_FOUND;
- return(0);
- }
- /*****************************************************************************/
- /*
- * Try to find an ONboard, Brumby or Stallion board and initialize it.
- * This handles only these board types.
- */
- static inline int stli_initonb(stlibrd_t *brdp)
- {
- cdkonbsig_t sig;
- cdkonbsig_t *sigsp;
- char *name;
- int i;
- #if DEBUG
- printk(KERN_DEBUG "stli_initonb(brdp=%x)n", (int) brdp);
- #endif
- /*
- * Do a basic sanity check on the IO and memory addresses.
- */
- if ((brdp->iobase == 0) || (brdp->memaddr == 0))
- return(-ENODEV);
- brdp->iosize = ONB_IOSIZE;
- if (check_region(brdp->iobase, brdp->iosize))
- printk(KERN_ERR "STALLION: Warning, board %d I/O address %x "
- "conflicts with another devicen",
- brdp->brdnr, brdp->iobase);
- /*
- * Based on the specific board type setup the common vars to access
- * and enable shared memory. Set all board specific information now
- * as well.
- */
- switch (brdp->brdtype) {
- case BRD_ONBOARD:
- case BRD_ONBOARD32:
- case BRD_ONBOARD2:
- case BRD_ONBOARD2_32:
- case BRD_ONBOARDRS:
- brdp->membase = (void *) brdp->memaddr;
- brdp->memsize = ONB_MEMSIZE;
- brdp->pagesize = ONB_ATPAGESIZE;
- brdp->init = stli_onbinit;
- brdp->enable = stli_onbenable;
- brdp->reenable = stli_onbenable;
- brdp->disable = stli_onbdisable;
- brdp->getmemptr = stli_onbgetmemptr;
- brdp->intr = stli_ecpintr;
- brdp->reset = stli_onbreset;
- if (brdp->memaddr > 0x100000)
- brdp->enabval = ONB_MEMENABHI;
- else
- brdp->enabval = ONB_MEMENABLO;
- name = "serial(ONBoard)";
- break;
- case BRD_ONBOARDE:
- brdp->membase = (void *) brdp->memaddr;
- brdp->memsize = ONB_EIMEMSIZE;
- brdp->pagesize = ONB_EIPAGESIZE;
- brdp->init = stli_onbeinit;
- brdp->enable = stli_onbeenable;
- brdp->reenable = stli_onbeenable;
- brdp->disable = stli_onbedisable;
- brdp->getmemptr = stli_onbegetmemptr;
- brdp->intr = stli_ecpintr;
- brdp->reset = stli_onbereset;
- name = "serial(ONBoard/E)";
- break;
- case BRD_BRUMBY4:
- case BRD_BRUMBY8:
- case BRD_BRUMBY16:
- brdp->membase = (void *) brdp->memaddr;
- brdp->memsize = BBY_MEMSIZE;
- brdp->pagesize = BBY_PAGESIZE;
- brdp->init = stli_bbyinit;
- brdp->enable = NULL;
- brdp->reenable = NULL;
- brdp->disable = NULL;
- brdp->getmemptr = stli_bbygetmemptr;
- brdp->intr = stli_ecpintr;
- brdp->reset = stli_bbyreset;
- name = "serial(Brumby)";
- break;
- case BRD_STALLION:
- brdp->membase = (void *) brdp->memaddr;
- brdp->memsize = STAL_MEMSIZE;
- brdp->pagesize = STAL_PAGESIZE;
- brdp->init = stli_stalinit;
- brdp->enable = NULL;
- brdp->reenable = NULL;
- brdp->disable = NULL;
- brdp->getmemptr = stli_stalgetmemptr;
- brdp->intr = stli_ecpintr;
- brdp->reset = stli_stalreset;
- name = "serial(Stallion)";
- break;
- default:
- return(-EINVAL);
- }
- /*
- * The per-board operations structure is all set up, so now let's go
- * and get the board operational. Firstly initialize board configuration
- * registers. Set the memory mapping info so we can get at the boards
- * shared memory.
- */
- EBRDINIT(brdp);
- brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
- if (brdp->membase == (void *) NULL)
- return(-ENOMEM);
- /*
- * Now that all specific code is set up, enable the shared memory and
- * look for the a signature area that will tell us exactly what board
- * this is, and how many ports.
- */
- EBRDENABLE(brdp);
- sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
- memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
- EBRDDISABLE(brdp);
- #if 0
- printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%xn",
- __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
- sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
- #endif
- if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
- (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
- return(-ENODEV);
- /*
- * Scan through the signature alive mask and calculate how many ports
- * there are on this board.
- */
- brdp->nrpanels = 1;
- if (sig.amask1) {
- brdp->nrports = 32;
- } else {
- for (i = 0; (i < 16); i++) {
- if (((sig.amask0 << i) & 0x8000) == 0)
- break;
- }
- brdp->nrports = i;
- }
- brdp->panels[0] = brdp->nrports;
- request_region(brdp->iobase, brdp->iosize, name);
- brdp->state |= BST_FOUND;
- return(0);
- }
- /*****************************************************************************/
- /*
- * Start up a running board. This routine is only called after the
- * code has been down loaded to the board and is operational. It will
- * read in the memory map, and get the show on the road...
- */
- static int stli_startbrd(stlibrd_t *brdp)
- {
- volatile cdkhdr_t *hdrp;
- volatile cdkmem_t *memp;
- volatile cdkasy_t *ap;
- unsigned long flags;
- stliport_t *portp;
- int portnr, nrdevs, i, rc;
- #if DEBUG
- printk(KERN_DEBUG "stli_startbrd(brdp=%x)n", (int) brdp);
- #endif
- rc = 0;
- save_flags(flags);
- cli();
- EBRDENABLE(brdp);
- hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
- nrdevs = hdrp->nrdevs;
- #if 0
- printk("%s(%d): CDK version %d.%d.%d --> "
- "nrdevs=%d memp=%x hostp=%x slavep=%xn",
- __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
- hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
- (int) hdrp->slavep);
- #endif
- if (nrdevs < (brdp->nrports + 1)) {
- printk(KERN_ERR "STALLION: slave failed to allocate memory for "
- "all devices, devices=%dn", nrdevs);
- brdp->nrports = nrdevs - 1;
- }
- brdp->nrdevs = nrdevs;
- brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
- brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
- brdp->bitsize = (nrdevs + 7) / 8;
- memp = (volatile cdkmem_t *) hdrp->memp;
- if (((unsigned long) memp) > brdp->memsize) {
- printk(KERN_ERR "STALLION: corrupted shared memory region?n");
- rc = -EIO;
- goto stli_donestartup;
- }
- memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
- if (memp->dtype != TYP_ASYNCTRL) {
- printk(KERN_ERR "STALLION: no slave control device foundn");
- goto stli_donestartup;
- }
- memp++;
- /*
- * Cycle through memory allocation of each port. We are guaranteed to
- * have all ports inside the first page of slave window, so no need to
- * change pages while reading memory map.
- */
- for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
- if (memp->dtype != TYP_ASYNC)
- break;
- portp = brdp->ports[portnr];
- if (portp == (stliport_t *) NULL)
- break;
- portp->devnr = i;
- portp->addr = memp->offset;
- portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
- portp->portidx = (unsigned char) (i / 8);
- portp->portbit = (unsigned char) (0x1 << (i % 8));
- }
- hdrp->slavereq = 0xff;
- /*
- * For each port setup a local copy of the RX and TX buffer offsets
- * and sizes. We do this separate from the above, because we need to
- * move the shared memory page...
- */
- for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
- portp = brdp->ports[portnr];
- if (portp == (stliport_t *) NULL)
- break;
- if (portp->addr == 0)
- break;
- ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
- if (ap != (volatile cdkasy_t *) NULL) {
- portp->rxsize = ap->rxq.size;
- portp->txsize = ap->txq.size;
- portp->rxoffset = ap->rxq.offset;
- portp->txoffset = ap->txq.offset;
- }
- }
- stli_donestartup:
- EBRDDISABLE(brdp);
- restore_flags(flags);
- if (rc == 0)
- brdp->state |= BST_STARTED;
- if (! stli_timeron) {
- stli_timeron++;
- stli_timerlist.expires = STLI_TIMEOUT;
- add_timer(&stli_timerlist);
- }
- return(rc);
- }
- /*****************************************************************************/
- /*
- * Probe and initialize the specified board.
- */
- static int __init stli_brdinit(stlibrd_t *brdp)
- {
- #if DEBUG
- printk(KERN_DEBUG "stli_brdinit(brdp=%x)n", (int) brdp);
- #endif
- stli_brds[brdp->brdnr] = brdp;
- switch (brdp->brdtype) {
- case BRD_ECP:
- case BRD_ECPE:
- case BRD_ECPMC:
- case BRD_ECPPCI:
- stli_initecp(brdp);
- break;
- case BRD_ONBOARD:
- case BRD_ONBOARDE:
- case BRD_ONBOARD2:
- case BRD_ONBOARD32:
- case BRD_ONBOARD2_32:
- case BRD_ONBOARDRS:
- case BRD_BRUMBY4:
- case BRD_BRUMBY8:
- case BRD_BRUMBY16:
- case BRD_STALLION:
- stli_initonb(brdp);
- break;
- case BRD_EASYIO:
- case BRD_ECH:
- case BRD_ECHMC:
- case BRD_ECHPCI:
- printk(KERN_ERR "STALLION: %s board type not supported in "
- "this drivern", stli_brdnames[brdp->brdtype]);
- return(ENODEV);
- default:
- printk(KERN_ERR "STALLION: board=%d is unknown board "
- "type=%dn", brdp->brdnr, brdp->brdtype);
- return(ENODEV);
- }
- if ((brdp->state & BST_FOUND) == 0) {
- printk(KERN_ERR "STALLION: %s board not found, board=%d "
- "io=%x mem=%xn",
- stli_brdnames[brdp->brdtype], brdp->brdnr,
- brdp->iobase, (int) brdp->memaddr);
- return(ENODEV);
- }
- stli_initports(brdp);
- printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
- "nrpanels=%d nrports=%dn", stli_brdnames[brdp->brdtype],
- brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
- brdp->nrpanels, brdp->nrports);
- return(0);
- }
- /*****************************************************************************/
- /*
- * Probe around trying to find where the EISA boards shared memory
- * might be. This is a bit if hack, but it is the best we can do.
- */
- static inline int stli_eisamemprobe(stlibrd_t *brdp)
- {
- cdkecpsig_t ecpsig, *ecpsigp;
- cdkonbsig_t onbsig, *onbsigp;
- int i, foundit;
- #if DEBUG
- printk(KERN_DEBUG "stli_eisamemprobe(brdp=%x)n", (int) brdp);
- #endif
- /*
- * First up we reset the board, to get it into a known state. There
- * is only 2 board types here we need to worry about. Don;t use the
- * standard board init routine here, it programs up the shared
- * memory address, and we don't know it yet...
- */
- if (brdp->brdtype == BRD_ECPE) {
- outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
- outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
- udelay(10);
- outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
- udelay(500);
- stli_ecpeienable(brdp);
- } else if (brdp->brdtype == BRD_ONBOARDE) {
- outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
- outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
- udelay(10);
- outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
- mdelay(100);
- outb(0x1, brdp->iobase);
- mdelay(1);
- stli_onbeenable(brdp);
- } else {
- return(-ENODEV);
- }
- foundit = 0;
- brdp->memsize = ECP_MEMSIZE;
- /*
- * Board shared memory is enabled, so now we have a poke around and
- * see if we can find it.
- */
- for (i = 0; (i < stli_eisamempsize); i++) {
- brdp->memaddr = stli_eisamemprobeaddrs[i];
- brdp->membase = (void *) brdp->memaddr;
- brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
- if (brdp->membase == (void *) NULL)
- continue;
- if (brdp->brdtype == BRD_ECPE) {
- ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp,
- CDK_SIGADDR, __LINE__);
- memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
- if (ecpsig.magic == ECP_MAGIC)
- foundit = 1;
- } else {
- onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp,
- CDK_SIGADDR, __LINE__);
- memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
- if ((onbsig.magic0 == ONB_MAGIC0) &&
- (onbsig.magic1 == ONB_MAGIC1) &&
- (onbsig.magic2 == ONB_MAGIC2) &&
- (onbsig.magic3 == ONB_MAGIC3))
- foundit = 1;
- }
- iounmap(brdp->membase);
- if (foundit)
- break;
- }
- /*
- * Regardless of whether we found the shared memory or not we must
- * disable the region. After that return success or failure.
- */
- if (brdp->brdtype == BRD_ECPE)
- stli_ecpeidisable(brdp);
- else
- stli_onbedisable(brdp);
- if (! foundit) {
- brdp->memaddr = 0;
- brdp->membase = 0;
- printk(KERN_ERR "STALLION: failed to probe shared memory "
- "region for %s in EISA slot=%dn",
- stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
- return(-ENODEV);
- }
- return(0);
- }
- /*****************************************************************************/
- /*
- * Probe around and try to find any EISA boards in system. The biggest
- * problem here is finding out what memory address is associated with
- * an EISA board after it is found. The registers of the ECPE and
- * ONboardE are not readable - so we can't read them from there. We
- * don't have access to the EISA CMOS (or EISA BIOS) so we don't
- * actually have any way to find out the real value. The best we can
- * do is go probing around in the usual places hoping we can find it.
- */
- static inline int stli_findeisabrds()
- {
- stlibrd_t *brdp;
- unsigned int iobase, eid;
- int i;
- #if DEBUG
- printk(KERN_DEBUG "stli_findeisabrds()n");
- #endif
- /*
- * Firstly check if this is an EISA system. Do this by probing for
- * the system board EISA ID. If this is not an EISA system then
- * don't bother going any further!
- */
- outb(0xff, 0xc80);
- if (inb(0xc80) == 0xff)
- return(0);
- /*
- * Looks like an EISA system, so go searching for EISA boards.
- */
- for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
- outb(0xff, (iobase + 0xc80));
- eid = inb(iobase + 0xc80);
- eid |= inb(iobase + 0xc81) << 8;
- if (eid != STL_EISAID)
- continue;
- /*
- * We have found a board. Need to check if this board was
- * statically configured already (just in case!).
- */
- for (i = 0; (i < STL_MAXBRDS); i++) {
- brdp = stli_brds[i];
- if (brdp == (stlibrd_t *) NULL)
- continue;
- if (brdp->iobase == iobase)
- break;
- }
- if (i < STL_MAXBRDS)
- continue;
- /*
- * We have found a Stallion board and it is not configured already.
- * Allocate a board structure and initialize it.
- */
- if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
- return(-ENOMEM);
- if ((brdp->brdnr = stli_getbrdnr()) < 0)
- return(-ENOMEM);
- eid = inb(iobase + 0xc82);
- if (eid == ECP_EISAID)
- brdp->brdtype = BRD_ECPE;
- else if (eid == ONB_EISAID)
- brdp->brdtype = BRD_ONBOARDE;
- else
- brdp->brdtype = BRD_UNKNOWN;
- brdp->iobase = iobase;
- outb(0x1, (iobase + 0xc84));
- if (stli_eisamemprobe(brdp))
- outb(0, (iobase + 0xc84));
- stli_brdinit(brdp);
- }
- return(0);
- }
- /*****************************************************************************/
- /*
- * Find the next available board number that is free.
- */
- static inline int stli_getbrdnr()
- {
- int i;
- for (i = 0; (i < STL_MAXBRDS); i++) {
- if (stli_brds[i] == (stlibrd_t *) NULL) {
- if (i >= stli_nrbrds)
- stli_nrbrds = i + 1;
- return(i);
- }
- }
- return(-1);
- }
- /*****************************************************************************/
- #ifdef CONFIG_PCI
- /*
- * We have a Stallion board. Allocate a board structure and
- * initialize it. Read its IO and MEMORY resources from PCI
- * configuration space.
- */
- static inline int stli_initpcibrd(int brdtype, struct pci_dev *devp)
- {
- stlibrd_t *brdp;
- #if DEBUG
- printk(KERN_DEBUG "stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)n",
- brdtype, dev->bus->number, dev->devfn);
- #endif
- if (pci_enable_device(devp))
- return(-EIO);
- if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
- return(-ENOMEM);
- if ((brdp->brdnr = stli_getbrdnr()) < 0) {
- printk(KERN_INFO "STALLION: too many boards found, "
- "maximum supported %dn", STL_MAXBRDS);
- return(0);
- }
- brdp->brdtype = brdtype;
- #if DEBUG
- printk(KERN_DEBUG "%s(%d): BAR[]=%lx,%lx,%lx,%lxn", __FILE__, __LINE__,
- pci_resource_start(devp, 0),
- pci_resource_start(devp, 1),
- pci_resource_start(devp, 2),
- pci_resource_start(devp, 3));
- #endif
- /*
- * We have all resources from the board, so lets setup the actual
- * board structure now.
- */
- brdp->iobase = pci_resource_start(devp, 3);
- brdp->memaddr = pci_resource_start(devp, 2);
- stli_brdinit(brdp);
- return(0);
- }
- /*****************************************************************************/
- /*
- * Find all Stallion PCI boards that might be installed. Initialize each
- * one as it is found.
- */
- static inline int stli_findpcibrds()
- {
- struct pci_dev *dev = NULL;
- int rc;
- #if DEBUG
- printk("stli_findpcibrds()n");
- #endif
- if (! pci_present())
- return(0);
- while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION,
- PCI_DEVICE_ID_ECRA, dev))) {
- if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
- return(rc);
- }
- return(0);
- }
- #endif
- /*****************************************************************************/
- /*
- * Allocate a new board structure. Fill out the basic info in it.
- */
- static stlibrd_t *stli_allocbrd()
- {
- stlibrd_t *brdp;
- brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
- if (brdp == (stlibrd_t *) NULL) {
- printk(KERN_ERR "STALLION: failed to allocate memory "
- "(size=%d)n", sizeof(stlibrd_t));
- return((stlibrd_t *) NULL);
- }
- memset(brdp, 0, sizeof(stlibrd_t));
- brdp->magic = STLI_BOARDMAGIC;
- return(brdp);
- }
- /*****************************************************************************/
- /*
- * Scan through all the boards in the configuration and see what we
- * can find.
- */
- static inline int stli_initbrds()
- {
- stlibrd_t *brdp, *nxtbrdp;
- stlconf_t *confp;
- int i, j;
- #if DEBUG
- printk(KERN_DEBUG "stli_initbrds()n");
- #endif
- if (stli_nrbrds > STL_MAXBRDS) {
- printk(KERN_INFO "STALLION: too many boards in configuration "
- "table, truncating to %dn", STL_MAXBRDS);
- stli_nrbrds = STL_MAXBRDS;
- }
- /*
- * Firstly scan the list of static boards configured. Allocate
- * resources and initialize the boards as found. If this is a
- * module then let the module args override static configuration.
- */
- for (i = 0; (i < stli_nrbrds); i++) {
- confp = &stli_brdconf[i];
- #ifdef MODULE
- stli_parsebrd(confp, stli_brdsp[i]);
- #endif
- if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
- return(-ENOMEM);
- brdp->brdnr = i;
- brdp->brdtype = confp->brdtype;
- brdp->iobase = confp->ioaddr1;
- brdp->memaddr = confp->memaddr;
- stli_brdinit(brdp);
- }
- /*
- * Static configuration table done, so now use dynamic methods to
- * see if any more boards should be configured.
- */
- #ifdef MODULE
- stli_argbrds();
- #endif
- if (stli_eisaprobe)
- stli_findeisabrds();
- #ifdef CONFIG_PCI
- stli_findpcibrds();
- #endif
- /*
- * All found boards are initialized. Now for a little optimization, if
- * no boards are sharing the "shared memory" regions then we can just
- * leave them all enabled. This is in fact the usual case.
- */
- stli_shared = 0;
- if (stli_nrbrds > 1) {
- for (i = 0; (i < stli_nrbrds); i++) {
- brdp = stli_brds[i];
- if (brdp == (stlibrd_t *) NULL)
- continue;
- for (j = i + 1; (j < stli_nrbrds); j++) {
- nxtbrdp = stli_brds[j];
- if (nxtbrdp == (stlibrd_t *) NULL)
- continue;
- if ((brdp->membase >= nxtbrdp->membase) &&
- (brdp->membase <= (nxtbrdp->membase +
- nxtbrdp->memsize - 1))) {
- stli_shared++;
- break;
- }
- }
- }
- }
- if (stli_shared == 0) {
- for (i = 0; (i < stli_nrbrds); i++) {
- brdp = stli_brds[i];
- if (brdp == (stlibrd_t *) NULL)
- continue;
- if (brdp->state & BST_FOUND) {
- EBRDENABLE(brdp);
- brdp->enable = NULL;
- brdp->disable = NULL;
- }
- }
- }
- return(0);
- }
- /*****************************************************************************/
- /*
- * Code to handle an "staliomem" read operation. This device is the
- * contents of the board shared memory. It is used for down loading
- * the slave image (and debugging :-)
- */
- static ssize_t stli_memread(struct file *fp, char *buf, size_t count, loff_t *offp)
- {
- unsigned long flags;
- void *memptr;
- stlibrd_t *brdp;
- int brdnr, size, n;
- #if DEBUG
- printk(KERN_DEBUG "stli_memread(fp=%x,buf=%x,count=%x,offp=%x)n",
- (int) fp, (int) buf, count, (int) offp);
- #endif
- brdnr = MINOR(fp->f_dentry->d_inode->i_rdev);
- if (brdnr >= stli_nrbrds)
- return(-ENODEV);
- brdp = stli_brds[brdnr];
- if (brdp == (stlibrd_t *) NULL)
- return(-ENODEV);
- if (brdp->state == 0)
- return(-ENODEV);
- if (fp->f_pos >= brdp->memsize)
- return(0);
- size = MIN(count, (brdp->memsize - fp->f_pos));
- save_flags(flags);
- cli();
- EBRDENABLE(brdp);
- while (size > 0) {
- memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
- n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
- if (copy_to_user(buf, memptr, n)) {
- count = -EFAULT;
- goto out;
- }
- fp->f_pos += n;
- buf += n;
- size -= n;
- }
- out:
- EBRDDISABLE(brdp);
- restore_flags(flags);
- return(count);
- }
- /*****************************************************************************/
- /*
- * Code to handle an "staliomem" write operation. This device is the
- * contents of the board shared memory. It is used for down loading
- * the slave image (and debugging :-)
- */
- static ssize_t stli_memwrite(struct file *fp, const char *buf, size_t count, loff_t *offp)
- {
- unsigned long flags;
- void *memptr;
- stlibrd_t *brdp;
- char *chbuf;
- int brdnr, size, n;
- #if DEBUG
- printk(KERN_DEBUG "stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)n",
- (int) fp, (int) buf, count, (int) offp);
- #endif
- brdnr = MINOR(fp->f_dentry->d_inode->i_rdev);
- if (brdnr >= stli_nrbrds)
- return(-ENODEV);
- brdp = stli_brds[brdnr];
- if (brdp == (stlibrd_t *) NULL)
- return(-ENODEV);
- if (brdp->state == 0)
- return(-ENODEV);
- if (fp->f_pos >= brdp->memsize)
- return(0);
- chbuf = (char *) buf;
- size = MIN(count, (brdp->memsize - fp->f_pos));
- save_flags(flags);
- cli();
- EBRDENABLE(brdp);
- while (size > 0) {
- memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
- n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
- if (copy_from_user(memptr, chbuf, n)) {
- count = -EFAULT;
- goto out;
- }
- fp->f_pos += n;
- chbuf += n;
- size -= n;
- }
- out:
- EBRDDISABLE(brdp);
- restore_flags(flags);
- return(count);
- }
- /*****************************************************************************/
- /*
- * Return the board stats structure to user app.
- */
- static int stli_getbrdstats(combrd_t *bp)
- {
- stlibrd_t *brdp;
- int i;
- if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
- return -EFAULT;
- if (stli_brdstats.brd >= STL_MAXBRDS)
- return(-ENODEV);
- brdp = stli_brds[stli_brdstats.brd];
- if (brdp == (stlibrd_t *) NULL)
- return(-ENODEV);
- memset(&stli_brdstats, 0, sizeof(combrd_t));
- stli_brdstats.brd = brdp->brdnr;
- stli_brdstats.type = brdp->brdtype;
- stli_brdstats.hwid = 0;
- stli_brdstats.state = brdp->state;
- stli_brdstats.ioaddr = brdp->iobase;
- stli_brdstats.memaddr = brdp->memaddr;
- stli_brdstats.nrpanels = brdp->nrpanels;
- stli_brdstats.nrports = brdp->nrports;
- for (i = 0; (i < brdp->nrpanels); i++) {
- stli_brdstats.panels[i].panel = i;
- stli_brdstats.panels[i].hwid = brdp->panelids[i];
- stli_brdstats.panels[i].nrports = brdp->panels[i];
- }
- if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
- return -EFAULT;
- return(0);
- }
- /*****************************************************************************/
- /*
- * Resolve the referenced port number into a port struct pointer.
- */
- static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
- {
- stlibrd_t *brdp;
- int i;
- if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
- return((stliport_t *) NULL);
- brdp = stli_brds[brdnr];
- if (brdp == (stlibrd_t *) NULL)
- return((stliport_t *) NULL);
- for (i = 0; (i < panelnr); i++)
- portnr += brdp->panels[i];
- if ((portnr < 0) || (portnr >= brdp->nrports))
- return((stliport_t *) NULL);
- return(brdp->ports[portnr]);
- }
- /*****************************************************************************/
- /*
- * Return the port stats structure to user app. A NULL port struct
- * pointer passed in means that we need to find out from the app
- * what port to get stats for (used through board control device).
- */
- static int stli_portcmdstats(stliport_t *portp)
- {
- unsigned long flags;
- stlibrd_t *brdp;
- int rc;
- memset(&stli_comstats, 0, sizeof(comstats_t));
- if (portp == (stliport_t *) NULL)
- return(-ENODEV);
- brdp = stli_brds[portp->brdnr];
- if (brdp == (stlibrd_t *) NULL)
- return(-ENODEV);
- if (brdp->state & BST_STARTED) {
- if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
- &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
- return(rc);
- } else {
- memset(&stli_cdkstats, 0, sizeof(asystats_t));
- }
- stli_comstats.brd = portp->brdnr;
- stli_comstats.panel = portp->panelnr;
- stli_comstats.port = portp->portnr;
- stli_comstats.state = portp->state;
- stli_comstats.flags = portp->flags;
- save_flags(flags);
- cli();
- if (portp->tty != (struct tty_struct *) NULL) {
- if (portp->tty->driver_data == portp) {
- stli_comstats.ttystate = portp->tty->flags;
- stli_comstats.rxbuffered = portp->tty->flip.count;
- if (portp->tty->termios != (struct termios *) NULL) {
- stli_comstats.cflags = portp->tty->termios->c_cflag;
- stli_comstats.iflags = portp->tty->termios->c_iflag;
- stli_comstats.oflags = portp->tty->termios->c_oflag;
- stli_comstats.lflags = portp->tty->termios->c_lflag;
- }
- }
- }
- restore_flags(flags);
- stli_comstats.txtotal = stli_cdkstats.txchars;
- stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
- stli_comstats.txbuffered = stli_cdkstats.txringq;
- stli_comstats.rxbuffered += stli_cdkstats.rxringq;
- stli_comstats.rxoverrun = stli_cdkstats.overruns;
- stli_comstats.rxparity = stli_cdkstats.parity;
- stli_comstats.rxframing = stli_cdkstats.framing;
- stli_comstats.rxlost = stli_cdkstats.ringover;
- stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
- stli_comstats.txbreaks = stli_cdkstats.txbreaks;
- stli_comstats.txxon = stli_cdkstats.txstart;
- stli_comstats.txxoff = stli_cdkstats.txstop;
- stli_comstats.rxxon = stli_cdkstats.rxstart;
- stli_comstats.rxxoff = stli_cdkstats.rxstop;
- stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
- stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
- stli_comstats.modem = stli_cdkstats.dcdcnt;
- stli_comstats.hwid = stli_cdkstats.hwid;
- stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
- return(0);
- }
- /*****************************************************************************/
- /*
- * Return the port stats structure to user app. A NULL port struct
- * pointer passed in means that we need to find out from the app
- * what port to get stats for (used through board control device).
- */
- static int stli_getportstats(stliport_t *portp, comstats_t *cp)
- {
- stlibrd_t *brdp;
- int rc;
- if (portp == (stliport_t *) NULL) {
- if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
- return -EFAULT;
- portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
- stli_comstats.port);
- if (portp == (stliport_t *) NULL)
- return(-ENODEV);
- }
- brdp = stli_brds[portp->brdnr];
- if (brdp == (stlibrd_t *) NULL)
- return(-ENODEV);
- if ((rc = stli_portcmdstats(portp)) < 0)
- return(rc);
- return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
- -EFAULT : 0;
- }
- /*****************************************************************************/
- /*
- * Clear the port stats structure. We also return it zeroed out...
- */
- static int stli_clrportstats(stliport_t *portp, comstats_t *cp)
- {
- stlibrd_t *brdp;
- int rc;
- if (portp == (stliport_t *) NULL) {
- if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
- return -EFAULT;
- portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
- stli_comstats.port);
- if (portp == (stliport_t *) NULL)
- return(-ENODEV);
- }
- brdp = stli_brds[portp->brdnr];
- if (brdp == (stlibrd_t *) NULL)
- return(-ENODEV);
- if (brdp->state & BST_STARTED) {
- if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, 0, 0, 0)) < 0)
- return(rc);
- }
- memset(&stli_comstats, 0, sizeof(comstats_t));
- stli_comstats.brd = portp->brdnr;
- stli_comstats.panel = portp->panelnr;
- stli_comstats.port = portp->portnr;
- if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
- return -EFAULT;
- return(0);
- }
- /*****************************************************************************/
- /*
- * Return the entire driver ports structure to a user app.
- */
- static int stli_getportstruct(unsigned long arg)
- {
- stliport_t *portp;
- if (copy_from_user(&stli_dummyport, (void *)arg, sizeof(stliport_t)))
- return -EFAULT;
- portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
- stli_dummyport.portnr);
- if (portp == (stliport_t *) NULL)
- return(-ENODEV);
- if (copy_to_user((void *) arg, portp, sizeof(stliport_t)))
- return -EFAULT;
- return(0);
- }
- /*****************************************************************************/
- /*
- * Return the entire driver board structure to a user app.
- */
- static int stli_getbrdstruct(unsigned long arg)
- {
- stlibrd_t *brdp;
- if (copy_from_user(&stli_dummybrd, (void *)arg, sizeof(stlibrd_t)))
- return -EFAULT;
- if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
- return(-ENODEV);
- brdp = stli_brds[stli_dummybrd.brdnr];
- if (brdp == (stlibrd_t *) NULL)
- return(-ENODEV);
- if (copy_to_user((void *) arg, brdp, sizeof(stlibrd_t)))
- return -EFAULT;
- return(0);
- }
- /*****************************************************************************/
- /*
- * The "staliomem" device is also required to do some special operations on
- * the board. We need to be able to send an interrupt to the board,
- * reset it, and start/stop it.
- */
- static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
- {
- stlibrd_t *brdp;
- int brdnr, rc, done;
- #if DEBUG
- printk(KERN_DEBUG "stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)n",
- (int) ip, (int) fp, cmd, (int) arg);
- #endif
- /*
- * First up handle the board independent ioctls.
- */
- done = 0;
- rc = 0;
- switch (cmd) {
- case COM_GETPORTSTATS:
- rc = stli_getportstats((stliport_t *)NULL, (comstats_t *)arg);
- done++;
- break;
- case COM_CLRPORTSTATS:
- rc = stli_clrportstats((stliport_t *)NULL, (comstats_t *)arg);
- done++;
- break;
- case COM_GETBRDSTATS:
- rc = stli_getbrdstats((combrd_t *) arg);
- done++;
- break;
- case COM_READPORT:
- rc = stli_getportstruct(arg);
- done++;
- break;
- case COM_READBOARD:
- rc = stli_getbrdstruct(arg);
- done++;
- break;
- }
- if (done)
- return(rc);
- /*
- * Now handle the board specific ioctls. These all depend on the
- * minor number of the device they were called from.
- */
- brdnr = MINOR(ip->i_rdev);
- if (brdnr >= STL_MAXBRDS)
- return(-ENODEV);
- brdp = stli_brds[brdnr];
- if (brdp == (stlibrd_t *) NULL)
- return(-ENODEV);
- if (brdp->state == 0)
- return(-ENODEV);
- switch (cmd) {
- case STL_BINTR:
- EBRDINTR(brdp);
- break;
- case STL_BSTART:
- rc = stli_startbrd(brdp);
- break;
- case STL_BSTOP:
- brdp->state &= ~BST_STARTED;
- break;
- case STL_BRESET:
- brdp->state &= ~BST_STARTED;
- EBRDRESET(brdp);
- if (stli_shared == 0) {
- if (brdp->reenable != NULL)
- (* brdp->reenable)(brdp);
- }
- break;
- default:
- rc = -ENOIOCTLCMD;
- break;
- }
- return(rc);
- }
- /*****************************************************************************/
- int __init stli_init(void)
- {
- printk(KERN_INFO "%s: version %sn", stli_drvtitle, stli_drvversion);
- stli_initbrds();
- /*
- * Allocate a temporary write buffer.
- */
- stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
- if (stli_tmpwritebuf == (char *) NULL)
- printk(KERN_ERR "STALLION: failed to allocate memory "
- "(size=%d)n", STLI_TXBUFSIZE);
- stli_txcookbuf = stli_memalloc(STLI_TXBUFSIZE);
- if (stli_txcookbuf == (char *) NULL)
- printk(KERN_ERR "STALLION: failed to allocate memory "
- "(size=%d)n", STLI_TXBUFSIZE);
- /*
- * Set up a character driver for the shared memory region. We need this
- * to down load the slave code image. Also it is a useful debugging tool.
- */
- if (devfs_register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
- printk(KERN_ERR "STALLION: failed to register serial memory "
- "devicen");
- devfs_handle = devfs_mk_dir (NULL, "staliomem", NULL);
- devfs_register_series (devfs_handle, "%u", 4, DEVFS_FL_DEFAULT,
- STL_SIOMEMMAJOR, 0,
- S_IFCHR | S_IRUSR | S_IWUSR,
- &stli_fsiomem, NULL);
- /*
- * Set up the tty driver structure and register us as a driver.
- * Also setup the callout tty device.
- */
- memset(&stli_serial, 0, sizeof(struct tty_driver));
- stli_serial.magic = TTY_DRIVER_MAGIC;
- stli_serial.driver_name = stli_drvname;
- stli_serial.name = stli_serialname;
- stli_serial.major = STL_SERIALMAJOR;
- stli_serial.minor_start = 0;
- stli_serial.num = STL_MAXBRDS * STL_MAXPORTS;
- stli_serial.type = TTY_DRIVER_TYPE_SERIAL;
- stli_serial.subtype = STL_DRVTYPSERIAL;
- stli_serial.init_termios = stli_deftermios;
- stli_serial.flags = TTY_DRIVER_REAL_RAW;
- stli_serial.refcount = &stli_refcount;
- stli_serial.table = stli_ttys;
- stli_serial.termios = stli_termios;
- stli_serial.termios_locked = stli_termioslocked;
-
- stli_serial.open = stli_open;
- stli_serial.close = stli_close;
- stli_serial.write = stli_write;
- stli_serial.put_char = stli_putchar;
- stli_serial.flush_chars = stli_flushchars;
- stli_serial.write_room = stli_writeroom;
- stli_serial.chars_in_buffer = stli_charsinbuffer;
- stli_serial.ioctl = stli_ioctl;
- stli_serial.set_termios = stli_settermios;
- stli_serial.throttle = stli_throttle;
- stli_serial.unthrottle = stli_unthrottle;
- stli_serial.stop = stli_stop;
- stli_serial.start = stli_start;
- stli_serial.hangup = stli_hangup;
- stli_serial.flush_buffer = stli_flushbuffer;
- stli_serial.break_ctl = stli_breakctl;
- stli_serial.wait_until_sent = stli_waituntilsent;
- stli_serial.send_xchar = stli_sendxchar;
- stli_serial.read_proc = stli_readproc;
- stli_callout = stli_serial;
- stli_callout.name = stli_calloutname;
- stli_callout.major = STL_CALLOUTMAJOR;
- stli_callout.subtype = STL_DRVTYPCALLOUT;
- stli_callout.read_proc = 0;
- if (tty_register_driver(&stli_serial))
- printk(KERN_ERR "STALLION: failed to register serial drivern");
- if (tty_register_driver(&stli_callout))
- printk(KERN_ERR "STALLION: failed to register callout drivern");
- return(0);
- }
- /*****************************************************************************/