History

PCI/switchtec: Separate Gen3 register structures into unions

Since the sys_info and flash_info registers differ significantly in Gen4 hardware, separate out the Gen3 registers into their own structure with a union in the main structure. No functional changes intended.

Logan Gunthorpe committed 6 years ago

Commit 993d2081 parent 6a3d1b52 files · +54 −25Browse files

Unified · Split

2 files
  1. drivers/pci/switch/switchtec.c +27 −11
  2. include/linux/switchtec.h +27 −14
drivers/pci/switch/switchtec.c+27−11
@@ -317,8 +317,12 @@ static ssize_t field ## _show(struct device *dev, \ · 316 unmodified lines
317317 struct device_attribute *attr, char *buf) \
318318 { \
319319 struct switchtec_dev *stdev = to_stdev(dev); \
320− return io_string_show(buf, &stdev->mmio_sys_info->field, \
321− sizeof(stdev->mmio_sys_info->field)); \
320+ struct sys_info_regs __iomem *si = stdev->mmio_sys_info; \
321+ if (stdev->gen == SWITCHTEC_GEN3) \
322+ return io_string_show(buf, &si->gen3.field, \
323+ sizeof(si->gen3.field)); \
324+ else \
325+ return -ENOTSUPP; \
322326 } \
323327 \
324328 static DEVICE_ATTR_RO(field)
@@ -337,8 +341,8 @@ static ssize_t component_vendor_show(struct device *dev, · 12 unmodified lines
337341 if (stdev->gen != SWITCHTEC_GEN3)
338342 return sprintf(buf, "none\n");
339343
340− return io_string_show(buf, &si->component_vendor,
341− sizeof(si->component_vendor));
344+ return io_string_show(buf, &si->gen3.component_vendor,
345+ sizeof(si->gen3.component_vendor));
342346 }
343347 static DEVICE_ATTR_RO(component_vendor);
344348
@@ -346,7 +350,7 @@ static ssize_t component_id_show(struct device *dev, · 1 unmodified line
346350 struct device_attribute *attr, char *buf)
347351 {
348352 struct switchtec_dev *stdev = to_stdev(dev);
349− int id = ioread16(&stdev->mmio_sys_info->component_id);
353+ int id = ioread16(&stdev->mmio_sys_info->gen3.component_id);
350354
351355 /* component_id field not supported after gen3 */
352356 if (stdev->gen != SWITCHTEC_GEN3)
@@ -360,7 +364,7 @@ static ssize_t component_revision_show(struct device *dev, · 7 unmodified lines
360364 struct device_attribute *attr, char *buf)
361365 {
362366 struct switchtec_dev *stdev = to_stdev(dev);
363− int rev = ioread8(&stdev->mmio_sys_info->component_revision);
367+ int rev = ioread8(&stdev->mmio_sys_info->gen3.component_revision);
364368
365369 /* component_revision field not supported after gen3 */
366370 if (stdev->gen != SWITCHTEC_GEN3)
@@ -590,8 +594,12 @@ static int ioctl_flash_info(struct switchtec_dev *stdev, · 223 unmodified lines
590594 struct switchtec_ioctl_flash_info info = {0};
591595 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info;
592596
593− info.flash_length = ioread32(&fi->flash_length);
594− info.num_partitions = SWITCHTEC_NUM_PARTITIONS_GEN3;
597+ if (stdev->gen == SWITCHTEC_GEN3) {
598+ info.flash_length = ioread32(&fi->gen3.flash_length);
599+ info.num_partitions = SWITCHTEC_NUM_PARTITIONS_GEN3;
600+ } else {
601+ return -ENOTSUPP;
602+ }
595603
596604 if (copy_to_user(uinfo, &info, sizeof(info)))
597605 return -EFAULT;
@@ -609,8 +617,9 @@ static void set_fw_info_part(struct switchtec_ioctl_flash_part_info *info, · 11 unmodified lines
609617 static int flash_part_info_gen3(struct switchtec_dev *stdev,
610618 struct switchtec_ioctl_flash_part_info *info)
611619 {
612− struct flash_info_regs __iomem *fi = stdev->mmio_flash_info;
613− struct sys_info_regs __iomem *si = stdev->mmio_sys_info;
620+ struct flash_info_regs_gen3 __iomem *fi =
621+ &stdev->mmio_flash_info->gen3;
622+ struct sys_info_regs_gen3 __iomem *si = &stdev->mmio_sys_info->gen3;
614623 u32 active_addr = -1;
615624
616625 switch (info->flash_partition) {
@@ -1382,6 +1391,7 @@ static int switchtec_init_pci(struct switchtec_dev *stdev, · 765 unmodified lines
13821391 int rc;
13831392 void __iomem *map;
13841393 unsigned long res_start, res_len;
1394+ u32 __iomem *part_id;
13851395
13861396 rc = pcim_enable_device(pdev);
13871397 if (rc)
@@ -1416,7 +1426,13 @@ static int switchtec_init_pci(struct switchtec_dev *stdev, · 28 unmodified lines
14161426 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET;
14171427 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET;
14181428 stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET;
1419− stdev->partition = ioread8(&stdev->mmio_sys_info->partition_id);
1429+
1430+ if (stdev->gen == SWITCHTEC_GEN3)
1431+ part_id = &stdev->mmio_sys_info->gen3.partition_id;
1432+ else
1433+ return -ENOTSUPP;
1434+
1435+ stdev->partition = ioread8(part_id);
14201436 stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count);
14211437 stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET;
14221438 stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition];
include/linux/switchtec.h+27−14
@@ -108,10 +108,7 @@ enum { · 107 unmodified lines
108108 SWITCHTEC_GEN3_IMG1_RUNNING = 0x07,
109109 };
110110
111−struct sys_info_regs {
112− u32 device_id;
113− u32 device_version;
114− u32 firmware_version;
111+struct sys_info_regs_gen3 {
115112 u32 reserved1;
116113 u32 vendor_table_revision;
117114 u32 table_format_version;
@@ -128,26 +125,36 @@ struct sys_info_regs { · 10 unmodified lines
128125 u8 component_revision;
129126 } __packed;
130127
131−struct flash_info_regs {
128+struct sys_info_regs {
129+ u32 device_id;
130+ u32 device_version;
131+ u32 firmware_version;
132+ union {
133+ struct sys_info_regs_gen3 gen3;
134+ };
135+} __packed;
136+
137+struct partition_info {
138+ u32 address;
139+ u32 length;
140+};
141+
142+struct flash_info_regs_gen3 {
132143 u32 flash_part_map_upd_idx;
133144
134− struct active_partition_info {
145+ struct active_partition_info_gen3 {
135146 u32 address;
136147 u32 build_version;
137148 u32 build_string;
138149 } active_img;
139150
140− struct active_partition_info active_cfg;
141− struct active_partition_info inactive_img;
142− struct active_partition_info inactive_cfg;
151+ struct active_partition_info_gen3 active_cfg;
152+ struct active_partition_info_gen3 inactive_img;
153+ struct active_partition_info_gen3 inactive_cfg;
143154
144155 u32 flash_length;
145156
146− struct partition_info {
147− u32 address;
148− u32 length;
149− } cfg0;
150−
157+ struct partition_info cfg0;
151158 struct partition_info cfg1;
152159 struct partition_info img0;
153160 struct partition_info img1;
@@ -155,6 +162,12 @@ struct flash_info_regs { · 1 unmodified line
155162 struct partition_info vendor[8];
156163 };
157164
165+struct flash_info_regs {
166+ union {
167+ struct flash_info_regs_gen3 gen3;
168+ };
169+};
170+
158171 enum {
159172 SWITCHTEC_NTB_REG_INFO_OFFSET = 0x0000,
160173 SWITCHTEC_NTB_REG_CTRL_OFFSET = 0x4000,