lmcconfig.c revision 216599
1150850Sscottl/* 2150850Sscottl * First author: Michael Graff. 3150850Sscottl * Copyright (c) 1997-2000 Lan Media Corp. (www.lanmedia.com). 4150850Sscottl * All rights reserved. 5150850Sscottl * 6150850Sscottl * Second author: Andrew Stanley-Jones. 7150850Sscottl * Copyright (c) 2000-2002 SBE Corp. (www.sbei.com). 8150850Sscottl * All rights reserved. 9150850Sscottl * 10150850Sscottl * Third author: David Boggs. 11150850Sscottl * Copyright (c) 2002-2004 David Boggs. (boggs@boggs.palo-alto.ca.us). 12150850Sscottl * All rights reserved. 13150850Sscottl * 14150850Sscottl * BSD License: 15150850Sscottl * 16150850Sscottl * Redistribution and use in source and binary forms, with or without 17150850Sscottl * modification, are permitted provided that the following conditions 18150850Sscottl * are met: 19150850Sscottl * 1. Redistributions of source code must retain the above copyright 20150850Sscottl * notice, this list of conditions and the following disclaimer. 21150850Sscottl * 2. Redistributions in binary form must reproduce the above copyright 22150850Sscottl * notice, this list of conditions and the following disclaimer in the 23150850Sscottl * documentation and/or other materials provided with the distribution. 24150850Sscottl * 25150850Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 26150850Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27150850Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28150850Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 29150850Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30150850Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31150850Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32150850Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33150850Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34150850Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35150850Sscottl * SUCH DAMAGE. 36150850Sscottl * 37150850Sscottl * GNU General Public License: 38150850Sscottl * 39150850Sscottl * This program is free software; you can redistribute it and/or modify it 40150850Sscottl * under the terms of the GNU General Public License as published by the Free 41150850Sscottl * Software Foundation; either version 2 of the License, or (at your option) 42150850Sscottl * any later version. 43150850Sscottl * 44150850Sscottl * This program is distributed in the hope that it will be useful, but WITHOUT 45150850Sscottl * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46150850Sscottl * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 47150850Sscottl * more details. 48150850Sscottl * 49150850Sscottl * You should have received a copy of the GNU General Public License along with 50150850Sscottl * this program; if not, write to the Free Software Foundation, Inc., 59 51150850Sscottl * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 52150850Sscottl * 53150850Sscottl * Description: 54150850Sscottl * 55150850Sscottl * This program configures the Unix/Linux device driver for SBE Corp's 56150850Sscottl * wanADAPT and wanPMC series of Wide Area Network Interface Cards. 57150850Sscottl * There is a man page for this program; go find it. 58150850Sscottl * 59150850Sscottl * If Netgraph is present (FreeBSD only): 60150850Sscottl * cc -o lmcconfig -l netgraph -D NETGRAPH lmcconfig.c 61150850Sscottl * If Netgraph is NOT present: 62150850Sscottl * cc -o lmcconfig lmcconfig.c 63150850Sscottl * Install the executable program in /usr/local/sbin/lmcconfig. 64150850Sscottl * 65150850Sscottl * $FreeBSD: head/usr.sbin/lmcconfig/lmcconfig.c 216599 2010-12-20 19:08:07Z uqs $ 66150850Sscottl */ 67150850Sscottl 68150850Sscottl#include <stdio.h> 69150850Sscottl#include <errno.h> 70150850Sscottl#include <stdlib.h> 71188826Simp#include <string.h> 72188826Simp#include <strings.h> 73150850Sscottl#include <unistd.h> 74150850Sscottl#if defined(NETGRAPH) 75150850Sscottl# include <netgraph.h> 76150850Sscottl#endif 77150850Sscottl#include <sys/param.h> 78150850Sscottl#include <sys/types.h> 79150850Sscottl#include <sys/time.h> 80150850Sscottl#include <sys/ioctl.h> 81150850Sscottl#include <sys/socket.h> 82150850Sscottl#include <net/if.h> 83150850Sscottl 84150850Sscottl#include <dev/lmc/if_lmc.h> 85150850Sscottl 86150850Sscottl/* program global variables */ 87150850Sscottlchar * progname; /* name of this program */ 88150850Sscottlchar * ifname; /* interface name */ 89150850Sscottlint fdcs; /* ifnet File Desc or ng Ctl Socket */ 90150850Sscottlstruct status status; /* card status (read only) */ 91150850Sscottlstruct config config; /* card configuration (read/write) */ 92150850Sscottlint netgraph = 0; /* non-zero if netgraph present */ 93150850Sscottlint summary = 0; /* print summary at end */ 94150850Sscottlint update = 0; /* update driver config */ 95150850Sscottlint verbose = 0; /* verbose output */ 96150850Sscottlu_int8_t checksum; /* gate array ucode file checksum */ 97150850Sscottl 98150850Sscottlvoid usage() 99150850Sscottl { 100150850Sscottl fprintf(stderr, "Usage: %s interface [-abBcCdDeEfhiLmMpPsStTuUvVwWxXyYzZ?]\n", progname); 101150850Sscottl fprintf(stderr, "or\n"); 102150850Sscottl fprintf(stderr, "Usage: %s interface -1 [-aABcdeEfFgiIlLpPstTuUvxX]\n", progname); 103150850Sscottl fprintf(stderr, "or\n"); 104150850Sscottl fprintf(stderr, "Usage: %s interface -3 [-aABcdefFlLsSvV]\n\n", progname); 105150850Sscottl fprintf(stderr, "\tInterface is the interface name, e.g. '%s'\n", ifname); 106150850Sscottl#if defined(NETGRAPH) 107150850Sscottl fprintf(stderr, "\tIf interface name ends with ':' then use netgraph\n"); 108150850Sscottl#endif 109150850Sscottl fprintf(stderr, "\t-1 following parameters apply to T1E1 cards\n"); 110150850Sscottl fprintf(stderr, "\t-3 following parameters apply to T3 cards\n"); 111150850Sscottl fprintf(stderr, "\t-a <number> Set Tx clock source, where:\n"); 112150850Sscottl fprintf(stderr, "\t 1:modem Tx clk 2:int src 3:modem Rx Clk 4:ext conn\n"); 113150850Sscottl fprintf(stderr, "\t-b Read and print bios rom addrs 0-255\n"); 114150850Sscottl fprintf(stderr, "\t-B Write bios rom with address pattern\n"); 115150850Sscottl fprintf(stderr, "\t-c Set 16-bit CRC (default)\n"); 116150850Sscottl fprintf(stderr, "\t-C Set 32-bit CRC\n"); 117150850Sscottl fprintf(stderr, "\t-d Clear driver DEBUG flag\n"); 118150850Sscottl fprintf(stderr, "\t-D Set driver DEBUG flag (more log msgs)\n"); 119150850Sscottl fprintf(stderr, "\t-e Set DTE mode (default)\n"); 120150850Sscottl fprintf(stderr, "\t-E Set DCE mode\n"); 121150850Sscottl fprintf(stderr, "\t-f <number> Set synth osc freq in bits/sec\n"); 122150850Sscottl fprintf(stderr, "\t-F Set SPPP line protocol to Frame-Relay\n"); 123150850Sscottl fprintf(stderr, "\t-h Help: this usage message\n"); 124150850Sscottl fprintf(stderr, "\t-i Interface name (eg, lmc0)\n"); 125150850Sscottl fprintf(stderr, "\t-L <number> Set loopback: 1:none 2:payload 3:line 4:other\n"); 126150850Sscottl fprintf(stderr, "\t 5:inward 6:dual 16:Tulip 17:pins 18:LA/LL 19:LB/RL\n"); 127150850Sscottl fprintf(stderr, "\t-m Read and print MII regs\n"); 128150850Sscottl fprintf(stderr, "\t-M <addr> <data> Write MII reg\n"); 129150850Sscottl fprintf(stderr, "\t-p Read and print PCI config regs\n"); 130150850Sscottl fprintf(stderr, "\t-P <addr> <data> Write PCI config reg\n"); 131150850Sscottl fprintf(stderr, "\t-s Read and print Tulip SROM\n"); 132150850Sscottl fprintf(stderr, "\t-S <number> Initialize Tulip SROM\n"); 133150850Sscottl fprintf(stderr, "\t-t Read and print Tulip Control/Status regs\n"); 134150850Sscottl fprintf(stderr, "\t-T <addr> <data> Write Tulip Control/status reg\n"); 135150850Sscottl fprintf(stderr, "\t-u Reset event counters\n"); 136150850Sscottl fprintf(stderr, "\t-U Reset gate array\n"); 137150850Sscottl fprintf(stderr, "\t-v Set verbose printout mode\n"); 138150850Sscottl fprintf(stderr, "\t-V Print card configuration\n"); 139150850Sscottl fprintf(stderr, "\t-w Load gate array from ROM\n"); 140150850Sscottl fprintf(stderr, "\t-W <filename> Load gate array from file\n"); 141150850Sscottl fprintf(stderr, "\t-x select RAWIP mode and bypass line protocols\n"); 142150850Sscottl fprintf(stderr, "\t-X Select line protocols: SPPP, P2P or HDLC\n"); 143150850Sscottl fprintf(stderr, "\t-y disable SPPP keep-alive packets\n"); 144150850Sscottl fprintf(stderr, "\t-Y enable SPPP keep-alive packets\n"); 145150850Sscottl fprintf(stderr, "\t-z Set SPPP line protocol to Cisco-HDLC\n"); 146150850Sscottl fprintf(stderr, "\t-Z Set SPPP line protocol to PPP\n"); 147150850Sscottl 148150850Sscottl fprintf(stderr, "The -1 switch precedes T1/E1 commands.\n"); 149150850Sscottl fprintf(stderr, "\t-a <y|b|a> Stop sending Yellow|Blue|AIS signal\n"); 150150850Sscottl fprintf(stderr, "\t-A <y|b|a> Start sending Yellow|Blue}AIS signal\n"); 151150850Sscottl fprintf(stderr, "\t-B <number> Send BOP msg 25 times\n"); 152150850Sscottl fprintf(stderr, "\t-c <number> Set cable length in meters\n"); 153150850Sscottl fprintf(stderr, "\t-d Print status of T1 DSU/CSU\n"); 154150850Sscottl fprintf(stderr, "\t-e <number> Set framing format, where:\n"); 155150850Sscottl fprintf(stderr, "\t 27:T1-ESF 9:T1-SF 0:E1-FAS 8:E1-FAS+CRC\n"); 156150850Sscottl fprintf(stderr, "\t 16:E1-FAS+CAS 24:E1-FAS+CRC+CAS 32:E1-NO-FRAMING\n"); 157150850Sscottl fprintf(stderr, "\t-E <32-bit hex number> 1 activates a channel and 0 deactivates it.\n"); 158150850Sscottl fprintf(stderr, "\t Use this to config a link in fractional T1/E1 mode\n"); 159150850Sscottl fprintf(stderr, "\t-f Read and print Framer/LIU registers\n"); 160150850Sscottl fprintf(stderr, "\t-F <addr> <data> Write Framer/LIU register\n"); 161150850Sscottl fprintf(stderr, "\t-g <number> Set receiver gain, where:\n"); 162150850Sscottl fprintf(stderr, "\t 0:short range 1:medium range\n"); 163150850Sscottl fprintf(stderr, "\t 2:long range 3:extended range\n"); 164150850Sscottl fprintf(stderr, "\t 4:auto-set based on cable length\n"); 165150850Sscottl fprintf(stderr, "\t-i Send 'CSU Loop Down' inband msg\n"); 166150850Sscottl fprintf(stderr, "\t-I Send 'CSU Loop Up' inband msg\n"); 167150850Sscottl fprintf(stderr, "\t-l Send 'Line Loop Down' BOP msg\n"); 168150850Sscottl fprintf(stderr, "\t-L Send 'Line Loop Up' BOP msg\n"); 169150850Sscottl fprintf(stderr, "\t-p Send 'Payload Loop Down' BOP msg\n"); 170150850Sscottl fprintf(stderr, "\t-P Send 'Payload Loop Up' BOP msg\n"); 171150850Sscottl fprintf(stderr, "\t-s Print status of T1 DSU/CSU\n"); 172150850Sscottl fprintf(stderr, "\t-t Stop sending test pattern\n"); 173150850Sscottl fprintf(stderr, "\t-T <number> Start sending test pattern, where:\n"); 174150850Sscottl fprintf(stderr, "\t 0:unframed 2^11 1:unframed 2^15\n"); 175150850Sscottl fprintf(stderr, "\t 2:unframed 2^20 3:unframed 2^23\n"); 176150850Sscottl fprintf(stderr, "\t 4:unframed 2^11 w/ZS 5:unframed 2^15 w/ZS\n"); 177150850Sscottl fprintf(stderr, "\t 6:unframed QRSS 7:unframed 2^23 w/ZS\n"); 178150850Sscottl fprintf(stderr, "\t 8: framed 2^11 9: framed 2^15\n"); 179150850Sscottl fprintf(stderr, "\t 10: framed 2^20 11: framed 2^23\n"); 180150850Sscottl fprintf(stderr, "\t 12: framed 2^11 w/ZS 13: framed 2^15 w/ZS\n"); 181150850Sscottl fprintf(stderr, "\t 14: framed QRSS 15: framed 2^23 w/ZS\n"); 182150850Sscottl fprintf(stderr, "\t-u <number> Set transmitter pulse shape, where:\n"); 183150850Sscottl fprintf(stderr, "\t 0:T1-DSX 0-40m 1:T1-DSX 40-80m\n"); 184150850Sscottl fprintf(stderr, "\t 2:T1-DSX 80-120m 3:T1-DSX 120-160m\n"); 185150850Sscottl fprintf(stderr, "\t 4:T1-DSX 160-200m 5:E1-G.703 75ohm coax\n"); 186150850Sscottl fprintf(stderr, "\t 6:E1-G.703 120ohm TP 7:T1-CSU Long range\n"); 187150850Sscottl fprintf(stderr, "\t 8:auto-set based on cable length (T1 only)\n"); 188150850Sscottl fprintf(stderr, "\t-U <number> Set line build out where:\n"); 189150850Sscottl fprintf(stderr, "\t 0:0dB 1:7.5dB 2:15dB 3:22.5dB\n"); 190150850Sscottl fprintf(stderr, "\t 4:auto-set based on cable length\n"); 191150850Sscottl fprintf(stderr, "\t-v Set verbose printout mode\n"); 192150850Sscottl fprintf(stderr, "\t-x disable Transmitter outputs\n"); 193150850Sscottl fprintf(stderr, "\t-X enable Transmitter outputs\n"); 194150850Sscottl 195150850Sscottl fprintf(stderr, "The -3 switch precedes T3 commands.\n"); 196150850Sscottl fprintf(stderr, "\t-a <y|b|a|i> Stop sending Yellow|Blue|AIS|Idle signal\n"); 197150850Sscottl fprintf(stderr, "\t-A <y|b|a|i> Start sending Yellow|Blue|AIS|Idle signal\n"); 198150850Sscottl fprintf(stderr, "\t-B <bopcode> Send BOP msg 10 times\n"); 199150850Sscottl fprintf(stderr, "\t-c <number> Set cable length in meters\n"); 200150850Sscottl fprintf(stderr, "\t-d Print status of T3 DSU/CSU\n"); 201150850Sscottl fprintf(stderr, "\t-e <number> Set T3 frame format, where:\n"); 202150850Sscottl fprintf(stderr, "\t 100:C-Bit Parity 101:M13\n"); 203150850Sscottl fprintf(stderr, "\t-f Read and print Framer registers\n"); 204150850Sscottl fprintf(stderr, "\t-F <addr> <data> Write Framer register\n"); 205150850Sscottl fprintf(stderr, "\t-l Send 'Line Loop Down' BOP msg\n"); 206150850Sscottl fprintf(stderr, "\t-L Send 'Line Loop Up' BOP msg\n"); 207150850Sscottl fprintf(stderr, "\t-s Print status of T3 DSU/CSU\n"); 208150850Sscottl fprintf(stderr, "\t-S <number> Set DS3 scrambler mode, where:\n"); 209150850Sscottl fprintf(stderr, "\t 1:OFF 2:DigitalLink|Kentrox 3:Larse\n"); 210150850Sscottl fprintf(stderr, "\t-v Set verbose printout mode\n"); 211150850Sscottl fprintf(stderr, "\t-V <number> Write to T3 VCXO freq control DAC\n"); 212150850Sscottl } 213150850Sscottl 214150850Sscottlvoid call_driver(unsigned long cmd, struct iohdr *iohdr) 215150850Sscottl { 216150850Sscottl int error = 0; 217150850Sscottl 218150850Sscottl strncpy(iohdr->ifname, ifname, sizeof(iohdr->ifname)); 219150850Sscottl iohdr->cookie = NGM_LMC_COOKIE; 220150850Sscottl iohdr->iohdr = iohdr; 221150850Sscottl 222150850Sscottl /* Exchange data with a running device driver. */ 223150850Sscottl#if defined(NETGRAPH) 224150850Sscottl if (netgraph) 225150850Sscottl { 226150850Sscottl NgSendMsg(fdcs, ifname, NGM_LMC_COOKIE, cmd, iohdr, IOCPARM_LEN(cmd)); 227150850Sscottl if (cmd & IOC_OUT) 228150850Sscottl { 229150850Sscottl int replen = sizeof(struct ng_mesg) + IOCPARM_LEN(cmd); 230150850Sscottl char rep[replen]; /* storage for the reply */ 231150850Sscottl struct ng_mesg *reply = (struct ng_mesg *)rep; 232150850Sscottl int rl = NgRecvMsg(fdcs, reply, replen, NULL); 233150850Sscottl if (rl == replen) 234150850Sscottl bcopy(&reply->data, iohdr, IOCPARM_LEN(cmd)); 235150850Sscottl else 236150850Sscottl { 237150850Sscottl fprintf(stderr, "%s: NgRecvMsg returned %d bytes, expected %d\n", 238150850Sscottl progname, rl, replen); 239150850Sscottl exit(1); 240150850Sscottl } 241150850Sscottl } 242150850Sscottl } 243150850Sscottl else 244150850Sscottl#endif 245150850Sscottl { 246150850Sscottl if ((error = ioctl(fdcs, cmd, (caddr_t)iohdr)) < 0) 247150850Sscottl { 248150850Sscottl fprintf(stderr, "%s: ioctl() returned error code %d: %s\n", 249150850Sscottl progname, errno, strerror(errno)); 250150850Sscottl if (errno == ENETDOWN) 251150850Sscottl printf("Type: 'ifconfig %s up' then try again.\n", ifname); 252150850Sscottl exit(1); 253150850Sscottl } 254150850Sscottl } 255150850Sscottl 256150850Sscottl if (iohdr->cookie != NGM_LMC_COOKIE) 257150850Sscottl { 258150850Sscottl fprintf(stderr, "%s: cookie = 0x%08X, expected 0x%08X\n", progname, iohdr->cookie, NGM_LMC_COOKIE); 259150850Sscottl fprintf(stderr, "%s: This version of %s is incompatible with the device driver\n", progname, progname); 260150850Sscottl exit(1); 261150850Sscottl } 262150850Sscottl } 263150850Sscottl 264150850Sscottlu_int32_t read_pci_config(u_int8_t addr) 265150850Sscottl { 266150850Sscottl struct ioctl ioctl; 267150850Sscottl 268150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 269150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 270150850Sscottl ioctl.cmd = IOCTL_RW_PCI; 271150850Sscottl ioctl.address = addr; 272150850Sscottl 273150850Sscottl call_driver(LMCIOCREAD, &ioctl.iohdr); 274150850Sscottl 275150850Sscottl return ioctl.data; 276150850Sscottl } 277150850Sscottl 278150850Sscottlvoid write_pci_config(u_int8_t addr, u_int32_t data) 279150850Sscottl { 280150850Sscottl struct ioctl ioctl; 281150850Sscottl 282150850Sscottl ioctl.iohdr.direction = DIR_IOW; 283150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 284150850Sscottl ioctl.cmd = IOCTL_RW_PCI; 285150850Sscottl ioctl.address = addr; 286150850Sscottl ioctl.data = data; 287150850Sscottl 288150850Sscottl call_driver(LMCIOCWRITE, &ioctl.iohdr); 289150850Sscottl } 290150850Sscottl 291150850Sscottlu_int32_t read_csr(u_int8_t addr) 292150850Sscottl { 293150850Sscottl struct ioctl ioctl; 294150850Sscottl 295150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 296150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 297150850Sscottl ioctl.cmd = IOCTL_RW_CSR; 298150850Sscottl ioctl.address = addr; 299150850Sscottl 300150850Sscottl call_driver(LMCIOCREAD, &ioctl.iohdr); 301150850Sscottl 302150850Sscottl return ioctl.data; 303150850Sscottl } 304150850Sscottl 305150850Sscottlvoid write_csr(u_int8_t addr, u_int32_t data) 306150850Sscottl { 307150850Sscottl struct ioctl ioctl; 308150850Sscottl 309150850Sscottl ioctl.iohdr.direction = DIR_IOW; 310150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 311150850Sscottl ioctl.cmd = IOCTL_RW_CSR; 312150850Sscottl ioctl.address = addr; 313150850Sscottl ioctl.data = data; 314150850Sscottl 315150850Sscottl call_driver(LMCIOCWRITE, &ioctl.iohdr); 316150850Sscottl } 317150850Sscottl 318150850Sscottlu_int16_t read_srom(u_int8_t addr) 319150850Sscottl { 320150850Sscottl struct ioctl ioctl; 321150850Sscottl 322150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 323150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 324150850Sscottl ioctl.cmd = IOCTL_RW_SROM; 325150850Sscottl ioctl.address = addr; 326150850Sscottl 327150850Sscottl call_driver(LMCIOCREAD, &ioctl.iohdr); 328150850Sscottl 329150850Sscottl return ioctl.data; 330150850Sscottl } 331150850Sscottl 332150850Sscottlvoid write_srom(u_int8_t addr, u_int16_t data) 333150850Sscottl { 334150850Sscottl struct ioctl ioctl; 335150850Sscottl 336150850Sscottl ioctl.iohdr.direction = DIR_IOW; 337150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 338150850Sscottl ioctl.cmd = IOCTL_RW_SROM; 339150850Sscottl ioctl.address = addr; 340150850Sscottl ioctl.data = data; 341150850Sscottl 342150850Sscottl call_driver(LMCIOCWRITE, &ioctl.iohdr); 343150850Sscottl } 344150850Sscottl 345150850Sscottlu_int8_t read_bios_rom(u_int32_t addr) 346150850Sscottl { 347150850Sscottl struct ioctl ioctl; 348150850Sscottl 349150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 350150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 351150850Sscottl ioctl.cmd = IOCTL_RW_BIOS; 352150850Sscottl ioctl.address = addr; 353150850Sscottl 354150850Sscottl call_driver(LMCIOCREAD, &ioctl.iohdr); 355150850Sscottl 356150850Sscottl return ioctl.data; 357150850Sscottl } 358150850Sscottl 359150850Sscottlvoid write_bios_rom(u_int32_t addr, u_int8_t data) 360150850Sscottl { 361150850Sscottl struct ioctl ioctl; 362150850Sscottl 363150850Sscottl ioctl.iohdr.direction = DIR_IOW; 364150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 365150850Sscottl ioctl.cmd = IOCTL_RW_BIOS; 366150850Sscottl ioctl.address = addr; 367150850Sscottl ioctl.data = data; 368150850Sscottl 369150850Sscottl call_driver(LMCIOCWRITE, &ioctl.iohdr); 370150850Sscottl } 371150850Sscottl 372150850Sscottlu_int16_t read_mii(u_int8_t addr) 373150850Sscottl { 374150850Sscottl struct ioctl ioctl; 375150850Sscottl 376150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 377150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 378150850Sscottl ioctl.cmd = IOCTL_RW_MII; 379150850Sscottl ioctl.address = addr; 380150850Sscottl 381150850Sscottl call_driver(LMCIOCREAD, &ioctl.iohdr); 382150850Sscottl 383150850Sscottl return ioctl.data; 384150850Sscottl } 385150850Sscottl 386150850Sscottlvoid write_mii(u_int8_t addr, u_int16_t data) 387150850Sscottl { 388150850Sscottl struct ioctl ioctl; 389150850Sscottl 390150850Sscottl ioctl.iohdr.direction = DIR_IOW; 391150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 392150850Sscottl ioctl.cmd = IOCTL_RW_MII; 393150850Sscottl ioctl.address = addr; 394150850Sscottl ioctl.data = data; 395150850Sscottl 396150850Sscottl call_driver(LMCIOCWRITE, &ioctl.iohdr); 397150850Sscottl } 398150850Sscottl 399150850Sscottlunsigned char read_framer(u_int16_t addr) 400150850Sscottl { 401150850Sscottl struct ioctl ioctl; 402150850Sscottl 403150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 404150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 405150850Sscottl ioctl.cmd = IOCTL_RW_FRAME; 406150850Sscottl ioctl.address = addr; 407150850Sscottl 408150850Sscottl call_driver(LMCIOCREAD, &ioctl.iohdr); 409150850Sscottl 410150850Sscottl return ioctl.data; 411150850Sscottl } 412150850Sscottl 413150850Sscottlvoid write_framer(u_int16_t addr, u_int8_t data) 414150850Sscottl { 415150850Sscottl struct ioctl ioctl; 416150850Sscottl 417150850Sscottl ioctl.iohdr.direction = DIR_IOW; 418150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 419150850Sscottl ioctl.cmd = IOCTL_RW_FRAME; 420150850Sscottl ioctl.address = addr; 421150850Sscottl ioctl.data = data; 422150850Sscottl 423150850Sscottl call_driver(LMCIOCWRITE, &ioctl.iohdr); 424150850Sscottl } 425150850Sscottl 426150850Sscottlvoid write_synth(struct synth synth) 427150850Sscottl { 428150850Sscottl struct ioctl ioctl; 429150850Sscottl 430150850Sscottl ioctl.iohdr.direction = DIR_IOW; 431150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 432150850Sscottl ioctl.cmd = IOCTL_WO_SYNTH; 433150850Sscottl bcopy(&synth, &ioctl.data, sizeof(synth)); 434150850Sscottl 435150850Sscottl call_driver(LMCIOCWRITE, &ioctl.iohdr); 436150850Sscottl } 437150850Sscottl 438150850Sscottlvoid write_dac(u_int16_t data) 439150850Sscottl { 440150850Sscottl struct ioctl ioctl; 441150850Sscottl 442150850Sscottl ioctl.iohdr.direction = DIR_IOW; 443150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 444150850Sscottl ioctl.cmd = IOCTL_WO_DAC; 445150850Sscottl ioctl.data = data; 446150850Sscottl 447150850Sscottl call_driver(LMCIOCWRITE, &ioctl.iohdr); 448150850Sscottl } 449150850Sscottl 450150850Sscottlvoid reset_xilinx() 451150850Sscottl { 452150850Sscottl struct ioctl ioctl; 453150850Sscottl 454150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 455150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 456150850Sscottl ioctl.cmd = IOCTL_XILINX_RESET; 457150850Sscottl 458150850Sscottl call_driver(LMCIOCTL, &ioctl.iohdr); 459150850Sscottl } 460150850Sscottl 461150850Sscottlvoid load_xilinx_from_rom() 462150850Sscottl { 463150850Sscottl struct ioctl ioctl; 464150850Sscottl 465150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 466150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 467150850Sscottl ioctl.cmd = IOCTL_XILINX_ROM; 468150850Sscottl 469150850Sscottl call_driver(LMCIOCTL, &ioctl.iohdr); 470150850Sscottl } 471150850Sscottl 472150850Sscottlvoid load_xilinx_from_file(char *ucode, u_int32_t len) 473150850Sscottl { 474150850Sscottl struct ioctl ioctl; 475150850Sscottl 476150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 477150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 478150850Sscottl ioctl.cmd = IOCTL_XILINX_FILE; 479150850Sscottl ioctl.data = len; 480150850Sscottl ioctl.ucode = ucode; 481150850Sscottl 482150850Sscottl call_driver(LMCIOCTL, &ioctl.iohdr); 483150850Sscottl } 484150850Sscottl 485150850Sscottlvoid ioctl_snmp_send(u_int32_t send) 486150850Sscottl { 487150850Sscottl struct ioctl ioctl; 488150850Sscottl 489150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 490150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 491150850Sscottl ioctl.cmd = IOCTL_SNMP_SEND; 492150850Sscottl ioctl.data = send; 493150850Sscottl 494150850Sscottl call_driver(LMCIOCTL, &ioctl.iohdr); 495150850Sscottl } 496150850Sscottl 497150850Sscottlvoid ioctl_snmp_loop(u_int32_t loop) 498150850Sscottl { 499150850Sscottl struct ioctl ioctl; 500150850Sscottl 501150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 502150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 503150850Sscottl ioctl.cmd = IOCTL_SNMP_LOOP; 504150850Sscottl ioctl.data = loop; 505150850Sscottl 506150850Sscottl call_driver(LMCIOCTL, &ioctl.iohdr); 507150850Sscottl } 508150850Sscottl 509150850Sscottlvoid ioctl_reset_cntrs() 510150850Sscottl { 511150850Sscottl struct ioctl ioctl; 512150850Sscottl 513150850Sscottl ioctl.iohdr.direction = DIR_IOWR; 514150850Sscottl ioctl.iohdr.length = sizeof(struct ioctl); 515150850Sscottl ioctl.cmd = IOCTL_RESET_CNTRS; 516150850Sscottl 517150850Sscottl call_driver(LMCIOCTL, &ioctl.iohdr); 518150850Sscottl } 519150850Sscottl 520150850Sscottlvoid ioctl_read_config() 521150850Sscottl { 522150850Sscottl config.iohdr.direction = DIR_IOWR; 523150850Sscottl config.iohdr.length = sizeof(struct config); 524150850Sscottl 525150850Sscottl call_driver(LMCIOCGCFG, &config.iohdr); 526150850Sscottl } 527150850Sscottl 528150850Sscottlvoid ioctl_write_config() 529150850Sscottl { 530150850Sscottl config.iohdr.direction = DIR_IOW; 531150850Sscottl config.iohdr.length = sizeof(struct config); 532150850Sscottl 533150850Sscottl call_driver(LMCIOCSCFG, &config.iohdr); 534150850Sscottl } 535150850Sscottl 536150850Sscottlvoid ioctl_read_status() 537150850Sscottl { 538150850Sscottl status.iohdr.direction = DIR_IOWR; 539150850Sscottl status.iohdr.length = sizeof(struct status); 540150850Sscottl 541150850Sscottl call_driver(LMCIOCGSTAT, &status.iohdr); 542150850Sscottl } 543150850Sscottl 544150850Sscottlvoid print_card_name() 545150850Sscottl { 546150850Sscottl printf("Card name:\t\t%s\n", ifname); 547150850Sscottl } 548150850Sscottl 549150850Sscottlvoid print_card_type() 550150850Sscottl { 551150850Sscottl printf("Card type:\t\t"); 552150850Sscottl switch(status.card_type) 553150850Sscottl { 554150850Sscottl case TLP_CSID_HSSI: 555150850Sscottl printf("HSSI (lmc5200)\n"); 556150850Sscottl break; 557150850Sscottl case TLP_CSID_T3: 558150850Sscottl printf("T3 (lmc5245)\n"); 559150850Sscottl break; 560150850Sscottl case TLP_CSID_SSI: 561150850Sscottl printf("SSI (lmc1000)\n"); 562150850Sscottl break; 563150850Sscottl case TLP_CSID_T1E1: 564150850Sscottl printf("T1E1 (lmc1200)\n"); 565150850Sscottl break; 566150850Sscottl case TLP_CSID_HSSIc: 567150850Sscottl printf("HSSI (lmc5200C)\n"); 568150850Sscottl break; 569150850Sscottl default: 570150850Sscottl printf("unknown card_type: %d\n", status.card_type); 571150850Sscottl break; 572150850Sscottl } 573150850Sscottl } 574150850Sscottl 575150850Sscottlvoid print_status() 576150850Sscottl { 577150850Sscottl char *status_string; 578150850Sscottl 579150850Sscottl if (status.oper_status == STATUS_UP) 580150850Sscottl status_string = "Up"; 581150850Sscottl else if (status.oper_status == STATUS_DOWN) 582150850Sscottl status_string = "Down"; 583150850Sscottl else if (status.oper_status == STATUS_TEST) 584150850Sscottl status_string = "Test"; 585150850Sscottl else 586150850Sscottl status_string = "Unknown"; 587150850Sscottl printf("Link status:\t\t%s\n", status_string); 588150850Sscottl } 589150850Sscottl 590150850Sscottlvoid print_tx_speed() 591150850Sscottl { 592150850Sscottl printf("Tx Speed:\t\t%u\n", status.tx_speed); 593150850Sscottl } 594150850Sscottl 595150850Sscottlvoid print_debug() 596150850Sscottl { 597150850Sscottl if (config.debug != 0) 598150850Sscottl printf("Debug:\t\t\t%s\n", "On"); 599150850Sscottl } 600150850Sscottl 601150850Sscottlvoid print_line_prot() 602150850Sscottl { 603150850Sscottl char *on = "On", *off = "Off"; 604150850Sscottl 605150850Sscottl printf("Line Prot/Pkg:\t\t"); 606150850Sscottl switch (status.line_prot) 607150850Sscottl { 608150850Sscottl case 0: 609150850Sscottl printf("NotSet/"); 610150850Sscottl break; 611150850Sscottl case PROT_PPP: 612150850Sscottl printf("PPP/"); 613150850Sscottl break; 614150850Sscottl case PROT_C_HDLC: 615150850Sscottl printf("Cisco-HDLC/"); 616150850Sscottl break; 617150850Sscottl case PROT_FRM_RLY: 618150850Sscottl printf("Frame-Relay/"); 619150850Sscottl break; 620150850Sscottl case PROT_IP_HDLC: 621150850Sscottl printf("IP-in-HDLC/"); 622150850Sscottl break; 623150850Sscottl case PROT_ETH_HDLC: 624150850Sscottl printf("Ether-in-HDLC/"); 625150850Sscottl break; 626150850Sscottl case PROT_X25: 627150850Sscottl printf("X25+LAPB/"); 628150850Sscottl break; 629150850Sscottl default: 630150850Sscottl printf("unknown line_prot: %d/", status.line_prot); 631150850Sscottl break; 632150850Sscottl } 633150850Sscottl 634150850Sscottl switch (status.line_pkg) 635150850Sscottl { 636150850Sscottl case 0: 637150850Sscottl printf("NotSet\n"); 638150850Sscottl break; 639150850Sscottl case PKG_RAWIP: 640150850Sscottl printf("Driver\n"); 641150850Sscottl break; 642150850Sscottl case PKG_NG: 643150850Sscottl printf("Netgraph\n"); 644150850Sscottl break; 645150850Sscottl case PKG_GEN_HDLC: 646150850Sscottl printf("GenHDLC\n"); 647150850Sscottl break; 648150850Sscottl case PKG_SPPP: 649150850Sscottl printf("SPPP\n"); 650150850Sscottl break; 651150850Sscottl case PKG_P2P: 652150850Sscottl printf("P2P\n"); 653150850Sscottl break; 654150850Sscottl default: 655150850Sscottl printf("unknown line_pkg: %d\n", status.line_pkg); 656150850Sscottl break; 657150850Sscottl } 658150850Sscottl 659150850Sscottl if (status.line_pkg == PKG_SPPP) 660150850Sscottl printf("SPPP Keep-alives:\t%s\n", 661150850Sscottl config.keep_alive ? on : off); 662150850Sscottl } 663150850Sscottl 664150850Sscottlvoid print_crc_len() 665150850Sscottl { 666150850Sscottl printf("CRC length:\t\t"); 667150850Sscottl if (config.crc_len == CFG_CRC_0) 668150850Sscottl printf("no CRC\n"); 669150850Sscottl else if (config.crc_len == CFG_CRC_16) 670150850Sscottl printf("16 bits\n"); 671150850Sscottl else if (config.crc_len == CFG_CRC_32) 672150850Sscottl printf("32 bits\n"); 673150850Sscottl else 674150850Sscottl printf("bad crc_len: %d\n", config.crc_len); 675150850Sscottl } 676150850Sscottl 677150850Sscottlvoid print_loop_back() 678150850Sscottl { 679150850Sscottl printf("Loopback:\t\t"); 680150850Sscottl switch (config.loop_back) 681150850Sscottl { 682150850Sscottl case CFG_LOOP_NONE: 683150850Sscottl printf("None\n"); 684150850Sscottl break; 685150850Sscottl case CFG_LOOP_PAYLOAD: 686150850Sscottl printf("Outward thru framer (payload loop)\n"); 687150850Sscottl break; 688150850Sscottl case CFG_LOOP_LINE: 689150850Sscottl printf("Outward thru line interface (line loop)\n"); 690150850Sscottl break; 691150850Sscottl case CFG_LOOP_OTHER: 692150850Sscottl printf("Inward thru line interface\n"); 693150850Sscottl break; 694150850Sscottl case CFG_LOOP_INWARD: 695150850Sscottl printf("Inward thru framer\n"); 696150850Sscottl break; 697150850Sscottl case CFG_LOOP_DUAL: 698150850Sscottl printf("Inward & outward (dual loop)\n"); 699150850Sscottl break; 700150850Sscottl case CFG_LOOP_TULIP: 701150850Sscottl printf("Inward thru Tulip chip\n"); 702150850Sscottl break; 703150850Sscottl case CFG_LOOP_PINS: 704150850Sscottl printf("Inward thru drvrs/rcvrs\n"); 705150850Sscottl break; 706150850Sscottl case CFG_LOOP_LL: 707150850Sscottl printf("LA/LL asserted\n"); 708150850Sscottl break; 709150850Sscottl case CFG_LOOP_RL: 710150850Sscottl printf("LB/RL asserted\n"); 711150850Sscottl break; 712150850Sscottl default: 713150850Sscottl printf("unknown loop_back: %d\n", config.loop_back); 714150850Sscottl break; 715150850Sscottl } 716150850Sscottl } 717150850Sscottl 718150850Sscottlvoid print_tx_clk_src() 719150850Sscottl { 720150850Sscottl printf("Tx Clk src:\t\t"); 721150850Sscottl switch (config.tx_clk_src) 722150850Sscottl { 723150850Sscottl case CFG_CLKMUX_ST: 724150850Sscottl printf("Tx Clk from modem\n"); 725150850Sscottl break; 726150850Sscottl case CFG_CLKMUX_INT: 727150850Sscottl printf("Internal source\n"); 728150850Sscottl break; 729150850Sscottl case CFG_CLKMUX_RT: 730150850Sscottl printf("Rx Clk from modem (loop timed)\n"); 731150850Sscottl break; 732150850Sscottl case CFG_CLKMUX_EXT: 733150850Sscottl printf("External connector\n"); 734150850Sscottl break; 735150850Sscottl default: 736150850Sscottl printf("unknown tx_clk_src: %d\n", config.tx_clk_src); 737150850Sscottl break; 738150850Sscottl } 739150850Sscottl } 740150850Sscottl 741150850Sscottlvoid print_format() 742150850Sscottl { 743150850Sscottl printf("Format-Frame/Code:\t"); 744150850Sscottl switch (config.format) 745150850Sscottl { 746150850Sscottl case CFG_FORMAT_T1SF: 747150850Sscottl printf("T1-SF/AMI\n"); 748150850Sscottl break; 749150850Sscottl case CFG_FORMAT_T1ESF: 750150850Sscottl printf("T1-ESF/B8ZS\n"); 751150850Sscottl break; 752150850Sscottl case CFG_FORMAT_E1FAS: 753150850Sscottl printf("E1-FAS/HDB3\n"); 754150850Sscottl break; 755150850Sscottl case CFG_FORMAT_E1FASCRC: 756150850Sscottl printf("E1-FAS+CRC/HDB3\n"); 757150850Sscottl break; 758150850Sscottl case CFG_FORMAT_E1FASCAS: 759150850Sscottl printf("E1-FAS+CAS/HDB3\n"); 760150850Sscottl break; 761150850Sscottl case CFG_FORMAT_E1FASCRCCAS: 762150850Sscottl printf("E1-FAS+CRC+CAS/HDB3\n"); 763150850Sscottl break; 764150850Sscottl case CFG_FORMAT_E1NONE: 765150850Sscottl printf("E1-NOFRAMING/HDB3\n"); 766150850Sscottl break; 767150850Sscottl case CFG_FORMAT_T3CPAR: 768150850Sscottl printf("T3-CParity/B3ZS\n"); 769150850Sscottl break; 770150850Sscottl case CFG_FORMAT_T3M13: 771150850Sscottl printf("T3-M13/B3ZS\n"); 772150850Sscottl break; 773150850Sscottl default: 774150850Sscottl printf("unknown format: %d\n", config.format); 775150850Sscottl break; 776150850Sscottl } 777150850Sscottl } 778150850Sscottl 779150850Sscottlvoid print_dte_dce() 780150850Sscottl { 781150850Sscottl printf("DTE or DCE:\t\t"); 782150850Sscottl switch(config.dte_dce) 783150850Sscottl { 784150850Sscottl case CFG_DTE: 785150850Sscottl printf("DTE (receiving TxClk)\n"); 786150850Sscottl break; 787150850Sscottl case CFG_DCE: 788150850Sscottl printf("DCE (driving TxClk)\n"); 789150850Sscottl break; 790150850Sscottl default: 791150850Sscottl printf("unknown dte_dce: %d\n", config.dte_dce); 792150850Sscottl break; 793150850Sscottl } 794150850Sscottl } 795150850Sscottl 796150850Sscottlvoid print_synth_freq() 797150850Sscottl { 798150850Sscottl double Fref = 20e6; 799150850Sscottl double Fout, Fvco; 800150850Sscottl 801150850Sscottl /* decode the synthesizer params */ 802150850Sscottl Fvco = (Fref * (config.synth.n<<(3*config.synth.v)))/config.synth.m; 803150850Sscottl Fout = Fvco / (1<<(config.synth.x+config.synth.r+config.synth.prescale)); 804150850Sscottl 805150850Sscottl printf("Synth freq:\t\t%.0f\n", Fout); 806150850Sscottl } 807150850Sscottl 808150850Sscottlvoid synth_freq(unsigned long target) 809150850Sscottl { 810150850Sscottl unsigned int n, m, v, x, r; 811150850Sscottl double Fout, Fvco, Ftarg; 812150850Sscottl double newdiff, olddiff; 813150850Sscottl double bestF=0.0, bestV=0.0; 814150850Sscottl unsigned prescale = (target < 50000) ? 9:4; 815150850Sscottl 816150850Sscottl Ftarg = target<<prescale; 817150850Sscottl for (n=3; n<=127; n++) 818150850Sscottl for (m=3; m<=127; m++) 819150850Sscottl for (v=0; v<=1; v++) 820150850Sscottl for (x=0; x<=3; x++) 821150850Sscottl for (r=0; r<=3; r++) 822150850Sscottl { 823150850Sscottl Fvco = (SYNTH_FREF * (n<<(3*v)))/m; 824150850Sscottl if (Fvco < SYNTH_FMIN || Fvco > SYNTH_FMAX) continue; 825150850Sscottl Fout = Fvco / (1<<(x+r)); 826150850Sscottl if (Fout >= Ftarg) 827150850Sscottl newdiff = Fout - Ftarg; 828150850Sscottl else 829150850Sscottl newdiff = Ftarg - Fout; 830150850Sscottl if (bestF >= Ftarg) 831150850Sscottl olddiff = bestF - Ftarg; 832150850Sscottl else 833150850Sscottl olddiff = Ftarg - bestF; 834150850Sscottl if ((newdiff < olddiff) || 835150850Sscottl ((newdiff == olddiff) && (Fvco < bestV))) 836150850Sscottl { 837150850Sscottl config.synth.n = n; 838150850Sscottl config.synth.m = m; 839150850Sscottl config.synth.v = v; 840150850Sscottl config.synth.x = x; 841150850Sscottl config.synth.r = r; 842150850Sscottl config.synth.prescale = prescale; 843150850Sscottl bestF = Fout; 844150850Sscottl bestV = Fvco; 845150850Sscottl } 846150850Sscottl } 847150850Sscottl#if 0 848150850Sscottl printf("Fbest=%.0f, Ftarg=%u, Fout=%.0f\n", bestF>>prescale, target, bestF); 849150850Sscottl printf("N=%u, M=%u, V=%u, X=%u, R=%u\n", config.synth.n, 850150850Sscottl config.synth.m, config.synth.v, config.synth.x, config.synth.r); 851150850Sscottl#endif 852150850Sscottl } 853150850Sscottl 854150850Sscottlvoid print_cable_len() 855150850Sscottl { 856150850Sscottl printf("Cable length:\t\t%d meters\n", config.cable_len); 857150850Sscottl } 858150850Sscottl 859150850Sscottlvoid print_cable_type() 860150850Sscottl { 861150850Sscottl printf("Cable type:\t\t"); 862150850Sscottl if (status.cable_type > 7) 863150850Sscottl printf("unknown cable_type: %d\n", status.cable_type); 864150850Sscottl else 865150850Sscottl printf("%s\n", ssi_cables[status.cable_type]); 866150850Sscottl } 867150850Sscottl 868150850Sscottlvoid print_time_slots() 869150850Sscottl { 870150850Sscottl printf("TimeSlot [31-0]:\t0x%08X\n", config.time_slots); 871150850Sscottl } 872150850Sscottl 873150850Sscottlvoid print_scrambler() 874150850Sscottl { 875150850Sscottl printf("Scrambler:\t\t"); 876150850Sscottl if (config.scrambler == CFG_SCRAM_OFF) 877150850Sscottl printf("off\n"); 878150850Sscottl else if (config.scrambler == CFG_SCRAM_DL_KEN) 879150850Sscottl printf("DigLink/Kentrox: X^43+1\n"); 880150850Sscottl else if (config.scrambler == CFG_SCRAM_LARS) 881150850Sscottl printf("Larse: X^20+X^17+1 w/28ZS\n"); 882150850Sscottl else 883150850Sscottl printf("unknown scrambler: %d\n", config.scrambler); 884150850Sscottl } 885150850Sscottl 886150850Sscottldouble vga_dbs(u_int8_t vga) 887150850Sscottl { 888150850Sscottl if (vga < 0x0F) return 0.0; 889150850Sscottl if ((vga >= 0x0F) && (vga <= 0x1B)) return 0.0 + 0.77 * (vga - 0x0F); 890150850Sscottl if ((vga >= 0x1C) && (vga <= 0x33)) return 10.0 + 1.25 * (vga - 0x1C); 891150850Sscottl if ((vga >= 0x34) && (vga <= 0x39)) return 40.0 + 1.67 * (vga - 0x34); 892216597Suqs if ((vga >= 0x3A) && (vga < 0x3F)) return 50.0 + 2.80 * (vga - 0x3A); 893216597Suqs return 64.0; 894150850Sscottl } 895150850Sscottl 896150850Sscottlvoid print_rx_gain() 897150850Sscottl { 898150850Sscottl printf("Rx gain max:\t\t"); 899150850Sscottl 900150850Sscottl if (config.rx_gain == CFG_GAIN_AUTO) 901150850Sscottl printf("auto-set to %02.1f dB\n", 902150850Sscottl vga_dbs(read_framer(Bt8370_VGA_MAX) & 0x3F)); 903150850Sscottl else 904150850Sscottl printf("up to %02.1f dB\n", vga_dbs(config.rx_gain)); 905150850Sscottl } 906150850Sscottl 907150850Sscottlvoid print_tx_lbo() 908150850Sscottl { 909150850Sscottl u_int8_t saved_lbo = config.tx_lbo; 910150850Sscottl 911150850Sscottl printf("LBO = "); 912150850Sscottl if (config.tx_lbo == CFG_LBO_AUTO) 913150850Sscottl { 914150850Sscottl config.tx_lbo = read_framer(Bt8370_TLIU_CR) & 0x30; 915150850Sscottl printf("auto-set to "); 916150850Sscottl } 917150850Sscottl 918150850Sscottl switch (config.tx_lbo) 919150850Sscottl { 920150850Sscottl case CFG_LBO_0DB: 921150850Sscottl printf("0 dB\n"); 922150850Sscottl break; 923150850Sscottl case CFG_LBO_7DB: 924150850Sscottl printf("7.5 dB\n"); 925150850Sscottl break; 926150850Sscottl case CFG_LBO_15DB: 927150850Sscottl printf("15 dB\n"); 928150850Sscottl break; 929150850Sscottl case CFG_LBO_22DB: 930150850Sscottl printf("22.5 dB\n"); 931150850Sscottl break; 932150850Sscottl default: 933150850Sscottl printf("unknown tx_lbo: %d\n", config.tx_lbo); 934150850Sscottl break; 935150850Sscottl } 936150850Sscottl 937150850Sscottl if (saved_lbo == CFG_LBO_AUTO) 938150850Sscottl config.tx_lbo = saved_lbo; 939150850Sscottl } 940150850Sscottl 941150850Sscottlvoid print_tx_pulse() 942150850Sscottl { 943150850Sscottl u_int8_t saved_pulse = config.tx_pulse; 944150850Sscottl 945150850Sscottl printf("Tx pulse shape:\t\t"); 946150850Sscottl if (config.tx_pulse == CFG_PULSE_AUTO) 947150850Sscottl { 948150850Sscottl config.tx_pulse = read_framer(Bt8370_TLIU_CR) & 0x0E; 949150850Sscottl printf("auto-set to "); 950150850Sscottl } 951150850Sscottl 952150850Sscottl switch (config.tx_pulse) 953150850Sscottl { 954150850Sscottl case CFG_PULSE_T1DSX0: 955150850Sscottl printf("T1-DSX: 0 to 40 meters\n"); 956150850Sscottl break; 957150850Sscottl case CFG_PULSE_T1DSX1: 958150850Sscottl printf("T1-DSX: 40 to 80 meters\n"); 959150850Sscottl break; 960150850Sscottl case CFG_PULSE_T1DSX2: 961150850Sscottl printf("T1-DSX: 80 to 120 meters\n"); 962150850Sscottl break; 963150850Sscottl case CFG_PULSE_T1DSX3: 964150850Sscottl printf("T1-DSX: 120 to 160 meters\n"); 965150850Sscottl break; 966150850Sscottl case CFG_PULSE_T1DSX4: 967150850Sscottl printf("T1-DSX: 160 to 200 meters\n"); 968150850Sscottl break; 969150850Sscottl case CFG_PULSE_E1COAX: 970150850Sscottl printf("E1: Twin Coax\n"); 971150850Sscottl break; 972150850Sscottl case CFG_PULSE_E1TWIST: 973150850Sscottl printf("E1: Twisted Pairs\n"); 974150850Sscottl break; 975150850Sscottl case CFG_PULSE_T1CSU: 976150850Sscottl printf("T1-CSU; "); 977150850Sscottl print_tx_lbo(); 978150850Sscottl break; 979150850Sscottl default: 980150850Sscottl printf("unknown tx_pulse: %d\n", config.tx_pulse); 981150850Sscottl break; 982150850Sscottl } 983150850Sscottl 984150850Sscottl if (saved_pulse == CFG_PULSE_AUTO) 985150850Sscottl config.tx_pulse = saved_pulse; 986150850Sscottl } 987150850Sscottl 988150850Sscottlvoid print_ssi_sigs() 989150850Sscottl { 990150850Sscottl u_int32_t mii16 = status.snmp.ssi.sigs; 991150850Sscottl char *on = "On", *off = "Off"; 992150850Sscottl 993150850Sscottl printf("Modem signals:\t\tDTR=%s DSR=%s RTS=%s CTS=%s\n", 994150850Sscottl (mii16 & MII16_SSI_DTR) ? on : off, 995150850Sscottl (mii16 & MII16_SSI_DSR) ? on : off, 996150850Sscottl (mii16 & MII16_SSI_RTS) ? on : off, 997150850Sscottl (mii16 & MII16_SSI_CTS) ? on : off); 998150850Sscottl printf("Modem signals:\t\tDCD=%s RI=%s LL=%s RL=%s TM=%s\n", 999150850Sscottl (mii16 & MII16_SSI_DCD) ? on : off, 1000150850Sscottl (mii16 & MII16_SSI_RI) ? on : off, 1001150850Sscottl (mii16 & MII16_SSI_LL) ? on : off, 1002150850Sscottl (mii16 & MII16_SSI_RL) ? on : off, 1003150850Sscottl (mii16 & MII16_SSI_TM) ? on : off); 1004150850Sscottl } 1005150850Sscottl 1006150850Sscottlvoid print_hssi_sigs() 1007150850Sscottl { 1008150850Sscottl u_int32_t mii16 = status.snmp.hssi.sigs; 1009150850Sscottl char *on = "On", *off = "Off"; 1010150850Sscottl 1011150850Sscottl printf("Modem signals:\t\tTA=%s CA=%s\n", 1012150850Sscottl (mii16 & MII16_HSSI_TA) ? on : off, 1013150850Sscottl (mii16 & MII16_HSSI_CA) ? on : off); 1014150850Sscottl printf("Modem signals:\t\tLA=%s LB=%s LC=%s TM=%s\n", 1015150850Sscottl (mii16 & MII16_HSSI_LA) ? on : off, 1016150850Sscottl (mii16 & MII16_HSSI_LB) ? on : off, 1017150850Sscottl (mii16 & MII16_HSSI_LC) ? on : off, 1018150850Sscottl (mii16 & MII16_HSSI_TM) ? on : off); 1019150850Sscottl } 1020150850Sscottl 1021150850Sscottlvoid print_events() 1022150850Sscottl { 1023150850Sscottl char *time; 1024150850Sscottl struct timeval tv; 1025150850Sscottl struct timezone tz; 1026150850Sscottl 1027150850Sscottl gettimeofday(&tv, &tz); 1028150850Sscottl time = (char *)ctime((time_t *)&tv); 1029150850Sscottl printf("Current time:\t\t%s", time); 1030150850Sscottl if (status.cntrs.reset_time.tv_sec < 1000) 1031150850Sscottl time = "Never\n"; 1032150850Sscottl else 1033150850Sscottl time = (char *)ctime((time_t *)&status.cntrs.reset_time.tv_sec); 1034150850Sscottl printf("Cntrs reset:\t\t%s", time); 1035150850Sscottl 1036150850Sscottl if (status.cntrs.ibytes) printf("Rx bytes:\t\t%qu\n", status.cntrs.ibytes); 1037150850Sscottl if (status.cntrs.obytes) printf("Tx bytes:\t\t%qu\n", status.cntrs.obytes); 1038150850Sscottl if (status.cntrs.ipackets) printf("Rx packets:\t\t%qu\n", status.cntrs.ipackets); 1039150850Sscottl if (status.cntrs.opackets) printf("Tx packets:\t\t%qu\n", status.cntrs.opackets); 1040150850Sscottl if (status.cntrs.ierrors) printf("Rx errors:\t\t%u\n", status.cntrs.ierrors); 1041150850Sscottl if (status.cntrs.oerrors) printf("Tx errors:\t\t%u\n", status.cntrs.oerrors); 1042150850Sscottl if (status.cntrs.idiscards) printf("Rx discards:\t\t%u\n", status.cntrs.idiscards); 1043150850Sscottl if (status.cntrs.odiscards) printf("Tx discards:\t\t%u\n", status.cntrs.odiscards); 1044150850Sscottl if (status.cntrs.fifo_over) printf("Rx fifo overruns:\t%u\n", status.cntrs.fifo_over); 1045150850Sscottl if (status.cntrs.fifo_under) printf("Tx fifo underruns:\t%u\n", status.cntrs.fifo_under); 1046150850Sscottl if (status.cntrs.missed) printf("Rx missed:\t\t%u\n", status.cntrs.missed); 1047150850Sscottl if (status.cntrs.overruns) printf("Rx overruns:\t\t%u\n", status.cntrs.overruns); 1048150850Sscottl if (status.cntrs.fdl_pkts) printf("Rx FDL pkts:\t\t%u\n", status.cntrs.fdl_pkts); 1049150850Sscottl if (status.cntrs.crc_errs) printf("Rx CRC:\t\t\t%u\n", status.cntrs.crc_errs); 1050150850Sscottl if (status.cntrs.lcv_errs) printf("Rx line code:\t\t%u\n", status.cntrs.lcv_errs); 1051150850Sscottl if (status.cntrs.frm_errs) printf("Rx F-bits:\t\t%u\n", status.cntrs.frm_errs); 1052150850Sscottl if (status.cntrs.febe_errs) printf("Rx FEBE:\t\t%u\n", status.cntrs.febe_errs); 1053150850Sscottl if (status.cntrs.par_errs) printf("Rx P-parity:\t\t%u\n", status.cntrs.par_errs); 1054150850Sscottl if (status.cntrs.cpar_errs) printf("Rx C-parity:\t\t%u\n", status.cntrs.cpar_errs); 1055150850Sscottl if (status.cntrs.mfrm_errs) printf("Rx M-bits:\t\t%u\n", status.cntrs.mfrm_errs); 1056150850Sscottl if (config.debug) 1057150850Sscottl { /* These events are hard to explain and may worry users, */ 1058150850Sscottl if (status.cntrs.rxdma) printf("Rx no buffs:\t\t%u\n", status.cntrs.rxdma); 1059150850Sscottl if (status.cntrs.txdma) printf("Tx no descs:\t\t%u\n", status.cntrs.txdma); 1060150850Sscottl if (status.cntrs.lck_watch) printf("Lck watch:\t\t%u\n", status.cntrs.lck_watch); 1061150850Sscottl if (status.cntrs.lck_ioctl) printf("Lck ioctl:\t\t%u\n", status.cntrs.lck_ioctl); 1062150850Sscottl if (status.cntrs.lck_intr) printf("Lck intr:\t\t%u\n", status.cntrs.lck_intr); 1063150850Sscottl } 1064150850Sscottl } 1065150850Sscottl 1066150850Sscottlvoid print_summary() 1067150850Sscottl { 1068150850Sscottl switch(status.card_type) 1069150850Sscottl { 1070150850Sscottl case TLP_CSID_HSSI: 1071150850Sscottl { 1072150850Sscottl print_card_name(); 1073150850Sscottl print_card_type(); 1074150850Sscottl print_debug(); 1075150850Sscottl print_status(); 1076150850Sscottl print_tx_speed(); 1077150850Sscottl print_line_prot(); 1078150850Sscottl print_crc_len(); 1079150850Sscottl print_loop_back(); 1080150850Sscottl print_tx_clk_src(); 1081150850Sscottl print_hssi_sigs(); 1082150850Sscottl print_events(); 1083150850Sscottl break; 1084150850Sscottl } 1085150850Sscottl case TLP_CSID_T3: 1086150850Sscottl { 1087150850Sscottl print_card_name(); 1088150850Sscottl print_card_type(); 1089150850Sscottl print_debug(); 1090150850Sscottl print_status(); 1091150850Sscottl print_tx_speed(); 1092150850Sscottl print_line_prot(); 1093150850Sscottl print_crc_len(); 1094150850Sscottl print_loop_back(); 1095150850Sscottl print_format(); 1096150850Sscottl print_cable_len(); 1097150850Sscottl print_scrambler(); 1098150850Sscottl print_events(); 1099150850Sscottl break; 1100150850Sscottl } 1101150850Sscottl case TLP_CSID_SSI: 1102150850Sscottl { 1103150850Sscottl print_card_name(); 1104150850Sscottl print_card_type(); 1105150850Sscottl print_debug(); 1106150850Sscottl print_status(); 1107150850Sscottl print_tx_speed(); 1108150850Sscottl print_line_prot(); 1109150850Sscottl print_crc_len(); 1110150850Sscottl print_loop_back(); 1111150850Sscottl print_dte_dce(); 1112150850Sscottl print_synth_freq(); 1113150850Sscottl print_cable_type(); 1114150850Sscottl print_ssi_sigs(); 1115150850Sscottl print_events(); 1116150850Sscottl break; 1117150850Sscottl } 1118150850Sscottl case TLP_CSID_T1E1: 1119150850Sscottl { 1120150850Sscottl print_card_name(); 1121150850Sscottl print_card_type(); 1122150850Sscottl print_debug(); 1123150850Sscottl print_status(); 1124150850Sscottl print_tx_speed(); 1125150850Sscottl print_line_prot(); 1126150850Sscottl print_crc_len(); 1127150850Sscottl print_loop_back(); 1128150850Sscottl print_tx_clk_src(); 1129150850Sscottl print_format(); 1130150850Sscottl print_time_slots(); 1131150850Sscottl print_cable_len(); 1132150850Sscottl print_tx_pulse(); 1133150850Sscottl print_rx_gain(); 1134150850Sscottl print_events(); 1135150850Sscottl break; 1136150850Sscottl } 1137150850Sscottl case TLP_CSID_HSSIc: 1138150850Sscottl { 1139150850Sscottl print_card_name(); 1140150850Sscottl print_card_type(); 1141150850Sscottl print_debug(); 1142150850Sscottl print_status(); 1143150850Sscottl print_line_prot(); 1144150850Sscottl print_tx_speed(); 1145150850Sscottl print_crc_len(); 1146150850Sscottl print_loop_back(); 1147150850Sscottl print_tx_clk_src(); 1148150850Sscottl print_dte_dce(); 1149150850Sscottl print_synth_freq(); 1150150850Sscottl print_hssi_sigs(); 1151150850Sscottl print_events(); 1152150850Sscottl break; 1153150850Sscottl } 1154150850Sscottl default: 1155150850Sscottl { 1156150850Sscottl printf("%s: Unknown card type: %d\n", ifname, status.card_type); 1157150850Sscottl break; 1158150850Sscottl } 1159150850Sscottl } 1160150850Sscottl } 1161150850Sscottl 1162150850Sscottlchar *print_t3_bop(int bop_code) 1163150850Sscottl { 1164150850Sscottl switch(bop_code) 1165150850Sscottl { 1166150850Sscottl case 0x00: 1167150850Sscottl return "far end LOF"; 1168150850Sscottl case 0x0E: 1169150850Sscottl return "far end LOS"; 1170150850Sscottl case 0x16: 1171150850Sscottl return "far end AIS"; 1172150850Sscottl case 0x1A: 1173150850Sscottl return "far end IDL"; 1174150850Sscottl case 0x07: 1175150850Sscottl return "Line Loopback activate"; 1176150850Sscottl case 0x1C: 1177150850Sscottl return "Line Loopback deactivate"; 1178150850Sscottl case 0x1B: 1179150850Sscottl return "Entire DS3 line"; 1180150850Sscottl default: 1181150850Sscottl return "Unknown BOP code"; 1182150850Sscottl } 1183150850Sscottl } 1184150850Sscottl 1185150850Sscottlvoid print_t3_snmp() 1186150850Sscottl { 1187150850Sscottl printf("SNMP performance data:\n"); 1188150850Sscottl printf(" LCV=%d", status.snmp.t3.lcv); 1189150850Sscottl printf(" LOS=%d", (status.snmp.t3.line & TLINE_LOS) ? 1 : 0); 1190150850Sscottl printf(" PCV=%d", status.snmp.t3.pcv); 1191150850Sscottl printf(" CCV=%d", status.snmp.t3.ccv); 1192150850Sscottl printf(" AIS=%d", (status.snmp.t3.line & TLINE_RX_AIS) ? 1 : 0); 1193150850Sscottl printf(" SEF=%d", (status.snmp.t3.line & T1LINE_SEF) ? 1 : 0); 1194150850Sscottl printf(" OOF=%d", (status.snmp.t3.line & TLINE_LOF) ? 1 : 0); 1195150850Sscottl printf(" FEBE=%d", status.snmp.t3.febe); 1196150850Sscottl printf(" RAI=%d", (status.snmp.t3.line & TLINE_RX_RAI) ? 1 : 0); 1197150850Sscottl printf("\n"); 1198150850Sscottl } 1199150850Sscottl 1200150850Sscottlvoid print_t3_dsu() 1201150850Sscottl { 1202150850Sscottl char *no = "No", *yes = "Yes"; 1203150850Sscottl u_int16_t mii16 = read_mii(16); 1204150850Sscottl u_int8_t ctl1 = read_framer(T3CSR_CTL1); 1205150850Sscottl u_int8_t ctl8 = read_framer(T3CSR_CTL8); 1206150850Sscottl u_int8_t stat9 = read_framer(T3CSR_STAT9); 1207150850Sscottl u_int8_t ctl12 = read_framer(T3CSR_CTL12); 1208150850Sscottl u_int8_t stat16 = read_framer(T3CSR_STAT16); 1209150850Sscottl 1210150850Sscottl printf("Framing: \t\t%s\n", ctl1 & CTL1_M13MODE ? "M13" : "CPAR"); 1211150850Sscottl print_tx_speed(); 1212150850Sscottl printf("Scrambler: \t\t%s\n", mii16 & MII16_DS3_SCRAM ? yes : no); 1213150850Sscottl printf("Scram poly: \t\t%s\n", mii16 & MII16_DS3_POLY ? "X^20" : "X^43"); 1214150850Sscottl printf("Cable length \t\t%s\n", mii16 & MII16_DS3_ZERO ? "Short" : "Long"); 1215150850Sscottl printf("Line loop: \t\t%s\n", mii16 & MII16_DS3_LNLBK ? yes : no); 1216150850Sscottl printf("Payload loop: \t\t%s\n", ctl12 & CTL12_RTPLOOP ? yes : no); 1217150850Sscottl printf("Frame loop: \t\t%s\n", ctl1 & CTL1_3LOOP ? yes : no); 1218150850Sscottl printf("Host loop: \t\t%s\n", mii16 & MII16_DS3_TRLBK ? yes : no); 1219150850Sscottl printf("Transmit RAI: \t\t%s\n", ctl1 & CTL1_XTX ? no : yes); 1220150850Sscottl printf("Receive RAI \t\t%s\n", stat16 & STAT16_XERR ? yes : no); 1221150850Sscottl printf("Transmit AIS: \t\t%s\n", ctl1 & CTL1_TXAIS ? yes : no); 1222150850Sscottl printf("Receive AIS: \t\t%s\n", stat16 & STAT16_RAIS ? yes : no); 1223150850Sscottl printf("Transmit IDLE: \t\t%s\n", ctl1 & CTL1_TXIDL ? yes : no); 1224150850Sscottl printf("Receive IDLE: \t\t%s\n", stat16 & STAT16_RIDL ? yes : no); 1225150850Sscottl printf("Transmit BLUE: \t\t%s\n", ctl8 & CTL8_TBLU ? yes : no); 1226150850Sscottl printf("Receive BLUE: \t\t%s\n", stat9 & STAT9_RBLU ? yes : no); 1227150850Sscottl printf("Loss of Signal:\t\t%s\n", stat16 & STAT16_RLOS ? yes : no); 1228150850Sscottl printf("Loss of Frame: \t\t%s\n", stat16 & STAT16_ROOF ? yes : no); 1229150850Sscottl printf("Sev Err Frms: \t\t%s\n", stat16 & STAT16_SEF ? yes : no); 1230150850Sscottl printf("Code errors: \t\t%d\n", read_framer(T3CSR_CVLO) + (read_framer(T3CSR_CVHI)<<8)); 1231150850Sscottl printf("C-Par errors: \t\t%d\n", read_framer(T3CSR_CERR)); 1232150850Sscottl printf("P-Par errors: \t\t%d\n", read_framer(T3CSR_PERR)); 1233150850Sscottl printf("F-Bit errors: \t\t%d\n", read_framer(T3CSR_FERR)); 1234150850Sscottl printf("M-Bit errors: \t\t%d\n", read_framer(T3CSR_MERR)); 1235150850Sscottl printf("FarEndBitErrs: \t\t%d\n", read_framer(T3CSR_FEBE)); 1236150850Sscottl printf("Last Tx FEAC msg:\t0x%02X (%s)\n", 1237150850Sscottl read_framer(T3CSR_TX_FEAC) & 0x3F, 1238150850Sscottl print_t3_bop(read_framer(T3CSR_TX_FEAC) & 0x3F)); 1239150850Sscottl printf("Last dbl FEAC msg;\t0x%02X (%s)\n", 1240150850Sscottl read_framer(T3CSR_DBL_FEAC) & 0x3F, 1241150850Sscottl print_t3_bop(read_framer(T3CSR_DBL_FEAC) & 0x3F)); 1242150850Sscottl printf("Last Rx FEAC msg:\t0x%02X (%s)\n", 1243150850Sscottl read_framer(T3CSR_RX_FEAC) & 0x3F, 1244150850Sscottl print_t3_bop(read_framer(T3CSR_RX_FEAC) & 0x3F)); 1245150850Sscottl print_t3_snmp(); 1246150850Sscottl } 1247150850Sscottl 1248150850Sscottlvoid t3_cmd(int argc, char **argv) 1249150850Sscottl { 1250150850Sscottl int ch; 1251150850Sscottl 1252150850Sscottl while ((ch = getopt(argc, argv, "a:A:B:c:de:fF:lLsS:vV:")) != -1) 1253150850Sscottl { 1254150850Sscottl switch (ch) 1255150850Sscottl { 1256150850Sscottl case 'a': /* stop alarms */ 1257150850Sscottl { 1258150850Sscottl switch (optarg[0]) 1259150850Sscottl { 1260150850Sscottl case 'a': /* Stop sending AIS Signal */ 1261150850Sscottl { 1262150850Sscottl write_mii(16, 1263150850Sscottl read_mii(16) & ~MII16_DS3_FRAME); 1264150850Sscottl write_framer(T3CSR_CTL1, 1265150850Sscottl read_framer(T3CSR_CTL1) & ~CTL1_TXAIS); 1266150850Sscottl if (verbose) printf("Stop sending Alarm Indication Signal (AIS)\n"); 1267150850Sscottl break; 1268150850Sscottl } 1269150850Sscottl case 'b': /* Stop sending Blue signal */ 1270150850Sscottl { 1271150850Sscottl write_mii(16, 1272150850Sscottl read_mii(16) & ~MII16_DS3_FRAME); 1273150850Sscottl write_framer(T3CSR_CTL8, 1274150850Sscottl read_framer(T3CSR_CTL8) & ~CTL8_TBLU); 1275150850Sscottl if (verbose) printf("Stop sending Blue signal\n"); 1276150850Sscottl break; 1277150850Sscottl } 1278150850Sscottl case 'i': /* Stop sending IDLE signal */ 1279150850Sscottl { 1280150850Sscottl write_framer(T3CSR_CTL1, 1281150850Sscottl read_framer(T3CSR_CTL1) & ~CTL1_TXIDL); 1282150850Sscottl if (verbose) printf("Stop sending IDLE signal\n"); 1283150850Sscottl break; 1284150850Sscottl } 1285150850Sscottl case 'y': /* Stop sending Yellow alarm */ 1286150850Sscottl { 1287150850Sscottl write_framer(T3CSR_CTL1, 1288150850Sscottl read_framer(T3CSR_CTL1) | CTL1_XTX); 1289150850Sscottl if (verbose) printf("Stop sending Yellow alarm\n"); 1290150850Sscottl break; 1291150850Sscottl } 1292150850Sscottl default: 1293150850Sscottl printf("Unknown alarm: %c\n", optarg[0]); 1294150850Sscottl break; 1295150850Sscottl } 1296150850Sscottl break; 1297150850Sscottl } 1298150850Sscottl case 'A': /* start alarms */ 1299150850Sscottl { 1300150850Sscottl switch (optarg[0]) 1301150850Sscottl { 1302150850Sscottl case 'a': /* Start sending AIS Signal */ 1303150850Sscottl { 1304150850Sscottl write_mii(16, 1305150850Sscottl read_mii(16) | MII16_DS3_FRAME); 1306150850Sscottl write_framer(T3CSR_CTL1, 1307150850Sscottl read_framer(T3CSR_CTL1) | CTL1_TXAIS); 1308150850Sscottl if (verbose) printf("Sending AIS signal (framed 1010..)\n"); 1309150850Sscottl break; 1310150850Sscottl } 1311150850Sscottl case 'b': /* Start sending Blue signal */ 1312150850Sscottl { 1313150850Sscottl write_mii(16, 1314150850Sscottl read_mii(16) | MII16_DS3_FRAME); 1315150850Sscottl write_framer(T3CSR_CTL8, 1316150850Sscottl read_framer(T3CSR_CTL8) | CTL8_TBLU); 1317150850Sscottl if (verbose) printf("Sending Blue signal (unframed all 1s)\n"); 1318150850Sscottl break; 1319150850Sscottl } 1320150850Sscottl case 'i': /* Start sending IDLE signal */ 1321150850Sscottl { 1322150850Sscottl write_framer(T3CSR_CTL1, 1323150850Sscottl read_framer(T3CSR_CTL1) | CTL1_TXIDL); 1324150850Sscottl if (verbose) printf("Sending IDLE signal (framed 1100..)\n"); 1325150850Sscottl break; 1326150850Sscottl } 1327150850Sscottl case 'y': /* Start sending Yellow alarm */ 1328150850Sscottl { 1329150850Sscottl write_framer(T3CSR_CTL1, 1330150850Sscottl read_framer(T3CSR_CTL1) & ~CTL1_XTX); 1331150850Sscottl if (verbose) printf("Sending Yellow alarm (X-bits=0)\n"); 1332150850Sscottl break; 1333150850Sscottl } 1334150850Sscottl default: 1335150850Sscottl printf("Unknown alarm: %c\n", optarg[0]); 1336150850Sscottl break; 1337150850Sscottl } 1338150850Sscottl break; 1339150850Sscottl } 1340150850Sscottl case 'B': /* send BOP msg */ 1341150850Sscottl { 1342150850Sscottl u_int8_t bop = strtoul(optarg, NULL, 0); 1343150850Sscottl write_framer(T3CSR_TX_FEAC, 0xC0 + bop); 1344150850Sscottl if (verbose) printf("Sent '0x%02X' BOP msg 10 times\n", bop); 1345150850Sscottl break; 1346150850Sscottl } 1347150850Sscottl case 'c': /* set cable length */ 1348150850Sscottl { 1349150850Sscottl config.cable_len = strtoul(optarg, NULL, 0); 1350150850Sscottl if (verbose) print_cable_len(); 1351150850Sscottl update = 1; 1352150850Sscottl break; 1353150850Sscottl } 1354150850Sscottl case 'd': /* DSU status */ 1355150850Sscottl case 's': /* deprecated */ 1356150850Sscottl { 1357150850Sscottl print_t3_dsu(); 1358150850Sscottl break; 1359150850Sscottl } 1360150850Sscottl case 'e': /* set framimg format */ 1361150850Sscottl { 1362150850Sscottl config.format = strtoul(optarg, NULL, 0); 1363150850Sscottl if (verbose) print_format(); 1364150850Sscottl update = 1; 1365150850Sscottl break; 1366150850Sscottl } 1367150850Sscottl case 'f': /* read and print framer regs */ 1368150850Sscottl { 1369150850Sscottl int i; 1370150850Sscottl printf("TXC03401 regs:\n"); 1371150850Sscottl printf(" 0 1 2 3 4 5 6 7"); 1372150850Sscottl for (i=0; i<21; i++) 1373150850Sscottl { 1374150850Sscottl if (i%8 == 0) printf("\n%02X: ", i); 1375150850Sscottl printf("%02X ", read_framer(i)); 1376150850Sscottl } 1377150850Sscottl printf("\n\n"); 1378150850Sscottl break; 1379150850Sscottl } 1380150850Sscottl case 'F': /* write framer reg */ 1381150850Sscottl { 1382150850Sscottl u_int32_t addr = strtoul(optarg, NULL, 0); 1383150850Sscottl u_int32_t data = strtoul(argv[optind++], NULL, 0); 1384150850Sscottl write_framer(addr, data); 1385150850Sscottl if (verbose) 1386150850Sscottl { 1387150850Sscottl data = read_framer(addr); 1388150850Sscottl printf("Write framer register: addr = 0x%02X data = 0x%02X\n", addr, data); 1389150850Sscottl } 1390150850Sscottl break; 1391150850Sscottl } 1392150850Sscottl case 'l': /* send DS3 line loopback deactivate BOP cmd */ 1393150850Sscottl { 1394150850Sscottl ioctl_snmp_send(TSEND_RESET); 1395150850Sscottl if (verbose) printf("Sent 'DS3 Line Loopback deactivate' BOP cmd\n"); 1396150850Sscottl break; 1397150850Sscottl } 1398150850Sscottl case 'L': /* send DS3 line loopback activate BOP cmd */ 1399150850Sscottl { 1400150850Sscottl ioctl_snmp_send(TSEND_LINE); 1401150850Sscottl if (verbose) printf("Sent 'DS3 Line Loopback activate' BOP cmd\n"); 1402150850Sscottl break; 1403150850Sscottl } 1404150850Sscottl case 'S': /* set scrambler */ 1405150850Sscottl { 1406150850Sscottl config.scrambler = strtoul(optarg, NULL, 0); 1407150850Sscottl if (verbose) print_scrambler(); 1408150850Sscottl update = 1; 1409150850Sscottl break; 1410150850Sscottl } 1411150850Sscottl case 'v': /* set verbose mode */ 1412150850Sscottl { 1413150850Sscottl verbose = 1; 1414150850Sscottl break; 1415150850Sscottl } 1416150850Sscottl case 'V': /* set T3 freq control DAC */ 1417150850Sscottl { 1418150850Sscottl u_int32_t dac = strtoul(optarg, NULL, 0); 1419150850Sscottl write_dac(dac); 1420150850Sscottl if (verbose) printf("VCXO DAC value is %d\n", dac); 1421150850Sscottl break; 1422150850Sscottl } 1423150850Sscottl default: 1424150850Sscottl { 1425150850Sscottl printf("Unknown command char: %c\n", ch); 1426150850Sscottl exit(1); 1427150850Sscottl } /* case */ 1428150850Sscottl } /* switch */ 1429150850Sscottl } /* while */ 1430150850Sscottl } /* proc */ 1431150850Sscottl 1432150850Sscottlvoid print_test_pattern(int patt) 1433150850Sscottl { 1434150850Sscottl printf("Test Pattern:\t\t"); 1435150850Sscottl switch (patt) 1436150850Sscottl { 1437150850Sscottl case 0: 1438150850Sscottl printf("unframed X^11+X^9+1\n"); 1439150850Sscottl break; 1440150850Sscottl case 1: 1441150850Sscottl printf("unframed X^15+X^14+1\n"); 1442150850Sscottl break; 1443150850Sscottl case 2: 1444150850Sscottl printf("unframed X^20+X^17+1\n"); 1445150850Sscottl break; 1446150850Sscottl case 3: 1447150850Sscottl printf("unframed X^23+X^18+1\n"); 1448150850Sscottl break; 1449150850Sscottl case 4: 1450150850Sscottl printf("unframed X^11+X^9+1 w/7ZS\n"); 1451150850Sscottl break; 1452150850Sscottl case 5: 1453150850Sscottl printf("unframed X^15+X^14+1 w/7ZS\n"); 1454150850Sscottl break; 1455150850Sscottl case 6: 1456150850Sscottl printf("unframed X^20+X^17+1 w/14ZS (QRSS)\n"); 1457150850Sscottl break; 1458150850Sscottl case 7: 1459150850Sscottl printf("unframed X^23+X^18+1 w/14ZS\n"); 1460150850Sscottl break; 1461150850Sscottl case 8: 1462150850Sscottl printf("framed X^11+X^9+1\n"); 1463150850Sscottl break; 1464150850Sscottl case 9: 1465150850Sscottl printf("framed X^15+X^14+1\n"); 1466150850Sscottl break; 1467150850Sscottl case 10: 1468150850Sscottl printf("framed X^20+X^17+1\n"); 1469150850Sscottl break; 1470150850Sscottl case 11: 1471150850Sscottl printf("framed X^23+X^18+1\n"); 1472150850Sscottl break; 1473150850Sscottl case 12:; 1474150850Sscottl printf("framed X^11+X^9+1 w/7ZS\n"); 1475150850Sscottl break; 1476150850Sscottl case 13: 1477150850Sscottl printf("framed X^15+X^14+1 w/7ZS\n"); 1478150850Sscottl break; 1479150850Sscottl case 14: 1480150850Sscottl printf("framed X^20+X^17+1 w/14ZS (QRSS)\n"); 1481150850Sscottl break; 1482150850Sscottl case 15: 1483150850Sscottl printf("framed X^23+X^18+1 w/14ZS\n"); 1484150850Sscottl break; 1485150850Sscottl } 1486150850Sscottl } 1487150850Sscottl 1488150850Sscottlchar *print_t1_bop(int bop_code) 1489150850Sscottl { 1490150850Sscottl switch(bop_code) 1491150850Sscottl { 1492150850Sscottl case 0x00: 1493150850Sscottl return "Yellow Alarm (far end LOF)"; 1494150850Sscottl case 0x07: 1495150850Sscottl return "Line Loop up"; 1496150850Sscottl case 0x1C: 1497150850Sscottl return "Line Loop down"; 1498150850Sscottl case 0x0A: 1499150850Sscottl return "Payload Loop up"; 1500150850Sscottl case 0x19: 1501150850Sscottl return "Payload Loop down"; 1502150850Sscottl case 0x09: 1503150850Sscottl return "Network Loop up"; 1504150850Sscottl case 0x12: 1505150850Sscottl return "Network Loop down"; 1506150850Sscottl default: 1507150850Sscottl return "Unknown BOP code"; 1508150850Sscottl } 1509150850Sscottl } 1510150850Sscottl 1511150850Sscottlvoid print_far_report(int index) 1512150850Sscottl { 1513150850Sscottl u_int16_t far = status.snmp.t1.prm[index]; 1514150850Sscottl 1515150850Sscottl printf(" SEQ=%d ", (far & T1PRM_SEQ)>>8); 1516150850Sscottl if (far & T1PRM_G1) printf("CRC=1"); 1517150850Sscottl else if (far & T1PRM_G2) printf("CRC=1 to 5"); 1518150850Sscottl else if (far & T1PRM_G3) printf("CRC=5 to 10"); 1519150850Sscottl else if (far & T1PRM_G4) printf("CRC=10 to 100"); 1520150850Sscottl else if (far & T1PRM_G5) printf("CRC=100 to 319"); 1521150850Sscottl else if (far & T1PRM_G6) printf("CRC>=320"); 1522150850Sscottl else printf("CRC=0"); 1523150850Sscottl printf(" SE=%d", (far & T1PRM_SE) ? 1 : 0); 1524150850Sscottl printf(" FE=%d", (far & T1PRM_FE) ? 1 : 0); 1525150850Sscottl printf(" LV=%d", (far & T1PRM_LV) ? 1 : 0); 1526150850Sscottl printf(" SL=%d", (far & T1PRM_SL) ? 1 : 0); 1527150850Sscottl printf(" LB=%d", (far & T1PRM_LB) ? 1 : 0); 1528150850Sscottl printf("\n"); 1529150850Sscottl } 1530150850Sscottl 1531150850Sscottlvoid print_t1_snmp() 1532150850Sscottl { 1533150850Sscottl printf("SNMP Near-end performance data:\n"); 1534150850Sscottl printf(" LCV=%d", status.snmp.t1.lcv); 1535150850Sscottl printf(" LOS=%d", (status.snmp.t1.line & TLINE_LOS) ? 1 : 0); 1536150850Sscottl printf(" FE=%d", status.snmp.t1.fe); 1537150850Sscottl printf(" CRC=%d", status.snmp.t1.crc); 1538150850Sscottl printf(" AIS=%d", (status.snmp.t1.line & TLINE_RX_AIS) ? 1 : 0); 1539150850Sscottl printf(" SEF=%d", (status.snmp.t1.line & T1LINE_SEF) ? 1 : 0); 1540150850Sscottl printf(" OOF=%d", (status.snmp.t1.line & TLINE_LOF) ? 1 : 0); 1541150850Sscottl printf(" RAI=%d",(status.snmp.t1.line & TLINE_RX_RAI) ? 1 : 0); 1542150850Sscottl printf("\n"); 1543150850Sscottl if (config.format == CFG_FORMAT_T1ESF) 1544150850Sscottl { 1545150850Sscottl printf("ANSI Far-end performance reports:\n"); 1546150850Sscottl print_far_report(0); 1547150850Sscottl print_far_report(1); 1548150850Sscottl print_far_report(2); 1549150850Sscottl print_far_report(3); 1550150850Sscottl } 1551150850Sscottl } 1552150850Sscottl 1553150850Sscottlvoid print_t1_dsu() 1554150850Sscottl { 1555150850Sscottl char *no = "No", *yes = "Yes"; 1556150850Sscottl u_int16_t mii16 = read_mii(16); 1557150850Sscottl u_int8_t isr0 = read_framer(Bt8370_ISR0); 1558150850Sscottl u_int8_t loop = read_framer(Bt8370_LOOP); 1559150850Sscottl u_int8_t vga_max = read_framer(Bt8370_VGA_MAX) & 0x3F; 1560150850Sscottl u_int8_t alm1 = read_framer(Bt8370_ALM1); 1561150850Sscottl u_int8_t alm3 = read_framer(Bt8370_ALM3); 1562150850Sscottl u_int8_t talm = read_framer(Bt8370_TALM); 1563150850Sscottl u_int8_t tpatt = read_framer(Bt8370_TPATT); 1564150850Sscottl u_int8_t tpulse = read_framer(Bt8370_TLIU_CR); 1565150850Sscottl u_int8_t vga; 1566150850Sscottl u_int8_t saved_pulse, saved_lbo; 1567150850Sscottl 1568150850Sscottl /* d/c write required before read */ 1569150850Sscottl write_framer(Bt8370_VGA, 0); 1570150850Sscottl vga = read_framer(Bt8370_VGA) & 0x3F; 1571150850Sscottl 1572150850Sscottl print_format(); 1573150850Sscottl print_time_slots(); 1574150850Sscottl print_tx_clk_src(); 1575150850Sscottl print_tx_speed(); 1576150850Sscottl 1577150850Sscottl saved_pulse = config.tx_pulse; 1578150850Sscottl config.tx_pulse = tpulse & 0x0E; 1579150850Sscottl saved_lbo = config.tx_lbo; 1580150850Sscottl config.tx_lbo = tpulse & 0x30; 1581150850Sscottl print_tx_pulse(); 1582150850Sscottl config.tx_pulse = saved_pulse; 1583150850Sscottl config.tx_lbo = saved_lbo; 1584150850Sscottl 1585150850Sscottl printf("Tx outputs: \t\t%sabled\n", (mii16 & MII16_T1_XOE) ? "En" : "Dis"); 1586150850Sscottl printf("Line impedance:\t\t%s ohms\n", (mii16 & MII16_T1_Z) ? "120" : "100"); 1587150850Sscottl printf("Max line loss: \t\t%4.1f dB\n", vga_dbs(vga_max)); 1588150850Sscottl printf("Cur line loss: \t\t%4.1f dB\n", vga_dbs(vga)); 1589150850Sscottl printf("Invert data: \t\t%s\n", (mii16 & MII16_T1_INVERT) ? yes : no); 1590150850Sscottl printf("Line loop: \t\t%s\n", (loop & LOOP_LINE) ? yes : no); 1591150850Sscottl printf("Payload loop: \t\t%s\n", (loop & LOOP_PAYLOAD) ? yes : no); 1592150850Sscottl printf("Framer loop: \t\t%s\n", (loop & LOOP_FRAMER) ? yes : no); 1593150850Sscottl printf("Analog loop: \t\t%s\n", (loop & LOOP_ANALOG) ? yes : no); 1594150850Sscottl printf("Tx AIS: \t\t%s\n", ((talm & TALM_TAIS) || 1595150850Sscottl ((talm & TALM_AUTO_AIS) && (alm1 & ALM1_RLOS))) ? yes : no); 1596150850Sscottl printf("Rx AIS: \t\t%s\n", (alm1 & ALM1_RAIS) ? yes : no); 1597150850Sscottl if (((config.format & 1)==0) && (config.format != CFG_FORMAT_E1NONE)) 1598150850Sscottl { 1599150850Sscottl printf("Tx RAI: \t\t%s\n", ((talm & TALM_TYEL) || 1600150850Sscottl ((talm & TALM_AUTO_YEL) && (alm3 & ALM3_FRED))) ? yes : no); 1601150850Sscottl printf("Rx RAI: \t\t%s\n", (alm1 & ALM1_RYEL) ? yes : no); 1602150850Sscottl } 1603150850Sscottl if (config.format == CFG_FORMAT_T1ESF) 1604150850Sscottl { 1605150850Sscottl printf("Tx BOP RAI: \t\t%s\n", (alm1 & ALM1_RLOF) ? yes : no); 1606150850Sscottl printf("Rx BOP RAI: \t\t%s\n", (alm1 & ALM1_RMYEL) ? yes : no); 1607150850Sscottl } 1608150850Sscottl if ((config.format & 0x11) == 0x10) /* E1CAS */ 1609150850Sscottl { 1610150850Sscottl printf("Rx TS16 AIS: \t\t%s\n", (alm3 & ALM3_RMAIS) ? yes : no); 1611150850Sscottl printf("Tx TS16 RAI; \t\t%s\n", 1612150850Sscottl ((talm & TALM_AUTO_MYEL) && (alm3 & ALM3_SRED)) ? yes : no); 1613150850Sscottl } 1614150850Sscottl printf("Rx LOS analog: \t\t%s\n", (alm1 & ALM1_RALOS) ? yes : no); 1615150850Sscottl printf("Rx LOS digital:\t\t%s\n", (alm1 & ALM1_RLOS) ? yes : no); 1616150850Sscottl printf("Rx LOF: \t\t%s\n", (alm1 & ALM1_RLOF) ? yes : no); 1617150850Sscottl printf("Tx QRS: \t\t%s\n", (tpatt & 0x10) ? yes : no); 1618150850Sscottl printf("Rx QRS: \t\t%s\n", (isr0 & 0x10) ? yes : no); 1619150850Sscottl printf("LCV errors: \t\t%d\n", 1620150850Sscottl read_framer(Bt8370_LCV_LO) + (read_framer(Bt8370_LCV_HI)<<8)); 1621150850Sscottl if (config.format != CFG_FORMAT_E1NONE) 1622150850Sscottl { 1623150850Sscottl if ((config.format & 1)==0) printf("Far End Block Errors:\t%d\n", 1624150850Sscottl read_framer(Bt8370_FEBE_LO) + (read_framer(Bt8370_FEBE_HI)<<8)); 1625150850Sscottl printf("CRC errors: \t\t%d\n", 1626150850Sscottl read_framer(Bt8370_CRC_LO) + (read_framer(Bt8370_CRC_HI)<<8)); 1627150850Sscottl printf("Frame errors: \t\t%d\n", 1628150850Sscottl read_framer(Bt8370_FERR_LO) + (read_framer(Bt8370_FERR_HI)<<8)); 1629150850Sscottl printf("Sev Err Frms: \t\t%d\n", read_framer(Bt8370_AERR) & 0x03); 1630150850Sscottl printf("Change of Frm align:\t%d\n", (read_framer(Bt8370_AERR) & 0x0C)>>2); 1631150850Sscottl printf("Loss of Frame events:\t%d\n", (read_framer(Bt8370_AERR) & 0xF0)>>4); 1632150850Sscottl } 1633150850Sscottl if (config.format == CFG_FORMAT_T1ESF) 1634150850Sscottl { 1635150850Sscottl printf("Last Tx BOP msg:\t0x%02X (%s)\n", 1636150850Sscottl read_framer(Bt8370_TBOP), print_t1_bop(read_framer(Bt8370_TBOP))); 1637150850Sscottl printf("Last Rx BOP msg:\t0x%02X (%s)\n", 1638150850Sscottl read_framer(Bt8370_RBOP), print_t1_bop(read_framer(Bt8370_RBOP)&0x3F)); 1639150850Sscottl } 1640150850Sscottl print_t1_snmp(); 1641150850Sscottl } 1642150850Sscottl 1643150850Sscottlvoid t1_cmd(int argc, char **argv) 1644150850Sscottl { 1645150850Sscottl int ch; 1646150850Sscottl 1647150850Sscottl while ((ch = getopt(argc, argv, "a:A:B:c:de:E:fF:g:iIlLpPstT:u:U:vxX")) != -1) 1648150850Sscottl { 1649150850Sscottl switch (ch) 1650150850Sscottl { 1651150850Sscottl case 'a': /* stop alarms */ 1652150850Sscottl { 1653150850Sscottl switch (optarg[0]) 1654150850Sscottl { 1655150850Sscottl case 'y': /* Stop sending Yellow Alarm */ 1656150850Sscottl { 1657150850Sscottl if ((config.format == CFG_FORMAT_T1SF) || 1658150850Sscottl (config.format == CFG_FORMAT_E1NONE)) 1659150850Sscottl printf("No Yellow alarm for this frame format\n"); 1660150850Sscottl else if (config.format == CFG_FORMAT_T1ESF) 1661150850Sscottl write_framer(Bt8370_BOP, 0xE0); /* rbop 25, tbop off */ 1662150850Sscottl else 1663150850Sscottl { 1664150850Sscottl u_int8_t talm = read_framer(Bt8370_TALM); 1665150850Sscottl write_framer(Bt8370_TALM, talm & ~TALM_TYEL); 1666150850Sscottl } 1667150850Sscottl if (verbose) printf("Stop sending Yellow alarm\n"); 1668150850Sscottl break; 1669150850Sscottl } 1670150850Sscottl case 'a': /* Stop sending AIS */ 1671150850Sscottl case 'b': /* Stop sending Blue Alarm */ 1672150850Sscottl { 1673150850Sscottl u_int8_t talm = read_framer(Bt8370_TALM); 1674150850Sscottl write_framer(Bt8370_TALM, talm & ~TALM_TAIS); 1675150850Sscottl if (verbose) printf("Stop sending AIS/Blue signal\n"); 1676150850Sscottl break; 1677150850Sscottl } 1678150850Sscottl default: 1679150850Sscottl printf("Unknown alarm: %c\n", optarg[0]); 1680150850Sscottl } 1681150850Sscottl break; 1682150850Sscottl } 1683150850Sscottl case 'A': /* start alarms */ 1684150850Sscottl { 1685150850Sscottl switch (optarg[0]) 1686150850Sscottl { 1687150850Sscottl case 'y': /* Start sending Yellow Alarm */ 1688150850Sscottl { 1689150850Sscottl if ((config.format == CFG_FORMAT_T1SF) || 1690150850Sscottl (config.format == CFG_FORMAT_E1NONE)) 1691150850Sscottl printf("No Yellow alarm for this frame format\n"); 1692150850Sscottl else if (config.format == CFG_FORMAT_T1ESF) 1693150850Sscottl { 1694150850Sscottl write_framer(Bt8370_BOP, 0x0F); /* rbop off, tbop cont */ 1695150850Sscottl write_framer(Bt8370_TBOP, T1BOP_OOF); 1696150850Sscottl } 1697150850Sscottl else 1698150850Sscottl { 1699150850Sscottl u_int8_t talm = read_framer(Bt8370_TALM); 1700150850Sscottl write_framer(Bt8370_TALM, talm | TALM_TYEL); 1701150850Sscottl } 1702150850Sscottl if (verbose) printf("Sending Yellow alarm\n"); 1703150850Sscottl break; 1704150850Sscottl } 1705150850Sscottl case 'a': /* Start sending AIS */ 1706150850Sscottl case 'b': /* Start sending Blue Alarm */ 1707150850Sscottl { 1708150850Sscottl u_int8_t talm = read_framer(Bt8370_TALM); 1709150850Sscottl write_framer(Bt8370_TALM, talm | TALM_TAIS); 1710150850Sscottl if (verbose) printf("Sending AIS/Blue signal\n"); 1711150850Sscottl break; 1712150850Sscottl } 1713150850Sscottl default: 1714150850Sscottl printf("Unknown alarm: %c\n", optarg[0]); 1715150850Sscottl } 1716150850Sscottl break; 1717150850Sscottl } 1718150850Sscottl case 'B': /* send BOP msg */ 1719150850Sscottl { 1720150850Sscottl u_int8_t bop = strtoul(optarg, NULL, 0); 1721150850Sscottl if (config.format == CFG_FORMAT_T1ESF) 1722150850Sscottl { 1723150850Sscottl write_framer(Bt8370_BOP, 0x0B); /* rbop off, tbop 25 */ 1724150850Sscottl write_framer(Bt8370_TBOP, bop); /* start sending BOP msg */ 1725150850Sscottl sleep(1); /* sending 25 BOP msgs takes about 100 ms. */ 1726150850Sscottl write_framer(Bt8370_BOP, 0xE0); /* rbop 25, tbop off */ 1727150850Sscottl if (verbose) printf("Sent '0x%02X' BOP msg 25 times\n", bop); 1728150850Sscottl } 1729150850Sscottl else 1730150850Sscottl printf("BOP msgs only work in T1-ESF format\n"); 1731150850Sscottl break; 1732150850Sscottl } 1733150850Sscottl case 'c': /* set cable length */ 1734150850Sscottl { 1735150850Sscottl config.cable_len = strtoul(optarg, NULL, 0); 1736150850Sscottl if (verbose) print_cable_len(); 1737150850Sscottl update = 1; 1738150850Sscottl break; 1739150850Sscottl } 1740150850Sscottl case 'd': /* DSU status */ 1741150850Sscottl case 's': /* deprecated */ 1742150850Sscottl { 1743150850Sscottl print_t1_dsu(); 1744150850Sscottl break; 1745150850Sscottl } 1746150850Sscottl case 'e': /* set framimg format */ 1747150850Sscottl { 1748150850Sscottl config.format = strtoul(optarg, NULL, 0); 1749150850Sscottl if (verbose) print_format(); 1750150850Sscottl update = 1; 1751150850Sscottl break; 1752150850Sscottl } 1753150850Sscottl case 'E': /* set time slots */ 1754150850Sscottl { 1755150850Sscottl config.time_slots = strtoul(optarg, NULL, 16); 1756150850Sscottl if (verbose) print_time_slots(); 1757150850Sscottl update = 1; 1758150850Sscottl break; 1759150850Sscottl } 1760150850Sscottl case 'f': /* read and print framer regs */ 1761150850Sscottl { 1762150850Sscottl int i; 1763150850Sscottl printf("Bt8370 regs:\n"); 1764150850Sscottl printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F"); 1765150850Sscottl for (i=0; i<512; i++) 1766150850Sscottl { 1767150850Sscottl if (i%16 == 0) printf("\n%03X: ", i); 1768150850Sscottl printf("%02X ", read_framer(i)); 1769150850Sscottl } 1770150850Sscottl printf("\n\n"); 1771150850Sscottl break; 1772150850Sscottl } 1773150850Sscottl case 'F': /* write framer reg */ 1774150850Sscottl { 1775150850Sscottl u_int32_t addr = strtoul(optarg, NULL, 0); 1776150850Sscottl u_int32_t data = strtoul(argv[optind++], NULL, 0); 1777150850Sscottl write_framer(addr, data); 1778150850Sscottl if (verbose) 1779150850Sscottl { 1780150850Sscottl data = read_framer(addr); 1781150850Sscottl printf("Write framer register: addr = 0x%02X data = 0x%02X\n", addr, data); 1782150850Sscottl } 1783150850Sscottl break; 1784150850Sscottl } 1785150850Sscottl case 'g': /* set receiver gain */ 1786150850Sscottl { 1787150850Sscottl config.rx_gain = strtoul(optarg, NULL, 0); 1788150850Sscottl if (verbose) print_rx_gain(); 1789150850Sscottl update = 1; 1790150850Sscottl break; 1791150850Sscottl } 1792150850Sscottl case 'i': /* send CSU loopback deactivate inband cmd */ 1793150850Sscottl { 1794150850Sscottl if (config.format == CFG_FORMAT_T1SF) 1795150850Sscottl { 1796150850Sscottl if (verbose) printf("Sending 'CSU loop down' inband cmd for 10 secs..."); 1797150850Sscottl ioctl_snmp_send(TSEND_RESET); 1798150850Sscottl sleep(10); 1799150850Sscottl ioctl_snmp_send(TSEND_NORMAL); 1800150850Sscottl if (verbose) printf("done\n"); 1801150850Sscottl } 1802150850Sscottl else 1803150850Sscottl printf("Inband loopback cmds only work in T1-SF format"); 1804150850Sscottl break; 1805150850Sscottl } 1806150850Sscottl case 'I': /* send CSU loopback activate inband cmd */ 1807150850Sscottl { 1808150850Sscottl if (config.format == CFG_FORMAT_T1SF) 1809150850Sscottl { 1810150850Sscottl if (verbose) printf("Sending 'CSU loop up' inband cmd for 10 secs..."); 1811150850Sscottl ioctl_snmp_send(TSEND_LINE); 1812150850Sscottl sleep(10); 1813150850Sscottl ioctl_snmp_send(TSEND_NORMAL); 1814150850Sscottl if (verbose) printf("done\n"); 1815150850Sscottl } 1816150850Sscottl else 1817150850Sscottl printf("Inband loopback cmds only work in T1-SF format"); 1818150850Sscottl break; 1819150850Sscottl } 1820150850Sscottl case 'l': /* send line loopback deactivate BOP msg */ 1821150850Sscottl { 1822150850Sscottl if (config.format == CFG_FORMAT_T1ESF) 1823150850Sscottl { 1824150850Sscottl ioctl_snmp_send(TSEND_RESET); 1825150850Sscottl if (verbose) printf("Sent 'Line Loop Down' BOP cmd\n"); 1826150850Sscottl } 1827150850Sscottl else 1828150850Sscottl printf("BOP msgs only work in T1-ESF format\n"); 1829150850Sscottl break; 1830150850Sscottl } 1831150850Sscottl case 'L': /* send line loopback activate BOP msg */ 1832150850Sscottl { 1833150850Sscottl if (config.format == CFG_FORMAT_T1ESF) 1834150850Sscottl { 1835150850Sscottl ioctl_snmp_send(TSEND_LINE); 1836150850Sscottl if (verbose) printf("Sent 'Line Loop Up' BOP cmd\n"); 1837150850Sscottl } 1838150850Sscottl else 1839150850Sscottl printf("BOP msgs only work in T1-ESF format\n"); 1840150850Sscottl break; 1841150850Sscottl } 1842150850Sscottl case 'p': /* send payload loopback deactivate BOP msg */ 1843150850Sscottl { 1844150850Sscottl if (config.format == CFG_FORMAT_T1ESF) 1845150850Sscottl { 1846150850Sscottl ioctl_snmp_send(TSEND_RESET); 1847150850Sscottl if (verbose) printf("Sent 'Payload Loop Down' BOP cmd\n"); 1848150850Sscottl } 1849150850Sscottl else 1850150850Sscottl printf("BOP msgs only work in T1-ESF format\n"); 1851150850Sscottl break; 1852150850Sscottl } 1853150850Sscottl case 'P': /* send payload loopback activate BOP msg */ 1854150850Sscottl { 1855150850Sscottl if (config.format == CFG_FORMAT_T1ESF) 1856150850Sscottl { 1857150850Sscottl ioctl_snmp_send(TSEND_PAYLOAD); 1858150850Sscottl if (verbose) printf("Sent 'Payload Loop Up' BOP cmd\n"); 1859150850Sscottl } 1860150850Sscottl else 1861150850Sscottl printf("BOP msgs only work in T1-ESF format\n"); 1862150850Sscottl break; 1863150850Sscottl } 1864150850Sscottl case 't': /* stop sending test pattern */ 1865150850Sscottl { 1866150850Sscottl ioctl_snmp_send(TSEND_NORMAL); 1867150850Sscottl if (verbose) printf("Stop sending test pattern\n"); 1868150850Sscottl break; 1869150850Sscottl } 1870150850Sscottl case 'T': /* start sending test pattern */ 1871150850Sscottl { 1872150850Sscottl u_int8_t patt = strtoul(optarg, NULL, 0); 1873150850Sscottl write_framer(Bt8370_TPATT, 0x10 + patt); 1874150850Sscottl write_framer(Bt8370_RPATT, 0x30 + patt); 1875150850Sscottl if (verbose) print_test_pattern(patt); 1876150850Sscottl break; 1877150850Sscottl } 1878150850Sscottl case 'u': /* set transmit pulse shape */ 1879150850Sscottl { 1880150850Sscottl config.tx_pulse = strtoul(optarg, NULL, 0); 1881150850Sscottl if (verbose) print_tx_pulse(); 1882150850Sscottl update = 1; 1883150850Sscottl break; 1884150850Sscottl } 1885150850Sscottl case 'U': /* set tx line build-out */ 1886150850Sscottl { 1887150850Sscottl if (config.tx_pulse == CFG_PULSE_T1CSU) 1888150850Sscottl { 1889150850Sscottl config.tx_lbo = strtoul(optarg, NULL, 0); 1890150850Sscottl if (verbose) print_tx_pulse(); 1891150850Sscottl update = 1; 1892150850Sscottl } 1893150850Sscottl else 1894150850Sscottl printf("LBO only meaningful if Tx Pulse is T1CSU\n"); 1895150850Sscottl break; 1896150850Sscottl } 1897150850Sscottl case 'v': /* set verbose mode */ 1898150850Sscottl { 1899150850Sscottl verbose = 1; 1900150850Sscottl break; 1901150850Sscottl } 1902150850Sscottl case 'x': /* disable transmitter outputs */ 1903150850Sscottl { 1904150850Sscottl write_mii(16, read_mii(16) & ~MII16_T1_XOE); 1905150850Sscottl if (verbose) printf("Transmitter outputs disabled\n"); 1906150850Sscottl break; 1907150850Sscottl } 1908150850Sscottl case 'X': /* enable transmitter outputs */ 1909150850Sscottl { 1910150850Sscottl write_mii(16, read_mii(16) | MII16_T1_XOE); 1911150850Sscottl if (verbose) printf("Transmitter outputs enabled\n"); 1912150850Sscottl break; 1913150850Sscottl } 1914150850Sscottl default: 1915150850Sscottl { 1916150850Sscottl printf("Unknown command char: %c\n", ch); 1917150850Sscottl exit(1); 1918150850Sscottl } /* case */ 1919150850Sscottl } /* switch */ 1920150850Sscottl } /* while */ 1921150850Sscottl } /* proc */ 1922150850Sscottl 1923150850Sscottl/* used when reading Motorola S-Record format ROM files */ 1924150850Sscottlunsigned char read_hex(FILE *f) 1925150850Sscottl { 1926150850Sscottl unsigned char a, b, c; 1927150850Sscottl for (a=0, b=0; a<2; a++) 1928150850Sscottl { 1929150850Sscottl c = fgetc(f); 1930150850Sscottl c -= 48; 1931150850Sscottl if (c > 9) c -= 7; 1932150850Sscottl b = (b<<4) | (c & 0xF); 1933150850Sscottl } 1934150850Sscottl checksum += b; 1935150850Sscottl return b; 1936150850Sscottl } 1937150850Sscottl 1938150850Sscottlstatic void load_xilinx(char *name) 1939150850Sscottl { 1940150850Sscottl FILE *f; 1941150850Sscottl char *ucode; 1942150850Sscottl int i, length; 1943216599Suqs int c; 1944150850Sscottl 1945150850Sscottl if (verbose) printf("Load firmware from file %s...\n", name); 1946150850Sscottl if ((f = fopen(name, "r")) == 0) 1947150850Sscottl { 1948150850Sscottl perror("Failed to open file"); 1949150850Sscottl exit(1); 1950150850Sscottl } 1951150850Sscottl 1952150850Sscottl ucode = (char *)malloc(8192); bzero(ucode, 8192); 1953150850Sscottl 1954150850Sscottl c = fgetc(f); 1955150850Sscottl if (c == 'X') 1956150850Sscottl { /* Xilinx raw bits file (foo.rbt) */ 1957150850Sscottl /* skip seven lines of boiler plate */ 1958150850Sscottl for (i=0; i<7;) if ((c=fgetc(f))=='\n') i++; 1959150850Sscottl /* build a dense bit array */ 1960150850Sscottl i = length = 0; 1961150850Sscottl while ((c=fgetc(f))!=EOF) 1962150850Sscottl { /* LSB first */ 1963150850Sscottl if (c=='1') ucode[length] |= 1<<i++; 1964150850Sscottl if (c=='0') i++; 1965150850Sscottl if (i==8) { i=0; length++; } 1966150850Sscottl } 1967150850Sscottl } 1968150850Sscottl else if (c == 'S') 1969150850Sscottl { /* Motarola S records (foo.exo) */ 1970150850Sscottl int blklen; 1971150850Sscottl length = 0; 1972150850Sscottl ungetc(c, f); 1973150850Sscottl while ((c = fgetc(f)) != EOF) 1974150850Sscottl { 1975150850Sscottl if (c != 'S') 1976150850Sscottl { 1977150850Sscottl printf("I'm confused; I expected an 'S'\n"); 1978150850Sscottl exit(1); 1979150850Sscottl } 1980150850Sscottl c = fgetc(f); 1981150850Sscottl if (c == '9') break; 1982150850Sscottl else if (c == '1') 1983150850Sscottl { 1984150850Sscottl checksum = 0; 1985150850Sscottl blklen = read_hex(f) -3; 1986150850Sscottl read_hex(f); /* hi blkaddr */ 1987150850Sscottl read_hex(f); /* lo blkaddr */ 1988150850Sscottl for (i=0; i<blklen; i++) 1989150850Sscottl ucode[length++] = read_hex(f); 1990150850Sscottl read_hex(f); /* process but ignore checksum */ 1991150850Sscottl if (checksum != 0xFF) 1992150850Sscottl { 1993150850Sscottl printf("File checksum error\n"); 1994150850Sscottl exit(1); 1995150850Sscottl } 1996150850Sscottl c = fgetc(f); /* throw away eol */ 1997150850Sscottl c = fgetc(f); /* throw away eol */ 1998150850Sscottl } 1999150850Sscottl else 2000150850Sscottl { 2001150850Sscottl printf("I'm confused; I expected a '1' or a '9'\n"); 2002150850Sscottl exit(1); 2003150850Sscottl } 2004150850Sscottl } /* while */ 2005150850Sscottl } /* Motorola S-Record */ 2006150850Sscottl else 2007150850Sscottl { 2008150850Sscottl printf("Unknown file type giving up\n"); 2009150850Sscottl exit(1); 2010150850Sscottl } 2011150850Sscottl 2012150850Sscottl load_xilinx_from_file(ucode, length); 2013150850Sscottl } 2014150850Sscottl 2015150850Sscottl/* 32-bit CRC calculated right-to-left over 8-bit bytes */ 2016150850Sscottlu_int32_t crc32(char *bufp, int len) 2017150850Sscottl { 2018150850Sscottl int bit, i; 2019150850Sscottl u_int32_t data; 2020150850Sscottl u_int32_t crc = 0xFFFFFFFFL; 2021150850Sscottl u_int32_t poly = 0xEDB88320L; 2022150850Sscottl 2023150850Sscottl for (i = 0; i < len; i++) 2024150850Sscottl for (data = *bufp++, bit = 0; bit < 8; bit++, data >>= 1) 2025150850Sscottl crc = (crc >> 1) ^ (((crc ^ data) & 1) ? poly : 0); 2026150850Sscottl 2027150850Sscottl return crc; 2028150850Sscottl } 2029150850Sscottl 2030150850Sscottl/* 8-bit CRC calculated left-to-right over 16-bit words */ 2031150850Sscottlu_int8_t crc8(u_int16_t *bufp, int len) 2032150850Sscottl { 2033150850Sscottl int bit, i; 2034150850Sscottl u_int16_t data; 2035150850Sscottl u_int8_t crc = 0xFF; 2036150850Sscottl u_int8_t poly = 0x07; 2037150850Sscottl 2038150850Sscottl for (i = 0; i < len; i++) 2039150850Sscottl for (data = *bufp++, bit = 15; bit >= 0; bit--) 2040150850Sscottl { 2041150850Sscottl if ((i==8) && (bit==7)) break; 2042150850Sscottl crc = (crc << 1) ^ ((((crc >> 7) ^ (data >> bit)) & 1) ? poly : 0); 2043150850Sscottl } 2044150850Sscottl return crc; 2045150850Sscottl } 2046150850Sscottl 2047150850Sscottl/* HSSI=3, DS3=4, SSI=5, T1E1=6, HSSIc=7, SDSL=8 */ 2048150850Sscottlvoid init_srom(int board) 2049150850Sscottl { 2050150850Sscottl int i; 2051150850Sscottl u_int16_t srom[64]; 2052150850Sscottl 2053150850Sscottl /* zero the entire rom */ 2054150850Sscottl for (i=0; i<64; i++) srom[i] = 0; 2055150850Sscottl 2056150850Sscottl srom[0] = 0x1376; /* subsys vendor id */ 2057150850Sscottl srom[1] = board ? board : (read_mii(3)>>4 & 0xF) +1; 2058150850Sscottl srom[8] = crc8(srom, 9); 2059150850Sscottl /* Tulip hardware checks this checksum */ 2060150850Sscottl srom[10] = 0x6000; /* ethernet address */ 2061150850Sscottl srom[11] = 0x0099; /* ethernet address */ 2062150850Sscottl srom[12] = 0x0000; /* ethernet address */ 2063150850Sscottl /* srom checksum is low 16 bits of Ethernet CRC-32 */ 2064150850Sscottl srom[63] = crc32((char *)srom, 126) ^ 0xFFFFFFFFL; 2065150850Sscottl 2066150850Sscottl /* write the SROM */ 2067150850Sscottl#if 1 /* really write it */ 2068150850Sscottl for (i=0; i<64; i++) write_srom(i, srom[i]); 2069150850Sscottl#else /* print what would be written */ 2070150850Sscottl printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F"); 2071150850Sscottl for (i=0; i<64; i++) 2072150850Sscottl { 2073150850Sscottl if (i%8 == 0) printf("\n%02X: ", i<<1); 2074150850Sscottl printf("%02X %02X ", srom[i] & 0xFF, srom[i]>>8); 2075150850Sscottl } 2076150850Sscottl printf("\n\n"); 2077150850Sscottl#endif 2078150850Sscottl } 2079150850Sscottl 2080150850Sscottlint main(int argc, char **argv) 2081150850Sscottl { 2082150850Sscottl int i, error, ch; 2083150850Sscottl char *optstring = "13a:bBcCdDeEf:Fhi:L:mM:pP:sS:tT:uUvVwW:xXyYzZ?"; 2084150850Sscottl 2085150850Sscottl progname = (char *)argv[0]; 2086150850Sscottl 2087150850Sscottl /* Here is the overall plan: 2088150850Sscottl * 1) Read the interface name from the command line. 2089150850Sscottl * 2) Open the device; decide if netgraph is being used. 2090150850Sscottl * 3) Read the current interface configuration from the driver. 2091150850Sscottl * 4) Read the command line args and carry out their actions. 2092150850Sscottl * 5) Write the modified interface configuration to the driver. 2093150850Sscottl */ 2094150850Sscottl 2095150850Sscottl /* 1) Read the interface name from the command line. */ 2096150850Sscottl#if __linux__ 2097150850Sscottl ifname = (argc==1) ? "hdlc0" : (char *) argv[1]; 2098150850Sscottl#else 2099150850Sscottl ifname = (argc==1) ? DEVICE_NAME"0" : (char *) argv[1]; 2100150850Sscottl#endif 2101150850Sscottl 2102150850Sscottl /* 2) Open the device; decide if netgraph is being used, */ 2103150850Sscottl /* use netgraph if ifname ends with ":" */ 2104150850Sscottl for (i=0; i<16; i++) if (ifname[i] == 0) break; 2105150850Sscottl 2106150850Sscottl /* Get a socket type file descriptor. */ 2107150850Sscottl#if defined(NETGRAPH) 2108150850Sscottl if ((netgraph = (ifname[i-1] == ':'))) 2109150850Sscottl error = NgMkSockNode(NULL, &fdcs, NULL); 2110150850Sscottl else 2111150850Sscottl#endif 2112150850Sscottl error = fdcs = socket(AF_INET, SOCK_DGRAM, 0); 2113150850Sscottl if (error < 0) 2114150850Sscottl { 2115150850Sscottl fprintf(stderr, "%s: %s() failed: %s\n", progname, 2116150850Sscottl netgraph? "NgMkSockNode" : "socket", strerror(errno)); 2117150850Sscottl exit(1); 2118150850Sscottl } 2119150850Sscottl 2120150850Sscottl /* 3) Read the current interface configuration from the driver. */ 2121150850Sscottl ioctl_read_config(); 2122150850Sscottl ioctl_read_status(); 2123150850Sscottl 2124150850Sscottl summary = (argc <= 2); /* print summary at end */ 2125150850Sscottl update = 0; /* write to card at end */ 2126150850Sscottl 2127150850Sscottl /* 4) Read the command line args and carry out their actions. */ 2128150850Sscottl optind = 2; 2129150850Sscottl while (((ch = getopt(argc, argv, optstring)) != -1) && (argc > 2)) 2130150850Sscottl { 2131150850Sscottl switch (ch) 2132150850Sscottl { 2133150850Sscottl case '1': /* T1 commands */ 2134150850Sscottl { 2135150850Sscottl if (verbose) printf("Doing T1 settings\n"); 2136150850Sscottl if (status.card_type != TLP_CSID_T1E1) 2137150850Sscottl { 2138150850Sscottl printf("T1 settings only apply to T1E1 cards\n"); 2139150850Sscottl exit(1); 2140150850Sscottl } 2141150850Sscottl t1_cmd(argc, argv); 2142150850Sscottl break; 2143150850Sscottl } 2144150850Sscottl case '3': /* T3 commands */ 2145150850Sscottl { 2146150850Sscottl if (verbose) printf("Doing T3 settings\n"); 2147150850Sscottl if (status.card_type != TLP_CSID_T3) 2148150850Sscottl { 2149150850Sscottl printf("T3 settings only apply to T3 cards\n"); 2150150850Sscottl exit(1); 2151150850Sscottl } 2152150850Sscottl t3_cmd(argc, argv); 2153150850Sscottl break; 2154150850Sscottl } 2155150850Sscottl case 'a': /* clock source */ 2156150850Sscottl { 2157150850Sscottl if ((status.card_type != TLP_CSID_T1E1) || 2158150850Sscottl (status.card_type != TLP_CSID_HSSI) || 2159150850Sscottl (status.card_type != TLP_CSID_HSSIc)) 2160150850Sscottl { 2161150850Sscottl if (verbose) print_tx_clk_src(); 2162150850Sscottl config.tx_clk_src = strtoul(optarg, NULL, 0); 2163150850Sscottl update = 1; 2164150850Sscottl } 2165150850Sscottl else 2166150850Sscottl printf("txclksrc only applies to T1E1 and HSSI card types\n"); 2167150850Sscottl break; 2168150850Sscottl } 2169150850Sscottl case 'b': /* read bios rom */ 2170150850Sscottl { 2171150850Sscottl int i; 2172150850Sscottl printf("Bios ROM:\n"); 2173150850Sscottl printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F"); 2174150850Sscottl for (i=0; i<256; i++) 2175150850Sscottl { 2176150850Sscottl if (i%16 == 0) printf("\n%02X: ", i); 2177150850Sscottl printf("%02X ", read_bios_rom(i)); 2178150850Sscottl } 2179150850Sscottl printf("\n\n"); 2180150850Sscottl break; 2181150850Sscottl } 2182150850Sscottl case 'B': /* write bios rom */ 2183150850Sscottl { 2184150850Sscottl int i; 2185150850Sscottl for (i=0; i<256; i++) write_bios_rom(i, 255-i); 2186150850Sscottl if (verbose) printf("wrote (0..255) to bios rom addrs (0..255)\n"); 2187150850Sscottl break; 2188150850Sscottl } 2189150850Sscottl case 'c': /* set crc_len = 16 */ 2190150850Sscottl { 2191150850Sscottl config.crc_len = CFG_CRC_16; 2192150850Sscottl if (verbose) print_crc_len(); 2193150850Sscottl update = 1; 2194150850Sscottl break; 2195150850Sscottl } 2196150850Sscottl case 'C': /* set crc_len = 32 */ 2197150850Sscottl { 2198150850Sscottl config.crc_len = CFG_CRC_32; 2199150850Sscottl if (verbose) print_crc_len(); 2200150850Sscottl update = 1; 2201150850Sscottl break; 2202150850Sscottl } 2203150850Sscottl case 'd': /* clear DEBUG flag */ 2204150850Sscottl { 2205150850Sscottl config.debug = 0; 2206150850Sscottl if (verbose) printf("DEBUG flag cleared\n"); 2207150850Sscottl update = 1; 2208150850Sscottl break; 2209150850Sscottl } 2210150850Sscottl case 'D': /* set DEBUG flag */ 2211150850Sscottl { 2212150850Sscottl config.debug = 1; 2213150850Sscottl if (verbose) printf("DEBUG flag set\n"); 2214150850Sscottl update = 1; 2215150850Sscottl break; 2216150850Sscottl } 2217150850Sscottl case 'e': /* set DTE (default) */ 2218150850Sscottl { 2219150850Sscottl if ((status.card_type == TLP_CSID_SSI) || 2220150850Sscottl (status.card_type == TLP_CSID_HSSIc)) 2221150850Sscottl { 2222150850Sscottl config.dte_dce = CFG_DTE; 2223150850Sscottl if (verbose) print_dte_dce(); 2224150850Sscottl update = 1; 2225150850Sscottl } 2226150850Sscottl else 2227150850Sscottl printf("DTE cmd only applies to SSI & HSSIc cards\n"); 2228150850Sscottl break; 2229150850Sscottl } 2230150850Sscottl case 'E': /* set DCE */ 2231150850Sscottl { 2232150850Sscottl if ((status.card_type == TLP_CSID_SSI) || 2233150850Sscottl (status.card_type == TLP_CSID_HSSIc)) 2234150850Sscottl { 2235150850Sscottl config.dte_dce = CFG_DCE; 2236150850Sscottl if (verbose) print_dte_dce(); 2237150850Sscottl update = 1; 2238150850Sscottl } 2239150850Sscottl else 2240150850Sscottl printf("DCE cmd only applies to SSI & HSSIc cards\n"); 2241150850Sscottl break; 2242150850Sscottl } 2243150850Sscottl case 'f': /* set synth osc freq */ 2244150850Sscottl { 2245150850Sscottl if ((status.card_type == TLP_CSID_SSI) || 2246150850Sscottl (status.card_type == TLP_CSID_HSSIc)) 2247150850Sscottl { 2248150850Sscottl synth_freq(strtoul(optarg, NULL, 0)); 2249150850Sscottl write_synth(config.synth); 2250150850Sscottl if (verbose) print_synth_freq(); 2251150850Sscottl } 2252150850Sscottl else 2253150850Sscottl printf("synth osc freq only applies to SSI & HSSIc cards\n"); 2254150850Sscottl break; 2255150850Sscottl } 2256150850Sscottl case 'F': /* set SPPP line protocol to Frame-Relay */ 2257150850Sscottl { 2258150850Sscottl config.line_prot = PROT_FRM_RLY; 2259150850Sscottl config.keep_alive = 1; /* required for LMI operation */ 2260150850Sscottl if (verbose) printf("SPPP line protocol set to Frame-Relay\n"); 2261150850Sscottl update = 1; 2262150850Sscottl break; 2263150850Sscottl } 2264150850Sscottl case 'h': /* help */ 2265150850Sscottl case '?': 2266150850Sscottl { 2267150850Sscottl usage(); 2268150850Sscottl exit(0); 2269150850Sscottl } 2270150850Sscottl case 'i': /* interface name */ 2271150850Sscottl { 2272150850Sscottl /* already scanned this */ 2273150850Sscottl break; 2274150850Sscottl } 2275150850Sscottl case 'L': /* set loopback modes */ 2276150850Sscottl { 2277150850Sscottl config.loop_back = strtoul(optarg, NULL, 0); 2278150850Sscottl if (verbose) print_loop_back(); 2279150850Sscottl update = 1; 2280150850Sscottl break; 2281150850Sscottl } 2282150850Sscottl case 'm': /* read and print MII regs */ 2283150850Sscottl { 2284150850Sscottl printf("MII regs:\n"); 2285150850Sscottl printf(" 0 1 2 3 4 5 6 7"); 2286150850Sscottl for (i=0; i<32; i++) 2287150850Sscottl { 2288150850Sscottl u_int16_t mii = read_mii(i); 2289150850Sscottl if (i%8 == 0) printf("\n%02X: ", i); 2290150850Sscottl printf("%04X ", mii); 2291150850Sscottl } 2292150850Sscottl printf("\n\n"); 2293150850Sscottl break; 2294150850Sscottl } 2295150850Sscottl case 'M': /* write MII reg */ 2296150850Sscottl { 2297150850Sscottl u_int32_t addr = strtoul(optarg, NULL, 0); 2298150850Sscottl u_int32_t data = strtoul(argv[optind++], NULL, 0); 2299150850Sscottl write_mii(addr, data); 2300150850Sscottl if (verbose) 2301150850Sscottl { 2302150850Sscottl data = read_mii(addr); 2303150850Sscottl printf("Write mii register: addr = 0x%02X data = 0x%04X\n", addr, data); 2304150850Sscottl } 2305150850Sscottl break; 2306150850Sscottl } 2307150850Sscottl case 'p': /* read and print PCI config regs */ 2308150850Sscottl { 2309150850Sscottl int i; 2310150850Sscottl printf("21140A PCI Config regs:\n"); 2311150850Sscottl printf(" 0 1 2 3"); 2312150850Sscottl for (i=0; i<16; i++) 2313150850Sscottl { 2314150850Sscottl if (i%4 == 0) printf("\n%X: ", i); 2315150850Sscottl printf("%08X ", read_pci_config(i<<2)); 2316150850Sscottl } 2317150850Sscottl printf("\n\n"); 2318150850Sscottl break; 2319150850Sscottl } 2320150850Sscottl case 'P': /* write PCI config reg */ 2321150850Sscottl { 2322150850Sscottl u_int32_t addr = strtoul(optarg, NULL, 0); 2323150850Sscottl u_int32_t data = strtoul(argv[optind++], NULL, 0); 2324150850Sscottl write_pci_config(addr, data); 2325150850Sscottl if (verbose) 2326150850Sscottl { 2327150850Sscottl data = read_pci_config(addr); 2328150850Sscottl printf("Write PCI config reg: addr = 0x%02X data = 0x%08X\n", addr, data); 2329150850Sscottl } 2330150850Sscottl break; 2331150850Sscottl } 2332150850Sscottl case 's': /* read and print Tulip SROM */ 2333150850Sscottl { 2334150850Sscottl int i; 2335150850Sscottl printf("21140A SROM:\n"); 2336150850Sscottl printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F"); 2337150850Sscottl for (i=0; i<64; i++) 2338150850Sscottl { 2339150850Sscottl u_int16_t srom = read_srom(i); 2340150850Sscottl if (i%8 == 0) printf("\n%02X: ", i<<1); 2341150850Sscottl printf("%02X %02X ", srom & 0xFF, srom>>8); 2342150850Sscottl } 2343150850Sscottl printf("\n\n"); 2344150850Sscottl break; 2345150850Sscottl } 2346150850Sscottl case 'S': /* write Tulip SROM loc */ 2347150850Sscottl { 2348150850Sscottl#if 0 /* write a single location -- not too useful */ 2349150850Sscottl u_int32_t addr = strtoul(optarg, NULL, 0); 2350150850Sscottl u_int32_t data = strtoul(argv[optind++], NULL, 0); 2351150850Sscottl write_mii(addr, data); 2352150850Sscottl data = read_mii(addr); 2353150850Sscottl printf("Write SROM: addr = 0x%02X data = 0x%04X\n", addr, data); 2354150850Sscottl#endif 2355150850Sscottl#if 0 /* write the whole SROM -- very dangerous */ 2356150850Sscottl init_srom(strtoul(optarg, NULL, 0)); 2357150850Sscottl#endif 2358150850Sscottl printf("Caution! Recompile %s to enable this.\n", progname); 2359150850Sscottl break; 2360150850Sscottl } 2361150850Sscottl case 't': /* read and print Tulip CSRs */ 2362150850Sscottl { 2363150850Sscottl int i; 2364150850Sscottl printf("21140A CSRs:\n"); 2365150850Sscottl printf(" 0 1 2 3"); 2366150850Sscottl for (i=0; i<16; i++) 2367150850Sscottl { 2368150850Sscottl if (i%4 == 0) printf("\n%X: ", i); 2369150850Sscottl printf("%08X ", read_csr(i)); 2370150850Sscottl } 2371150850Sscottl printf("\n\n"); 2372150850Sscottl break; 2373150850Sscottl } 2374150850Sscottl case 'T': /* write Tulip CSR */ 2375150850Sscottl { 2376150850Sscottl u_int32_t addr = strtoul(optarg, NULL, 0); 2377150850Sscottl u_int32_t data = strtoul(argv[optind++], NULL, 0); 2378150850Sscottl write_csr(addr, data); 2379150850Sscottl if (verbose) 2380150850Sscottl { 2381150850Sscottl data = read_csr(addr); 2382150850Sscottl printf("Write 21140A CSR: addr = 0x%02X data = 0x%08X\n", addr, data); 2383150850Sscottl } 2384150850Sscottl break; 2385150850Sscottl } 2386150850Sscottl case 'u': /* reset event counters */ 2387150850Sscottl { 2388150850Sscottl ioctl_reset_cntrs(); 2389150850Sscottl if (verbose) printf("Event counters reset\n"); 2390150850Sscottl break; 2391150850Sscottl } 2392150850Sscottl case 'U': /* reset gate array */ 2393150850Sscottl { 2394150850Sscottl reset_xilinx(); 2395150850Sscottl if (verbose) printf("gate array reset\n"); 2396150850Sscottl break; 2397150850Sscottl } 2398150850Sscottl case 'v': /* set verbose mode */ 2399150850Sscottl { 2400150850Sscottl verbose = 1; 2401150850Sscottl break; 2402150850Sscottl } 2403150850Sscottl case 'V': /* print card configuration */ 2404150850Sscottl { 2405150850Sscottl summary = 1; 2406150850Sscottl break; 2407150850Sscottl } 2408150850Sscottl case 'w': /* load gate array microcode from ROM */ 2409150850Sscottl { 2410150850Sscottl load_xilinx_from_rom(); 2411150850Sscottl if (verbose) printf("gate array configured from on-board ROM\n"); 2412150850Sscottl break; 2413150850Sscottl } 2414150850Sscottl case 'W': /* load gate array microcode from file */ 2415150850Sscottl { 2416150850Sscottl load_xilinx(optarg); 2417150850Sscottl if (verbose) printf("gate array configured from file %s\n", optarg); 2418150850Sscottl break; 2419150850Sscottl } 2420150850Sscottl case 'x': /* select RAWIP protocol */ 2421150850Sscottl { 2422150850Sscottl config.line_pkg = PKG_RAWIP; 2423150850Sscottl if (verbose) printf("RAWIP mode selected\n"); 2424150850Sscottl update = 1; 2425150850Sscottl break; 2426150850Sscottl } 2427150850Sscottl case 'X': /* Select in-kernel line protocol packages */ 2428150850Sscottl { 2429150850Sscottl config.line_pkg = 0; 2430150850Sscottl if (verbose) printf("line protocol mode selected\n"); 2431150850Sscottl update = 1; 2432150850Sscottl break; 2433150850Sscottl } 2434150850Sscottl case 'y': /* disable SPPP keep-alive packets */ 2435150850Sscottl { 2436150850Sscottl if ((config.line_pkg == PKG_SPPP) && 2437150850Sscottl (config.line_prot == PROT_FRM_RLY)) 2438150850Sscottl printf("keep-alives must be ON for Frame-Relay/SPPP\n"); 2439150850Sscottl else 2440150850Sscottl { 2441150850Sscottl config.keep_alive = 0; 2442150850Sscottl if (verbose) printf("SPPP keep-alive packets disabled\n"); 2443150850Sscottl update = 1; 2444150850Sscottl } 2445150850Sscottl break; 2446150850Sscottl } 2447150850Sscottl case 'Y': /* enable SPPP keep-alive packets */ 2448150850Sscottl { 2449150850Sscottl config.keep_alive = 1; 2450150850Sscottl if (verbose) printf("SPPP keep-alive packets enabled\n"); 2451150850Sscottl update = 1; 2452150850Sscottl break; 2453150850Sscottl } 2454150850Sscottl case 'z': /* set SPPP line protocol to Cisco HDLC */ 2455150850Sscottl { 2456150850Sscottl config.line_prot = PROT_C_HDLC; 2457150850Sscottl config.keep_alive = 1; 2458150850Sscottl if (verbose) printf("SPPP line protocol set to Cisco-HDLC\n"); 2459150850Sscottl update = 1; 2460150850Sscottl break; 2461150850Sscottl } 2462150850Sscottl case 'Z': /* set SPPP line protocol to PPP */ 2463150850Sscottl { 2464150850Sscottl config.line_prot = PROT_PPP; 2465150850Sscottl config.keep_alive = 0; 2466150850Sscottl if (verbose) printf("SPPP line protocol set to PPP\n"); 2467150850Sscottl update = 1; 2468150850Sscottl break; 2469150850Sscottl } 2470150850Sscottl default: 2471150850Sscottl { 2472150850Sscottl printf("Unknown command char: %c\n", ch); 2473150850Sscottl exit(1); 2474150850Sscottl } 2475150850Sscottl } /* switch */ 2476150850Sscottl } /* while */ 2477150850Sscottl 2478150850Sscottl if (summary) print_summary(); 2479150850Sscottl 2480150850Sscottl /* 5) Write the modified interface configuration to the driver. */ 2481150850Sscottl if (update) ioctl_write_config(); 2482150850Sscottl 2483150850Sscottl exit(0); 2484150850Sscottl } 2485