1e3d60c9bSAdrian Frost /* 2e3d60c9bSAdrian Frost * CDDL HEADER START 3e3d60c9bSAdrian Frost * 4e3d60c9bSAdrian Frost * The contents of this file are subject to the terms of the 5e3d60c9bSAdrian Frost * Common Development and Distribution License (the "License"). 6e3d60c9bSAdrian Frost * You may not use this file except in compliance with the License. 7e3d60c9bSAdrian Frost * 8e3d60c9bSAdrian Frost * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9e3d60c9bSAdrian Frost * or http://www.opensolaris.org/os/licensing. 10e3d60c9bSAdrian Frost * See the License for the specific language governing permissions 11e3d60c9bSAdrian Frost * and limitations under the License. 12e3d60c9bSAdrian Frost * 13e3d60c9bSAdrian Frost * When distributing Covered Code, include this CDDL HEADER in each 14e3d60c9bSAdrian Frost * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15e3d60c9bSAdrian Frost * If applicable, add the following below this CDDL HEADER, with the 16e3d60c9bSAdrian Frost * fields enclosed by brackets "[]" replaced with your own identifying 17e3d60c9bSAdrian Frost * information: Portions Copyright [yyyy] [name of copyright owner] 18e3d60c9bSAdrian Frost * 19e3d60c9bSAdrian Frost * CDDL HEADER END 20e3d60c9bSAdrian Frost */ 21e3d60c9bSAdrian Frost 22e3d60c9bSAdrian Frost /* 23*e8ee2240SAdrian Frost * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24e3d60c9bSAdrian Frost * Use is subject to license terms. 25e3d60c9bSAdrian Frost */ 26e3d60c9bSAdrian Frost 27e3d60c9bSAdrian Frost #include <sys/types.h> 28e3d60c9bSAdrian Frost #include <sys/time.h> 29e3d60c9bSAdrian Frost #include <sys/nvpair.h> 30e3d60c9bSAdrian Frost #include <sys/cmn_err.h> 31e3d60c9bSAdrian Frost #include <sys/cred.h> 32e3d60c9bSAdrian Frost #include <sys/open.h> 33e3d60c9bSAdrian Frost #include <sys/ddi.h> 34e3d60c9bSAdrian Frost #include <sys/sunddi.h> 35e3d60c9bSAdrian Frost #include <sys/conf.h> 36e3d60c9bSAdrian Frost #include <sys/modctl.h> 37e3d60c9bSAdrian Frost #include <sys/cyclic.h> 38e3d60c9bSAdrian Frost #include <sys/errorq.h> 39e3d60c9bSAdrian Frost #include <sys/stat.h> 40e3d60c9bSAdrian Frost #include <sys/cpuvar.h> 41e3d60c9bSAdrian Frost #include <sys/mc_intel.h> 42e3d60c9bSAdrian Frost #include <sys/mc.h> 43e3d60c9bSAdrian Frost #include <sys/fm/protocol.h> 44e3d60c9bSAdrian Frost #include "nhm_log.h" 45e3d60c9bSAdrian Frost #include "intel_nhm.h" 46e3d60c9bSAdrian Frost 47e3d60c9bSAdrian Frost extern nvlist_t *inhm_mc_nvl[MAX_CPU_NODES]; 48e3d60c9bSAdrian Frost extern char closed_page; 49e3d60c9bSAdrian Frost extern char ecc_enabled; 50e3d60c9bSAdrian Frost extern char lockstep[MAX_CPU_NODES]; 51e3d60c9bSAdrian Frost extern char mirror_mode[MAX_CPU_NODES]; 52e3d60c9bSAdrian Frost extern char spare_channel[MAX_CPU_NODES]; 53e3d60c9bSAdrian Frost 54e3d60c9bSAdrian Frost static void 55e3d60c9bSAdrian Frost inhm_vrank(nvlist_t *vrank, int num, uint64_t dimm_base, uint64_t limit, 56e3d60c9bSAdrian Frost uint32_t sinterleave, uint32_t cinterleave, uint32_t rinterleave, 57e3d60c9bSAdrian Frost uint32_t sway, uint32_t cway, uint32_t rway) 58e3d60c9bSAdrian Frost { 59e3d60c9bSAdrian Frost char buf[128]; 60e3d60c9bSAdrian Frost 61e3d60c9bSAdrian Frost (void) snprintf(buf, sizeof (buf), "dimm-rank-base-%d", num); 62e3d60c9bSAdrian Frost (void) nvlist_add_uint64(vrank, buf, dimm_base); 63e3d60c9bSAdrian Frost (void) snprintf(buf, sizeof (buf), "dimm-rank-limit-%d", num); 64e3d60c9bSAdrian Frost (void) nvlist_add_uint64(vrank, buf, dimm_base + limit); 65e3d60c9bSAdrian Frost if (sinterleave > 1) { 66e3d60c9bSAdrian Frost (void) snprintf(buf, sizeof (buf), "dimm-socket-interleave-%d", 67e3d60c9bSAdrian Frost num); 68e3d60c9bSAdrian Frost (void) nvlist_add_uint32(vrank, buf, sinterleave); 69e3d60c9bSAdrian Frost (void) snprintf(buf, sizeof (buf), 70e3d60c9bSAdrian Frost "dimm-socket-interleave-way-%d", num); 71e3d60c9bSAdrian Frost (void) nvlist_add_uint32(vrank, buf, sway); 72e3d60c9bSAdrian Frost } 73e3d60c9bSAdrian Frost if (cinterleave > 1) { 74e3d60c9bSAdrian Frost (void) snprintf(buf, sizeof (buf), "dimm-channel-interleave-%d", 75e3d60c9bSAdrian Frost num); 76e3d60c9bSAdrian Frost (void) nvlist_add_uint32(vrank, buf, cinterleave); 77e3d60c9bSAdrian Frost (void) snprintf(buf, sizeof (buf), 78e3d60c9bSAdrian Frost "dimm-channel-interleave-way-%d", num); 79e3d60c9bSAdrian Frost (void) nvlist_add_uint32(vrank, buf, cway); 80e3d60c9bSAdrian Frost } 81e3d60c9bSAdrian Frost if (rinterleave > 1) { 82e3d60c9bSAdrian Frost (void) snprintf(buf, sizeof (buf), "dimm-rank-interleave-%d", 83e3d60c9bSAdrian Frost num); 84e3d60c9bSAdrian Frost (void) nvlist_add_uint32(vrank, buf, rinterleave); 85e3d60c9bSAdrian Frost (void) snprintf(buf, sizeof (buf), 86e3d60c9bSAdrian Frost "dimm-rank-interleave-way-%d", num); 87e3d60c9bSAdrian Frost (void) nvlist_add_uint32(vrank, buf, rway); 88e3d60c9bSAdrian Frost } 89e3d60c9bSAdrian Frost } 90e3d60c9bSAdrian Frost 91e3d60c9bSAdrian Frost static void 92e3d60c9bSAdrian Frost inhm_rank(nvlist_t *newdimm, nhm_dimm_t *nhm_dimm, uint32_t node, 93e3d60c9bSAdrian Frost uint8_t channel, uint32_t dimm, uint64_t rank_size) 94e3d60c9bSAdrian Frost { 95e3d60c9bSAdrian Frost nvlist_t **newrank; 96e3d60c9bSAdrian Frost int num; 97e3d60c9bSAdrian Frost int i; 98e3d60c9bSAdrian Frost uint64_t dimm_base; 99e3d60c9bSAdrian Frost uint64_t vrank_sz; 100e3d60c9bSAdrian Frost uint64_t rank_addr; 101e3d60c9bSAdrian Frost uint64_t pa; 102e3d60c9bSAdrian Frost uint32_t sinterleave, cinterleave, rinterleave; 103e3d60c9bSAdrian Frost uint32_t sway, cway, rway; 104e3d60c9bSAdrian Frost 105e3d60c9bSAdrian Frost newrank = kmem_zalloc(sizeof (nvlist_t *) * nhm_dimm->nranks, KM_SLEEP); 106e3d60c9bSAdrian Frost for (i = 0; i < nhm_dimm->nranks; i++) { 107e3d60c9bSAdrian Frost (void) nvlist_alloc(&newrank[i], NV_UNIQUE_NAME, KM_SLEEP); 108e3d60c9bSAdrian Frost rank_addr = 0; 109e3d60c9bSAdrian Frost num = 0; 110e3d60c9bSAdrian Frost while (rank_addr < rank_size) { 111e3d60c9bSAdrian Frost pa = dimm_to_addr(node, channel, dimm * 4 + i, 112e3d60c9bSAdrian Frost rank_addr, &dimm_base, &vrank_sz, &sinterleave, 113e3d60c9bSAdrian Frost &cinterleave, &rinterleave, &sway, &cway, &rway); 114*e8ee2240SAdrian Frost if (pa == -1 || vrank_sz == 0) 115e3d60c9bSAdrian Frost break; 116e3d60c9bSAdrian Frost inhm_vrank(newrank[i], num, dimm_base, 117e3d60c9bSAdrian Frost vrank_sz * sinterleave * cinterleave * rinterleave, 118e3d60c9bSAdrian Frost sinterleave, cinterleave, rinterleave, sway, cway, 119e3d60c9bSAdrian Frost rway); 120e3d60c9bSAdrian Frost rank_addr += vrank_sz; 121e3d60c9bSAdrian Frost num++; 122e3d60c9bSAdrian Frost } 123e3d60c9bSAdrian Frost 124e3d60c9bSAdrian Frost } 125e3d60c9bSAdrian Frost (void) nvlist_add_nvlist_array(newdimm, MCINTEL_NVLIST_RANKS, newrank, 126e3d60c9bSAdrian Frost nhm_dimm->nranks); 127e3d60c9bSAdrian Frost for (i = 0; i < nhm_dimm->nranks; i++) 128e3d60c9bSAdrian Frost nvlist_free(newrank[i]); 129e3d60c9bSAdrian Frost kmem_free(newrank, sizeof (nvlist_t *) * nhm_dimm->nranks); 130e3d60c9bSAdrian Frost } 131e3d60c9bSAdrian Frost 132e3d60c9bSAdrian Frost static nvlist_t * 133e3d60c9bSAdrian Frost inhm_dimm(nhm_dimm_t *nhm_dimm, uint32_t node, uint8_t channel, uint32_t dimm) 134e3d60c9bSAdrian Frost { 135e3d60c9bSAdrian Frost nvlist_t *newdimm; 136e3d60c9bSAdrian Frost uint8_t t; 137e3d60c9bSAdrian Frost char sbuf[65]; 138e3d60c9bSAdrian Frost 139e3d60c9bSAdrian Frost (void) nvlist_alloc(&newdimm, NV_UNIQUE_NAME, KM_SLEEP); 140e3d60c9bSAdrian Frost (void) nvlist_add_uint32(newdimm, "dimm-number", dimm); 141e3d60c9bSAdrian Frost 142e3d60c9bSAdrian Frost if (nhm_dimm->dimm_size >= 1024*1024*1024) { 143e3d60c9bSAdrian Frost (void) snprintf(sbuf, sizeof (sbuf), "%dG", 144e3d60c9bSAdrian Frost (int)(nhm_dimm->dimm_size / (1024*1024*1024))); 145e3d60c9bSAdrian Frost } else { 146e3d60c9bSAdrian Frost (void) snprintf(sbuf, sizeof (sbuf), "%dM", 147e3d60c9bSAdrian Frost (int)(nhm_dimm->dimm_size / (1024*1024))); 148e3d60c9bSAdrian Frost } 149e3d60c9bSAdrian Frost (void) nvlist_add_string(newdimm, "dimm-size", sbuf); 150e3d60c9bSAdrian Frost (void) nvlist_add_uint64(newdimm, "size", nhm_dimm->dimm_size); 151e3d60c9bSAdrian Frost (void) nvlist_add_uint32(newdimm, "nbanks", (uint32_t)nhm_dimm->nbanks); 152e3d60c9bSAdrian Frost (void) nvlist_add_uint32(newdimm, "ncolumn", 153e3d60c9bSAdrian Frost (uint32_t)nhm_dimm->ncolumn); 154e3d60c9bSAdrian Frost (void) nvlist_add_uint32(newdimm, "nrow", (uint32_t)nhm_dimm->nrow); 155e3d60c9bSAdrian Frost (void) nvlist_add_uint32(newdimm, "width", (uint32_t)nhm_dimm->width); 156e3d60c9bSAdrian Frost (void) nvlist_add_uint32(newdimm, "ranks", (uint32_t)nhm_dimm->nranks); 157e3d60c9bSAdrian Frost inhm_rank(newdimm, nhm_dimm, node, channel, dimm, 158e3d60c9bSAdrian Frost nhm_dimm->dimm_size / nhm_dimm->nranks); 159e3d60c9bSAdrian Frost if (nhm_dimm->manufacturer && nhm_dimm->manufacturer[0]) { 160e3d60c9bSAdrian Frost t = sizeof (nhm_dimm->manufacturer); 161e3d60c9bSAdrian Frost (void) strncpy(sbuf, nhm_dimm->manufacturer, t); 162e3d60c9bSAdrian Frost sbuf[t] = 0; 163e3d60c9bSAdrian Frost (void) nvlist_add_string(newdimm, "manufacturer", sbuf); 164e3d60c9bSAdrian Frost } 165e3d60c9bSAdrian Frost if (nhm_dimm->serial_number && nhm_dimm->serial_number[0]) { 166e3d60c9bSAdrian Frost t = sizeof (nhm_dimm->serial_number); 167e3d60c9bSAdrian Frost (void) strncpy(sbuf, nhm_dimm->serial_number, t); 168e3d60c9bSAdrian Frost sbuf[t] = 0; 169e3d60c9bSAdrian Frost (void) nvlist_add_string(newdimm, FM_FMRI_HC_SERIAL_ID, sbuf); 170e3d60c9bSAdrian Frost } 171e3d60c9bSAdrian Frost if (nhm_dimm->part_number && nhm_dimm->part_number[0]) { 172e3d60c9bSAdrian Frost t = sizeof (nhm_dimm->part_number); 173e3d60c9bSAdrian Frost (void) strncpy(sbuf, nhm_dimm->part_number, t); 174e3d60c9bSAdrian Frost sbuf[t] = 0; 175e3d60c9bSAdrian Frost (void) nvlist_add_string(newdimm, FM_FMRI_HC_PART, sbuf); 176e3d60c9bSAdrian Frost } 177e3d60c9bSAdrian Frost if (nhm_dimm->revision && nhm_dimm->revision[0]) { 178e3d60c9bSAdrian Frost t = sizeof (nhm_dimm->revision); 179e3d60c9bSAdrian Frost (void) strncpy(sbuf, nhm_dimm->revision, t); 180e3d60c9bSAdrian Frost sbuf[t] = 0; 181e3d60c9bSAdrian Frost (void) nvlist_add_string(newdimm, FM_FMRI_HC_REVISION, sbuf); 182e3d60c9bSAdrian Frost } 183e3d60c9bSAdrian Frost t = sizeof (nhm_dimm->label); 184e3d60c9bSAdrian Frost (void) strncpy(sbuf, nhm_dimm->label, t); 185e3d60c9bSAdrian Frost sbuf[t] = 0; 186e3d60c9bSAdrian Frost (void) nvlist_add_string(newdimm, FM_FAULT_FRU_LABEL, sbuf); 187e3d60c9bSAdrian Frost return (newdimm); 188e3d60c9bSAdrian Frost } 189e3d60c9bSAdrian Frost 190e3d60c9bSAdrian Frost static void 191e3d60c9bSAdrian Frost inhm_dimmlist(uint32_t node, nvlist_t *nvl) 192e3d60c9bSAdrian Frost { 193e3d60c9bSAdrian Frost nvlist_t **dimmlist; 194e3d60c9bSAdrian Frost nvlist_t **newchannel; 195e3d60c9bSAdrian Frost int nchannels = CHANNELS_PER_MEMORY_CONTROLLER; 196e3d60c9bSAdrian Frost int nd; 197e3d60c9bSAdrian Frost uint8_t i, j; 198e3d60c9bSAdrian Frost nhm_dimm_t **dimmpp; 199e3d60c9bSAdrian Frost nhm_dimm_t *dimmp; 200e3d60c9bSAdrian Frost 201e3d60c9bSAdrian Frost dimmlist = kmem_zalloc(sizeof (nvlist_t *) * MAX_DIMMS_PER_CHANNEL, 202e3d60c9bSAdrian Frost KM_SLEEP); 203e3d60c9bSAdrian Frost newchannel = kmem_zalloc(sizeof (nvlist_t *) * nchannels, KM_SLEEP); 204e3d60c9bSAdrian Frost dimmpp = &nhm_dimms[node * CHANNELS_PER_MEMORY_CONTROLLER * 205e3d60c9bSAdrian Frost MAX_DIMMS_PER_CHANNEL]; 206e3d60c9bSAdrian Frost (void) nvlist_add_string(nvl, "memory-policy", 207e3d60c9bSAdrian Frost closed_page ? "closed-page" : "open-page"); 208e3d60c9bSAdrian Frost (void) nvlist_add_string(nvl, "memory-ecc", 209e3d60c9bSAdrian Frost ecc_enabled ? lockstep[node] ? "x8" : "x4" : "no"); 210e3d60c9bSAdrian Frost for (i = 0; i < nchannels; i++) { 211e3d60c9bSAdrian Frost (void) nvlist_alloc(&newchannel[i], NV_UNIQUE_NAME, KM_SLEEP); 212e3d60c9bSAdrian Frost (void) nvlist_add_string(newchannel[i], "channel-mode", 213e3d60c9bSAdrian Frost CHANNEL_DISABLED(MC_STATUS_RD(node), i) ? "disabled" : 214e3d60c9bSAdrian Frost i != 2 && lockstep[node] ? "lockstep" : 215e3d60c9bSAdrian Frost i != 2 && mirror_mode[node] ? 216e3d60c9bSAdrian Frost REDUNDANCY_LOSS(MC_RAS_STATUS_RD(node)) ? 217e3d60c9bSAdrian Frost "redundancy-loss" : "mirror" : 218e3d60c9bSAdrian Frost i == 2 && spare_channel[node] && 219e3d60c9bSAdrian Frost !REDUNDANCY_LOSS(MC_RAS_STATUS_RD(node)) ? "spare" : 220e3d60c9bSAdrian Frost "independent"); 221e3d60c9bSAdrian Frost nd = 0; 222e3d60c9bSAdrian Frost for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) { 223e3d60c9bSAdrian Frost dimmp = *dimmpp; 224e3d60c9bSAdrian Frost if (dimmp != NULL) { 225e3d60c9bSAdrian Frost dimmlist[nd] = inhm_dimm(dimmp, node, i, 226e3d60c9bSAdrian Frost (uint32_t)j); 227e3d60c9bSAdrian Frost nd++; 228e3d60c9bSAdrian Frost } 229e3d60c9bSAdrian Frost dimmpp++; 230e3d60c9bSAdrian Frost } 231e3d60c9bSAdrian Frost if (nd) { 232e3d60c9bSAdrian Frost (void) nvlist_add_nvlist_array(newchannel[i], 233e3d60c9bSAdrian Frost "memory-dimms", dimmlist, nd); 234e3d60c9bSAdrian Frost for (j = 0; j < nd; j++) 235e3d60c9bSAdrian Frost nvlist_free(dimmlist[j]); 236e3d60c9bSAdrian Frost } 237e3d60c9bSAdrian Frost } 238e3d60c9bSAdrian Frost (void) nvlist_add_nvlist_array(nvl, MCINTEL_NVLIST_MC, newchannel, 239e3d60c9bSAdrian Frost nchannels); 240e3d60c9bSAdrian Frost for (i = 0; i < nchannels; i++) 241e3d60c9bSAdrian Frost nvlist_free(newchannel[i]); 242e3d60c9bSAdrian Frost kmem_free(dimmlist, sizeof (nvlist_t *) * MAX_DIMMS_PER_CHANNEL); 243e3d60c9bSAdrian Frost kmem_free(newchannel, sizeof (nvlist_t *) * nchannels); 244e3d60c9bSAdrian Frost } 245e3d60c9bSAdrian Frost 246e3d60c9bSAdrian Frost char * 247e3d60c9bSAdrian Frost inhm_mc_name() 248e3d60c9bSAdrian Frost { 249ee9ef9e5SAdrian Frost return (NHM_INTERCONNECT); 250e3d60c9bSAdrian Frost } 251e3d60c9bSAdrian Frost 252e3d60c9bSAdrian Frost void 253e3d60c9bSAdrian Frost inhm_create_nvl(int chip) 254e3d60c9bSAdrian Frost { 255e3d60c9bSAdrian Frost nvlist_t *nvl; 256e3d60c9bSAdrian Frost 257e3d60c9bSAdrian Frost (void) nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_SLEEP); 258e3d60c9bSAdrian Frost (void) nvlist_add_uint8(nvl, MCINTEL_NVLIST_VERSTR, 259e3d60c9bSAdrian Frost MCINTEL_NVLIST_VERS); 260e3d60c9bSAdrian Frost (void) nvlist_add_string(nvl, MCINTEL_NVLIST_MEM, inhm_mc_name()); 261e3d60c9bSAdrian Frost (void) nvlist_add_uint8(nvl, MCINTEL_NVLIST_NMEM, 1); 262e3d60c9bSAdrian Frost (void) nvlist_add_uint8(nvl, MCINTEL_NVLIST_NRANKS, 4); 263e3d60c9bSAdrian Frost inhm_dimmlist(chip, nvl); 264e3d60c9bSAdrian Frost 265e3d60c9bSAdrian Frost if (inhm_mc_nvl[chip]) 266e3d60c9bSAdrian Frost nvlist_free(inhm_mc_nvl[chip]); 267e3d60c9bSAdrian Frost inhm_mc_nvl[chip] = nvl; 268e3d60c9bSAdrian Frost } 269