Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI/switchtec: Add Gen4 flash information interface support

Add the new flash_info registers struct and the implementation of
ioctl_flash_part_info() for the new Gen4 hardware.

[logang@deltatee.com: rewrote commit message]
Link: https://lore.kernel.org/r/20200115035648.2578-7-logang@deltatee.com
Signed-off-by: Kelvin Cao <kelvin.cao@microchip.com>
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

authored by

Kelvin Cao and committed by
Bjorn Helgaas
4efa1d2e a3321ca3

+171
+111
drivers/pci/switch/switchtec.c
··· 600 600 if (stdev->gen == SWITCHTEC_GEN3) { 601 601 info.flash_length = ioread32(&fi->gen3.flash_length); 602 602 info.num_partitions = SWITCHTEC_NUM_PARTITIONS_GEN3; 603 + } else if (stdev->gen == SWITCHTEC_GEN4) { 604 + info.flash_length = ioread32(&fi->gen4.flash_length); 605 + info.num_partitions = SWITCHTEC_NUM_PARTITIONS_GEN4; 603 606 } else { 604 607 return -ENOTSUPP; 605 608 } ··· 690 687 return 0; 691 688 } 692 689 690 + static int flash_part_info_gen4(struct switchtec_dev *stdev, 691 + struct switchtec_ioctl_flash_part_info *info) 692 + { 693 + struct flash_info_regs_gen4 __iomem *fi = &stdev->mmio_flash_info->gen4; 694 + struct sys_info_regs_gen4 __iomem *si = &stdev->mmio_sys_info->gen4; 695 + struct active_partition_info_gen4 __iomem *af = &fi->active_flag; 696 + 697 + switch (info->flash_partition) { 698 + case SWITCHTEC_IOCTL_PART_MAP_0: 699 + set_fw_info_part(info, &fi->map0); 700 + break; 701 + case SWITCHTEC_IOCTL_PART_MAP_1: 702 + set_fw_info_part(info, &fi->map1); 703 + break; 704 + case SWITCHTEC_IOCTL_PART_KEY_0: 705 + set_fw_info_part(info, &fi->key0); 706 + if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY0_ACTIVE) 707 + info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; 708 + if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY0_RUNNING) 709 + info->active |= SWITCHTEC_IOCTL_PART_RUNNING; 710 + break; 711 + case SWITCHTEC_IOCTL_PART_KEY_1: 712 + set_fw_info_part(info, &fi->key1); 713 + if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY1_ACTIVE) 714 + info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; 715 + if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY1_RUNNING) 716 + info->active |= SWITCHTEC_IOCTL_PART_RUNNING; 717 + break; 718 + case SWITCHTEC_IOCTL_PART_BL2_0: 719 + set_fw_info_part(info, &fi->bl2_0); 720 + if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_0_ACTIVE) 721 + info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; 722 + if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_0_RUNNING) 723 + info->active |= SWITCHTEC_IOCTL_PART_RUNNING; 724 + break; 725 + case SWITCHTEC_IOCTL_PART_BL2_1: 726 + set_fw_info_part(info, &fi->bl2_1); 727 + if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_1_ACTIVE) 728 + info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; 729 + if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_1_RUNNING) 730 + info->active |= SWITCHTEC_IOCTL_PART_RUNNING; 731 + break; 732 + case SWITCHTEC_IOCTL_PART_CFG0: 733 + set_fw_info_part(info, &fi->cfg0); 734 + if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG0_ACTIVE) 735 + info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; 736 + if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG0_RUNNING) 737 + info->active |= SWITCHTEC_IOCTL_PART_RUNNING; 738 + break; 739 + case SWITCHTEC_IOCTL_PART_CFG1: 740 + set_fw_info_part(info, &fi->cfg1); 741 + if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG1_ACTIVE) 742 + info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; 743 + if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG1_RUNNING) 744 + info->active |= SWITCHTEC_IOCTL_PART_RUNNING; 745 + break; 746 + case SWITCHTEC_IOCTL_PART_IMG0: 747 + set_fw_info_part(info, &fi->img0); 748 + if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG0_ACTIVE) 749 + info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; 750 + if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG0_RUNNING) 751 + info->active |= SWITCHTEC_IOCTL_PART_RUNNING; 752 + break; 753 + case SWITCHTEC_IOCTL_PART_IMG1: 754 + set_fw_info_part(info, &fi->img1); 755 + if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG1_ACTIVE) 756 + info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; 757 + if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG1_RUNNING) 758 + info->active |= SWITCHTEC_IOCTL_PART_RUNNING; 759 + break; 760 + case SWITCHTEC_IOCTL_PART_NVLOG: 761 + set_fw_info_part(info, &fi->nvlog); 762 + break; 763 + case SWITCHTEC_IOCTL_PART_VENDOR0: 764 + set_fw_info_part(info, &fi->vendor[0]); 765 + break; 766 + case SWITCHTEC_IOCTL_PART_VENDOR1: 767 + set_fw_info_part(info, &fi->vendor[1]); 768 + break; 769 + case SWITCHTEC_IOCTL_PART_VENDOR2: 770 + set_fw_info_part(info, &fi->vendor[2]); 771 + break; 772 + case SWITCHTEC_IOCTL_PART_VENDOR3: 773 + set_fw_info_part(info, &fi->vendor[3]); 774 + break; 775 + case SWITCHTEC_IOCTL_PART_VENDOR4: 776 + set_fw_info_part(info, &fi->vendor[4]); 777 + break; 778 + case SWITCHTEC_IOCTL_PART_VENDOR5: 779 + set_fw_info_part(info, &fi->vendor[5]); 780 + break; 781 + case SWITCHTEC_IOCTL_PART_VENDOR6: 782 + set_fw_info_part(info, &fi->vendor[6]); 783 + break; 784 + case SWITCHTEC_IOCTL_PART_VENDOR7: 785 + set_fw_info_part(info, &fi->vendor[7]); 786 + break; 787 + default: 788 + return -EINVAL; 789 + } 790 + 791 + return 0; 792 + } 793 + 693 794 static int ioctl_flash_part_info(struct switchtec_dev *stdev, 694 795 struct switchtec_ioctl_flash_part_info __user *uinfo) 695 796 { ··· 805 698 806 699 if (stdev->gen == SWITCHTEC_GEN3) { 807 700 ret = flash_part_info_gen3(stdev, &info); 701 + if (ret) 702 + return ret; 703 + } else if (stdev->gen == SWITCHTEC_GEN4) { 704 + ret = flash_part_info_gen4(stdev, &info); 808 705 if (ret) 809 706 return ret; 810 707 } else {
+52
include/linux/switchtec.h
··· 109 109 SWITCHTEC_GEN3_IMG1_RUNNING = 0x07, 110 110 }; 111 111 112 + enum { 113 + SWITCHTEC_GEN4_MAP0_RUNNING = 0x00, 114 + SWITCHTEC_GEN4_MAP1_RUNNING = 0x01, 115 + SWITCHTEC_GEN4_KEY0_RUNNING = 0x02, 116 + SWITCHTEC_GEN4_KEY1_RUNNING = 0x03, 117 + SWITCHTEC_GEN4_BL2_0_RUNNING = 0x04, 118 + SWITCHTEC_GEN4_BL2_1_RUNNING = 0x05, 119 + SWITCHTEC_GEN4_CFG0_RUNNING = 0x06, 120 + SWITCHTEC_GEN4_CFG1_RUNNING = 0x07, 121 + SWITCHTEC_GEN4_IMG0_RUNNING = 0x08, 122 + SWITCHTEC_GEN4_IMG1_RUNNING = 0x09, 123 + }; 124 + 125 + enum { 126 + SWITCHTEC_GEN4_KEY0_ACTIVE = 0, 127 + SWITCHTEC_GEN4_KEY1_ACTIVE = 1, 128 + SWITCHTEC_GEN4_BL2_0_ACTIVE = 0, 129 + SWITCHTEC_GEN4_BL2_1_ACTIVE = 1, 130 + SWITCHTEC_GEN4_CFG0_ACTIVE = 0, 131 + SWITCHTEC_GEN4_CFG1_ACTIVE = 1, 132 + SWITCHTEC_GEN4_IMG0_ACTIVE = 0, 133 + SWITCHTEC_GEN4_IMG1_ACTIVE = 1, 134 + }; 135 + 112 136 struct sys_info_regs_gen3 { 113 137 u32 reserved1; 114 138 u32 vendor_table_revision; ··· 229 205 struct partition_info vendor[8]; 230 206 }; 231 207 208 + struct flash_info_regs_gen4 { 209 + u32 flash_address; 210 + u32 flash_length; 211 + 212 + struct active_partition_info_gen4 { 213 + unsigned char bl2; 214 + unsigned char cfg; 215 + unsigned char img; 216 + unsigned char key; 217 + } active_flag; 218 + 219 + u32 reserved[3]; 220 + 221 + struct partition_info map0; 222 + struct partition_info map1; 223 + struct partition_info key0; 224 + struct partition_info key1; 225 + struct partition_info bl2_0; 226 + struct partition_info bl2_1; 227 + struct partition_info cfg0; 228 + struct partition_info cfg1; 229 + struct partition_info img0; 230 + struct partition_info img1; 231 + struct partition_info nvlog; 232 + struct partition_info vendor[8]; 233 + }; 234 + 232 235 struct flash_info_regs { 233 236 union { 234 237 struct flash_info_regs_gen3 gen3; 238 + struct flash_info_regs_gen4 gen4; 235 239 }; 236 240 }; 237 241
+8
include/uapi/linux/switchtec_ioctl.h
··· 32 32 #define SWITCHTEC_IOCTL_PART_VENDOR5 10 33 33 #define SWITCHTEC_IOCTL_PART_VENDOR6 11 34 34 #define SWITCHTEC_IOCTL_PART_VENDOR7 12 35 + #define SWITCHTEC_IOCTL_PART_BL2_0 13 36 + #define SWITCHTEC_IOCTL_PART_BL2_1 14 37 + #define SWITCHTEC_IOCTL_PART_MAP_0 15 38 + #define SWITCHTEC_IOCTL_PART_MAP_1 16 39 + #define SWITCHTEC_IOCTL_PART_KEY_0 17 40 + #define SWITCHTEC_IOCTL_PART_KEY_1 18 41 + 35 42 #define SWITCHTEC_NUM_PARTITIONS_GEN3 13 43 + #define SWITCHTEC_NUM_PARTITIONS_GEN4 19 36 44 37 45 /* obsolete: for compatibility with old userspace software */ 38 46 #define SWITCHTEC_IOCTL_NUM_PARTITIONS SWITCHTEC_NUM_PARTITIONS_GEN3