From patchwork Tue Sep 24 00:06:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Hutter X-Patchwork-Id: 13810010 X-Patchwork-Delegate: bhelgaas@google.com Received: from mx0f-00379502.gpphosted.com (mx0f-00379502.gpphosted.com [67.231.155.129]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B6CE38C; Tue, 24 Sep 2024 00:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=67.231.155.129 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727136559; cv=fail; b=HcADUl1bjoZ1OevMRDtf8NSYCyU/Jsx1p7JswQg+h+/GLhYFe6Zo6tIxMiUPcMdSdXKwhVl5+tv5GGkjuAkhaVgyUdIFm3SsuJPs5uTLEvJPbXdBK+lI+WZSbepv24kDikFDZvSJggbGBe7779o7KCr80zk7KJzLyaAvcNI2Nc0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727136559; c=relaxed/simple; bh=qBRSIJUpibUKDQYK0O4h5/7EM1ur+DFd7W2GIjnthIM=; h=Message-ID:Date:From:Subject:To:Cc:Content-Type:MIME-Version; b=LeLjiJFqEoNsq/9dYbvPjL26Aw1d8+80mYWxWFOWNTUkWkNVqyDPE6hy6f7Zx/csXzf2H6cxVq3PQdc5HrF3Mzp8MKjNR9z7bckLsGFRWjGfs1QZaUspB/l2dGuYOtxSBqwIXefuMi6EDWFBb6MTeQHML77YAX+TAfDvsDwKRNE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=llnl.gov; spf=pass smtp.mailfrom=llnl.gov; dkim=pass (2048-bit key) header.d=llnl.gov header.i=@llnl.gov header.b=F0fOCprM; dkim=pass (1024-bit key) header.d=doellnl.onmicrosoft.com header.i=@doellnl.onmicrosoft.com header.b=Ss6tMgkJ; arc=fail smtp.client-ip=67.231.155.129 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=llnl.gov Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=llnl.gov Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=llnl.gov header.i=@llnl.gov header.b="F0fOCprM"; dkim=pass (1024-bit key) header.d=doellnl.onmicrosoft.com header.i=@doellnl.onmicrosoft.com header.b="Ss6tMgkJ" Received: from pps.filterd (m0422210.ppops.net [127.0.0.1]) by mx0f-00379502.gpphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NN7XNv016491; Mon, 23 Sep 2024 17:06:11 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=llnl.gov; h=message-id : date : from : subject : to : cc : content-type : content-transfer-encoding : mime-version; s=02022021-podllnl; bh=7c0irPOi9NGi2Ay7F/8w8ZZ1S736dq7ifNm8fjriH/8=; b=F0fOCprMStfmwmnRcEGYfGgVRJDvI4TOaxgAFtTVyVlx7y5IiB65Az+IycRaAJw7H9cS +H5T6GhQvxgIgIWr1FpK685Y01GaumJqYtZtcxeTRdCaY3OvxhdylpzcxcOOsDcECIXY a+aG6LUaVmFpsaJ0ad5PYOinGBycyoxyt8dm//OPBvN5xaUqlcEjbUnoMiE8IjY8e9qb DE6ax/c3PmlHEr2RevCcA9WiHvEkvAmpZLHQ7TWCvW56zqyrTXVlEz+NAJTLz03gOfwF JSTOxWvTQKb2wZ5ZOZMcfLdSWRNeYaK6j6zPazVOiz+lIaa1/TwfzQpKfeYVN108vnZY +A== Received: from sa9pr09cu002.outbound.protection.outlook.com (mail-southcentralusazlp17010022.outbound.protection.outlook.com [40.93.14.22]) by mx0f-00379502.gpphosted.com (PPS) with ESMTPS id 41u6qqhq0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 17:06:10 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gjFVi6Ui/s40RT98hYGfLbjkorQzrL0lRfOqdyRTHLlOP7Wk5I8WUeRPy7R6zHWMOdT9BdwDG9T0e6omYnV7Los+YrTiTNyH32KSPTt4BI/+7eJAjdx7PJTA1zNnT7YYVZhL5bvDy6hxE0UvIAvqnXoLtsdCDSwEPt3QFchPuvURaENnBx0H9WtcaSlOC1Gu+nnSC7f7vlnBppXl88VL3hVV6U70V10lUCi3UETTpiVNTI7Iu2J7ca8fEzoxLHp8mEPAUx6FSZWO9sGDj6bUeNutvPU3rqBq8/ltnoLqHgeI6uj1Ge35MNaVW6SjztTOAIplMYHcGc/P8H/1GeSgzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7c0irPOi9NGi2Ay7F/8w8ZZ1S736dq7ifNm8fjriH/8=; b=tc5IIrmxaPf8wZvzXCgDr+dXvg/oSMpMOYY/HCRPToPwcy/pN4eGC73dSpLN5k1k84OpGa/f9HbmeSPUXGouf9wZm3IYrhCHHUNYSLXlWBk1VIAgzlmHpll36SzSVLRcfVjbevJW9jrmKApJhCKOUFxoZNsdoAr/JuTY5at23Ap0vx0DpOxnUvq337xMZrW/YWyfhyl83HbXdqAUVcd/2sZIQ+rlItjM4EAI4k8qV+jfuzZFkrvlG/JZ32U9glTc5ePwZ0/knVW9c9Cqy2Mcdiuy9ZHfr+Jf1FUq0FHb43t2s0r1VMKUj8Wu+nd6UDmu6K5+1akAU/XQfqQ5oHNazQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=llnl.gov; dmarc=pass action=none header.from=llnl.gov; dkim=pass header.d=llnl.gov; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=doellnl.onmicrosoft.com; s=selector1-doellnl-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7c0irPOi9NGi2Ay7F/8w8ZZ1S736dq7ifNm8fjriH/8=; b=Ss6tMgkJMD5biq13moUjq2744QOb8+bgjEAtEUygp1k6AALO/9RB14O5txiWL6MS0FeIrUH31Esls8JbKZyA2OegAAd065CBNu+2z/3ILKldncIVt3cYM4LH1vNhqCluiLm2N1MHOnf8nLD3bob1+MF0KPi1KOHKnaIMvlSpT00= Received: from BY3PR09MB8834.namprd09.prod.outlook.com (2603:10b6:a03:346::22) by SJ0PR09MB11459.namprd09.prod.outlook.com (2603:10b6:a03:510::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.25; Tue, 24 Sep 2024 00:06:07 +0000 Received: from BY3PR09MB8834.namprd09.prod.outlook.com ([fe80::9fcf:fc76:1d:f39]) by BY3PR09MB8834.namprd09.prod.outlook.com ([fe80::9fcf:fc76:1d:f39%3]) with mapi id 15.20.7982.022; Tue, 24 Sep 2024 00:06:07 +0000 Message-ID: <8f35eb96-3458-45d2-a31d-7813ae4e7260@llnl.gov> Date: Mon, 23 Sep 2024 17:06:05 -0700 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Tony Hutter Subject: [PATCH v2] PCI: Introduce Cray ClusterStor E1000 NVMe slot LED driver To: Lukas Wunner , Bjorn Helgaas , mariusz.tkaczyk@linux.intel.com, minyard@acm.org Cc: linux-pci@vger.kernel.org, openipmi-developer@lists.sourceforge.net, Linux Kernel Mailing List X-ClientProxiedBy: SJ0PR03CA0122.namprd03.prod.outlook.com (2603:10b6:a03:33c::7) To BY3PR09MB8834.namprd09.prod.outlook.com (2603:10b6:a03:346::22) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY3PR09MB8834:EE_|SJ0PR09MB11459:EE_ X-MS-Office365-Filtering-Correlation-Id: 87e408a0-3294-49e2-f814-08dcdc2caff9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?utf-8?q?WfvVk6t/7Owz6Ub2MTPrvxBiYIJJGc4?= =?utf-8?q?jaC8vDmXIi78eAHGjoTw1NeWJcLke5oObH/XGvaXVOqX0Ds+k7e2VyjmOPrsajVcb?= =?utf-8?q?zrgDzKEiVgTOSCsfCRaAro4rs8CoYaNkArE/NMikn+NwP5Lmec8GY7T+0d+2mOkuR?= =?utf-8?q?+NoXuyDYog2szaufuH5Xx3wGbF6SVBV8YQLUsjH9tDGYAxl3nMmrEgmaBwRtHa5/q?= =?utf-8?q?Zj2iumTaf+6ZYeC9bYENl38xiYtIWRTrlxcGFD9H/+tWZ5im6/CspeWP/ZTO+UVWv?= =?utf-8?q?RZJhA0fV77405j5p0YTxqZLDUDEiLOEyXMOIE3wrK1/CRAv8R0H6Qnv9vevZNbqEb?= =?utf-8?q?nQ8K3P4rGrfZPe3xe6JQf+jRUO+TJYzm7loAreCZC5rFAs4cyXoCPeLPQ2d8NN4gb?= =?utf-8?q?YWccawvhCIY4qav89CTPj0Vv8uYpL/31QEimdEUK/7Iiy0ScBioEy1LCu2rpFklP6?= =?utf-8?q?CNANMcBIjHE8FcHCx6jTGKrUIKHUI1iOyRq49gJsUoj8UV8NqAup6pqk8HJ63gpDJ?= =?utf-8?q?rudS+LpCI37aYz8qy9PVp34HJzzUKA1YBIkLDiAIdcjW41c8lENOtMAXxg8ajqg2g?= =?utf-8?q?fPyEgz1epuH9xE9oCJobFM1eb3YBk4s7HJ1SbHToJAsHe+F4r20AcHa4NiasFQi4F?= =?utf-8?q?R2LtDSxdX0N9VWg5ZJEtsGJbjEbu/5AkVQaeYR4CB9lInL6lyuJg4iwtazLfn7a3q?= =?utf-8?q?Z4X2HFYjaLUzz8Q5fQKZ5s3jZIaFp8mgp1D0zRNeELsLUdcerOplWcyx41AHQdCSP?= =?utf-8?q?a8aihjVATFb0IF9KZeyVye5GqAIKYjGYlCO/XmItqK1/TiaX+fy20LT8tjAJaY+lh?= =?utf-8?q?dEgAMWzQTUwHQnHECnPDQFTp9GB5SYmJEnE+6vWB0Jp0aRssVrjazmNiFJYj1FbPW?= =?utf-8?q?dKuvHsz0uEEBSDyov6U50jih4knwrk/d+g/VQm+C5JpsQH9Arj3mnHza7GErLRjF5?= =?utf-8?q?TWwlHg+nVxNEMRG/kW9uKeEjDfbWbm5ZuTeWQWIw1v2PKar1vNwiJijTSCeyqJSfR?= =?utf-8?q?Jb5v0g+sqRlUejTqqIor8FBaKCcY8jCNp9+Fz03SU06rkvoe8U7A4jneFtTGgrQUX?= =?utf-8?q?h8KLXnbXyDlDzQRXlV3+MuuFiMtg6EdVZPhUcNutOxhnAz0N412hS4PWi1N/MP9kG?= =?utf-8?q?9V+IdbkwGQxgzlRrdg4k5UJcMOUqj16FKdN5MOImqDuMxqto+JC4vRBNgb2HqHiKW?= =?utf-8?q?caZjaT1IDIQicpGR8jitUA3VGHpuhJS2e/xQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY3PR09MB8834.namprd09.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?zloGl4zOyBdXsropf8a89mo701gM?= =?utf-8?q?Z+GiLYNZjoOIz7oQPj945LzgN6pkwjshqdD/rRDEfEyKOWtcRDXqdiXFGcOy0qHYI?= =?utf-8?q?+sowbIrPaqSjszm2kt0xgI6Ph2mywsC6tvoQ0J6vmtWbG1JzXOe5XxQmsXn33fA6/?= =?utf-8?q?Mnr4tdpjrtp02LnFF2FcYLBJwWN9Cue2o+bS9hHwe/8n4MX+anFVhu0y9ZOSfGqLa?= =?utf-8?q?1LVASeQWhRl98k7PT982UCAx3pd6KbP6DO4jvzoEQaJokMeW+FngFLxxp9fpguiql?= =?utf-8?q?pK4y6OP2vZ1DCAt7Ya+sp7HTdMkgsYCSf2JwGvs9jpzP7cyuAa0o51nP1Oj9MnYEP?= =?utf-8?q?9BKqYProE82uor01CtWBZ3jG8BnuthLonV2OEegsTfoWv74GtdJEjXLQAsN7RBQMS?= =?utf-8?q?lEgTLGQPyhyC4trjohwP8NntK76/k9KlwDWvNZiV3FVWJezB/5UqyT2z68tGGTa+9?= =?utf-8?q?TkNrCa0hR3aIgXks4819Y4WaGCmjoeJV3K41AOMJgkSJYgcZbbNft8Av3upHJ5lI/?= =?utf-8?q?0gbpj8qmPu4woZHr+r9mBcnV7I99Ad/BQcbh2rDkh0di+F4TqfqKa3l/QEzSgY3il?= =?utf-8?q?bEVjzG4TEXpmfkeUoakcHFaIgnEOC2yBRrnSdEKygZmXyybGAOpeIezPUm1UClHVY?= =?utf-8?q?NZcam/ymaWPk7TUDl1MxQswGl2QoXO4RKzGEcOcm8yvZeI0lIZzgXJPvxgb6WGtr5?= =?utf-8?q?FUiVWb2DHTOg0F5p/73zvxtiBUTc8zezH9bOpVmw52/vdj33Mlz2xE+sD4hq9Z+pR?= =?utf-8?q?5sjMW7maK6/6a7BR6aXLTd9a2xdX0SL3iJRhs4NdrqTKZeLRou3EktHyz6FK5lVdy?= =?utf-8?q?hDIKB1RzcJxVwc+b6IkS1f/Rv5kFKnOuQYoyOQRFYnKqM96UDJcSrnMa2OKFTN7p6?= =?utf-8?q?gFjjxEAXDsGmoudEHw0Y4UrfnWzy57eCsROT8/aemBlP5dhEK01l6oS+EnxnIa4ch?= =?utf-8?q?NNFQgq2y4vlm7YV+VY73xAvMoVZuUUDPA2hCy9dZuvLKG4kqu8LCoWwd340y6qu/i?= =?utf-8?q?emcBbcQZpm7ywjuqe/GA/+RdKJWy6MII0B9CoxuAWEQySv0sDXD8bab/bki/8T+ri?= =?utf-8?q?ZULiENqcZ5/2nsPn734HS5dVhwDCtPWIFuR2MUsMaf7kx3Cet16ZPN7lRDjgPzxv5?= =?utf-8?q?PMu/JHSoyatP1JdqQOnhJTmj+SyhHFw/Y8jCpu7TKQEV2odrMMto1xoZjv5z0AGjP?= =?utf-8?q?7Ese5lL+pXXvKo+a529PVwQO8sfV54iJocdkivmpnU6LryEn4ahygRxHFIYcOZpD5?= =?utf-8?q?bFDqeP/KjE2dOT0N8NbTa9afCVlN7ypqMgC3gS9ZZT6koAMp70nrWuCGXlOFBtc/T?= =?utf-8?q?1nWce0JpG72fMdWb9nCSs1zGu7tXZpt4u85b0wnpE9pKkLzn1xyMxvCgtlisKz6h0?= =?utf-8?q?Z8hUlYCDGuKAnVGGZI6IIXGhkpqZG8rtm2kdzzMIag+uvBGKc+zWO9/rLT/NnYWoR?= =?utf-8?q?r8NdzYPyhQb+PRE75jQt2Y5a/c9wXmvEnms7t66gBmxdDYbBBzXCQjoVLv01L54hp?= =?utf-8?q?WLuggoxYudrE?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: KxjUfCtGAqDdw71up7Ow2RJ/LLK9fx1YPY/f9A/yeMVi3uiGXya6N/YiWWrlCUw9Paku6IzZMgkuj0ASYtdzBHZdDf2NQVI8/BqcZhJXaSEQyl/MNpwIGdOHq+Mog9PyyyyEGaP6vqqyMRialoidZSKvDQODZLBFJuZEuOH6rrQYxaL6cwVYmtVo6A4gadKnAJOLyM8ZKUHJvzbnird4Q5HtY1y7kmfHcfkU01j9O0bcUYOC6y23REtpITyXEm809GRHFK42L7fXj2Stu6rrQnR5x34HVbOwySv4KHOvJcnnQjxZ4+L5SBkeNFW4putccMtjXQ3WnsRLTPeb7roc8t5xonTGt65xU/dqIuTlg6n4chjCa0swDx1QKzNw4zT/SdFIPkaRQzbjR2HoS315WqqzxrXz7KkuKBYKGOBBYug8NGGUMOciQMvM/Xmpcc4L6iA1BAo27A+XHDCURR8tC3NHjFESp+JctbgMpNs14m/9KwtBgoTw7mMrV7lUqOtI43cTOFjiEmV/G+2kutZqYEOELetNoRwTyWY1Gs01xVNmYSUFTih79eBbGRrQCO7r3GeqBAGIkkVHhlQDjsiDzZjVfub1H7gFYY2A28z+SK0Bky5GNskzdckYbddQHJ9aIMwvXn9qjBNEtlGKp049/A== X-OriginatorOrg: llnl.gov X-MS-Exchange-CrossTenant-Network-Message-Id: 87e408a0-3294-49e2-f814-08dcdc2caff9 X-MS-Exchange-CrossTenant-AuthSource: BY3PR09MB8834.namprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2024 00:06:07.1493 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a722dec9-ae4e-4ae3-9d75-fd66e2680a63 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR09MB11459 X-Proofpoint-ORIG-GUID: AnbvG4ImWy3nlPlalsavqKMyQI0LOlVZ X-Proofpoint-GUID: AnbvG4ImWy3nlPlalsavqKMyQI0LOlVZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_15,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 clxscore=1011 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409230172 Add driver to control the NVMe slot LEDs on the Cray ClusterStor E1000. The driver provides hotplug attention status callbacks for the 24 NVMe slots on the E1000. This allows users to access the E1000's locate and fault LEDs via the normal /sys/bus/pci/slots//attention sysfs entries. This driver uses IPMI to communicate with the E1000 controller to toggle the LEDs. Changes in v2: - Integrated E1000 code into the pciehp driver as an built-in extention rather than as a standalone module. - Moved debug tunables and counters to debugfs. - Removed forward declarations. - Kept the /sys/bus/pci/slots//attention interface rather than using NPEM/_DSM or led_classdev as suggested. The "attention" interface is more beneficial for our site, since it allows us to control the NVMe slot LEDs agnostically across different enclosure vendors and kernel versions using the same scripts. It is also nice to use the same /sys/bus/pci/slots// sysfs directory for both slot LED toggling ("attention") and slot power control ("power"). Signed-off-by: Tony Hutter --- MAINTAINERS | 5 + drivers/pci/hotplug/Kconfig | 10 + drivers/pci/hotplug/Makefile | 3 + drivers/pci/hotplug/pciehp.h | 7 + drivers/pci/hotplug/pciehp_core.c | 12 + drivers/pci/hotplug/pciehp_craye1k.c | 677 +++++++++++++++++++++++++++ 6 files changed, 714 insertions(+) create mode 100644 drivers/pci/hotplug/pciehp_craye1k.c diff --git a/MAINTAINERS b/MAINTAINERS index 42d2d950877c..4e6edb323754 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5928,6 +5928,11 @@ S: Maintained F: Documentation/filesystems/cramfs.rst F: fs/cramfs/ +CRAY CLUSTERSTOR E1000 NVME SLOT LED DRIVER EXTENSIONS +M: Tony Hutter +S: Maintained +F: drivers/pci/hotplug/pciehp_craye1k.c + CREATIVE SB0540 M: Bastien Nocera L: linux-input@vger.kernel.org diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig index 1472aef0fb81..6cd664be6b66 100644 --- a/drivers/pci/hotplug/Kconfig +++ b/drivers/pci/hotplug/Kconfig @@ -173,4 +173,14 @@ config HOTPLUG_PCI_S390 When in doubt, say Y. +config HOTPLUG_PCI_PCIE_CRAY_E1000 + bool "PCIe Hotplug extensions for Cray ClusterStor E1000" + depends on ACPI_PCI_SLOT && HOTPLUG_PCI_PCIE && IPMI_HANDLER=y + help + Say Y here if you have a Cray ClusterStor E1000 and want to control + your NVMe slot LEDs. Without this driver is it not possible + to control the fault and locate LEDs on the E1000's 24 NVMe slots. + + When in doubt, say N. + endif # HOTPLUG_PCI diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile index 240c99517d5e..b3cb75ff2db2 100644 --- a/drivers/pci/hotplug/Makefile +++ b/drivers/pci/hotplug/Makefile @@ -65,6 +65,9 @@ pciehp-objs := pciehp_core.o \ pciehp_ctrl.o \ pciehp_pci.o \ pciehp_hpc.o +ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 +pciehp-objs += pciehp_craye1k.o +endif shpchp-objs := shpchp_core.o \ shpchp_ctrl.o \ diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h index 273dd8c66f4e..ea68ae041547 100644 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h @@ -198,6 +198,13 @@ int pciehp_get_raw_indicator_status(struct hotplug_slot *h_slot, u8 *status); int pciehp_slot_reset(struct pcie_device *dev); +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 +int craye1k_get_attention_status(struct hotplug_slot *hotplug_slot, u8 *status); +int craye1k_set_attention_status(struct hotplug_slot *hotplug_slot, u8 status); +bool is_craye1k_slot(struct controller *ctrl); +int craye1k_init(void); +#endif + static inline const char *slot_name(struct controller *ctrl) { return hotplug_slot_name(&ctrl->hotplug_slot); diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c index ff458e692fed..9a7a7b320810 100644 --- a/drivers/pci/hotplug/pciehp_core.c +++ b/drivers/pci/hotplug/pciehp_core.c @@ -73,6 +73,13 @@ static int init_slot(struct controller *ctrl) ops->get_attention_status = pciehp_get_raw_indicator_status; ops->set_attention_status = pciehp_set_raw_indicator_status; } +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 + if (is_craye1k_slot(ctrl)) { + /* slots 1-24 on Cray E1000s are controlled differently */ + ops->get_attention_status = craye1k_get_attention_status; + ops->set_attention_status = craye1k_set_attention_status; + } +#endif /* register this slot with the hotplug pci core */ ctrl->hotplug_slot.ops = ops; @@ -404,6 +411,11 @@ int __init pcie_hp_init(void) pr_debug("pcie_port_service_register = %d\n", retval); if (retval) pr_debug("Failure to register service\n"); +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 + retval = craye1k_init(); + if (retval) + pr_debug("Failure to register Cray E1000 extensions"); +#endif return retval; } diff --git a/drivers/pci/hotplug/pciehp_craye1k.c b/drivers/pci/hotplug/pciehp_craye1k.c new file mode 100644 index 000000000000..9f44c7b35d03 --- /dev/null +++ b/drivers/pci/hotplug/pciehp_craye1k.c @@ -0,0 +1,677 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2022-2024 Lawrence Livermore National Security, LLC + */ +/* + * Cray ClusterStor E1000 hotplug slot LED driver extensions + * + * This driver controls the NVMe slot LEDs on the Cray ClusterStore E1000. + * It provides hotplug attention status callbacks for the 24 NVMe slots on + * the E1000. This allows users to access the E1000's locate and fault + * LEDs via the normal /sys/bus/pci/slots//attention sysfs entries. + * This driver uses IPMI to communicate with the E1000 controller to toggle + * the LEDs. + * + * This driver is based off of ibmpex.c + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pciehp.h" + +/* Cray E1000 commands */ +#define CRAYE1K_CMD_NETFN 0x3c +#define CRAYE1K_CMD_PRIMARY 0x33 +#define CRAYE1K_CMD_FAULT_LED 0x39 +#define CRAYE1K_CMD_LOCATE_LED 0x22 + +/* Subcommands */ +#define CRAYE1K_GET_LED 0x0 +#define CRAYE1K_SET_LED 0x1 +#define CRAYE1K_SET_PRIMARY 0x1 + +/* + * Milliseconds to wait after get/set LED command. 200ms value found though + * experimentation + */ +#define CRAYE1K_POST_CMD_WAIT_MS 200 + +struct craye1k { + struct device *dev; /* BMC device */ + struct mutex lock; + struct completion read_complete; + struct ipmi_addr address; + struct ipmi_user *user; + int iface; + + long tx_msg_id; + struct kernel_ipmi_msg tx_msg; + unsigned char tx_msg_data[IPMI_MAX_MSG_LENGTH]; + unsigned char rx_msg_data[IPMI_MAX_MSG_LENGTH]; + unsigned long rx_msg_len; + unsigned char rx_result; /* IPMI completion code */ + + /* Parent dir for all our debugfs entries */ + struct dentry *parent; + + /* debugfs stats */ + u64 check_primary; + u64 check_primary_failed; + u64 was_already_primary; + u64 was_not_already_primary; + u64 set_primary; + u64 set_initial_primary_failed; + u64 set_primary_failed; + u64 set_led_locate_failed; + u64 set_led_fault_failed; + u64 set_led_readback_failed; + u64 set_led_failed; + u64 get_led_failed; + u64 completion_timeout; + u64 wrong_msgid; + u64 request_failed; + + /* debugfs configuration options */ + + /* Print info on spurious IPMI messages */ + bool print_errors; + + /* Retries for kernel IPMI layer */ + u32 ipmi_retries; + + /* Timeout in ms for IPMI (0 = use IPMI default_retry_ms) */ + u32 ipmi_timeout_ms; + + /* Timeout in ms to wait for E1000 message completion */ + u32 completion_timeout_ms; +}; + +/* + * Make our craye1k a global so get/set_attention_status() can access it. + * This is safe since there's only one node controller on the board, and so it's + * impossible to instantiate more than one craye1k. + */ +static struct craye1k *craye1k_global; + +/* Return parent dir dentry */ +static struct dentry * +craye1k_debugfs_init(struct craye1k *craye1k) +{ + umode_t mode = 0644; + struct dentry *parent = debugfs_create_dir("pciehp_craye1k", NULL); + + if (!parent) + return NULL; + + debugfs_create_x64("check_primary", mode, parent, + &craye1k->check_primary); + debugfs_create_x64("check_primary_failed", mode, parent, + &craye1k->check_primary_failed); + debugfs_create_x64("was_already_primary", mode, parent, + &craye1k->was_already_primary); + debugfs_create_x64("was_not_already_primary", mode, parent, + &craye1k->was_not_already_primary); + debugfs_create_x64("set_primary", mode, parent, + &craye1k->set_primary); + debugfs_create_x64("set_initial_primary_failed", mode, parent, + &craye1k->set_initial_primary_failed); + debugfs_create_x64("set_primary_failed", mode, parent, + &craye1k->set_primary_failed); + debugfs_create_x64("set_led_locate_failed", mode, parent, + &craye1k->set_led_locate_failed); + debugfs_create_x64("set_led_fault_failed", mode, parent, + &craye1k->set_led_fault_failed); + debugfs_create_x64("set_led_readback_failed", mode, parent, + &craye1k->set_led_readback_failed); + debugfs_create_x64("set_led_failed", mode, parent, + &craye1k->set_led_failed); + debugfs_create_x64("get_led_failed", mode, parent, + &craye1k->get_led_failed); + debugfs_create_x64("completion_timeout", mode, parent, + &craye1k->completion_timeout); + debugfs_create_x64("wrong_msgid", mode, parent, + &craye1k->wrong_msgid); + debugfs_create_x64("request_failed", mode, parent, + &craye1k->request_failed); + + debugfs_create_x32("ipmi_retries", mode, parent, + &craye1k->ipmi_retries); + debugfs_create_x32("ipmi_timeout_ms", mode, parent, + &craye1k->ipmi_timeout_ms); + debugfs_create_x32("completion_timeout_ms", mode, parent, + &craye1k->completion_timeout_ms); + debugfs_create_bool("print_errors", mode, parent, + &craye1k->print_errors); + + return parent; +} + +/* + * craye1k_msg_handler() - IPMI message response handler + */ +static void craye1k_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data) +{ + struct craye1k *craye1k = user_msg_data; + + if (msg->msgid != craye1k->tx_msg_id) { + craye1k->wrong_msgid++; + if (craye1k->print_errors) { + dev_warn_ratelimited(craye1k->dev, "rx msgid %d != %d", + (int)msg->msgid, + (int)craye1k->tx_msg_id); + } + ipmi_free_recv_msg(msg); + return; + } + + /* Set rx_result to the IPMI completion code */ + if (msg->msg.data_len > 0) + craye1k->rx_result = msg->msg.data[0]; + else + craye1k->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE; + + if (msg->msg.data_len > 1) { + /* Exclude completion code from data bytes */ + craye1k->rx_msg_len = msg->msg.data_len - 1; + memcpy(craye1k->rx_msg_data, msg->msg.data + 1, + craye1k->rx_msg_len); + } else { + craye1k->rx_msg_len = 0; + } + + ipmi_free_recv_msg(msg); + + complete(&craye1k->read_complete); +} + +static const struct ipmi_user_hndl craye1k_user_hndl = { + .ipmi_recv_hndl = craye1k_msg_handler +}; + +static void craye1k_new_smi(int iface, struct device *dev) +{ + int rc; + struct craye1k *craye1k; + + /* There's only one node controller so driver data should not be set */ + WARN_ON(craye1k_global); + + craye1k = kzalloc(sizeof(*craye1k), GFP_KERNEL); + if (!craye1k) + return; + + craye1k->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; + craye1k->address.channel = IPMI_BMC_CHANNEL; + craye1k->iface = iface; + craye1k->dev = dev; + craye1k->tx_msg.data = craye1k->tx_msg_data; + craye1k->ipmi_retries = 4; + craye1k->ipmi_timeout_ms = 500; + craye1k->completion_timeout_ms = 300; + + init_completion(&craye1k->read_complete); + mutex_init(&craye1k->lock); + + dev_set_drvdata(dev, craye1k); + + rc = ipmi_create_user(craye1k->iface, &craye1k_user_hndl, craye1k, + &craye1k->user); + if (rc < 0) { + dev_err_ratelimited(dev, + "Unable to register IPMI user, iface %d\n", + craye1k->iface); + kfree(craye1k); + dev_set_drvdata(dev, NULL); + return; + } + + craye1k_global = craye1k; + + craye1k->parent = craye1k_debugfs_init(craye1k); + if (!craye1k->parent) + dev_warn_ratelimited(dev, "Cannot create debugfs"); + + dev_info_ratelimited(dev, + "Cray ClusterStor E1000 slot LEDs registered"); +} + +static void craye1k_smi_gone(int iface) +{ + pr_warn("craye1k: Got unexpected smi_gone, iface=%d", iface); +} + +static struct ipmi_smi_watcher craye1k_smi_watcher = { + .owner = THIS_MODULE, + .new_smi = craye1k_new_smi, + .smi_gone = craye1k_smi_gone +}; + +/* + * craye1k_send_message() - Send the message already setup in 'craye1k' + * + * Context: craye1k->lock is already held. + * Return: 0 on success, non-zero on error. + */ +static int craye1k_send_message(struct craye1k *craye1k) +{ + int rc; + + rc = ipmi_validate_addr(&craye1k->address, sizeof(craye1k->address)); + if (rc) { + dev_err_ratelimited(craye1k->dev, "validate_addr() = %d\n", rc); + return rc; + } + + craye1k->tx_msg_id++; + + rc = ipmi_request_settime(craye1k->user, &craye1k->address, + craye1k->tx_msg_id, &craye1k->tx_msg, craye1k, + 0, craye1k->ipmi_retries, + craye1k->ipmi_timeout_ms); + + if (rc) { + craye1k->request_failed++; + return rc; + } + + return 0; +} + +/* + * craye1k_do_message() - Send the message in 'craye1k' and wait for a response + * + * Context: craye1k->lock is already held. + * Return: 0 on success, non-zero on error. + */ +static int craye1k_do_message(struct craye1k *craye1k) +{ + int rc; + long rc2; + struct completion *read_complete = &craye1k->read_complete; + unsigned long tout = msecs_to_jiffies(craye1k->completion_timeout_ms); + + rc = craye1k_send_message(craye1k); + if (rc == 0) { + rc2 = wait_for_completion_killable_timeout(read_complete, tout); + if (rc2 == 0) { + craye1k->completion_timeout++; + rc = -ETIME; + } + } + + if (craye1k->rx_result == IPMI_UNKNOWN_ERR_COMPLETION_CODE || rc2 <= 0) + rc = -1; + + return rc; +} + +/* + * __craye1k_do_command() - Do an IPMI command + * + * Send a command with optional data bytes, and read back response bytes. + * Context: craye1k->lock is already held. + * Returns: 0 on success, non-zero on error. + */ +static int __craye1k_do_command(struct craye1k *craye1k, u8 netfn, u8 cmd, + u8 *send_data, u8 send_data_len, u8 *recv_data, + u8 recv_data_len) +{ + int rc; + + craye1k->tx_msg.netfn = netfn; + craye1k->tx_msg.cmd = cmd; + + if (send_data) { + memcpy(&craye1k->tx_msg_data[0], send_data, send_data_len); + craye1k->tx_msg.data_len = send_data_len; + } else { + craye1k->tx_msg_data[0] = 0; + craye1k->tx_msg.data_len = 0; + } + + rc = craye1k_do_message(craye1k); + memcpy(recv_data, craye1k->rx_msg_data, recv_data_len); + + return rc; +} + +/* + * craye1k_do_command_and_netfn() - Do IPMI command and return 1st data byte + * + * Do an IPMI command with the given netfn, cmd, and optional send payload + * bytes. + * + * Context: craye1k->lock is already held. + * Returns: the last byte from the response or 0 if response had no response + * data bytes, else -1 on error. + */ +static int craye1k_do_command_and_netfn(struct craye1k *craye1k, u8 netfn, + u8 cmd, u8 *send_data, u8 send_data_len) +{ + int rc; + + rc = __craye1k_do_command(craye1k, netfn, cmd, send_data, send_data_len, + NULL, 0); + if (rc != 0) { + /* Error attempting command */ + return -1; + } + + if (craye1k->tx_msg.data_len == 0) + return 0; + + /* Return last received byte value */ + return craye1k->rx_msg_data[craye1k->rx_msg_len - 1]; +} + +/* + * craye1k_do_command() - Do a Cray E1000 specific IPMI command. + * @cmd: Cray E1000 specific command + * @send_data: Data to send after the command + * @send_data_len: Data length + * + * Context: craye1k->lock is already held. + * Returns: the last byte from the response or 0 if response had no response + * data bytes, else -1 on error. + */ +static int craye1k_do_command(struct craye1k *craye1k, u8 cmd, u8 *send_data, + u8 send_data_len) +{ + return (craye1k_do_command_and_netfn(craye1k, CRAYE1K_CMD_NETFN, cmd, + send_data, send_data_len)); +} + +/* + * __craye1k_set_primary() - Tell the BMC we want to be the primary server + * + * An E1000 board has two physical servers on it. In order to set a slot + * NVMe LED, this server needs to first tell the BMC that it's the primary + * server. + * + * Returns: 0 on success, non-zero on error. + */ +static int __craye1k_set_primary(struct craye1k *craye1k) +{ + u8 bytes[2] = {CRAYE1K_SET_PRIMARY, 1}; /* set primary to 1 */ + + craye1k->set_primary++; + return craye1k_do_command(craye1k, CRAYE1K_CMD_PRIMARY, bytes, 2); +} + +/* + * craye1k_is_primary() - Are we the primary server? + * + * Returns: 1 if we are the primary server, 0 otherwise. + */ +static int craye1k_is_primary(struct craye1k *craye1k) +{ + u8 byte = 0; + int rc; + + /* Response byte is 0x1 on success */ + rc = craye1k_do_command(craye1k, CRAYE1K_CMD_PRIMARY, &byte, 1); + craye1k->check_primary++; + if (rc == 0x1) + return 1; /* success */ + + craye1k->check_primary_failed++; + return 0; /* We are not the primary server node */ +} + +/* + * craye1k_set_primary() - Attempt to set ourselves as the primary server + * + * Returns: 0 on success, 1 otherwise. + */ +static int craye1k_set_primary(struct craye1k *craye1k) +{ + int tries = 10; + + if (craye1k_is_primary(craye1k)) { + craye1k->was_already_primary++; + return 0; + } + craye1k->was_not_already_primary++; + + /* delay found through experimentation */ + msleep(300); + + if (__craye1k_set_primary(craye1k) != 0) { + craye1k->set_initial_primary_failed++; + return 1; /* error */ + } + + /* + * It can take 2 to 3 seconds after setting primary for the controller + * to report that it is the primary. + */ + while (tries--) { + msleep(500); + if (craye1k_is_primary(craye1k)) + break; + } + + if (tries == 0) { + craye1k->set_primary_failed++; + return 1; /* never reported that it's primary */ + } + + /* Wait for primary switch to finish */ + msleep(1500); + + return 0; +} + +/* + * craye1k_get_slot_led() - Get slot LED value + * @slot: Slot number (1-24) + * @is_locate_led: 0 = get fault LED value, 1 = get locate LED value + * + * Returns: slot value on success, -1 on failure. + */ +static int craye1k_get_slot_led(struct craye1k *craye1k, unsigned char slot, + bool is_locate_led) +{ + u8 bytes[2]; + u8 cmd; + + bytes[0] = CRAYE1K_GET_LED; + bytes[1] = slot; + + cmd = is_locate_led ? CRAYE1K_CMD_LOCATE_LED : CRAYE1K_CMD_FAULT_LED; + + return craye1k_do_command(craye1k, cmd, bytes, 2); +} + +/* + * craye1k_set_slot_led() - Attempt to set the locate/fault LED to a value + * @slot: Slot number (1-24) + * @is_locate_led: 0 = use fault LED, 1 = use locate LED + * @value: Value to set (0 or 1) + * + * Check the LED value after calling this function to ensure it has been set + * properly. + * + * Returns: 0 on success, non-zero on failure. + */ +static int craye1k_set_slot_led(struct craye1k *craye1k, unsigned char slot, + unsigned char is_locate_led, + unsigned char value) +{ + u8 bytes[3]; + u8 cmd; + + bytes[0] = CRAYE1K_SET_LED; + bytes[1] = slot; + bytes[2] = value; + + cmd = is_locate_led ? CRAYE1K_CMD_LOCATE_LED : CRAYE1K_CMD_FAULT_LED; + + return craye1k_do_command(craye1k, cmd, bytes, 3); +} + +static int __craye1k_get_attention_status(struct hotplug_slot *hotplug_slot, + u8 *status, bool set_primary) +{ + unsigned char slot; + int locate, fault; + struct craye1k *craye1k; + + craye1k = craye1k_global; + slot = PSN(to_ctrl(hotplug_slot)); + + if (set_primary) { + if (craye1k_set_primary(craye1k) != 0) { + craye1k->get_led_failed++; + return -EIO; + } + } + + locate = craye1k_get_slot_led(craye1k, slot, true); + if (locate == -1) { + craye1k->get_led_failed++; + return -EINVAL; + } + msleep(CRAYE1K_POST_CMD_WAIT_MS); + + fault = craye1k_get_slot_led(craye1k, slot, false); + if (fault == -1) { + craye1k->get_led_failed++; + return -EINVAL; + } + msleep(CRAYE1K_POST_CMD_WAIT_MS); + + *status = locate << 1 | fault; + + return 0; +} + +int craye1k_get_attention_status(struct hotplug_slot *hotplug_slot, + u8 *status) +{ + int rc; + struct craye1k *craye1k; + + craye1k = craye1k_global; + + if (mutex_lock_interruptible(&craye1k->lock) != 0) + return -EINTR; + + rc = __craye1k_get_attention_status(hotplug_slot, status, true); + + mutex_unlock(&craye1k->lock); + return rc; +} + +int craye1k_set_attention_status(struct hotplug_slot *hotplug_slot, + u8 status) +{ + unsigned char slot; + int tries = 4; + int rc; + u8 new_status; + struct craye1k *craye1k; + bool locate, fault; + + craye1k = craye1k_global; + + slot = PSN(to_ctrl(hotplug_slot)); + + if (mutex_lock_interruptible(&craye1k->lock) != 0) + return -EINTR; + + /* Retry to ensure all LEDs are set */ + while (tries--) { + /* + * The node must first set itself to be the primary node before + * setting the slot LEDs (each board has two nodes, or + * "servers" as they're called by the manufacturer). This can + * lead to contention if both nodes are trying to set the LEDs + * at the same time. + */ + rc = craye1k_set_primary(craye1k); + if (rc != 0) { + /* Could not set as primary node. Just retry again. */ + continue; + } + + /* Write value twice to increase success rate */ + locate = (status & 0x2) >> 1; + craye1k_set_slot_led(craye1k, slot, 1, locate); + if (craye1k_set_slot_led(craye1k, slot, 1, locate) != 0) { + craye1k->set_led_locate_failed++; + continue; /* fail, retry */ + } + + msleep(CRAYE1K_POST_CMD_WAIT_MS); + + fault = status & 0x1; + craye1k_set_slot_led(craye1k, slot, 0, fault); + if (craye1k_set_slot_led(craye1k, slot, 0, fault) != 0) { + craye1k->set_led_fault_failed++; + continue; /* fail, retry */ + } + + msleep(CRAYE1K_POST_CMD_WAIT_MS); + + rc = __craye1k_get_attention_status(hotplug_slot, &new_status, + false); + + msleep(CRAYE1K_POST_CMD_WAIT_MS); + + if (rc == 0 && new_status == status) + break; /* success */ + + craye1k->set_led_readback_failed++; + + /* + * At this point we weren't successful in setting the LED and + * need to try again. + * + * Do a random back-off to reduce contention with other server + * node in the unlikely case that both server nodes are trying to + * trying to set a LED at the same time. + * + * The 500ms minimum in the back-off reduced the chance of this + * whole retry loop failing from 1 in 700 to none in 10000. + */ + msleep(500 + (get_random_long() % 500)); + } + mutex_unlock(&craye1k->lock); + if (tries == 0) { + craye1k->set_led_failed++; + return -EIO; + } + + return 0; +} + +static bool is_craye1k_board(void) +{ + return dmi_match(DMI_PRODUCT_NAME, "VSSEP1EC"); +} + +bool is_craye1k_slot(struct controller *ctrl) +{ + return (PSN(ctrl) >= 1 && PSN(ctrl) <= 24 && is_craye1k_board()); +} + +int craye1k_init(void) +{ + if (!is_craye1k_board()) + return 0; + + return ipmi_smi_watcher_register(&craye1k_smi_watcher); +} + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Tony Hutter "); +MODULE_DESCRIPTION("Cray E1000 NVMe Slot LED driver");