17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*39b361b2SRichard Bean * Common Development and Distribution License (the "License").
6*39b361b2SRichard Bean * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*39b361b2SRichard Bean * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * Standard module for handling DLPI Style 2 attach/detach
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/conf.h>
327c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
337c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
347c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
357c478bd9Sstevel@tonic-gate #include <sys/esunddi.h>
367c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
377c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
387c478bd9Sstevel@tonic-gate #include <sys/dlpi.h>
397c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
407c478bd9Sstevel@tonic-gate #include <sys/policy.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate static struct streamtab drstab;
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate static struct fmodsw fsw = {
457c478bd9Sstevel@tonic-gate DRMODNAME,
467c478bd9Sstevel@tonic-gate &drstab,
477c478bd9Sstevel@tonic-gate D_MP
487c478bd9Sstevel@tonic-gate };
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate * Module linkage information for the kernel.
537c478bd9Sstevel@tonic-gate */
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
56*39b361b2SRichard Bean &mod_strmodops, "dr compatibility for DLPI style 2 drivers", &fsw
577c478bd9Sstevel@tonic-gate };
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
617c478bd9Sstevel@tonic-gate MODREV_1, &modlstrmod, NULL
627c478bd9Sstevel@tonic-gate };
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate int
_init(void)667c478bd9Sstevel@tonic-gate _init(void)
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage));
697c478bd9Sstevel@tonic-gate }
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate int
_fini(void)727c478bd9Sstevel@tonic-gate _fini(void)
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage));
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)787c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
797c478bd9Sstevel@tonic-gate {
807c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate static int dropen(queue_t *, dev_t *, int, int, cred_t *);
857c478bd9Sstevel@tonic-gate static int drclose(queue_t *, int, cred_t *);
867c478bd9Sstevel@tonic-gate static int drrput(queue_t *, mblk_t *);
877c478bd9Sstevel@tonic-gate static int drwput(queue_t *, mblk_t *);
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate static struct module_info drinfo = {
907c478bd9Sstevel@tonic-gate 0,
917c478bd9Sstevel@tonic-gate DRMODNAME,
927c478bd9Sstevel@tonic-gate 0,
937c478bd9Sstevel@tonic-gate INFPSZ,
947c478bd9Sstevel@tonic-gate 1,
957c478bd9Sstevel@tonic-gate 0
967c478bd9Sstevel@tonic-gate };
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate static struct qinit drrinit = {
997c478bd9Sstevel@tonic-gate (int (*)())drrput,
1007c478bd9Sstevel@tonic-gate NULL,
1017c478bd9Sstevel@tonic-gate dropen,
1027c478bd9Sstevel@tonic-gate drclose,
1037c478bd9Sstevel@tonic-gate NULL,
1047c478bd9Sstevel@tonic-gate &drinfo
1057c478bd9Sstevel@tonic-gate };
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate static struct qinit drwinit = {
1087c478bd9Sstevel@tonic-gate (int (*)())drwput,
1097c478bd9Sstevel@tonic-gate NULL,
1107c478bd9Sstevel@tonic-gate NULL,
1117c478bd9Sstevel@tonic-gate NULL,
1127c478bd9Sstevel@tonic-gate NULL,
1137c478bd9Sstevel@tonic-gate &drinfo
1147c478bd9Sstevel@tonic-gate };
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate static struct streamtab drstab = {
1177c478bd9Sstevel@tonic-gate &drrinit,
1187c478bd9Sstevel@tonic-gate &drwinit,
1197c478bd9Sstevel@tonic-gate NULL,
1207c478bd9Sstevel@tonic-gate NULL
1217c478bd9Sstevel@tonic-gate };
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * This module is pushed directly on top of the bottom driver
1257c478bd9Sstevel@tonic-gate * in a DLPI style-2 stream by stropen(). It intercepts
1267c478bd9Sstevel@tonic-gate * DL_ATTACH_REQ/DL_DETACH_REQ messages on the write side
1277c478bd9Sstevel@tonic-gate * and acks on the read side, calls qassociate where needed.
1287c478bd9Sstevel@tonic-gate * The primary purpose is to workaround a DR race condition
1297c478bd9Sstevel@tonic-gate * affecting non-DDI compliant DLPI style 2 drivers, which may
1307c478bd9Sstevel@tonic-gate * cause the system to panic.
1317c478bd9Sstevel@tonic-gate *
1327c478bd9Sstevel@tonic-gate * The following action is taken:
1337c478bd9Sstevel@tonic-gate * Write side (drwput):
1347c478bd9Sstevel@tonic-gate * attach request: hold driver instance assuming ppa == instance.
1357c478bd9Sstevel@tonic-gate * This way, the instance cannot be detached while the
1367c478bd9Sstevel@tonic-gate * driver is processing DL_ATTACH_REQ.
1377c478bd9Sstevel@tonic-gate *
1387c478bd9Sstevel@tonic-gate * On a successful hold, store the dip in a ring buffer
1397c478bd9Sstevel@tonic-gate * to be processed lated by the read side.
1407c478bd9Sstevel@tonic-gate * If hold fails (most likely ppa != instance), we store
1417c478bd9Sstevel@tonic-gate * NULL in the ring buffer and read side won't take
1427c478bd9Sstevel@tonic-gate * any action on ack.
1437c478bd9Sstevel@tonic-gate *
1447c478bd9Sstevel@tonic-gate * Read side (drrput):
1457c478bd9Sstevel@tonic-gate * attach success: if (dip held on write side) associate queue with dip
1467c478bd9Sstevel@tonic-gate * attach failure: if (dip held on write side) release hold on dip
1477c478bd9Sstevel@tonic-gate * detach success: associate queue with NULL
1487c478bd9Sstevel@tonic-gate * detach failure: do nothing
1497c478bd9Sstevel@tonic-gate *
1507c478bd9Sstevel@tonic-gate * The module assumes that incoming DL_ATTACH_REQ/DL_DETACH_REQ
1517c478bd9Sstevel@tonic-gate * messages are ordered (non-concurrent) and the bottom
1527c478bd9Sstevel@tonic-gate * driver processes them and sends acknowledgements in the same
1537c478bd9Sstevel@tonic-gate * order. This assumption is reasonable because concurrent
1547c478bd9Sstevel@tonic-gate * association results in non-deterministic queue behavior.
1557c478bd9Sstevel@tonic-gate * The module is coded carefully such that unordered messages
1567c478bd9Sstevel@tonic-gate * do not result in a system panic.
1577c478bd9Sstevel@tonic-gate *
1587c478bd9Sstevel@tonic-gate * The module handles multiple outstanding messages queued
1597c478bd9Sstevel@tonic-gate * in the bottom driver. Messages processed on the write side
1607c478bd9Sstevel@tonic-gate * but not yet arrived at read side are placed in the ring buffer
1617c478bd9Sstevel@tonic-gate * dr_dip[], between dr_nfirst and dr_nlast. The write side is
1627c478bd9Sstevel@tonic-gate * producer and the read side is the consumer. The buffer is full
1637c478bd9Sstevel@tonic-gate * when dr_nfirst == dr_nlast.
1647c478bd9Sstevel@tonic-gate *
1657c478bd9Sstevel@tonic-gate * The current size of the ring buffer is 64 (MAX_DLREQS) per stream.
1667c478bd9Sstevel@tonic-gate * During normal testing, we have not seen outstanding messages
1677c478bd9Sstevel@tonic-gate * above 10.
1687c478bd9Sstevel@tonic-gate */
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate #define MAX_DLREQS 64
1717c478bd9Sstevel@tonic-gate #define INCR(x) {(x)++; if ((x) >= MAX_DLREQS) (x) = 0; }
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate struct drstate {
1747c478bd9Sstevel@tonic-gate kmutex_t dr_lock;
1757c478bd9Sstevel@tonic-gate major_t dr_major;
1767c478bd9Sstevel@tonic-gate int dr_nfirst;
1777c478bd9Sstevel@tonic-gate int dr_nlast;
1787c478bd9Sstevel@tonic-gate dev_info_t *dr_dip[MAX_DLREQS];
1797c478bd9Sstevel@tonic-gate };
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
1827c478bd9Sstevel@tonic-gate static int
dropen(queue_t * q,dev_t * devp,int oflag,int sflag,cred_t * crp)1837c478bd9Sstevel@tonic-gate dropen(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *crp)
1847c478bd9Sstevel@tonic-gate {
1857c478bd9Sstevel@tonic-gate struct drstate *dsp;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate if (sflag != MODOPEN) { /* must be a pushed module */
1887c478bd9Sstevel@tonic-gate return (EINVAL);
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate if (secpolicy_net_rawaccess(crp) != 0) {
1927c478bd9Sstevel@tonic-gate return (EPERM);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate if (q->q_ptr != NULL) {
1967c478bd9Sstevel@tonic-gate return (0); /* already open */
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate dsp = kmem_zalloc(sizeof (*dsp), KM_SLEEP);
2007c478bd9Sstevel@tonic-gate dsp->dr_major = getmajor(*devp);
2017c478bd9Sstevel@tonic-gate mutex_init(&dsp->dr_lock, NULL, MUTEX_DEFAULT, NULL);
2027c478bd9Sstevel@tonic-gate q->q_ptr = OTHERQ(q)->q_ptr = dsp;
2037c478bd9Sstevel@tonic-gate qprocson(q);
2047c478bd9Sstevel@tonic-gate ddi_assoc_queue_with_devi(q, NULL);
2057c478bd9Sstevel@tonic-gate return (0);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
2097c478bd9Sstevel@tonic-gate static int
drclose(queue_t * q,int cflag,cred_t * crp)2107c478bd9Sstevel@tonic-gate drclose(queue_t *q, int cflag, cred_t *crp)
2117c478bd9Sstevel@tonic-gate {
2127c478bd9Sstevel@tonic-gate struct drstate *dsp = q->q_ptr;
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate ASSERT(dsp);
2157c478bd9Sstevel@tonic-gate ddi_assoc_queue_with_devi(q, NULL);
2167c478bd9Sstevel@tonic-gate qprocsoff(q);
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate mutex_destroy(&dsp->dr_lock);
2197c478bd9Sstevel@tonic-gate kmem_free(dsp, sizeof (*dsp));
2207c478bd9Sstevel@tonic-gate q->q_ptr = NULL;
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate return (0);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate static int
drrput(queue_t * q,mblk_t * mp)2267c478bd9Sstevel@tonic-gate drrput(queue_t *q, mblk_t *mp)
2277c478bd9Sstevel@tonic-gate {
2287c478bd9Sstevel@tonic-gate struct drstate *dsp;
2297c478bd9Sstevel@tonic-gate union DL_primitives *dlp;
2307c478bd9Sstevel@tonic-gate dev_info_t *dip;
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate switch (DB_TYPE(mp)) {
2337c478bd9Sstevel@tonic-gate case M_PROTO:
2347c478bd9Sstevel@tonic-gate case M_PCPROTO:
2357c478bd9Sstevel@tonic-gate break;
2367c478bd9Sstevel@tonic-gate default:
2377c478bd9Sstevel@tonic-gate putnext(q, mp);
2387c478bd9Sstevel@tonic-gate return (0);
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate /* make sure size is sufficient for dl_primitive */
2427c478bd9Sstevel@tonic-gate if (MBLKL(mp) < sizeof (t_uscalar_t)) {
2437c478bd9Sstevel@tonic-gate putnext(q, mp);
2447c478bd9Sstevel@tonic-gate return (0);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate dlp = (union DL_primitives *)mp->b_rptr;
2487c478bd9Sstevel@tonic-gate switch (dlp->dl_primitive) {
2497c478bd9Sstevel@tonic-gate case DL_OK_ACK: {
2507c478bd9Sstevel@tonic-gate /* check for proper size, let upper layer deal with error */
2517c478bd9Sstevel@tonic-gate if (MBLKL(mp) < DL_OK_ACK_SIZE) {
2527c478bd9Sstevel@tonic-gate putnext(q, mp);
2537c478bd9Sstevel@tonic-gate return (0);
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate dsp = q->q_ptr;
2577c478bd9Sstevel@tonic-gate switch (dlp->ok_ack.dl_correct_primitive) {
2587c478bd9Sstevel@tonic-gate case DL_ATTACH_REQ:
2597c478bd9Sstevel@tonic-gate /*
2607c478bd9Sstevel@tonic-gate * ddi_assoc_queue_with_devi() will hold dip,
2617c478bd9Sstevel@tonic-gate * so release after association.
2627c478bd9Sstevel@tonic-gate *
2637c478bd9Sstevel@tonic-gate * dip is NULL means we didn't hold dip on read side.
2647c478bd9Sstevel@tonic-gate * (unlikely, but possible), so we do nothing.
2657c478bd9Sstevel@tonic-gate */
2667c478bd9Sstevel@tonic-gate mutex_enter(&dsp->dr_lock);
2677c478bd9Sstevel@tonic-gate dip = dsp->dr_dip[dsp->dr_nlast];
2687c478bd9Sstevel@tonic-gate dsp->dr_dip[dsp->dr_nlast] = NULL;
2697c478bd9Sstevel@tonic-gate INCR(dsp->dr_nlast);
2707c478bd9Sstevel@tonic-gate mutex_exit(&dsp->dr_lock);
2717c478bd9Sstevel@tonic-gate if (dip) {
2727c478bd9Sstevel@tonic-gate ddi_assoc_queue_with_devi(q, dip);
2737c478bd9Sstevel@tonic-gate ddi_release_devi(dip);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate break;
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate case DL_DETACH_REQ:
2787c478bd9Sstevel@tonic-gate ddi_assoc_queue_with_devi(q, NULL);
2797c478bd9Sstevel@tonic-gate break;
2807c478bd9Sstevel@tonic-gate default:
2817c478bd9Sstevel@tonic-gate break;
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate break;
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate case DL_ERROR_ACK:
2867c478bd9Sstevel@tonic-gate if (dlp->error_ack.dl_error_primitive != DL_ATTACH_REQ)
2877c478bd9Sstevel@tonic-gate break;
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate dsp = q->q_ptr;
2907c478bd9Sstevel@tonic-gate mutex_enter(&dsp->dr_lock);
2917c478bd9Sstevel@tonic-gate dip = dsp->dr_dip[dsp->dr_nlast];
2927c478bd9Sstevel@tonic-gate dsp->dr_dip[dsp->dr_nlast] = NULL;
2937c478bd9Sstevel@tonic-gate INCR(dsp->dr_nlast);
2947c478bd9Sstevel@tonic-gate mutex_exit(&dsp->dr_lock);
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate * Release dip on attach failure
2977c478bd9Sstevel@tonic-gate */
2987c478bd9Sstevel@tonic-gate if (dip) {
2997c478bd9Sstevel@tonic-gate ddi_release_devi(dip);
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate break;
3027c478bd9Sstevel@tonic-gate default:
3037c478bd9Sstevel@tonic-gate break;
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate putnext(q, mp);
3077c478bd9Sstevel@tonic-gate return (0);
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate /*
3117c478bd9Sstevel@tonic-gate * Detect dl attach, hold the dip to prevent it from detaching
3127c478bd9Sstevel@tonic-gate */
3137c478bd9Sstevel@tonic-gate static int
drwput(queue_t * q,mblk_t * mp)3147c478bd9Sstevel@tonic-gate drwput(queue_t *q, mblk_t *mp)
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate struct drstate *dsp;
3177c478bd9Sstevel@tonic-gate union DL_primitives *dlp;
3187c478bd9Sstevel@tonic-gate dev_info_t *dip;
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate switch (DB_TYPE(mp)) {
3217c478bd9Sstevel@tonic-gate case M_PROTO:
3227c478bd9Sstevel@tonic-gate case M_PCPROTO:
3237c478bd9Sstevel@tonic-gate break;
3247c478bd9Sstevel@tonic-gate default:
3257c478bd9Sstevel@tonic-gate putnext(q, mp);
3267c478bd9Sstevel@tonic-gate return (0);
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate /* make sure size is sufficient for dl_primitive */
3307c478bd9Sstevel@tonic-gate if (MBLKL(mp) < sizeof (t_uscalar_t)) {
3317c478bd9Sstevel@tonic-gate putnext(q, mp);
3327c478bd9Sstevel@tonic-gate return (0);
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate dlp = (union DL_primitives *)mp->b_rptr;
3367c478bd9Sstevel@tonic-gate switch (dlp->dl_primitive) {
3377c478bd9Sstevel@tonic-gate case DL_ATTACH_REQ:
3387c478bd9Sstevel@tonic-gate /*
3397c478bd9Sstevel@tonic-gate * Check for proper size of the message.
3407c478bd9Sstevel@tonic-gate *
3417c478bd9Sstevel@tonic-gate * If size is correct, get the ppa and attempt to
3427c478bd9Sstevel@tonic-gate * hold the device assuming ppa is instance.
3437c478bd9Sstevel@tonic-gate *
3447c478bd9Sstevel@tonic-gate * If size is wrong, we can't get the ppa, but
3457c478bd9Sstevel@tonic-gate * still increment dr_nfirst because the read side
3467c478bd9Sstevel@tonic-gate * will get a error ack on DL_ATTACH_REQ.
3477c478bd9Sstevel@tonic-gate */
3487c478bd9Sstevel@tonic-gate dip = NULL;
3497c478bd9Sstevel@tonic-gate dsp = q->q_ptr;
3507c478bd9Sstevel@tonic-gate if (MBLKL(mp) >= DL_OK_ACK_SIZE) {
3517c478bd9Sstevel@tonic-gate dip = ddi_hold_devi_by_instance(dsp->dr_major,
3527c478bd9Sstevel@tonic-gate dlp->attach_req.dl_ppa, E_DDI_HOLD_DEVI_NOATTACH);
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate mutex_enter(&dsp->dr_lock);
3567c478bd9Sstevel@tonic-gate dsp->dr_dip[dsp->dr_nfirst] = dip;
3577c478bd9Sstevel@tonic-gate INCR(dsp->dr_nfirst);
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate * Check if ring buffer is full. If so, assert in debug
3607c478bd9Sstevel@tonic-gate * kernel and produce a warning in non-debug kernel.
3617c478bd9Sstevel@tonic-gate */
3627c478bd9Sstevel@tonic-gate ASSERT(dsp->dr_nfirst != dsp->dr_nlast);
3637c478bd9Sstevel@tonic-gate if (dsp->dr_nfirst == dsp->dr_nlast) {
3647c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "drcompat: internal buffer full");
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate mutex_exit(&dsp->dr_lock);
3677c478bd9Sstevel@tonic-gate break;
3687c478bd9Sstevel@tonic-gate default:
3697c478bd9Sstevel@tonic-gate break;
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate putnext(q, mp);
3737c478bd9Sstevel@tonic-gate return (0);
3747c478bd9Sstevel@tonic-gate }
375