7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm * Common Development and Distribution License (the "License").
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm * You may not use this file except in compliance with the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * or http://www.opensolaris.org/os/licensing.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * When distributing Covered Code, include this CDDL HEADER in each
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If applicable, add the following below this CDDL HEADER, with the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * fields enclosed by brackets "[]" replaced with your own identifying
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * information: Portions Copyright [yyyy] [name of copyright owner]
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER END
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesan * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <sys/types.h>
fb2f18f820d90b001aea4fb27dd654bc1263c440esaxe#include <sys/pghw.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <sys/cmn_err.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <sys/sysmacros.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <sys/fm/protocol.h>
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm#include <sys/x86_archext.h>
20c794b39650d115e17a15983b6b82e46238cf45gavinm#include <sys/pci_cfgspace.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include "ao.h"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * AMD Opteron CPU Subroutines
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
20c794b39650d115e17a15983b6b82e46238cf45gavinm * The following two tunables are used to determine the scrubbing rates for
20c794b39650d115e17a15983b6b82e46238cf45gavinm * the D$ and L2$. The values range from 0x00-0x16 as described in BKDG
20c794b39650d115e17a15983b6b82e46238cf45gavinm * Scrub Control Register. A value of zero disables the scrubber. Values
20c794b39650d115e17a15983b6b82e46238cf45gavinm * above zero indicate rates in descending order.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The current default values are used on several Sun systems. In the future
20c794b39650d115e17a15983b6b82e46238cf45gavinm * this code should assign values dynamically based on cache sizing. If you
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * tune these values manually be aware of the following architectural issue:
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * At present, Opteron can only survive certain kinds of multi-bit errors if
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * they are detected by the scrubbers. Therefore in general we want these
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * values tuned as high as possible without impacting workload performance.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiuint32_t ao_scrub_rate_dcache = 8; /* 64B every 5.12 us */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiuint32_t ao_scrub_rate_l2cache = 9; /* 64B every 10.2 us */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindienum {
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm AO_SCRUB_BIOSDEFAULT, /* retain system default values */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi AO_SCRUB_FIXED, /* assign ao_scrub_rate_* values */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi AO_SCRUB_MAX /* assign max of system and tunables */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi} ao_scrub_policy = AO_SCRUB_MAX;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
20c794b39650d115e17a15983b6b82e46238cf45gavinmvoid
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesanao_pcicfg_write(uint_t procnodeid, uint_t func, uint_t reg, uint32_t val)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesan ASSERT(procnodeid + 24 <= 31);
20c794b39650d115e17a15983b6b82e46238cf45gavinm ASSERT((func & 7) == func);
20c794b39650d115e17a15983b6b82e46238cf45gavinm ASSERT((reg & 3) == 0 && reg < 256);
20c794b39650d115e17a15983b6b82e46238cf45gavinm
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesan cmi_pci_putl(0, procnodeid + 24, func, reg, 0, val);
20c794b39650d115e17a15983b6b82e46238cf45gavinm}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
20c794b39650d115e17a15983b6b82e46238cf45gavinmuint32_t
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesanao_pcicfg_read(uint_t procnodeid, uint_t func, uint_t reg)
20c794b39650d115e17a15983b6b82e46238cf45gavinm{
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesan ASSERT(procnodeid + 24 <= 31);
20c794b39650d115e17a15983b6b82e46238cf45gavinm ASSERT((func & 7) == func);
20c794b39650d115e17a15983b6b82e46238cf45gavinm ASSERT((reg & 3) == 0 && reg < 256);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesan return (cmi_pci_getl(0, procnodeid + 24, func, reg, 0, 0));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
20c794b39650d115e17a15983b6b82e46238cf45gavinm
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Return the maximum scrubbing rate between r1 and r2, where r2 is extracted
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * from the specified 'cfg' register value using 'mask' and 'shift'. If a
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * value is zero, scrubbing is off so return the opposite value. Otherwise
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * the maximum rate is the smallest non-zero value of the two values.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic uint32_t
20c794b39650d115e17a15983b6b82e46238cf45gavinmao_scrubber_max(uint32_t r1, uint32_t r2)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (r1 != 0 && r2 != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (MIN(r1, r2));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (r1 ? r1 : r2);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesan * Enable the node-specific hardware scrubbers for the D$ and L2$. We set
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * the scrubber rate based on a set of tunables defined at the top of the file.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
20c794b39650d115e17a15983b6b82e46238cf45gavinmvoid
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesanao_procnode_scrubber_enable(cmi_hdl_t hdl, ao_ms_data_t *ao)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesan uint_t procnodeid = cmi_hdl_procnodeid(hdl);
20c794b39650d115e17a15983b6b82e46238cf45gavinm union mcreg_scrubctl scrubctl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
20c794b39650d115e17a15983b6b82e46238cf45gavinm ao->ao_ms_shared->aos_bcfg_scrubctl = MCREG_VAL32(&scrubctl) =
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesan ao_pcicfg_read(procnodeid, MC_FUNC_MISCCTL, MC_CTL_REG_SCRUBCTL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
20c794b39650d115e17a15983b6b82e46238cf45gavinm if (ao_scrub_policy == AO_SCRUB_BIOSDEFAULT)
20c794b39650d115e17a15983b6b82e46238cf45gavinm return;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (ao_scrub_rate_dcache > AMD_NB_SCRUBCTL_RATE_MAX) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi cmn_err(CE_WARN, "ao_scrub_rate_dcache is too large; "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "resetting to 0x%x\n", AMD_NB_SCRUBCTL_RATE_MAX);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi ao_scrub_rate_dcache = AMD_NB_SCRUBCTL_RATE_MAX;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (ao_scrub_rate_l2cache > AMD_NB_SCRUBCTL_RATE_MAX) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi cmn_err(CE_WARN, "ao_scrub_rate_l2cache is too large; "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "resetting to 0x%x\n", AMD_NB_SCRUBCTL_RATE_MAX);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi ao_scrub_rate_l2cache = AMD_NB_SCRUBCTL_RATE_MAX;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm switch (ao_scrub_policy) {
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm case AO_SCRUB_FIXED:
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm /* Use the system values checked above */
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm break;
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm default:
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm cmn_err(CE_WARN, "Unknown ao_scrub_policy value %d - "
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm "using default policy of AO_SCRUB_MAX", ao_scrub_policy);
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm /*FALLTHRU*/
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm case AO_SCRUB_MAX:
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi ao_scrub_rate_dcache =
20c794b39650d115e17a15983b6b82e46238cf45gavinm ao_scrubber_max(ao_scrub_rate_dcache,
20c794b39650d115e17a15983b6b82e46238cf45gavinm MCREG_FIELD_CMN(&scrubctl, DcacheScrub));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi ao_scrub_rate_l2cache =
20c794b39650d115e17a15983b6b82e46238cf45gavinm ao_scrubber_max(ao_scrub_rate_l2cache,
20c794b39650d115e17a15983b6b82e46238cf45gavinm MCREG_FIELD_CMN(&scrubctl, L2Scrub));
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm break;
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm }
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm
20c794b39650d115e17a15983b6b82e46238cf45gavinm MCREG_FIELD_CMN(&scrubctl, DcacheScrub) = ao_scrub_rate_dcache;
20c794b39650d115e17a15983b6b82e46238cf45gavinm MCREG_FIELD_CMN(&scrubctl, L2Scrub) = ao_scrub_rate_l2cache;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
8031591d3cc3c82e97f4b60ea22d671525077b15Srihari Venkatesan ao_pcicfg_write(procnodeid, MC_FUNC_MISCCTL, MC_CTL_REG_SCRUBCTL,
20c794b39650d115e17a15983b6b82e46238cf45gavinm MCREG_VAL32(&scrubctl));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}