xref: /onnv-gate/usr/src/uts/common/io/1394/adapters/hci1394.c (revision 7656:2621e50fdf4a)
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
5*7656SSherry.Moore@Sun.COM  * Common Development and Distribution License (the "License").
6*7656SSherry.Moore@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*7656SSherry.Moore@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate  * hci1394.c
290Sstevel@tonic-gate  *    1394 (firewire) OpenHCI 1.0 HBA driver. This file contains the driver's
300Sstevel@tonic-gate  *    _init(), _info(), and _fini().
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <sys/modctl.h>
340Sstevel@tonic-gate #include <sys/conf.h>
350Sstevel@tonic-gate #include <sys/ddi.h>
360Sstevel@tonic-gate #include <sys/sunddi.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #include <sys/1394/ieee1394.h>
390Sstevel@tonic-gate #include <sys/1394/h1394.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include <sys/1394/adapters/hci1394.h>
420Sstevel@tonic-gate 
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /* HAL State Pointer */
450Sstevel@tonic-gate void *hci1394_statep;
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /* Character/Block Operations */
480Sstevel@tonic-gate static struct cb_ops hci1394_cb_ops = {
490Sstevel@tonic-gate 	hci1394_open,		/* open */
500Sstevel@tonic-gate 	hci1394_close,		/* close */
510Sstevel@tonic-gate 	nodev,			/* strategy (block) */
520Sstevel@tonic-gate 	nodev,			/* print (block) */
530Sstevel@tonic-gate 	nodev,			/* dump (block) */
540Sstevel@tonic-gate 	nodev,			/* read */
550Sstevel@tonic-gate 	nodev,			/* write */
560Sstevel@tonic-gate 	hci1394_ioctl,		/* ioctl */
570Sstevel@tonic-gate 	nodev,			/* devmap */
580Sstevel@tonic-gate 	nodev,			/* mmap */
590Sstevel@tonic-gate 	nodev,			/* segmap */
600Sstevel@tonic-gate 	nochpoll,		/* chpoll */
610Sstevel@tonic-gate 	ddi_prop_op,		/* prop_op */
620Sstevel@tonic-gate 	NULL,			/* streams */
630Sstevel@tonic-gate 	D_NEW | D_MP |
640Sstevel@tonic-gate 	D_64BIT | D_HOTPLUG,	/* flags */
650Sstevel@tonic-gate 	CB_REV			/* rev */
660Sstevel@tonic-gate };
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /* Driver Operations */
690Sstevel@tonic-gate static struct dev_ops hci1394_ops = {
700Sstevel@tonic-gate 	DEVO_REV,		/* struct rev */
710Sstevel@tonic-gate 	0,			/* refcnt */
720Sstevel@tonic-gate 	hci1394_getinfo,	/* getinfo */
730Sstevel@tonic-gate 	nulldev,		/* identify */
740Sstevel@tonic-gate 	nulldev,		/* probe */
750Sstevel@tonic-gate 	hci1394_attach,		/* attach */
760Sstevel@tonic-gate 	hci1394_detach,		/* detach */
770Sstevel@tonic-gate 	nodev,			/* reset */
780Sstevel@tonic-gate 	&hci1394_cb_ops,	/* cb_ops */
790Sstevel@tonic-gate 	NULL,			/* bus_ops */
80*7656SSherry.Moore@Sun.COM 	NULL,			/* power */
81*7656SSherry.Moore@Sun.COM 	hci1394_quiesce,	/* devo_quiesce */
820Sstevel@tonic-gate };
830Sstevel@tonic-gate 
840Sstevel@tonic-gate /* Module Driver Info */
850Sstevel@tonic-gate static struct modldrv hci1394_modldrv = {
860Sstevel@tonic-gate 	&mod_driverops,
87*7656SSherry.Moore@Sun.COM 	"1394 OpenHCI HBA driver",
880Sstevel@tonic-gate 	&hci1394_ops
890Sstevel@tonic-gate };
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /* Module Linkage */
920Sstevel@tonic-gate static struct modlinkage hci1394_modlinkage = {
930Sstevel@tonic-gate 	MODREV_1,
940Sstevel@tonic-gate 	&hci1394_modldrv,
950Sstevel@tonic-gate 	NULL
960Sstevel@tonic-gate };
970Sstevel@tonic-gate 
980Sstevel@tonic-gate #ifndef NPROBE
990Sstevel@tonic-gate extern int tnf_mod_load(void);
1000Sstevel@tonic-gate extern int tnf_mod_unload(struct modlinkage *mlp);
1010Sstevel@tonic-gate #endif
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate int
_init()1040Sstevel@tonic-gate _init()
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate 	int status;
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate #ifndef NPROBE
1100Sstevel@tonic-gate 	(void) tnf_mod_load();
1110Sstevel@tonic-gate #endif
1120Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_init_enter, HCI1394_TNF_HAL_STACK, "");
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	status = ddi_soft_state_init(&hci1394_statep, sizeof (hci1394_state_t),
1150Sstevel@tonic-gate 	    (size_t)HCI1394_INITIAL_STATES);
1160Sstevel@tonic-gate 	if (status != 0) {
1170Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_init_ssi_fail, HCI1394_TNF_HAL_ERROR, "",
1180Sstevel@tonic-gate 		    tnf_string, errmsg, "failed in ddi_soft_state_init",
1190Sstevel@tonic-gate 		    tnf_int, error, status);
1200Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_init_exit, HCI1394_TNF_HAL_STACK, "");
1210Sstevel@tonic-gate #ifndef NPROBE
1220Sstevel@tonic-gate 		(void) tnf_mod_unload(&hci1394_modlinkage);
1230Sstevel@tonic-gate #endif
1240Sstevel@tonic-gate 		return (status);
1250Sstevel@tonic-gate 	}
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	/* Call into services layer to init bus-ops */
1280Sstevel@tonic-gate 	status = h1394_init(&hci1394_modlinkage);
1290Sstevel@tonic-gate 	if (status != 0) {
1300Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_init_h1394_fail, HCI1394_TNF_HAL_ERROR, "",
1310Sstevel@tonic-gate 		    tnf_string, errmsg, "failed in h1394_init",
1320Sstevel@tonic-gate 		    tnf_int, error, status);
1330Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_init_exit, HCI1394_TNF_HAL_STACK, "");
1340Sstevel@tonic-gate #ifndef NPROBE
1350Sstevel@tonic-gate 		(void) tnf_mod_unload(&hci1394_modlinkage);
1360Sstevel@tonic-gate #endif
1370Sstevel@tonic-gate 		return (status);
1380Sstevel@tonic-gate 	}
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	status = mod_install(&hci1394_modlinkage);
1410Sstevel@tonic-gate 	if (status != 0) {
1420Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_init_modi_fail, HCI1394_TNF_HAL_ERROR, "",
1430Sstevel@tonic-gate 		    tnf_string, errmsg, "failed in mod_install",
1440Sstevel@tonic-gate 		    tnf_int, error, status);
1450Sstevel@tonic-gate 		ddi_soft_state_fini(&hci1394_statep);
1460Sstevel@tonic-gate #ifndef NPROBE
1470Sstevel@tonic-gate 		(void) tnf_mod_unload(&hci1394_modlinkage);
1480Sstevel@tonic-gate #endif
1490Sstevel@tonic-gate 		return (status);
1500Sstevel@tonic-gate 	}
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_init_exit, HCI1394_TNF_HAL_STACK, "");
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	return (status);
1550Sstevel@tonic-gate }
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1590Sstevel@tonic-gate _info(struct modinfo *modinfop)
1600Sstevel@tonic-gate {
1610Sstevel@tonic-gate 	int status;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_info_enter, HCI1394_TNF_HAL_STACK, "");
1640Sstevel@tonic-gate 	status = mod_info(&hci1394_modlinkage, modinfop);
1650Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_info_exit, HCI1394_TNF_HAL_STACK, "");
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 	return (status);
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate int
_fini()1720Sstevel@tonic-gate _fini()
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate 	int status;
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_fini_enter, HCI1394_TNF_HAL_STACK, "");
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	status = mod_remove(&hci1394_modlinkage);
1790Sstevel@tonic-gate 	if (status != 0) {
1800Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_fini_modr_fail, HCI1394_TNF_HAL_ERROR, "",
1810Sstevel@tonic-gate 		    tnf_string, errmsg, "failed in mod_remove",
1820Sstevel@tonic-gate 		    tnf_int, error, status);
1830Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_fini_exit, HCI1394_TNF_HAL_STACK, "");
1840Sstevel@tonic-gate 		return (status);
1850Sstevel@tonic-gate 	}
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate 	/* Call into services layer notify about _fini */
1880Sstevel@tonic-gate 	h1394_fini(&hci1394_modlinkage);
1890Sstevel@tonic-gate 	ddi_soft_state_fini(&hci1394_statep);
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_fini_exit, HCI1394_TNF_HAL_STACK, "");
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate #ifndef NPROBE
1940Sstevel@tonic-gate 	(void) tnf_mod_unload(&hci1394_modlinkage);
1950Sstevel@tonic-gate #endif
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	return (status);
1980Sstevel@tonic-gate }
199