]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/pci/switch/switchtec.c
PCI/switchtec: Separate Gen3 register structures into unions
[linux.git] / drivers / pci / switch / switchtec.c
index 05d4cb49219b3bcbd753ade61999e319828978cf..c4dae075a692511ceae300bc8dfd849c5fa6ba8e 100644 (file)
@@ -317,8 +317,12 @@ static ssize_t field ## _show(struct device *dev, \
        struct device_attribute *attr, char *buf) \
 { \
        struct switchtec_dev *stdev = to_stdev(dev); \
-       return io_string_show(buf, &stdev->mmio_sys_info->field, \
-                           sizeof(stdev->mmio_sys_info->field)); \
+       struct sys_info_regs __iomem *si = stdev->mmio_sys_info; \
+       if (stdev->gen == SWITCHTEC_GEN3) \
+               return io_string_show(buf, &si->gen3.field, \
+                                     sizeof(si->gen3.field)); \
+       else \
+               return -ENOTSUPP; \
 } \
 \
 static DEVICE_ATTR_RO(field)
@@ -326,13 +330,31 @@ static DEVICE_ATTR_RO(field)
 DEVICE_ATTR_SYS_INFO_STR(vendor_id);
 DEVICE_ATTR_SYS_INFO_STR(product_id);
 DEVICE_ATTR_SYS_INFO_STR(product_revision);
-DEVICE_ATTR_SYS_INFO_STR(component_vendor);
+
+static ssize_t component_vendor_show(struct device *dev,
+                                    struct device_attribute *attr, char *buf)
+{
+       struct switchtec_dev *stdev = to_stdev(dev);
+       struct sys_info_regs __iomem *si = stdev->mmio_sys_info;
+
+       /* component_vendor field not supported after gen3 */
+       if (stdev->gen != SWITCHTEC_GEN3)
+               return sprintf(buf, "none\n");
+
+       return io_string_show(buf, &si->gen3.component_vendor,
+                             sizeof(si->gen3.component_vendor));
+}
+static DEVICE_ATTR_RO(component_vendor);
 
 static ssize_t component_id_show(struct device *dev,
        struct device_attribute *attr, char *buf)
 {
        struct switchtec_dev *stdev = to_stdev(dev);
-       int id = ioread16(&stdev->mmio_sys_info->component_id);
+       int id = ioread16(&stdev->mmio_sys_info->gen3.component_id);
+
+       /* component_id field not supported after gen3 */
+       if (stdev->gen != SWITCHTEC_GEN3)
+               return sprintf(buf, "none\n");
 
        return sprintf(buf, "PM%04X\n", id);
 }
@@ -342,7 +364,11 @@ static ssize_t component_revision_show(struct device *dev,
        struct device_attribute *attr, char *buf)
 {
        struct switchtec_dev *stdev = to_stdev(dev);
-       int rev = ioread8(&stdev->mmio_sys_info->component_revision);
+       int rev = ioread8(&stdev->mmio_sys_info->gen3.component_revision);
+
+       /* component_revision field not supported after gen3 */
+       if (stdev->gen != SWITCHTEC_GEN3)
+               return sprintf(buf, "255\n");
 
        return sprintf(buf, "%d\n", rev);
 }
@@ -568,8 +594,12 @@ static int ioctl_flash_info(struct switchtec_dev *stdev,
        struct switchtec_ioctl_flash_info info = {0};
        struct flash_info_regs __iomem *fi = stdev->mmio_flash_info;
 
-       info.flash_length = ioread32(&fi->flash_length);
-       info.num_partitions = SWITCHTEC_IOCTL_NUM_PARTITIONS;
+       if (stdev->gen == SWITCHTEC_GEN3) {
+               info.flash_length = ioread32(&fi->gen3.flash_length);
+               info.num_partitions = SWITCHTEC_NUM_PARTITIONS_GEN3;
+       } else {
+               return -ENOTSUPP;
+       }
 
        if (copy_to_user(uinfo, &info, sizeof(info)))
                return -EFAULT;
@@ -584,75 +614,92 @@ static void set_fw_info_part(struct switchtec_ioctl_flash_part_info *info,
        info->length = ioread32(&pi->length);
 }
 
-static int ioctl_flash_part_info(struct switchtec_dev *stdev,
-       struct switchtec_ioctl_flash_part_info __user *uinfo)
+static int flash_part_info_gen3(struct switchtec_dev *stdev,
+               struct switchtec_ioctl_flash_part_info *info)
 {
-       struct switchtec_ioctl_flash_part_info info = {0};
-       struct flash_info_regs __iomem *fi = stdev->mmio_flash_info;
-       struct sys_info_regs __iomem *si = stdev->mmio_sys_info;
+       struct flash_info_regs_gen3 __iomem *fi =
+               &stdev->mmio_flash_info->gen3;
+       struct sys_info_regs_gen3 __iomem *si = &stdev->mmio_sys_info->gen3;
        u32 active_addr = -1;
 
-       if (copy_from_user(&info, uinfo, sizeof(info)))
-               return -EFAULT;
-
-       switch (info.flash_partition) {
+       switch (info->flash_partition) {
        case SWITCHTEC_IOCTL_PART_CFG0:
                active_addr = ioread32(&fi->active_cfg);
-               set_fw_info_part(&info, &fi->cfg0);
-               if (ioread16(&si->cfg_running) == SWITCHTEC_CFG0_RUNNING)
-                       info.active |= SWITCHTEC_IOCTL_PART_RUNNING;
+               set_fw_info_part(info, &fi->cfg0);
+               if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG0_RUNNING)
+                       info->active |= SWITCHTEC_IOCTL_PART_RUNNING;
                break;
        case SWITCHTEC_IOCTL_PART_CFG1:
                active_addr = ioread32(&fi->active_cfg);
-               set_fw_info_part(&info, &fi->cfg1);
-               if (ioread16(&si->cfg_running) == SWITCHTEC_CFG1_RUNNING)
-                       info.active |= SWITCHTEC_IOCTL_PART_RUNNING;
+               set_fw_info_part(info, &fi->cfg1);
+               if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG1_RUNNING)
+                       info->active |= SWITCHTEC_IOCTL_PART_RUNNING;
                break;
        case SWITCHTEC_IOCTL_PART_IMG0:
                active_addr = ioread32(&fi->active_img);
-               set_fw_info_part(&info, &fi->img0);
-               if (ioread16(&si->img_running) == SWITCHTEC_IMG0_RUNNING)
-                       info.active |= SWITCHTEC_IOCTL_PART_RUNNING;
+               set_fw_info_part(info, &fi->img0);
+               if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG0_RUNNING)
+                       info->active |= SWITCHTEC_IOCTL_PART_RUNNING;
                break;
        case SWITCHTEC_IOCTL_PART_IMG1:
                active_addr = ioread32(&fi->active_img);
-               set_fw_info_part(&info, &fi->img1);
-               if (ioread16(&si->img_running) == SWITCHTEC_IMG1_RUNNING)
-                       info.active |= SWITCHTEC_IOCTL_PART_RUNNING;
+               set_fw_info_part(info, &fi->img1);
+               if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG1_RUNNING)
+                       info->active |= SWITCHTEC_IOCTL_PART_RUNNING;
                break;
        case SWITCHTEC_IOCTL_PART_NVLOG:
-               set_fw_info_part(&info, &fi->nvlog);
+               set_fw_info_part(info, &fi->nvlog);
                break;
        case SWITCHTEC_IOCTL_PART_VENDOR0:
-               set_fw_info_part(&info, &fi->vendor[0]);
+               set_fw_info_part(info, &fi->vendor[0]);
                break;
        case SWITCHTEC_IOCTL_PART_VENDOR1:
-               set_fw_info_part(&info, &fi->vendor[1]);
+               set_fw_info_part(info, &fi->vendor[1]);
                break;
        case SWITCHTEC_IOCTL_PART_VENDOR2:
-               set_fw_info_part(&info, &fi->vendor[2]);
+               set_fw_info_part(info, &fi->vendor[2]);
                break;
        case SWITCHTEC_IOCTL_PART_VENDOR3:
-               set_fw_info_part(&info, &fi->vendor[3]);
+               set_fw_info_part(info, &fi->vendor[3]);
                break;
        case SWITCHTEC_IOCTL_PART_VENDOR4:
-               set_fw_info_part(&info, &fi->vendor[4]);
+               set_fw_info_part(info, &fi->vendor[4]);
                break;
        case SWITCHTEC_IOCTL_PART_VENDOR5:
-               set_fw_info_part(&info, &fi->vendor[5]);
+               set_fw_info_part(info, &fi->vendor[5]);
                break;
        case SWITCHTEC_IOCTL_PART_VENDOR6:
-               set_fw_info_part(&info, &fi->vendor[6]);
+               set_fw_info_part(info, &fi->vendor[6]);
                break;
        case SWITCHTEC_IOCTL_PART_VENDOR7:
-               set_fw_info_part(&info, &fi->vendor[7]);
+               set_fw_info_part(info, &fi->vendor[7]);
                break;
        default:
                return -EINVAL;
        }
 
-       if (info.address == active_addr)
-               info.active |= SWITCHTEC_IOCTL_PART_ACTIVE;
+       if (info->address == active_addr)
+               info->active |= SWITCHTEC_IOCTL_PART_ACTIVE;
+
+       return 0;
+}
+
+static int ioctl_flash_part_info(struct switchtec_dev *stdev,
+               struct switchtec_ioctl_flash_part_info __user *uinfo)
+{
+       int ret;
+       struct switchtec_ioctl_flash_part_info info = {0};
+
+       if (copy_from_user(&info, uinfo, sizeof(info)))
+               return -EFAULT;
+
+       if (stdev->gen == SWITCHTEC_GEN3) {
+               ret = flash_part_info_gen3(stdev, &info);
+               if (ret)
+                       return ret;
+       } else {
+               return -ENOTSUPP;
+       }
 
        if (copy_to_user(uinfo, &info, sizeof(info)))
                return -EFAULT;
@@ -1344,6 +1391,7 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,
        int rc;
        void __iomem *map;
        unsigned long res_start, res_len;
+       u32 __iomem *part_id;
 
        rc = pcim_enable_device(pdev);
        if (rc)
@@ -1378,7 +1426,13 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,
        stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET;
        stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET;
        stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET;
-       stdev->partition = ioread8(&stdev->mmio_sys_info->partition_id);
+
+       if (stdev->gen == SWITCHTEC_GEN3)
+               part_id = &stdev->mmio_sys_info->gen3.partition_id;
+       else
+               return -ENOTSUPP;
+
+       stdev->partition = ioread8(part_id);
        stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count);
        stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET;
        stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition];
@@ -1420,6 +1474,8 @@ static int switchtec_pci_probe(struct pci_dev *pdev,
        if (IS_ERR(stdev))
                return PTR_ERR(stdev);
 
+       stdev->gen = id->driver_data;
+
        rc = switchtec_init_pci(stdev, pdev);
        if (rc)
                goto err_put;
@@ -1467,7 +1523,7 @@ static void switchtec_pci_remove(struct pci_dev *pdev)
        put_device(&stdev->dev);
 }
 
-#define SWITCHTEC_PCI_DEVICE(device_id) \
+#define SWITCHTEC_PCI_DEVICE(device_id, gen) \
        { \
                .vendor     = PCI_VENDOR_ID_MICROSEMI, \
                .device     = device_id, \
@@ -1475,6 +1531,7 @@ static void switchtec_pci_remove(struct pci_dev *pdev)
                .subdevice  = PCI_ANY_ID, \
                .class      = (PCI_CLASS_MEMORY_OTHER << 8), \
                .class_mask = 0xFFFFFFFF, \
+               .driver_data = gen, \
        }, \
        { \
                .vendor     = PCI_VENDOR_ID_MICROSEMI, \
@@ -1483,39 +1540,40 @@ static void switchtec_pci_remove(struct pci_dev *pdev)
                .subdevice  = PCI_ANY_ID, \
                .class      = (PCI_CLASS_BRIDGE_OTHER << 8), \
                .class_mask = 0xFFFFFFFF, \
+               .driver_data = gen, \
        }
 
 static const struct pci_device_id switchtec_pci_tbl[] = {
-       SWITCHTEC_PCI_DEVICE(0x8531),  //PFX 24xG3
-       SWITCHTEC_PCI_DEVICE(0x8532),  //PFX 32xG3
-       SWITCHTEC_PCI_DEVICE(0x8533),  //PFX 48xG3
-       SWITCHTEC_PCI_DEVICE(0x8534),  //PFX 64xG3
-       SWITCHTEC_PCI_DEVICE(0x8535),  //PFX 80xG3
-       SWITCHTEC_PCI_DEVICE(0x8536),  //PFX 96xG3
-       SWITCHTEC_PCI_DEVICE(0x8541),  //PSX 24xG3
-       SWITCHTEC_PCI_DEVICE(0x8542),  //PSX 32xG3
-       SWITCHTEC_PCI_DEVICE(0x8543),  //PSX 48xG3
-       SWITCHTEC_PCI_DEVICE(0x8544),  //PSX 64xG3
-       SWITCHTEC_PCI_DEVICE(0x8545),  //PSX 80xG3
-       SWITCHTEC_PCI_DEVICE(0x8546),  //PSX 96xG3
-       SWITCHTEC_PCI_DEVICE(0x8551),  //PAX 24XG3
-       SWITCHTEC_PCI_DEVICE(0x8552),  //PAX 32XG3
-       SWITCHTEC_PCI_DEVICE(0x8553),  //PAX 48XG3
-       SWITCHTEC_PCI_DEVICE(0x8554),  //PAX 64XG3
-       SWITCHTEC_PCI_DEVICE(0x8555),  //PAX 80XG3
-       SWITCHTEC_PCI_DEVICE(0x8556),  //PAX 96XG3
-       SWITCHTEC_PCI_DEVICE(0x8561),  //PFXL 24XG3
-       SWITCHTEC_PCI_DEVICE(0x8562),  //PFXL 32XG3
-       SWITCHTEC_PCI_DEVICE(0x8563),  //PFXL 48XG3
-       SWITCHTEC_PCI_DEVICE(0x8564),  //PFXL 64XG3
-       SWITCHTEC_PCI_DEVICE(0x8565),  //PFXL 80XG3
-       SWITCHTEC_PCI_DEVICE(0x8566),  //PFXL 96XG3
-       SWITCHTEC_PCI_DEVICE(0x8571),  //PFXI 24XG3
-       SWITCHTEC_PCI_DEVICE(0x8572),  //PFXI 32XG3
-       SWITCHTEC_PCI_DEVICE(0x8573),  //PFXI 48XG3
-       SWITCHTEC_PCI_DEVICE(0x8574),  //PFXI 64XG3
-       SWITCHTEC_PCI_DEVICE(0x8575),  //PFXI 80XG3
-       SWITCHTEC_PCI_DEVICE(0x8576),  //PFXI 96XG3
+       SWITCHTEC_PCI_DEVICE(0x8531, SWITCHTEC_GEN3),  //PFX 24xG3
+       SWITCHTEC_PCI_DEVICE(0x8532, SWITCHTEC_GEN3),  //PFX 32xG3
+       SWITCHTEC_PCI_DEVICE(0x8533, SWITCHTEC_GEN3),  //PFX 48xG3
+       SWITCHTEC_PCI_DEVICE(0x8534, SWITCHTEC_GEN3),  //PFX 64xG3
+       SWITCHTEC_PCI_DEVICE(0x8535, SWITCHTEC_GEN3),  //PFX 80xG3
+       SWITCHTEC_PCI_DEVICE(0x8536, SWITCHTEC_GEN3),  //PFX 96xG3
+       SWITCHTEC_PCI_DEVICE(0x8541, SWITCHTEC_GEN3),  //PSX 24xG3
+       SWITCHTEC_PCI_DEVICE(0x8542, SWITCHTEC_GEN3),  //PSX 32xG3
+       SWITCHTEC_PCI_DEVICE(0x8543, SWITCHTEC_GEN3),  //PSX 48xG3
+       SWITCHTEC_PCI_DEVICE(0x8544, SWITCHTEC_GEN3),  //PSX 64xG3
+       SWITCHTEC_PCI_DEVICE(0x8545, SWITCHTEC_GEN3),  //PSX 80xG3
+       SWITCHTEC_PCI_DEVICE(0x8546, SWITCHTEC_GEN3),  //PSX 96xG3
+       SWITCHTEC_PCI_DEVICE(0x8551, SWITCHTEC_GEN3),  //PAX 24XG3
+       SWITCHTEC_PCI_DEVICE(0x8552, SWITCHTEC_GEN3),  //PAX 32XG3
+       SWITCHTEC_PCI_DEVICE(0x8553, SWITCHTEC_GEN3),  //PAX 48XG3
+       SWITCHTEC_PCI_DEVICE(0x8554, SWITCHTEC_GEN3),  //PAX 64XG3
+       SWITCHTEC_PCI_DEVICE(0x8555, SWITCHTEC_GEN3),  //PAX 80XG3
+       SWITCHTEC_PCI_DEVICE(0x8556, SWITCHTEC_GEN3),  //PAX 96XG3
+       SWITCHTEC_PCI_DEVICE(0x8561, SWITCHTEC_GEN3),  //PFXL 24XG3
+       SWITCHTEC_PCI_DEVICE(0x8562, SWITCHTEC_GEN3),  //PFXL 32XG3
+       SWITCHTEC_PCI_DEVICE(0x8563, SWITCHTEC_GEN3),  //PFXL 48XG3
+       SWITCHTEC_PCI_DEVICE(0x8564, SWITCHTEC_GEN3),  //PFXL 64XG3
+       SWITCHTEC_PCI_DEVICE(0x8565, SWITCHTEC_GEN3),  //PFXL 80XG3
+       SWITCHTEC_PCI_DEVICE(0x8566, SWITCHTEC_GEN3),  //PFXL 96XG3
+       SWITCHTEC_PCI_DEVICE(0x8571, SWITCHTEC_GEN3),  //PFXI 24XG3
+       SWITCHTEC_PCI_DEVICE(0x8572, SWITCHTEC_GEN3),  //PFXI 32XG3
+       SWITCHTEC_PCI_DEVICE(0x8573, SWITCHTEC_GEN3),  //PFXI 48XG3
+       SWITCHTEC_PCI_DEVICE(0x8574, SWITCHTEC_GEN3),  //PFXI 64XG3
+       SWITCHTEC_PCI_DEVICE(0x8575, SWITCHTEC_GEN3),  //PFXI 80XG3
+       SWITCHTEC_PCI_DEVICE(0x8576, SWITCHTEC_GEN3),  //PFXI 96XG3
        {0}
 };
 MODULE_DEVICE_TABLE(pci, switchtec_pci_tbl);