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
56881Sbharding * Common Development and Distribution License (the "License").
66881Sbharding * 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 /*
226881Sbharding * 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_detach.c
290Sstevel@tonic-gate * HBA detach() routine with associated funtions.
300Sstevel@tonic-gate */
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/kmem.h>
340Sstevel@tonic-gate #include <sys/conf.h>
350Sstevel@tonic-gate #include <sys/ddi.h>
360Sstevel@tonic-gate #include <sys/modctl.h>
370Sstevel@tonic-gate #include <sys/stat.h>
380Sstevel@tonic-gate #include <sys/sunddi.h>
390Sstevel@tonic-gate
400Sstevel@tonic-gate #include <sys/1394/h1394.h>
410Sstevel@tonic-gate #include <sys/1394/adapters/hci1394.h>
420Sstevel@tonic-gate #include <sys/1394/adapters/hci1394_extern.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate
450Sstevel@tonic-gate
460Sstevel@tonic-gate int
hci1394_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)470Sstevel@tonic-gate hci1394_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
480Sstevel@tonic-gate {
490Sstevel@tonic-gate hci1394_state_t *soft_state;
500Sstevel@tonic-gate
510Sstevel@tonic-gate
520Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_detach_enter, HCI1394_TNF_HAL_STACK, "");
530Sstevel@tonic-gate
540Sstevel@tonic-gate soft_state = ddi_get_soft_state(hci1394_statep, ddi_get_instance(dip));
550Sstevel@tonic-gate if (soft_state == NULL) {
560Sstevel@tonic-gate TNF_PROBE_1(hci1394_detach_ssn_fail, HCI1394_TNF_HAL_ERROR, "",
570Sstevel@tonic-gate tnf_string, errmsg, "soft_state = NULL");
580Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_detach_exit, HCI1394_TNF_HAL_STACK,
590Sstevel@tonic-gate "");
600Sstevel@tonic-gate return (DDI_FAILURE);
610Sstevel@tonic-gate }
620Sstevel@tonic-gate
630Sstevel@tonic-gate switch (cmd) {
640Sstevel@tonic-gate case DDI_DETACH:
650Sstevel@tonic-gate /* Don't allow the HW to generate any more interrupts */
660Sstevel@tonic-gate hci1394_ohci_intr_master_disable(soft_state->ohci);
676881Sbharding hci1394_ohci_it_intr_disable(soft_state->ohci, 0xFFFFFFFF);
686881Sbharding hci1394_ohci_ir_intr_disable(soft_state->ohci, 0xFFFFFFFF);
696881Sbharding
706881Sbharding /* Clear any pending interrupts - no longer valid */
716881Sbharding hci1394_ohci_intr_clear(soft_state->ohci, 0xFFFFFFFF);
726881Sbharding hci1394_ohci_it_intr_clear(soft_state->ohci, 0xFFFFFFFF);
736881Sbharding hci1394_ohci_ir_intr_clear(soft_state->ohci, 0xFFFFFFFF);
746881Sbharding
756881Sbharding /* Make sure we tell others on the bus we are dropping out */
766881Sbharding (void) hci1394_ohci_phy_clr(soft_state->ohci, 4, 0xc0);
776881Sbharding ddi_put32(soft_state->ohci->ohci_reg_handle,
786881Sbharding &soft_state->ohci->ohci_regs->link_ctrl_clr,
796881Sbharding 0xFFFFFFFF);
800Sstevel@tonic-gate
81638Sap25164 /* unregister interrupt handler */
82638Sap25164 hci1394_isr_handler_fini(soft_state);
83638Sap25164
840Sstevel@tonic-gate /* don't accept anymore commands from services layer */
850Sstevel@tonic-gate (void) hci1394_state_set(&soft_state->drvinfo,
860Sstevel@tonic-gate HCI1394_SHUTDOWN);
870Sstevel@tonic-gate
886881Sbharding /* Do a long reset on the bus so every one knows we are gone */
896881Sbharding (void) hci1394_ohci_bus_reset_nroot(soft_state->ohci);
906881Sbharding
910Sstevel@tonic-gate /* Reset the OHCI HW */
920Sstevel@tonic-gate (void) hci1394_ohci_soft_reset(soft_state->ohci);
930Sstevel@tonic-gate
940Sstevel@tonic-gate /* Flush out async DMA Q's (cancels pendingQ timeouts too) */
950Sstevel@tonic-gate hci1394_async_flush(soft_state->async);
960Sstevel@tonic-gate
970Sstevel@tonic-gate (void) h1394_detach(&soft_state->drvinfo.di_sl_private,
980Sstevel@tonic-gate DDI_DETACH);
990Sstevel@tonic-gate
1000Sstevel@tonic-gate /* remove the minor node */
1010Sstevel@tonic-gate ddi_remove_minor_node(dip, "devctl");
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate /* cleanup */
1040Sstevel@tonic-gate hci1394_detach_hardware(soft_state);
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate /* cleanup Solaris interrupt stuff */
1070Sstevel@tonic-gate hci1394_isr_fini(soft_state);
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate /* cleanup soft state stuff */
1100Sstevel@tonic-gate hci1394_soft_state_fini(soft_state);
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate /* free soft state */
1130Sstevel@tonic-gate ddi_soft_state_free(hci1394_statep,
1140Sstevel@tonic-gate soft_state->drvinfo.di_instance);
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_detach_exit, HCI1394_TNF_HAL_STACK,
1170Sstevel@tonic-gate "");
1180Sstevel@tonic-gate return (DDI_SUCCESS);
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate case DDI_SUSPEND:
1210Sstevel@tonic-gate /* Don't allow the HW to generate any more interrupts */
1220Sstevel@tonic-gate hci1394_ohci_intr_master_disable(soft_state->ohci);
1236881Sbharding hci1394_ohci_it_intr_disable(soft_state->ohci, 0xFFFFFFFF);
1246881Sbharding hci1394_ohci_ir_intr_disable(soft_state->ohci, 0xFFFFFFFF);
1256881Sbharding
1266881Sbharding /* Clear any pending interrupts - no longer valid */
1276881Sbharding hci1394_ohci_intr_clear(soft_state->ohci, 0xFFFFFFFF);
1286881Sbharding hci1394_ohci_it_intr_clear(soft_state->ohci, 0xFFFFFFFF);
1296881Sbharding hci1394_ohci_ir_intr_clear(soft_state->ohci, 0xFFFFFFFF);
1306881Sbharding
1316881Sbharding /* Make sure we tell others on the bus we are dropping out */
1326881Sbharding (void) hci1394_ohci_phy_clr(soft_state->ohci, 4, 0xc0);
1336881Sbharding ddi_put32(soft_state->ohci->ohci_reg_handle,
1346881Sbharding &soft_state->ohci->ohci_regs->link_ctrl_clr,
1356881Sbharding 0xFFFFFFFF);
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate /* don't accept anymore commands from services layer */
1380Sstevel@tonic-gate (void) hci1394_state_set(&soft_state->drvinfo,
1390Sstevel@tonic-gate HCI1394_SHUTDOWN);
1400Sstevel@tonic-gate
1416881Sbharding /* Do a long reset on the bus so every one knows we are gone */
1426881Sbharding (void) hci1394_ohci_bus_reset_nroot(soft_state->ohci);
1436881Sbharding
1440Sstevel@tonic-gate /* Reset the OHCI HW */
1450Sstevel@tonic-gate (void) hci1394_ohci_soft_reset(soft_state->ohci);
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate /* Make sure async engine is ready to suspend */
1480Sstevel@tonic-gate hci1394_async_suspend(soft_state->async);
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate (void) h1394_detach(&soft_state->drvinfo.di_sl_private,
1510Sstevel@tonic-gate DDI_SUSPEND);
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_detach_exit, HCI1394_TNF_HAL_STACK,
1540Sstevel@tonic-gate "");
1550Sstevel@tonic-gate return (DDI_SUCCESS);
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate default:
1580Sstevel@tonic-gate TNF_PROBE_1(hci1394_detach_fail, HCI1394_TNF_HAL_ERROR, "",
1590Sstevel@tonic-gate tnf_string, errmsg, "in detach default");
1600Sstevel@tonic-gate break;
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_detach_exit, HCI1394_TNF_HAL_STACK, "");
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate return (DDI_FAILURE);
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate
168*7656SSherry.Moore@Sun.COM /*
169*7656SSherry.Moore@Sun.COM * quiesce(9E) entry point.
170*7656SSherry.Moore@Sun.COM *
171*7656SSherry.Moore@Sun.COM * This function is called when the system is single-threaded at high
172*7656SSherry.Moore@Sun.COM * PIL with preemption disabled. Therefore, this function must not be
173*7656SSherry.Moore@Sun.COM * blocked.
174*7656SSherry.Moore@Sun.COM *
175*7656SSherry.Moore@Sun.COM * This function returns DDI_SUCCESS on success, or DDI_FAILURE on failure.
176*7656SSherry.Moore@Sun.COM * DDI_FAILURE indicates an error condition and should almost never happen.
177*7656SSherry.Moore@Sun.COM */
178*7656SSherry.Moore@Sun.COM int
hci1394_quiesce(dev_info_t * dip)179*7656SSherry.Moore@Sun.COM hci1394_quiesce(dev_info_t *dip)
180*7656SSherry.Moore@Sun.COM {
181*7656SSherry.Moore@Sun.COM hci1394_state_t *soft_state;
182*7656SSherry.Moore@Sun.COM
183*7656SSherry.Moore@Sun.COM soft_state = ddi_get_soft_state(hci1394_statep, ddi_get_instance(dip));
184*7656SSherry.Moore@Sun.COM
185*7656SSherry.Moore@Sun.COM if (soft_state == NULL) {
186*7656SSherry.Moore@Sun.COM return (DDI_FAILURE);
187*7656SSherry.Moore@Sun.COM }
188*7656SSherry.Moore@Sun.COM
189*7656SSherry.Moore@Sun.COM /* Don't allow the HW to generate any more interrupts */
190*7656SSherry.Moore@Sun.COM hci1394_ohci_intr_master_disable(soft_state->ohci);
191*7656SSherry.Moore@Sun.COM hci1394_ohci_it_intr_disable(soft_state->ohci, 0xFFFFFFFF);
192*7656SSherry.Moore@Sun.COM hci1394_ohci_ir_intr_disable(soft_state->ohci, 0xFFFFFFFF);
193*7656SSherry.Moore@Sun.COM
194*7656SSherry.Moore@Sun.COM /* Clear any pending interrupts - no longer valid */
195*7656SSherry.Moore@Sun.COM hci1394_ohci_intr_clear(soft_state->ohci, 0xFFFFFFFF);
196*7656SSherry.Moore@Sun.COM hci1394_ohci_it_intr_clear(soft_state->ohci, 0xFFFFFFFF);
197*7656SSherry.Moore@Sun.COM hci1394_ohci_ir_intr_clear(soft_state->ohci, 0xFFFFFFFF);
198*7656SSherry.Moore@Sun.COM
199*7656SSherry.Moore@Sun.COM /* Make sure we tell others on the bus we are dropping out */
200*7656SSherry.Moore@Sun.COM (void) hci1394_ohci_phy_clr(soft_state->ohci, 4, 0xc0);
201*7656SSherry.Moore@Sun.COM ddi_put32(soft_state->ohci->ohci_reg_handle,
202*7656SSherry.Moore@Sun.COM &soft_state->ohci->ohci_regs->link_ctrl_clr, 0xFFFFFFFF);
203*7656SSherry.Moore@Sun.COM
204*7656SSherry.Moore@Sun.COM /* Do a long reset on the bus so every one knows we are gone */
205*7656SSherry.Moore@Sun.COM (void) hci1394_ohci_bus_reset_nroot(soft_state->ohci);
206*7656SSherry.Moore@Sun.COM
207*7656SSherry.Moore@Sun.COM /* Reset the OHCI HW */
208*7656SSherry.Moore@Sun.COM (void) hci1394_ohci_soft_reset(soft_state->ohci);
209*7656SSherry.Moore@Sun.COM
210*7656SSherry.Moore@Sun.COM return (DDI_SUCCESS);
211*7656SSherry.Moore@Sun.COM }
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate void
hci1394_detach_hardware(hci1394_state_t * soft_state)2140Sstevel@tonic-gate hci1394_detach_hardware(hci1394_state_t *soft_state)
2150Sstevel@tonic-gate {
2160Sstevel@tonic-gate ASSERT(soft_state != NULL);
2170Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_detach_hardware_enter, HCI1394_TNF_HAL_STACK,
2180Sstevel@tonic-gate "");
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate /* free up vendor specific registers */
2210Sstevel@tonic-gate hci1394_vendor_fini(&soft_state->vendor);
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate /* cleanup isoch layer */
2240Sstevel@tonic-gate hci1394_isoch_fini(&soft_state->isoch);
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate /* cleanup async layer */
2270Sstevel@tonic-gate hci1394_async_fini(&soft_state->async);
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate /* Free up csr register space */
2300Sstevel@tonic-gate hci1394_csr_fini(&soft_state->csr);
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate /* free up OpenHCI registers */
2330Sstevel@tonic-gate hci1394_ohci_fini(&soft_state->ohci);
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate /* free up PCI config space */
2360Sstevel@tonic-gate hci1394_pci_fini(soft_state);
2370Sstevel@tonic-gate
2380Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_detach_hardware_exit, HCI1394_TNF_HAL_STACK,
2390Sstevel@tonic-gate "");
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate /*
2440Sstevel@tonic-gate * hci1394_pci_fini()
2450Sstevel@tonic-gate * Cleanup after a PCI init.
2460Sstevel@tonic-gate */
2470Sstevel@tonic-gate void
hci1394_pci_fini(hci1394_state_t * soft_state)2480Sstevel@tonic-gate hci1394_pci_fini(hci1394_state_t *soft_state)
2490Sstevel@tonic-gate {
2500Sstevel@tonic-gate ASSERT(soft_state != NULL);
2510Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_pci_fini_enter, HCI1394_TNF_HAL_STACK, "");
2520Sstevel@tonic-gate pci_config_teardown(&soft_state->pci_config);
2530Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_pci_fini_exit, HCI1394_TNF_HAL_STACK, "");
2540Sstevel@tonic-gate }
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate /*
2580Sstevel@tonic-gate * hci1394_soft_state_fini()
2590Sstevel@tonic-gate * Cleanup any mutex's, etc. in soft_state.
2600Sstevel@tonic-gate */
2610Sstevel@tonic-gate void
hci1394_soft_state_fini(hci1394_state_t * soft_state)2620Sstevel@tonic-gate hci1394_soft_state_fini(hci1394_state_t *soft_state)
2630Sstevel@tonic-gate {
2640Sstevel@tonic-gate ASSERT(soft_state != NULL);
2650Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_soft_state_fini_enter, HCI1394_TNF_HAL_STACK,
2660Sstevel@tonic-gate "");
2670Sstevel@tonic-gate mutex_destroy(&soft_state->drvinfo.di_drvstate.ds_mutex);
2680Sstevel@tonic-gate TNF_PROBE_0_DEBUG(hci1394_soft_state_fini_exit, HCI1394_TNF_HAL_STACK,
2690Sstevel@tonic-gate "");
2700Sstevel@tonic-gate }
271