From patchwork Thu May 14 22:51:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 472545 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 746C8140B0E for ; Fri, 15 May 2015 08:51:49 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b=E57h6gds; dkim-atps=neutral Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 541C81A0484 for ; Fri, 15 May 2015 08:51:49 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b=E57h6gds; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-ig0-x22d.google.com (mail-ig0-x22d.google.com [IPv6:2607:f8b0:4001:c05::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 66A811A0468 for ; Fri, 15 May 2015 08:51:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b=E57h6gds; dkim-atps=neutral Received: by igbhj9 with SMTP id hj9so86354720igb.1 for ; Thu, 14 May 2015 15:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id; bh=bRojU7AJTZ37UZaSIKZ8Jvbx2efvHaHuYxvXWktIrc4=; b=E57h6gdsm3jUgaNcZjrEquQi1DZ+oBL5n8XPC4IJ5J3HUAPwKhuchM9/LIPqEDIw9L 1cbIzbaztby+CHlgOOSJnTBrRtGr9TvB5TE+tM2Q/Ji2Z4j6eU3DoYoh9Cl1E9CapO3O 3oVBaTlY76qvi/jeJDcJmIpd77hUeCQhDMAuY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bRojU7AJTZ37UZaSIKZ8Jvbx2efvHaHuYxvXWktIrc4=; b=Uogc5o6HjlibDL8M0a/LpTK7PYXdnwY/yMZQl9kGMvi6b4ROIsWs4aeJBAhBiZYhsx qJzK/iMIQADSA1wKthSWnzez1FglbL6SEDDLLdlSeth53UeJGpQqtld4PDIPmGt4DNGq PO7znJwMePieAruM9jghdu+BIdjWCxIW/PnyBnQJ8qIytuQVFAkhYKM0Z91p1inQMaeh F+qF4s75Jk25AAIRiF59os9SD/qStOhMy1dKl6sAmmM8hUiStqQ/bAfjO7bIgrAfEmtY ucf0yPTeEVszlXDwU609bFmoGEDA0bhQX6Tvky4nf3cPh/UIDa+Ji+OXXIcxSbszdX3u x5yQ== X-Gm-Message-State: ALoCoQkqQwdageoONUFMEl2ESrqrK+/faDXPe7Te1tn0ZwRtPjEI0DUqCkb+IaDLyIGf/1EVE/Lm X-Received: by 10.68.115.42 with SMTP id jl10mr12570826pbb.39.1431643900260; Thu, 14 May 2015 15:51:40 -0700 (PDT) Received: from gamma.ozlabs.ibm.com ([122.99.82.10]) by mx.google.com with ESMTPSA id df7sm219667pdb.32.2015.05.14.15.51.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 May 2015 15:51:39 -0700 (PDT) From: Daniel Axtens To: skiboot@lists.ozlabs.org Date: Fri, 15 May 2015 08:51:08 +1000 Message-Id: <1431643868-5581-1-git-send-email-dja@axtens.net> X-Mailer: git-send-email 2.1.4 Subject: [Skiboot] [PATCH] Add -Tn to ibm,loc-code for ethernet adaptors X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" On pHyp, the location code of ethernet adaptors ends with -Tn, where n is the port number on the card. Detect if an adaptor advertises itself as ethernet based on it's PCI class code, and if it does, give each PCI function a -Tn suffix, where n = function number + 1. (Therefore n is between 1 and 8 inclusive) This is a reasonably non-invasive change to match pHyp behaviour. Alternatives considered were: - putting this in kernel space, which requires messing with the device tree, which is frowned upon. - putting this in user space, which requires patching every userspace tool that might consume this data, of which there are several. As such, while it's a bit of a hack, this is the best place for it. Signed-off-by: Daniel Axtens --- core/pci.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/core/pci.c b/core/pci.c index 8ea9177..477f806 100644 --- a/core/pci.c +++ b/core/pci.c @@ -1145,10 +1145,14 @@ static void pci_add_slot_properties(struct phb *phb, struct pci_slot_info *info, dt_add_property_string(np, "ibm,slot-label", info->label); } -static void pci_add_loc_code(struct dt_node *np) +static void pci_add_loc_code(struct dt_node *np, struct pci_device *pd) { struct dt_node *p = np->parent; const char *blcode = NULL; + char *lcode; + uint32_t class_code; + uint8_t class, sub; + uint8_t pos, len; /* Look for a parent with a slot-location-code */ while (p && !blcode) { @@ -1157,7 +1161,31 @@ static void pci_add_loc_code(struct dt_node *np) } if (!blcode) return; - dt_add_property_string(np, "ibm,loc-code", blcode); + + /* ethernet devices get port codes */ + class_code = dt_prop_get_u32(np, "class-code"); + class = class_code >> 16; + sub = (class_code >> 8) & 0xff; + if (class == 0x02 && sub == 0x00) { + /* There's usually several spaces at the end of the property. + Test for, but don't rely on, that being the case */ + len = strlen(blcode); + for (pos = 0; pos < len; pos++) + if (blcode[pos] == ' ') break; + if (pos + 3 < len) + lcode = strdup(blcode); + else { + lcode = malloc(pos + 3); + memcpy(lcode, blcode, len); + } + lcode[pos++] = '-'; + lcode[pos++] = 'T'; + lcode[pos++] = (char)(pd->bdfn & 0x7) + '1'; + lcode[pos++] = '\0'; + dt_add_property_string(np, "ibm,loc-code", lcode); + free(lcode); + } else + dt_add_property_string(np, "ibm,loc-code", blcode); } static void pci_print_summary_line(struct phb *phb, struct pci_device *pd, @@ -1288,7 +1316,7 @@ static void pci_add_one_node(struct phb *phb, struct pci_device *pd, pci_add_slot_properties(phb, pd->slot_info, np); /* Make up location code */ - pci_add_loc_code(np); + pci_add_loc_code(np, pd); /* XXX FIXME: We don't look for BARs, we only put the config space * entry in the "reg" property. That's enough for Linux and we might