Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1881916yba; Sun, 14 Apr 2019 23:43:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfB6TUu6d5GrSZYJ7EfJDVWkqSALbUTekJvmru+uD9ki9/yAgoExcKEOHLShx+U6gxuglZ X-Received: by 2002:a17:902:2de4:: with SMTP id p91mr71773087plb.191.1555310623625; Sun, 14 Apr 2019 23:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555310623; cv=none; d=google.com; s=arc-20160816; b=c39ekZ1g7R1RON3HBhCxkECNlzzCdCsmWnmz0op9vzoSB8cgFLmHYawR6HJVY1I3Ke Kf2mgYi8TUsPUO2LwhohgUsbpi9BvS6biJPyUbSgCqEKqWeQjnWhJHqUcKUYtlCKwtbz ay9DnR/Boq3uGImCsl43Qxp9MKZfGaDD2GqMt2aI8IDnj8iaGTF+QWEz9VgZU8ZFsAA3 RHKVyJtRF+PeNK/nDBMkpPjRWMBu30vKZhZXGLgu8eVrNRfNNfftPmER63i8z0WNHKoe Shz6RwUavvz7Vw5V5w4AOk64VzbhFef6ZMl60vksorObcLIPl1/25jD736wruw3eKucU ZuWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=oFprbKzBBpnKVXRQcVYU8o6i53yGn9Tfvv5wo0l+lxA=; b=HJNXSXOLFwSz+XeE2gMtgC4VFkDsFPe+/14/qyEFOKq65R8edbD96hczozRl/rbvkt 2aQ/S416GzxpfTQleNVy1WSlsZhVqz2rtLplTpRzM9z8+49ZRaLYqLAhrAQhz21f5+BF 3UUtPbAzzedKqymqToD7jQ97wH8J78vTnscB/Pfsbag4Rkcl9mKbQqw8N8mJM0qeBg1c Wf+hCVz2LTAAf0PAkF8ct9PJljDtFoT9CJA6eW8SdVD2sonr53v9RFrMUpjXhVDN/n/D nkci9gNwdWr2PXDnQFWAM8+h8i/ccOu2wrRA9Q++/300iKe+aoqvjrC2rRRUlFQemSJe rRTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q23si43944214pgk.140.2019.04.14.23.43.27; Sun, 14 Apr 2019 23:43:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726252AbfDOGmw (ORCPT + 99 others); Mon, 15 Apr 2019 02:42:52 -0400 Received: from esa3.microchip.iphmx.com ([68.232.153.233]:20694 "EHLO esa3.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725796AbfDOGmu (ORCPT ); Mon, 15 Apr 2019 02:42:50 -0400 X-IronPort-AV: E=Sophos;i="5.60,352,1549954800"; d="scan'208";a="30309593" Received: from unknown (HELO smtp.microsemi.com) ([208.19.99.222]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 14 Apr 2019 23:42:49 -0700 Received: from AUSMBX2.microsemi.net (10.201.34.32) by AUSMBX2.microsemi.net (10.201.34.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 15 Apr 2019 01:42:48 -0500 Received: from server1.microsemi.net (10.188.116.154) by ausmbx2.microsemi.net (10.201.34.32) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Mon, 15 Apr 2019 01:42:45 -0500 From: Wesley Sheng To: , , , , CC: , Subject: [PATCH v2 1/2] switchtec: Fix false maximum supported PCIe function number issue Date: Mon, 15 Apr 2019 22:41:41 +0800 Message-ID: <1555339302-31829-2-git-send-email-wesley.sheng@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1555339302-31829-1-git-send-email-wesley.sheng@microchip.com> References: <1555339302-31829-1-git-send-email-wesley.sheng@microchip.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The hardware supports up to 255 PFFs and the driver only supports 48, so this patch updates the driver to support them all. To be backward compatible, a new ioctl and corresponding data structure are created, while keep the deprecated one. Signed-off-by: Wesley Sheng --- drivers/pci/switch/switchtec.c | 39 +++++++++++++++++++++++++----------- include/linux/switchtec.h | 2 +- include/uapi/linux/switchtec_ioctl.h | 13 +++++++++++- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c index e22766c..7df9a69 100644 --- a/drivers/pci/switch/switchtec.c +++ b/drivers/pci/switch/switchtec.c @@ -658,19 +658,25 @@ static int ioctl_flash_part_info(struct switchtec_dev *stdev, static int ioctl_event_summary(struct switchtec_dev *stdev, struct switchtec_user *stuser, - struct switchtec_ioctl_event_summary __user *usum) + struct switchtec_ioctl_event_summary __user *usum, + size_t size) { - struct switchtec_ioctl_event_summary s = {0}; + struct switchtec_ioctl_event_summary *s; int i; u32 reg; + int ret = 0; - s.global = ioread32(&stdev->mmio_sw_event->global_summary); - s.part_bitmap = ioread32(&stdev->mmio_sw_event->part_event_bitmap); - s.local_part = ioread32(&stdev->mmio_part_cfg->part_event_summary); + s = kzalloc(sizeof(*s), GFP_KERNEL); + if (!s) + return -ENOMEM; + + s->global = ioread32(&stdev->mmio_sw_event->global_summary); + s->part_bitmap = ioread32(&stdev->mmio_sw_event->part_event_bitmap); + s->local_part = ioread32(&stdev->mmio_part_cfg->part_event_summary); for (i = 0; i < stdev->partition_count; i++) { reg = ioread32(&stdev->mmio_part_cfg_all[i].part_event_summary); - s.part[i] = reg; + s->part[i] = reg; } for (i = 0; i < SWITCHTEC_MAX_PFF_CSR; i++) { @@ -679,15 +685,19 @@ static int ioctl_event_summary(struct switchtec_dev *stdev, break; reg = ioread32(&stdev->mmio_pff_csr[i].pff_event_summary); - s.pff[i] = reg; + s->pff[i] = reg; } - if (copy_to_user(usum, &s, sizeof(s))) - return -EFAULT; + if (copy_to_user(usum, s, size)) { + ret = -EFAULT; + goto error_case; + } stuser->event_cnt = atomic_read(&stdev->event_cnt); - return 0; +error_case: + kfree(s); + return ret; } static u32 __iomem *global_ev_reg(struct switchtec_dev *stdev, @@ -977,8 +987,9 @@ static long switchtec_dev_ioctl(struct file *filp, unsigned int cmd, case SWITCHTEC_IOCTL_FLASH_PART_INFO: rc = ioctl_flash_part_info(stdev, argp); break; - case SWITCHTEC_IOCTL_EVENT_SUMMARY: - rc = ioctl_event_summary(stdev, stuser, argp); + case SWITCHTEC_IOCTL_EVENT_SUMMARY_LEGACY: + rc = ioctl_event_summary(stdev, stuser, argp, + sizeof(struct switchtec_ioctl_event_summary_legacy)); break; case SWITCHTEC_IOCTL_EVENT_CTL: rc = ioctl_event_ctl(stdev, argp); @@ -989,6 +1000,10 @@ static long switchtec_dev_ioctl(struct file *filp, unsigned int cmd, case SWITCHTEC_IOCTL_PORT_TO_PFF: rc = ioctl_port_to_pff(stdev, argp); break; + case SWITCHTEC_IOCTL_EVENT_SUMMARY: + rc = ioctl_event_summary(stdev, stuser, argp, + sizeof(struct switchtec_ioctl_event_summary)); + break; default: rc = -ENOTTY; break; diff --git a/include/linux/switchtec.h b/include/linux/switchtec.h index 52a079b..0cfc34a 100644 --- a/include/linux/switchtec.h +++ b/include/linux/switchtec.h @@ -20,7 +20,7 @@ #include #define SWITCHTEC_MRPC_PAYLOAD_SIZE 1024 -#define SWITCHTEC_MAX_PFF_CSR 48 +#define SWITCHTEC_MAX_PFF_CSR 255 #define SWITCHTEC_EVENT_OCCURRED BIT(0) #define SWITCHTEC_EVENT_CLEAR BIT(0) diff --git a/include/uapi/linux/switchtec_ioctl.h b/include/uapi/linux/switchtec_ioctl.h index 4f4daf8..c912b5a 100644 --- a/include/uapi/linux/switchtec_ioctl.h +++ b/include/uapi/linux/switchtec_ioctl.h @@ -50,7 +50,7 @@ struct switchtec_ioctl_flash_part_info { __u32 active; }; -struct switchtec_ioctl_event_summary { +struct switchtec_ioctl_event_summary_legacy { __u64 global; __u64 part_bitmap; __u32 local_part; @@ -59,6 +59,15 @@ struct switchtec_ioctl_event_summary { __u32 pff[48]; }; +struct switchtec_ioctl_event_summary { + __u64 global; + __u64 part_bitmap; + __u32 local_part; + __u32 padding; + __u32 part[48]; + __u32 pff[255]; +}; + #define SWITCHTEC_IOCTL_EVENT_STACK_ERROR 0 #define SWITCHTEC_IOCTL_EVENT_PPU_ERROR 1 #define SWITCHTEC_IOCTL_EVENT_ISP_ERROR 2 @@ -127,6 +136,8 @@ struct switchtec_ioctl_pff_port { _IOWR('W', 0x41, struct switchtec_ioctl_flash_part_info) #define SWITCHTEC_IOCTL_EVENT_SUMMARY \ _IOR('W', 0x42, struct switchtec_ioctl_event_summary) +#define SWITCHTEC_IOCTL_EVENT_SUMMARY_LEGACY \ + _IOR('W', 0x42, struct switchtec_ioctl_event_summary_legacy) #define SWITCHTEC_IOCTL_EVENT_CTL \ _IOWR('W', 0x43, struct switchtec_ioctl_event_ctl) #define SWITCHTEC_IOCTL_PFF_TO_PORT \ -- 2.7.4