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
51624Spjha * Common Development and Distribution License (the "License").
61624Spjha * 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 /*
221624Spjha * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/kmem.h>
300Sstevel@tonic-gate #include <sys/async.h>
310Sstevel@tonic-gate #include <sys/sysmacros.h>
320Sstevel@tonic-gate #include <sys/sunddi.h>
330Sstevel@tonic-gate #include <sys/sunndi.h>
340Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
350Sstevel@tonic-gate #include <sys/ddi_implfuncs.h>
360Sstevel@tonic-gate #include <sys/pci/pci_obj.h>
370Sstevel@tonic-gate #include <sys/pci.h>
381624Spjha #include <sys/pci_cap.h>
390Sstevel@tonic-gate
400Sstevel@tonic-gate /*LINTLIBRARY*/
410Sstevel@tonic-gate
420Sstevel@tonic-gate void
pcix_set_cmd_reg(dev_info_t * child,uint16_t value)430Sstevel@tonic-gate pcix_set_cmd_reg(dev_info_t *child, uint16_t value)
440Sstevel@tonic-gate {
451624Spjha uint16_t pcix_cap_ptr, pcix_cmd;
460Sstevel@tonic-gate ddi_acc_handle_t handle;
470Sstevel@tonic-gate
480Sstevel@tonic-gate if (pci_config_setup(child, &handle) != DDI_SUCCESS)
490Sstevel@tonic-gate return;
500Sstevel@tonic-gate
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate * Only modify the Command Register of non-bridge functions.
530Sstevel@tonic-gate */
541624Spjha if ((pci_config_get8(handle, PCI_CONF_HEADER) & PCI_HEADER_TYPE_M)
551624Spjha == PCI_HEADER_PPB)
561624Spjha goto teardown;
570Sstevel@tonic-gate
581624Spjha if (PCI_CAP_LOCATE(handle, PCI_CAP_ID_PCIX, &pcix_cap_ptr) ==
591624Spjha DDI_FAILURE)
601624Spjha goto teardown;
610Sstevel@tonic-gate
621624Spjha DEBUG1(DBG_INIT_CLD, child, "pcix_set_cmd_reg: pcix_cap_ptr = %x\n",
631624Spjha pcix_cap_ptr);
640Sstevel@tonic-gate
651624Spjha /*
661624Spjha * Read the PCI-X Command Register.
671624Spjha */
681624Spjha if ((pcix_cmd = PCI_CAP_GET16(handle, NULL, pcix_cap_ptr, 2))
69*1774Spjha == PCI_CAP_EINVAL16)
701624Spjha goto teardown;
710Sstevel@tonic-gate
721624Spjha DEBUG1(DBG_INIT_CLD, child, "pcix_set_cmd_reg: PCI-X CMD Register "
731624Spjha "(Before) %x\n", pcix_cmd);
740Sstevel@tonic-gate
751624Spjha pcix_cmd &= ~(0x1f << 2); /* clear bits 6-2 */
761624Spjha pcix_cmd |= value;
770Sstevel@tonic-gate
781624Spjha DEBUG1(DBG_INIT_CLD, child, "pcix_set_cmd_reg: PCI-X CMD Register "
791624Spjha "(After) %x\n", pcix_cmd);
800Sstevel@tonic-gate
811624Spjha PCI_CAP_PUT16(handle, NULL, pcix_cap_ptr, 2, pcix_cmd);
820Sstevel@tonic-gate
831624Spjha teardown:
840Sstevel@tonic-gate pci_config_teardown(&handle);
850Sstevel@tonic-gate }
86