]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
switchtec: Increase PFF limit from 48 to 255
authorWesley Sheng <wesley.sheng@microchip.com>
Mon, 15 Apr 2019 14:41:41 +0000 (22:41 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 17 Apr 2019 22:20:01 +0000 (17:20 -0500)
The Switchtec devices supports two PCIe Function Frameworks (PFFs) per
upstream port (one for the port itself and one for the management endoint),
and each PFF may have up to 255 ports.  Previously the driver only
supported 48 of those ports, and the SWITCHTEC_IOCTL_EVENT_SUMMARY ioctl
only returned information about those 48.

Increase SWITCHTEC_MAX_PFF_CSR from 48 to 255 so the driver supports all
255 possible ports.

Rename SWITCHTEC_IOCTL_EVENT_SUMMARY and associated struct
switchtec_ioctl_event_summary to SWITCHTEC_IOCTL_EVENT_SUMMARY_LEGACY and
switchtec_ioctl_event_summary_legacy with so existing applications work
unchanged, supporting up to 48 ports.

Add replacement SWITCHTEC_IOCTL_EVENT_SUMMARY and struct
switchtec_ioctl_event_summary that new and recompiled applications support
up to 255 ports.

Signed-off-by: Wesley Sheng <wesley.sheng@microchip.com>
[bhelgaas: changelog]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
drivers/pci/switch/switchtec.c
include/linux/switchtec.h
include/uapi/linux/switchtec_ioctl.h

index e22766c79fe96c6e008b9cca0ebad8e38251b8bd..7df9a69f7d938880e0ee766e616e1cd903c76760 100644 (file)
@@ -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;
index 52a079b3a9a6d0d1fb889343c3d75a605a6c8f80..0cfc34ac37fb94e3a7621570521d4490915b6c02 100644 (file)
@@ -20,7 +20,7 @@
 #include <linux/cdev.h>
 
 #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)
index 4f4daf8db954330605a4788a4cd3bb161e194389..c912b5a678e4270010359cd13f9fba01744de906 100644 (file)
@@ -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 \