xref: /titanic_52/usr/src/uts/common/io/sundlpi.c (revision 392b1d6e2db675a130786159484085bd39c1c5f2)
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*392b1d6eSyz147064  * Common Development and Distribution License (the "License").
6*392b1d6eSyz147064  * 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*392b1d6eSyz147064  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  *  Common Sun DLPI routines.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include	<sys/types.h>
337c478bd9Sstevel@tonic-gate #include	<sys/sysmacros.h>
347c478bd9Sstevel@tonic-gate #include	<sys/byteorder.h>
357c478bd9Sstevel@tonic-gate #include	<sys/systm.h>
367c478bd9Sstevel@tonic-gate #include	<sys/stream.h>
377c478bd9Sstevel@tonic-gate #include	<sys/strsun.h>
387c478bd9Sstevel@tonic-gate #include	<sys/dlpi.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define		DLADDRL		(80)
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate void
437c478bd9Sstevel@tonic-gate dlbindack(
447c478bd9Sstevel@tonic-gate 	queue_t		*wq,
457c478bd9Sstevel@tonic-gate 	mblk_t		*mp,
467c478bd9Sstevel@tonic-gate 	t_scalar_t	sap,
477c478bd9Sstevel@tonic-gate 	void		*addrp,
487c478bd9Sstevel@tonic-gate 	t_uscalar_t	addrlen,
497c478bd9Sstevel@tonic-gate 	t_uscalar_t	maxconind,
507c478bd9Sstevel@tonic-gate 	t_uscalar_t	xidtest)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	union DL_primitives	*dlp;
537c478bd9Sstevel@tonic-gate 	size_t			size;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate 	size = sizeof (dl_bind_ack_t) + addrlen;
567c478bd9Sstevel@tonic-gate 	if ((mp = mexchange(wq, mp, size, M_PCPROTO, DL_BIND_ACK)) == NULL)
577c478bd9Sstevel@tonic-gate 		return;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	dlp = (union DL_primitives *)mp->b_rptr;
607c478bd9Sstevel@tonic-gate 	dlp->bind_ack.dl_sap = sap;
617c478bd9Sstevel@tonic-gate 	dlp->bind_ack.dl_addr_length = addrlen;
627c478bd9Sstevel@tonic-gate 	dlp->bind_ack.dl_addr_offset = sizeof (dl_bind_ack_t);
637c478bd9Sstevel@tonic-gate 	dlp->bind_ack.dl_max_conind = maxconind;
647c478bd9Sstevel@tonic-gate 	dlp->bind_ack.dl_xidtest_flg = xidtest;
657c478bd9Sstevel@tonic-gate 	if (addrlen != 0)
667c478bd9Sstevel@tonic-gate 		bcopy(addrp, mp->b_rptr + sizeof (dl_bind_ack_t), addrlen);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	qreply(wq, mp);
697c478bd9Sstevel@tonic-gate }
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate void
727c478bd9Sstevel@tonic-gate dlokack(
737c478bd9Sstevel@tonic-gate 	queue_t		*wq,
747c478bd9Sstevel@tonic-gate 	mblk_t		*mp,
757c478bd9Sstevel@tonic-gate 	t_uscalar_t	correct_primitive)
767c478bd9Sstevel@tonic-gate {
777c478bd9Sstevel@tonic-gate 	union DL_primitives	*dlp;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	if ((mp = mexchange(wq, mp, sizeof (dl_ok_ack_t), M_PCPROTO,
807c478bd9Sstevel@tonic-gate 	    DL_OK_ACK)) == NULL)
817c478bd9Sstevel@tonic-gate 		return;
827c478bd9Sstevel@tonic-gate 	dlp = (union DL_primitives *)mp->b_rptr;
837c478bd9Sstevel@tonic-gate 	dlp->ok_ack.dl_correct_primitive = correct_primitive;
847c478bd9Sstevel@tonic-gate 	qreply(wq, mp);
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate void
887c478bd9Sstevel@tonic-gate dlerrorack(
897c478bd9Sstevel@tonic-gate 	queue_t		*wq,
907c478bd9Sstevel@tonic-gate 	mblk_t		*mp,
917c478bd9Sstevel@tonic-gate 	t_uscalar_t	error_primitive,
927c478bd9Sstevel@tonic-gate 	t_uscalar_t	error,
937c478bd9Sstevel@tonic-gate 	t_uscalar_t	unix_errno)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	union DL_primitives	*dlp;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	if ((mp = mexchange(wq, mp, sizeof (dl_error_ack_t), M_PCPROTO,
987c478bd9Sstevel@tonic-gate 	    DL_ERROR_ACK)) == NULL)
997c478bd9Sstevel@tonic-gate 		return;
1007c478bd9Sstevel@tonic-gate 	dlp = (union DL_primitives *)mp->b_rptr;
1017c478bd9Sstevel@tonic-gate 	dlp->error_ack.dl_error_primitive = error_primitive;
1027c478bd9Sstevel@tonic-gate 	dlp->error_ack.dl_errno = error;
1037c478bd9Sstevel@tonic-gate 	dlp->error_ack.dl_unix_errno = unix_errno;
1047c478bd9Sstevel@tonic-gate 	qreply(wq, mp);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate void
1087c478bd9Sstevel@tonic-gate dluderrorind(
1097c478bd9Sstevel@tonic-gate 	queue_t		*wq,
1107c478bd9Sstevel@tonic-gate 	mblk_t		*mp,
1117c478bd9Sstevel@tonic-gate 	void		*addrp,
1127c478bd9Sstevel@tonic-gate 	t_uscalar_t	addrlen,
1137c478bd9Sstevel@tonic-gate 	t_uscalar_t	error,
1147c478bd9Sstevel@tonic-gate 	t_uscalar_t	unix_errno)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	union DL_primitives	*dlp;
1177c478bd9Sstevel@tonic-gate 	char			buf[DLADDRL];
1187c478bd9Sstevel@tonic-gate 	size_t			size;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	if (addrlen > DLADDRL)
1217c478bd9Sstevel@tonic-gate 		addrlen = DLADDRL;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	bcopy(addrp, buf, addrlen);
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	size = sizeof (dl_uderror_ind_t) + addrlen;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	if ((mp = mexchange(wq, mp, size, M_PCPROTO, DL_UDERROR_IND)) == NULL)
1287c478bd9Sstevel@tonic-gate 		return;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	dlp = (union DL_primitives *)mp->b_rptr;
1317c478bd9Sstevel@tonic-gate 	dlp->uderror_ind.dl_dest_addr_length = addrlen;
1327c478bd9Sstevel@tonic-gate 	dlp->uderror_ind.dl_dest_addr_offset = sizeof (dl_uderror_ind_t);
1337c478bd9Sstevel@tonic-gate 	dlp->uderror_ind.dl_unix_errno = unix_errno;
1347c478bd9Sstevel@tonic-gate 	dlp->uderror_ind.dl_errno = error;
1357c478bd9Sstevel@tonic-gate 	bcopy((caddr_t)buf,
1367c478bd9Sstevel@tonic-gate 	    (caddr_t)(mp->b_rptr + sizeof (dl_uderror_ind_t)), addrlen);
1377c478bd9Sstevel@tonic-gate 	qreply(wq, mp);
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate void
1417c478bd9Sstevel@tonic-gate dlphysaddrack(
1427c478bd9Sstevel@tonic-gate 	queue_t		*wq,
1437c478bd9Sstevel@tonic-gate 	mblk_t		*mp,
1447c478bd9Sstevel@tonic-gate 	void		*addrp,
1457c478bd9Sstevel@tonic-gate 	t_uscalar_t	len)
1467c478bd9Sstevel@tonic-gate {
1477c478bd9Sstevel@tonic-gate 	union DL_primitives	*dlp;
1487c478bd9Sstevel@tonic-gate 	size_t			size;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	size = sizeof (dl_phys_addr_ack_t) + len;
1517c478bd9Sstevel@tonic-gate 	if ((mp = mexchange(wq, mp, size, M_PCPROTO, DL_PHYS_ADDR_ACK)) == NULL)
1527c478bd9Sstevel@tonic-gate 		return;
1537c478bd9Sstevel@tonic-gate 	dlp = (union DL_primitives *)mp->b_rptr;
1547c478bd9Sstevel@tonic-gate 	dlp->physaddr_ack.dl_addr_length = len;
1557c478bd9Sstevel@tonic-gate 	dlp->physaddr_ack.dl_addr_offset = sizeof (dl_phys_addr_ack_t);
1567c478bd9Sstevel@tonic-gate 	if (len != 0)
1577c478bd9Sstevel@tonic-gate 		bcopy(addrp, mp->b_rptr + sizeof (dl_phys_addr_ack_t), len);
1587c478bd9Sstevel@tonic-gate 	qreply(wq, mp);
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate void
1627c478bd9Sstevel@tonic-gate dlcapabsetqid(dl_mid_t *idp, const queue_t *q)
1637c478bd9Sstevel@tonic-gate {
1647c478bd9Sstevel@tonic-gate #ifndef _LP64
1657c478bd9Sstevel@tonic-gate 	idp->mid[0] = (t_uscalar_t)q;
1667c478bd9Sstevel@tonic-gate #else
1677c478bd9Sstevel@tonic-gate 	idp->mid[0] = (t_uscalar_t)BMASK_32((uint64_t)q);
1687c478bd9Sstevel@tonic-gate 	idp->mid[1] = (t_uscalar_t)BMASK_32(((uint64_t)q) >> 32);
1697c478bd9Sstevel@tonic-gate #endif
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate boolean_t
1737c478bd9Sstevel@tonic-gate dlcapabcheckqid(const dl_mid_t *idp, const queue_t *q)
1747c478bd9Sstevel@tonic-gate {
1757c478bd9Sstevel@tonic-gate #ifndef _LP64
1767c478bd9Sstevel@tonic-gate 	return ((queue_t *)(idp->mid[0]) == q);
1777c478bd9Sstevel@tonic-gate #else
1787c478bd9Sstevel@tonic-gate 	return ((queue_t *)
1797c478bd9Sstevel@tonic-gate 	    ((uint64_t)idp->mid[0] | ((uint64_t)idp->mid[1] << 32)) == q);
1807c478bd9Sstevel@tonic-gate #endif
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate void
1847c478bd9Sstevel@tonic-gate dlnotifyack(
1857c478bd9Sstevel@tonic-gate 	queue_t		*wq,
1867c478bd9Sstevel@tonic-gate 	mblk_t		*mp,
1877c478bd9Sstevel@tonic-gate 	uint32_t	notifications)
1887c478bd9Sstevel@tonic-gate {
1897c478bd9Sstevel@tonic-gate 	union DL_primitives	*dlp;
1907c478bd9Sstevel@tonic-gate 
191*392b1d6eSyz147064 	if ((mp = mexchange(wq, mp, sizeof (dl_notify_ack_t), M_PROTO,
1927c478bd9Sstevel@tonic-gate 	    DL_NOTIFY_ACK)) == NULL)
1937c478bd9Sstevel@tonic-gate 		return;
1947c478bd9Sstevel@tonic-gate 	dlp = (union DL_primitives *)mp->b_rptr;
1957c478bd9Sstevel@tonic-gate 	dlp->notify_ack.dl_notifications = notifications;
1967c478bd9Sstevel@tonic-gate 	qreply(wq, mp);
1977c478bd9Sstevel@tonic-gate }
198