10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*796Smathue * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * HDLC protocol handler for Z8530 SCC. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/param.h> 340Sstevel@tonic-gate #include <sys/systm.h> 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate #include <sys/sysmacros.h> 370Sstevel@tonic-gate #include <sys/kmem.h> 380Sstevel@tonic-gate #include <sys/stropts.h> 390Sstevel@tonic-gate #include <sys/stream.h> 400Sstevel@tonic-gate #include <sys/strsun.h> 410Sstevel@tonic-gate #include <sys/stat.h> 420Sstevel@tonic-gate #include <sys/cred.h> 430Sstevel@tonic-gate #include <sys/user.h> 440Sstevel@tonic-gate #include <sys/proc.h> 450Sstevel@tonic-gate #include <sys/file.h> 460Sstevel@tonic-gate #include <sys/uio.h> 470Sstevel@tonic-gate #include <sys/buf.h> 480Sstevel@tonic-gate #include <sys/mkdev.h> 490Sstevel@tonic-gate #include <sys/cmn_err.h> 500Sstevel@tonic-gate #include <sys/errno.h> 510Sstevel@tonic-gate #include <sys/fcntl.h> 520Sstevel@tonic-gate 530Sstevel@tonic-gate #include <sys/zsdev.h> 540Sstevel@tonic-gate #include <sys/ser_sync.h> 550Sstevel@tonic-gate #include <sys/conf.h> 560Sstevel@tonic-gate #include <sys/ddi.h> 570Sstevel@tonic-gate #include <sys/sunddi.h> 580Sstevel@tonic-gate #include <sys/dlpi.h> 590Sstevel@tonic-gate 600Sstevel@tonic-gate #define ZSH_TRACING 610Sstevel@tonic-gate #ifdef ZSH_TRACING 620Sstevel@tonic-gate #include <sys/vtrace.h> 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * Temp tracepoint definitions 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate #define TR_ZSH 50 680Sstevel@tonic-gate 690Sstevel@tonic-gate #define TR_ZSH_TXINT 1 700Sstevel@tonic-gate #define TR_ZSH_XSINT 2 710Sstevel@tonic-gate #define TR_ZSH_RXINT 3 720Sstevel@tonic-gate #define TR_ZSH_SRINT 4 730Sstevel@tonic-gate 740Sstevel@tonic-gate #define TR_ZSH_WPUT_START 5 750Sstevel@tonic-gate #define TR_ZSH_WPUT_END 6 760Sstevel@tonic-gate #define TR_ZSH_START_START 7 770Sstevel@tonic-gate #define TR_ZSH_START_END 8 780Sstevel@tonic-gate #define TR_ZSH_SOFT_START 9 790Sstevel@tonic-gate #define TR_ZSH_SOFT_END 10 800Sstevel@tonic-gate 810Sstevel@tonic-gate #define TR_ZSH_OPEN 11 820Sstevel@tonic-gate #define TR_ZSH_CLOSE 12 830Sstevel@tonic-gate 840Sstevel@tonic-gate #endif /* ZSH_TRACING */ 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* 870Sstevel@tonic-gate * Logging definitions 880Sstevel@tonic-gate */ 890Sstevel@tonic-gate 900Sstevel@tonic-gate /* 910Sstevel@tonic-gate * #define ZSH_DEBUG 920Sstevel@tonic-gate */ 930Sstevel@tonic-gate #ifdef ZSH_DEBUG 940Sstevel@tonic-gate 950Sstevel@tonic-gate #ifdef ZS_DEBUG_ALL 960Sstevel@tonic-gate extern char zs_h_log[]; 970Sstevel@tonic-gate extern int zs_h_log_n; 980Sstevel@tonic-gate #define zsh_h_log_add(c) \ 990Sstevel@tonic-gate { \ 1000Sstevel@tonic-gate if (zs_h_log_n >= ZS_H_LOG_MAX) \ 1010Sstevel@tonic-gate zs_h_log_n = 0; \ 1020Sstevel@tonic-gate zs_h_log[zs_h_log_n++] = 'A' + zs->zs_unit; \ 1030Sstevel@tonic-gate zs_h_log[zs_h_log_n++] = c; \ 1040Sstevel@tonic-gate zs_h_log[zs_h_log_n] = '\0'; \ 1050Sstevel@tonic-gate } 1060Sstevel@tonic-gate #define zsh_h_log_clear 1070Sstevel@tonic-gate #else 1080Sstevel@tonic-gate #define ZSH_H_LOG_MAX 0x8000 1090Sstevel@tonic-gate char zsh_h_log[2][ZSH_H_LOG_MAX +10]; 1100Sstevel@tonic-gate int zsh_h_log_n[2]; 1110Sstevel@tonic-gate #define zsh_h_log_add(c) \ 1120Sstevel@tonic-gate { \ 1130Sstevel@tonic-gate if (zsh_h_log_n[zs->zs_unit] >= ZSH_H_LOG_MAX) \ 1140Sstevel@tonic-gate zsh_h_log_n[zs->zs_unit] = 0; \ 1150Sstevel@tonic-gate zsh_h_log[zs->zs_unit][zsh_h_log_n[zs->zs_unit]++] = c; \ 1160Sstevel@tonic-gate zsh_h_log[zs->zs_unit][zsh_h_log_n[zs->zs_unit]] = '\0'; \ 1170Sstevel@tonic-gate } 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #define zsh_h_log_clear \ 1200Sstevel@tonic-gate { register char *p; \ 1210Sstevel@tonic-gate for (p = &zsh_h_log[zs->zs_unit][ZSH_H_LOG_MAX]; \ 1220Sstevel@tonic-gate p >= &zsh_h_log[zs->zs_unit][0]; p--) \ 1230Sstevel@tonic-gate *p = '\0'; \ 1240Sstevel@tonic-gate zsh_h_log_n[zs->zs_unit] = 0; \ 1250Sstevel@tonic-gate } 1260Sstevel@tonic-gate #endif 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate #define ZSH_R0_LOG(r0) { \ 1290Sstevel@tonic-gate if (r0 & ZSRR0_RX_READY) zsh_h_log_add('R'); \ 1300Sstevel@tonic-gate if (r0 & ZSRR0_TIMER) zsh_h_log_add('Z'); \ 1310Sstevel@tonic-gate if (r0 & ZSRR0_TX_READY) zsh_h_log_add('T'); \ 1320Sstevel@tonic-gate if (r0 & ZSRR0_CD) zsh_h_log_add('D'); \ 1330Sstevel@tonic-gate if (r0 & ZSRR0_SYNC) zsh_h_log_add('S'); \ 1340Sstevel@tonic-gate if (r0 & ZSRR0_CTS) zsh_h_log_add('C'); \ 1350Sstevel@tonic-gate if (r0 & ZSRR0_TXUNDER) zsh_h_log_add('U'); \ 1360Sstevel@tonic-gate if (r0 & ZSRR0_BREAK) zsh_h_log_add('B'); \ 1370Sstevel@tonic-gate } 1380Sstevel@tonic-gate #endif 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate char _depends_on[] = "drv/zs"; 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate #ifndef MAXZSH 1440Sstevel@tonic-gate #define MAXZSH 2 1450Sstevel@tonic-gate #define MAXZSHCLONES (80) /* three clone opens per instance */ 1460Sstevel@tonic-gate #endif /* MAXZSH */ 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate int maxzsh = MAXZSH; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate int zsh_timer_count = 10; 1510Sstevel@tonic-gate int zsh_default_mru = 1024; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate struct ser_str *zsh_str = NULL; 1540Sstevel@tonic-gate unsigned char zsh_usedminor[MAXZSHCLONES]; 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* 1580Sstevel@tonic-gate * The HDLC protocol 1590Sstevel@tonic-gate */ 1600Sstevel@tonic-gate int zsh_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result); 1610Sstevel@tonic-gate static int zsh_probe(dev_info_t *dev); 1620Sstevel@tonic-gate static int zsh_attach(dev_info_t *dev, ddi_attach_cmd_t cmd); 1630Sstevel@tonic-gate static int zsh_detach(dev_info_t *dev, ddi_detach_cmd_t cmd); 1640Sstevel@tonic-gate static int zsh_open(queue_t *rq, dev_t *dev, int flag, int sflag, cred_t *cr); 1650Sstevel@tonic-gate static int zsh_close(queue_t *rq, int flag); 1660Sstevel@tonic-gate static void zsh_wput(queue_t *wq, mblk_t *mp); 1670Sstevel@tonic-gate static int zsh_start(struct zscom *zs, struct syncline *zss); 1680Sstevel@tonic-gate static void zsh_ioctl(queue_t *wq, mblk_t *mp); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate static struct module_info hdlc_minfo = { 1710Sstevel@tonic-gate 0x5a48, /* module ID number: "ZH" */ 1720Sstevel@tonic-gate "zsh", /* module name */ 1730Sstevel@tonic-gate 0, /* minimum packet size accepted */ 1740Sstevel@tonic-gate INFPSZ, /* maximum packet size accepted */ 1750Sstevel@tonic-gate 12*1024, /* queue high water mark (bytes) */ 1760Sstevel@tonic-gate 4*1024 /* queue low water mark (bytes) */ 1770Sstevel@tonic-gate }; 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate static struct qinit hdlc_rinit = { 1800Sstevel@tonic-gate putq, /* input put procedure */ 1810Sstevel@tonic-gate NULL, /* input service procedure */ 1820Sstevel@tonic-gate zsh_open, /* open procedure */ 1830Sstevel@tonic-gate zsh_close, /* close procedure */ 1840Sstevel@tonic-gate NULL, /* reserved */ 1850Sstevel@tonic-gate &hdlc_minfo, /* module info */ 1860Sstevel@tonic-gate NULL /* reserved */ 1870Sstevel@tonic-gate }; 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate static struct qinit hdlc_winit = { 1900Sstevel@tonic-gate (int (*)())zsh_wput, /* output put procedure */ 1910Sstevel@tonic-gate NULL, /* output service procedure */ 1920Sstevel@tonic-gate NULL, /* open procedure */ 1930Sstevel@tonic-gate NULL, /* close procedure */ 1940Sstevel@tonic-gate NULL, /* reserved */ 1950Sstevel@tonic-gate &hdlc_minfo, /* module info */ 1960Sstevel@tonic-gate NULL /* reserved */ 1970Sstevel@tonic-gate }; 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate struct streamtab hdlctab = { 2000Sstevel@tonic-gate &hdlc_rinit, /* initialize read queue */ 2010Sstevel@tonic-gate &hdlc_winit, /* initialize write queue */ 2020Sstevel@tonic-gate NULL, /* mux read qinit */ 2030Sstevel@tonic-gate NULL /* mux write qinit */ 2040Sstevel@tonic-gate }; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(zsh_ops, nulldev, zsh_probe, zsh_attach, 2070Sstevel@tonic-gate zsh_detach, nodev, zsh_info, D_MP, &hdlctab); 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate /* 2100Sstevel@tonic-gate * This is the loadable module wrapper. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate #include <sys/errno.h> 2140Sstevel@tonic-gate #include <sys/modctl.h> 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate /* 2170Sstevel@tonic-gate * Module linkage information for the kernel. 2180Sstevel@tonic-gate */ 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate static struct modldrv modldrv = { 2210Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */ 2220Sstevel@tonic-gate "Z8530 serial HDLC drv V%I%", 2230Sstevel@tonic-gate &zsh_ops, /* our own ops for this module */ 2240Sstevel@tonic-gate }; 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate static struct modlinkage modlinkage = { 2270Sstevel@tonic-gate MODREV_1, 2280Sstevel@tonic-gate (void *)&modldrv, 2290Sstevel@tonic-gate NULL 2300Sstevel@tonic-gate }; 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate int 2330Sstevel@tonic-gate _init(void) 2340Sstevel@tonic-gate { 2350Sstevel@tonic-gate return (mod_install(&modlinkage)); 2360Sstevel@tonic-gate } 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate int 2390Sstevel@tonic-gate _fini(void) 2400Sstevel@tonic-gate { 2410Sstevel@tonic-gate return (mod_remove(&modlinkage)); 2420Sstevel@tonic-gate } 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate int 2450Sstevel@tonic-gate _info(struct modinfo *modinfop) 2460Sstevel@tonic-gate { 2470Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate /* 2520Sstevel@tonic-gate * The HDLC interrupt entry points. 2530Sstevel@tonic-gate */ 2540Sstevel@tonic-gate static void zsh_txint(struct zscom *zs); 2550Sstevel@tonic-gate static void zsh_xsint(struct zscom *zs); 2560Sstevel@tonic-gate static void zsh_rxint(struct zscom *zs); 2570Sstevel@tonic-gate static void zsh_srint(struct zscom *zs); 2580Sstevel@tonic-gate static int zsh_softint(struct zscom *zs); 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate struct zsops zsops_hdlc = { 2610Sstevel@tonic-gate zsh_txint, 2620Sstevel@tonic-gate zsh_xsint, 2630Sstevel@tonic-gate zsh_rxint, 2640Sstevel@tonic-gate zsh_srint, 2650Sstevel@tonic-gate zsh_softint, 2660Sstevel@tonic-gate NULL, 2670Sstevel@tonic-gate NULL 2680Sstevel@tonic-gate }; 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate static int zsh_program(struct zscom *zs, struct scc_mode *sm); 2710Sstevel@tonic-gate static void zsh_setmstat(struct zscom *zs, int event); 2720Sstevel@tonic-gate static void zsh_rxbad(struct zscom *zs, struct syncline *zss); 2730Sstevel@tonic-gate static void zsh_txbad(struct zscom *zs, struct syncline *zss); 2740Sstevel@tonic-gate static void zsh_watchdog(void *); 2750Sstevel@tonic-gate static void zsh_callback(void *); 2760Sstevel@tonic-gate static int zsh_hdp_ok_or_rts_state(struct zscom *zs, struct syncline *zss); 2770Sstevel@tonic-gate static void zsh_init_port(struct zscom *zs, struct syncline *zss); 2780Sstevel@tonic-gate static int zsh_setmode(struct zscom *zs, struct syncline *zss, 2790Sstevel@tonic-gate struct scc_mode *sm); 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate /* 2830Sstevel@tonic-gate * The HDLC Driver. 2840Sstevel@tonic-gate */ 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate /* 2880Sstevel@tonic-gate * Special macros to handle STREAMS operations. 2890Sstevel@tonic-gate * These are required to address memory leakage problems. 2900Sstevel@tonic-gate * WARNING : the macro do NOT call ZSSETSOFT 2910Sstevel@tonic-gate */ 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* 2940Sstevel@tonic-gate * Should be called holding only the adaptive (zs_excl) mutex. 2950Sstevel@tonic-gate */ 2960Sstevel@tonic-gate #define ZSH_GETBLOCK(zs, allocbcount) \ 2970Sstevel@tonic-gate { \ 2980Sstevel@tonic-gate register int n = ZSH_MAX_RSTANDBY; \ 2990Sstevel@tonic-gate while (--n >= 0) { \ 3000Sstevel@tonic-gate if (!zss->sl_rstandby[n]) { \ 3010Sstevel@tonic-gate if ((zss->sl_rstandby[n] = \ 3020Sstevel@tonic-gate allocb(zss->sl_mru, BPRI_MED)) == NULL) { \ 3030Sstevel@tonic-gate if (zss->sl_bufcid == 0) { \ 3040Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); \ 3050Sstevel@tonic-gate if (zss->sl_txstate != TX_OFF) { \ 3060Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); \ 3070Sstevel@tonic-gate zss->sl_bufcid = bufcall(zss->sl_mru, \ 3080Sstevel@tonic-gate BPRI_MED, zsh_callback, zs); \ 3090Sstevel@tonic-gate break; \ 3100Sstevel@tonic-gate } else \ 3110Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); \ 3120Sstevel@tonic-gate } \ 3130Sstevel@tonic-gate } \ 3140Sstevel@tonic-gate allocbcount--; \ 3150Sstevel@tonic-gate } \ 3160Sstevel@tonic-gate } \ 3170Sstevel@tonic-gate } 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate /* 3200Sstevel@tonic-gate * Should be called holding the spin (zs_excl_hi) mutex. 3210Sstevel@tonic-gate */ 3220Sstevel@tonic-gate #define ZSH_ALLOCB(mp) \ 3230Sstevel@tonic-gate { \ 3240Sstevel@tonic-gate register int n = ZSH_MAX_RSTANDBY; \ 3250Sstevel@tonic-gate mp = NULL; \ 3260Sstevel@tonic-gate while (--n >= 0) { \ 3270Sstevel@tonic-gate if ((mp = zss->sl_rstandby[n]) != NULL) { \ 3280Sstevel@tonic-gate zss->sl_rstandby[n] = NULL; \ 3290Sstevel@tonic-gate break; \ 3300Sstevel@tonic-gate } \ 3310Sstevel@tonic-gate } \ 3320Sstevel@tonic-gate } 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate #define ZSH_PUTQ(mp) \ 3350Sstevel@tonic-gate { \ 3360Sstevel@tonic-gate register int wptr, rptr; \ 3370Sstevel@tonic-gate wptr = zss->sl_rdone_wptr; \ 3380Sstevel@tonic-gate rptr = zss->sl_rdone_rptr; \ 3390Sstevel@tonic-gate zss->sl_rdone[wptr] = mp; \ 3400Sstevel@tonic-gate if ((wptr) + 1 == ZSH_RDONE_MAX) \ 3410Sstevel@tonic-gate zss->sl_rdone_wptr = wptr = 0; \ 3420Sstevel@tonic-gate else \ 3430Sstevel@tonic-gate zss->sl_rdone_wptr = ++wptr; \ 3440Sstevel@tonic-gate if (wptr == rptr) { /* Should never occur */ \ 3450Sstevel@tonic-gate SCC_BIC(1, ZSWR1_INIT); \ 3460Sstevel@tonic-gate zss->sl_m_error = ENOSR; \ 3470Sstevel@tonic-gate ZSSETSOFT(zs); \ 3480Sstevel@tonic-gate } \ 3490Sstevel@tonic-gate } 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate #define ZSH_FREEMSG(mp) \ 3520Sstevel@tonic-gate { \ 3530Sstevel@tonic-gate ZSH_PUTQ(mp); \ 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate /* 3580Sstevel@tonic-gate * Should be called holding only the adaptive (zs_excl) mutex. 3590Sstevel@tonic-gate */ 3600Sstevel@tonic-gate #define ZSH_GETQ(mp) \ 3610Sstevel@tonic-gate { \ 3620Sstevel@tonic-gate if (zss->sl_rdone_rptr != zss->sl_rdone_wptr) { \ 3630Sstevel@tonic-gate mp = zss->sl_rdone[zss->sl_rdone_rptr++]; \ 3640Sstevel@tonic-gate if (zss->sl_rdone_rptr == ZSH_RDONE_MAX) \ 3650Sstevel@tonic-gate zss->sl_rdone_rptr = 0; \ 3660Sstevel@tonic-gate } else \ 3670Sstevel@tonic-gate mp = NULL; \ 3680Sstevel@tonic-gate } 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate #define ZSH_FLUSHQ \ 3710Sstevel@tonic-gate { \ 3720Sstevel@tonic-gate register mblk_t *tmp; \ 3730Sstevel@tonic-gate for (;;) { \ 3740Sstevel@tonic-gate ZSH_GETQ(tmp); \ 3750Sstevel@tonic-gate if (!(tmp)) \ 3760Sstevel@tonic-gate break; \ 3770Sstevel@tonic-gate freemsg(tmp); \ 3780Sstevel@tonic-gate } \ 3790Sstevel@tonic-gate } 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate /*ARGSUSED*/ 3820Sstevel@tonic-gate static int 3830Sstevel@tonic-gate zsh_probe(dev_info_t *dev) 3840Sstevel@tonic-gate { 3850Sstevel@tonic-gate return (DDI_PROBE_DONTCARE); 3860Sstevel@tonic-gate } 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate /*ARGSUSED*/ 3890Sstevel@tonic-gate static int 3900Sstevel@tonic-gate zsh_attach(dev_info_t *dev, ddi_attach_cmd_t cmd) 3910Sstevel@tonic-gate { 3920Sstevel@tonic-gate register int unit; 3930Sstevel@tonic-gate char name[3] = { 3940Sstevel@tonic-gate '\0', '\0', '\0' }; 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate /* 3970Sstevel@tonic-gate * Since zsh is a child of the "pseudo" nexus, we can expect the 3980Sstevel@tonic-gate * attach routine to be called only once. We need to create all 3990Sstevel@tonic-gate * necessary devices in one shot. There is never more than one 4000Sstevel@tonic-gate * SCC chip that supports zsh devices. 4010Sstevel@tonic-gate */ 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate if (cmd != DDI_ATTACH) 4040Sstevel@tonic-gate return (DDI_FAILURE); 4050Sstevel@tonic-gate if (zscom == NULL) 4060Sstevel@tonic-gate return (DDI_FAILURE); /* zsattach not done */ 4070Sstevel@tonic-gate unit = 2 * ddi_get_instance(dev); 4080Sstevel@tonic-gate if (unit > 1) 4090Sstevel@tonic-gate return (DDI_FAILURE); /* only use cpu ports */ 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate if (ddi_create_minor_node(dev, "zsh", S_IFCHR, 4120Sstevel@tonic-gate NULL, DDI_PSEUDO, CLONE_DEV) == DDI_FAILURE) { 4130Sstevel@tonic-gate ddi_remove_minor_node(dev, NULL); 4140Sstevel@tonic-gate cmn_err(CE_WARN, "zsh clone device creation failed."); 4150Sstevel@tonic-gate return (DDI_FAILURE); 4160Sstevel@tonic-gate } 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate for (; unit < maxzsh/2; unit++) { 4190Sstevel@tonic-gate zscom[unit].zs_hdlc_dip = dev; 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate (void) sprintf(name, "%d", unit); 4220Sstevel@tonic-gate if (ddi_create_minor_node(dev, name, S_IFCHR, 4230Sstevel@tonic-gate 2*unit, DDI_PSEUDO, NULL) == DDI_FAILURE) { 4240Sstevel@tonic-gate ddi_remove_minor_node(dev, NULL); 4250Sstevel@tonic-gate return (DDI_FAILURE); 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate unit++; 4280Sstevel@tonic-gate (void) sprintf(name, "%d", unit); 4290Sstevel@tonic-gate if (ddi_create_minor_node(dev, name, S_IFCHR, 4300Sstevel@tonic-gate 2*(unit-1)+1, DDI_PSEUDO, NULL) == DDI_FAILURE) { 4310Sstevel@tonic-gate ddi_remove_minor_node(dev, NULL); 4320Sstevel@tonic-gate return (DDI_FAILURE); 4330Sstevel@tonic-gate } 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate return (DDI_SUCCESS); 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate /* ARGSUSED */ 4400Sstevel@tonic-gate int 4410Sstevel@tonic-gate zsh_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 4420Sstevel@tonic-gate void **result) 4430Sstevel@tonic-gate { 4440Sstevel@tonic-gate register dev_t dev = (dev_t)arg; 4450Sstevel@tonic-gate register int unit, error; 4460Sstevel@tonic-gate register struct zscom *zs; 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate if ((unit = UNIT(dev)) >= nzs) 4490Sstevel@tonic-gate return (DDI_FAILURE); 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate switch (infocmd) { 4520Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 4530Sstevel@tonic-gate if (zscom == NULL) { 4540Sstevel@tonic-gate error = DDI_FAILURE; 4550Sstevel@tonic-gate } else { 4560Sstevel@tonic-gate zs = &zscom[unit]; 4570Sstevel@tonic-gate *result = zs->zs_hdlc_dip; 4580Sstevel@tonic-gate error = DDI_SUCCESS; 4590Sstevel@tonic-gate } 4600Sstevel@tonic-gate break; 4610Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 462*796Smathue *result = (void *)(uintptr_t)(unit / 2); 4630Sstevel@tonic-gate error = DDI_SUCCESS; 4640Sstevel@tonic-gate break; 4650Sstevel@tonic-gate default: 4660Sstevel@tonic-gate error = DDI_FAILURE; 4670Sstevel@tonic-gate } 4680Sstevel@tonic-gate return (error); 4690Sstevel@tonic-gate } 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate static int 4720Sstevel@tonic-gate zsh_detach(dev_info_t *dev, ddi_detach_cmd_t cmd) 4730Sstevel@tonic-gate { 4740Sstevel@tonic-gate if (cmd != DDI_DETACH) 4750Sstevel@tonic-gate return (DDI_FAILURE); 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate ddi_remove_minor_node(dev, NULL); 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate return (DDI_SUCCESS); 4800Sstevel@tonic-gate } 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate static void 4830Sstevel@tonic-gate zsh_init_port(struct zscom *zs, struct syncline *zss) 4840Sstevel@tonic-gate { 4850Sstevel@tonic-gate register uchar_t s0; 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate SCC_WRITE(3, (ZSWR3_RX_ENABLE | ZSWR3_RXCRC_ENABLE | ZSWR3_RX_8)); 4880Sstevel@tonic-gate SCC_WRITE(5, (ZSWR5_TX_8 | ZSWR5_DTR | ZSWR5_TXCRC_ENABLE)); 4890Sstevel@tonic-gate zss->sl_rr0 = SCC_READ0(); 4900Sstevel@tonic-gate if (zss->sl_flags & SF_FDXPTP) { 4910Sstevel@tonic-gate SCC_BIS(5, ZSWR5_TX_ENABLE); 4920Sstevel@tonic-gate SCC_BIS(5, ZSWR5_RTS); 4930Sstevel@tonic-gate s0 = SCC_READ0(); 4940Sstevel@tonic-gate if ((s0 & ZSRR0_CTS) || 4950Sstevel@tonic-gate !(zss->sl_mode.sm_config & (CONN_SIGNAL | CONN_IBM))) { 4960Sstevel@tonic-gate /* 4970Sstevel@tonic-gate * send msg that CTS is up 4980Sstevel@tonic-gate */ 4990Sstevel@tonic-gate zss->sl_rr0 |= ZSRR0_CTS; 5000Sstevel@tonic-gate zss->sl_txstate = TX_IDLE; 5010Sstevel@tonic-gate } else { 5020Sstevel@tonic-gate zss->sl_flags |= SF_XMT_INPROG; 5030Sstevel@tonic-gate zss->sl_txstate = TX_RTS; 5040Sstevel@tonic-gate zss->sl_rr0 &= ~ZSRR0_CTS; 5050Sstevel@tonic-gate zss->sl_wd_count = zsh_timer_count; 5060Sstevel@tonic-gate if (!zss->sl_wd_id) 5070Sstevel@tonic-gate zss->sl_wd_id = timeout(zsh_watchdog, 5080Sstevel@tonic-gate zs, SIO_WATCHDOG_TICK); 5090Sstevel@tonic-gate } 5100Sstevel@tonic-gate } else { 5110Sstevel@tonic-gate SCC_BIC(15, ZSR15_CTS); 5120Sstevel@tonic-gate SCC_BIC(5, ZSWR5_TX_ENABLE); 5130Sstevel@tonic-gate SCC_BIC(5, ZSWR5_RTS); 5140Sstevel@tonic-gate zss->sl_flags &= ~SF_FLUSH_WQ; 5150Sstevel@tonic-gate } 5160Sstevel@tonic-gate } 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate /* 5190Sstevel@tonic-gate * Open routine. 5200Sstevel@tonic-gate */ 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate /*ARGSUSED*/ 5230Sstevel@tonic-gate static int 5240Sstevel@tonic-gate zsh_open(queue_t *rq, dev_t *dev, int flag, int sflag, cred_t *cr) 5250Sstevel@tonic-gate { 5260Sstevel@tonic-gate register struct zscom *zs; 5270Sstevel@tonic-gate register struct syncline *zss; 5280Sstevel@tonic-gate register struct ser_str *stp; 5290Sstevel@tonic-gate register int unit; 5300Sstevel@tonic-gate register int tmp; 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate if (sflag != CLONEOPEN) { 5330Sstevel@tonic-gate if (rq->q_ptr) 5340Sstevel@tonic-gate return (EBUSY); /* We got a stream that is in use */ 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate unit = UNIT(*dev); 5370Sstevel@tonic-gate if (unit >= maxzsh) 5380Sstevel@tonic-gate return (ENXIO); /* unit not configured */ 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate if (zscom == NULL) 5410Sstevel@tonic-gate return (ENXIO); /* device not found by autoconfig */ 5420Sstevel@tonic-gate zs = &zscom[unit]; 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate if (zs->zs_ops == NULL) { 5450Sstevel@tonic-gate return (ENXIO); /* device not found by autoconfig */ 5460Sstevel@tonic-gate } 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_OPEN, "zsh_open:unit = %d", unit); 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate mutex_enter(zs->zs_excl); 5510Sstevel@tonic-gate if ((zs->zs_ops != &zsops_null) && 5520Sstevel@tonic-gate (zs->zs_ops != &zsops_hdlc)) { 5530Sstevel@tonic-gate mutex_exit(zs->zs_excl); 5540Sstevel@tonic-gate return (EBUSY); /* another protocol got here first */ 5550Sstevel@tonic-gate } 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate /* Mark device as busy (for power management) */ 5580Sstevel@tonic-gate (void) pm_busy_component(zs->zs_dip, unit%2+1); 5590Sstevel@tonic-gate (void) ddi_dev_is_needed(zs->zs_dip, unit%2+1, 1); 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate zsopinit(zs, &zsops_hdlc); 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate zss = (struct syncline *)&zscom[unit].zs_priv_str; 5640Sstevel@tonic-gate stp = &zss->sl_stream; 5650Sstevel@tonic-gate stp->str_state = NULL; 5660Sstevel@tonic-gate stp->str_com = (caddr_t)zs; 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate zss->sl_xhead = NULL; 5690Sstevel@tonic-gate zss->sl_xactb = NULL; 5700Sstevel@tonic-gate zs->zs_wr_cur = NULL; 5710Sstevel@tonic-gate zs->zs_wr_lim = NULL; 5720Sstevel@tonic-gate zs->zs_wr_cur = NULL; 5730Sstevel@tonic-gate zs->zs_wr_lim = NULL; 5740Sstevel@tonic-gate zss->sl_rhead = NULL; 5750Sstevel@tonic-gate zss->sl_ractb = NULL; 5760Sstevel@tonic-gate zs->zs_rd_cur = NULL; 5770Sstevel@tonic-gate zs->zs_rd_lim = NULL; 5780Sstevel@tonic-gate zss->sl_mstat = NULL; 5790Sstevel@tonic-gate zss->sl_xstandby = NULL; 5800Sstevel@tonic-gate zss->sl_wd_id = 0; 5810Sstevel@tonic-gate zss->sl_soft_active = 0; 5820Sstevel@tonic-gate zss->sl_stream.str_rq = NULL; 5830Sstevel@tonic-gate 5840Sstevel@tonic-gate zs->zs_priv = (caddr_t)zss; 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate zss->sl_mru = zsh_default_mru; 5870Sstevel@tonic-gate tmp = ZSH_MAX_RSTANDBY; 5880Sstevel@tonic-gate ZSH_GETBLOCK(zs, tmp); 5890Sstevel@tonic-gate if (zss->sl_rstandby[0] == NULL) { 5900Sstevel@tonic-gate cmn_err(CE_WARN, "zsh_open: can't alloc message block"); 5910Sstevel@tonic-gate mutex_exit(zs->zs_excl); 5920Sstevel@tonic-gate return (ENOSR); 5930Sstevel@tonic-gate } 5940Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 5950Sstevel@tonic-gate ZSH_ALLOCB(zss->sl_ractb); 5960Sstevel@tonic-gate zss->sl_txstate = TX_OFF; 5970Sstevel@tonic-gate zss->sl_rr0 = SCC_READ0(); 5980Sstevel@tonic-gate zss->sl_flags &= (SF_INITIALIZED | SF_FDXPTP); 5990Sstevel@tonic-gate if (zss->sl_flags & SF_INITIALIZED) 6000Sstevel@tonic-gate zsh_init_port(zs, zss); 6010Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 6020Sstevel@tonic-gate mutex_exit(zs->zs_excl); 6030Sstevel@tonic-gate } else { /* CLONEOPEN */ 6040Sstevel@tonic-gate mutex_enter(&zs_curr_lock); 6050Sstevel@tonic-gate for (unit = maxzsh; unit < MAXZSHCLONES; unit++) 6060Sstevel@tonic-gate if (!zsh_usedminor[unit]) { 6070Sstevel@tonic-gate zsh_usedminor[unit] = (unsigned char)unit; 6080Sstevel@tonic-gate break; 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate mutex_exit(&zs_curr_lock); 6110Sstevel@tonic-gate if (unit >= MAXZSHCLONES) /* no slots available */ 6120Sstevel@tonic-gate return (ENODEV); 6130Sstevel@tonic-gate *dev = makedevice(getmajor(*dev), unit); 6140Sstevel@tonic-gate 6150Sstevel@tonic-gate stp = kmem_zalloc(sizeof (struct ser_str), KM_NOSLEEP); 6160Sstevel@tonic-gate if (stp == NULL) { 6170Sstevel@tonic-gate cmn_err(CE_WARN, 6180Sstevel@tonic-gate "zsh clone open failed, no memory, rq=%p\n", 6190Sstevel@tonic-gate (void *)rq); 6200Sstevel@tonic-gate return (ENOMEM); 6210Sstevel@tonic-gate } 6220Sstevel@tonic-gate stp->str_state = STR_CLONE; 6230Sstevel@tonic-gate stp->str_com = NULL; /* can't determine without ppa */ 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate stp->str_rq = rq; 6260Sstevel@tonic-gate stp->str_inst = unit; 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate rq->q_ptr = WR(rq)->q_ptr = (caddr_t)stp; 6290Sstevel@tonic-gate qprocson(rq); 6300Sstevel@tonic-gate return (0); 6310Sstevel@tonic-gate } 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate /* 6340Sstevel@tonic-gate * Close routine. 6350Sstevel@tonic-gate */ 6360Sstevel@tonic-gate int zsh_tx_enable_in_close = 0; 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate /*ARGSUSED*/ 6390Sstevel@tonic-gate static int 6400Sstevel@tonic-gate zsh_close(queue_t *rq, int flag) 6410Sstevel@tonic-gate { 6420Sstevel@tonic-gate struct ser_str *stp; 6430Sstevel@tonic-gate struct zscom *zs; 6440Sstevel@tonic-gate struct syncline *zss; 6450Sstevel@tonic-gate mblk_t *mp; 6460Sstevel@tonic-gate int i; 6470Sstevel@tonic-gate timeout_id_t sl_wd_id; 6480Sstevel@tonic-gate bufcall_id_t sl_bufcid; 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate /* 6510Sstevel@tonic-gate * Note that a close is only called on the last close of a 6520Sstevel@tonic-gate * particular stream. Assume that we need to do it all. 6530Sstevel@tonic-gate */ 6540Sstevel@tonic-gate qprocsoff(rq); /* no new business after this */ 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate stp = (struct ser_str *)rq->q_ptr; 6570Sstevel@tonic-gate if (stp == NULL) 6580Sstevel@tonic-gate return (0); /* already been closed once */ 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate if (stp->str_state == STR_CLONE) { 6610Sstevel@tonic-gate zsh_usedminor[stp->str_inst] = 0; 6620Sstevel@tonic-gate } else { 6630Sstevel@tonic-gate zs = (struct zscom *)stp->str_com; 6640Sstevel@tonic-gate if (zs == NULL) 6650Sstevel@tonic-gate goto out; 6660Sstevel@tonic-gate 6670Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_CLOSE, "zs = %p", zs); 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate zss = (struct syncline *)zs->zs_priv; 6700Sstevel@tonic-gate mutex_enter(zs->zs_excl); 6710Sstevel@tonic-gate flushq(WR(rq), FLUSHALL); 6720Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 6730Sstevel@tonic-gate if (zss->sl_xstandby) { 6740Sstevel@tonic-gate zss->sl_xstandby->b_wptr = zss->sl_xstandby->b_rptr; 6750Sstevel@tonic-gate ZSH_FREEMSG(zss->sl_xstandby); 6760Sstevel@tonic-gate zss->sl_xstandby = NULL; 6770Sstevel@tonic-gate } 6780Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate ZSH_FLUSHQ; 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate /* 6830Sstevel@tonic-gate * Stop the Watchdog Timer. 6840Sstevel@tonic-gate */ 6850Sstevel@tonic-gate if ((sl_wd_id = zss->sl_wd_id) != 0) 6860Sstevel@tonic-gate zss->sl_wd_id = 0; 6870Sstevel@tonic-gate 6880Sstevel@tonic-gate /* 6890Sstevel@tonic-gate * Cancel outstanding "bufcall" request. 6900Sstevel@tonic-gate */ 6910Sstevel@tonic-gate if ((sl_bufcid = zss->sl_bufcid) != 0) 6920Sstevel@tonic-gate zss->sl_bufcid = 0; 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 6950Sstevel@tonic-gate if (zs->zs_wr_cur) { 6960Sstevel@tonic-gate zs->zs_wr_cur = NULL; 6970Sstevel@tonic-gate zs->zs_wr_lim = NULL; 6980Sstevel@tonic-gate SCC_WRITE0(ZSWR0_SEND_ABORT); 6990Sstevel@tonic-gate ZSDELAY(); 7000Sstevel@tonic-gate ZSDELAY(); 7010Sstevel@tonic-gate } 7020Sstevel@tonic-gate zss->sl_txstate = TX_OFF; /* so it can't rearm in close */ 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate zs->zs_wr_cur = NULL; 7050Sstevel@tonic-gate zs->zs_wr_lim = NULL; 7060Sstevel@tonic-gate SCC_BIC(15, 7070Sstevel@tonic-gate (ZSR15_TX_UNDER | ZSR15_BREAK | ZSR15_SYNC | ZSR15_CTS)); 7080Sstevel@tonic-gate SCC_WRITE(3, 0); /* Quiesce receiver */ 7090Sstevel@tonic-gate if (zsh_tx_enable_in_close && !(zss->sl_flags & SF_FDXPTP)) { 7100Sstevel@tonic-gate SCC_BIS(5, ZSWR5_TX_ENABLE); 7110Sstevel@tonic-gate } else 7120Sstevel@tonic-gate SCC_BIC(5, ZSWR5_TX_ENABLE); 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate SCC_BIC(5, (ZSWR5_DTR | ZSWR5_RTS | ZSWR5_TXCRC_ENABLE)); 7150Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); /* reset TX */ 7160Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_STATUS); /* reset XS */ 7170Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_ERRORS); 7180Sstevel@tonic-gate (void) SCC_READDATA(); /* reset RX */ 7190Sstevel@tonic-gate ZSDELAY(); 7200Sstevel@tonic-gate (void) SCC_READDATA(); 7210Sstevel@tonic-gate ZSDELAY(); 7220Sstevel@tonic-gate (void) SCC_READDATA(); 7230Sstevel@tonic-gate ZSDELAY(); 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate /* 7270Sstevel@tonic-gate * Free up everything we ever allocated. 7280Sstevel@tonic-gate */ 7290Sstevel@tonic-gate if ((mp = zss->sl_rhead) != NULL) { 7300Sstevel@tonic-gate zss->sl_ractb = NULL; /* already freed */ 7310Sstevel@tonic-gate zs->zs_rd_cur = NULL; 7320Sstevel@tonic-gate zs->zs_rd_lim = NULL; 7330Sstevel@tonic-gate zss->sl_rhead = NULL; 7340Sstevel@tonic-gate } 7350Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 7360Sstevel@tonic-gate if (mp) 7370Sstevel@tonic-gate freemsg(mp); 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 7400Sstevel@tonic-gate if ((mp = zss->sl_ractb) != NULL) { 7410Sstevel@tonic-gate zs->zs_rd_cur = NULL; 7420Sstevel@tonic-gate zs->zs_rd_lim = NULL; 7430Sstevel@tonic-gate zss->sl_ractb = NULL; 7440Sstevel@tonic-gate } 7450Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 7460Sstevel@tonic-gate if (mp) 7470Sstevel@tonic-gate freemsg(mp); 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate for (i = 0; i < ZSH_MAX_RSTANDBY; i++) { 7500Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 7510Sstevel@tonic-gate mp = zss->sl_rstandby[i]; 7520Sstevel@tonic-gate zss->sl_rstandby[i] = NULL; 7530Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 7540Sstevel@tonic-gate if (mp) 7550Sstevel@tonic-gate freemsg(mp); 7560Sstevel@tonic-gate } 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 7590Sstevel@tonic-gate if ((mp = zss->sl_xhead) != NULL) { 7600Sstevel@tonic-gate zss->sl_xhead = NULL; 7610Sstevel@tonic-gate zss->sl_xactb = NULL; 7620Sstevel@tonic-gate } 7630Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 7640Sstevel@tonic-gate if (mp) 7650Sstevel@tonic-gate freemsg(mp); 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate ZSH_FLUSHQ; 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 7700Sstevel@tonic-gate if ((mp = zss->sl_xstandby) != NULL) 7710Sstevel@tonic-gate zss->sl_xstandby = NULL; 7720Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 7730Sstevel@tonic-gate if (mp) 7740Sstevel@tonic-gate freemsg(mp); 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 7770Sstevel@tonic-gate if ((mp = zss->sl_mstat) != NULL) 7780Sstevel@tonic-gate zss->sl_mstat = NULL; 7790Sstevel@tonic-gate zss->sl_txstate = TX_OFF; /* so it can't rearm in close */ 7800Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 7810Sstevel@tonic-gate if (mp) 7820Sstevel@tonic-gate freemsg(mp); 7830Sstevel@tonic-gate 7840Sstevel@tonic-gate zss->sl_stream.str_rq = NULL; 7850Sstevel@tonic-gate zsopinit(zs, &zsops_null); 7860Sstevel@tonic-gate mutex_exit(zs->zs_excl); 7870Sstevel@tonic-gate if (sl_wd_id) 7880Sstevel@tonic-gate (void) untimeout(sl_wd_id); 7890Sstevel@tonic-gate if (sl_bufcid) 7900Sstevel@tonic-gate unbufcall(sl_bufcid); 7910Sstevel@tonic-gate while (zss->sl_soft_active) 7920Sstevel@tonic-gate drv_usecwait(1); 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate /* Mark device as available for power management */ 7950Sstevel@tonic-gate (void) pm_idle_component(zs->zs_dip, zs->zs_unit%2+1); 7960Sstevel@tonic-gate } 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate if (stp->str_state == STR_CLONE) 7990Sstevel@tonic-gate kmem_free(stp, sizeof (struct ser_str)); 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate out: 8020Sstevel@tonic-gate rq->q_ptr = WR(rq)->q_ptr = NULL; 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate return (0); 8050Sstevel@tonic-gate } 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate static int 8080Sstevel@tonic-gate zsh_hdp_ok_or_rts_state(struct zscom *zs, struct syncline *zss) 8090Sstevel@tonic-gate { 8100Sstevel@tonic-gate register uchar_t s0; 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate SCC_BIS(15, ZSR15_CTS); 8130Sstevel@tonic-gate SCC_BIS(5, ZSWR5_RTS); 8140Sstevel@tonic-gate s0 = SCC_READ0(); 8150Sstevel@tonic-gate if (s0 & ZSRR0_CTS) { 8160Sstevel@tonic-gate SCC_BIS(5, ZSWR5_TX_ENABLE); 8170Sstevel@tonic-gate zss->sl_rr0 |= ZSRR0_CTS; 8180Sstevel@tonic-gate return (1); 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate zss->sl_flags |= SF_XMT_INPROG; 8210Sstevel@tonic-gate zss->sl_txstate = TX_RTS; 8220Sstevel@tonic-gate zss->sl_rr0 &= ~ZSRR0_CTS; 8230Sstevel@tonic-gate zss->sl_wd_count = zsh_timer_count; 8240Sstevel@tonic-gate return (0); 8250Sstevel@tonic-gate } 8260Sstevel@tonic-gate 8270Sstevel@tonic-gate /* 8280Sstevel@tonic-gate * Put procedure for write queue. 8290Sstevel@tonic-gate */ 8300Sstevel@tonic-gate static void 8310Sstevel@tonic-gate zsh_wput(queue_t *wq, mblk_t *mp) 8320Sstevel@tonic-gate { 8330Sstevel@tonic-gate register struct ser_str *stp = (struct ser_str *)wq->q_ptr; 8340Sstevel@tonic-gate register struct zscom *zs; 8350Sstevel@tonic-gate register struct syncline *zss = NULL; 8360Sstevel@tonic-gate register ulong_t prim, error = 0; 8370Sstevel@tonic-gate register union DL_primitives *dlp; 8380Sstevel@tonic-gate register int ppa; 8390Sstevel@tonic-gate register mblk_t *tmp; 8400Sstevel@tonic-gate register struct copyresp *resp; 8410Sstevel@tonic-gate 8420Sstevel@tonic-gate /* 8430Sstevel@tonic-gate * stp->str_com supplied by open or DLPI attach. 8440Sstevel@tonic-gate */ 8450Sstevel@tonic-gate if (stp == NULL) { 8460Sstevel@tonic-gate freemsg(mp); 8470Sstevel@tonic-gate return; 8480Sstevel@tonic-gate } 8490Sstevel@tonic-gate zs = (struct zscom *)stp->str_com; 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate TRACE_0(TR_ZSH, TR_ZSH_WPUT_START, "zsh_wput start"); 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate if ((mp->b_datap->db_type == M_FLUSH) && 8540Sstevel@tonic-gate (stp->str_state == STR_CLONE)) { 8550Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) { 8560Sstevel@tonic-gate flushq(wq, FLUSHDATA); 8570Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHW; 8580Sstevel@tonic-gate } 8590Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) 8600Sstevel@tonic-gate qreply(wq, mp); /* let the read queues have at it */ 8610Sstevel@tonic-gate else 8620Sstevel@tonic-gate freemsg(mp); 8630Sstevel@tonic-gate return; 8640Sstevel@tonic-gate } 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate if ((zs == NULL) && (mp->b_datap->db_type != M_PROTO)) { 8670Sstevel@tonic-gate freemsg(mp); 8680Sstevel@tonic-gate cmn_err(CE_WARN, 8690Sstevel@tonic-gate "zsh: clone device %d must be attached before use!", 8700Sstevel@tonic-gate stp->str_inst); 8710Sstevel@tonic-gate (void) putnextctl1(RD(wq), M_ERROR, EPROTO); 8720Sstevel@tonic-gate return; 8730Sstevel@tonic-gate } 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate if (stp->str_state == STR_CLONE) { /* Clone opened, limited. */ 8760Sstevel@tonic-gate if ((mp->b_datap->db_type != M_PROTO) && 8770Sstevel@tonic-gate (mp->b_datap->db_type != M_IOCTL) && 8780Sstevel@tonic-gate (mp->b_datap->db_type != M_IOCDATA)) { 8790Sstevel@tonic-gate freemsg(mp); 8800Sstevel@tonic-gate cmn_err(CE_WARN, 8810Sstevel@tonic-gate "zsh%x: invalid operation for clone dev.\n", 8820Sstevel@tonic-gate stp->str_inst); 8830Sstevel@tonic-gate (void) putnextctl1(RD(wq), M_ERROR, EPROTO); 8840Sstevel@tonic-gate return; 8850Sstevel@tonic-gate } 8860Sstevel@tonic-gate } else { 8870Sstevel@tonic-gate zss = (struct syncline *)zs->zs_priv; 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate switch (mp->b_datap->db_type) { 8910Sstevel@tonic-gate 8920Sstevel@tonic-gate case M_DATA: 8930Sstevel@tonic-gate /* 8940Sstevel@tonic-gate * Queue the message up to be transmitted. 8950Sstevel@tonic-gate * Set "in progress" flag and call the start routine. 8960Sstevel@tonic-gate */ 8970Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 8980Sstevel@tonic-gate if (!(zss->sl_flags & SF_INITIALIZED)) { 8990Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 9000Sstevel@tonic-gate cmn_err(CE_WARN, 9010Sstevel@tonic-gate "zsh%x not initialized, can't send message", 9020Sstevel@tonic-gate zs->zs_unit); 9030Sstevel@tonic-gate freemsg(mp); 9040Sstevel@tonic-gate (void) putnextctl1(RD(wq), M_ERROR, ECOMM); 9050Sstevel@tonic-gate return; 9060Sstevel@tonic-gate } 9070Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 9080Sstevel@tonic-gate if (zs->zs_flags & ZS_NEEDSOFT) { 9090Sstevel@tonic-gate zs->zs_flags &= ~ZS_NEEDSOFT; 9100Sstevel@tonic-gate (void) zsh_softint(zs); 9110Sstevel@tonic-gate } 9120Sstevel@tonic-gate while (mp->b_wptr == mp->b_rptr) { 9130Sstevel@tonic-gate register mblk_t *mp1; 9140Sstevel@tonic-gate mp1 = unlinkb(mp); 9150Sstevel@tonic-gate freemsg(mp); 9160Sstevel@tonic-gate mp = mp1; 9170Sstevel@tonic-gate if (mp == NULL) 9180Sstevel@tonic-gate return; 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate mutex_enter(zs->zs_excl); 9210Sstevel@tonic-gate (void) putq(wq, mp); 9220Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 9230Sstevel@tonic-gate if (zss->sl_flags & SF_FLUSH_WQ) { 9240Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 9250Sstevel@tonic-gate flushq(wq, FLUSHDATA); 9260Sstevel@tonic-gate mutex_exit(zs->zs_excl); 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_WPUT_END, 9290Sstevel@tonic-gate "zsh_wput end: zs = %p", zs); 9300Sstevel@tonic-gate 9310Sstevel@tonic-gate return; 9320Sstevel@tonic-gate } 9330Sstevel@tonic-gate tmp = NULL; 9340Sstevel@tonic-gate again: 9350Sstevel@tonic-gate if (!zss->sl_xstandby) { 9360Sstevel@tonic-gate if (tmp) 9370Sstevel@tonic-gate zss->sl_xstandby = tmp; 9380Sstevel@tonic-gate else { 9390Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 9400Sstevel@tonic-gate tmp = getq(wq); 9410Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 9420Sstevel@tonic-gate if (tmp) 9430Sstevel@tonic-gate goto again; 9440Sstevel@tonic-gate } 9450Sstevel@tonic-gate } else if (tmp) { 9460Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 9470Sstevel@tonic-gate (void) putbq(wq, tmp); 9480Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 9490Sstevel@tonic-gate } 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate if (zss->sl_flags & SF_XMT_INPROG) { 9520Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 9530Sstevel@tonic-gate mutex_exit(zs->zs_excl); 9540Sstevel@tonic-gate 9550Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_WPUT_END, 9560Sstevel@tonic-gate "zsh_wput end: zs = %p", zs); 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate return; 9590Sstevel@tonic-gate } 9600Sstevel@tonic-gate 9610Sstevel@tonic-gate if (!zss->sl_wd_id) { 9620Sstevel@tonic-gate zss->sl_wd_count = zsh_timer_count; 9630Sstevel@tonic-gate zss->sl_txstate = TX_IDLE; 9640Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 9650Sstevel@tonic-gate zss->sl_wd_id = timeout(zsh_watchdog, zs, 9660Sstevel@tonic-gate SIO_WATCHDOG_TICK); 9670Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 9680Sstevel@tonic-gate } 9690Sstevel@tonic-gate 9700Sstevel@tonic-gate zss->sl_flags |= SF_XMT_INPROG; 9710Sstevel@tonic-gate if ((zss->sl_flags & SF_FDXPTP) || 9720Sstevel@tonic-gate zsh_hdp_ok_or_rts_state(zs, zss)) 9730Sstevel@tonic-gate (void) zsh_start(zs, zss); 9740Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 9750Sstevel@tonic-gate mutex_exit(zs->zs_excl); 9760Sstevel@tonic-gate break; 9770Sstevel@tonic-gate 9780Sstevel@tonic-gate case M_PROTO: 9790Sstevel@tonic-gate /* 9800Sstevel@tonic-gate * Here is where a clone device finds out about the 9810Sstevel@tonic-gate * hardware it is going to attach to. The request is 9820Sstevel@tonic-gate * validated and a ppa is extracted from it and validated. 9830Sstevel@tonic-gate * This number is used to index the hardware data structure 9840Sstevel@tonic-gate * and the protocol data structure, in case the latter 9850Sstevel@tonic-gate * was not provided by a data-path open before this. 9860Sstevel@tonic-gate */ 9870Sstevel@tonic-gate if (stp->str_state != STR_CLONE) { 9880Sstevel@tonic-gate freemsg(mp); 9890Sstevel@tonic-gate return; 9900Sstevel@tonic-gate } 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate if (MBLKL(mp) < DL_ATTACH_REQ_SIZE) { 9930Sstevel@tonic-gate prim = DL_ATTACH_REQ; 9940Sstevel@tonic-gate error = DL_BADPRIM; 9950Sstevel@tonic-gate goto end_proto; 9960Sstevel@tonic-gate } 9970Sstevel@tonic-gate dlp = (union DL_primitives *)mp->b_rptr; 9980Sstevel@tonic-gate prim = dlp->dl_primitive; 9990Sstevel@tonic-gate if (prim != DL_ATTACH_REQ) { 10000Sstevel@tonic-gate error = DL_BADPRIM; 10010Sstevel@tonic-gate goto end_proto; 10020Sstevel@tonic-gate } 10030Sstevel@tonic-gate ppa = dlp->attach_req.dl_ppa; 10040Sstevel@tonic-gate ppa = (ppa%2) ? ((ppa-1)*2 +1) : (ppa*2); 10050Sstevel@tonic-gate if (ppa >= maxzsh) { 10060Sstevel@tonic-gate error = DL_BADPPA; 10070Sstevel@tonic-gate goto end_proto; 10080Sstevel@tonic-gate } 10090Sstevel@tonic-gate zs = &zscom[ppa]; 10100Sstevel@tonic-gate if (zs->zs_ops == NULL) { 10110Sstevel@tonic-gate error = ENXIO; 10120Sstevel@tonic-gate goto end_proto; 10130Sstevel@tonic-gate } 10140Sstevel@tonic-gate mutex_enter(zs->zs_excl); 10150Sstevel@tonic-gate if ((zs->zs_ops != &zsops_null) && 10160Sstevel@tonic-gate (zs->zs_ops != &zsops_hdlc)) { 10170Sstevel@tonic-gate /* 10180Sstevel@tonic-gate * another protocol got here first 10190Sstevel@tonic-gate */ 10200Sstevel@tonic-gate error = (EBUSY); 10210Sstevel@tonic-gate mutex_exit(zs->zs_excl); 10220Sstevel@tonic-gate goto end_proto; 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate } 10250Sstevel@tonic-gate 10260Sstevel@tonic-gate stp->str_com = (caddr_t)zs; 10270Sstevel@tonic-gate mutex_exit(zs->zs_excl); 10280Sstevel@tonic-gate end_proto: 10290Sstevel@tonic-gate if (error) 10300Sstevel@tonic-gate dlerrorack(wq, mp, prim, error, 0); 10310Sstevel@tonic-gate else 10320Sstevel@tonic-gate dlokack(wq, mp, DL_ATTACH_REQ); 10330Sstevel@tonic-gate break; 10340Sstevel@tonic-gate 10350Sstevel@tonic-gate case M_IOCTL: 10360Sstevel@tonic-gate zsh_ioctl(wq, mp); 10370Sstevel@tonic-gate break; 10380Sstevel@tonic-gate 10390Sstevel@tonic-gate case M_IOCDATA: 10400Sstevel@tonic-gate resp = (struct copyresp *)mp->b_rptr; 10410Sstevel@tonic-gate if (resp->cp_rval) { 10420Sstevel@tonic-gate /* 10430Sstevel@tonic-gate * Just free message on failure. 10440Sstevel@tonic-gate */ 10450Sstevel@tonic-gate freemsg(mp); 10460Sstevel@tonic-gate break; 10470Sstevel@tonic-gate } 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate switch (resp->cp_cmd) { 10500Sstevel@tonic-gate 10510Sstevel@tonic-gate case S_IOCGETMODE: 10520Sstevel@tonic-gate case S_IOCGETSTATS: 10530Sstevel@tonic-gate case S_IOCGETSPEED: 10540Sstevel@tonic-gate case S_IOCGETMCTL: 10550Sstevel@tonic-gate case S_IOCGETMRU: 10560Sstevel@tonic-gate mioc2ack(mp, NULL, 0, 0); 10570Sstevel@tonic-gate qreply(wq, mp); 10580Sstevel@tonic-gate break; 10590Sstevel@tonic-gate 10600Sstevel@tonic-gate case S_IOCSETMODE: 10610Sstevel@tonic-gate zss = (struct syncline *)&zs->zs_priv_str; 10620Sstevel@tonic-gate mutex_enter(zs->zs_excl); 10630Sstevel@tonic-gate error = zsh_setmode(zs, zss, 10640Sstevel@tonic-gate (struct scc_mode *)mp->b_cont->b_rptr); 10650Sstevel@tonic-gate if (error) { 10660Sstevel@tonic-gate register struct iocblk *iocp = 10670Sstevel@tonic-gate (struct iocblk *)mp->b_rptr; 10680Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 10690Sstevel@tonic-gate iocp->ioc_error = error; 10700Sstevel@tonic-gate } else 10710Sstevel@tonic-gate mioc2ack(mp, NULL, 0, 0); 10720Sstevel@tonic-gate mutex_exit(zs->zs_excl); 10730Sstevel@tonic-gate qreply(wq, mp); 10740Sstevel@tonic-gate break; 10750Sstevel@tonic-gate 10760Sstevel@tonic-gate case S_IOCSETMRU: 10770Sstevel@tonic-gate zss = (struct syncline *)&zs->zs_priv_str; 10780Sstevel@tonic-gate mutex_enter(zs->zs_excl); 10790Sstevel@tonic-gate zss->sl_mru = *(int *)mp->b_cont->b_rptr; 10800Sstevel@tonic-gate mutex_exit(zs->zs_excl); 10810Sstevel@tonic-gate mioc2ack(mp, NULL, 0, 0); 10820Sstevel@tonic-gate qreply(wq, mp); 10830Sstevel@tonic-gate break; 10840Sstevel@tonic-gate default: 10850Sstevel@tonic-gate freemsg(mp); 10860Sstevel@tonic-gate } 10870Sstevel@tonic-gate break; 10880Sstevel@tonic-gate 10890Sstevel@tonic-gate /* 10900Sstevel@tonic-gate * We're at the bottom of the food chain, so we flush our 10910Sstevel@tonic-gate * write queue, clear the FLUSHW bit so it doesn't go round 10920Sstevel@tonic-gate * and round forever, then flush our read queue (since there's 10930Sstevel@tonic-gate * no read put procedure down here) and pass it up for any 10940Sstevel@tonic-gate * higher modules to deal with in their own way. 10950Sstevel@tonic-gate */ 10960Sstevel@tonic-gate case M_FLUSH: 10970Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) { 10980Sstevel@tonic-gate mutex_enter(zs->zs_excl); 10990Sstevel@tonic-gate flushq(wq, FLUSHDATA); 11000Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 11010Sstevel@tonic-gate tmp = zss->sl_xstandby; 11020Sstevel@tonic-gate zss->sl_xstandby = NULL; 11030Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 11040Sstevel@tonic-gate if (tmp) 11050Sstevel@tonic-gate freemsg(tmp); 11060Sstevel@tonic-gate mutex_exit(zs->zs_excl); 11070Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHW; 11080Sstevel@tonic-gate } 11090Sstevel@tonic-gate 11100Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) { 11110Sstevel@tonic-gate mutex_enter(zs->zs_excl); 11120Sstevel@tonic-gate ZSH_FLUSHQ; 11130Sstevel@tonic-gate mutex_exit(zs->zs_excl); 11140Sstevel@tonic-gate qreply(wq, mp); /* let the read queues have at it */ 11150Sstevel@tonic-gate } else 11160Sstevel@tonic-gate freemsg(mp); 11170Sstevel@tonic-gate break; 11180Sstevel@tonic-gate 11190Sstevel@tonic-gate default: 11200Sstevel@tonic-gate /* 11210Sstevel@tonic-gate * "No, I don't want a subscription to Chain Store Age, 11220Sstevel@tonic-gate * thank you anyway." 11230Sstevel@tonic-gate */ 11240Sstevel@tonic-gate freemsg(mp); 11250Sstevel@tonic-gate break; 11260Sstevel@tonic-gate } 11270Sstevel@tonic-gate 11280Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_WPUT_END, "zsh_wput end: zs = %p", zs); 11290Sstevel@tonic-gate } 11300Sstevel@tonic-gate 11310Sstevel@tonic-gate /* 11320Sstevel@tonic-gate * Get the next message from the write queue, set up the necessary pointers, 11330Sstevel@tonic-gate * state info, etc., and start the transmit "engine" by sending the first 11340Sstevel@tonic-gate * character. We'll then rotate through txint until done, then get an xsint. 11350Sstevel@tonic-gate */ 11360Sstevel@tonic-gate static int 11370Sstevel@tonic-gate zsh_start(struct zscom *zs, struct syncline *zss) 11380Sstevel@tonic-gate { 11390Sstevel@tonic-gate register mblk_t *mp; 11400Sstevel@tonic-gate register uchar_t *wptr; 11410Sstevel@tonic-gate register uchar_t *rptr; 11420Sstevel@tonic-gate register uchar_t sl_flags = zss->sl_flags; 11430Sstevel@tonic-gate 11440Sstevel@tonic-gate /* 11450Sstevel@tonic-gate * Attempt to grab the next M_DATA message off the queue (that's 11460Sstevel@tonic-gate * all that will be left after wput) and begin transmission. 11470Sstevel@tonic-gate * This routine is normally called after completion of a previous 11480Sstevel@tonic-gate * frame, or when zsh_wput gets a new message. If we are in a 11490Sstevel@tonic-gate * mode that put us in the TX_RTS state, waiting for CTS, and CTS 11500Sstevel@tonic-gate * is not up yet, we have no business here. Ditto if we're in 11510Sstevel@tonic-gate * either the TX_ACTIVE or TX_CRC states. In these cases we 11520Sstevel@tonic-gate * don't clear SF_CALLSTART, so we don't forget there's work to do. 11530Sstevel@tonic-gate */ 11540Sstevel@tonic-gate 11550Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_START_START, 11560Sstevel@tonic-gate "zsh_start start: zs = %p", zs); 11570Sstevel@tonic-gate 11580Sstevel@tonic-gate if (sl_flags & SF_PHONY) { 11590Sstevel@tonic-gate sl_flags &= ~SF_PHONY; 11600Sstevel@tonic-gate SCC_BIC(15, ZSR15_CTS); 11610Sstevel@tonic-gate SCC_BIC(5, ZSWR5_RTS); 11620Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); 11630Sstevel@tonic-gate SCC_BIC(5, ZSWR5_TX_ENABLE); 11640Sstevel@tonic-gate zss->sl_rr0 &= ~ZSRR0_CTS; 11650Sstevel@tonic-gate zss->sl_txstate = TX_IDLE; 11660Sstevel@tonic-gate /* 11670Sstevel@tonic-gate * if we get another msg by chance zsh_watchog will start 11680Sstevel@tonic-gate */ 11690Sstevel@tonic-gate sl_flags &= ~SF_XMT_INPROG; 11700Sstevel@tonic-gate zss->sl_flags = sl_flags; 11710Sstevel@tonic-gate 11720Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_START_END, 11730Sstevel@tonic-gate "zsh_start end: zs = %d", zs); 11740Sstevel@tonic-gate 11750Sstevel@tonic-gate return (0); 11760Sstevel@tonic-gate } 11770Sstevel@tonic-gate mp = zss->sl_xstandby; 11780Sstevel@tonic-gate if (mp == NULL) { 11790Sstevel@tonic-gate if (!(sl_flags & SF_FDXPTP)) { 11800Sstevel@tonic-gate sl_flags |= SF_PHONY; 11810Sstevel@tonic-gate ZSH_ALLOCB(mp); 11820Sstevel@tonic-gate if (!mp) 11830Sstevel@tonic-gate return (0); 11840Sstevel@tonic-gate mp->b_datap->db_type = M_RSE; 11850Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + 1; 11860Sstevel@tonic-gate goto transmit; 11870Sstevel@tonic-gate } 11880Sstevel@tonic-gate sl_flags &= ~SF_XMT_INPROG; 11890Sstevel@tonic-gate zss->sl_flags = sl_flags; 11900Sstevel@tonic-gate 11910Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_START_END, 11920Sstevel@tonic-gate "zsh_start end: zs = %p", zs); 11930Sstevel@tonic-gate 11940Sstevel@tonic-gate return (0); 11950Sstevel@tonic-gate } 11960Sstevel@tonic-gate 11970Sstevel@tonic-gate transmit: 11980Sstevel@tonic-gate zss->sl_xstandby = NULL; 11990Sstevel@tonic-gate rptr = mp->b_rptr; 12000Sstevel@tonic-gate wptr = mp->b_wptr; 12010Sstevel@tonic-gate ZSSETSOFT(zs); 12020Sstevel@tonic-gate 12030Sstevel@tonic-gate #ifdef ZSH_DEBUG 12040Sstevel@tonic-gate if (zss->sl_xhead || zss->sl_xactb) { 12050Sstevel@tonic-gate debug_enter("xhead1"); 12060Sstevel@tonic-gate } 12070Sstevel@tonic-gate #endif 12080Sstevel@tonic-gate 12090Sstevel@tonic-gate zss->sl_xhead = mp; 12100Sstevel@tonic-gate zss->sl_xactb = mp; 12110Sstevel@tonic-gate zss->sl_wd_count = zsh_timer_count; 12120Sstevel@tonic-gate zss->sl_txstate = TX_ACTIVE; 12130Sstevel@tonic-gate zss->sl_ocnt = 0; 12140Sstevel@tonic-gate SCC_BIS(10, ZSWR10_UNDERRUN_ABORT); /* abort on underrun */ 12150Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXCRC); /* reset transmit CRC */ 12160Sstevel@tonic-gate zss->sl_ocnt = wptr - rptr; 12170Sstevel@tonic-gate mp->b_wptr = rptr; /* to tell soft to free this msg */ 12180Sstevel@tonic-gate SCC_WRITEDATA(*rptr++); /* resets TXINT */ 12190Sstevel@tonic-gate zs->zs_wr_cur = rptr; 12200Sstevel@tonic-gate zs->zs_wr_lim = wptr; 12210Sstevel@tonic-gate 12220Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_EOM); 12230Sstevel@tonic-gate 12240Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_START_END, 12250Sstevel@tonic-gate "zsh_start end: zs = %p", zs); 12260Sstevel@tonic-gate 12270Sstevel@tonic-gate zss->sl_flags = sl_flags; 12280Sstevel@tonic-gate return (1); 12290Sstevel@tonic-gate } 12300Sstevel@tonic-gate 12310Sstevel@tonic-gate 12320Sstevel@tonic-gate /* 12330Sstevel@tonic-gate * Process an "ioctl" message sent down to us. 12340Sstevel@tonic-gate */ 12350Sstevel@tonic-gate static void 12360Sstevel@tonic-gate zsh_ioctl(queue_t *wq, mblk_t *mp) 12370Sstevel@tonic-gate { 12380Sstevel@tonic-gate register struct ser_str *stp = (struct ser_str *)wq->q_ptr; 12390Sstevel@tonic-gate register struct zscom *zs = (struct zscom *)stp->str_com; 12400Sstevel@tonic-gate register struct syncline *zss = (struct syncline *)&zs->zs_priv_str; 12410Sstevel@tonic-gate register struct iocblk *iocp = (struct iocblk *)mp->b_rptr; 12420Sstevel@tonic-gate register struct scc_mode *sm; 12430Sstevel@tonic-gate register struct sl_stats *st; 12440Sstevel@tonic-gate register uchar_t *msignals; 12450Sstevel@tonic-gate register mblk_t *tmp; 12460Sstevel@tonic-gate register int error = 0; 12470Sstevel@tonic-gate 12480Sstevel@tonic-gate mutex_enter(zs->zs_excl); 12490Sstevel@tonic-gate if ((zs->zs_ops != &zsops_null) && 12500Sstevel@tonic-gate (zs->zs_ops != &zsops_hdlc)) { 12510Sstevel@tonic-gate /* 12520Sstevel@tonic-gate * another protocol got here first 12530Sstevel@tonic-gate */ 12540Sstevel@tonic-gate error = (EBUSY); 12550Sstevel@tonic-gate goto end_zsh_ioctl; 12560Sstevel@tonic-gate } 12570Sstevel@tonic-gate 12580Sstevel@tonic-gate 12590Sstevel@tonic-gate switch (iocp->ioc_cmd) { 12600Sstevel@tonic-gate 12610Sstevel@tonic-gate case S_IOCGETMODE: 12620Sstevel@tonic-gate tmp = allocb(sizeof (struct scc_mode), BPRI_MED); 12630Sstevel@tonic-gate if (tmp == NULL) { 12640Sstevel@tonic-gate error = EAGAIN; 12650Sstevel@tonic-gate break; 12660Sstevel@tonic-gate } 12670Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) 12680Sstevel@tonic-gate mioc2ack(mp, tmp, sizeof (struct scc_mode), 0); 12690Sstevel@tonic-gate else 12700Sstevel@tonic-gate mcopyout(mp, NULL, sizeof (struct scc_mode), NULL, tmp); 12710Sstevel@tonic-gate sm = (struct scc_mode *)mp->b_cont->b_rptr; 12720Sstevel@tonic-gate bcopy(&zss->sl_mode, sm, sizeof (struct scc_mode)); 12730Sstevel@tonic-gate break; 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate case S_IOCGETSTATS: 12760Sstevel@tonic-gate tmp = allocb(sizeof (struct sl_stats), BPRI_MED); 12770Sstevel@tonic-gate if (tmp == NULL) { 12780Sstevel@tonic-gate error = EAGAIN; 12790Sstevel@tonic-gate break; 12800Sstevel@tonic-gate } 12810Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) 12820Sstevel@tonic-gate mioc2ack(mp, tmp, sizeof (struct sl_stats), 0); 12830Sstevel@tonic-gate else 12840Sstevel@tonic-gate mcopyout(mp, NULL, sizeof (struct sl_stats), NULL, tmp); 12850Sstevel@tonic-gate st = (struct sl_stats *)mp->b_cont->b_rptr; 12860Sstevel@tonic-gate bcopy(&zss->sl_st, st, sizeof (struct sl_stats)); 12870Sstevel@tonic-gate break; 12880Sstevel@tonic-gate 12890Sstevel@tonic-gate case S_IOCGETSPEED: 12900Sstevel@tonic-gate tmp = allocb(sizeof (int), BPRI_MED); 12910Sstevel@tonic-gate if (tmp == NULL) { 12920Sstevel@tonic-gate error = EAGAIN; 12930Sstevel@tonic-gate break; 12940Sstevel@tonic-gate } 12950Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) 12960Sstevel@tonic-gate mioc2ack(mp, tmp, sizeof (int), 0); 12970Sstevel@tonic-gate else 12980Sstevel@tonic-gate mcopyout(mp, NULL, sizeof (int), NULL, tmp); 12990Sstevel@tonic-gate *(int *)mp->b_cont->b_rptr = zss->sl_mode.sm_baudrate; 13000Sstevel@tonic-gate break; 13010Sstevel@tonic-gate 13020Sstevel@tonic-gate case S_IOCGETMCTL: 13030Sstevel@tonic-gate tmp = allocb(sizeof (char), BPRI_MED); 13040Sstevel@tonic-gate if (tmp == NULL) { 13050Sstevel@tonic-gate error = EAGAIN; 13060Sstevel@tonic-gate break; 13070Sstevel@tonic-gate } 13080Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) 13090Sstevel@tonic-gate mioc2ack(mp, tmp, sizeof (char), 0); 13100Sstevel@tonic-gate else 13110Sstevel@tonic-gate mcopyout(mp, NULL, sizeof (char), NULL, tmp); 13120Sstevel@tonic-gate msignals = (uchar_t *)mp->b_cont->b_rptr; 13130Sstevel@tonic-gate *msignals = zss->sl_rr0 & (ZSRR0_CD | ZSRR0_CTS); 13140Sstevel@tonic-gate break; 13150Sstevel@tonic-gate 13160Sstevel@tonic-gate case S_IOCGETMRU: 13170Sstevel@tonic-gate tmp = allocb(sizeof (int), BPRI_MED); 13180Sstevel@tonic-gate if (tmp == NULL) { 13190Sstevel@tonic-gate error = EAGAIN; 13200Sstevel@tonic-gate break; 13210Sstevel@tonic-gate } 13220Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) 13230Sstevel@tonic-gate mioc2ack(mp, tmp, sizeof (int), 0); 13240Sstevel@tonic-gate else 13250Sstevel@tonic-gate mcopyout(mp, NULL, sizeof (int), NULL, tmp); 13260Sstevel@tonic-gate *(int *)mp->b_cont->b_rptr = zss->sl_mru; 13270Sstevel@tonic-gate break; 13280Sstevel@tonic-gate 13290Sstevel@tonic-gate case S_IOCSETMODE: 13300Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) { 13310Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct scc_mode)); 13320Sstevel@tonic-gate if (error != 0) 13330Sstevel@tonic-gate break; 13340Sstevel@tonic-gate error = zsh_setmode(zs, zss, 13350Sstevel@tonic-gate (struct scc_mode *)mp->b_cont->b_rptr); 13360Sstevel@tonic-gate if (error == 0) 13370Sstevel@tonic-gate mioc2ack(mp, NULL, 0, 0); 13380Sstevel@tonic-gate } else 13390Sstevel@tonic-gate mcopyin(mp, NULL, sizeof (struct scc_mode), NULL); 13400Sstevel@tonic-gate break; 13410Sstevel@tonic-gate 13420Sstevel@tonic-gate case S_IOCCLRSTATS: 13430Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 13440Sstevel@tonic-gate bzero(&zss->sl_st, sizeof (struct sl_stats)); 13450Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 13460Sstevel@tonic-gate mioc2ack(mp, NULL, 0, 0); 13470Sstevel@tonic-gate break; 13480Sstevel@tonic-gate 13490Sstevel@tonic-gate case S_IOCSETMRU: 13500Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) { 13510Sstevel@tonic-gate error = miocpullup(mp, sizeof (int)); 13520Sstevel@tonic-gate if (error != 0) 13530Sstevel@tonic-gate break; 13540Sstevel@tonic-gate zss->sl_mru = *(int *)mp->b_cont->b_rptr; 13550Sstevel@tonic-gate mioc2ack(mp, NULL, 0, 0); 13560Sstevel@tonic-gate } else 13570Sstevel@tonic-gate mcopyin(mp, NULL, sizeof (int), NULL); 13580Sstevel@tonic-gate break; 13590Sstevel@tonic-gate 13600Sstevel@tonic-gate case S_IOCSETDTR: 13610Sstevel@tonic-gate /* 13620Sstevel@tonic-gate * The first integer of the M_DATA block that should 13630Sstevel@tonic-gate * follow indicate if DTR must be set or reset 13640Sstevel@tonic-gate */ 13650Sstevel@tonic-gate error = miocpullup(mp, sizeof (int)); 13660Sstevel@tonic-gate if (error != 0) 13670Sstevel@tonic-gate break; 13680Sstevel@tonic-gate 13690Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 13700Sstevel@tonic-gate if (*(int *)mp->b_cont->b_rptr != 0) 13710Sstevel@tonic-gate (void) zsmctl(zs, ZSWR5_DTR, DMBIS); 13720Sstevel@tonic-gate else 13730Sstevel@tonic-gate (void) zsmctl(zs, ZSWR5_DTR, DMBIC); 13740Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 13750Sstevel@tonic-gate break; 13760Sstevel@tonic-gate 13770Sstevel@tonic-gate default: 13780Sstevel@tonic-gate error = EINVAL; 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate } 13810Sstevel@tonic-gate end_zsh_ioctl: 13820Sstevel@tonic-gate iocp->ioc_error = error; 13830Sstevel@tonic-gate mp->b_datap->db_type = (error) ? M_IOCNAK : M_IOCACK; 13840Sstevel@tonic-gate mutex_exit(zs->zs_excl); 13850Sstevel@tonic-gate qreply(wq, mp); 13860Sstevel@tonic-gate } 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate /* 13890Sstevel@tonic-gate * Set the mode of the zsh port 13900Sstevel@tonic-gate */ 13910Sstevel@tonic-gate 13920Sstevel@tonic-gate int 13930Sstevel@tonic-gate zsh_setmode(struct zscom *zs, struct syncline *zss, struct scc_mode *sm) 13940Sstevel@tonic-gate { 13950Sstevel@tonic-gate register int error = 0; 13960Sstevel@tonic-gate register mblk_t *mp; 13970Sstevel@tonic-gate 13980Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 13990Sstevel@tonic-gate if (sm->sm_rxclock == RXC_IS_PLL) { 14000Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_RXC; 14010Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 14020Sstevel@tonic-gate return (EINVAL); /* not supported */ 14030Sstevel@tonic-gate } else { 14040Sstevel@tonic-gate if (((zss->sl_mode.sm_config ^ sm->sm_config) & 14050Sstevel@tonic-gate CONN_SIGNAL) != 0) { /* Changing, going... */ 14060Sstevel@tonic-gate if (sm->sm_config & CONN_SIGNAL) { /* ...up. */ 14070Sstevel@tonic-gate if (zss->sl_mstat == NULL) { 14080Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 14090Sstevel@tonic-gate mp = allocb( 14100Sstevel@tonic-gate sizeof (struct sl_status), BPRI_MED); 14110Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 14120Sstevel@tonic-gate zss->sl_mstat = mp; 14130Sstevel@tonic-gate } 14140Sstevel@tonic-gate } else { /* ...down. */ 14150Sstevel@tonic-gate if ((mp = zss->sl_mstat) != NULL) 14160Sstevel@tonic-gate zss->sl_mstat = NULL; 14170Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 14180Sstevel@tonic-gate if (mp) 14190Sstevel@tonic-gate freemsg(mp); 14200Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 14210Sstevel@tonic-gate } 14220Sstevel@tonic-gate } 14230Sstevel@tonic-gate if (!(sm->sm_config & CONN_IBM)) { 14240Sstevel@tonic-gate if (sm->sm_config & CONN_HDX) { 14250Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_HDX; 14260Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 14270Sstevel@tonic-gate return (EINVAL); 14280Sstevel@tonic-gate } 14290Sstevel@tonic-gate if (sm->sm_config & CONN_MPT) { 14300Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_MPT; 14310Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 14320Sstevel@tonic-gate return (EINVAL); 14330Sstevel@tonic-gate } 14340Sstevel@tonic-gate } 14350Sstevel@tonic-gate zss->sl_flags &= ~SF_FDXPTP; /* "conmode" */ 14360Sstevel@tonic-gate if ((sm->sm_config & (CONN_HDX | CONN_MPT)) == 0) 14370Sstevel@tonic-gate zss->sl_flags |= SF_FDXPTP; 14380Sstevel@tonic-gate 14390Sstevel@tonic-gate error = zsh_program(zs, sm); 14400Sstevel@tonic-gate if (!error && (zs->zs_ops != &zsops_null)) 14410Sstevel@tonic-gate zsh_init_port(zs, zss); 14420Sstevel@tonic-gate } 14430Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 14440Sstevel@tonic-gate 14450Sstevel@tonic-gate return (error); 14460Sstevel@tonic-gate } 14470Sstevel@tonic-gate 14480Sstevel@tonic-gate /* 14490Sstevel@tonic-gate * Transmit interrupt service procedure 14500Sstevel@tonic-gate */ 14510Sstevel@tonic-gate 14520Sstevel@tonic-gate static void 14530Sstevel@tonic-gate zsh_txint(struct zscom *zs) 14540Sstevel@tonic-gate { 14550Sstevel@tonic-gate register struct syncline *zss; 14560Sstevel@tonic-gate register mblk_t *mp; 14570Sstevel@tonic-gate register int tmp; 14580Sstevel@tonic-gate register uchar_t *wr_cur; 14590Sstevel@tonic-gate 14600Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_TXINT, "zsh_txint: zs = %p", zs); 14610Sstevel@tonic-gate 14620Sstevel@tonic-gate if ((wr_cur = zs->zs_wr_cur) != NULL && (wr_cur < zs->zs_wr_lim)) { 14630Sstevel@tonic-gate SCC_WRITEDATA(*wr_cur++); 14640Sstevel@tonic-gate zs->zs_wr_cur = wr_cur; 14650Sstevel@tonic-gate return; 14660Sstevel@tonic-gate } 14670Sstevel@tonic-gate 14680Sstevel@tonic-gate 14690Sstevel@tonic-gate zss = (struct syncline *)&zs->zs_priv_str; 14700Sstevel@tonic-gate 14710Sstevel@tonic-gate switch (zss->sl_txstate) { 14720Sstevel@tonic-gate 14730Sstevel@tonic-gate /* 14740Sstevel@tonic-gate * we here because end of message block lim = cur 14750Sstevel@tonic-gate */ 14760Sstevel@tonic-gate case TX_ACTIVE: 14770Sstevel@tonic-gate 14780Sstevel@tonic-gate mp = zss->sl_xactb; 14790Sstevel@tonic-gate 14800Sstevel@tonic-gate again_txint: 14810Sstevel@tonic-gate mp = mp->b_cont; 14820Sstevel@tonic-gate if (mp) { 14830Sstevel@tonic-gate zss->sl_xactb = mp; 14840Sstevel@tonic-gate zss->sl_ocnt += tmp = mp->b_wptr - mp->b_rptr; 14850Sstevel@tonic-gate if (!tmp) 14860Sstevel@tonic-gate goto again_txint; 14870Sstevel@tonic-gate zs->zs_wr_cur = mp->b_rptr; 14880Sstevel@tonic-gate zs->zs_wr_lim = mp->b_wptr; 14890Sstevel@tonic-gate SCC_WRITEDATA(*zs->zs_wr_cur++); 14900Sstevel@tonic-gate return; 14910Sstevel@tonic-gate } 14920Sstevel@tonic-gate 14930Sstevel@tonic-gate /* 14940Sstevel@tonic-gate * This is where the fun starts. At this point the 14950Sstevel@tonic-gate * last character in the frame has been sent. We 14960Sstevel@tonic-gate * issue a RESET_TXINT so we won't get another txint 14970Sstevel@tonic-gate * until the CRC has been completely sent. Also we 14980Sstevel@tonic-gate * reset the Abort-On-Underrun bit so that CRC is 14990Sstevel@tonic-gate * sent at EOM, rather than an Abort. 15000Sstevel@tonic-gate */ 15010Sstevel@tonic-gate zs->zs_wr_cur = zs->zs_wr_lim = NULL; 15020Sstevel@tonic-gate zss->sl_txstate = TX_CRC; 15030Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); 15040Sstevel@tonic-gate if (!(zss->sl_flags & SF_PHONY)) { 15050Sstevel@tonic-gate SCC_BIC(10, ZSWR10_UNDERRUN_ABORT); 15060Sstevel@tonic-gate zss->sl_st.opack++; 15070Sstevel@tonic-gate zss->sl_st.ochar += zss->sl_ocnt; 15080Sstevel@tonic-gate } 15090Sstevel@tonic-gate zss->sl_ocnt = 0; 15100Sstevel@tonic-gate ZSH_FREEMSG(zss->sl_xhead); 15110Sstevel@tonic-gate zss->sl_xhead = zss->sl_xactb = NULL; 15120Sstevel@tonic-gate ZSSETSOFT(zs); 15130Sstevel@tonic-gate break; 15140Sstevel@tonic-gate /* 15150Sstevel@tonic-gate * This txint means we have sent the CRC bytes at EOF. 15160Sstevel@tonic-gate * The next txint will mean we are sending or have sent the 15170Sstevel@tonic-gate * flag character at EOF, but we handle that differently, and 15180Sstevel@tonic-gate * enter different states,depending on whether we're IBM or not. 15190Sstevel@tonic-gate */ 15200Sstevel@tonic-gate case TX_CRC: 15210Sstevel@tonic-gate if (!(zss->sl_flags & SF_FDXPTP)) { 15220Sstevel@tonic-gate zss->sl_txstate = TX_FLAG; /* HDX path */ 15230Sstevel@tonic-gate } else { /* FDX path */ 15240Sstevel@tonic-gate if (!zsh_start(zs, zss)) { 15250Sstevel@tonic-gate zss->sl_txstate = TX_IDLE; 15260Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); 15270Sstevel@tonic-gate } 15280Sstevel@tonic-gate } 15290Sstevel@tonic-gate break; 15300Sstevel@tonic-gate 15310Sstevel@tonic-gate /* 15320Sstevel@tonic-gate * This txint means the closing flag byte is going out the door. 15330Sstevel@tonic-gate * We use this state to allow this to complete before dropping RTS. 15340Sstevel@tonic-gate */ 15350Sstevel@tonic-gate case TX_FLAG: 15360Sstevel@tonic-gate zss->sl_txstate = TX_LAST; 15370Sstevel@tonic-gate (void) zsh_start(zs, zss); 15380Sstevel@tonic-gate break; 15390Sstevel@tonic-gate 15400Sstevel@tonic-gate /* 15410Sstevel@tonic-gate * Arriving here means the flag should be out and it's finally 15420Sstevel@tonic-gate * time to close the barn door. 15430Sstevel@tonic-gate */ 15440Sstevel@tonic-gate case TX_LAST: 15450Sstevel@tonic-gate zss->sl_txstate = TX_IDLE; 15460Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); 15470Sstevel@tonic-gate break; 15480Sstevel@tonic-gate 15490Sstevel@tonic-gate /* 15500Sstevel@tonic-gate * If transmit was aborted, do nothing - watchdog will recover. 15510Sstevel@tonic-gate */ 15520Sstevel@tonic-gate case TX_ABORTED: 15530Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); 15540Sstevel@tonic-gate break; 15550Sstevel@tonic-gate 15560Sstevel@tonic-gate default: 15570Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); 15580Sstevel@tonic-gate break; 15590Sstevel@tonic-gate } 15600Sstevel@tonic-gate } 15610Sstevel@tonic-gate 15620Sstevel@tonic-gate /* 15630Sstevel@tonic-gate * External Status Change interrupt service procedure 15640Sstevel@tonic-gate */ 15650Sstevel@tonic-gate static void 15660Sstevel@tonic-gate zsh_xsint(struct zscom *zs) 15670Sstevel@tonic-gate { 15680Sstevel@tonic-gate register struct syncline *zss = (struct syncline *)&zs->zs_priv_str; 15690Sstevel@tonic-gate register uchar_t s0, x0; 15700Sstevel@tonic-gate 15710Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_XSINT, "zsh_xsint: zs = %p", zs); 15720Sstevel@tonic-gate 15730Sstevel@tonic-gate s0 = SCC_READ0(); 15740Sstevel@tonic-gate x0 = s0 ^ zss->sl_rr0; 15750Sstevel@tonic-gate zss->sl_rr0 = s0; 15760Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_STATUS); 15770Sstevel@tonic-gate 15780Sstevel@tonic-gate if (s0 & ZSRR0_TXUNDER) { 15790Sstevel@tonic-gate switch (zss->sl_txstate) { 15800Sstevel@tonic-gate /* 15810Sstevel@tonic-gate * A transmitter underrun has occurred. If we are not 15820Sstevel@tonic-gate * here as the result of an abort sent by the watchdog 15830Sstevel@tonic-gate * timeout routine, we need to send an abort to flush 15840Sstevel@tonic-gate * the transmitter. Otherwise there is a danger of 15850Sstevel@tonic-gate * trashing the next frame but still sending a good crc. 15860Sstevel@tonic-gate * The TX_ABORTED flag is set so that the watchdog 15870Sstevel@tonic-gate * routine can initiate recovery. 15880Sstevel@tonic-gate */ 15890Sstevel@tonic-gate case TX_ACTIVE: 15900Sstevel@tonic-gate SCC_WRITE0(ZSWR0_SEND_ABORT); 15910Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); 15920Sstevel@tonic-gate zss->sl_st.underrun++; 15930Sstevel@tonic-gate zsh_txbad(zs, zss); 15940Sstevel@tonic-gate 15950Sstevel@tonic-gate zss->sl_txstate = TX_ABORTED; 15960Sstevel@tonic-gate zss->sl_wd_count = 0; 15970Sstevel@tonic-gate break; 15980Sstevel@tonic-gate 15990Sstevel@tonic-gate case TX_CRC: 16000Sstevel@tonic-gate break; 16010Sstevel@tonic-gate 16020Sstevel@tonic-gate case TX_FLAG: 16030Sstevel@tonic-gate break; 16040Sstevel@tonic-gate 16050Sstevel@tonic-gate case TX_ABORTED: 16060Sstevel@tonic-gate break; 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate case TX_OFF: 16090Sstevel@tonic-gate break; 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate case TX_LAST: 16120Sstevel@tonic-gate break; 16130Sstevel@tonic-gate 16140Sstevel@tonic-gate default: 16150Sstevel@tonic-gate break; 16160Sstevel@tonic-gate } 16170Sstevel@tonic-gate } 16180Sstevel@tonic-gate 16190Sstevel@tonic-gate if ((x0 & ZSRR0_BREAK) && (s0 & ZSRR0_BREAK) && zs->zs_rd_cur) { 16200Sstevel@tonic-gate zss->sl_st.abort++; 16210Sstevel@tonic-gate zsh_rxbad(zs, zss); 16220Sstevel@tonic-gate } else if ((s0 & ZSRR0_SYNC) && (zs->zs_rd_cur)) { 16230Sstevel@tonic-gate /* 16240Sstevel@tonic-gate * Tricky code to avoid disaster in the case where 16250Sstevel@tonic-gate * an abort was detected while receiving a packet, 16260Sstevel@tonic-gate * but the abort did not last long enough to be 16270Sstevel@tonic-gate * detected by zsh_xsint - this can happen since 16280Sstevel@tonic-gate * the ZSRR0_BREAK is not latched. Since an abort 16290Sstevel@tonic-gate * will automatically cause the SCC to enter 16300Sstevel@tonic-gate * hunt mode, hopefully, the sync/hunt bit will be 16310Sstevel@tonic-gate * set in this case (although if the interrupt is 16320Sstevel@tonic-gate * sufficiently delayed, the SCC may have sync'ed 16330Sstevel@tonic-gate * in again if it has detected a flag). 16340Sstevel@tonic-gate */ 16350Sstevel@tonic-gate zss->sl_st.abort++; 16360Sstevel@tonic-gate zsh_rxbad(zs, zss); 16370Sstevel@tonic-gate } 16380Sstevel@tonic-gate 16390Sstevel@tonic-gate if (x0 & s0 & ZSRR0_CTS) { 16400Sstevel@tonic-gate if (zss->sl_txstate == TX_RTS) { 16410Sstevel@tonic-gate if (!(zss->sl_flags & SF_FDXPTP)) { 16420Sstevel@tonic-gate SCC_BIS(5, ZSWR5_TX_ENABLE); 16430Sstevel@tonic-gate } 16440Sstevel@tonic-gate (void) zsh_start(zs, zss); 16450Sstevel@tonic-gate } else if ((zss->sl_mode.sm_config & (CONN_IBM | CONN_SIGNAL))) { 16460Sstevel@tonic-gate zss->sl_flags &= ~SF_FLUSH_WQ; 16470Sstevel@tonic-gate zsh_setmstat(zs, CS_CTS_UP); 16480Sstevel@tonic-gate } 16490Sstevel@tonic-gate } 16500Sstevel@tonic-gate 16510Sstevel@tonic-gate /* 16520Sstevel@tonic-gate * We don't care about CTS transitions unless we are in either 16530Sstevel@tonic-gate * IBM or SIGNAL mode, or both. So, if we see CTS drop, and we 16540Sstevel@tonic-gate * care, and we are not idle, send up a report message. 16550Sstevel@tonic-gate */ 16560Sstevel@tonic-gate if ((x0 & ZSRR0_CTS) && ((s0 & ZSRR0_CTS) == 0) && 16570Sstevel@tonic-gate (zss->sl_txstate != TX_OFF) && 16580Sstevel@tonic-gate (zss->sl_mode.sm_config & (CONN_IBM | CONN_SIGNAL))) { 16590Sstevel@tonic-gate SCC_BIC(15, ZSR15_CTS); 16600Sstevel@tonic-gate zsh_setmstat(zs, CS_CTS_DOWN); 16610Sstevel@tonic-gate zss->sl_flags &= ~SF_XMT_INPROG; 16620Sstevel@tonic-gate zss->sl_flags |= SF_FLUSH_WQ; 16630Sstevel@tonic-gate zss->sl_st.cts++; 16640Sstevel@tonic-gate if (zss->sl_txstate != TX_IDLE) 16650Sstevel@tonic-gate SCC_WRITE0(ZSWR0_SEND_ABORT); 16660Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_ERRORS); 16670Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); 16680Sstevel@tonic-gate zss->sl_wd_count = 0; 16690Sstevel@tonic-gate zsh_txbad(zs, zss); 16700Sstevel@tonic-gate } 16710Sstevel@tonic-gate } 16720Sstevel@tonic-gate 16730Sstevel@tonic-gate 16740Sstevel@tonic-gate /* 16750Sstevel@tonic-gate * Receive interrupt service procedure 16760Sstevel@tonic-gate */ 16770Sstevel@tonic-gate static void 16780Sstevel@tonic-gate zsh_rxint(struct zscom *zs) 16790Sstevel@tonic-gate { 16800Sstevel@tonic-gate register struct syncline *zss = (struct syncline *)&zs->zs_priv_str; 16810Sstevel@tonic-gate register mblk_t *bp = zss->sl_ractb; 16820Sstevel@tonic-gate unsigned char *rd_cur; 16830Sstevel@tonic-gate 16840Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_RXINT, "zsh_rxint: zs = %p", zs); 16850Sstevel@tonic-gate 16860Sstevel@tonic-gate if (((rd_cur = zs->zs_rd_cur) != NULL) && rd_cur < zs->zs_rd_lim) { 16870Sstevel@tonic-gate *rd_cur++ = SCC_READDATA(); 16880Sstevel@tonic-gate zs->zs_rd_cur = rd_cur; 16890Sstevel@tonic-gate return; 16900Sstevel@tonic-gate } 16910Sstevel@tonic-gate 16920Sstevel@tonic-gate if (!rd_cur) { /* Beginning of frame */ 16930Sstevel@tonic-gate if (!bp) { 16940Sstevel@tonic-gate ZSH_ALLOCB(bp); 16950Sstevel@tonic-gate zss->sl_ractb = bp; 16960Sstevel@tonic-gate } 16970Sstevel@tonic-gate zss->sl_rhead = bp; 16980Sstevel@tonic-gate } else { /* end of data block should be cur==lim */ 16990Sstevel@tonic-gate bp->b_wptr = zs->zs_rd_cur; 17000Sstevel@tonic-gate ZSH_ALLOCB(bp->b_cont); 17010Sstevel@tonic-gate bp = zss->sl_ractb = bp->b_cont; 17020Sstevel@tonic-gate } 17030Sstevel@tonic-gate if (!bp) { 17040Sstevel@tonic-gate zss->sl_st.nobuffers++; 17050Sstevel@tonic-gate zsh_rxbad(zs, zss); 17060Sstevel@tonic-gate return; 17070Sstevel@tonic-gate } 17080Sstevel@tonic-gate zs->zs_rd_cur = bp->b_wptr; 17090Sstevel@tonic-gate zs->zs_rd_lim = bp->b_datap->db_lim; 17100Sstevel@tonic-gate *zs->zs_rd_cur++ = SCC_READDATA(); /* Also resets interrupt */ 17110Sstevel@tonic-gate } 17120Sstevel@tonic-gate 17130Sstevel@tonic-gate 17140Sstevel@tonic-gate /* 17150Sstevel@tonic-gate * Special Receive Condition Interrupt routine 17160Sstevel@tonic-gate */ 17170Sstevel@tonic-gate static void 17180Sstevel@tonic-gate zsh_srint(struct zscom *zs) 17190Sstevel@tonic-gate { 17200Sstevel@tonic-gate register struct syncline *zss = (struct syncline *)&zs->zs_priv_str; 17210Sstevel@tonic-gate register uchar_t s1; 17220Sstevel@tonic-gate register uchar_t *rd_cur; 17230Sstevel@tonic-gate 17240Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_SRINT, "zsh_srint: zs = %p", zs); 17250Sstevel@tonic-gate 17260Sstevel@tonic-gate SCC_READ(1, s1); 17270Sstevel@tonic-gate 17280Sstevel@tonic-gate if (s1 & ZSRR1_RXEOF) { /* end of frame */ 17290Sstevel@tonic-gate (void) SCC_READDATA(); 17300Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_ERRORS); 17310Sstevel@tonic-gate if (s1 & ZSRR1_FE) { /* bad CRC */ 17320Sstevel@tonic-gate zss->sl_st.crc++; 17330Sstevel@tonic-gate zsh_rxbad(zs, zss); 17340Sstevel@tonic-gate return; 17350Sstevel@tonic-gate } 17360Sstevel@tonic-gate 17370Sstevel@tonic-gate if ((rd_cur = zs->zs_rd_cur) == NULL) 17380Sstevel@tonic-gate return; 17390Sstevel@tonic-gate 17400Sstevel@tonic-gate /* 17410Sstevel@tonic-gate * Drop one CRC byte from length because it came in 17420Sstevel@tonic-gate * before the special interrupt got here. 17430Sstevel@tonic-gate */ 17440Sstevel@tonic-gate zss->sl_ractb->b_wptr = rd_cur - 1; 17450Sstevel@tonic-gate 17460Sstevel@tonic-gate /* 17470Sstevel@tonic-gate * put on done queue 17480Sstevel@tonic-gate */ 17490Sstevel@tonic-gate ZSH_PUTQ(zss->sl_rhead); 17500Sstevel@tonic-gate zss->sl_rhead = NULL; 17510Sstevel@tonic-gate zss->sl_ractb = NULL; 17520Sstevel@tonic-gate zs->zs_rd_cur = NULL; 17530Sstevel@tonic-gate zs->zs_rd_lim = NULL; 17540Sstevel@tonic-gate ZSSETSOFT(zs); 17550Sstevel@tonic-gate 17560Sstevel@tonic-gate } else if (s1 & ZSRR1_DO) { 17570Sstevel@tonic-gate (void) SCC_READDATA(); 17580Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_ERRORS); 17590Sstevel@tonic-gate zss->sl_st.overrun++; 17600Sstevel@tonic-gate zsh_rxbad(zs, zss); 17610Sstevel@tonic-gate } else 17620Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_ERRORS); 17630Sstevel@tonic-gate } 17640Sstevel@tonic-gate 17650Sstevel@tonic-gate /* 17660Sstevel@tonic-gate * Handle a second stage interrupt. 17670Sstevel@tonic-gate * Does mostly lower priority buffer management stuff. 17680Sstevel@tonic-gate */ 17690Sstevel@tonic-gate static int 17700Sstevel@tonic-gate zsh_softint(struct zscom *zs) 17710Sstevel@tonic-gate { 17720Sstevel@tonic-gate register struct syncline *zss; 17730Sstevel@tonic-gate register queue_t *q; 17740Sstevel@tonic-gate register mblk_t *mp, *tmp; 17750Sstevel@tonic-gate register mblk_t *head = NULL, *tail = NULL; 17760Sstevel@tonic-gate register int allocbcount = 0; 17770Sstevel@tonic-gate int m_error; 17780Sstevel@tonic-gate 17790Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_SOFT_START, "zsh_soft start: zs = %p", zs); 17800Sstevel@tonic-gate 17810Sstevel@tonic-gate mutex_enter(zs->zs_excl); 17820Sstevel@tonic-gate zss = (struct syncline *)zs->zs_priv; 17830Sstevel@tonic-gate if (!zss || (q = zss->sl_stream.str_rq) == NULL) { 17840Sstevel@tonic-gate mutex_exit(zs->zs_excl); 17850Sstevel@tonic-gate return (0); 17860Sstevel@tonic-gate } 17870Sstevel@tonic-gate m_error = zss->sl_m_error; 17880Sstevel@tonic-gate 17890Sstevel@tonic-gate zss->sl_m_error = 0; 17900Sstevel@tonic-gate 17910Sstevel@tonic-gate 17920Sstevel@tonic-gate if (!zss->sl_mstat) 17930Sstevel@tonic-gate zss->sl_mstat = allocb(sizeof (struct sl_status), BPRI_MED); 17940Sstevel@tonic-gate 17950Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 17960Sstevel@tonic-gate if (zss->sl_flags & SF_FLUSH_WQ) { 17970Sstevel@tonic-gate if (!(zss->sl_flags & SF_FDXPTP)) { 17980Sstevel@tonic-gate zss->sl_flags &= ~SF_FLUSH_WQ; 17990Sstevel@tonic-gate } else { 18000Sstevel@tonic-gate register uchar_t s0; 18010Sstevel@tonic-gate 18020Sstevel@tonic-gate s0 = SCC_READ0(); 18030Sstevel@tonic-gate if (s0 & ZSRR0_CTS) { 18040Sstevel@tonic-gate zss->sl_rr0 |= ZSRR0_CTS; 18050Sstevel@tonic-gate SCC_BIS(15, ZSR15_CTS); 18060Sstevel@tonic-gate zss->sl_flags &= ~SF_FLUSH_WQ; 18070Sstevel@tonic-gate zsh_setmstat(zs, CS_CTS_UP); 18080Sstevel@tonic-gate } 18090Sstevel@tonic-gate if (zss->sl_flags & SF_FLUSH_WQ) { 18100Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 18110Sstevel@tonic-gate flushq(WR(q), FLUSHDATA); 18120Sstevel@tonic-gate goto next; 18130Sstevel@tonic-gate } 18140Sstevel@tonic-gate } 18150Sstevel@tonic-gate } 18160Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 18170Sstevel@tonic-gate 18180Sstevel@tonic-gate next: 18190Sstevel@tonic-gate for (;;) { 18200Sstevel@tonic-gate ZSH_GETQ(mp); 18210Sstevel@tonic-gate if (!mp) 18220Sstevel@tonic-gate break; 18230Sstevel@tonic-gate 18240Sstevel@tonic-gate if (mp->b_rptr == mp->b_wptr) { 18250Sstevel@tonic-gate if (mp->b_datap->db_type == M_RSE) { 18260Sstevel@tonic-gate allocbcount++; 18270Sstevel@tonic-gate } 18280Sstevel@tonic-gate freemsg(mp); 18290Sstevel@tonic-gate continue; 18300Sstevel@tonic-gate } 18310Sstevel@tonic-gate if (mp->b_datap->db_type == M_DATA) { 18320Sstevel@tonic-gate zss->sl_st.ichar += msgdsize(mp); 18330Sstevel@tonic-gate zss->sl_st.ipack++; 18340Sstevel@tonic-gate if (!(canputnext(q))) { 18350Sstevel@tonic-gate zss->sl_st.ierror++; 18360Sstevel@tonic-gate allocbcount++; 18370Sstevel@tonic-gate freemsg(mp); 18380Sstevel@tonic-gate continue; 18390Sstevel@tonic-gate } 18400Sstevel@tonic-gate } else if (mp->b_datap->db_type == M_PROTO) { 18410Sstevel@tonic-gate if (!(canputnext(q))) { 18420Sstevel@tonic-gate freemsg(mp); 18430Sstevel@tonic-gate continue; 18440Sstevel@tonic-gate } 18450Sstevel@tonic-gate } 18460Sstevel@tonic-gate if (!head) { 18470Sstevel@tonic-gate allocbcount++; 18480Sstevel@tonic-gate zss->sl_soft_active = 1; 18490Sstevel@tonic-gate head = mp; 18500Sstevel@tonic-gate } else { 18510Sstevel@tonic-gate if (!tail) 18520Sstevel@tonic-gate tail = head; 18530Sstevel@tonic-gate tail->b_next = mp; 18540Sstevel@tonic-gate tail = mp; 18550Sstevel@tonic-gate } 18560Sstevel@tonic-gate } 18570Sstevel@tonic-gate if (allocbcount) 18580Sstevel@tonic-gate ZSH_GETBLOCK(zs, allocbcount); 18590Sstevel@tonic-gate 18600Sstevel@tonic-gate tmp = NULL; 18610Sstevel@tonic-gate again: 18620Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 18630Sstevel@tonic-gate if (!zss->sl_xstandby) { 18640Sstevel@tonic-gate if (tmp) { 18650Sstevel@tonic-gate zss->sl_xstandby = tmp; 18660Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 18670Sstevel@tonic-gate } else { 18680Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 18690Sstevel@tonic-gate if (tmp = getq(WR(q))) 18700Sstevel@tonic-gate goto again; 18710Sstevel@tonic-gate } 18720Sstevel@tonic-gate } else { 18730Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 18740Sstevel@tonic-gate if (tmp) 18750Sstevel@tonic-gate (void) putbq(WR(q), tmp); 18760Sstevel@tonic-gate } 18770Sstevel@tonic-gate 18780Sstevel@tonic-gate mutex_exit(zs->zs_excl); 18790Sstevel@tonic-gate 18800Sstevel@tonic-gate while (head) { 18810Sstevel@tonic-gate if (!tail) { 18820Sstevel@tonic-gate putnext(q, head); 18830Sstevel@tonic-gate break; 18840Sstevel@tonic-gate } 18850Sstevel@tonic-gate mp = head; 18860Sstevel@tonic-gate head = head->b_next; 18870Sstevel@tonic-gate mp->b_next = NULL; 18880Sstevel@tonic-gate putnext(q, mp); 18890Sstevel@tonic-gate 18900Sstevel@tonic-gate } 18910Sstevel@tonic-gate 18920Sstevel@tonic-gate if (m_error) 18930Sstevel@tonic-gate (void) putnextctl1(q, M_ERROR, m_error); 18940Sstevel@tonic-gate 18950Sstevel@tonic-gate zss->sl_soft_active = 0; 18960Sstevel@tonic-gate 18970Sstevel@tonic-gate TRACE_1(TR_ZSH, TR_ZSH_SOFT_END, "zsh_soft end: zs = %p", zs); 18980Sstevel@tonic-gate 18990Sstevel@tonic-gate return (0); 19000Sstevel@tonic-gate } 19010Sstevel@tonic-gate 19020Sstevel@tonic-gate /* 19030Sstevel@tonic-gate * Initialization routine. 19040Sstevel@tonic-gate * Sets Clock sources, baud rate, modes and miscellaneous parameters. 19050Sstevel@tonic-gate */ 19060Sstevel@tonic-gate static int 19070Sstevel@tonic-gate zsh_program(struct zscom *zs, struct scc_mode *sm) 19080Sstevel@tonic-gate { 19090Sstevel@tonic-gate register struct syncline *zss = (struct syncline *)&zs->zs_priv_str; 19100Sstevel@tonic-gate register struct zs_prog *zspp; 19110Sstevel@tonic-gate register ushort_t tconst = 0; 19120Sstevel@tonic-gate register int wr11 = 0; 19130Sstevel@tonic-gate register int baud = 0; 19140Sstevel@tonic-gate register int pll = 0; 19150Sstevel@tonic-gate register int speed = 0; 19160Sstevel@tonic-gate register int flags = ZSP_SYNC; 19170Sstevel@tonic-gate int err = 0; 19180Sstevel@tonic-gate 19190Sstevel@tonic-gate ZSSETSOFT(zs); /* get our house in order */ 19200Sstevel@tonic-gate 19210Sstevel@tonic-gate switch (sm->sm_txclock) { 19220Sstevel@tonic-gate case TXC_IS_TXC: 19230Sstevel@tonic-gate wr11 |= ZSWR11_TXCLK_TRXC; 19240Sstevel@tonic-gate break; 19250Sstevel@tonic-gate case TXC_IS_RXC: 19260Sstevel@tonic-gate wr11 |= ZSWR11_TXCLK_RTXC; 19270Sstevel@tonic-gate break; 19280Sstevel@tonic-gate case TXC_IS_BAUD: 19290Sstevel@tonic-gate wr11 |= ZSWR11_TXCLK_BAUD; 19300Sstevel@tonic-gate wr11 |= ZSWR11_TRXC_OUT_ENA + ZSWR11_TRXC_XMIT; 19310Sstevel@tonic-gate baud++; 19320Sstevel@tonic-gate break; 19330Sstevel@tonic-gate case TXC_IS_PLL: 19340Sstevel@tonic-gate wr11 |= ZSWR11_TXCLK_DPLL; 19350Sstevel@tonic-gate pll++; 19360Sstevel@tonic-gate break; 19370Sstevel@tonic-gate default: 19380Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_TXC; 19390Sstevel@tonic-gate err = EINVAL; 19400Sstevel@tonic-gate goto out; 19410Sstevel@tonic-gate } 19420Sstevel@tonic-gate switch (sm->sm_rxclock) { 19430Sstevel@tonic-gate case RXC_IS_RXC: 19440Sstevel@tonic-gate wr11 |= ZSWR11_RXCLK_RTXC; 19450Sstevel@tonic-gate break; 19460Sstevel@tonic-gate case RXC_IS_TXC: 19470Sstevel@tonic-gate wr11 |= ZSWR11_RXCLK_TRXC; 19480Sstevel@tonic-gate break; 19490Sstevel@tonic-gate case RXC_IS_BAUD: 19500Sstevel@tonic-gate wr11 |= ZSWR11_RXCLK_BAUD; 19510Sstevel@tonic-gate baud++; 19520Sstevel@tonic-gate break; 19530Sstevel@tonic-gate case RXC_IS_PLL: 19540Sstevel@tonic-gate wr11 |= ZSWR11_RXCLK_DPLL; 19550Sstevel@tonic-gate pll++; 19560Sstevel@tonic-gate break; 19570Sstevel@tonic-gate default: 19580Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_RXC; 19590Sstevel@tonic-gate err = EINVAL; 19600Sstevel@tonic-gate goto out; 19610Sstevel@tonic-gate } 19620Sstevel@tonic-gate if (baud && pll) { 19630Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_PLL; 19640Sstevel@tonic-gate err = EINVAL; 19650Sstevel@tonic-gate goto out; 19660Sstevel@tonic-gate } 19670Sstevel@tonic-gate if (pll && !(sm->sm_config & CONN_NRZI)) { 19680Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_PLL; 19690Sstevel@tonic-gate err = EINVAL; 19700Sstevel@tonic-gate goto out; 19710Sstevel@tonic-gate } 19720Sstevel@tonic-gate 19730Sstevel@tonic-gate /* 19740Sstevel@tonic-gate * If we're going to use the BRG and the speed we want is != 0... 19750Sstevel@tonic-gate */ 19760Sstevel@tonic-gate if (baud && (speed = sm->sm_baudrate)) { 19770Sstevel@tonic-gate tconst = (PCLK + speed) / (2 * speed) - 2; 19780Sstevel@tonic-gate if (tconst == 0) { 19790Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_BAUDRATE; 19800Sstevel@tonic-gate err = EINVAL; 19810Sstevel@tonic-gate goto out; 19820Sstevel@tonic-gate } 19830Sstevel@tonic-gate sm->sm_baudrate = PCLK / (2 * ((int)tconst + 2)); 19840Sstevel@tonic-gate } else { 19850Sstevel@tonic-gate tconst = 0; /* Stop BRG. Also quiesces pin 24. */ 19860Sstevel@tonic-gate } 19870Sstevel@tonic-gate 19880Sstevel@tonic-gate if (pll) { 19890Sstevel@tonic-gate if ((speed = sm->sm_baudrate * 32) != 0) 19900Sstevel@tonic-gate tconst = (PCLK + speed) / (2 * speed) - 2; 19910Sstevel@tonic-gate else 19920Sstevel@tonic-gate tconst = 0; 19930Sstevel@tonic-gate if (tconst == 0) { 19940Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_BAUDRATE; 19950Sstevel@tonic-gate err = EINVAL; 19960Sstevel@tonic-gate goto out; 19970Sstevel@tonic-gate } 19980Sstevel@tonic-gate speed = PCLK / (2 * ((int)tconst + 2)); 19990Sstevel@tonic-gate sm->sm_baudrate = speed / 32; 20000Sstevel@tonic-gate flags |= ZSP_PLL; 20010Sstevel@tonic-gate } 20020Sstevel@tonic-gate 20030Sstevel@tonic-gate if ((sm->sm_config & (CONN_LPBK|CONN_ECHO)) == (CONN_LPBK|CONN_ECHO)) { 20040Sstevel@tonic-gate zss->sl_mode.sm_retval = SMERR_LPBKS; 20050Sstevel@tonic-gate err = EINVAL; 20060Sstevel@tonic-gate goto out; 20070Sstevel@tonic-gate } 20080Sstevel@tonic-gate if (sm->sm_config & CONN_LPBK) 20090Sstevel@tonic-gate flags |= ZSP_LOOP; 20100Sstevel@tonic-gate if (sm->sm_config & CONN_NRZI) 20110Sstevel@tonic-gate flags |= ZSP_NRZI; 20120Sstevel@tonic-gate if (sm->sm_config & CONN_ECHO) 20130Sstevel@tonic-gate flags |= ZSP_ECHO; 20140Sstevel@tonic-gate 20150Sstevel@tonic-gate zspp = &zs_prog[zs->zs_unit]; 20160Sstevel@tonic-gate 20170Sstevel@tonic-gate zspp->zs = zs; 20180Sstevel@tonic-gate zspp->flags = (uchar_t)flags; 20190Sstevel@tonic-gate zspp->wr4 = ZSWR4_SDLC; 20200Sstevel@tonic-gate zspp->wr11 = (uchar_t)wr11; 20210Sstevel@tonic-gate zspp->wr12 = (uchar_t)(tconst & 0xff); 20220Sstevel@tonic-gate zspp->wr13 = (uchar_t)((tconst >> 8) & 0xff); 20230Sstevel@tonic-gate zspp->wr3 = (uchar_t)(ZSWR3_RX_ENABLE | ZSWR3_RXCRC_ENABLE | 20240Sstevel@tonic-gate ZSWR3_RX_8); 20250Sstevel@tonic-gate zspp->wr5 = (uchar_t)(ZSWR5_TX_8 | ZSWR5_DTR | ZSWR5_TXCRC_ENABLE); 20260Sstevel@tonic-gate 20270Sstevel@tonic-gate if (zss->sl_flags & SF_FDXPTP) { 20280Sstevel@tonic-gate zspp->wr5 |= ZSWR5_RTS; 20290Sstevel@tonic-gate zss->sl_rr0 |= ZSRR0_CTS; /* Assume CTS is high */ 20300Sstevel@tonic-gate } 20310Sstevel@tonic-gate if (sm->sm_config & CONN_IBM) { 20320Sstevel@tonic-gate zspp->wr15 = (uchar_t) 20330Sstevel@tonic-gate (ZSR15_TX_UNDER | ZSR15_BREAK | ZSR15_SYNC | ZSR15_CTS); 20340Sstevel@tonic-gate if (!(zss->sl_flags & SF_FDXPTP)) 20350Sstevel@tonic-gate zspp->wr15 &= ~ZSR15_CTS; 20360Sstevel@tonic-gate } else { 20370Sstevel@tonic-gate zspp->wr5 |= ZSWR5_TX_ENABLE; 20380Sstevel@tonic-gate zspp->wr15 = (uchar_t) 20390Sstevel@tonic-gate (ZSR15_TX_UNDER | ZSR15_BREAK | ZSR15_SYNC); 20400Sstevel@tonic-gate if (sm->sm_config & CONN_SIGNAL) 20410Sstevel@tonic-gate zspp->wr15 |= ZSR15_CTS; 20420Sstevel@tonic-gate } 20430Sstevel@tonic-gate 20440Sstevel@tonic-gate zs_program(zspp); 20450Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_STATUS); /* reset XS */ 20460Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_STATUS); /* reset XS */ 20470Sstevel@tonic-gate zss->sl_flags |= SF_INITIALIZED; 20480Sstevel@tonic-gate bzero(&zss->sl_st, sizeof (struct sl_stats)); 20490Sstevel@tonic-gate bcopy(sm, &zss->sl_mode, sizeof (struct scc_mode)); 20500Sstevel@tonic-gate zss->sl_mode.sm_retval = 0; /* successful */ 20510Sstevel@tonic-gate out: 20520Sstevel@tonic-gate return (err); 20530Sstevel@tonic-gate } 20540Sstevel@tonic-gate 20550Sstevel@tonic-gate /* 20560Sstevel@tonic-gate * Function to store modem signal changes in sl_mstat field. 20570Sstevel@tonic-gate * Note that these events are supposed to be so far apart in time that 20580Sstevel@tonic-gate * we should always be able to send up the event and allocate a message 20590Sstevel@tonic-gate * block before another one happens. If not, we'll overwrite this one. 20600Sstevel@tonic-gate */ 20610Sstevel@tonic-gate static void 20620Sstevel@tonic-gate zsh_setmstat(struct zscom *zs, int event) 20630Sstevel@tonic-gate { 20640Sstevel@tonic-gate register struct syncline *zss = (struct syncline *)&zs->zs_priv_str; 20650Sstevel@tonic-gate register struct sl_status *mstat; 20660Sstevel@tonic-gate register mblk_t *mp; 20670Sstevel@tonic-gate 20680Sstevel@tonic-gate if (((mp = zss->sl_mstat) != NULL) && 20690Sstevel@tonic-gate (zss->sl_mode.sm_config & (CONN_SIGNAL))) { 20700Sstevel@tonic-gate mstat = (struct sl_status *)mp->b_wptr; 20710Sstevel@tonic-gate mstat->type = (zss->sl_mode.sm_config & CONN_IBM) ? 20720Sstevel@tonic-gate SLS_LINKERR : SLS_MDMSTAT; 20730Sstevel@tonic-gate mstat->status = event; 20740Sstevel@tonic-gate gethrestime(&mstat->tstamp); 20750Sstevel@tonic-gate mp->b_wptr += sizeof (struct sl_status); 20760Sstevel@tonic-gate mp->b_datap->db_type = M_PROTO; 20770Sstevel@tonic-gate ZSH_PUTQ(mp); 20780Sstevel@tonic-gate zss->sl_mstat = NULL; 20790Sstevel@tonic-gate ZSSETSOFT(zs); 20800Sstevel@tonic-gate } 20810Sstevel@tonic-gate } 20820Sstevel@tonic-gate 20830Sstevel@tonic-gate /* 20840Sstevel@tonic-gate * Received Bad Frame procedure 20850Sstevel@tonic-gate */ 20860Sstevel@tonic-gate static void 20870Sstevel@tonic-gate zsh_rxbad(struct zscom *zs, struct syncline *zss) 20880Sstevel@tonic-gate { 20890Sstevel@tonic-gate /* 20900Sstevel@tonic-gate * swallow bad characters 20910Sstevel@tonic-gate */ 20920Sstevel@tonic-gate (void) SCC_READDATA(); 20930Sstevel@tonic-gate (void) SCC_READDATA(); 20940Sstevel@tonic-gate (void) SCC_READDATA(); 20950Sstevel@tonic-gate 20960Sstevel@tonic-gate SCC_BIS(3, ZSWR3_HUNT); /* enter hunt mode - ignores rest of frame */ 20970Sstevel@tonic-gate 20980Sstevel@tonic-gate zss->sl_st.ierror++; 20990Sstevel@tonic-gate 21000Sstevel@tonic-gate /* 21010Sstevel@tonic-gate * Free active receive message. 21020Sstevel@tonic-gate */ 21030Sstevel@tonic-gate if (zss->sl_rhead) { 21040Sstevel@tonic-gate zss->sl_rhead->b_wptr = zss->sl_rhead->b_rptr; 21050Sstevel@tonic-gate zss->sl_rhead->b_datap->db_type = M_RSE; 21060Sstevel@tonic-gate ZSH_FREEMSG(zss->sl_rhead); 21070Sstevel@tonic-gate zss->sl_ractb = NULL; 21080Sstevel@tonic-gate zs->zs_rd_cur = NULL; 21090Sstevel@tonic-gate zs->zs_rd_lim = NULL; 21100Sstevel@tonic-gate } 21110Sstevel@tonic-gate if (zss->sl_rhead) { 21120Sstevel@tonic-gate zss->sl_rhead = NULL; 21130Sstevel@tonic-gate ZSH_ALLOCB(zss->sl_ractb); 21140Sstevel@tonic-gate zs->zs_rd_cur = NULL; 21150Sstevel@tonic-gate zs->zs_rd_lim = NULL; 21160Sstevel@tonic-gate } 21170Sstevel@tonic-gate 21180Sstevel@tonic-gate ZSSETSOFT(zs); 21190Sstevel@tonic-gate } 21200Sstevel@tonic-gate 21210Sstevel@tonic-gate /* 21220Sstevel@tonic-gate * Transmit error procedure 21230Sstevel@tonic-gate */ 21240Sstevel@tonic-gate static void 21250Sstevel@tonic-gate zsh_txbad(struct zscom *zs, struct syncline *zss) 21260Sstevel@tonic-gate { 21270Sstevel@tonic-gate if (zss->sl_xhead) { /* free the message we were sending */ 21280Sstevel@tonic-gate zss->sl_xhead->b_wptr = zss->sl_xhead->b_rptr; 21290Sstevel@tonic-gate ZSH_FREEMSG(zss->sl_xhead); 21300Sstevel@tonic-gate zss->sl_xactb = NULL; 21310Sstevel@tonic-gate zs->zs_wr_cur = NULL; 21320Sstevel@tonic-gate zs->zs_wr_lim = NULL; 21330Sstevel@tonic-gate } 21340Sstevel@tonic-gate zss->sl_xhead = NULL; 21350Sstevel@tonic-gate 21360Sstevel@tonic-gate if (!(zss->sl_flags & SF_FDXPTP)) { 21370Sstevel@tonic-gate /* 21380Sstevel@tonic-gate * drop RTS and our notion of CTS 21390Sstevel@tonic-gate */ 21400Sstevel@tonic-gate SCC_BIC(5, ZSWR5_RTS); 21410Sstevel@tonic-gate SCC_BIC(5, ZSWR5_TX_ENABLE); 21420Sstevel@tonic-gate zss->sl_rr0 &= ~ZSRR0_CTS; 21430Sstevel@tonic-gate } 21440Sstevel@tonic-gate zss->sl_txstate = TX_IDLE; 21450Sstevel@tonic-gate if (!(zss->sl_flags & SF_PHONY)) 21460Sstevel@tonic-gate zss->sl_st.oerror++; 21470Sstevel@tonic-gate } 21480Sstevel@tonic-gate 21490Sstevel@tonic-gate /* 21500Sstevel@tonic-gate * Transmitter watchdog timeout routine 21510Sstevel@tonic-gate */ 21520Sstevel@tonic-gate static void 21530Sstevel@tonic-gate zsh_watchdog(void *arg) 21540Sstevel@tonic-gate { 21550Sstevel@tonic-gate struct zscom *zs = arg; 21560Sstevel@tonic-gate struct syncline *zss = (struct syncline *)&zs->zs_priv_str; 21570Sstevel@tonic-gate queue_t *wq; 21580Sstevel@tonic-gate mblk_t *mp; 21590Sstevel@tonic-gate int warning = 0; 21600Sstevel@tonic-gate uchar_t s0; 21610Sstevel@tonic-gate int do_flushwq = 0; 21620Sstevel@tonic-gate 21630Sstevel@tonic-gate /* 21640Sstevel@tonic-gate * The main reason for this routine is because, under some 21650Sstevel@tonic-gate * circumstances, a transmit interrupt may get lost (ie., if 21660Sstevel@tonic-gate * underrun occurs after the last character has been sent, and 21670Sstevel@tonic-gate * the tx interrupt following the abort gets scheduled before 21680Sstevel@tonic-gate * the current tx interrupt has been serviced). Transmit can 21690Sstevel@tonic-gate * also get hung if the cable is pulled out and the clock was 21700Sstevel@tonic-gate * coming in from the modem. 21710Sstevel@tonic-gate */ 21720Sstevel@tonic-gate 21730Sstevel@tonic-gate mutex_enter(zs->zs_excl); 21740Sstevel@tonic-gate if (zss->sl_stream.str_rq) 21750Sstevel@tonic-gate wq = WR(zss->sl_stream.str_rq); 21760Sstevel@tonic-gate else { 21770Sstevel@tonic-gate mutex_exit(zs->zs_excl); 21780Sstevel@tonic-gate return; /* guard against close/callback race */ 21790Sstevel@tonic-gate } 21800Sstevel@tonic-gate 21810Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 21820Sstevel@tonic-gate if (!(zss->sl_flags & SF_XMT_INPROG) && wq->q_first) { 21830Sstevel@tonic-gate zss->sl_flags |= SF_XMT_INPROG; 21840Sstevel@tonic-gate if ((zss->sl_flags & SF_FDXPTP) || 21850Sstevel@tonic-gate zsh_hdp_ok_or_rts_state(zs, zss)) 21860Sstevel@tonic-gate (void) zsh_start(zs, zss); 21870Sstevel@tonic-gate goto end_watchdog; 21880Sstevel@tonic-gate } 21890Sstevel@tonic-gate 21900Sstevel@tonic-gate if (zss->sl_wd_count-- > 0) 21910Sstevel@tonic-gate goto end_watchdog; 21920Sstevel@tonic-gate 21930Sstevel@tonic-gate if (zss->sl_flags & SF_FLUSH_WQ) { 21940Sstevel@tonic-gate if (!(zss->sl_flags & SF_FDXPTP)) 21950Sstevel@tonic-gate zss->sl_flags &= ~SF_FLUSH_WQ; 21960Sstevel@tonic-gate else { 21970Sstevel@tonic-gate s0 = SCC_READ0(); 21980Sstevel@tonic-gate if (s0 & ZSRR0_CTS) { 21990Sstevel@tonic-gate zss->sl_rr0 |= ZSRR0_CTS; 22000Sstevel@tonic-gate SCC_BIS(15, ZSR15_CTS); 22010Sstevel@tonic-gate zss->sl_flags &= ~SF_FLUSH_WQ; 22020Sstevel@tonic-gate zsh_setmstat(zs, CS_CTS_UP); 22030Sstevel@tonic-gate } 22040Sstevel@tonic-gate } 22050Sstevel@tonic-gate } 22060Sstevel@tonic-gate 22070Sstevel@tonic-gate switch (zss->sl_txstate) { 22080Sstevel@tonic-gate 22090Sstevel@tonic-gate case TX_ABORTED: 22100Sstevel@tonic-gate /* 22110Sstevel@tonic-gate * Transmitter was hung ... try restarting it. 22120Sstevel@tonic-gate */ 22130Sstevel@tonic-gate if (zss->sl_flags & SF_FDXPTP) { 22140Sstevel@tonic-gate zss->sl_flags |= SF_XMT_INPROG; 22150Sstevel@tonic-gate (void) zsh_start(zs, zss); 22160Sstevel@tonic-gate } else 22170Sstevel@tonic-gate do_flushwq = 1; 22180Sstevel@tonic-gate break; 22190Sstevel@tonic-gate 22200Sstevel@tonic-gate case TX_ACTIVE: 22210Sstevel@tonic-gate case TX_CRC: 22220Sstevel@tonic-gate /* 22230Sstevel@tonic-gate * Transmit is hung for some reason. Reset tx interrupt. 22240Sstevel@tonic-gate * Flush transmit fifo by sending an abort command 22250Sstevel@tonic-gate * which also sets the Underrun/EOM latch in WR0 and in 22260Sstevel@tonic-gate * turn generates an External Status interrupt that 22270Sstevel@tonic-gate * will reset the necessary message buffer pointers. 22280Sstevel@tonic-gate * The watchdog timer will cycle again to allow the SCC 22290Sstevel@tonic-gate * to settle down after the abort command. The next 22300Sstevel@tonic-gate * time through we'll see that the state is now TX_ABORTED 22310Sstevel@tonic-gate * and call zsh_start to grab a new message. 22320Sstevel@tonic-gate */ 22330Sstevel@tonic-gate if (--zss->sl_wd_count <= 0) { 22340Sstevel@tonic-gate SCC_WRITE0(ZSWR0_SEND_ABORT); 22350Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_ERRORS); 22360Sstevel@tonic-gate SCC_WRITE0(ZSWR0_RESET_TXINT); 22370Sstevel@tonic-gate zsh_txbad(zs, zss); 22380Sstevel@tonic-gate zss->sl_txstate = TX_ABORTED; /* must be after txbad */ 22390Sstevel@tonic-gate warning = 1; 22400Sstevel@tonic-gate } 22410Sstevel@tonic-gate break; 22420Sstevel@tonic-gate 22430Sstevel@tonic-gate case TX_RTS: 22440Sstevel@tonic-gate /* 22450Sstevel@tonic-gate * Timer expired after we raised RTS. CTS never came up. 22460Sstevel@tonic-gate */ 22470Sstevel@tonic-gate zss->sl_st.cts++; 22480Sstevel@tonic-gate 22490Sstevel@tonic-gate zsh_setmstat(zs, CS_CTS_TO); 22500Sstevel@tonic-gate zss->sl_flags &= ~SF_XMT_INPROG; 22510Sstevel@tonic-gate zss->sl_flags |= SF_FLUSH_WQ; 22520Sstevel@tonic-gate ZSSETSOFT(zs); 22530Sstevel@tonic-gate break; 22540Sstevel@tonic-gate 22550Sstevel@tonic-gate default: 22560Sstevel@tonic-gate /* 22570Sstevel@tonic-gate * If we time out in an inactive state we set a soft 22580Sstevel@tonic-gate * interrupt. This will call zsh_start which will 22590Sstevel@tonic-gate * clear SF_XMT_INPROG if the queue is empty. 22600Sstevel@tonic-gate */ 22610Sstevel@tonic-gate break; 22620Sstevel@tonic-gate } 22630Sstevel@tonic-gate end_watchdog: 22640Sstevel@tonic-gate if (zss->sl_txstate != TX_OFF) { 22650Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 22660Sstevel@tonic-gate zss->sl_wd_id = timeout(zsh_watchdog, zs, SIO_WATCHDOG_TICK); 22670Sstevel@tonic-gate } else { 22680Sstevel@tonic-gate zss->sl_wd_id = 0; /* safety */ 22690Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 22700Sstevel@tonic-gate } 22710Sstevel@tonic-gate if (warning || do_flushwq) { 22720Sstevel@tonic-gate flushq(wq, FLUSHDATA); 22730Sstevel@tonic-gate mutex_enter(zs->zs_excl_hi); 22740Sstevel@tonic-gate if ((mp = zss->sl_xstandby) != NULL) 22750Sstevel@tonic-gate zss->sl_xstandby = NULL; 22760Sstevel@tonic-gate mutex_exit(zs->zs_excl_hi); 22770Sstevel@tonic-gate if (mp) 22780Sstevel@tonic-gate freemsg(mp); 22790Sstevel@tonic-gate } 22800Sstevel@tonic-gate mutex_exit(zs->zs_excl); 22810Sstevel@tonic-gate if (warning) 22820Sstevel@tonic-gate cmn_err(CE_WARN, "zsh%x: transmit hung", zs->zs_unit); 22830Sstevel@tonic-gate } 22840Sstevel@tonic-gate 22850Sstevel@tonic-gate static void 22860Sstevel@tonic-gate zsh_callback(void *arg) 22870Sstevel@tonic-gate { 22880Sstevel@tonic-gate struct zscom *zs = arg; 22890Sstevel@tonic-gate struct syncline *zss = (struct syncline *)&zs->zs_priv_str; 22900Sstevel@tonic-gate int tmp = ZSH_MAX_RSTANDBY; 22910Sstevel@tonic-gate 22920Sstevel@tonic-gate mutex_enter(zs->zs_excl); 22930Sstevel@tonic-gate if (zss->sl_bufcid) { 22940Sstevel@tonic-gate zss->sl_bufcid = 0; 22950Sstevel@tonic-gate ZSH_GETBLOCK(zs, tmp); 22960Sstevel@tonic-gate } 22970Sstevel@tonic-gate mutex_exit(zs->zs_excl); 22980Sstevel@tonic-gate } 2299