/* apelib.c */ /* This module contains some utility function for configuring */ /* and controlling the APE 25 */ typedef int spinlock_t; typedef int wait_queue_head_t; struct sk_buff_head { int x; }; #include #include #include "atmdd.h" int iobuf[20]; /**/ /* Return LC number */ int ape_lcid( int apefd, int vci) { int lciloc; lciloc = LCI_TABLE_BASE + ((vci & VCI_MASK) << 1); iobuf[0] = 0x08000000 + lciloc; ioctl(apefd, AIO_RDVSAP, iobuf); return(iobuf[1]); } /**/ /* Configure a transmission queue */ int ape_tmqcfg( int apefd, /* Open device handle. */ int tmqid, /* Queue # ... 0,1,.. 7 */ int peak_bps, /* Set peak BPS for the queue */ int enable, /* 1 => enable 0 => disable */ int priority) /* 1 => high priority 0 => low */ { float clk_divf; int clk_div; int regid; short mask; clk_divf = 1.0 * 424 * (32 * 1024 * 1024 / (2.0 * peak_bps)); clk_div = clk_divf + 0.5; printf("Using clock divider %d \n", clk_div); regid = TMQ_CFG_0 + 2 * tmqid; iobuf[0] = regid; iobuf[1] = clk_div; ioctl(apefd, AIO_WTCREG, iobuf); ioctl(apefd, AIO_RDCREG, iobuf); printf("Value of control reg %x is %x \n", iobuf[0], iobuf[1]); iobuf[0] = ACONFIG_REG; ioctl(apefd, AIO_RDCREG, iobuf); mask = 1 << (8 + tmqid); if (priority) { iobuf[1] |= mask; } else { iobuf[1] &= ~mask; } mask = 1 << (tmqid); if (enable) { iobuf[1] |= mask; } else { iobuf[1] &= ~mask; } ioctl(apefd, AIO_WTCREG, iobuf); ioctl(apefd, AIO_RDCREG, iobuf); printf("Value of control reg %x is %x \n", iobuf[0], iobuf[1]); } /**/ int ape_lccfg( int apefd, /* Open device handle. */ int vci, /* Queue # ... 0,1,.. 7 */ int psr, /* Set peak to sust ratio. */ int climit) /* Set cell credit limit. */ { int offset; struct lc5type lc5; unsigned char *loc1; unsigned char *loc2; int lcnum; int bts; lcnum = ape_lcid(apefd, vci); printf("Configuring lc number %d \n", lcnum); if (lcnum == 0) return(-1); offset = lcnum << 7; offset += 0x24; iobuf[0] = 0x08000000 + offset; ioctl(apefd, AIO_RDVSAP, iobuf); printf("Old value of CRD/PSR is %04x \n", iobuf[1]); if (psr == 0) psr = 1; if (psr > 255) psr = 255; iobuf[1] = iobuf[1] & 0xff00; iobuf[1] |= psr; ioctl(apefd, AIO_WTVSAP, iobuf); ioctl(apefd, AIO_RDVSAP, iobuf); printf("New value of CRD/PSR is %04x \n", iobuf[1]); offset += 2; iobuf[0] = 0x08000000 + offset; ioctl(apefd, AIO_RDVSAP, iobuf); printf("Old value of BTS is %04x \n", iobuf[1]); bts = psr * climit / 8; if (bts == 0) bts = 1; if (bts > 0xffff) bts = 0xffff; iobuf[1] = bts; ioctl(apefd, AIO_WTVSAP, iobuf); ioctl(apefd, AIO_RDVSAP, iobuf); printf("New value of BTS is %04x \n", iobuf[1]); } /**/ int ape_settmq( int apefd, /* Open device handle. */ int vci, /* VC */ int tmq) /* Desired TMQ */ { int offset; struct lc5type lc5; unsigned char *loc1; unsigned char *loc2; int lcnum; lcnum = ape_lcid(apefd, vci); printf("Configuring lc number %d \n", lcnum); if (lcnum == 0) return(-1); offset = lcnum << 7; offset += 0x4a; iobuf[0] = 0x08000000 + offset; ioctl(apefd, AIO_RDVSAP, iobuf); printf("Old value of LnkStat/TMQ is %04x \n", iobuf[1]); iobuf[1] = iobuf[1] & 0xfff8; iobuf[1] |= tmq; ioctl(apefd, AIO_WTVSAP, iobuf); ioctl(apefd, AIO_RDVSAP, iobuf); printf("New value of LnkStat/TMQ is %04x \n", iobuf[1]); } /**/ /* Create a logical channel */ int ape_createlc( int apefd, int vci) /* vc number to use (vp must be 0). */ { iobuf[0] = vci; ioctl(apefd, AIO_CREATELC, iobuf); /*printf("Created lc number %x\n", iobuf[1]); */ return(iobuf[1]); } /**/ /* Free a logical channel */ int ape_freelc( int apefd, int vci) /* vc number to use (vp must be 0). */ { iobuf[0] = vci; ioctl(apefd, AIO_FREELC, iobuf); printf("Free lc returned %d\n", iobuf[1]); } /**/ /* Send a packet */ int ape_send( int apefd, /* Open device handle */ int vcid, /* Active LC number */ char *buf, /* => data. */ int buflen) /* Length of data */ { iobuf[0] = vcid; iobuf[1] = (unsigned long)buf; iobuf[2] = buflen; ioctl(apefd, AIO_SENDDATA, iobuf); } /**/ /* Recv a packet */ int ape_recv( int apefd, /* Open device handle */ int vcid, /* Active VC number */ char *buf, /* => data. */ int buflen) /* Length of data */ { int rc; iobuf[0] = vcid; iobuf[1] = (unsigned long)buf; iobuf[2] = buflen; rc = ioctl(apefd, AIO_RECVDATA, iobuf); /* printf("Recvd %d bytes \n", rc); */ }