11414Scindi /*
21414Scindi * CDDL HEADER START
31414Scindi *
41414Scindi * The contents of this file are subject to the terms of the
52869Sgavinm * Common Development and Distribution License (the "License").
62869Sgavinm * You may not use this file except in compliance with the License.
71414Scindi *
81414Scindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91414Scindi * or http://www.opensolaris.org/os/licensing.
101414Scindi * See the License for the specific language governing permissions
111414Scindi * and limitations under the License.
121414Scindi *
131414Scindi * When distributing Covered Code, include this CDDL HEADER in each
141414Scindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151414Scindi * If applicable, add the following below this CDDL HEADER, with the
161414Scindi * fields enclosed by brackets "[]" replaced with your own identifying
171414Scindi * information: Portions Copyright [yyyy] [name of copyright owner]
181414Scindi *
191414Scindi * CDDL HEADER END
201414Scindi */
211414Scindi
221414Scindi /*
23*10947SSrihari.Venkatesan@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
241414Scindi * Use is subject to license terms.
251414Scindi */
261414Scindi
271414Scindi #include <sys/types.h>
283434Sesaxe #include <sys/pghw.h>
291414Scindi #include <sys/cmn_err.h>
301414Scindi #include <sys/sysmacros.h>
311414Scindi #include <sys/fm/protocol.h>
322869Sgavinm #include <sys/x86_archext.h>
335254Sgavinm #include <sys/pci_cfgspace.h>
341414Scindi
351414Scindi #include "ao.h"
361414Scindi
371414Scindi /*
381414Scindi * AMD Opteron CPU Subroutines
391414Scindi *
405254Sgavinm * The following two tunables are used to determine the scrubbing rates for
415254Sgavinm * the D$ and L2$. The values range from 0x00-0x16 as described in BKDG
425254Sgavinm * Scrub Control Register. A value of zero disables the scrubber. Values
435254Sgavinm * above zero indicate rates in descending order.
441414Scindi *
451414Scindi * The current default values are used on several Sun systems. In the future
465254Sgavinm * this code should assign values dynamically based on cache sizing. If you
471414Scindi * tune these values manually be aware of the following architectural issue:
481414Scindi * At present, Opteron can only survive certain kinds of multi-bit errors if
491414Scindi * they are detected by the scrubbers. Therefore in general we want these
501414Scindi * values tuned as high as possible without impacting workload performance.
511414Scindi */
521414Scindi uint32_t ao_scrub_rate_dcache = 8; /* 64B every 5.12 us */
531414Scindi uint32_t ao_scrub_rate_l2cache = 9; /* 64B every 10.2 us */
541414Scindi
551414Scindi enum {
562869Sgavinm AO_SCRUB_BIOSDEFAULT, /* retain system default values */
571414Scindi AO_SCRUB_FIXED, /* assign ao_scrub_rate_* values */
581414Scindi AO_SCRUB_MAX /* assign max of system and tunables */
591414Scindi } ao_scrub_policy = AO_SCRUB_MAX;
601414Scindi
615254Sgavinm void
ao_pcicfg_write(uint_t procnodeid,uint_t func,uint_t reg,uint32_t val)62*10947SSrihari.Venkatesan@Sun.COM ao_pcicfg_write(uint_t procnodeid, uint_t func, uint_t reg, uint32_t val)
631414Scindi {
64*10947SSrihari.Venkatesan@Sun.COM ASSERT(procnodeid + 24 <= 31);
655254Sgavinm ASSERT((func & 7) == func);
665254Sgavinm ASSERT((reg & 3) == 0 && reg < 256);
675254Sgavinm
68*10947SSrihari.Venkatesan@Sun.COM cmi_pci_putl(0, procnodeid + 24, func, reg, 0, val);
695254Sgavinm }
701414Scindi
715254Sgavinm uint32_t
ao_pcicfg_read(uint_t procnodeid,uint_t func,uint_t reg)72*10947SSrihari.Venkatesan@Sun.COM ao_pcicfg_read(uint_t procnodeid, uint_t func, uint_t reg)
735254Sgavinm {
74*10947SSrihari.Venkatesan@Sun.COM ASSERT(procnodeid + 24 <= 31);
755254Sgavinm ASSERT((func & 7) == func);
765254Sgavinm ASSERT((reg & 3) == 0 && reg < 256);
771414Scindi
78*10947SSrihari.Venkatesan@Sun.COM return (cmi_pci_getl(0, procnodeid + 24, func, reg, 0, 0));
791414Scindi }
801414Scindi
815254Sgavinm
821414Scindi /*
831414Scindi * Return the maximum scrubbing rate between r1 and r2, where r2 is extracted
841414Scindi * from the specified 'cfg' register value using 'mask' and 'shift'. If a
851414Scindi * value is zero, scrubbing is off so return the opposite value. Otherwise
861414Scindi * the maximum rate is the smallest non-zero value of the two values.
871414Scindi */
881414Scindi static uint32_t
ao_scrubber_max(uint32_t r1,uint32_t r2)895254Sgavinm ao_scrubber_max(uint32_t r1, uint32_t r2)
901414Scindi {
911414Scindi if (r1 != 0 && r2 != 0)
921414Scindi return (MIN(r1, r2));
931414Scindi
941414Scindi return (r1 ? r1 : r2);
951414Scindi }
961414Scindi
971414Scindi /*
98*10947SSrihari.Venkatesan@Sun.COM * Enable the node-specific hardware scrubbers for the D$ and L2$. We set
991414Scindi * the scrubber rate based on a set of tunables defined at the top of the file.
1001414Scindi */
1015254Sgavinm void
ao_procnode_scrubber_enable(cmi_hdl_t hdl,ao_ms_data_t * ao)102*10947SSrihari.Venkatesan@Sun.COM ao_procnode_scrubber_enable(cmi_hdl_t hdl, ao_ms_data_t *ao)
1031414Scindi {
104*10947SSrihari.Venkatesan@Sun.COM uint_t procnodeid = cmi_hdl_procnodeid(hdl);
1055254Sgavinm union mcreg_scrubctl scrubctl;
1061414Scindi
1075254Sgavinm ao->ao_ms_shared->aos_bcfg_scrubctl = MCREG_VAL32(&scrubctl) =
108*10947SSrihari.Venkatesan@Sun.COM ao_pcicfg_read(procnodeid, MC_FUNC_MISCCTL, MC_CTL_REG_SCRUBCTL);
1091414Scindi
1102869Sgavinm if (ao_scrub_policy == AO_SCRUB_BIOSDEFAULT)
1115254Sgavinm return;
1121414Scindi
1131414Scindi if (ao_scrub_rate_dcache > AMD_NB_SCRUBCTL_RATE_MAX) {
1141414Scindi cmn_err(CE_WARN, "ao_scrub_rate_dcache is too large; "
1151414Scindi "resetting to 0x%x\n", AMD_NB_SCRUBCTL_RATE_MAX);
1161414Scindi ao_scrub_rate_dcache = AMD_NB_SCRUBCTL_RATE_MAX;
1171414Scindi }
1181414Scindi
1191414Scindi if (ao_scrub_rate_l2cache > AMD_NB_SCRUBCTL_RATE_MAX) {
1201414Scindi cmn_err(CE_WARN, "ao_scrub_rate_l2cache is too large; "
1211414Scindi "resetting to 0x%x\n", AMD_NB_SCRUBCTL_RATE_MAX);
1221414Scindi ao_scrub_rate_l2cache = AMD_NB_SCRUBCTL_RATE_MAX;
1231414Scindi }
1241414Scindi
1252869Sgavinm switch (ao_scrub_policy) {
1262869Sgavinm case AO_SCRUB_FIXED:
1272869Sgavinm /* Use the system values checked above */
1282869Sgavinm break;
1292869Sgavinm
1302869Sgavinm default:
1312869Sgavinm cmn_err(CE_WARN, "Unknown ao_scrub_policy value %d - "
1322869Sgavinm "using default policy of AO_SCRUB_MAX", ao_scrub_policy);
1332869Sgavinm /*FALLTHRU*/
1342869Sgavinm
1352869Sgavinm case AO_SCRUB_MAX:
1361414Scindi ao_scrub_rate_dcache =
1375254Sgavinm ao_scrubber_max(ao_scrub_rate_dcache,
1385254Sgavinm MCREG_FIELD_CMN(&scrubctl, DcacheScrub));
1391414Scindi
1401414Scindi ao_scrub_rate_l2cache =
1415254Sgavinm ao_scrubber_max(ao_scrub_rate_l2cache,
1425254Sgavinm MCREG_FIELD_CMN(&scrubctl, L2Scrub));
1432869Sgavinm break;
1441414Scindi }
1451414Scindi
1465254Sgavinm MCREG_FIELD_CMN(&scrubctl, DcacheScrub) = ao_scrub_rate_dcache;
1475254Sgavinm MCREG_FIELD_CMN(&scrubctl, L2Scrub) = ao_scrub_rate_l2cache;
1482869Sgavinm
149*10947SSrihari.Venkatesan@Sun.COM ao_pcicfg_write(procnodeid, MC_FUNC_MISCCTL, MC_CTL_REG_SCRUBCTL,
1505254Sgavinm MCREG_VAL32(&scrubctl));
1511414Scindi }
152