xref: /titanic_50/usr/src/uts/common/io/1394/adapters/hci1394.c (revision 193974072f41a843678abf5f61979c748687e66b)
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*19397407SSherry Moore  * Common Development and Distribution License (the "License").
6*19397407SSherry Moore  * 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*19397407SSherry Moore  * 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 /*
287c478bd9Sstevel@tonic-gate  * hci1394.c
297c478bd9Sstevel@tonic-gate  *    1394 (firewire) OpenHCI 1.0 HBA driver. This file contains the driver's
307c478bd9Sstevel@tonic-gate  *    _init(), _info(), and _fini().
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
347c478bd9Sstevel@tonic-gate #include <sys/conf.h>
357c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
367c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/1394/ieee1394.h>
397c478bd9Sstevel@tonic-gate #include <sys/1394/h1394.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <sys/1394/adapters/hci1394.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /* HAL State Pointer */
457c478bd9Sstevel@tonic-gate void *hci1394_statep;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /* Character/Block Operations */
487c478bd9Sstevel@tonic-gate static struct cb_ops hci1394_cb_ops = {
497c478bd9Sstevel@tonic-gate 	hci1394_open,		/* open */
507c478bd9Sstevel@tonic-gate 	hci1394_close,		/* close */
517c478bd9Sstevel@tonic-gate 	nodev,			/* strategy (block) */
527c478bd9Sstevel@tonic-gate 	nodev,			/* print (block) */
537c478bd9Sstevel@tonic-gate 	nodev,			/* dump (block) */
547c478bd9Sstevel@tonic-gate 	nodev,			/* read */
557c478bd9Sstevel@tonic-gate 	nodev,			/* write */
567c478bd9Sstevel@tonic-gate 	hci1394_ioctl,		/* ioctl */
577c478bd9Sstevel@tonic-gate 	nodev,			/* devmap */
587c478bd9Sstevel@tonic-gate 	nodev,			/* mmap */
597c478bd9Sstevel@tonic-gate 	nodev,			/* segmap */
607c478bd9Sstevel@tonic-gate 	nochpoll,		/* chpoll */
617c478bd9Sstevel@tonic-gate 	ddi_prop_op,		/* prop_op */
627c478bd9Sstevel@tonic-gate 	NULL,			/* streams */
637c478bd9Sstevel@tonic-gate 	D_NEW | D_MP |
647c478bd9Sstevel@tonic-gate 	D_64BIT | D_HOTPLUG,	/* flags */
657c478bd9Sstevel@tonic-gate 	CB_REV			/* rev */
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /* Driver Operations */
697c478bd9Sstevel@tonic-gate static struct dev_ops hci1394_ops = {
707c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* struct rev */
717c478bd9Sstevel@tonic-gate 	0,			/* refcnt */
727c478bd9Sstevel@tonic-gate 	hci1394_getinfo,	/* getinfo */
737c478bd9Sstevel@tonic-gate 	nulldev,		/* identify */
747c478bd9Sstevel@tonic-gate 	nulldev,		/* probe */
757c478bd9Sstevel@tonic-gate 	hci1394_attach,		/* attach */
767c478bd9Sstevel@tonic-gate 	hci1394_detach,		/* detach */
777c478bd9Sstevel@tonic-gate 	nodev,			/* reset */
787c478bd9Sstevel@tonic-gate 	&hci1394_cb_ops,	/* cb_ops */
797c478bd9Sstevel@tonic-gate 	NULL,			/* bus_ops */
80*19397407SSherry Moore 	NULL,			/* power */
81*19397407SSherry Moore 	hci1394_quiesce,	/* devo_quiesce */
827c478bd9Sstevel@tonic-gate };
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /* Module Driver Info */
857c478bd9Sstevel@tonic-gate static struct modldrv hci1394_modldrv = {
867c478bd9Sstevel@tonic-gate 	&mod_driverops,
87*19397407SSherry Moore 	"1394 OpenHCI HBA driver",
887c478bd9Sstevel@tonic-gate 	&hci1394_ops
897c478bd9Sstevel@tonic-gate };
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /* Module Linkage */
927c478bd9Sstevel@tonic-gate static struct modlinkage hci1394_modlinkage = {
937c478bd9Sstevel@tonic-gate 	MODREV_1,
947c478bd9Sstevel@tonic-gate 	&hci1394_modldrv,
957c478bd9Sstevel@tonic-gate 	NULL
967c478bd9Sstevel@tonic-gate };
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #ifndef NPROBE
997c478bd9Sstevel@tonic-gate extern int tnf_mod_load(void);
1007c478bd9Sstevel@tonic-gate extern int tnf_mod_unload(struct modlinkage *mlp);
1017c478bd9Sstevel@tonic-gate #endif
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate int
_init()1047c478bd9Sstevel@tonic-gate _init()
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate 	int status;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #ifndef NPROBE
1107c478bd9Sstevel@tonic-gate 	(void) tnf_mod_load();
1117c478bd9Sstevel@tonic-gate #endif
1127c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_init_enter, HCI1394_TNF_HAL_STACK, "");
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	status = ddi_soft_state_init(&hci1394_statep, sizeof (hci1394_state_t),
1157c478bd9Sstevel@tonic-gate 	    (size_t)HCI1394_INITIAL_STATES);
1167c478bd9Sstevel@tonic-gate 	if (status != 0) {
1177c478bd9Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_init_ssi_fail, HCI1394_TNF_HAL_ERROR, "",
1187c478bd9Sstevel@tonic-gate 		    tnf_string, errmsg, "failed in ddi_soft_state_init",
1197c478bd9Sstevel@tonic-gate 		    tnf_int, error, status);
1207c478bd9Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_init_exit, HCI1394_TNF_HAL_STACK, "");
1217c478bd9Sstevel@tonic-gate #ifndef NPROBE
1227c478bd9Sstevel@tonic-gate 		(void) tnf_mod_unload(&hci1394_modlinkage);
1237c478bd9Sstevel@tonic-gate #endif
1247c478bd9Sstevel@tonic-gate 		return (status);
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	/* Call into services layer to init bus-ops */
1287c478bd9Sstevel@tonic-gate 	status = h1394_init(&hci1394_modlinkage);
1297c478bd9Sstevel@tonic-gate 	if (status != 0) {
1307c478bd9Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_init_h1394_fail, HCI1394_TNF_HAL_ERROR, "",
1317c478bd9Sstevel@tonic-gate 		    tnf_string, errmsg, "failed in h1394_init",
1327c478bd9Sstevel@tonic-gate 		    tnf_int, error, status);
1337c478bd9Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_init_exit, HCI1394_TNF_HAL_STACK, "");
1347c478bd9Sstevel@tonic-gate #ifndef NPROBE
1357c478bd9Sstevel@tonic-gate 		(void) tnf_mod_unload(&hci1394_modlinkage);
1367c478bd9Sstevel@tonic-gate #endif
1377c478bd9Sstevel@tonic-gate 		return (status);
1387c478bd9Sstevel@tonic-gate 	}
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	status = mod_install(&hci1394_modlinkage);
1417c478bd9Sstevel@tonic-gate 	if (status != 0) {
1427c478bd9Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_init_modi_fail, HCI1394_TNF_HAL_ERROR, "",
1437c478bd9Sstevel@tonic-gate 		    tnf_string, errmsg, "failed in mod_install",
1447c478bd9Sstevel@tonic-gate 		    tnf_int, error, status);
1457c478bd9Sstevel@tonic-gate 		ddi_soft_state_fini(&hci1394_statep);
1467c478bd9Sstevel@tonic-gate #ifndef NPROBE
1477c478bd9Sstevel@tonic-gate 		(void) tnf_mod_unload(&hci1394_modlinkage);
1487c478bd9Sstevel@tonic-gate #endif
1497c478bd9Sstevel@tonic-gate 		return (status);
1507c478bd9Sstevel@tonic-gate 	}
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_init_exit, HCI1394_TNF_HAL_STACK, "");
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	return (status);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1597c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate 	int status;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_info_enter, HCI1394_TNF_HAL_STACK, "");
1647c478bd9Sstevel@tonic-gate 	status = mod_info(&hci1394_modlinkage, modinfop);
1657c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_info_exit, HCI1394_TNF_HAL_STACK, "");
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	return (status);
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate int
_fini()1727c478bd9Sstevel@tonic-gate _fini()
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate 	int status;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_fini_enter, HCI1394_TNF_HAL_STACK, "");
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	status = mod_remove(&hci1394_modlinkage);
1797c478bd9Sstevel@tonic-gate 	if (status != 0) {
1807c478bd9Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_fini_modr_fail, HCI1394_TNF_HAL_ERROR, "",
1817c478bd9Sstevel@tonic-gate 		    tnf_string, errmsg, "failed in mod_remove",
1827c478bd9Sstevel@tonic-gate 		    tnf_int, error, status);
1837c478bd9Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_fini_exit, HCI1394_TNF_HAL_STACK, "");
1847c478bd9Sstevel@tonic-gate 		return (status);
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	/* Call into services layer notify about _fini */
1887c478bd9Sstevel@tonic-gate 	h1394_fini(&hci1394_modlinkage);
1897c478bd9Sstevel@tonic-gate 	ddi_soft_state_fini(&hci1394_statep);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_fini_exit, HCI1394_TNF_HAL_STACK, "");
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate #ifndef NPROBE
1947c478bd9Sstevel@tonic-gate 	(void) tnf_mod_unload(&hci1394_modlinkage);
1957c478bd9Sstevel@tonic-gate #endif
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	return (status);
1987c478bd9Sstevel@tonic-gate }
199