diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/RA-b6010-48gt4x-board.json b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/RA-b6010-48gt4x-board.json deleted file mode 100644 index 80fb222380..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/RA-b6010-48gt4x-board.json +++ /dev/null @@ -1,868 +0,0 @@ -{ - "macleds" : { - "polarity" : 1, - "freq" : 2500, - "interval" : 50000000, - "maps" : [ - { - "port_id" : 0, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port1/brightness" - }, - { - "port_id" : 1, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port2/brightness" - }, - { - "port_id" : 2, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port3/brightness" - }, - { - "port_id" : 3, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port4/brightness" - }, - { - "port_id" : 4, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port5/brightness" - }, - { - "port_id" : 5, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port6/brightness" - }, - { - "port_id" : 6, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port7/brightness" - }, - { - "port_id" : 7, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port8/brightness" - }, - { - "port_id" : 16, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port9/brightness" - }, - { - "port_id" : 17, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port10/brightness" - }, - { - "port_id" : 18, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port11/brightness" - }, - { - "port_id" : 19, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port12/brightness" - }, - { - "port_id" : 20, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port13/brightness" - }, - { - "port_id" : 21, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port14/brightness" - }, - { - "port_id" : 22, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port15/brightness" - }, - { - "port_id" : 23, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port16/brightness" - }, - { - "port_id" : 8, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port17/brightness" - }, - { - "port_id" : 9, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port18/brightness" - }, - { - "port_id" : 10, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port19/brightness" - }, - { - "port_id" : 11, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port20/brightness" - }, - { - "port_id" : 32, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port21/brightness" - }, - { - "port_id" : 33, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port22/brightness" - }, - { - "port_id" : 34, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port23/brightness" - }, - { - "port_id" : 35, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port24/brightness" - }, - { - "port_id" : 36, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port25/brightness" - }, - { - "port_id" : 37, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port26/brightness" - }, - { - "port_id" : 38, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port27/brightness" - }, - { - "port_id" : 39, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port28/brightness" - }, - { - "port_id" : 40, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port29/brightness" - }, - { - "port_id" : 41, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port30/brightness" - }, - { - "port_id" : 42, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port31/brightness" - }, - { - "port_id" : 43, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port32/brightness" - }, - { - "port_id" : 24, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port33/brightness" - }, - { - "port_id" : 25, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port34/brightness" - }, - { - "port_id" : 26, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port35/brightness" - }, - { - "port_id" : 27, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port36/brightness" - }, - { - "port_id" : 48, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port37/brightness" - }, - { - "port_id" : 49, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port38/brightness" - }, - { - "port_id" : 50, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port39/brightness" - }, - { - "port_id" : 51, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port40/brightness" - }, - { - "port_id" : 52, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port41/brightness" - }, - { - "port_id" : 53, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port42/brightness" - }, - { - "port_id" : 54, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port43/brightness" - }, - { - "port_id" : 55, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port44/brightness" - }, - { - "port_id" : 56, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port45/brightness" - }, - { - "port_id" : 57, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port46/brightness" - }, - { - "port_id" : 58, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port47/brightness" - }, - { - "port_id" : 59, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port48/brightness" - }, - { - "port_id" : 12, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port49/brightness" - }, - { - "port_id" : 13, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port50/brightness" - }, - { - "port_id" : 14, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port51/brightness" - }, - { - "port_id" : 15, - "lchip" : 0, - "ctl_id" : 0, - "mode" : "LED_MODE_1_RXLNK_BIACT", - "fixed" : 0, - "sysfs_path" : "/sys/class/leds/port52/brightness" - } - ] - }, - "phys" : [ - { - "macid" : 0, - "busid" : 0, - "addr" : 0, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 1, - "busid" : 0, - "addr" : 1, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 2, - "busid" : 0, - "addr" : 2, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 3, - "busid" : 0, - "addr" : 3, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 4, - "busid" : 0, - "addr" : 4, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 5, - "busid" : 0, - "addr" : 5, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 6, - "busid" : 0, - "addr" : 6, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 7, - "busid" : 0, - "addr" : 7, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 16, - "busid" : 0, - "addr" : 8, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 17, - "busid" : 0, - "addr" : 9, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 18, - "busid" : 0, - "addr" : 10, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 19, - "busid" : 0, - "addr" : 11, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 20, - "busid" : 0, - "addr" : 12, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 21, - "busid" : 0, - "addr" : 13, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 22, - "busid" : 0, - "addr" : 14, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 23, - "busid" : 0, - "addr" : 15, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 8, - "busid" : 0, - "addr" : 16, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 9, - "busid" : 0, - "addr" : 17, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 10, - "busid" : 0, - "addr" : 18, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 11, - "busid" : 0, - "addr" : 19, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 32, - "busid" : 0, - "addr" : 20, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 33, - "busid" : 0, - "addr" : 21, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 34, - "busid" : 0, - "addr" : 22, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 35, - "busid" : 0, - "addr" : 23, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 36, - "busid" : 1, - "addr" : 0, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 37, - "busid" : 1, - "addr" : 1, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 38, - "busid" : 1, - "addr" : 2, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 39, - "busid" : 1, - "addr" : 3, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 40, - "busid" : 1, - "addr" : 4, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 41, - "busid" : 1, - "addr" : 5, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 42, - "busid" : 1, - "addr" : 6, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 43, - "busid" : 1, - "addr" : 7, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 24, - "busid" : 1, - "addr" : 8, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 25, - "busid" : 1, - "addr" : 9, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 26, - "busid" : 1, - "addr" : 10, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 27, - "busid" : 1, - "addr" : 11, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 48, - "busid" : 1, - "addr" : 12, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 49, - "busid" : 1, - "addr" : 13, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 50, - "busid" : 1, - "addr" : 14, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 51, - "busid" : 1, - "addr" : 15, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 52, - "busid" : 1, - "addr" : 16, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 53, - "busid" : 1, - "addr" : 17, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 54, - "busid" : 1, - "addr" : 18, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 55, - "busid" : 1, - "addr" : 19, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 56, - "busid" : 1, - "addr" : 20, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 57, - "busid" : 1, - "addr" : 21, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 58, - "busid" : 1, - "addr" : 22, - "base_port": 1, - "last_port": 4 - }, - { - "macid" : 59, - "busid" : 1, - "addr" : 23, - "base_port": 1, - "last_port": 4 - } - ], - "ffe" : { - "board_material" : "BOARD_MATERIAL_M4", - "config" : [ - { - "serdes_id" : [0], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [0, 255, 10, 0] - }, - { - "serdes_id" : [1], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [0, 240, 10, 0] - }, - { - "serdes_id" : [2], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [0, 230, 10, 0] - }, - { - "serdes_id" : [3], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [0, 220, 7, 0] - }, - { - "serdes_id" : [4], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [0, 220, 8, 0] - }, - { - "serdes_id" : [5], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [0, 210, 6, 0] - }, - { - "serdes_id" : [6], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [0, 180, 6, 0] - }, - { - "serdes_id" : [7], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [0, 180, 5, 0] - }, - { - "serdes_id" : [8], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [2, 160, 4, 0] - }, - { - "serdes_id" : [9], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [2, 160, 4, 0] - }, - { - "serdes_id" : [10], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [3, 140, 9, 0] - }, - { - "serdes_id" : [11], - "is_dac" : 0, - "speed" : [1000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [3, 140, 5, 0] - }, - { - "serdes_id" : [12, 13, 14, 15], - "is_dac" : 0, - "speed" : [10000], - "mode" : "CTC_CHIP_SERDES_FFE_MODE_DEFINE", - "cfg" : [3, 94, 15, 0] - } - ] - }, - "ctle" : { - "config" : [ - { - "serdes_id" : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], - "auto-en" : 0, - "cfg" : [6, 14, 2] - } - ] - } -} diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/RA-b6010-48gt4x-p-chip-profile.txt b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/RA-b6010-48gt4x-p-chip-profile.txt deleted file mode 100644 index 2373e27f5f..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/RA-b6010-48gt4x-p-chip-profile.txt +++ /dev/null @@ -1,96 +0,0 @@ -#----------------- SDK Feature Support -------------- -[MPLS_SUPPORT] = 1; -[APS_SUPPORT] = 1; -[OAM_SUPPORT] = 1; -[PTP_SUPPORT] = 0; -[SYNCE_SUPPORT] = 0; -[STACKING_SUPPORT] = 1; -[BPE_SUPPORT] = 0; -[IPFIX_SUPPORT] = 1; -[MONITOR_SUPPORT] = 1; -[OVERLAY_SUPPORT] = 1; -[EFD_SUPPORT] = 1; -[FCOE_SUPPORT] = 0; -[TRILL_SUPPORT] = 0; -[WLAN_SUPPORT] = 1; -[NPM_SUPPORT] = 1; -[DOT1AE_SUPPORT] = 1; - -#----------------- Chip Init Parameter -------------- -#Local chip number and global chip id -[Local chip_num] = 1 -[Local chip0] = 0 -[Local chip1] = 1 - -#Cut through mode 0: Disable; 1:10/40/100G; 2:1/10/100G; 3:1/10/40G; other:Flex, refer to CUT_THROUGH_BITMAP -[CUT_THROUGH_SPEED] = 0 -#Flex cut through mode, speed enable by bitmap, refer to ctc_port_speed_t, Notice: 10M/100M/1G treat as the same speed -[CUT_THROUGH_BITMAP] = 0 - -#Network cpu port -[CPU_NETWORK_PORT_EN] = 0 -[CPU_NETWORK_PORT_ID] = 47 - -#Enable parity error and multi-bit ecc recover -[ECC_RECOVER_EN] = 0 -[TCAM_SCAN_EN] = 0 - -#----------------- Interrupt Init Parameter -------------- -#0: pin, 1: msi -[Interrupt_mode] = 0 -[IRQ] = 69 - -#----------------- NextHop Init Parameter -------------- -#0: SDK work in pizzbox (single chip system), 1: SDK work in multi-chip system -[Nexthop Edit Mode] = 0 -[External Nexthop Number] = 16384 -[MPLS Tunnel Number] = 1024 - -#----------------- L2 Init Parameter -------------- -[FDB Hw Learning] = 1 -[Logic Port Num] = 1024 -#0: 128 instance per port, 1: 64 instance per port, 2: 32 instance per port -[STP MODE] = 0 -[MAX_FID_NUM] = 5120 - -#----------------- Stats Init Parameter -------------- -[STATS_PORT_EN] = 0 -[STATS_ECMP_EN] = 0 - -#----------------- BPE Init Parameter -------------- -[BPE_BR_PORT_EXTENDER_EN] = 0 -[BPE_BR_UC_MAX_ECID] = 1024 -[BPE_BR_MC_MAX_ECID] = 4096 -[BPE_BR_PORT_BASE] = 0 - -#----------------- Ipuc Init Parameter -------------- -#0: tcam use prefix 16; 1: tcam use prefix 8 -[IPUC_TCAM_PREFIX_8] = 1 - -#----------------- QoS Init Parameter -------------- -#QoS policer number support 1K/2K/4K/8K, default 4K -[QOS_POLICER_NUM] = 4096 -#QoS port queue number support 16/8/8 BPE/4 BPE, -#When resrc_profile.cfg exist, queue number valid, -#Default 8 queue mode -#8 queue = 8 -#16 queue = 16 -#4 queue BPE = 17 -#8 queue BPE = 18 -[QOS_PORT_QUEUE_NUM] = 8 -#QoS port extend queue number support 0/4, default 0 -[QOS_PORT_EXT_QUEUE_NUM] = 0 -#QoS CPU reason queue number support 128/64/32, default 128 -[QOS_CPU_QUEUE_NUM] = 128 -[QOS_INGRESS_VLAN_POLICER_NUM] = 0 -[QOS_EGRESS_VLAN_POLICER_NUM] = 0 -[QOS_POLICER_MERGE_MODE] = 0 -#QOS service queue mode, default 0,0:logic scr port + dstport enq 1:service id + dstport enq -[QOS_SERVICE_QUEUE_MODE] = 0 -#Global enable logic dst port + dstport enq -[QOS_SERVICE_QUEUE_EGRESS_EN] = 0 - -#----------------- Stacking Init Parameter -------------- -#0: normal mode; 1: spine-leaf mode -[FABRIC MODE] = 0 -[STACKING VERSION] = 1 diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/RA-b6010-48gt4x-p-datapath.txt b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/RA-b6010-48gt4x-p-datapath.txt deleted file mode 100644 index 959b97a150..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/RA-b6010-48gt4x-p-datapath.txt +++ /dev/null @@ -1,281 +0,0 @@ -#Generated by 'CTC DataPath Tools' on Fri Dec 18 19:15:31 2020 -#Version 1.0, Supported by TsingMa SDK - - -#SERDES_MODE : 0-NONE, 1-XFI, 2-SGMII, 3-Not Support, 4-QSGMII, 5-XAUI, 6-DXAUI, 7-XLG, 8-CG, 9-SGMII2G5 -# 10-USXGMII-S, 11-USXGMII-M2G5, 12-USXGMII-M5G, 13-XXVG, 14-LG, 15-100BASE-FX -#SERDES_RX_POLY: 0-Normal, 1-Inverse -#SERDES_SWITCH : 0-Not Support Dynamic Switch, 1-Support Dynamic Switch - -[WLAN_ENABLE] = 1 -[DOT1AE_ENABLE] = 1 - -[CORE_PLLA] = 600 -#{ -[SERDES_ITEM] -#repeat 32 step 6 -[SERDES_ID] = 0 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 1 -[SERDES_TX_POLY] = 1 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 1 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 2 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 1 -[SERDES_TX_POLY] = 1 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 3 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 4 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 5 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 6 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 7 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 1 -[SERDES_TX_POLY] = 1 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 8 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 1 -[SERDES_TX_POLY] = 1 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 9 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 10 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 11 -[SERDES_MODE] = 4 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 12 -[SERDES_MODE] = 1 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 1 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 13 -[SERDES_MODE] = 1 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 1 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 14 -[SERDES_MODE] = 1 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 1 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 15 -[SERDES_MODE] = 1 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 1 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 16 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 17 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 18 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 19 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 20 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 21 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 22 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 23 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 24 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 25 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 26 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 1 - -[SERDES_ID] = 27 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 1 - -[SERDES_ID] = 28 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 29 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 0 - -[SERDES_ID] = 30 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 1 - -[SERDES_ID] = 31 -[SERDES_MODE] = 3 -[SERDES_RX_POLY] = 0 -[SERDES_TX_POLY] = 0 -[SERDES_SWITCH] = 0 -[SERDES_GROUP] = 1 - -#repeat end -#} - - -#[SERDES_TO_LPORT] -#{ -# | QSGMII/USXGMII-M2G5 | USXGMII-M5G | USXGMII-S | 100BASE-FX | SGMII/SGMII2G5/XFI | XAUI/DXAUI | XLG | XXVG | LG | CG -#---------|---------------------|-------------|-----------|------------|--------------------|------------|-----|------|----|--- -#serdes 0 |0 /1 /2 /3 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 1 |4 /5 /6 /7 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 2 |16/17/18/19 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 3 |20/21/22/23 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 4 |8 /9 /10/11 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 5 |32/33/34/35 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 6 |36/37/38/39 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 7 |40/41/42/43 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 8 |24/25/26/27 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 9 |48/49/50/51 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 10|52/53/54/55 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 11|56/57/58/59 |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 12|NA |NA |NA |12 |12 |12 |12 |NA |NA |NA -#serdes 13|NA |NA |NA |13 |13 |12 |12 |NA |NA |NA -#serdes 14|NA |NA |NA |14 |14 |12 |12 |NA |NA |NA -#serdes 15|NA |NA |NA |15 |15 |12 |12 |NA |NA |NA -#serdes 16|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 17|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 18|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 19|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 20|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 21|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 22|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 23|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 24|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 25|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 26|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 27|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 28|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 29|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 30|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#serdes 31|NA |NA |NA |NA |NA |NA |NA |NA |NA |NA -#} diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/default_sku b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/default_sku deleted file mode 100644 index 2a8d51c1f2..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/default_sku +++ /dev/null @@ -1 +0,0 @@ -RA-B6010-48GT4X l1 diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/phy_mapping.cfg b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/phy_mapping.cfg deleted file mode 100644 index eefd67e9c2..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/phy_mapping.cfg +++ /dev/null @@ -1,198 +0,0 @@ -#######################PHY_MAPPING_48+4####################### - -#{ -[PHY_MAPPING_ITEM] - -[API_PORT] = 0 -[PHY_ADDR] = 0 -[MDIO_BUS] = 0 - -[API_PORT] = 1 -[PHY_ADDR] = 1 -[MDIO_BUS] = 0 - -[API_PORT] = 2 -[PHY_ADDR] = 2 -[MDIO_BUS] = 0 - -[API_PORT] = 3 -[PHY_ADDR] = 3 -[MDIO_BUS] = 0 - -[API_PORT] = 4 -[PHY_ADDR] = 4 -[MDIO_BUS] = 0 - -[API_PORT] = 5 -[PHY_ADDR] = 5 -[MDIO_BUS] = 0 - -[API_PORT] = 6 -[PHY_ADDR] = 6 -[MDIO_BUS] = 0 - -[API_PORT] = 7 -[PHY_ADDR] = 7 -[MDIO_BUS] = 0 - -[API_PORT] = 16 -[PHY_ADDR] = 8 -[MDIO_BUS] = 0 - -[API_PORT] = 17 -[PHY_ADDR] = 9 -[MDIO_BUS] = 0 - -[API_PORT] = 18 -[PHY_ADDR] = 10 -[MDIO_BUS] = 0 - -[API_PORT] = 19 -[PHY_ADDR] = 11 -[MDIO_BUS] = 0 - -[API_PORT] = 20 -[PHY_ADDR] = 12 -[MDIO_BUS] = 0 - -[API_PORT] = 21 -[PHY_ADDR] = 13 -[MDIO_BUS] = 0 - -[API_PORT] = 22 -[PHY_ADDR] = 14 -[MDIO_BUS] = 0 - -[API_PORT] = 23 -[PHY_ADDR] = 15 -[MDIO_BUS] = 0 - -[API_PORT] = 8 -[PHY_ADDR] = 16 -[MDIO_BUS] = 0 - -[API_PORT] = 9 -[PHY_ADDR] = 17 -[MDIO_BUS] = 0 - -[API_PORT] = 10 -[PHY_ADDR] = 18 -[MDIO_BUS] = 0 - -[API_PORT] = 11 -[PHY_ADDR] = 19 -[MDIO_BUS] = 0 - -[API_PORT] = 32 -[PHY_ADDR] = 20 -[MDIO_BUS] = 0 - -[API_PORT] = 33 -[PHY_ADDR] = 21 -[MDIO_BUS] = 0 - -[API_PORT] = 34 -[PHY_ADDR] = 22 -[MDIO_BUS] = 0 - -[API_PORT] = 35 -[PHY_ADDR] = 23 -[MDIO_BUS] = 0 - -[API_PORT] = 36 -[PHY_ADDR] = 0 -[MDIO_BUS] = 1 - -[API_PORT] = 37 -[PHY_ADDR] = 1 -[MDIO_BUS] = 1 - -[API_PORT] = 38 -[PHY_ADDR] = 2 -[MDIO_BUS] = 1 - -[API_PORT] = 39 -[PHY_ADDR] = 3 -[MDIO_BUS] = 1 - -[API_PORT] = 40 -[PHY_ADDR] = 4 -[MDIO_BUS] = 1 - -[API_PORT] = 41 -[PHY_ADDR] = 5 -[MDIO_BUS] = 1 - -[API_PORT] = 42 -[PHY_ADDR] = 6 -[MDIO_BUS] = 1 - -[API_PORT] = 43 -[PHY_ADDR] = 7 -[MDIO_BUS] = 1 - -[API_PORT] = 24 -[PHY_ADDR] = 8 -[MDIO_BUS] = 1 - -[API_PORT] = 25 -[PHY_ADDR] = 9 -[MDIO_BUS] = 1 - -[API_PORT] = 26 -[PHY_ADDR] = 10 -[MDIO_BUS] = 1 - -[API_PORT] = 27 -[PHY_ADDR] = 11 -[MDIO_BUS] = 1 - -[API_PORT] = 48 -[PHY_ADDR] = 12 -[MDIO_BUS] = 1 - -[API_PORT] = 49 -[PHY_ADDR] = 13 -[MDIO_BUS] = 1 - -[API_PORT] = 50 -[PHY_ADDR] = 14 -[MDIO_BUS] = 1 - -[API_PORT] = 51 -[PHY_ADDR] = 15 -[MDIO_BUS] = 1 - -[API_PORT] = 52 -[PHY_ADDR] = 16 -[MDIO_BUS] = 1 - -[API_PORT] = 53 -[PHY_ADDR] = 17 -[MDIO_BUS] = 1 - -[API_PORT] = 54 -[PHY_ADDR] = 18 -[MDIO_BUS] = 1 - -[API_PORT] = 55 -[PHY_ADDR] = 19 -[MDIO_BUS] = 1 - -[API_PORT] = 56 -[PHY_ADDR] = 20 -[MDIO_BUS] = 1 - -[API_PORT] = 57 -[PHY_ADDR] = 21 -[MDIO_BUS] = 1 - -[API_PORT] = 58 -[PHY_ADDR] = 22 -[MDIO_BUS] = 1 - -[API_PORT] = 59 -[PHY_ADDR] = 23 -[MDIO_BUS] = 1 - -#} diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/platform_asic b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/platform_asic deleted file mode 100644 index 0815c8a78c..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/platform_asic +++ /dev/null @@ -1 +0,0 @@ -centec-arm64 diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/port_config.ini b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/port_config.ini deleted file mode 100644 index cd9f488c53..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/port_config.ini +++ /dev/null @@ -1,53 +0,0 @@ -# name lanes alias index speed admin_status -Ethernet1 0 eth-0-1 1 1000 up -Ethernet2 1 eth-0-2 2 1000 up -Ethernet3 2 eth-0-3 3 1000 up -Ethernet4 3 eth-0-4 4 1000 up -Ethernet5 4 eth-0-5 5 1000 up -Ethernet6 5 eth-0-6 6 1000 up -Ethernet7 6 eth-0-7 7 1000 up -Ethernet8 7 eth-0-8 8 1000 up -Ethernet9 16 eth-0-9 9 1000 up -Ethernet10 17 eth-0-10 10 1000 up -Ethernet11 18 eth-0-11 11 1000 up -Ethernet12 19 eth-0-12 12 1000 up -Ethernet13 20 eth-0-13 13 1000 up -Ethernet14 21 eth-0-14 14 1000 up -Ethernet15 22 eth-0-15 15 1000 up -Ethernet16 23 eth-0-16 16 1000 up -Ethernet17 8 eth-0-17 17 1000 up -Ethernet18 9 eth-0-18 18 1000 up -Ethernet19 10 eth-0-19 19 1000 up -Ethernet20 11 eth-0-20 20 1000 up -Ethernet21 32 eth-0-21 21 1000 up -Ethernet22 33 eth-0-22 22 1000 up -Ethernet23 34 eth-0-23 23 1000 up -Ethernet24 35 eth-0-24 24 1000 up -Ethernet25 36 eth-0-25 25 1000 up -Ethernet26 37 eth-0-26 26 1000 up -Ethernet27 38 eth-0-27 27 1000 up -Ethernet28 39 eth-0-28 28 1000 up -Ethernet29 40 eth-0-29 29 1000 up -Ethernet30 41 eth-0-30 30 1000 up -Ethernet31 42 eth-0-31 31 1000 up -Ethernet32 43 eth-0-32 32 1000 up -Ethernet33 24 eth-0-33 33 1000 up -Ethernet34 25 eth-0-34 34 1000 up -Ethernet35 26 eth-0-35 35 1000 up -Ethernet36 27 eth-0-36 36 1000 up -Ethernet37 48 eth-0-37 37 1000 up -Ethernet38 49 eth-0-38 38 1000 up -Ethernet39 50 eth-0-39 39 1000 up -Ethernet40 51 eth-0-40 40 1000 up -Ethernet41 52 eth-0-41 41 1000 up -Ethernet42 53 eth-0-42 42 1000 up -Ethernet43 54 eth-0-43 43 1000 up -Ethernet44 55 eth-0-44 44 1000 up -Ethernet45 56 eth-0-45 45 1000 up -Ethernet46 57 eth-0-46 46 1000 up -Ethernet47 58 eth-0-47 47 1000 up -Ethernet48 59 eth-0-48 48 1000 up -Ethernet49 12 eth-0-49 49 10000 up -Ethernet50 13 eth-0-50 50 10000 up -Ethernet51 14 eth-0-51 51 10000 up -Ethernet52 15 eth-0-52 52 10000 up diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/sai.profile b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/sai.profile deleted file mode 100644 index 5a5fe93dd4..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/sai.profile +++ /dev/null @@ -1,4 +0,0 @@ -SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/RA-b6010-48gt4x-p-chip-profile.txt -SAI_HW_PORT_PROFILE_ID_CONFIG_FILE=/usr/share/sonic/hwsku/RA-b6010-48gt4x-p-datapath.txt -SAI_PLATFORM_CFG_FILE=/usr/share/sonic/hwsku/RA-b6010-48gt4x-board.json -SAI_PHY_DRIVER_PATH=/usr/share/sonic/hwsku/phy_drv \ No newline at end of file diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/start_up.cfg b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/start_up.cfg deleted file mode 100644 index b012adedb2..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X/start_up.cfg +++ /dev/null @@ -1,48 +0,0 @@ - -chip set serdes 0 ffe mode user-define c0 0 c1 255 c2 10 c3 0 c4 0 -chip set serdes 1 ffe mode user-define c0 0 c1 240 c2 10 c3 0 c4 0 -chip set serdes 2 ffe mode user-define c0 0 c1 230 c2 10 c3 0 c4 0 -chip set serdes 3 ffe mode user-define c0 0 c1 220 c2 7 c3 0 c4 0 -chip set serdes 4 ffe mode user-define c0 0 c1 220 c2 8 c3 0 c4 0 -chip set serdes 5 ffe mode user-define c0 0 c1 210 c2 6 c3 0 c4 0 -chip set serdes 6 ffe mode user-define c0 0 c1 180 c2 6 c3 0 c4 0 -chip set serdes 7 ffe mode user-define c0 0 c1 180 c2 5 c3 0 c4 0 -chip set serdes 8 ffe mode user-define c0 2 c1 160 c2 4 c3 0 c4 0 -chip set serdes 9 ffe mode user-define c0 2 c1 160 c2 4 c3 0 c4 0 -chip set serdes 10 ffe mode user-define c0 3 c1 140 c2 9 c3 0 c4 0 -chip set serdes 11 ffe mode user-define c0 3 c1 140 c2 5 c3 0 c4 0 -chip set serdes 12 ffe mode user-define c0 3 c1 94 c2 15 c3 0 c4 0 -chip set serdes 13 ffe mode user-define c0 3 c1 94 c2 15 c3 0 c4 0 -chip set serdes 14 ffe mode user-define c0 3 c1 94 c2 15 c3 0 c4 0 -chip set serdes 15 ffe mode user-define c0 3 c1 94 c2 15 c3 0 c4 0 - - -chip set serdes 0 ctle 6 14 2 -chip set serdes 1 ctle 6 14 2 -chip set serdes 2 ctle 6 14 2 -chip set serdes 3 ctle 6 14 2 -chip set serdes 4 ctle 6 14 2 -chip set serdes 5 ctle 6 14 2 -chip set serdes 6 ctle 6 14 2 -chip set serdes 7 ctle 6 14 2 -chip set serdes 8 ctle 6 14 2 -chip set serdes 9 ctle 6 14 2 -chip set serdes 10 ctle 6 14 2 -chip set serdes 11 ctle 6 14 2 - - - -# rtk eye param, post_amp|main_amp|pre_amp -port 0 phy-attr type 2001 value 0x1c1e00 -port 4 phy-attr type 2001 value 0x101600 -port 16 phy-attr type 2001 value 0x111500 -port 20 phy-attr type 2001 value 0x0e1100 -port 8 phy-attr type 2001 value 0x0f1000 -port 32 phy-attr type 2001 value 0x0e0f00 -port 36 phy-attr type 2001 value 0x0a0a00 -port 40 phy-attr type 2001 value 0x0a0900 -port 24 phy-attr type 2001 value 0x000c00 -port 48 phy-attr type 2001 value 0x000b00 -port 52 phy-attr type 2001 value 0x000b00 -port 56 phy-attr type 2001 value 0x000a00 - diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/default_sku b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/default_sku deleted file mode 100644 index 2a8d51c1f2..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/default_sku +++ /dev/null @@ -1 +0,0 @@ -RA-B6010-48GT4X l1 diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/installer.conf b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/installer.conf deleted file mode 100644 index 6e00c7ff77..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/installer.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONSOLE_SPEED=115200 - -#fix env -config_env(){ - dd if=/dev/mtd1 of=env.bin - flashcp -v env.bin /dev/mtd4 -} -trap_push "config_env || true" - diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/platform.json b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/platform.json deleted file mode 100644 index b3a5623d1c..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/platform.json +++ /dev/null @@ -1,173 +0,0 @@ -{ - "chassis": { - "name": "RA-B6010-48GT4X", - "thermal_manager": false, - "status_led": { - "controllable": false, - "colors": ["green", "blinking_green", "amber", "blinking_amber"] - }, - "components": [ - { - "name": "CPU CPLD" - }, - { - "name": "MAC1 CPLD" - } - ], - "fans": [ - { - "name": "Fantray1_1", - "speed": { - "controllable": true, - "minimum": 30, - "maximum": 99 - }, - "status_led": { - "available": false, - "colors": ["off", "red", "amber", "green"] - } - }, - { - "name": "Fantray2_1", - "speed": { - "controllable": true, - "minimum": 30, - "maximum": 99 - }, - "status_led": { - "available": false, - "colors": ["off", "red", "amber", "green"] - } - } - ], - "fan_drawers":[ - { - "name": "Fantray1", - "num_fans" : 1, - "status_led": { - "controllable": false, - "colors": ["amber", "green", "off"] - }, - "fans": [ - { - "name": "FanTray1_1", - "speed": { - "controllable": true, - "minimum": 30, - "maximum": 99 - }, - "status_led": { - "available": false - } - } - ] - }, - { - "name": "Fantray2", - "num_fans" : 1, - "status_led": { - "controllable": false, - "colors": ["amber", "green", "off"] - }, - "fans": [ - { - "name": "FanTray2_1", - "speed": { - "controllable": true, - "minimum": 30, - "maximum": 99 - }, - "status_led": { - "available": false - } - } - ] - } - ], - "psus": [ - { - "name": "PSU 1", - "voltage": true, - "current": true, - "power": true, - "max_power": false, - "voltage_high_threshold": true, - "voltage_low_threshold": true, - "temperature": true, - "fans_target_speed": false, - "status_led": { - "controllable": false - } - }, - { - "name": "PSU 2", - "voltage": true, - "current": true, - "power": true, - "max_power": false, - "voltage_high_threshold": true, - "voltage_low_threshold": true, - "temperature": true, - "fans_target_speed": false, - "status_led": { - "controllable": false - } - } - ], - "thermals": [ - { - "name": "ASIC_TEMP", - "controllable": false, - "low-crit-threshold": true, - "high-crit-threshold": true, - "low-threshold": true, - "high-threshold": true, - "minimum-recorded": true, - "maximum-recorded": true - }, - { - "name": "CPU_TEMP", - "controllable": false, - "low-crit-threshold": true, - "high-crit-threshold": true, - "low-threshold": true, - "high-threshold": true, - "minimum-recorded": true, - "maximum-recorded": true - }, - { - "name": "INLET_TEMP", - "controllable": false, - "low-crit-threshold": true, - "high-crit-threshold": true, - "low-threshold": true, - "high-threshold": true, - "minimum-recorded": true, - "maximum-recorded": true - }, - { - "name": "OUTLET_TEMP", - "controllable": false, - "low-crit-threshold": true, - "high-crit-threshold": true, - "low-threshold": true, - "high-threshold": true, - "minimum-recorded": true, - "maximum-recorded": true - }, - { - "name": "TPS53688_TEMP", - "controllable": false, - "low-crit-threshold": true, - "high-crit-threshold": true, - "low-threshold": true, - "high-threshold": true, - "minimum-recorded": true, - "maximum-recorded": true - } - ], - "modules": [], - "sfps": [] - }, - "interfaces": {} -} diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/platform_asic b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/platform_asic deleted file mode 100644 index 0815c8a78c..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/platform_asic +++ /dev/null @@ -1 +0,0 @@ -centec-arm64 diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/config.py b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/config.py deleted file mode 100644 index 93b331573d..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/config.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- -RAGILE_CARDID = 0x00004099 -RAGILE_PRODUCTNAME = "RA-B6010-48GT4X" -RAGILE_PART_NUMBER = "RJ000001" -RAGILE_LABEL_REVISION = "R01" -RAGILE_ONIE_VERSION = "2018.02" -RAGILE_MAC_SIZE = 3 -RAGILE_MANUF_NAME = "Ragile" -RAGILE_MANUF_COUNTRY = "CHN" -RAGILE_VENDOR_NAME = "Ragile" -RAGILE_DIAG_VERSION = "0.1.0.15" -RAGILE_SERVICE_TAG = "www.ragile.com" - -CPUEEPROMS = {"name":"cpueeprom","bus":5,"loc":0x57,"E2PRODUCT":'2', "E2TYPE":'4'} - -# rg_eeprom = "1-0056/eeprom" -E2_LOC = {"bus":1, "devno":0x56} -E2_PROTECT = {} -FAN_PROTECT = {"bus":1, "devno":0x0d, "addr":0x19, "open":0x00, "close":0xff} - - diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/eeprom.py b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/eeprom.py deleted file mode 100644 index 77016e1794..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/eeprom.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python - -try: - import exceptions - import binascii - import time - import optparse - import warnings - import os - import sys - from sonic_eeprom import eeprom_base - from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") - - -class board(eeprom_tlvinfo.TlvInfoDecoder): - - def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/sfputil.py b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/sfputil.py deleted file mode 100644 index ad619bf334..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/sfputil.py +++ /dev/null @@ -1,455 +0,0 @@ -# sfputil.py -# -# Platform-specific SFP transceiver interface for SONiC -# - -try: - import time - import subprocess - import re - import os - import threading - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError as e: - raise ImportError("%s - required module not found" % str(e)) - - -class SfpUtil(SfpUtilBase): - """Platform-specific SfpUtil class""" - - PORT_START = 49 - PORT_END = 52 - PORTS_IN_BLOCK = 53 - EEPROM_OFFSET = 9 - SFP_DEVICE_TYPE = "optoe2" - QSFP_DEVICE_TYPE = "optoe1" - I2C_MAX_ATTEMPT = 3 - - SFP_STATUS_INSERTED = '1' - SFP_STATUS_REMOVED = '0' - - TXWRT_PROTECT = 0X4E - TXWRT_NO_PROTECT = 0X59 - - _port_to_eeprom_mapping = {} - port_to_i2cbus_mapping ={} - port_dict = {} - port_presence_info = {} - port_reset_info = {} - port_txdis_info = {} - port_txwrt_info = {} - port_led_info = {} - - port_rxlos_info = {} - port_txfault_info = {} - port_drop_info = {} - - @property - def port_start(self): - return self.PORT_START - - @property - def port_end(self): - return self.PORT_END - - @property - def sfp_ports(self): - return list(range(self.PORT_START, self.PORTS_IN_BLOCK)) - - @property - def qsfp_ports(self): - return [] - - @property - def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping - - def __init__(self): - for x in range(self.PORT_START, self.PORTS_IN_BLOCK): - self.port_to_i2cbus_mapping[x] = (x - self.PORT_START + self.EEPROM_OFFSET) - self.port_presence_info["/sys/bus/i2c/devices/3-0030/sfp_presence1"] = [49, 50, 51, 52] - self.port_txdis_info["/sys/bus/i2c/devices/3-0030/tx_disable"] = [49, 50, 51, 52] - self.port_txwrt_info["/sys/bus/i2c/devices/3-0030/tx_write_protect"] = [49, 50, 51, 52] - - # bit 1: los - self.port_rxlos_info["/sys/bus/i2c/devices/3-0030/sfp_rx_loss1"] = [49, 50, 51, 52] - - # bit 1: fault - self.port_txfault_info["/sys/bus/i2c/devices/3-0030/sfp_tx_fault1"] = [49, 50, 51, 52] - - # bit 1: drop - self.port_drop_info["/sys/bus/i2c/devices/3-0030/sfp_drop_record1"] = [49, 50, 51, 52] - - SfpUtilBase.__init__(self) - - def _sfp_read_file_path(self, file_path, offset, num_bytes): - attempts = 0 - while attempts < self.I2C_MAX_ATTEMPT: - try: - file_path.seek(offset) - read_buf = file_path.read(num_bytes) - except: - attempts += 1 - time.sleep(0.05) - else: - return True, read_buf - return False, None - - def _sfp_eeprom_present(self, sysfs_sfp_i2c_client_eeprompath, offset): - """Tries to read the eeprom file to determine if the - device/sfp is present or not. If sfp present, the read returns - valid bytes. If not, read returns error 'Connection timed out""" - - if not os.path.exists(sysfs_sfp_i2c_client_eeprompath): - return False - else: - with open(sysfs_sfp_i2c_client_eeprompath, "rb", buffering=0) as sysfsfile: - rv, buf = self._sfp_read_file_path(sysfsfile, offset, 1) - return rv - - def _add_new_sfp_device(self, sysfs_sfp_i2c_adapter_path, devaddr, devtype): - try: - sysfs_nd_path = "%s/new_device" % sysfs_sfp_i2c_adapter_path - - # Write device address to new_device file - nd_file = open(sysfs_nd_path, "w") - nd_str = "%s %s" % (devtype, hex(devaddr)) - nd_file.write(nd_str) - nd_file.close() - - except Exception as err: - print(("Error writing to new device file: %s" % str(err))) - return 1 - else: - return 0 - - def _get_port_eeprom_path(self, port_num, devid): - sysfs_i2c_adapter_base_path = "/sys/class/i2c-adapter" - - if port_num in list(self.port_to_eeprom_mapping.keys()): - sysfs_sfp_i2c_client_eeprom_path = self.port_to_eeprom_mapping[port_num] - else: - sysfs_i2c_adapter_base_path = "/sys/class/i2c-adapter" - - i2c_adapter_id = self._get_port_i2c_adapter_id(port_num) - if i2c_adapter_id is None: - print("Error getting i2c bus num") - return None - - # Get i2c virtual bus path for the sfp - sysfs_sfp_i2c_adapter_path = "%s/i2c-%s" % (sysfs_i2c_adapter_base_path, - str(i2c_adapter_id)) - - # If i2c bus for port does not exist - if not os.path.exists(sysfs_sfp_i2c_adapter_path): - print(("Could not find i2c bus %s. Driver not loaded?" % sysfs_sfp_i2c_adapter_path)) - return None - - sysfs_sfp_i2c_client_path = "%s/%s-00%s" % (sysfs_sfp_i2c_adapter_path, - str(i2c_adapter_id), - hex(devid)[-2:]) - - # If sfp device is not present on bus, Add it - if not os.path.exists(sysfs_sfp_i2c_client_path): - if port_num in self.qsfp_ports: - ret = self._add_new_sfp_device( - sysfs_sfp_i2c_adapter_path, devid, self.QSFP_DEVICE_TYPE) - else: - ret = self._add_new_sfp_device( - sysfs_sfp_i2c_adapter_path, devid, self.SFP_DEVICE_TYPE) - if ret != 0: - print("Error adding sfp device") - return None - - sysfs_sfp_i2c_client_eeprom_path = "%s/eeprom" % sysfs_sfp_i2c_client_path - return sysfs_sfp_i2c_client_eeprom_path - - def _read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes): - eeprom_raw = [] - for i in range(0, num_bytes): - eeprom_raw.append("0x00") - - rv, raw = self._sfp_read_file_path(sysfsfile_eeprom, offset, num_bytes) - if rv == False: - return None - - try: - if isinstance(raw, str): - for n in range(0, num_bytes): - eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2) - else: - for n in range(0, num_bytes): - eeprom_raw[n] = hex(raw[n])[2:].zfill(2) - except Exception as err: - return None - return eeprom_raw - - def get_eeprom_dom_raw(self, port_num): - if port_num in self.qsfp_ports: - # QSFP DOM EEPROM is also at addr 0x50 and thus also stored in eeprom_ifraw - return None - else: - # Read dom eeprom at addr 0x51 - return self._read_eeprom_devid(port_num, self.IDENTITY_EEPROM_ADDR, 256) - - def get_presence(self, port_num): - # Check for invalid port_num - if port_num < self.port_start or port_num > self.port_end: - return False - - presence_path = None - for presence_key in self.port_presence_info: - if port_num in self.port_presence_info[presence_key]: - presence_path = presence_key - presence_offset = self.port_presence_info[presence_key].index(port_num) - break - if presence_path == None: - return False - - try: - data = open(presence_path, "rb") - except IOError: - return False - - presence_data = data.read(2) - if presence_data == "": - return False - result = int(presence_data, 16) - data.close() - - # ModPrsL is active low - if result & (1 << presence_offset) == 0: - return True - - return False - - def get_low_power_mode(self, port_num): - return False - - def set_low_power_mode(self, port_num, lpmode): - return False - - def reset(self, port_num): - return False - - def reset_all(self): - return False - - def _do_write_file(self, file_handle, offset, value): - file_handle.seek(offset) - file_handle.write(hex(value)) - - def get_transceiver_change_event(self, timeout=0): - - start_time = time.time() - currernt_port_dict = {} - forever = False - - if timeout == 0: - forever = True - elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs - else: - print(("get_transceiver_change_event:Invalid timeout value", timeout)) - return False, {} - - end_time = start_time + timeout - if start_time > end_time: - print(('get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout)) - - return False, {} # Time wrap or possibly incorrect timeout - - while timeout >= 0: - # Check for OIR events and return updated port_dict - for x in range(self.PORT_START, self.PORTS_IN_BLOCK): - if self.get_presence(x): - currernt_port_dict[x] = self.SFP_STATUS_INSERTED - else: - currernt_port_dict[x] = self.SFP_STATUS_REMOVED - if (currernt_port_dict == self.port_dict): - if forever: - time.sleep(1) - else: - timeout = end_time - time.time() - if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity - else: - if timeout > 0: - time.sleep(timeout) - return True, {} - else: - # Update reg value - self.port_dict = currernt_port_dict - return True, self.port_dict - print ("get_transceiver_change_event: Should not reach here.") - return False, {} - - def tx_disable(self, port_num, disable): - if not self.get_presence(port_num): - return False - - if port_num in self.sfp_ports: - txwrt_path = None - txdis_path = None - txdis_offset = 0 - - for key in self.port_txwrt_info: - if port_num in self.port_txwrt_info[key]: - txwrt_path = key - break - if txwrt_path == None: - return False - - for key in self.port_txdis_info: - if port_num in self.port_txdis_info[key]: - txdis_path = key - txdis_offset = self.port_txdis_info[key].index(port_num) - break - if txdis_path == None: - return False - - - try: - with open(txwrt_path, "r+") as sys_file: - sres = hex(self.TXWRT_NO_PROTECT)[2:] - sys_file.write(sres) - - with open(txdis_path, "r+") as sys_file: - txdis_data = sys_file.read(2) - if not txdis_data: - return False - result = int(txdis_data, 16) - if disable: - result = result | (1 << txdis_offset) - else: - result = result & (~(1 << txdis_offset)) - sys_file.seek(0) - sres = hex(result)[2:] - print(result,sres) - sys_file.write(sres) - - with open(txwrt_path, "r+") as sys_file: - sres = hex(self.TXWRT_PROTECT)[2:] - sys_file.write(sres) - except Exception as err: - print(err) - return False - - return True - else: - return False - -########### sysdiag ########### - def _get_cpld_info(self, port_num, info): - path = None - offset = 0 - for key in info: - if port_num in info[key]: - path = key - offset = info[key].index(port_num) - break - return path, offset - - def get_tx_disable(self, port_num): - # cur only support sfp moudle - if port_num not in self.sfp_ports: - return False - - if not self.get_presence(port_num): - return False - - path, offset = self._get_cpld_info(port_num, self.port_txdis_info) - if path == None: - return False - - result = 0 - try: - with open(path, "r") as sys_file: - data = sys_file.read(2) - result = int(data, 16) - except Exception as e: - print((str(e))) - return False - - # 1: disable - if result & (1 << offset): - return True - else: - return False - - def get_rx_los(self, port_num): - # cur only support sfp moudle - if port_num not in self.sfp_ports: - return False - - path, offset = self._get_cpld_info(port_num, self.port_rxlos_info) - if path == None: - return False - - result = 0 - try: - with open(path, "r") as sys_file: - data = sys_file.read(2) - result = int(data, 16) - except Exception as e: - print((str(e))) - return False - - # 1: los - if result & (1 << offset): - return True - else: - return False - - def get_tx_fault(self, port_num): - # cur only support sfp moudle - if port_num not in self.sfp_ports: - return False - - if not self.get_presence(port_num): - return False - - path, offset = self._get_cpld_info(port_num, self.port_txfault_info) - if path == None: - return False - - result = 0 - try: - with open(path, "r") as sys_file: - data = sys_file.read(2) - result = int(data, 16) - except Exception as e: - print((str(e))) - return False - - # 1: fault - if result & (1 << offset): - return True - else: - return False - - return False - - def get_plug_record(self, port_num): - if not self.get_presence(port_num): - return False - - path, offset = self._get_cpld_info(port_num, self.port_drop_info) - if path == None: - return False - - result = 0 - try: - with open(path, "r") as sys_file: - data = sys_file.read(2) - result = int(data, 16) - except Exception as e: - print((str(e))) - return False - - # 1: drop - if result & (1 << offset): - return True - else: - return False diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/ssd_util.py b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/ssd_util.py deleted file mode 100644 index 95ca23e8b3..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/plugins/ssd_util.py +++ /dev/null @@ -1,112 +0,0 @@ -# -# ssd_util.py -# -# Generic implementation of the SSD health API -# SSD models supported: -# - InnoDisk -# - StorFly -# - Virtium - -try: - import subprocess - from sonic_platform_base.sonic_ssd.ssd_base import SsdBase -except ImportError as e: - raise ImportError (str(e) + "- required module not found") - -HEALTH_CMD = "cat /sys/kernel/debug/mmc0/mmc0:0001/ext_csd | cut -c 537-538" -SERIAL_CMD = "cat /sys/bus/mmc/devices/mmc0\\:0001/serial" -FIRMWARE_CMD = "cat /sys/kernel/debug/mmc0/mmc0:0001/ext_csd | cut -c 509-522" -NOT_AVAILABLE = "N/A" - -class SsdUtil(SsdBase): - """ - Generic implementation of the SSD health API - """ - def __init__(self, diskdev): - self.model = "KLMCG4JETD-B041" - self.temperature = NOT_AVAILABLE - self.vendor_ssd_info = "====No vendor information====" - self.health_list = [100,90,80,70,60,50,40,30,20,10,0] - try: - life_time = self._execute_shell(HEALTH_CMD) - if int(life_time) in range(1,12): - self.health = self.health_list[int(life_time) - 1] - else: - self.health = NOT_AVAILABLE - except Exception as e: - self.health = NOT_AVAILABLE - - try: - self.firmware = self._execute_shell(FIRMWARE_CMD) - except Exception as e: - self.firmware = NOT_AVAILABLE - - try: - serial = self._execute_shell(SERIAL_CMD) - self.serial = serial.replace("0x",'') - except Exception as e: - self.serial = NOT_AVAILABLE - - def _execute_shell(self, cmd): - status, output = subprocess.getstatusoutput(cmd) - if status: - return None - - return output - - def get_health(self): - """ - Retrieves current disk health in percentages - - Returns: - A float number of current ssd health - e.g. 83.5 - """ - return self.health - - def get_temperature(self): - """ - Retrieves current disk temperature in Celsius - - Returns: - A float number of current temperature in Celsius - e.g. 40.1 - """ - return self.temperature - - def get_model(self): - """ - Retrieves model for the given disk device - - Returns: - A string holding disk model as provided by the manufacturer - """ - return self.model - - def get_firmware(self): - """ - Retrieves firmware version for the given disk device - - Returns: - A string holding disk firmware version as provided by the manufacturer - """ - return self.firmware - - def get_serial(self): - """ - Retrieves serial number for the given disk device - - Returns: - A string holding disk serial number as provided by the manufacturer - """ - return self.serial - - def get_vendor_output(self): - """ - Retrieves vendor specific data for the given disk device - - Returns: - A string holding some vendor specific disk information - """ - return self.vendor_ssd_info - diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/pmon_daemon_control.json b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/pmon_daemon_control.json deleted file mode 100644 index 5fdf83f1b9..0000000000 --- a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/pmon_daemon_control.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "skip_ledd": true, - "skip_xcvrd": false, - "skip_syseepromd": false, - "skip_thermalctld": false, - "skip_psud": false -} diff --git a/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/system_health_monitoring_config.json b/device/ragile/arm64-ragile_ra-b6010-48gt4x-r0/system_health_monitoring_config.json deleted file mode 100755 index e69de29bb2..0000000000 diff --git a/platform/centec-arm64/one-image.mk b/platform/centec-arm64/one-image.mk index 47042e4556..3bcb9258fc 100755 --- a/platform/centec-arm64/one-image.mk +++ b/platform/centec-arm64/one-image.mk @@ -11,9 +11,8 @@ $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(CENTEC_E530_24X2C_PLATFORM_MODULE) $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(CENTEC_E530_48S4X_PLATFORM_MODULE) $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(CENTEC_E530_24X2Q_PLATFORM_MODULE) $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(FS_S5800_48T4S_PLATFORM_MODULE) -$(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(RA_B6010_48GT4X_PLATFORM_MODULE) -ifeq ($(INSTALL_DEBUG_TOOLS),y) +ifeq ($(INSTALL_DEBUG_TOOLS),y) $(SONIC_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_DBG_IMAGES) $(SONIC_ONE_IMAGE)_DOCKERS += $(filter-out $(patsubst %-$(DBG_IMAGE_MARK).gz,%.gz, $(SONIC_INSTALL_DOCKER_DBG_IMAGES)), $(SONIC_INSTALL_DOCKER_IMAGES)) else diff --git a/platform/centec-arm64/platform-modules-ragile.dep b/platform/centec-arm64/platform-modules-ragile.dep deleted file mode 100644 index 48684b053f..0000000000 --- a/platform/centec-arm64/platform-modules-ragile.dep +++ /dev/null @@ -1,9 +0,0 @@ -MPATH := $($(RA_B6010_48GT4X_PLATFORM_MODULE)_SRC_PATH) -DEP_FILES := $(SONIC_COMMON_FILES_LIST) platform/centec-arm64/platform-modules-ragile.mk platform/centec-arm64/platform-modules-ragile.dep -DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) -DEP_FILES += $(addprefix $(MPATH)/,$(shell cd $(MPATH) && git ls-files)) - -$(RA_B6010_48GT4X_PLATFORM_MODULE)_CACHE_MODE := GIT_CONTENT_SHA -$(RA_B6010_48GT4X_PLATFORM_MODULE)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) -$(RA_B6010_48GT4X_PLATFORM_MODULE)_DEP_FILES := $(DEP_FILES) - diff --git a/platform/centec-arm64/platform-modules-ragile.mk b/platform/centec-arm64/platform-modules-ragile.mk deleted file mode 100644 index 232d183bc9..0000000000 --- a/platform/centec-arm64/platform-modules-ragile.mk +++ /dev/null @@ -1,10 +0,0 @@ -## RA-B6010-48GT4X -RA_B6010_48GT4X_PLATFORM_MODULE_VERSION =1.3 -export RA_B6010_48GT4X_PLATFORM_MODULE_VERSION - -RA_B6010_48GT4X_PLATFORM_MODULE = platform-modules-ra-b6010-48gt4x_$(RA_B6010_48GT4X_PLATFORM_MODULE_VERSION)_arm64.deb - -$(RA_B6010_48GT4X_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-ragile -$(RA_B6010_48GT4X_PLATFORM_MODULE)_PLATFORM = arm64-ragile_ra-b6010-48gt4x-r0 -$(RA_B6010_48GT4X_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) -SONIC_DPKG_DEBS += $(RA_B6010_48GT4X_PLATFORM_MODULE) diff --git a/platform/centec-arm64/rules.mk b/platform/centec-arm64/rules.mk index 2466b7032d..d88670f130 100755 --- a/platform/centec-arm64/rules.mk +++ b/platform/centec-arm64/rules.mk @@ -7,7 +7,6 @@ include $(PLATFORM_PATH)/libsaithrift-dev.mk include $(PLATFORM_PATH)/tsingma-bsp.mk include $(PLATFORM_PATH)/platform-modules-centec-e530.mk include $(PLATFORM_PATH)/platform-modules-fs.mk -include $(PLATFORM_PATH)/platform-modules-ragile.mk SONIC_ALL += $(SONIC_ONE_IMAGE) \ $(DOCKER_FPM) diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/LICENSE b/platform/centec-arm64/sonic-platform-modules-ragile/LICENSE deleted file mode 100644 index 2d14d2b778..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -Copyright (C) 2019 Centec, Inc - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/README.md b/platform/centec-arm64/sonic-platform-modules-ragile/README.md deleted file mode 100644 index 6b907de173..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/README.md +++ /dev/null @@ -1 +0,0 @@ -platform drivers for Centec E530 for the SONiC project diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/Makefile b/platform/centec-arm64/sonic-platform-modules-ragile/common/Makefile deleted file mode 100644 index 3db49b5961..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -PWD = $(shell pwd) -CC ?=gcc -INSTALL_MOD_DIR ?=extra -KVERSION ?= $(shell uname -r) -KERNEL_SRC ?= /lib/modules/$(KVERSION) -EXTRA_CFLAGS:= -I$(M)/include -EXTRA_CFLAGS+= -Wall -ifdef ENABLE_GCOV -ifeq ($(ENABLE_GCOV), y) -EXTRA_CFLAGS+= -fprofile-arcs -ftest-coverage -lgcov -endif -endif # ENABLE_GCOV -SUB_BUILD_DIR = $(PWD)/build -DIR_KERNEL_SRC = $(PWD)/modules -SCRIPT_DIR = $(PWD)/script -SERVICE_DIR = $(PWD)/service -BLACK_DRIVER_CONF_DIR = $(PWD)/modprobe_conf - -app_dir = $(PWD)/app -app_build_dir = $(app_dir)/build -modules_build_dir = $(DIR_KERNEL_SRC)/build - -INSTALL_MODULE_DIR = $(SUB_BUILD_DIR)/$(KERNEL_SRC)/$(INSTALL_MOD_DIR) -INSTALL_SCRIPT_DIR = $(SUB_BUILD_DIR)/usr/local/bin -INSTALL_SERVICE_DIR = $(SUB_BUILD_DIR)/lib/systemd/system -INSTALL_LIB_DIR = $(SUB_BUILD_DIR)/usr/lib/python3.9/dist-packages -INSTALL_BLACK_DRIVER = $(SUB_BUILD_DIR)/etc/modprobe.d -CTC_48GT4X_PHY_DIR = $(SUB_BUILD_DIR)/usr/share/sonic/device/arm64-ragile_ra-b6010-48gt4x-r0/RA-B6010-48GT4X - -all: - $(MAKE) -C $(app_dir) - $(MAKE) -C $(DIR_KERNEL_SRC) - @if [ ! -d ${INSTALL_MODULE_DIR} ]; then mkdir -p ${INSTALL_MODULE_DIR} ;fi - @if [ ! -d ${INSTALL_SCRIPT_DIR} ]; then mkdir -p ${INSTALL_SCRIPT_DIR} ;fi - @if [ ! -d ${INSTALL_SERVICE_DIR} ]; then mkdir -p ${INSTALL_SERVICE_DIR} ;fi - @if [ ! -d ${CTC_48GT4X_PHY_DIR} ]; then mkdir -p ${CTC_48GT4X_PHY_DIR}/phy_drv ;fi - @if [ ! -d ${INSTALL_LIB_DIR} ]; then mkdir -p ${INSTALL_LIB_DIR} ;fi - @if [ -d $(PWD)/lib/ ]; then cp -r $(PWD)/lib/* ${INSTALL_LIB_DIR} ;fi - cp -r $(app_dir)/*.so $(CTC_48GT4X_PHY_DIR)/phy_drv - cp -r $(app_build_dir)/module/*.ko $(INSTALL_MODULE_DIR) - cp -r $(modules_build_dir)/*.ko $(INSTALL_MODULE_DIR) - cp -r $(app_dir)/build/app/* $(INSTALL_SCRIPT_DIR) - if [ -d $(SCRIPT_DIR) ]; then cp -r $(SCRIPT_DIR)/* $(INSTALL_SCRIPT_DIR) ;fi - if [ -d $(SERVICE_DIR) ]; then cp -r $(SERVICE_DIR)/* $(INSTALL_SERVICE_DIR) ;fi - @if [ -d $(INSTALL_SCRIPT_DIR) ]; then chmod +x $(INSTALL_SCRIPT_DIR)/* ;fi -clean: - rm -rf $(SUB_BUILD_DIR) diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/Makefile b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/Makefile deleted file mode 100644 index 2d86cdf4c4..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -pes_parent_dir:=$(shell pwd)/$(lastword $(MAKEFILE_LIST)) -pes_parent_dir:=$(shell dirname $(pes_parent_dir)) - -SUBDIRS=$(shell ls -l | grep ^d | awk '{if($$9 != "build") print $$9}') -INC = -I./inc - -COMMON_OUT_PUT := $(shell pwd)/build -common_out_put_dir := $(COMMON_OUT_PUT)/app -common_module_dir := $(COMMON_OUT_PUT)/module/ -export common_out_put_dir common_module_dir - -all : CHECK $(SUBDIRS) -CHECK : - @echo $(pes_parent_dir) - -$(SUBDIRS):ECHO -# make all - #@echo $@ - make -C $@ - -ECHO: - @echo $(SUBDIRS) - -.PHONY : clean -clean : - -rm -rf $(COMMON_OUT_PUT) diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/Makefile b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/Makefile deleted file mode 100644 index 448b52f44f..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -top_srcdir:= $(shell pwd) -include $(top_srcdir)/Rules.mk -export top_srcdir - -firmware-y:= -firmware-y += firmware_driver_ispvme -firmware-y += firmware_upgrade_ispvme - -.PHONY: all -all: build - -.PHONY: build -build: $(firmware-y) -$(foreach dir,$(firmware-y),$(eval $(call compile_dirs,$(dir)))) - -.PHONY: rpmpkg -rpmpkg: -ifeq ("$(CONFIG_CPLD_UPGRADE_ISPVME)", "y") - #$(RPMPKG) $(install_cpld_dir) firmware-cpld-ispvme.spec git -endif diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/Rules.mk b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/Rules.mk deleted file mode 100644 index c342398674..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/Rules.mk +++ /dev/null @@ -1,45 +0,0 @@ -CC ?= $(CROSS)gcc -AR ?= $(CROSS)ar -AS ?= $(CROSS)as -LD ?= $(CROSS)ld -STRIP ?= $(CROSS)strip - -install_root:=${top_srcdir}/images - -install_header_dir:=${install_root}/header -install_adir:=$(install_root)/lib -install_symbol_dir:=$(install_root)/symbol -# symbol_files -symbol_files:=$(shell find $(EXPORT_SYMBOL) -name 'Module.symvers') -# -# symbol_files += $(shell find $(install_symbol_dir) -name 'Module.symvers') - -# top root: install_rootfs_dir -# install_rootfs_dir -install_rootfs_dir:=$(install_root)/rootfs - -# install_sodir -install_sodir:=$(install_rootfs_dir)/$(INSTALL_SODIR) - -install_usr_bin_dir:=$(install_rootfs_dir)/usr/bin -# install_sbin_dir -install_sbin_dir:=$(install_rootfs_dir)/sbin -install_etc_dir:=$(install_rootfs_dir)/etc - -export INSTALL_MOD_PATH:=$(ROOT) - -BUILD_CFLAGS:=$(CFLAGS) -I$(install_header_dir) -BUILD_LDFLAGS:=$(LDFLAGS) -L/$(install_sodir) -L/$(install_adir) - -define compile_dirs -.PHONY: $(1) -$(1): - @echo;echo "building $(1)..." - @$(MAKE) -C ${1} -endef - -compile.c = $(CC) $(BUILD_CFLAGS) -d -c -o $@ $< - -%.o: %.c - $(compile.c) - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware-cpld-ispvme.spec b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware-cpld-ispvme.spec deleted file mode 100644 index b8c1ca37b5..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware-cpld-ispvme.spec +++ /dev/null @@ -1,25 +0,0 @@ -Summary: Firmware Upgrade Package - -Name: firmware-cpld - -Version: 1.0.0.%patch - -Release: firmware - -License: Ragile - -Group: common - -AutoReqProv: no - -%clean -%description -[common] -%des_name -%des_ver -%des_target - -%files - -%attr(755,root,root) -/* diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/Makefile b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/Makefile deleted file mode 100644 index 57a67bea2d..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -PWD = $(shell pwd) - -EXTRA_CFLAGS:= -I$(M)/include -EXTRA_CFLAGS+= -Wall -ifdef ENABLE_GCOV -ifeq ($(ENABLE_GCOV), y) -EXTRA_CFLAGS+= -fprofile-arcs -ftest-coverage -lgcov -endif -endif # ENABLE_GCOV -RAGILE_PRODUCT = ra_b6010_48gt4x -firmware_driver-objs := firmware_ispvme.o -firmware_driver-objs += firmware_cpld_ispvme.o firmware_cpld_upgrade_ispvme.o - -#ifndef CONFIG_FRM_PRODUCT_FILE - -firmware_driver-objs += $(RAGILE_PRODUCT).o -$(warning $(firmware_driver-objs)) -obj-m := firmware_driver.o -all: - $(MAKE) -C $(KERNEL_SRC)/build M=$(PWD) modules - @if [ ! -d $(common_module_dir) ]; then mkdir -p $(common_module_dir) ;fi - cp -p $(PWD)/*.ko $(common_module_dir) \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/firmware_cpld_ispvme.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/firmware_cpld_ispvme.c deleted file mode 100644 index 9c7e694c5a..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/firmware_cpld_ispvme.c +++ /dev/null @@ -1,283 +0,0 @@ -/** - * Copyright(C) 2013 Ragile Network. All rights reserved. - */ -/* - * firmware_cpld.c - * Original Author : support 2013-10-25 - * - * CPLD driver - * - * History - * v1.0 support 2013-10-25 Initial version. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int firmware_cpld_open(struct inode *inode, struct file *file) -{ - firmware_cpld_t *cpld_info; - firmware_device_t *frm_dev; - - dev_debug(firmware_debug(), "Open cpld device.\n"); - - frm_dev = firmware_get_device_by_minor(FIRMWARE_CPLD, MINOR(inode->i_rdev)); - if (frm_dev == NULL) { - return -ENXIO; - } - - file->private_data = frm_dev; - cpld_info = (firmware_cpld_t *)frm_dev->priv; - - if (cpld_info != NULL && cpld_info->init_cpld) { - cpld_info->init_cpld(); - } - - if (cpld_info != NULL && cpld_info->init_chip) { - cpld_info->init_chip(0); - } - - return FIRMWARE_SUCCESS; -} - -static ssize_t firmware_cpld_read (struct file *file, char __user *buf, size_t count, - loff_t *offset) -{ - return 0; -} - -static ssize_t firmware_cpld_write (struct file *file, const char __user *buf, size_t count, - loff_t *offset) -{ - return 0; -} - -static loff_t firmware_cpld_llseek(struct file *file, loff_t offset, int origin) -{ - return 0; -} - -static long firmware_cpld_ioctl(struct file *file, unsigned int cmd, unsigned long arg) -{ - char value; - void __user *argp; - cmd_info_t cmd_info; - char *buf; - int ret; - - argp = (void __user *)arg; - - switch (cmd) { - case FIRMWARE_JTAG_TDI: - if (copy_from_user(&value, argp, sizeof(value))) { - return -EFAULT; - } - fwm_cpld_tdi_op(value); - break; - case FIRMWARE_JTAG_TCK: - if (copy_from_user(&value, argp, sizeof(value))) { - return -EFAULT; - } - fwm_cpld_tck_op(value); - break; - - case FIRMWARE_JTAG_TMS: - if (copy_from_user(&value, argp, sizeof(value))) { - return -EFAULT; - } - fwm_cpld_tms_op(value); - break; - - case FIRMWARE_JTAG_TDO: - value = fwm_cpld_tdo_op(); - - if (copy_to_user(argp, &value, sizeof(value))) { - return -EFAULT; - } - - break; - - case FIRMWARE_SET_GPIO_INFO: - /* set GPIO information */ - if (copy_from_user(&cmd_info, argp, sizeof(cmd_info_t))) { - return -EFAULT; - } - - buf = (char *) kzalloc(cmd_info.size + 1, GFP_KERNEL); - if (buf == NULL) { - return -ENOMEM; - } - if (copy_from_user(buf, cmd_info.data, cmd_info.size)) { - kfree(buf); - return -EFAULT; - } - - ret = fmw_cpld_set_gpio_info((firmware_upg_gpio_info_t*)buf); - if (ret != FIRMWARE_SUCCESS) { - dev_debug(firmware_debug(), "Failed to set gpio info.\n"); - kfree(buf); - return -ESRCH; - } - - kfree(buf); - break; - - case FIRMWARE_SET_DEBUG_ON: - /* DEBUG ON */ - firmware_set_debug(1); - break; - case FIRMWARE_SET_DEBUG_OFF: - /* DEBUG_OFF */ - firmware_set_debug(0); - break; - - default: - return -ENOTTY; - } - - return FIRMWARE_SUCCESS; -} - -static int firmware_cpld_release(struct inode *inode, struct file *file) -{ - firmware_cpld_t *cpld_info; - firmware_device_t *frm_dev; - - frm_dev = (firmware_device_t *)(file->private_data); - cpld_info = (firmware_cpld_t *)(frm_dev->priv); - - if (cpld_info != NULL && cpld_info->finish_chip) { - cpld_info->finish_chip(0); - } - - if (cpld_info != NULL && cpld_info->finish_cpld) { - cpld_info->finish_cpld(); - } - return 0; -} - -static const struct file_operations cpld_dev_fops = { - .owner = THIS_MODULE, - .llseek = firmware_cpld_llseek, - .read = firmware_cpld_read, - .write = firmware_cpld_write, - .unlocked_ioctl = firmware_cpld_ioctl, - .open = firmware_cpld_open, - .release = firmware_cpld_release, -}; - -static int firmware_cpld_probe(struct platform_device *pdev) -{ - const __be32 *slot; - int len; - int ret; - firmware_cpld_t *cpld_info; - firmware_device_t *frm_dev; - - frm_dev = (firmware_device_t *) kzalloc(sizeof(firmware_device_t), GFP_KERNEL); - if (frm_dev == NULL) { - dev_debug(firmware_debug(), "Failed to kzalloc firmware device.\n"); - return -EPERM; - } - - slot = of_get_property(pdev->dev.of_node, "slot", &len); - if (slot && len == sizeof(*slot)) { - frm_dev->slot = be32_to_cpup(slot); - } else { - frm_dev->slot = firmware_get_device_num(FIRMWARE_CPLD) + 1; - } - - snprintf(frm_dev->name, FIRMWARE_NAME_LEN - 1, "firmware_cpld_ispvme%d", frm_dev->slot - 1); - cpld_info = fmw_cpld_upg_get_cpld(frm_dev->name); - - INIT_LIST_HEAD(&frm_dev->list); - frm_dev->type = FIRMWARE_CPLD; - frm_dev->dev.minor = MISC_DYNAMIC_MINOR; - frm_dev->dev.name = frm_dev->name; - frm_dev->dev.fops = &cpld_dev_fops; - frm_dev->priv = cpld_info; - - dev_debug(firmware_debug(), "Register cpld firmware slot:%d, name:%s.\n", frm_dev->slot, frm_dev->name); - - ret = firmware_device_register(frm_dev); - if (ret < 0) { - dev_debug(firmware_debug(), "Failed to register firmware device.\n"); - kfree(frm_dev); - return -EPERM; - } - - platform_set_drvdata(pdev, frm_dev); - - return 0; -} - -static int __exit firmware_cpld_remove(struct platform_device *dev) -{ - firmware_device_t *frm_dev; - - frm_dev = (firmware_device_t *)platform_get_drvdata(dev); - firmware_device_unregister(frm_dev); - - kfree(frm_dev); - - return 0; -} - -static struct of_device_id cpld_match[] = { - { - .compatible = "firmware_cpld_ispvme", - }, - {}, -}; - -static struct platform_driver cpld_driver = { - .driver = { - .name = "firmware_cpld_ispvme", - .owner = THIS_MODULE, - .of_match_table = cpld_match, - }, - .probe = firmware_cpld_probe, - .remove = firmware_cpld_remove, -}; - -static firmware_driver_t fmw_drv = { - .name = "firmware_cpld_ispvme", - .type = FIRMWARE_CPLD, - .drv = &cpld_driver, -}; - -void firmware_cpld_init(void) -{ - int ret; -#if 0 - struct device_node* node; - node = of_find_node_by_name(NULL, "cpld_upgrade"); - if (node == NULL) { - pr_notice("No cpld_upgrade\r\n"); - return; - } - pr_notice("Found cpld_upgrade\r\n"); -#else - printk(KERN_INFO "Do init cpld_upgrade\r\n"); -#endif - INIT_LIST_HEAD(&fmw_drv.list); - ret = fmw_cpld_upg_init(); - if (ret < 0) { - return; - } - firmware_driver_register(&fmw_drv); -} - -void firmware_cpld_exit(void) -{ - fmw_cpld_upg_exit(); - firmware_driver_unregister(&fmw_drv); - INIT_LIST_HEAD(&fmw_drv.list); -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/firmware_cpld_upgrade_ispvme.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/firmware_cpld_upgrade_ispvme.c deleted file mode 100644 index 758498796b..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/firmware_cpld_upgrade_ispvme.c +++ /dev/null @@ -1,329 +0,0 @@ -/** - * Copyright(C) 2013 Ragile Network. All rights reserved. - */ -/* - * firmware_cpld_upgrade.c - * Original Author : support 2013-10-25 - * - * CPLD upgrade driver - * - * History - * v1.0 support 2013-10-25 Initial version. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* TCK clock MAX 16MHz */ -#define TCK_DELAY (current_fmw_cpld->tck_delay) -#if 0 -static firmware_cpld_t default_fmw_cpld; -#endif -static firmware_cpld_t fmw_cpld[FIRMWARE_MAX_CPLD_NUM]; -static firmware_cpld_t *current_fmw_cpld; - -static firmware_set_gpio_info_func_t g_set_gpio_info_func = NULL; - -void set_currrent_cpld_info(firmware_cpld_t *info) -{ - current_fmw_cpld = info; -} - -static void TDI_PULL_DOWN(void) -{ - if (current_fmw_cpld != NULL && current_fmw_cpld->pull_tdi_down) { - current_fmw_cpld->pull_tdi_down(); - } else { - dev_debug(firmware_debug(), "NO support TDI_PULL_DOWN.\n"); - } -} - -static void TDI_PULL_UP(void) -{ - if (current_fmw_cpld != NULL && current_fmw_cpld->pull_tdi_up) { - current_fmw_cpld->pull_tdi_up(); - } else { - dev_debug(firmware_debug(), "NO support TDI_PULL_UP.\n"); - } -} - -static void TCK_PULL_DOWN(void) -{ - if (current_fmw_cpld != NULL && current_fmw_cpld->pull_tck_down) { - current_fmw_cpld->pull_tck_down(); - } else { - dev_debug(firmware_debug(), "NO support TCK_PULL_DOWN.\n"); - } -} - -static void TCK_PULL_UP(void) -{ - if (current_fmw_cpld != NULL && current_fmw_cpld->pull_tck_up) { - current_fmw_cpld->pull_tck_up(); - } else { - dev_debug(firmware_debug(), "NO support TCK_PULL_UP.\n"); - } -} - -static void TMS_PULL_DOWN(void) -{ - if (current_fmw_cpld != NULL && current_fmw_cpld->pull_tms_down) { - current_fmw_cpld->pull_tms_down(); - } else { - dev_debug(firmware_debug(), "NO support TMS_PULL_DOWN.\n"); - } -} - -static void TMS_PULL_UP(void) -{ - if (current_fmw_cpld != NULL && current_fmw_cpld->pull_tms_up) { - current_fmw_cpld->pull_tms_up(); - } else { - dev_debug(firmware_debug(), "NO support TMS_PULL_UP.\n"); - } -} - -static int TDO_READ(void) -{ - if (current_fmw_cpld != NULL && current_fmw_cpld->read_tdo) { - return current_fmw_cpld->read_tdo(); - } else { - dev_debug(firmware_debug(), "NO support TDO_READ.\n"); - return -1; - } -} - -firmware_cpld_t *fmw_cpld_upg_get_cpld(char *name) -{ - int i; - - for (i = 0; i < FIRMWARE_MAX_CPLD_NUM; i++) { - if (fmw_cpld[i].is_used == 1 && strcmp(name, fmw_cpld[i].devname) == 0) { - return &fmw_cpld[i]; - } - } - - return NULL; -} - -int fmw_cpld_upg_copy_firmware_info(firmware_cpld_t *info) -{ - int i; - - for (i = 0; i < FIRMWARE_MAX_CPLD_NUM; i++) { - if (fmw_cpld[i].is_used == 1) { - continue; - } else { - strncpy(fmw_cpld[i].devname, info->devname, FIRMWARE_DEV_NAME_LEN); - fmw_cpld[i].slot = info->slot; - fmw_cpld[i].chip_index = info->chip_index; - fmw_cpld[i].is_used = info->is_used; - fmw_cpld[i].tck_delay = info->tck_delay; - fmw_cpld[i].pull_tdi_up = info->pull_tdi_up; - fmw_cpld[i].pull_tdi_down = info->pull_tdi_down; - fmw_cpld[i].pull_tck_up = info->pull_tck_up; - fmw_cpld[i].pull_tck_down = info->pull_tck_down; - fmw_cpld[i].pull_tms_up = info->pull_tms_up; - fmw_cpld[i].pull_tms_down = info->pull_tms_down; - fmw_cpld[i].read_tdo = info->read_tdo; - fmw_cpld[i].init_cpld = info->init_cpld; - fmw_cpld[i].init_chip = info->init_chip; - fmw_cpld[i].finish_chip = info->finish_chip; - fmw_cpld[i].finish_cpld = info->finish_cpld; - fmw_cpld[i].touch_watch_dog = info->touch_watch_dog; - fmw_cpld[i].keeplive = info->keeplive; - fmw_cpld[i].get_version = info->get_version; - fmw_cpld[i].get_card_name = info->get_card_name; - return 0; - } - } - return -1; -} - -int fmw_cpld_set_gpio_info(firmware_upg_gpio_info_t *info) -{ - if (g_set_gpio_info_func == NULL) { - dev_debug(firmware_debug(), "g_set_gpio_info_func is null.\n"); - return -1; - } - - return g_set_gpio_info_func(info); -} - -void fmw_cpld_reg_gpio_info_set_func(firmware_set_gpio_info_func_t func) -{ - if (func == NULL) { - dev_debug(firmware_debug(), "fmw_cpld_register_gpio_info_set_func func = NULL.\n"); - return; - } - g_set_gpio_info_func = func; - return; - -} -#if 0 -/* CPLD upgrade initialization operation */ -static int fmw_cpld_upg_init_cpld(void) -{ - gpio_request(JTAG_TDI, "cpld_upgrade"); - gpio_request(JTAG_TCK, "cpld_upgrade"); - gpio_request(JTAG_TMS, "cpld_upgrade"); - gpio_request(JTAG_EN, "cpld_upgrade"); - gpio_request(JTAG_TDO, "cpld_upgrade"); - - gpio_direction_output(JTAG_TDI, 1); - gpio_direction_output(JTAG_TCK, 1); - gpio_direction_output(JTAG_TMS, 1); - gpio_direction_output(JTAG_EN, 1); - - gpio_direction_input(JTAG_TDO); - return 0; -} - -/* CPLD upgrade completion operation */ -static int fmw_cpld_upg_finish_cpld(void) -{ - gpio_direction_output(JTAG_EN, 0); - - gpio_free(JTAG_TDI); - gpio_free(JTAG_TCK); - gpio_free(JTAG_TMS); - gpio_free(JTAG_EN); - gpio_free(JTAG_TDO); - return 0; -} - -/* TDI pull up */ -static void fmw_cpld_upg_pull_tdi_up(void) -{ - __gpio_set_value(JTAG_TDI, 1); -} - -/* TDI pull down */ -static void fmw_cpld_upg_pull_tdi_down(void) -{ - __gpio_set_value(JTAG_TDI, 0); -} - -/* TCK pull up */ -static void fmw_cpld_upg_pull_tck_up(void) -{ - __gpio_set_value(JTAG_TCK, 1); -} - -/* TCK pull down */ -static void fmw_cpld_upg_pull_tck_down(void) -{ - __gpio_set_value(JTAG_TCK, 0); -} - -/* TMS pull up */ -static void fmw_cpld_upg_pull_tms_up(void) -{ - __gpio_set_value(JTAG_TMS, 1); -} - -/* TCK pull down */ -static void fmw_cpld_upg_pull_tms_down(void) -{ - __gpio_set_value(JTAG_TMS, 0); -} - -/* read TDO */ -static int fmw_cpld_upg_read_tdo(void) -{ - return __gpio_get_value(JTAG_TDO); -} -#endif -#if 0 -static firmware_cpld_t default_fmw_cpld = { - .devname = "default_firmware_cpld", - .slot = 1, - .is_used = 1, - .tck_delay = 50, - .pull_tdi_up = fmw_cpld_upg_pull_tdi_up, - .pull_tdi_down = fmw_cpld_upg_pull_tdi_down, - .pull_tck_up = fmw_cpld_upg_pull_tck_up, - .pull_tck_down = fmw_cpld_upg_pull_tck_down, - .pull_tms_up = fmw_cpld_upg_pull_tms_up, - .pull_tms_down = fmw_cpld_upg_pull_tms_down, - .read_tdo = fmw_cpld_upg_read_tdo, - .init_cpld = fmw_cpld_upg_init_cpld, - .finish_cpld = fmw_cpld_upg_finish_cpld, -}; -#endif - -/** - * Each product initializes its own related CPLD driver and needs to re-define the interface - * In the new interface, assign the relevant driver to fmw_cpld through the fmw_cpld_upg_copy_firmware_info interface - */ -int __attribute__ ((weak))fmw_cpld_product_init(void) -{ - dev_debug(firmware_debug(), "Nothing cpld init for this product.\n"); - return 0; -} - -void __attribute__ ((weak))fmw_cpld_product_exit(void) -{ - dev_debug(firmware_debug(), "Nothing exit init for this product.\n"); - return; -} - -int fmw_cpld_upg_init(void) -{ - int ret; - mem_clear(fmw_cpld, FIRMWARE_MAX_CPLD_NUM * sizeof(firmware_cpld_t)); - ret = fmw_cpld_product_init(); - if (ret < 0) { - return ret; - } -#if 0 - set_currrent_cpld_info(&default_fmw_cpld); -#endif - - return 0; -} - -void fmw_cpld_upg_exit(void) -{ - fmw_cpld_product_exit(); - return; -} - -void fwm_cpld_tdi_op(int value) -{ - if (value) { - TDI_PULL_UP(); - } else { - TDI_PULL_DOWN(); - } -} - -void fwm_cpld_tck_op(int value) -{ - if (value) { - TCK_PULL_UP(); - } else { - TCK_PULL_DOWN(); - } -} - -void fwm_cpld_tms_op(int value) -{ - if (value) { - TMS_PULL_UP(); - } else { - TMS_PULL_DOWN(); - } -} - -int fwm_cpld_tdo_op() -{ - return TDO_READ(); -} diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/firmware_ispvme.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/firmware_ispvme.c deleted file mode 100644 index 9aabfeb5f6..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/firmware_ispvme.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - * Copyright(C) 2013 Ragile Network. All rights reserved. - */ -/* - * firmware.c - * Original Author : support 2013-10-25 - * - * firmware upgrade driver - * - * History - * v1.0 support 2013-10-25 Initial version. - * - */ -#include -#include -#include -#include - -int drv_debug = 0; -module_param(drv_debug, int, S_IRUGO | S_IWUSR); - -static LIST_HEAD(drv_list); -static LIST_HEAD(dev_list); - -void firmware_set_debug(int value) -{ - drv_debug = value; - return; -} - -int firmware_debug(void) -{ - return drv_debug; -} - -int firmware_driver_register(firmware_driver_t *fw_drv) -{ - int ret; - - if (fw_drv == NULL) { - return FIRMWARE_FAILED; - } - - ret = platform_driver_register(fw_drv->drv); - if (ret < 0) { - return FIRMWARE_FAILED; - } - - list_add(&fw_drv->list, &drv_list); - - return FIRMWARE_SUCCESS; -} - -void firmware_driver_unregister(firmware_driver_t *fw_drv) -{ - list_del_init(&fw_drv->list); - platform_driver_unregister(fw_drv->drv); -} - -int firmware_get_device_num(int type) -{ - int num; - firmware_device_t *tmp; - - num = 0; - list_for_each_entry(tmp, &dev_list, list) { - if (tmp->type == type) { - num++; - } - } - - return num; -} - -firmware_device_t *firmware_get_device_by_minor(int type, int minor) -{ - firmware_device_t *tmp; - - list_for_each_entry(tmp, &dev_list, list) { - if (tmp->type == type && tmp->dev.minor == minor) { - return tmp; - } - } - - return NULL; -} - -int firmware_device_register(firmware_device_t *fw_dev) -{ - int ret; - firmware_device_t *tmp; - - if (fw_dev == NULL) { - return FIRMWARE_FAILED; - } - - list_for_each_entry(tmp, &dev_list, list) { - if (strcmp(tmp->name, fw_dev->name) == 0) { - return FIRMWARE_FAILED; - } - } - - ret = misc_register(&fw_dev->dev); - if (ret < 0) { - return FIRMWARE_FAILED; - } - - list_add(&fw_dev->list, &dev_list); - return FIRMWARE_SUCCESS; -} - -void firmware_device_unregister(firmware_device_t *fw_dev) -{ - list_del(&fw_dev->list); - misc_deregister(&fw_dev->dev); -} - -static int __init firmware_driver_init(void) -{ - INIT_LIST_HEAD(&drv_list); - INIT_LIST_HEAD(&dev_list); - dev_debug(firmware_debug(), "firmware_driver_init cpld init.\n"); - firmware_cpld_init(); - - return FIRMWARE_SUCCESS; -} - -static void __exit firmware_driver_exit(void) -{ - dev_debug(firmware_debug(), "firmware_driver_exit cpld exit.\n"); - firmware_cpld_exit(); - INIT_LIST_HEAD(&drv_list); - INIT_LIST_HEAD(&dev_list); - return; -} - -module_init(firmware_driver_init); -module_exit(firmware_driver_exit); - -MODULE_AUTHOR("support "); -MODULE_DESCRIPTION("ragile Platform Support"); -MODULE_LICENSE("GPL"); \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/include/config_ispvme.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/include/config_ispvme.h deleted file mode 100644 index ac9f12006c..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/include/config_ispvme.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __CONFIG_H__ -#define __CONFIG_H__ - -#define JTAG_TDI (32) -#define JTAG_TDO (67) -#define JTAG_TCK (65) -#define JTAG_TMS (6) -#define JTAG_EN (50) - -#endif /* __CONFIG_H__ */ \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/include/firmware_cpld_ispvme.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/include/firmware_cpld_ispvme.h deleted file mode 100644 index 6c809aa0b9..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/include/firmware_cpld_ispvme.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef __FIRMWARE_CPLD_H__ -#define __FIRMWARE_CPLD_H__ - -#define FIRMWARE_DEV_NAME_LEN 32 -#define FIRMWARE_MAX_CPLD_NUM 16 - -typedef struct firmware_cpld_s { - char devname[FIRMWARE_DEV_NAME_LEN]; - int slot; - int chip_index; - int is_used; /* 0:unused 1:used */ - u32 tck_delay; /* delay time */ - void (*pull_tdi_up)(void); /* TDI pull up */ - void (*pull_tdi_down)(void); /* TDI pull dowm */ - void (*pull_tck_up)(void); /* TCK pull up */ - void (*pull_tck_down)(void); /* TCK pull dowm */ - void (*pull_tms_up)(void); /* TMS pull up */ - void (*pull_tms_down)(void); /* TCK pull dowm */ - int (*read_tdo)(void); /* read ?TDO */ - int (*init_cpld)(void); /* CPLD upgrade initialization operation */ - int (*init_chip)(int slot); /* Chip related initialization operations */ - int (*finish_chip)(int slot); /* Chip related completion operations */ - int (*finish_cpld)(void); /* CPLD upgrade completion operation */ - int (*check_upgrade_data)(char *src, int src_len, int *dst, int dst_len); - int (*touch_watch_dog)(void); /* touch watch dog related operation */ - int (*keeplive)(void); /* KEEPLIVE */ - int (*get_version)(int slot, char *ver, int len); - int (*get_card_name)(char *name, int len); /* get card name */ -} firmware_cpld_t; - -typedef int (*firmware_set_gpio_info_func_t)(firmware_upg_gpio_info_t *info); - -extern int fmw_cpld_upg_get_chip_name(int slot, firmware_cpld_t *cpld, char *info, int len); -extern int fmw_cpld_upg_get_card_name(int slot, firmware_cpld_t *cpld, char *info, int len); -extern int fmw_cpld_upg_program(int slot, firmware_cpld_t *cpld, char *info, int len); -extern int fmw_cpld_upg_get_version(int slot, firmware_cpld_t *cpld, char *info, int len); -extern firmware_cpld_t *fmw_cpld_upg_get_cpld(char *name); -extern int fmw_cpld_upg_init(void); -extern void fmw_cpld_upg_exit(void); -extern int fmw_cpld_upg_copy_firmware_info(firmware_cpld_t *info); -extern int fmw_cpld_upg_get_chip_info(int slot, firmware_cpld_t *cpld, void *info, int len); - -extern void fwm_cpld_tdi_op(int value); -extern void fwm_cpld_tck_op(int value); -extern void fwm_cpld_tms_op(int value); -extern int fwm_cpld_tdo_op(void); -extern void firmware_cpld_upgrade_init(void); -extern void firmware_cpld_upgrade_finish(void); -extern int fmw_cpld_set_gpio_info(firmware_upg_gpio_info_t *info); -extern void fmw_cpld_reg_gpio_info_set_func(firmware_set_gpio_info_func_t func); - -#endif /* __FIRMWARE_CPLD_H__ */ \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/include/firmware_ispvme.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/include/firmware_ispvme.h deleted file mode 100644 index 7568602770..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/include/firmware_ispvme.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef __FIRMWARE_H__ -#define __FIRMWARE_H__ - -#include -#include - -#include -#include - -#define mem_clear(data, size) memset((data), 0, (size)) -#define dev_debug(debug, fmt, arg...) \ - if (debug == 1) { do{printk(KERN_ERR fmt,##arg);} while(0); } - -#define FIRMWARE_NAME_LEN 48 - -#define FIRMWARE_FAILED (-1) -#define FIRMWARE_SUCCESS 0 - -enum firmware_type_s { - FIRMWARE_CPLD = 0, - FIRMWARE_FPGA, -}; - -/* ioctl command */ -#define FIRMWARE_TYPE 'F' -#define FIRMWARE_JTAG_TDI _IOR(FIRMWARE_TYPE, 0, char) -#define FIRMWARE_JTAG_TDO _IOR(FIRMWARE_TYPE, 1, char) -#define FIRMWARE_JTAG_TCK _IOR(FIRMWARE_TYPE, 2, char) -#define FIRMWARE_JTAG_TMS _IOR(FIRMWARE_TYPE, 3, char) -#define FIRMWARE_JTAG_EN _IOR(FIRMWARE_TYPE, 4, char) -#define FIRMWARE_SET_DEBUG_ON _IOW(FIRMWARE_TYPE, 5, int) /* debug on */ -#define FIRMWARE_SET_DEBUG_OFF _IOW(FIRMWARE_TYPE, 6, int) /* debug off */ -#define FIRMWARE_SET_GPIO_INFO _IOR(FIRMWARE_TYPE, 7, int) /* Set GPIO pin configuration */ - -typedef struct cmd_info_s { - int size; - void __user *data; -} cmd_info_t; - -typedef struct firmware_device_s { - struct list_head list; /* device linked list */ - int type; /* the type of device */ - int slot; /* position */ - char name[FIRMWARE_NAME_LEN]; /* name */ - struct miscdevice dev; /* device */ - void *priv; /* private data */ -} firmware_device_t; - -typedef struct firmware_driver_s { - struct list_head list; /* linked list */ - int type; /* type */ - char name[FIRMWARE_NAME_LEN]; /* name */ - struct platform_driver *drv; /* driver */ - void *priv; /* private data */ -} firmware_driver_t; - -typedef struct gpio_group_s { - int pin; - int val; - int dir; -} gpio_group_t; - -typedef struct firmware_upg_gpio_info_s { - int tdi; - int tck; - int tms; - int tdo; - int jtag_en; - int select; - gpio_group_t jtag_5; - gpio_group_t jtag_4; - gpio_group_t jtag_3; - gpio_group_t jtag_2; - gpio_group_t jtag_1; -} firmware_upg_gpio_info_t; - -extern int firmware_debug(void); -extern void firmware_set_debug(int value); -extern firmware_device_t *firmware_get_device_by_minor(int type, int minor); -extern int firmware_get_device_num(int type); -extern int firmware_device_register(firmware_device_t *fw_dev); -extern void firmware_device_unregister(firmware_device_t *fw_dev); -extern int firmware_driver_register(firmware_driver_t *fw_drv); -extern void firmware_driver_unregister(firmware_driver_t *fw_drv); -extern void firmware_fpga_init(void); -extern void firmware_cpld_init(void); -extern void firmware_fpga_exit(void); -extern void firmware_cpld_exit(void); - -#endif /* end of __FIRMWARE_H__ */ \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/ra_b6010_48gt4x.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/ra_b6010_48gt4x.c deleted file mode 100644 index 880fffbfc8..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/ra_b6010_48gt4x.c +++ /dev/null @@ -1,493 +0,0 @@ -/** - * Copyright(C) 2013 Ragile Network. All rights reserved. - */ -/* - * ca-octeon-cmx.c - * Original Author : support 2013-10-25 - * ca-octeon-cmx CPLD upgrade driver - * - * firmware upgrade driver - * - * History - * v1.0 support 2013-10-25 Initial version. - */ - -#include -#include -#include -#if 0 -#include -#include -#endif -#include -#include -#include "ra_b6010_48gt4x.h" - -/* extern void cmic_gpio_set_output_value(int gpio, int val); */ -firmware_device_info_t *current_info = NULL; -static firmware_device_info_t set_gpio_info; -static int set_gpio_info_flag = 0; -firmware_device_info_t default_cpld_info = { - .type = 0, - .tdi = JTAG_TDI, - .tck = JTAG_TCK, - .tms = JTAG_TMS, - .tdo = JTAG_TDO, - .jtag_en = JTAG_EN, - .select = -1, - .cmic_start_gpio = -1, - .cmic_end_gpio = -1, -}; - -firmware_device_info_t as13_cpld_info = { - .type = 0, - .tdi = 67, - .tck = JTAG_TCK, - .tms = JTAG_TMS, - .tdo = 32, - .jtag_en = JTAG_EN, - .select = 48, - .cmic_start_gpio = -1, - .cmic_end_gpio = -1, -}; - -static int firmware_cpld_gpio_is_from_cmic(int gpio) -{ - if (current_info == NULL) { - return -1; - } - - dev_debug(firmware_debug(), "gpio %d current_info.cmic_start_gpio %d current_info.cmic_end_gpio %d.\n", - gpio, current_info->cmic_start_gpio, current_info->cmic_end_gpio); - - if ((current_info->cmic_start_gpio == -1) || (current_info->cmic_end_gpio == -1)) { - return 0; - } - - if ((gpio >= current_info->cmic_start_gpio) && (gpio <= current_info->cmic_end_gpio)) { - return 1; - } - - return 0; -} - -static int firmware_cpld_gpio_get_value(int gpio) -{ -#if 0 - int ret; - - ret = firmware_cpld_gpio_is_from_cmic(gpio); - if (ret < 0) { - dev_debug(firmware_debug(), "firmware_cpld_gpio_is_from_cmic gpio %d failed ret %d.\n", - gpio, ret); - return -1; - } - - if (ret == 1) { - /* Not currently supported */ - dev_debug(firmware_debug(), "gpio %d not support to get value.\n", gpio); - return -1; - } else { - return __gpio_get_value(gpio); - } -#endif - - return __gpio_get_value(gpio); -} - -static void firmware_cpld_gpio_set_output_value(int gpio, int val) -{ -#if 0 - int ret; - - ret = firmware_cpld_gpio_is_from_cmic(gpio); - if (ret < 0) { - dev_debug(firmware_debug(), "firmware_cpld_gpio_is_from_cmic gpio %d failed ret %d.\n", - gpio, ret); - return; - } - - if (ret == 1) { - __gpio_set_value(gpio, val); - /*cmic_gpio_set_output_value(gpio, val);*/ - } else { - __gpio_set_value(gpio, val); - } -#endif - - __gpio_set_value(gpio, val); -} - -static void firmware_cpld_gpio_set_direction(int gpio, int out) -{ - if (out) { - gpio_direction_output(gpio, 1); - } else { - gpio_direction_input(gpio); - } - - return; -} - -static void firmware_cpld_gpio_request(int gpio, char *name) -{ - int ret; - - ret = firmware_cpld_gpio_is_from_cmic(gpio); - if (ret < 0) { - dev_debug(firmware_debug(), "firmware_cpld_gpio_is_from_cmic gpio %d failed ret %d.\n", - gpio, ret); - return; - } - - if (ret == 1) { - /* do nothing */ - } else { - gpio_request(gpio, name); - } - - return; -} - -static void firmware_cpld_gpio_free(int gpio) -{ - int ret; - - ret = firmware_cpld_gpio_is_from_cmic(gpio); - if (ret < 0) { - dev_debug(firmware_debug(), "firmware_cpld_gpio_is_from_cmic gpio %d failed ret %d.\n", - gpio, ret); - return; - } - - if (ret == 1) { - /* do nothing */ - } else { - gpio_free(gpio); - } - - return; -} - -/* CPLD upgrade initialization operation */ -static int init_cpld(void) -{ - if (current_info == NULL) { - return -1; - } - - firmware_cpld_gpio_request(current_info->tdi, "cpld_upgrade"); - firmware_cpld_gpio_request(current_info->tck, "cpld_upgrade"); - firmware_cpld_gpio_request(current_info->tms, "cpld_upgrade"); - firmware_cpld_gpio_request(current_info->jtag_en, "cpld_upgrade"); - if (current_info->select >= 0) { - firmware_cpld_gpio_request(current_info->select, "cpld_upgrade"); - } - firmware_cpld_gpio_request(current_info->tdo, "cpld_upgrade"); - if (current_info->jtag_4.pin >= 0){ - firmware_cpld_gpio_request(current_info->jtag_1.pin, "cpld_upgrade"); - firmware_cpld_gpio_request(current_info->jtag_2.pin, "cpld_upgrade"); - firmware_cpld_gpio_request(current_info->jtag_3.pin, "cpld_upgrade"); - firmware_cpld_gpio_request(current_info->jtag_4.pin, "cpld_upgrade"); - firmware_cpld_gpio_request(current_info->jtag_5.pin, "cpld_upgrade"); - } - return 0; -} - -/* CPLD upgrade completion operation */ -static int finish_cpld(void) -{ - if (current_info == NULL) { - return -1; - } - - firmware_cpld_gpio_set_output_value(current_info->jtag_en, 0); - if (current_info->select >= 0) { - firmware_cpld_gpio_set_output_value(current_info->select, 0); - } - if (current_info->jtag_4.pin >= 0) { - gpio_direction_input(current_info->jtag_4.pin); - gpio_direction_input(current_info->jtag_1.pin); - gpio_direction_input(current_info->jtag_2.pin); - gpio_direction_input(current_info->jtag_3.pin); - gpio_direction_input(current_info->jtag_5.pin); - } - firmware_cpld_gpio_free(current_info->tdi); - firmware_cpld_gpio_free(current_info->tck); - firmware_cpld_gpio_free(current_info->tms); - firmware_cpld_gpio_free(current_info->jtag_en); - firmware_cpld_gpio_free(current_info->tdo); - if (current_info->jtag_4.pin >= 0) { - firmware_cpld_gpio_free(current_info->jtag_1.pin); - firmware_cpld_gpio_free(current_info->jtag_2.pin); - firmware_cpld_gpio_free(current_info->jtag_3.pin); - firmware_cpld_gpio_free(current_info->jtag_4.pin); - firmware_cpld_gpio_free(current_info->jtag_5.pin); - } - - if (current_info->select >= 0) { - firmware_cpld_gpio_free(current_info->select); - } - - if (set_gpio_info_flag == 1) { - memcpy(current_info, &set_gpio_info, sizeof(firmware_device_info_t)); - set_gpio_info_flag = 0; - } - - dev_debug(firmware_debug(), "%s %d\n", __func__, __LINE__); - - return 0; -} - -static void init_chip_pre(void) -{ - - dev_debug(firmware_debug(), "%s %d\n", __func__, __LINE__); - - /* to be reset every time when upgrade,solve the use of MAC side GPIO, - During the startup process, the MAC terminal will be reset, causing the problem of invalid settings */ - firmware_cpld_gpio_set_direction(current_info->tdi, 1); - firmware_cpld_gpio_set_direction(current_info->tck, 1); - firmware_cpld_gpio_set_direction(current_info->tms, 1); - firmware_cpld_gpio_set_direction(current_info->jtag_en, 1); - if (current_info->select >= 0) { - firmware_cpld_gpio_set_direction(current_info->select, 1); - } - if (current_info->jtag_4.pin >= 0) { - firmware_cpld_gpio_set_direction(current_info->jtag_4.pin, 1); - firmware_cpld_gpio_set_direction(current_info->jtag_3.pin, 1); - firmware_cpld_gpio_set_direction(current_info->jtag_2.pin, 1); - firmware_cpld_gpio_set_direction(current_info->jtag_1.pin, 1); - firmware_cpld_gpio_set_direction(current_info->jtag_5.pin, 1); - } - - firmware_cpld_gpio_set_output_value(current_info->tdi, 1); - firmware_cpld_gpio_set_output_value(current_info->tck, 1); - firmware_cpld_gpio_set_output_value(current_info->tms, 1); - firmware_cpld_gpio_set_output_value(current_info->jtag_en, 1); - if (current_info->jtag_4.pin >= 0) { - firmware_cpld_gpio_set_output_value(current_info->jtag_1.pin, current_info->jtag_1.val); - firmware_cpld_gpio_set_output_value(current_info->jtag_2.pin, current_info->jtag_2.val); - firmware_cpld_gpio_set_output_value(current_info->jtag_3.pin, current_info->jtag_3.val); - firmware_cpld_gpio_set_output_value(current_info->jtag_4.pin, current_info->jtag_4.val); - firmware_cpld_gpio_set_output_value(current_info->jtag_5.pin, current_info->jtag_5.val); - } - if (current_info->select >= 0) { - firmware_cpld_gpio_set_output_value(current_info->select, 1); - } - - firmware_cpld_gpio_set_direction(current_info->tdo, 0); - return; -} - -static int init_chip(int slot) -{ - - dev_debug(firmware_debug(), "%s %d\n", __func__, __LINE__); - - if (current_info == NULL) { - return -1; - } - init_chip_pre(); - - dev_debug(firmware_debug(), "tdi %d %d\n",current_info->tdi, firmware_cpld_gpio_get_value(current_info->tdi)); - dev_debug(firmware_debug(), "tdo %d %d\n",current_info->tdo, firmware_cpld_gpio_get_value(current_info->tdo)); - dev_debug(firmware_debug(), "tck %d %d\n",current_info->tck, firmware_cpld_gpio_get_value(current_info->tck)); - dev_debug(firmware_debug(), "tms %d %d\n",current_info->tms, firmware_cpld_gpio_get_value(current_info->tms)); - dev_debug(firmware_debug(), " jtag_en:%d %d\n",current_info->jtag_en, firmware_cpld_gpio_get_value(current_info->jtag_en)); - if (current_info->select >= 0) { - dev_debug(firmware_debug(), " select:%d %d\n",current_info->select, firmware_cpld_gpio_get_value(current_info->select)); - } - - return 0; -} - -static int finish_chip(int slot) -{ - if (current_info == NULL) { - return -1; - } - - firmware_cpld_gpio_set_output_value(current_info->jtag_en, 0); - if (current_info->select >= 0) { - firmware_cpld_gpio_set_output_value(current_info->select, 0); - } - if (current_info->jtag_4.pin >= 0) { - firmware_cpld_gpio_set_output_value(current_info->jtag_4.pin, 1); - } - - return 0; -} - -/* TDI pull up */ -static void pull_tdi_up(void) -{ - if (current_info == NULL) { - return; - } - firmware_cpld_gpio_set_output_value(current_info->tdi, 1); -} - -/* TDI pull dowm */ -static void pull_tdi_down(void) -{ - if (current_info == NULL) { - return; - } - firmware_cpld_gpio_set_output_value(current_info->tdi, 0); -} - -/* TCK pull up */ -static void pull_tck_up(void) -{ - if (current_info == NULL) { - return; - } - firmware_cpld_gpio_set_output_value(current_info->tck, 1); -} - -/* TCK pull down */ -static void pull_tck_down(void) -{ - if (current_info == NULL) { - return; - } - firmware_cpld_gpio_set_output_value(current_info->tck, 0); -} - -/* TMS pull up */ -static void pull_tms_up(void) -{ - if (current_info == NULL) { - return; - } - firmware_cpld_gpio_set_output_value(current_info->tms, 1); -} - -/* TCK pull dowm */ -static void pull_tms_down(void) -{ - if (current_info == NULL) { - return; - } - firmware_cpld_gpio_set_output_value(current_info->tms, 0); -} - -/* read TDO */ -static int read_tdo(void) -{ - if (current_info == NULL) { - return -1; - } - return firmware_cpld_gpio_get_value(current_info->tdo); -} - -int B6510_fmw_set_gpio_info(firmware_upg_gpio_info_t *info) -{ - if (info == NULL) { - dev_debug(firmware_debug(), "set gpio info info %p is null.\n", info); - return -1; - } - - set_gpio_info.tdi = info->tdi; - set_gpio_info.tck = info->tck; - set_gpio_info.tms = info->tms; - set_gpio_info.tdo = info->tdo; - set_gpio_info.jtag_en = info->jtag_en; - set_gpio_info.select= info->select; - set_gpio_info.jtag_5.pin = info->jtag_5.pin; - set_gpio_info.jtag_4.pin = info->jtag_4.pin; - set_gpio_info.jtag_3.pin = info->jtag_3.pin; - set_gpio_info.jtag_2.pin = info->jtag_2.pin; - set_gpio_info.jtag_1.pin = info->jtag_1.pin; - set_gpio_info.jtag_5.val = info->jtag_5.val; - set_gpio_info.jtag_4.val = info->jtag_4.val; - set_gpio_info.jtag_3.val = info->jtag_3.val; - set_gpio_info.jtag_2.val = info->jtag_2.val; - set_gpio_info.jtag_1.val = info->jtag_1.val; - set_gpio_info_flag = 1; - dev_debug(firmware_debug(), "set gpio info[tdi:%d tck:%d tms:%d tdo:%d jtag_en:%d select:%d].\n", - info->tdi, info->tck, info->tms, info->tdo, info->jtag_en, info->select); - return 0; -} - -firmware_cpld_t fmw_cpld0 = { - .devname = "firmware_cpld_ispvme0", - .slot = 1, - .chip_index = 1, - .is_used = 1, - .tck_delay = 60, - .pull_tdi_up = pull_tdi_up, - .pull_tdi_down = pull_tdi_down, - .pull_tck_up = pull_tck_up, - .pull_tck_down = pull_tck_down, - .pull_tms_up = pull_tms_up, - .pull_tms_down = pull_tms_down, - .read_tdo = read_tdo, - .init_cpld = init_cpld, - .init_chip = init_chip, - .finish_chip = finish_chip, - .finish_cpld = finish_cpld, - .get_version = NULL, -}; - -static void cpld_release(struct device *dev) -{ - return; -} - -static struct platform_device cpld = { - .name = "firmware_cpld_ispvme", - .id = 0, - .num_resources = 0, - .dev = { - .release = cpld_release, - } -}; - -extern void set_currrent_cpld_info(firmware_cpld_t *info); -extern int dfd_get_my_card_type(void); - -int fmw_cpld_product_init(void) -{ - current_info = NULL; -#if 0 - int dev_type; - int i; - - dev_type = drv_get_my_dev_type(); - if (dev_type < 0) { - printk(KERN_ERR "Failed to get device type, when upgrade cpld.\n"); - return FIRMWARE_FAILED; - } - - for (i = 0; i < sizeof(cpld_info)/sizeof(cpld_info[0]); i++) { - if (cpld_info[i].type == dev_type) { - current_info = &cpld_info[i]; - printk(KERN_ERR "device type 0x%x match i %d.\n", dev_type, i); - printk(KERN_ERR "tdi[%d] tck[%d] tms[%d] tdo[%d] jtat_en[%d].\n", current_info->tdi, - current_info->tck, current_info->tms, current_info->tdo, current_info->jtag_en); - } - } -#endif - - if (current_info == NULL) { - current_info = &default_cpld_info; - } - - platform_device_register(&cpld); - fmw_cpld_upg_copy_firmware_info(&fmw_cpld0); - - /* fmw_cpld0.init_cpld(); */ - set_currrent_cpld_info(&fmw_cpld0); - - fmw_cpld_reg_gpio_info_set_func(B6510_fmw_set_gpio_info); - - return FIRMWARE_SUCCESS; -} - -void fmw_cpld_product_exit(void) -{ - platform_device_unregister(&cpld); - return; -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/ra_b6010_48gt4x.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/ra_b6010_48gt4x.h deleted file mode 100644 index 90307c4117..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver_ispvme/ra_b6010_48gt4x.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __CONFIG_H__ -#define __CONFIG_H__ - -#include - -#define JTAG_TDI (32) -#define JTAG_TDO (67) -#define JTAG_TCK (65) -#define JTAG_TMS (6) -#define JTAG_EN (50) - -typedef struct firmware_device_info_s { - int type; - int tdi; - int tck; - int tms; - int tdo; - int jtag_en; - int select; - gpio_group_t jtag_5; - gpio_group_t jtag_4; - gpio_group_t jtag_3; - gpio_group_t jtag_2; - gpio_group_t jtag_1; - int cmic_start_gpio; - int cmic_end_gpio; -} firmware_device_info_t; - -#endif /* __CONFIG_H__ */ \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/Makefile b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/Makefile deleted file mode 100644 index c42c9bf3d2..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -include $(top_srcdir)/Rules.mk - -OBJ = firmware_app_ispvme.o debug_ispvme.o hardware.o ispvm_ui.o ivm_core.o dfd_fpga_pkt.o dfd_fpga_upg.o dfd_fpga_debug.o -LIB += $(BUILD_CFALGS) $(BUILD_LDFLAGS) -lpthread -lreadline -lncurses -ifdef ENABLE_GCOV -ifeq ($(ENABLE_GCOV), y) -LIB += -lgcov -endif -endif # ENABLE_GCOV -APP = firmware_upgrade -BUILD_DIR = tmp -ELF_FILE = $(BUILD_DIR)/$(APP) -MAP_FILE = $(BUILD_DIR)/$(APP).map.sym -INCLUDE = -Iinclude - -.PHONY: build -build:make-dir $(addprefix $(BUILD_DIR)/,$(OBJ)) - $(CC) -o $(ELF_FILE) $(addprefix $(BUILD_DIR)/,$(OBJ)) $(LINKFLAGS) $(LIB) - $(NM) $(ELF_FILE) | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' \ - | sort > $(MAP_FILE) - @if [ ! -d $(common_out_put_dir) ]; then mkdir -p $(common_out_put_dir) ;fi - cp -p $(ELF_FILE) $(common_out_put_dir) - -# build -.PHONY: make-dir -make-dir: - @mkdir -p $(BUILD_DIR) - -$(BUILD_DIR)/%.o:%.c - $(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@ - -.PHONY: install -install: - echo "firmware_upgrade install success." - cp -p $(ELF_FILE) $(common_out_put_dir) - -.PHONY: clean -clean: - rm -rf $(BUILD_DIR) diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/common.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/common.h deleted file mode 100644 index 208c415f36..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/common.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __COMMON_H__ -#define __COMMON_H__ - -#include -#include -#include -#include -#include -#include - -#define FIRMWARE_TYPE 'F' -#define FIRMWARE_JTAG_TDI _IOR(FIRMWARE_TYPE, 0, char) -#define FIRMWARE_JTAG_TDO _IOR(FIRMWARE_TYPE, 1, char) -#define FIRMWARE_JTAG_TCK _IOR(FIRMWARE_TYPE, 2, char) -#define FIRMWARE_JTAG_TMS _IOR(FIRMWARE_TYPE, 3, char) -#define FIRMWARE_JTAG_EN _IOR(FIRMWARE_TYPE, 4, char) -#define FIRMWARE_SET_DEBUG_ON _IOW(FIRMWARE_TYPE, 5, int) /* debug on */ -#define FIRMWARE_SET_DEBUG_OFF _IOW(FIRMWARE_TYPE, 6, int) /* debug off */ -#define FIRMWARE_SET_GPIO_INFO _IOR(FIRMWARE_TYPE, 7, int) /* set GPIO pin configuration */ - -#define JTAG_TDI (1) -#define JTAG_TDO (2) -#define JTAG_TCK (3) -#define JTAG_TMS (4) -#define JTAG_ENABLE (5) -#define JTAG_TRST (6) - -#endif \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/debug_ispvme.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/debug_ispvme.c deleted file mode 100644 index 0b49ad034d..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/debug_ispvme.c +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright(C) 2013 Ragile Network. All rights reserved. - */ -/* - * debug.c - * - * firmware upgrade debug control - * - * Original Author : support 2013-10-25 - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * firmware_upgrade_debug:handle debug switch - * - * analyse file /tmp/firmware_upgrade_debug,return the information correspoding to debug - * - * return:return DEBUG_OFF when debug off,return DEBUG_ON when debug on,return DEBUG_IGNORE in other cases - */ -int firmware_upgrade_debug(void) -{ - int size; - FILE *fp; - char debug_info[DEBUG_INFO_LEN] = {0}; - - fp = fopen(DEBUG_FILE, "r"); - if (fp == NULL) { - return DEBUG_IGNORE; - } - - size = fread(debug_info, DEBUG_INFO_LEN - 1, 1, fp); - if (size < 0) { - fclose(fp); - return DEBUG_IGNORE; - } - - if (strncmp(debug_info, DEBUG_ON_INFO, 1) == 0) { - fclose(fp); - return DEBUG_APP_ON; - } - - if (strncmp(debug_info, DEBUG_ON_KERN, 1) == 0) { - fclose(fp); - return DEBUG_KERN_ON; - } - - if (strncmp(debug_info, DEBUG_ON_ALL, 1) == 0) { - fclose(fp); - return DEBUG_ALL_ON; - } - - if (strncmp(debug_info, DEBUG_OFF_INFO, 1) == 0) { - fclose(fp); - return DEBUG_OFF; - } - - fclose(fp); - return DEBUG_IGNORE; -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_debug.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_debug.c deleted file mode 100644 index f9deb51e24..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_debug.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright(C) 2001-2013 Ragile Network. All rights reserved. - */ -/* - * dfd_debug.c - * - * Function:Device framework driver debugging interface - * - * History - * v1.0 support 2013-10-25 Initial version. - */ - -#include -#include - -#include -#include -#include -#include -#include - -#include "dfd_fpga_debug.h" - -#undef ARRAY_SIZE -#define ARRAY_SIZE(a) (sizeof(a) /sizeof((a)[0])) -/* Debug switch storage of dfd module */ -int g_dfd_fpga_debug = 0x0; - -/** - * dfd_fpga_pkt_debug_set - Debug switch setting interface of dfd module - * @type: Types of debugging information - * @enable: enable/Disable debugging information - * - * return 0 if success, otherwise reuturn -1. - */ -static int dfd_fpga_pkt_debug_set(int type, int enable) -{ - - if (type >= DFD_DBG_CNT || type < 0) { - DFD_ERROR("unknow dfd debug type=%d\n", type); - return -1; - } - - if (enable) { - g_dfd_fpga_debug |= 1U << type; - } else { - g_dfd_fpga_debug &= ~(1U << type); - } - - return 0; -} - -void dfd_fpga_open_debug(int val) -{ - if (val == 1) { - (void)dfd_fpga_pkt_debug_set(DFD_DBG_ERR, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_WARN, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_VBOSE, 1); - } else if (val == 2) { - (void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 1); - } else if (val == 3) { - (void)dfd_fpga_pkt_debug_set(DFD_DBG_ERR, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_WARN, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_VBOSE, 1); - (void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_DBG, 1); - } else if (val == 4) { - (void)dfd_fpga_pkt_debug_set(DFD_DBG_DBG, 1); - } else { - (void)dfd_fpga_pkt_debug_set(DFD_DBG_ERR, 0); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_WARN, 0); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_VBOSE, 0); - (void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 0); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_DBG, 0); - } - - return; -} - -void dfd_fpga_debug_init(void) -{ - FILE *fp; - char buf[10] = {0}; - - fp = fopen(DFD_DEBUG_FILE, "r"); - if (fp != NULL) { - if (fgets(buf, sizeof(buf), fp) != NULL) { - if (strstr(buf, DFD_DEBUG_SET_NO_WARN) != NULL) { - (void)dfd_fpga_pkt_debug_set(DFD_DBG_ERR, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_WARN, 0); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_VBOSE, 0); - (void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 0); - } else if (strstr(buf, DFD_DEBUG_SET_NO_VBOSE) != NULL) { - (void)dfd_fpga_pkt_debug_set(DFD_DBG_ERR, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_WARN, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_VBOSE, 0); - (void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 0); - } else if (strstr(buf, DFD_DEBUG_SET_NO_FLOCK_VBOSE) != NULL) { - (void)dfd_fpga_pkt_debug_set(DFD_DBG_ERR, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_WARN, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_VBOSE, 1); - (void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 0); - } else if (strstr(buf, DFD_DEBUG_SET_ALL) != NULL) { - (void)dfd_fpga_pkt_debug_set(DFD_DBG_ERR, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_WARN, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_VBOSE, 1); - (void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 1); - (void)dfd_fpga_pkt_debug_set(DFD_DBG_DBG, 1); - } else if (strstr(buf, DFD_DEBUG_SET_DBG) != NULL) { - (void)dfd_fpga_pkt_debug_set(DFD_DBG_DBG, 1); - } else if (strstr(buf, DFD_DEBUG_SET_FLOCK) != NULL) { - (void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 1); - } - } - - fclose(fp); - } - - return; -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_debug.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_debug.h deleted file mode 100644 index 501ba7f373..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_debug.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _DFD_FPGA_DEBUG_H_ -#define _DFD_FPGA_DEBUG_H_ - -#include -#include -#include - -#define DFD_DEBUG_FILE "/sbin/.dfd_debug_flag" - -#define DFD_DEBUG_SET_NO_WARN "0x1" -#define DFD_DEBUG_SET_NO_VBOSE "0x3" -#define DFD_DEBUG_SET_NO_FLOCK_VBOSE "0x7" -#define DFD_DEBUG_SET_ALL "0xf" -#define DFD_DEBUG_SET_DBG "0xd" -#define DFD_DEBUG_SET_FLOCK "0xe" -#define mem_clear(data, size) memset((data), 0, (size)) - -#define DFD_DEBUG_CHECK(type) (g_dfd_fpga_debug & (1U << (type))) - -#define DFD_ERROR(fmt, args...) do { \ - if (DFD_DEBUG_CHECK(DFD_DBG_ERR)) { \ - printf("[%s-%s]:\n" fmt, "DFD", "err", \ - __FILE__, __FUNCTION__, __LINE__, ##args); \ - } \ -} while (0) - -#define DFD_WARN(fmt, args...) do { \ - if (DFD_DEBUG_CHECK(DFD_DBG_WARN)) { \ - printf("[%s-%s]:\n" fmt, "DFD", "warn", \ - __FILE__, __FUNCTION__, __LINE__, ##args); \ - } \ -} while (0) - -#define DFD_VERBOS(fmt, args...) do { \ - if (DFD_DEBUG_CHECK(DFD_DBG_VBOSE)) { \ - printf("[%s-%s]:\n" fmt, "DFD", "vbose", \ - __FILE__, __FUNCTION__, __LINE__, ##args); \ - } \ -} while (0) - -#define DFD_FLOCK_VERBOS(fmt, args...) do { \ - if (DFD_DEBUG_CHECK(DFD_FLOCK_DBG_VBOSE)) { \ - printf("[%s-%s]:\n" fmt, "DFD", "flock_vbose", \ - __FILE__, __FUNCTION__, __LINE__, ##args); \ - } \ -} while (0) - -#define DFD_DBG(fmt, args...) do { \ - if (DFD_DEBUG_CHECK(DFD_DBG_DBG)) { \ - printf("" fmt,\ - ##args); \ - } \ - } while (0) -/* define the type of debugging information */ -typedef enum { - DFD_DBG_ERR, - DFD_DBG_WARN, - DFD_DBG_VBOSE, - DFD_FLOCK_DBG_VBOSE, - DFD_DBG_DBG, - DFD_DBG_CNT -} DFD_DEBUG_TYPE_E; - -extern int g_dfd_fpga_debug; - -int dfd_fpga_debug_set(int type, int enable); -void dfd_fpga_open_debug(int val); -void dfd_fpga_debug_init(void); - -#endif \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_pkt.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_pkt.c deleted file mode 100644 index 8014267806..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_pkt.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - * Copyright(C) 2001-2012 Ragile Network. All rights reserved. - */ -/* - * dfd_fpga_pkt.c - * - * FPGA message interaction related interface - * - * History - * v1.0 support 2013-10-25 Initial version. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dfd_fpga_pkt.h" -#include "dfd_fpga_debug.h" - -#define DFD_FPGA_FAC_MODE_CONFIG_FILE "/tmp/.factory_disabale_cli_tty" -#if 1 -#define DFD_FPGA_PKT_SEND_PKT_TO_FRAME -#endif - -void dfd_fpga_pkt_print(uint8_t *buf, int buf_len) -{ - int i; - - for (i = 0; i < buf_len; i++) { - if ((i % 16) == 0) { - DFD_DBG("\n"); - } - DFD_DBG("%02x ", buf[i]); - } - - DFD_DBG("\n"); - return; -} - -static unsigned int littel_endian_byte_to_word32(uint8_t *byte_buf, int len) -{ - uint8_t tmp_buf[4]; - unsigned int word; - - word = 0; - - mem_clear(tmp_buf, 4); - memcpy(tmp_buf, byte_buf, len < 4 ? len : 4); - - word = tmp_buf[0] | (tmp_buf[1] << 8) | (tmp_buf[2] << 16) | (tmp_buf[3] << 24); - - return word; -} - -static int littel_endian_word32_to_byte(uint8_t *byte_buf, int len, unsigned int word) -{ - uint8_t tmp_buf[4]; - int ret; - - if (len < 4) { - DFD_ERROR("Not enough buf, word32 to byte: len[%d], word[0x%x]\n"); - return -1; - } - - mem_clear(tmp_buf, 4); - tmp_buf[0] = word & 0xff; - tmp_buf[1] = (word >> 8) & 0xff; - tmp_buf[2] = (word >> 16) & 0xff; - tmp_buf[3] = (word >> 24) & 0xff; - - memcpy(byte_buf, tmp_buf, 4); - - return 0; -} - -static int open_pci_dev(dfd_pci_dev_priv_t *pci_priv, int is_cfg) -{ - int file, ret; - char filename[DFD_PCI_MAX_NAME_SIZE]; - - if (is_cfg) { - ret = snprintf(filename, DFD_PCI_MAX_NAME_SIZE, - "/sys/class/pci_bus/%04x:%02x/device/%04x:%02x:%02x.%d/config", - 0, pci_priv->pcibus, 0, pci_priv->pcibus, pci_priv->slot, pci_priv->fn); - } else { - ret = snprintf(filename, DFD_PCI_MAX_NAME_SIZE, - "/sys/class/pci_bus/%04x:%02x/device/%04x:%02x:%02x.%d/resource%d", - 0, pci_priv->pcibus, 0, pci_priv->pcibus, pci_priv->slot, pci_priv->fn, - pci_priv->bar); - } - - filename[ret] = '\0'; - if ((file = open(filename, O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO)) < 0) { - DFD_ERROR("Error: Could not open file %s\n", filename); - } - - return file; -} - -/** - * dfd_fpga_buf_read - provide FPGA write register interface (address must be four-byte aligned) - * @dst: The data structure of sslot and unit corresponding to the target chip - * @addr: address (four-byte alignment). For the byte alignment required by the specific FPGA address, please refer to the FPGA manual - * @buf: Buffer for reading data - * @wr_len: the length of reading data,please refer to the FPGA manual for the length of the specific FPGA address requirements - * return: return if success,else return -1 - */ -int dfd_fpga_pci_read(dfd_pci_dev_priv_t *pci_priv, int offset, uint8_t *buf, int rd_len) -{ - int ret, fd; - unsigned int data; - uint8_t *ptr, *ptr_data; - struct stat sb; - int i; - int len, align; - - if ((pci_priv == NULL) || (buf == NULL)) { - DFD_ERROR("pci_prive or read buf is null.\n"); - return -1; - } - - if ((pci_priv->align < 1) || (offset & (pci_priv->align - 1)) || (rd_len & (pci_priv->align - 1))) { - DFD_ERROR("offset[%d] or rd_len[%d] don't align[%d].\n", offset, rd_len, pci_priv->align); - return -1; - } - - if ((fd = open_pci_dev(pci_priv, 0)) < 0) { - return -1; - } - - if ((ret = fstat(fd, &sb)) == -1) { - DFD_ERROR("Error: Could not fstat : %s\n", strerror(errno)); - close(fd); - return -1; - } - - if (offset + rd_len >= sb.st_size) { - DFD_ERROR("Error: offset is out of range\n"); - close(fd); - return -1; - } - - if ((ptr = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, - MAP_SHARED, fd, 0)) == MAP_FAILED) { - DFD_ERROR("Error: Could not mmap : %s or resource is IO\n", strerror(errno)); - close(fd); - return -1; - } - - align = pci_priv->align; - len = rd_len; - ret = 0; - i = 0; - ptr_data = ptr + offset; - - while((i < len) && (ret == 0)){ - if (align == 4) { - data = *((volatile unsigned int *)(ptr_data + i)); - ret = littel_endian_word32_to_byte(buf + i, len - i, data); - i += 4; - } else { - ret = -1; - } - } - - munmap(ptr, sb.st_size); - close(fd); - return ret; - -} - -/** - * dfd_fpga_buf_write -provide FPGA write register interface (address must be four-byte aligned) - * @dst: The data structure of sslot and unit corresponding to the target chip - * @addr: address (four-byte alignment). For the byte alignment required by the specific FPGA address, please refer to the FPGA manual - * @buf: Buffer for reading data - * @wr_len: the length of reading data,please refer to the FPGA manual for the length of the specific FPGA address requirements - * return: return if success,else return -1 - */ - -int dfd_fpga_pci_write(dfd_pci_dev_priv_t *pci_priv, int offset, uint8_t *buf, int wr_len) -{ - int ret, fd; - unsigned int data; - uint8_t *ptr, *ptr_data; - struct stat sb; - int i; - int len, align; - - if ((pci_priv == NULL) || (buf == NULL)) { - DFD_ERROR("pci_prive or write buf is null.\n"); - return -1; - } - - if ((pci_priv->align < 1) || (offset & (pci_priv->align - 1)) || (wr_len & (pci_priv->align - 1))) { - DFD_ERROR("offset[%d] or rd_len[%d] don't align[%d].\n", offset, wr_len, pci_priv->align); - return -1; - } - - if ((fd = open_pci_dev(pci_priv, 0)) < 0) { - return -1; - } - - if ((ret = fstat(fd, &sb)) == -1) { - DFD_ERROR("Error: Could not fstat : %s\n", strerror(errno)); - close(fd); - return -1; - } - - if (offset + wr_len >= sb.st_size) { - DFD_ERROR("Error: offset is out of range\n"); - close(fd); - return -1; - } - - if ((ptr = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, - MAP_SHARED, fd, 0)) == MAP_FAILED) { - DFD_ERROR("Error: Could not mmap : %s or resource is IO\n", strerror(errno)); - close(fd); - return -1; - } - - align = pci_priv->align; - len = wr_len; - ret = 0; - i = 0; - ptr_data = ptr + offset; - - while((i < len) && (ret == 0)){ - if (align == 4) { - data = littel_endian_byte_to_word32(buf + i,len - i); - *((volatile unsigned int *)(ptr_data + i)) = data; - i += 4; - } else { - ret = -1; - } - } - - munmap(ptr, sb.st_size); - close(fd); - return ret; - -} - -/** - * dfd_fpga_read_word -provide FPGA read register interface (address must be four-byte aligned) - * @addr: address (four-byte alignment) - * @val: the returned number of reading - * return: return 0 if success,else return failure - */ -int dfd_fpga_read_word(dfd_pci_dev_priv_t *pci_priv, int addr, int *val) -{ - int ret, i; - uint8_t tmp[DFD_FPGA_PKT_WORD_LEN]; - - if ((pci_priv == NULL) || (val == NULL) || (addr & 0x03)) { - DFD_ERROR("Input para invalid pci_priv %p val %p addr 0x%x.\n", pci_priv, val, addr); - return -1; - } - - ret = dfd_fpga_pci_read(pci_priv, addr, tmp, DFD_FPGA_PKT_WORD_LEN); - if (ret) { - DFD_ERROR("dfd_fpga_pci_read addr 0x%x failed ret %d.\n", addr, ret); - return ret; - } - - *val = littel_endian_byte_to_word32(tmp,DFD_FPGA_PKT_WORD_LEN); - for (i = 0; i < DFD_FPGA_PKT_WORD_LEN; i++) { - DFD_VERBOS("tmp[%d]: 0x%x.\n", i, tmp[i]); - } - DFD_VERBOS("dfd_fpga_read_word addr 0x%x val 0x%x.\n", addr, *val); - - return 0; -} - -/** - * dfd_fpga_write_word -provide FPGA write register interface (address must be four-byte aligned) - * @addr: address (four-byte alignment) - * @val: Data written - * return: return 0 if success,else return failure - */ -int dfd_fpga_write_word(dfd_pci_dev_priv_t *pci_priv, int addr, int val) -{ - int ret, i; - uint8_t tmp[DFD_FPGA_PKT_WORD_LEN]; - - if ((pci_priv == NULL) || (addr & 0x03)) { - DFD_ERROR("Input para invalid pci_priv %p addr 0x%x.\n", pci_priv, addr); - return -1; - } - - littel_endian_word32_to_byte(tmp, DFD_FPGA_PKT_WORD_LEN, val); - for (i = 0; i < DFD_FPGA_PKT_WORD_LEN; i++) { - DFD_VERBOS("tmp[%d]: 0x%x.\n", i, tmp[i]); - } - - ret = dfd_fpga_pci_write(pci_priv, addr, tmp, DFD_FPGA_PKT_WORD_LEN); - if (ret) { - DFD_ERROR("dfd_fpga_pci_write addr 0x%x failed ret %d.\n", addr, ret); - return ret; - } - - DFD_VERBOS("dfd_fpga_write_word addr 0x%x val 0x%x.\n", addr, val); - return 0; -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_pkt.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_pkt.h deleted file mode 100644 index 0d3c3fc9f1..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_pkt.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef __DFD_FPGA_PKT_H__ -#define __DFD_FPGA_PKT_H__ - -typedef enum dfd_fpga_pkt_op_type_e { - DFD_FPGA_PKT_OP_TYPE_READ = 0, /* read */ - DFD_FPGA_PKT_OP_TYPE_WRITE = 1, /* write */ - DFD_FPGA_PKT_OP_TYPE_END, -} dfd_fpga_pkt_op_type_t; - -typedef enum dfd_fpga_pkt_ack_type_e { - DFD_FPGA_PKT_ACK_TYPE_NO_ERROR = 0, /* successful operation */ - DFD_FPGA_PKT_ACK_TYPE_FCS_ERROR = 1, /* operation FCS check error */ - DFD_FPGA_PKT_ACK_TYPE_FAIL_ERROR = 2, /* operation failed */ - DFD_FPGA_PKT_ACK_TYPE_END, -} dfd_fpga_pkt_ack_type_t; - -typedef enum dfd_rv_s { - DFD_RV_OK = 0, - DFD_RV_INIT_ERR = 1, - DFD_RV_SLOT_INVALID = 2, - DFD_RV_MODE_INVALID = 3, - DFD_RV_MODE_NOTSUPPORT = 4, - DFD_RV_TYPE_ERR = 5, - DFD_RV_DEV_NOTSUPPORT = 6, - DFD_RV_DEV_FAIL = 7, - DFD_RV_INDEX_INVALID = 8, - DFD_RV_NO_INTF = 9, - DFD_RV_NO_NODE = 10, - DFD_RV_NODE_FAIL = 11, -} dfd_rv_t; - -typedef struct dfd_pci_dev_priv_s { - int pcibus; - int slot; - int fn; - int bar; - int offset; - int times; - int align; - int fpga_upg_base; -}dfd_pci_dev_priv_t; - -#define DFD_PCI_MAX_NAME_SIZE 256 - -#define DFD_MAX_FPGA_NUM (8) -#define DFD_FPGA_PKT_WORD_LEN (4) - -#define DFD_FPGA_PKT_MAC_LEN (6) -#define DFD_FPGA_PKT_PAYLOAD_WORD_DATA_LEN (4) - -#define DFD_FPGA_PKT_WORD_RW_LEN (1)/* for each access, according to 1 WORD, 4 bytes to access FPGA */ - -#define DFD_FPGA_PKT_ETYPE (0xfff9) - -#define DFD_FPGA_PKT_PAYLOAD_ADDR_LEN (4) -#define DFD_FPGA_PKT_PAYLOAD_LENGTH_LEN (2) - -#define DFD_FPGA_PKT_PAYLOAD_ADDR_OFFSET (0) -#define DFD_FPGA_PKT_PAYLOAD_LENGTH_OFFSET (DFD_FPGA_PKT_PAYLOAD_ADDR_LEN) -#define DFD_FPGA_PKT_PAYLOAD_DATA_OFFSET ((DFD_FPGA_PKT_PAYLOAD_ADDR_LEN) + (DFD_FPGA_PKT_PAYLOAD_LENGTH_LEN)) - -#define DFD_FPGA_PKT_GET_DATA(payload) (((uint8_t*)(payload)) + DFD_FPGA_PKT_PAYLOAD_DATA_OFFSET) -#define DFD_FPGA_PKT_GET_PAYLOAD_LEN(len) ((DFD_FPGA_PKT_PAYLOAD_ADDR_LEN) + (DFD_FPGA_PKT_PAYLOAD_LENGTH_LEN) + (len)) - -#pragma pack (1) -typedef struct dfd_fpga_pkt_payload_s { - uint32_t addr; /* the address of reading and writting */ - uint16_t length; /* the length of reading and writting */ - uint32_t data; /* read and write data (for read operations, you don't need to care about this field) */ -} dfd_fpga_pkt_payload_t; - -typedef struct dfd_fpga_pkt_rd_payload_s { - uint32_t addr; /* the address of reading */ - uint16_t length; /* the length of reading */ -} dfd_fpga_pkt_rd_payload_t; -#pragma pack () - -typedef enum fpga_version_e { - FPGA_VER_00 = 0x00, - FPGA_VER_01, - FPGA_VER_02, - FPGA_VER_03, - FPGA_VER_04, - FPGA_VER_05, - FPGA_VER_06, -} fpga_version_t; - -int dfd_fpga_upg_init(void); -int dfd_fpga_write_word(dfd_pci_dev_priv_t *pci_priv, int addr, int val); -int dfd_fpga_read_word(dfd_pci_dev_priv_t *pci_priv, int addr, int *val); -int dfd_fpga_pci_write(dfd_pci_dev_priv_t *pci_priv, int offset, uint8_t *buf, int wr_len); -int dfd_fpga_pci_read(dfd_pci_dev_priv_t *pci_priv, int offset, uint8_t *buf, int rd_len); -extern int drv_get_my_dev_type(void); - -#endif \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_upg.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_upg.c deleted file mode 100644 index 57c648d915..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/dfd_fpga_upg.c +++ /dev/null @@ -1,1443 +0,0 @@ -/* - * Copyright(C) 2001-2012 Ragile Network. All rights reserved. - */ -/* - * dfd_fpga_upg.c - * - * FPGA upgrade related interface - * v1.0 support 2013-10-25 Initial version. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dfd_fpga_pkt.h" -#include "dfd_fpga_debug.h" - -typedef struct dfd_fpga_upg_node_s { - int sslot; /* Expansion card slot number */ - int extype; /* Expansion card type */ - int fpga_ver; /* Expansion card FPGA version number */ -} dfd_fpga_upg_node_t; - -/* FPGA upgrade related registers */ -#define FPGA_UPG_CONTENT_BASE_REG_A00 (0xa00) -#define FPGA_UPG_CONTENT_BASE_REG_E00 (0xe00) - -#define FPGA_UPG_STATUS_REG (0x180) -#define FPGA_UPG_SPI_CTRL_REG (0x184) -#define FPGA_UPG_WR_FLASH_STATUS_REG (0x188) -#define FPGA_UPG_RD_FLASH_STATUS_REG (0x18C) -#define FPGA_UPG_INSTRUCTION_REG (0x190) - -#define FPGA_UPG_ADDR_REG (0x194) -#define FPGA_UPG_LENGTH_REG (0x198) -#define FPGA_UPG_DEVICE_ID_REG (0x19C) - -#define FPGA_UPG_DROP_REQ_NUM_REG (0x1A8) - -#define FPGA_VER_ADDRESS (0x00000000) - -#define FPGA_VER_MASK (0xFFFF) -#define FPGA_VERSION(ver) ((ver & FPGA_VER_MASK) >> 8) - -/* define FPGA upgrade related instructions */ -#define FPGA_UPG_INSTRUTION_SE (0xD8) -#define FPGA_UPG_INSTRUTION_RDID (0x9F) -#define FPGA_UPG_INSTRUTION_WRSR (0x01) -#define FPGA_UPG_INSTRUTION_RDSR (0x05) -#define FPGA_UPG_INSTRUTION_WREN (0x06) -#define FPGA_UPG_INSTRUTION_WRDI (0x04) -#define FPGA_UPG_INSTRUTION_BE (0xC7) -#define FPGA_UPG_INSTRUTION_PP (0x02) -#define FPGA_UPG_INSTRUTION_FR (0x0B) -#define FPGA_UPG_INSTRUTION_P4E (0x20) - -#define FPGA_UPG_CONTENT_LENGTH (256) - -#define FPGA_UPG_STATUS_MASK (0x1) -#define FPGA_UPG_ACCESS_ENABLE (0x3) -#define FPGA_UPG_STATUS_RESET (0x0) - -#define FPGA_UPG_SPI_STATUS_MASK (0x1) - -#define FPGA_UPG_RETRY_SLEEP_TIME (10) /* 10us */ -#define FPGA_UPG_RETRY_CNT (1000) - -#define FPGA_UPG_PKT_RETRY_CNT (100) - -#define DFD_FPGA_VERSION_REG (0x10D0) - -#define DFD_FPGA_UPGRADE_BUFF_SIZE (256) -#define DFD_FPGA_UPGADE_RETRY_CNT (10) -#define DFD_FPGA_UPGRADE_CMD_BUFF_SIZE (100) -#define DFD_FPGA_UPGRADE_MAX_NODE (16) - -#define DFD_FPGA_UPDATE_BOOT_ADDR (0x1A0000) /* UPDATE area start address */ -#define DFD_FPGA_UPDATE_BOOT_ADDR_FIX (0x2F0000) -#define DFD_FPGA_SPI_SECTOR_SIZE (0x10000) /* One sector is 64k */ -#define DFD_FPGA_UPDATE_FLASH_SIZE (0x4000000) -#define DFD_FPGA_BASE_TEST_ADD (DFD_FPGA_UPDATE_FLASH_SIZE - DFD_FPGA_SPI_SECTOR_SIZE) - -#define DFD_FPGA_CRITICAL_SWITCH_PAGE_ADDR (0xF00) /* CRITICAL SWITCH page address */ -#define DFD_FPGA_CRITICAL_SWITCH_PAGE_OFFSET (0xFC) /* CRITICAL SWITCH in-page offset address */ -#define DFD_FPGA_CRITICAL_SWITCH_WORD (0xAA995566) /* CRITICAL SWITCH value */ - -#define DFD_FPGA_ERASE_P4E_SIZE (0x1000)/* erase p4e,4k at a time*/ - -#define FPGA_UPG_WAIT_SPI_RETRY_CNT (1000) -#define FPGA_UPG_WAIT_SPI_RETRY_SLEEP_TIME (1000 * 10) /* 10ms */ -#define FPGA_RETRY_TIMES (3) - -static dfd_pci_dev_priv_t default_pci_priv = { - .pcibus = 8, - .slot = 0, - .fn = 0, - .bar = 0, - .align = 4, -}; - -static dfd_pci_dev_priv_t *current_pci_priv = NULL; - -static void dfd_utest_printf_reg(uint8_t *buf, int buf_len) -{ - int i; - - for (i = 0; i < buf_len; i++) { - if ((i % 16) == 0) { - printf("\n"); - } - printf("%02x ", buf[i]); - } - - printf("\n"); - return; -} - -static int dfd_fpga_upg_write_word(dfd_pci_dev_priv_t *pci_priv, int addr, int val) -{ - int ret; - int i; - int cnt; - - i = 0; - cnt = FPGA_UPG_PKT_RETRY_CNT; - while(i < cnt) { - ret = dfd_fpga_write_word(pci_priv, addr, val); - if (ret) { - i++; - DFD_VERBOS("dfd_fpga_write_word addr 0x%x val 0x%x i %d failed ret %d.\n", addr, val, i, - ret); - continue; - } else { - DFD_VERBOS("dfd_fpga_write_word addr 0x%x val 0x%x success.\n", addr, val); - return 0; - } - } - - DFD_VERBOS("dfd_fpga_upg_write_word addr 0x%x val 0x%x i %d failed ret %d.\n", addr, val, i, ret); - return -1; -} - -static int dfd_fpga_upg_read_word(dfd_pci_dev_priv_t *pci_priv, int addr, int *val) -{ - int ret; - int i; - int cnt; - - i = 0; - cnt = FPGA_UPG_PKT_RETRY_CNT; - while(i < cnt) { - ret = dfd_fpga_read_word(pci_priv, addr, val); - if (ret) { - i++; - DFD_VERBOS("dfd_fpga_read_word addr 0x%x i %d failed ret %d.\n", addr, i, - ret); - continue; - } else { - DFD_VERBOS("dfd_fpga_read_word addr 0x%x val 0x%x success.\n", addr, *val); - return 0; - } - } - - DFD_VERBOS("dfd_fpga_read_word addr 0x%x i %d failed ret %d.\n", addr, i, ret); - return -1; -} - -static int dfd_fpga_upg_buf_write(dfd_pci_dev_priv_t *pci_priv, int addr, uint8_t *buf, int wr_len) -{ - int ret; - int i; - int cnt; - - i = 0; - cnt = FPGA_UPG_PKT_RETRY_CNT; - while(i < cnt) { - ret = dfd_fpga_pci_write(pci_priv, addr, buf, wr_len); - if (ret) { - i++; - DFD_VERBOS("dfd_fpga_buf_write addr 0x%x wr_len %d i %d failed ret %d.\n", addr, wr_len, i, - ret); - continue; - } else { - DFD_VERBOS("dfd_fpga_buf_write addr 0x%x wr_len %d success.\n", addr, wr_len); - return 0; - } - } - - DFD_VERBOS("dfd_fpga_buf_write addr 0x%x wr_len %d i %d failed ret %d.\n", addr, wr_len, i, ret); - return -1; -} - -static int dfd_fpga_upg_buf_read(dfd_pci_dev_priv_t *pci_priv, int addr, uint8_t *buf, int rd_len) -{ - int ret; - int i; - int cnt; - - i = 0; - cnt = FPGA_UPG_PKT_RETRY_CNT; - while(i < cnt) { - ret = dfd_fpga_pci_read(pci_priv, addr, buf, rd_len); - if (ret) { - i++; - DFD_VERBOS("dfd_fpga_buf_read addr 0x%x rd_len %d i %d failed ret %d.\n", addr, rd_len, i, - ret); - continue; - } else { - DFD_VERBOS("dfd_fpga_buf_read addr 0x%x rd_len %d success.\n", addr, rd_len); - return 0; - } - } - - DFD_VERBOS("dfd_fpga_buf_read addr 0x%x rd_len %d i %d failed ret %d.\n", addr, rd_len, i, ret); - return -1; -} - -/* Configuring boot Access */ -static int dfd_fpga_upg_set_access(dfd_pci_dev_priv_t *pci_priv, int cmd) -{ - int ret; - int val; - int addr; - - addr = pci_priv->fpga_upg_base + FPGA_UPG_INSTRUCTION_REG; - val = cmd; - ret = dfd_fpga_upg_write_word(pci_priv, addr, val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret); - return -1; - } - - addr = pci_priv->fpga_upg_base + FPGA_UPG_SPI_CTRL_REG; - val = FPGA_UPG_ACCESS_ENABLE; - ret = dfd_fpga_upg_write_word(pci_priv, addr, val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret); - return -1; - } - - DFD_VERBOS("Success: cmd %d.\n", cmd); - return 0; -} - -static int dfd_fpga_upg_reset(dfd_pci_dev_priv_t *pci_priv) -{ - int ret; - int val; - int addr; - - addr = pci_priv->fpga_upg_base + FPGA_UPG_SPI_CTRL_REG; - val = FPGA_UPG_STATUS_RESET; - ret = dfd_fpga_upg_write_word(pci_priv, addr, val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret); - return -1; - } - - DFD_VERBOS("Success: reset %d.\n", val); - return 0; -} - -/* Whether the SPI port is idle. 0 indicates idle, and 1 indicates busy */ -static int dfd_fpga_upg_get_status(dfd_pci_dev_priv_t *pci_priv, char *status) -{ - int ret; - int val; - int addr; - - addr = pci_priv->fpga_upg_base + FPGA_UPG_STATUS_REG; - ret = dfd_fpga_upg_read_word(pci_priv, addr, &val); - DFD_VERBOS("dfd_fpga_upg_read_word return.\n"); - if (ret) { - DFD_ERROR("dfd_fpga_upg_read_word addr 0x%x failed ret %d.\n", addr, ret); - return -1; - } - - *status = val & FPGA_UPG_STATUS_MASK; - DFD_VERBOS("Success: val %d status %d.\n", val, *status); - return 0; -} - -/* Wait for the SPI port to become idle */ -static int dfd_fpga_upg_wait_ready(dfd_pci_dev_priv_t *pci_priv) -{ - int timeout; - char status; - int ret; - - timeout = FPGA_UPG_RETRY_CNT; - while (timeout--) { - DFD_VERBOS("timeout %d.\n", timeout); - ret = dfd_fpga_upg_get_status(pci_priv, &status); - if (ret) { - DFD_ERROR("dfd_fpga_upg_get_status failed ret %d.\n", ret); - continue; - } - - DFD_VERBOS("timeout %d status %d.\n", timeout, status); - /* Determine whether to be idle */ - if (!status) { - DFD_VERBOS("FPGA SPI READY.\n"); - return 0; - } - usleep(FPGA_UPG_RETRY_SLEEP_TIME); - } - - return -2; -} - -/* Configure the FPGA upgrade write function */ -static int dfd_fpga_upg_set_wr_enable(dfd_pci_dev_priv_t *pci_priv) -{ - int ret; - int cmd; - - cmd = FPGA_UPG_INSTRUTION_WREN; - ret = dfd_fpga_upg_set_access(pci_priv, cmd); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_access cmd %d failed ret %d.\n", cmd, ret); - return -1; - } - - DFD_VERBOS("Success.\n"); - return 0; -} - -/* get SPI's STATUS register */ -static int dfd_fpga_upg_get_spi_status(dfd_pci_dev_priv_t *pci_priv, char *status) -{ - int ret; - int val; - int addr; - int cmd; - - cmd = FPGA_UPG_INSTRUTION_RDSR; - ret = dfd_fpga_upg_set_access(pci_priv, cmd); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_access cmd %d failed ret %d.\n", cmd, ret); - return -1; - } - - addr = pci_priv->fpga_upg_base + FPGA_UPG_RD_FLASH_STATUS_REG; - ret = dfd_fpga_upg_read_word(pci_priv, addr, &val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_read_word addr 0x%x failed ret %d.\n", addr, ret); - return -1; - } - - ret = dfd_fpga_upg_reset(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_reset failed ret %d.\n", ret); - return -1; - } - - *status = val & FPGA_UPG_SPI_STATUS_MASK; - DFD_VERBOS("Success: val %d spi_status %d.\n", val, *status); - return 0; -} - -/* waiting for SPI chip opreation to complete */ -static int dfd_fpga_wait_spi_ready(dfd_pci_dev_priv_t *pci_priv) -{ - int timeout; - char status; - int ret; - - timeout = FPGA_UPG_WAIT_SPI_RETRY_CNT; - while (timeout--) { - DFD_VERBOS("timeout %d.\n", timeout); - ret = dfd_fpga_upg_get_spi_status(pci_priv, &status); - if (ret) { - DFD_ERROR("dfd_fpga_upg_get_spi_status failed ret %d.\n", ret); - continue; - } - DFD_VERBOS("timeout %d status %d.\n", timeout, status); - /* assert whether it is free */ - if (!status) { - DFD_VERBOS("SPI CHIP READY.\n"); - return 0; - } - usleep(FPGA_UPG_RETRY_SLEEP_TIME); - } - - return -2; -} - -/* Erase the entire chip */ -static int dfd_fpga_upg_set_erase_all(dfd_pci_dev_priv_t *pci_priv) -{ - int ret; - int cmd; - - /* waiting for FPGA's SPI port to become free */ - ret = dfd_fpga_upg_wait_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready failed ret %d.\n", ret); - return -1; - } - - /* configure write enable */ - ret = dfd_fpga_upg_set_wr_enable(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_wr_enable failed ret %d.\n", ret); - return -1; - } - - cmd = FPGA_UPG_INSTRUTION_BE; - ret = dfd_fpga_upg_set_access(pci_priv, cmd); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_access cmd %d failed ret %d.\n", cmd, ret); - return -1; - } - - /* Hardware requirements, delay 1s */ - sleep(1); - - /* Waiting for the SPI chip operation to complete */ - ret = dfd_fpga_wait_spi_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready sslot %d unit %d failed ret %d.\n", ret); - return -1; - } - - ret = dfd_fpga_upg_reset(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_reset failed ret %d.\n", ret); - return -1; - } - - DFD_VERBOS("Success.\n"); - return 0; -} - -/* Erase sector (256 pages, 64k in total) */ -int dfd_fpga_upg_set_erase_sector(dfd_pci_dev_priv_t *pci_priv, int spi_addr) -{ - int ret; - int cmd, val, addr; - - DFD_VERBOS("Enter spi_addr 0x%x.\n", spi_addr); - - /* waiting for FPGA's SPI port to become free*/ - ret = dfd_fpga_upg_wait_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready failed ret %d.\n", ret); - return -1; - } - - /* Start write enable */ - ret = dfd_fpga_upg_set_wr_enable(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_wr_enable failed ret %d.\n", ret); - return -1; - } - - /* Write erase address */ - val = spi_addr; - addr = pci_priv->fpga_upg_base + FPGA_UPG_ADDR_REG; - ret = dfd_fpga_upg_write_word(pci_priv, addr, val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret); - return -1; - } - - /* Start sector erase? */ - cmd = FPGA_UPG_INSTRUTION_SE; - ret = dfd_fpga_upg_set_access(pci_priv, cmd); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_access cmd %d failed ret %d.\n", cmd, ret); - return -1; - } - - /* hardware requirment ,delay 500ms */ - usleep(500 * 1000); - - /* waiting for SPI chip operation to complete */ - ret = dfd_fpga_wait_spi_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready failed ret %d.\n", ret); - return -1; - } - - ret = dfd_fpga_upg_reset(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_reset failed ret %d.\n", ret); - return -1; - } - - DFD_VERBOS("Success.\n"); - - return 0; -} - -/* eara 4k area */ -int dfd_fpga_upg_set_erase_p4e(dfd_pci_dev_priv_t *pci_priv, int spi_addr) -{ - int ret; - int cmd, val, addr; - - DFD_VERBOS("Enter spi_addr 0x%x.\n", spi_addr); - - /* waiting for FPGA's SPI port to become free */ - ret = dfd_fpga_upg_wait_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready failed ret %d.\n", ret); - return -1; - } - - /* start write enable */ - ret = dfd_fpga_upg_set_wr_enable(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_wr_enable failed ret %d.\n", ret); - return -1; - } - - /* write erase address */ - val = spi_addr; - addr = pci_priv->fpga_upg_base + FPGA_UPG_ADDR_REG; - ret = dfd_fpga_upg_write_word(pci_priv, addr, val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret); - return -1; - } - - /* start 4k erase */ - cmd = FPGA_UPG_INSTRUTION_P4E; - ret = dfd_fpga_upg_set_access(pci_priv, cmd); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_access cmd %d failed ret %d.\n", cmd, ret); - return -1; - } - - /* hardware requirment,delay 200ms */ - usleep(200 * 1000); - - /* waiting for SPI chip operation to complete */ - ret = dfd_fpga_wait_spi_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready failed ret %d.\n", ret); - return -1; - } - - ret = dfd_fpga_upg_reset(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_reset failed ret %d.\n", ret); - return -1; - } - - DFD_VERBOS("Success.\n"); - - return 0; -} - -static int dfd_fpga_upg_program(dfd_pci_dev_priv_t *pci_priv, int spi_addr, char *buf, int len) -{ - int ret; - int addr; - int val; - int cmd; - int step; - int wr_len; - - /* Write data to upgrade content register */ - step = 1; - #if 0 - /* FPGA temporarily only supports 4 bytes of read and write */ - for (i = 0; i < len; i += 4) { - addr = pci_priv->fpga_upg_base + i; - wr_len = ((i + 4) <= len) ? (4) : (len - i); - DFD_VERBOS("dfd_fpga_buf_write sslot %d unit %d i %d addr 0x%x wr_len %d.\n", - dst->sslot, dst->unit, i, addr, wr_len); - ret = dfd_fpga_upg_buf_write(dst, addr, (uint8_t*)&buf[i], wr_len); - if (ret) { - DFD_ERROR("dfd_fpga_upg_buf_write addr 0x%x wr_len %d failed ret %d.\n", addr, len, ret); - return -1; - } - } - #else - addr = pci_priv->fpga_upg_base; - wr_len = len; - DFD_VERBOS("dfd_fpga_buf_write addr 0x%x wr_len %d.\n", addr, wr_len); - ret = dfd_fpga_upg_buf_write(pci_priv, addr, (uint8_t*)buf, wr_len); - if (ret) { - DFD_ERROR("dfd_fpga_upg_buf_write addr 0x%x wr_len %d failed ret %d.\n", addr, len, ret); - return -1; - } - #endif - - /* Write length register */ - step++; - val = FPGA_UPG_CONTENT_LENGTH;/* Fpga is always written in 256 length */ - addr = pci_priv->fpga_upg_base + FPGA_UPG_LENGTH_REG; - ret = dfd_fpga_upg_write_word(pci_priv, addr, val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret); - return -step; - } - - /* write address register */ - step++; - val = spi_addr; - addr = pci_priv->fpga_upg_base + FPGA_UPG_ADDR_REG; - ret = dfd_fpga_upg_write_word(pci_priv, addr, val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret); - return -step; - } - - /* Start writing upgrade data to SPI */ - step++; - cmd = FPGA_UPG_INSTRUTION_PP; - ret = dfd_fpga_upg_set_access(pci_priv, cmd); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_access cmd %d failed ret %d.\n", cmd, ret); - return -step; - } - - /* Wait for the SPI port of FPGA to recover from idle */ - step++; - ret = dfd_fpga_upg_wait_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready failed ret %d.\n", ret); - return -step; - } - - step++; - ret = dfd_fpga_upg_reset(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_reset failed ret %d.\n", ret); - return -step; - } - - return 0; -} - -/** - * dfd_fpga_upg_write -write operation interface provided to upgrade module - * @dst: the data structure of sslot and unit corresponding to the target chip to be upgraded - * @addr: write address (must ensure 256-byte alignment) - * @buf: write address buffer - * @len: Write length (when upgrading, 256 bytes of data must be written every time, only the last set of data can be less than 256) - * return: return 0 if success,else return failure - * - */ -int dfd_fpga_upg_write(dfd_pci_dev_priv_t *pci_priv, int addr, char *buf, int len) -{ - int ret; - int step; - - /* address must be 256-byte alignment */ - step = 1; - if ((pci_priv == NULL) || (buf == NULL) || (addr & 0xff) || (len > 256)) { - DFD_ERROR("Input para invalid pci_priv %p buf %p addr 0x%x len %d.\n", pci_priv, buf, addr, len); - return -step; - } - - DFD_VERBOS("Enter: addr 0x%x len %d.\n", addr, len); - - /* waiting for FPGA's SPI port to become free */ - step++; - ret = dfd_fpga_upg_wait_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready failed ret %d.\n", ret); - return -step; - } - - /* configure write enable */ - step++; - ret = dfd_fpga_upg_set_wr_enable(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_wr_enable failed ret %d.\n", ret); - return -step; - } - - /* write upgrade data */ - step++; - ret = dfd_fpga_upg_program(pci_priv, addr, buf, len); - if (ret) { - DFD_ERROR("dfd_fpga_upg_program addr 0x%x len %d failed ret %d.\n", addr, len, ret); - return -step; - } - - DFD_VERBOS("Success: addr 0x%x len %d.\n", addr, len); - return 0; -} - -static int dfd_fpga_upg_fast_read(dfd_pci_dev_priv_t *pci_priv, int spi_addr, char *buf, int len) -{ - int ret; - uint32_t val; - int addr; - int cmd; - int step; - - step = 0; - - /* clear register value */ - step++; - addr = pci_priv->fpga_upg_base; - ret = dfd_fpga_upg_buf_write(pci_priv, addr, buf, len); - if (ret) { - DFD_ERROR("dfd_fpga_upg_buf_write addr 0x%x len %d failed ret %d.\n", addr, len, ret); - return -step; - } - /* write length register */ - step++; - val = FPGA_UPG_CONTENT_LENGTH; - addr = pci_priv->fpga_upg_base + FPGA_UPG_LENGTH_REG; - ret = dfd_fpga_upg_write_word(pci_priv, addr, val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret); - return -step; - } - - /* write address register */ - step++; - val = spi_addr; - addr = pci_priv->fpga_upg_base + FPGA_UPG_ADDR_REG; - ret = dfd_fpga_upg_write_word(pci_priv, addr, val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret); - return -step; - } - - /* start reading SPI data */ - step++; - cmd = FPGA_UPG_INSTRUTION_FR; - ret = dfd_fpga_upg_set_access(pci_priv, cmd); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_access cmd %d failed ret %d.\n", cmd, ret); - return -step; - } - - /* waiting for FPGA's SPI port to become free */ - step++; - ret = dfd_fpga_upg_wait_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready failed ret %d.\n", ret); - return -step; - } - - /* Read upgrade content register to buffer */ - step++; - - /* FPGA temporarily only supports 4 bytes of read and write */ - #if 1 - addr = pci_priv->fpga_upg_base; - ret = dfd_fpga_upg_buf_read(pci_priv, addr, (uint8_t*)buf, len); - if (ret) { - DFD_ERROR("dfd_fpga_upg_buf_read addr 0x%x len %d failed ret %d.\n", addr, len, ret); - return -step; - } - - step++; - ret = dfd_fpga_upg_reset(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_reset failed ret %d.\n", ret); - return -step; - } - - #else - for (i = 0; i < len; i += 4) { - addr = pci_priv->fpga_upg_base + i; - rd_len = ((i + 4) <= len) ? (4) : (len - i); - DFD_VERBOS("dfd_fpga_upg_buf_read sslot %d unit %d i %d addr 0x%x rd_len %d.\n", - dst->sslot, dst->unit, i, addr, rd_len); - ret = dfd_fpga_upg_buf_read(dst, addr, (uint8_t*)(&buf[i]), rd_len); - if (ret) { - DFD_ERROR("dfd_fpga_upg_buf_read addr 0x%x rd_len %d failed ret %d.\n", addr, rd_len, ret); - return -step; - } - - for (j = 0; j < rd_len; j++) { - DFD_VERBOS("buf[%d]: 0x%x.\n", i, buf[i]); - } - } - #endif - - return 0; -} - -/** - * dfd_fpga_upg_read -read operation interface provided to upgrade module - * @dst: the data structure of sslot and unit corresponding to the target chip - * @addr: read address (must ensure 256-byte alignment) - * @buf: buffer for reading data - * @len: read length (the data read each time must be 256 bytes, only the last time can be less than 256 bytes) - * return: return 0 if success,else return failure - * - */ -int dfd_fpga_upg_read(dfd_pci_dev_priv_t *pci_priv, int addr, char *buf, int len) -{ - int ret; - int step; - - /* address must be 256-byte alignment */ - step = 1; - if ((pci_priv == NULL) || (buf == NULL) || (addr & 0xff) || (len > 256)) { - DFD_ERROR("Input para invalid pci_priv %p buf %p addr 0x%x len %d.\n", pci_priv, buf, addr, len); - return -step; - } - - DFD_VERBOS("Enter: addr 0x%x len %d.\n", addr, len); - - /* waiting for FPGA's SPI port to become free */ - step++; - ret = dfd_fpga_upg_wait_ready(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_wait_ready failed ret %d.\n", ret); - return -step; - } - - /* configure write enable */ - step++; - ret = dfd_fpga_upg_set_wr_enable(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_wr_enable failed ret %d.\n", ret); - return -step; - } - - /* read upgrade data */ - step++; - ret = dfd_fpga_upg_fast_read(pci_priv, addr, buf, len); - if (ret) { - DFD_ERROR("dfd_fpga_upg_fast_read addr 0x%x len %d failed ret %d.\n", addr, len, ret); - return -step; - } - - DFD_VERBOS("Success: addr 0x%x len %d.\n", addr, len); - return 0; - -} - -/** - * dfd_fpga_upg_hw_init -upgrade initialization interface provided to the upgrade module (call before starting the upgrade) - * @dst: the data structure of sslot and unit corresponding to the target chip to be upgraded - * return: return 0 if success,else return failure - * Before the interface returns, it will actively delay 1s (required by FPGA) - */ -int dfd_fpga_upg_hw_init(dfd_pci_dev_priv_t *pci_priv) -{ - int ret; - - ret = dfd_fpga_upg_set_erase_all(pci_priv); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_wr_enable failed ret %d.\n", ret); - return -2; - } - - DFD_VERBOS("Success.\n"); - return 0; -} - -static int dfd_fpga_upgrade_get_fpga_version(dfd_pci_dev_priv_t *pci_priv, int *ver) -{ - int addr; - int ret; - int val; - - addr = DFD_FPGA_VERSION_REG; - ret = dfd_fpga_upg_read_word(pci_priv, addr, &val); - if (ret) { - DFD_ERROR("dfd_fpga_upg_read_word addr 0x%x failed ret %d.\n", addr, ret); - return -1; - } - - *ver = val; - DFD_VERBOS("ver 0x%x.\n", *ver); - return 0; -} - -unsigned long dfd_fpga_upg_get_file_size(const char *path) -{ - unsigned long filesize; - struct stat statbuff; - - if(stat(path, &statbuff) < 0){ - filesize = -1; - } else{ - filesize = statbuff.st_size; - } - - DFD_VERBOS("file %s size is %lu.\n", path, filesize); - return filesize; -} - -static int dfd_fpga_address_init(void) -{ - int fw_version; - int ret; - - ret = dfd_fpga_upg_read_word(current_pci_priv, FPGA_VER_ADDRESS, &fw_version); - switch (FPGA_VERSION(fw_version)) { - case FPGA_VER_00: - case FPGA_VER_02: - case FPGA_VER_03: - case FPGA_VER_06: - current_pci_priv->fpga_upg_base = FPGA_UPG_CONTENT_BASE_REG_A00; - break; - case FPGA_VER_05: - current_pci_priv->fpga_upg_base = FPGA_UPG_CONTENT_BASE_REG_E00; - break; - default: - current_pci_priv->fpga_upg_base = FPGA_UPG_CONTENT_BASE_REG_A00; - break; - } - return ret; -} - -static int dfd_fpga_device_init(void) -{ - current_pci_priv = &default_pci_priv; - if (drv_get_my_dev_type() == 0x4075){ - current_pci_priv->pcibus = 1; /* ATS48's pcie channel is 1 */ - } - - return dfd_fpga_address_init(); -} - -/** - * dfd_fpga_pkt_init -DFD FPGA driver library initialization interface (if you need to use DFD FPGA driver, you must initialize first) - * return: return 0 if success,else return failure - */ - -int dfd_fpga_upg_init(void) -{ - int ret; - static int flag; - - if (flag) { - DFD_VERBOS("Already init.\n"); - return 0; - } - - /* debug initialization */ - dfd_fpga_debug_init(); - - ret = dfd_fpga_device_init(); - if (ret) { - DFD_ERROR("dfd_fpga_upg_init failed ret %d.\n", ret); - return ret; - } - - flag = 1; - return 0; -} - -int dfd_fpga_erase64_sector(dfd_pci_dev_priv_t *pci_priv, int offset) -{ - int ret; - ret = -1; - - if ((offset % DFD_FPGA_SPI_SECTOR_SIZE) == 0) { - DFD_VERBOS("erase 64k area, offset 0x%x.\n", offset); - ret = dfd_fpga_upg_set_erase_sector(pci_priv, offset); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_erase_sector offset 0x%x failed ret %d.\n", offset, ret); - return ret; - } - } - DFD_ERROR("Input para invalid, offset 0x%x.\n", offset); - return ret; -} - -int dfd_fpga_upgrade_test(void) -{ - int ret, i, j, offset, num, len, res, retry; - char wbuf[DFD_FPGA_SPI_SECTOR_SIZE]; - char rbuf[DFD_FPGA_UPGRADE_BUFF_SIZE]; - - offset = DFD_FPGA_BASE_TEST_ADD; - len = DFD_FPGA_UPGRADE_BUFF_SIZE; - dfd_pci_dev_priv_t *pci_priv; - dfd_fpga_upg_init(); - - if (current_pci_priv == NULL) { - printf("fpga test input para invalid pci_priv %p.\n", current_pci_priv); - return -DFD_RV_INIT_ERR; - } - pci_priv = current_pci_priv; - - mem_clear(wbuf, DFD_FPGA_SPI_SECTOR_SIZE); - /* get random data */ - for (j = 0; j < DFD_FPGA_SPI_SECTOR_SIZE; j++) { - num = rand() % 256; - wbuf[j] = num & 0xff; - } - ret = dfd_fpga_erase64_sector(pci_priv, offset); - if (ret) { - goto exit; - } - - for (i = 0; i < DFD_FPGA_UPGRADE_BUFF_SIZE; i++) { - mem_clear(rbuf, DFD_FPGA_UPGRADE_BUFF_SIZE); - /* write data first */ - ret = dfd_fpga_upg_write(pci_priv, offset, &wbuf[i * DFD_FPGA_UPGRADE_BUFF_SIZE], len); - if (ret) { - DFD_ERROR("fpga upg write offset 0x%x len %d failed ret %d.\n", offset, len, ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } else { - DFD_VERBOS("page %d upg write offset 0x%x len %d success.\n", i, offset, len); - } - - /* go back to read the data*/ - for (retry = 0; retry < FPGA_RETRY_TIMES; retry++) { /*retry 3 times*/ - ret = dfd_fpga_upg_read(pci_priv, offset, rbuf, len); - res = memcmp(rbuf, &wbuf[i * DFD_FPGA_UPGRADE_BUFF_SIZE], len); - if (ret || res) { - usleep(1000); - continue; - } - break; - } - if (ret) { - DFD_ERROR("fpga upg read offset 0x%x len %d failed ret %d.\n", offset, len, ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } else { - DFD_VERBOS("page %d upg read offset 0x%x len %d success.\n", i, offset, len); - } - - if (res) { - DFD_ERROR("rbuf wbuf not equal, len %d, check failed.\n", len); - DFD_ERROR("wbuf: \n"); - dfd_utest_printf_reg((uint8_t*)wbuf, len); - DFD_ERROR("rbuf: \n"); - dfd_utest_printf_reg((uint8_t*)rbuf, len); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } - - offset += len; - } - - offset = DFD_FPGA_BASE_TEST_ADD; - ret = dfd_fpga_erase64_sector(pci_priv, offset); - if (ret) { - goto exit; - } -exit: - return ret; -} - -static int dfd_fpga_upgrade_do_upgrade_onetime(dfd_pci_dev_priv_t *pci_priv, int fd, unsigned long filesize) -{ - int ret, res; - int i, len, read_len, retry; - char wbuf[DFD_FPGA_UPGRADE_BUFF_SIZE]; - char rbuf[DFD_FPGA_UPGRADE_BUFF_SIZE]; - int offset; - - if (current_pci_priv == NULL) { - DFD_ERROR("Input para invalid pci_priv %p.\n", pci_priv); - return -DFD_RV_INDEX_INVALID; - } - -#if 0 - /* handle before upgrading */ - ret = dfd_fpga_upg_do_pre(dst, filesize); - if (ret) { - DFD_ERROR("fpga hw init failed ret %d.\n", ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } -#endif - - i = 0; - offset = DFD_FPGA_UPDATE_BOOT_ADDR; - ret = lseek(fd, 0, SEEK_SET); - if (ret == -1) { - DFD_ERROR("seek file failed ret %d.\n", ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } - while(1) { - len = DFD_FPGA_UPGRADE_BUFF_SIZE; -#if 0 - if ((offset % DFD_FPGA_ERASE_P4E_SIZE) == 0) { - DFD_VERBOS("erase 4k area, offset 0x%x.\n", offset); - ret = dfd_fpga_upg_set_erase_p4e(dst, offset); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_erase_p4e offset 0x%x failed ret %d.\n", offset, ret); - goto exit; - } - } -#else - if ((offset % DFD_FPGA_SPI_SECTOR_SIZE) == 0) { - DFD_VERBOS("erase 64k area, offset 0x%x.\n", offset); - ret = dfd_fpga_upg_set_erase_sector(pci_priv, offset); - if (ret) { - DFD_ERROR("dfd_fpga_upg_set_erase_sector offset 0x%x failed ret %d.\n", offset, ret); - goto exit; - } - } -#endif - - mem_clear(wbuf, DFD_FPGA_UPGRADE_BUFF_SIZE); - read_len = read(fd, wbuf, len); - i++; - if ((read_len > 0) && (read_len <= len)) { - /* write data first */ - ret = dfd_fpga_upg_write(pci_priv, offset, wbuf, read_len); - if (ret) { - DFD_ERROR("fpga upg write offset 0x%x len %d failed ret %d.\n", offset, read_len, ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } else { - DFD_VERBOS("page %d upg write offset 0x%x len %d success.\n", i, offset, read_len); - } - - /* go back to read data */ - for (retry = 0; retry < FPGA_RETRY_TIMES; retry++) { /*retry 3 times*/ - mem_clear(rbuf, DFD_FPGA_UPGRADE_BUFF_SIZE); - ret = dfd_fpga_upg_read(pci_priv, offset, rbuf, read_len); - res = memcmp(rbuf, wbuf, read_len); - if (ret || res) { - usleep(1000); - continue; - } - break; - } - if (ret) { - DFD_ERROR("fpga upg read offset 0x%x len %d failed ret %d.\n", offset, read_len, ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } else { - DFD_VERBOS("page %d upg read offset 0x%x len %d success.\n", i, offset, read_len); - } - - if (res) { - DFD_ERROR("rbuf wbuf not equal, read_len %d, check failed.\n", read_len); - DFD_ERROR("wbuf: \n"); - dfd_utest_printf_reg((uint8_t*)wbuf, read_len); - DFD_ERROR("rbuf: \n"); - dfd_utest_printf_reg((uint8_t*)rbuf, read_len); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } - - DFD_VERBOS("page %d upg check offset 0x%x len %d success.\n", i, offset, read_len); - offset += read_len; - if (read_len != len) { - DFD_VERBOS("page %d read_len %d len %d, last page exit.\n", i, read_len, len); - break; - } - } else if (read_len == 0) { - DFD_VERBOS("read_len %d exit.\n", read_len); - break; - } else { - DFD_ERROR("len %d read_len %d, read failed, errno(%s).\n", len, read_len, strerror(errno)); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } - } - -#if 0 - ret = dfd_fpga_upg_do_post(dst); - if (ret) { - DFD_ERROR("dfd_fpga_upg_do_post dst->sslot %d dst->unit %d failed ret %d.\n", dst->sslot, - dst->unit, ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } -#endif - - ret = 0; - DFD_VERBOS("Update success.\n"); -exit: - return ret; -} - -/* external FPGA upgrade interface */ -int dfd_fpga_upgrade_do_upgrade(char* upg_file) -{ - int ret; - int i; - int cnt; - unsigned long filesize; - int fd; - - DFD_VERBOS("Enter.\n"); - - if (upg_file == NULL) { - DFD_ERROR("Input para invalid upg_file %p.\n", upg_file); - return -DFD_RV_INDEX_INVALID; - } - - dfd_fpga_upg_init(); - - filesize = dfd_fpga_upg_get_file_size(upg_file); - if (filesize <= 0) { - DFD_ERROR("invalid filesize %lu.\n", filesize); - return -DFD_RV_DEV_FAIL; - } - - fd = open(upg_file, O_RDONLY); - if (fd < 0) { - DFD_ERROR("open file[%s] fail.\n", upg_file); - return -DFD_RV_DEV_FAIL; - } - - i = 0; - cnt = DFD_FPGA_UPGADE_RETRY_CNT; - while(i < cnt) { - ret = dfd_fpga_upgrade_do_upgrade_onetime(current_pci_priv, fd, filesize); - if (ret) { - i++; - DFD_ERROR("dfd_fpga_upgrade_do_upgrade_onetime upg_file %s failed ret %d.\n", upg_file, ret); - continue; - } else { - DFD_ERROR("dfd_fpga_upgrade_do_upgrade_onetime upg_file %s success.\n", upg_file); - close(fd); - return 0; - } - } - - DFD_ERROR("upg_file %s failed ret %d.\n", upg_file, ret); - close(fd); - return ret; -} - -static int dfd_fpga_upgrade_do_upgrade_onetime_all(dfd_pci_dev_priv_t *pci_priv, char* upg_file) -{ - int ret; - int i, len, fd, read_len; - char wbuf[DFD_FPGA_UPGRADE_BUFF_SIZE]; - char rbuf[DFD_FPGA_UPGRADE_BUFF_SIZE]; - int offset; - - DFD_VERBOS("Update upg_file: %s.\n", upg_file); - - if ((current_pci_priv == NULL) || (upg_file == NULL)) { - DFD_ERROR("Input para invalid pci_priv %p upg_file %p.\n", pci_priv, upg_file); - return -DFD_RV_INDEX_INVALID; - } - - fd = open(upg_file, O_RDONLY); - if (fd < 0) { - DFD_ERROR("open file[%s] fail.\n", upg_file); - return -DFD_RV_DEV_FAIL; - } - - /* Before upgrading, first initialize the configuration and erase the entire SPI chip */ - ret = dfd_fpga_upg_hw_init(pci_priv); - if (ret) { - DFD_ERROR("fpga hw init failed ret %d.\n", ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } - - i = 0; - offset = 0; - while(1) { - len = DFD_FPGA_UPGRADE_BUFF_SIZE; - mem_clear(wbuf, DFD_FPGA_UPGRADE_BUFF_SIZE); - read_len = read(fd, wbuf, len); - i++; - if ((read_len > 0) && (read_len <= len)) { - /* write data first */ - ret = dfd_fpga_upg_write(pci_priv, offset, wbuf, read_len); - if (ret) { - DFD_ERROR("fpga upg write offset 0x%x len %d failed ret %d.\n", offset, read_len, ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } else { - DFD_VERBOS("page %d upg write offset 0x%x len %d success.\n", i, offset, read_len); - } - - /* go back to read data */ - mem_clear(rbuf, DFD_FPGA_UPGRADE_BUFF_SIZE); - ret = dfd_fpga_upg_read(pci_priv, offset, rbuf, read_len); - if (ret) { - DFD_ERROR("fpga upg read offset 0x%x len %d failed ret %d.\n", offset, read_len, ret); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } else { - DFD_VERBOS("page %d upg read offset 0x%x len %d success.\n", i, offset, read_len); - } - - if (memcmp(rbuf, wbuf, read_len)) { - DFD_ERROR("rbuf wbuf not equal, read_len %d, check failed.\n", read_len); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } - - DFD_VERBOS("page %d upg check offset 0x%x len %d success.\n", i, offset, read_len); - offset += read_len; - if (read_len != len) { - DFD_VERBOS("page %d read_len %d len %d, last page exit.\n", i, read_len, len); - break; - } - } else if (read_len == 0) { - DFD_VERBOS("read_len %d exit.\n", read_len); - break; - } else { - DFD_ERROR("len %d read_len %d, read failed.\n", len, read_len); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } - } - - ret = 0; - DFD_VERBOS("Update upg_file: %s success.\n", upg_file); -exit: - close(fd); - return ret; -} - -int dfd_fpga_upgrade_do_upgrade_all(char* upg_file) -{ - int ret; - int i; - int cnt; - - DFD_VERBOS("Enter.\n"); - - if (upg_file == NULL) { - DFD_ERROR("Input para invalid upg_file %p.\n", upg_file); - return -DFD_RV_INDEX_INVALID; - } - - dfd_fpga_upg_init(); - - i = 0; - cnt = DFD_FPGA_UPGADE_RETRY_CNT; - while(i < cnt) { - ret = dfd_fpga_upgrade_do_upgrade_onetime_all(current_pci_priv, upg_file); - if (ret) { - i++; - DFD_ERROR("dfd_fpga_upgrade_do_upgrade_onetime upg_file %s failed ret %d.\n", upg_file, ret); - continue; - } else { - DFD_ERROR("dfd_fpga_upgrade_do_upgrade_onetime upg_file %s success.\n", upg_file); - return 0; - } - } - - DFD_ERROR("upg_file %s failed ret %d.\n", upg_file, ret); - return ret; -} - -/* External fpga dump interface */ -int dfd_fpga_upgrade_dump_flash(int argc, char* argv[]) -{ - int offset, addr, len, dlen; - int size, cnt, i; - char *stopstring; - int ret, fd; - char filename[DFD_FPGA_UPGRADE_BUFF_SIZE]; - char tmp[DFD_FPGA_UPGRADE_BUFF_SIZE]; - char is_print; - char buf[DFD_FPGA_UPGRADE_BUFF_SIZE]; - dfd_pci_dev_priv_t *pci_priv; - - ret = DFD_RV_OK; - if (argc != 6) { - printf("fpga dump flash Input invalid.\n"); - return -DFD_RV_INDEX_INVALID; - } - - dfd_fpga_upg_init(); - - if (current_pci_priv == NULL) { - printf("fpga dump flash Input para invalid pci_priv %p.\n", current_pci_priv); - return -DFD_RV_INIT_ERR; - } - - offset = strtol(argv[3], &stopstring, 16); - size = strtol(argv[4], &stopstring, 16); - - if (strcmp(argv[5], "print") != 0) { - is_print = 0; - mem_clear(filename, DFD_FPGA_UPGRADE_BUFF_SIZE); - strncpy(filename, argv[5], (DFD_FPGA_UPGRADE_BUFF_SIZE - 1)); - fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXG|S_IRWXU|S_IRWXO); - if (fd < 0) { - snprintf(tmp, sizeof(tmp), "%s", filename); - printf("open file %s fail(err:%d)!\r\n", tmp, errno); - ret = -DFD_RV_DEV_FAIL; - goto exit; - } - } else { - is_print = 1; - } - - pci_priv = current_pci_priv; - cnt = size / DFD_FPGA_UPGRADE_BUFF_SIZE; - if (size % DFD_FPGA_UPGRADE_BUFF_SIZE) { - cnt++; - } - len = DFD_FPGA_UPGRADE_BUFF_SIZE; - printf("cnt %d.\n", cnt); - for (i = 0; i < cnt; i++) { - mem_clear(buf, len); - addr = offset + i * DFD_FPGA_UPGRADE_BUFF_SIZE; - if (i == (cnt - 1)) { - dlen = size - len * i; - if (dlen > len) { - printf("dlen %d len %d error.\n", dlen, len); - } - } else { - dlen = len; - } - ret = dfd_fpga_upg_read(pci_priv, addr, buf, dlen); - if (ret < 0) { - printf("addr 0x%x failed ret %d\n", addr, ret); - goto exit_close; - } - if (is_print) { - dfd_utest_printf_reg((uint8_t*)buf, dlen); - } else { - ret = write(fd, buf, dlen); - if (ret < 0) { - printf("write failed (errno: %d).\n", errno); - ret = -DFD_RV_DEV_FAIL; - goto exit_close; - } - } - } - -exit_close: - if (!is_print) { - close(fd); - } -exit: - return ret; -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/firmware_app_ispvme.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/firmware_app_ispvme.c deleted file mode 100644 index 13446ddebb..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/firmware_app_ispvme.c +++ /dev/null @@ -1,906 +0,0 @@ -/** - * Copyright(C) 2013 Ragile Network. All rights reserved. - */ -/* - * firmware_app.c - - * firmware upgrade - * v1.0 support 2013-10-25 Initial version. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if 0 -#include -#include -#endif -#include -static firmware_card_info_t g_card_info[] = { - { - .dev_type = RA_B6010_48GT4X, - .slot_num = 1, - .card_name = "RA_B6010_48GT4X", - .gpio_info = { - /* slot 0 */ - { - .tdi = 507, - .tck = 505, - .tms = 506, - .tdo = 508, - .jtag_en = 504, - .select = -1, - .jtag_5 = GPIO(-1, 0,1) - .jtag_4 = GPIO(-1, 0,1) - .jtag_3 = GPIO(-1, 1,1) - .jtag_2 = GPIO(-1, 0,1) - .jtag_1 = GPIO(-1, 1,1) - }, - }, - - }, - - { - .dev_type = RA_B6010_48GT4X_R, - .slot_num = 1, - .card_name = "RA_B6010_48GT4X_R", - .gpio_info = { - /* slot 0 */ - { - .tdi = 507, - .tck = 505, - .tms = 506, - .tdo = 508, - .jtag_en = 504, - .select = -1, - .jtag_5 = GPIO(-1, 0,1) - .jtag_4 = GPIO(-1, 0,1) - .jtag_3 = GPIO(-1, 1,1) - .jtag_2 = GPIO(-1, 0,1) - .jtag_1 = GPIO(-1, 1,1) - }, - }, - }, -}; - -static int is_debug_on; -static int dfd_my_type = 0; - -#if 0 -#if defined(CONFIG_FRM_PRODUCT_NAME) -#define CONFIG_RAGILE_PRODUCT_NAME CONFIG_FRM_PRODUCT_NAME -#else -#define CONFIG_RAGILE_PRODUCT_NAME "card" -#endif -#endif - -#define DFD_TYPE_FILE "/sys/module/ragile_common/parameters/dfd_my_type" -#define DFD_TYPE_BUFF_SIZE (256) - -static int is_vme_file(char *file_name) -{ - char *tmp; - - tmp = strchr(file_name, '.'); - if (strcmp(tmp, ".bin") == 0) { - return 0; - } else if (strcmp(tmp, ".vme") == 0) { - return 1; - } else { - return -1; - } -} - -int drv_get_my_dev_type(void) -{ - int type; - int fd; - char rbuf[DFD_TYPE_BUFF_SIZE]; - int read_len; - - if (dfd_my_type != 0) { - dbg_print(is_debug_on, "my_type = 0x%x\r\n", dfd_my_type); - return dfd_my_type; - } - - fd = open(DFD_TYPE_FILE, O_RDONLY); - if (fd < 0) { - dbg_print(is_debug_on, "can't open device %s.\r\n", DFD_TYPE_FILE); - return RA_B6010_48GT4X; /* Avoid B6510 to obtain different device types */ - } - - mem_clear(rbuf, DFD_TYPE_BUFF_SIZE); - type = 0; - read_len = read(fd, rbuf, DFD_TYPE_BUFF_SIZE - 1); - if (read_len > 0) { - type = strtoul(rbuf, NULL, 0); - } - close(fd); - - dfd_my_type = type; - - dbg_print(is_debug_on, "read dfd type file is %s read_len %d, dfd_my_type 0x%x\n", rbuf, read_len, dfd_my_type); - return dfd_my_type; -} - -firmware_card_info_t* firmware_get_card_info(int dev_type) -{ - int i; - int size; - - size = (sizeof(g_card_info) /sizeof((g_card_info)[0])); - - dbg_print(is_debug_on, "Enter dev_type 0x%x size %d.\n", dev_type, size); - for (i = 0; i < size; i++) { - if (g_card_info[i].dev_type == dev_type) { - dbg_print(is_debug_on, "match dev_type 0x%x.\n", dev_type); - return &g_card_info[i]; - } - } - - dbg_print(is_debug_on, "dismatch dev_type 0x%x.\n", dev_type); - return NULL; -} - -int firmware_get_card_name(char *name, int len) -{ - int dev_type; - firmware_card_info_t *info; - - dbg_print(is_debug_on, "Enter len %d.\n", len); - dev_type = drv_get_my_dev_type(); - if (dev_type < 0) { - dbg_print(is_debug_on, "drv_get_my_dev_type failed ret %d.\n", dev_type); - return FIRMWARE_FAILED; - } - - info = firmware_get_card_info(dev_type); - if (info == NULL) { - dbg_print(is_debug_on, "firmware_get_card_info dev_type %d failed.\n", dev_type ); - return FIRMWARE_FAILED; - } - - strncpy(name, info->card_name, len - 1); - dbg_print(is_debug_on, "Leave dev_type 0x%x name %s, info->name %s.\n", dev_type, - name, info->card_name); - return FIRMWARE_SUCCESS; -} - -int get_debug_value(void) -{ - return is_debug_on; -} - -#if 0 -/* each device implements its own corresponding interface */ -int __attribute__ ((weak)) firmware_get_card_name(char *name, int len) -{ - strncpy(name, CONFIG_RAGILE_PRODUCT_NAME, len - 1); - return FIRMWARE_SUCCESS; -} -#endif - -static int firmware_check_file_is_dir(char *dir, char *file_name) -{ - int ret; - struct stat buf; - char tmp[FIRMWARE_FILE_DIR_LEN]; - - if (strcmp(file_name, ".") == 0 || strcmp(file_name, "..") == 0) { - return -1; - } - - mem_clear(tmp, FIRMWARE_FILE_DIR_LEN); - snprintf(tmp, FIRMWARE_FILE_DIR_LEN - 1, "%s/%s", dir, file_name); - ret = stat(tmp, &buf); - if (ret < 0) { - return -1; - } - - if (S_ISDIR(buf.st_mode)) { - return 1; - } - - return 0; -} - -static inline int firmware_error_type(int action, name_info_t *info) -{ - if (info == NULL) { - return ERR_FW_UPGRADE; - } - if (info->type == FIRMWARE_CPLD) { - switch (action) { - case FIRMWARE_ACTION_CHECK: - return ERR_FW_CHECK_CPLD_UPGRADE; - case FIRMWARE_ACTION_UPGRADE: - return ERR_FW_DO_CPLD_UPGRADE; - default: - return ERR_FW_UPGRADE; - } - } else if (info->type == FIRMWARE_FPGA) { - switch (action) { - case FIRMWARE_ACTION_CHECK: - return ERR_FW_CHECK_FPGA_UPGRADE; - case FIRMWARE_ACTION_UPGRADE: - return ERR_FW_DO_FPGA_UPGRADE; - default: - return ERR_FW_UPGRADE; - } - } else { - return ERR_FW_UPGRADE; - } -} - -/* analyze file's name,Name rule: card name_firmware type_slot number_firmware chip name.bin*/ -static int firmware_parse_file_name(char *name, name_info_t *info) -{ - int i; - char *tmp, *start; - char slot[FIRMWARE_NAME_LEN]; - - dbg_print(is_debug_on, "Parse file name: %s\n", name); - - start = name; - /* card name */ - tmp = strchr(start, '_'); - if (tmp == NULL) { - dbg_print(is_debug_on, "Failed to get card name form file name: %s.\n", name); - return firmware_error_type(FIRMWARE_ACTION_CHECK, NULL); - } - - strncpy(info->card_name, start, - (tmp - start > FIRMWARE_NAME_LEN - 1) ? (FIRMWARE_NAME_LEN - 1) : (tmp - start)); - - /* firmware type */ - start = tmp + 1; - tmp = strchr(start, '_'); - if (tmp == NULL) { - dbg_print(is_debug_on, "Failed to get upgrade type form file name: %s.\n", name); - return firmware_error_type(FIRMWARE_ACTION_CHECK, NULL); - } - - if (strncmp(start, FIRMWARE_CPLD_NAME, tmp - start) == 0) { - info->type = FIRMWARE_CPLD; - } else if (strncmp(start, FIRMWARE_FPGA_NAME, tmp - start) == 0) { - info->type = FIRMWARE_FPGA; - } else { - info->type = FIRMWARE_OTHER; - } - - /* slot number */ - start = tmp + 1; - tmp = strchr(start, '_'); - if (tmp == NULL) { - dbg_print(is_debug_on, "Failed to get slot form file name: %s.\n", name); - return firmware_error_type(FIRMWARE_ACTION_CHECK, info); - } - - mem_clear(slot, FIRMWARE_NAME_LEN); - strncpy(slot, start, - ((tmp - start > FIRMWARE_NAME_LEN - 1) ? FIRMWARE_NAME_LEN - 1 : tmp - start)); - - for (i = 0; i < FIRMWARE_NAME_LEN && slot[i] != '\0'; i++) { - if (!isdigit(slot[i])) { - return firmware_error_type(FIRMWARE_ACTION_CHECK, info); - } - } - - dbg_print(is_debug_on, "get slot info: %s.\n", name); - info->slot = strtoul(slot, NULL, 10); - dbg_print(is_debug_on, "get slot info slot: %d.\n", info->slot); - - /* firmware chip name */ - start = tmp + 1; - tmp = strchr(start, '_'); - if (tmp == NULL) { - dbg_print(is_debug_on, "Failed to get chip name form file name: %s.\n", name); - return firmware_error_type(FIRMWARE_ACTION_CHECK, info); - } - strncpy(info->chip_name, start, - (tmp - start > FIRMWARE_NAME_LEN - 1) ? (FIRMWARE_NAME_LEN - 1) : (tmp - start)); - - /* version */ - start = tmp + 1; - tmp = strstr(start, ".vme"); - if (tmp == NULL) { - dbg_print(is_debug_on, "Failed to get chip version form file name: %s.\n", name); - return firmware_error_type(FIRMWARE_ACTION_CHECK, info); - } - strncpy(info->version, start, - (tmp - start > FIRMWARE_NAME_LEN - 1) ? (FIRMWARE_NAME_LEN - 1) : (tmp - start)); - - /* finish checking */ - if (strcmp(tmp, ".vme") != 0) { - dbg_print(is_debug_on, "The file format is wrong: %s.\n", name); - return firmware_error_type(FIRMWARE_ACTION_CHECK, info); - } - - return FIRMWARE_SUCCESS; -} - -/* check the file information to determine whether the file can be used in the device */ -static int firmware_check_file_info(name_info_t *info) -{ - int ret; - char card_name[FIRMWARE_NAME_LEN]; - - dbg_print(is_debug_on, "Check file info.\n"); - - /* get card name */ - mem_clear(card_name, FIRMWARE_NAME_LEN); - ret = firmware_get_card_name(card_name, FIRMWARE_NAME_LEN); - if (ret != FIRMWARE_SUCCESS) { - dbg_print(is_debug_on, "Failed to get card name.(%s)\n", info->card_name); - return firmware_error_type(FIRMWARE_ACTION_CHECK, info); - } - - /* check card name */ - dbg_print(is_debug_on, "The card name: %s, the file card name: %s.\n", - card_name, info->card_name); - if (strcmp(card_name, info->card_name) != 0) { - dbg_print(is_debug_on, "The file card name %s is wrong.(real: %s)\n", - info->card_name, card_name); - return firmware_error_type(FIRMWARE_ACTION_CHECK, info); - } - - /* check type */ - if (info->type != FIRMWARE_CPLD && info->type != FIRMWARE_FPGA) { - dbg_print(is_debug_on, "The file type %d is wrong.(cpld %d, fpga %d)\n", - info->type, FIRMWARE_CPLD, FIRMWARE_FPGA); - return firmware_error_type(FIRMWARE_ACTION_CHECK, info); - } - - /* check slot */ - if (info->slot < 1 || info->slot > FIRMWARE_MAX_SLOT_NUM) { - dbg_print(is_debug_on, "The file slot %d is wrong.\n", info->slot); - return firmware_error_type(FIRMWARE_ACTION_CHECK, info); - } - - dbg_print(is_debug_on, "Success check file info.\n"); - return FIRMWARE_SUCCESS; -} - -static void firmware_get_dev_file_name(name_info_t *info, char *file_name, int len) -{ - if (info->type == FIRMWARE_CPLD) { - snprintf(file_name, len, "/dev/firmware_cpld_ispvme%d", info->slot - 1); - } else if (info->type == FIRMWARE_FPGA) { - snprintf(file_name, len, "/dev/firmware_fpga_ispvme%d", info->slot - 1); - } else { - snprintf(file_name, len, "/dev/firmware_ispvme%d", info->slot - 1); - } -} - -static void firmware_set_driver_debug(int fd) -{ - int ret; - - if (is_debug_on == DEBUG_ALL_ON || is_debug_on == DEBUG_KERN_ON) { - ret = ioctl(fd, FIRMWARE_SET_DEBUG_ON, NULL); - if (ret < 0) { - dbg_print(is_debug_on, "Failed to set driver debug on.\n"); - } else { - dbg_print(is_debug_on, "Open driver debug.\n"); - } - } else if (is_debug_on == DEBUG_OFF) { - ret = ioctl(fd, FIRMWARE_SET_DEBUG_OFF, NULL); - if (ret < 0) { - dbg_print(is_debug_on, "Failed to set driver debug off.\n"); - } else { - dbg_print(is_debug_on, "OFF driver debug.\n"); - } - } else { - dbg_print(is_debug_on, "Ignore driver debug.\n"); - } -} - -static int firmware_check_chip_name(int fd, name_info_t *info) -{ - return FIRMWARE_SUCCESS; -} - -static int firmware_check_chip_verison(int fd, name_info_t *info) -{ - return FIRMWARE_SUCCESS; -} - -static int firmware_get_file_size(char *file_name, int *size) -{ - int ret; - struct stat buf; - - ret = stat(file_name, &buf); - if (ret < 0) { - return FIRMWARE_FAILED; - } - - if (buf.st_size < 0) { - return FIRMWARE_FAILED; - } - - *size = buf.st_size; - - return FIRMWARE_SUCCESS; -} - -static int firmware_get_file_info(char *file_name, char *buf, int size) -{ - FILE *fp; - int len; - - fp = fopen(file_name, "r"); - if (fp == NULL) { - return FIRMWARE_FAILED; - } - - len = fread(buf, size, 1, fp); - if (len < 0) { - fclose(fp); - return FIRMWARE_FAILED; - } - - fclose(fp); - - return FIRMWARE_SUCCESS; -} - -static int firmware_upgrade_info(int fd, char *buf, int size) -{ - return FIRMWARE_SUCCESS; -} - -/* upgrade CPLD */ -static int firmware_upgrade(char *dir, char *file_name, name_info_t *info) -{ - return FIRMWARE_SUCCESS; -} - -static int firmware_upgrade_file(char *dir, char *file_name) -{ - int ret, argc; - name_info_t info; - char *argv[2]; - char tmp_file[FIRMWARE_FILE_DIR_LEN]; - - mem_clear(&info, sizeof(name_info_t)); - ret = firmware_parse_file_name(file_name, &info); - if (ret != FIRMWARE_SUCCESS) { - dbg_print(is_debug_on, "Failed to parse file name: %s\n", file_name); - return ret; - } - - dbg_print(is_debug_on, "The file name parse:(%s) \n" - " card name: %s, \n" - " type : %d, \n" - " slot : %d, \n" - " chip name: %s \n" - " version : %s \n", - file_name, info.card_name, info.type, info.slot, info.chip_name, info.version); - - ret = firmware_check_file_info(&info); - if (ret != FIRMWARE_SUCCESS) { - dbg_print(is_debug_on, "Failed to check file name: %s\n", file_name); - return ret; - } - - /* get the information of upgrade file */ - mem_clear(tmp_file, FIRMWARE_FILE_DIR_LEN); - if (dir != NULL) { - snprintf(tmp_file, FIRMWARE_FILE_DIR_LEN - 1, "%s/%s", dir, file_name); - } else { - snprintf(tmp_file, FIRMWARE_FILE_DIR_LEN - 1, "%s", file_name); - } - - argc = 2; - argv[1] = tmp_file; - ret = ispvme_main(argc, (char **)&argv); - if (ret != FIRMWARE_SUCCESS){ - dbg_print(is_debug_on, "Failed to upgrade file name: %s\n", file_name); - } - - return ret; -} - -static int firmware_upgrade_set_gpio_info(int slot) -{ - firmware_card_info_t *hw_info; - cmd_info_t cmd_info; - firmware_upg_gpio_info_t *gpio_info; - int ret; - int fd; - int dev_type; - int my_slot; - - ret = 0; - - dev_type = drv_get_my_dev_type(); - fd = open("/dev/firmware_cpld_ispvme0", O_RDWR); - if (fd < 0) { - dbg_print(is_debug_on, "%s can't open device\r\n", __func__); - return -1; - } - - hw_info = firmware_get_card_info(dev_type); - - if (hw_info == NULL) { - dbg_print(is_debug_on, "card type 0x%x don't support firmware.\n", dev_type); - ret = -1; - goto gpio_info_err; - } - - if (slot >= hw_info->slot_num) { - dbg_print(is_debug_on, "slot %d is too large, support slot num %d.\n", slot, hw_info->slot_num); - ret = -1; - goto gpio_info_err; - } - - gpio_info = &(hw_info->gpio_info[slot]); - cmd_info.size = sizeof(firmware_upg_gpio_info_t); - cmd_info.data = (void *)gpio_info; - - dbg_print(is_debug_on, "slot = %d, gpio_info[jtag_en:%d select:%d tck:%d tdi:%d tdo=%d tms=%d]\n",slot, \ - gpio_info->jtag_en, gpio_info->select,gpio_info->tck,gpio_info->tdi,gpio_info->tdo,gpio_info->tms); - - ret = ioctl(fd, FIRMWARE_SET_GPIO_INFO, &cmd_info); - -gpio_info_err: - if (ret < 0) { - dbg_print(is_debug_on, "Failed due to:set gpio info.\n"); - } - - close(fd); - - return ret; -} - -/** - * argv[1]: file name - * argv[2]: type - * argv[3]: slot number - * argv[4]: chip name - */ -static int firmware_upgrade_one_file(int argc, char *argv[]) -{ - int ret; - name_info_t info; - char tmp[FIRMWARE_FILE_DIR_LEN]; - - mem_clear(&info, sizeof(name_info_t)); - - info.slot = strtoul(argv[3], NULL, 10); - strncpy(info.chip_name, argv[4], FIRMWARE_NAME_LEN - 1); - - if (strcmp(argv[2], FIRMWARE_CPLD_NAME) == 0) { /* CPLD upgrade */ - if(is_vme_file(argv[1]) == 1){ /* VME upgrade file */ - dbg_print(is_debug_on, "vme file\n"); - info.type = FIRMWARE_CPLD; - ret = firmware_upgrade_set_gpio_info(info.slot); - if (ret < 0) { - goto upgrade_err; - } - ret = ispvme_main(2, argv); - } - else if(is_vme_file(argv[1]) == 0){ /* bin upgrade file */ - dbg_print(is_debug_on, "bin file\n"); - mem_clear(tmp, FIRMWARE_FILE_DIR_LEN); - snprintf(tmp, FIRMWARE_FILE_DIR_LEN, "firmware_upgrade_bin %s %s %s %s", argv[1], argv[2], argv[3], argv[4]); - ret = system(tmp); - } - else{ - dbg_print(is_debug_on, "unknow file\n"); - return FIRMWARE_FAILED; - } - } - else if (strcmp(argv[2], FIRMWARE_FPGA_NAME) == 0) { /* FPGA upgrade */ - info.type = FIRMWARE_FPGA; - ret = dfd_fpga_upgrade_do_upgrade(argv[1]); - } else { - dbg_print(is_debug_on, "Failed to get upgrade type: %s.\n", argv[2]); - return ERR_FW_UPGRADE; - } - -upgrade_err: - if (ret != FIRMWARE_SUCCESS){ - dbg_print(is_debug_on, "Failed to upgrade: %s.\n", argv[1]); - } - - return ret; -} - -static void firmware_get_err_type(int err, int *real_err) -{ - int tmp_err; - - tmp_err = *real_err; - - if (tmp_err == err) { - return; - } - switch (err) { - case ERR_FW_DO_CPLD_UPGRADE: - case ERR_FW_DO_FPGA_UPGRADE: - if (tmp_err == ERR_FW_CHECK_CPLD_UPGRADE - || tmp_err == ERR_FW_CHECK_FPGA_UPGRADE - || tmp_err == FIRMWARE_SUCCESS || tmp_err == ERR_FW_UPGRADE) { - tmp_err = err; - } - break; - case ERR_FW_CHECK_CPLD_UPGRADE: - case ERR_FW_CHECK_FPGA_UPGRADE: - if (tmp_err == FIRMWARE_SUCCESS || tmp_err == ERR_FW_UPGRADE) { - tmp_err = err; - } - break; - case ERR_FW_UPGRADE: - if (tmp_err == FIRMWARE_SUCCESS) { - tmp_err = err; - } - break; - case FIRMWARE_SUCCESS: - break; - default: - return; - } - - *real_err = tmp_err; - - return; -} - -/* argv[1]: Pathname */ -static int firmware_upgrade_one_dir(int argc, char *argv[]) -{ - int ret, real_ret; - int flag; - DIR *dirp; - struct dirent *dp; - char *dir; - - dir = argv[1]; - dirp = opendir(dir); - if (dirp == NULL) { - dbg_print(is_debug_on, "Failed to open the dir: %s.\n", dir); - return ERR_FW_UPGRADE; - } - - ret = ERR_FW_UPGRADE; - real_ret = FIRMWARE_SUCCESS; - flag = 0; - for (;;) { - /* read the pathname of the file */ - dp = readdir(dirp); - if (dp == NULL) { - break; - } - - dbg_print(is_debug_on, "The file name: %s.\n", dp->d_name); - /* check whether it is a file */ - if (firmware_check_file_is_dir(dir, dp->d_name) != 0) { - continue; - } - - dbg_print(is_debug_on, "\n=========== Start: %s ===========\n", dp->d_name); - - /* upgrade a upgrade file */ - ret = firmware_upgrade_file(dir, dp->d_name); - if (ret != FIRMWARE_SUCCESS) { - firmware_get_err_type(ret, &real_ret); - dbg_print(is_debug_on, "Failed to upgrade the file: %s.(%d, %d)\n", dp->d_name, ret, real_ret); - } else { - flag = 1; - dbg_print(is_debug_on, "Upgrade the file: %s success.\n", dp->d_name); - } - - dbg_print(is_debug_on, "=========== End: %s ===========\n", dp->d_name); - } - - if (flag == 1 && (real_ret == ERR_FW_CHECK_CPLD_UPGRADE || real_ret == ERR_FW_CHECK_FPGA_UPGRADE)) { - real_ret = FIRMWARE_SUCCESS; - } - - if (real_ret != FIRMWARE_SUCCESS) { - dbg_print(is_debug_on, "Failed to upgrade: %s.\n", dir); - } else { - dbg_print(is_debug_on, "Upgrade success: %s.\n", dir); - } - - closedir(dirp); - return real_ret; -} - -/** - * argv[1]: file name - * argv[2]: type - * argv[3]: slot number - */ -static int firmware_upgrade_read_chip(int argc, char *argv[]) -{ - - return FIRMWARE_SUCCESS; -} - -static int firmware_upgrade_test_fpga(int argc, char *argv[]) -{ - int ret; - char tmp1[128]; - char tmp2[128]; - - if ((strcmp(argv[1], FIRMWARE_FPGA_NAME) != 0) - || (strcmp(argv[2], FIRMWARE_FPGA_TEST) != 0)) { - snprintf(tmp1, sizeof(tmp1), "%s", argv[1]); - snprintf(tmp2, sizeof(tmp2), "%s", argv[2]); - printf( "fpga test:Failed to Input ERR Parm, argv[1]:%s, agrv[2]:%s\n", tmp1,tmp2); - return FIRMWARE_FAILED; - } - ret = dfd_fpga_upgrade_test(); - return ret; -} - -static int firmware_upgrade_test_chip(int argc, char *argv[]) -{ - int ret,dev_type,slot; - int err_ret=0; - firmware_card_info_t *hw_info; - char tmp1[128]; - char tmp2[128]; - - if ((strcmp(argv[1], FIRMWARE_CPLD_NAME) != 0) - || (strcmp(argv[2], FIRMWARE_CPLD_TEST) != 0)) { - snprintf(tmp1, sizeof(tmp1), "%s", argv[1]); - snprintf(tmp2, sizeof(tmp2), "%s", argv[2]); - printf( "gpio test:Failed to Input ERR Parm, argv[1]:%s, agrv[2]:%s\n", tmp1, tmp2); - return FIRMWARE_FAILED; - } - - dev_type = drv_get_my_dev_type(); /* get the type of card first */ - if (dev_type < 0) { - printf("gpio test:drv_get_my_dev_type failed ret 0x%x.\n", dev_type); - return FIRMWARE_FAILED; - } - - hw_info = firmware_get_card_info(dev_type); /* get the detail information of card */ - if (hw_info == NULL) { - printf( "gpio test:card type 0x%x don't support firmware.\n", dev_type); - return FIRMWARE_FAILED; - } - - for(slot = 0; slot < hw_info->slot_num; slot++){ - ret = firmware_upgrade_set_gpio_info(slot); /* set GPIO information */ - if(ret < 0){ - err_ret++; - printf( "gpio test:Failed to set gpio info,dev_type 0x%x,slot %d\n", dev_type, slot); - continue; - } - ret = ispvme_test(); /* GPIO path test */ - if(ret != 0){ - err_ret++; - printf("gpio test:ispvme_test failed,dev_type 0x%x,slot %d\n", dev_type, slot); - } - } - if(err_ret != 0) - return FIRMWARE_FAILED; - return FIRMWARE_SUCCESS; -} - -int main(int argc, char *argv[]) -{ - int ret; - - is_debug_on = firmware_upgrade_debug(); - - if (argc != 2 && argc != 5 && argc != 4 && argc != 3 && argc != 6) { - printf("Use:\n"); - printf(" upgrade dir : firmware_upgrade_ispvme dir\n"); - printf(" upgrade file : firmware_upgrade_ispvme file type slot chip_name\n"); - printf(" read chip : firmware_upgrade_ispvme file type slot\n"); - dbg_print(is_debug_on, "Failed to upgrade the number of argv: %d.\n", argc); - return ERR_FW_UPGRADE; - } -#if 0 - ret = dev_drv_init(); - if (ret) { - dbg_print(is_debug_on, "failed to init dfd ret %d.", ret); - return ERR_FW_UPGRADE; - } -#endif - /* dump fpga flash operation */ - if (argc == 6) { - if (strcmp(argv[1], "fpga_dump_flash") == 0) { - ret = dfd_fpga_upgrade_dump_flash(argc, argv); - printf("fpga_dump_flash ret %d.\n", ret); - return FIRMWARE_SUCCESS; - } else { - printf("Not support, please check your cmd.\n"); - return FIRMWARE_SUCCESS; - } - } - - /* upgrade individual files */ - if (argc == 5) { - printf("+================================+\n"); - printf("|Begin to upgrade, please wait...|\n"); - ret = firmware_upgrade_one_file(argc, argv); - if (ret != FIRMWARE_SUCCESS) { - if(strcmp(argv[2], FIRMWARE_CPLD_NAME) == 0) - printf("| CPLD Upgrade failed! |\n"); - else if(strcmp(argv[2], FIRMWARE_FPGA_NAME) == 0) - printf("| FPGA Upgrade failed! |\n"); - else - printf("| Failed to get upgrade type! |\n"); - printf("+================================+\n"); - dbg_print(is_debug_on, "Failed to upgrade a firmware file: %s.\n", argv[1]); - return ret; - } - if(strcmp(argv[2], FIRMWARE_CPLD_NAME) == 0) - printf("| CPLD Upgrade succeeded! |\n"); - else - printf("| FPGA Upgrade succeeded! |\n"); - printf("+================================+\n"); - return FIRMWARE_SUCCESS; - } - - if (argc == 2) { - printf("+================================+\n"); - printf("|Begin to upgrade, please wait...|\n"); - - ret = firmware_upgrade_one_dir(argc, argv); - if (ret != FIRMWARE_SUCCESS) { - printf("| Upgrade failed! |\n"); - printf("+================================+\n"); - dbg_print(is_debug_on, "Failed to upgrade a firmware dir: %s.\n", argv[1]); - return ret; - } - printf("| Upgrade succeeded! |\n"); - printf("+================================+\n"); - return FIRMWARE_SUCCESS; - } - - if (argc == 4) { - ret = firmware_upgrade_read_chip(argc, argv); - if (ret != FIRMWARE_SUCCESS) { - dbg_print(is_debug_on, "Failed to read chip: %s.\n", argv[1]); - return ret; - } - - return FIRMWARE_SUCCESS; - } - - if (argc == 3) { - if (strcmp(argv[1], FIRMWARE_FPGA_NAME) == 0) { - ret = firmware_upgrade_test_fpga(argc, argv); - if (ret != FIRMWARE_SUCCESS) { - printf("+=================+\n"); - printf("| FPGA TEST FAIL! |\n"); - printf("+=================+\n"); - return FIRMWARE_FAILED; - } else { - printf("+=================+\n"); - printf("| FPGA TEST PASS! |\n"); - printf("+=================+\n"); - return FIRMWARE_SUCCESS; - } - } else { - ret = firmware_upgrade_test_chip(argc, argv); - if (ret != FIRMWARE_SUCCESS) { - printf("+=================+\n"); - printf("| GPIO TEST FAIL! |\n"); - printf("+=================+\n"); - return FIRMWARE_FAILED; - } else { - printf("+=================+\n"); - printf("| GPIO TEST PASS! |\n"); - printf("+=================+\n"); - return FIRMWARE_SUCCESS; - } - } - } - - return ERR_FW_UPGRADE; -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/hardware.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/hardware.c deleted file mode 100644 index 8f8ca9ed8c..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/hardware.c +++ /dev/null @@ -1,249 +0,0 @@ -/********************************************************************************* -* Lattice Semiconductor Corp. Copyright 2000-2008 -* -* This is the hardware.c of ispVME V12.1 for JTAG programmable devices. -* All the functions requiring customization are organized into this file for -* the convinience of porting. -*********************************************************************************/ -/********************************************************************************* -* Revision History: -* -* 09/11/07 NN Type cast mismatch variables -* 09/24/07 NN Added calibration function. -* Calibration will help to determine the system clock frequency -* and the count value for one micro-second delay of the target -* specific hardware. -* Modified the ispVMDelay function -* Removed Delay Percent support -* Moved the sclock() function from ivm_core.c to hardware.c -*********************************************************************************/ - -/* #include */ -#include -#include -#include "common.h" - -/******************************************************************************** -* Declaration of global variables -* -*********************************************************************************/ - -unsigned char g_siIspPins = 0x00; /*Keeper of JTAG pin state*/ -unsigned short g_usInPort = 0x379; /*Address of the TDO pin*/ -unsigned short g_usOutPort = 0x378; /*Address of TDI, TMS, TCK pin*/ -unsigned short g_usCpu_Frequency = 1000; /*Enter your CPU frequency here, unit in MHz.*/ - -/********************************************************************************* -* This is the definition of the bit locations of each respective -* signal in the global variable g_siIspPins. -* -* NOTE: Users must add their own implementation here to define -* the bit location of the signal to target their hardware. -* The example below is for the Lattice download cable on -* on the parallel port. -* -*********************************************************************************/ - -#if 0 -const unsigned char g_ucPinTDI = JTAG_TDI; /* Bit address of TDI */ -const unsigned char g_ucPinTCK = JTAG_TCK; /* Bit address of TCK */ -const unsigned char g_ucPinTMS = JTAG_TMS; /* Bit address of TMS */ -const unsigned char g_ucPinENABLE = JTAG_ENABLE; /* Bit address of ENABLE */ -const unsigned char g_ucPinTRST = JTAG_TRST; /* Bit address of TRST */ -const unsigned char g_ucPinTDO = JTAG_TDO; /* Bit address of TDO*/ -#endif -int g_file_fd; -/*************************************************************** -* -* Functions declared in hardware.c module. -* -***************************************************************/ -void writePort(unsigned char a_ucPins, unsigned char a_ucValue); -unsigned char readPort(); -void sclock(); -void ispVMDelay(unsigned short a_usTimeDelay); -void calibration(void); - -/******************************************************************************** -* writePort -* To apply the specified value to the pins indicated. This routine will -* be modified for specific systems. -* As an example, this code uses the IBM-PC standard Parallel port, along with the -* schematic shown in Lattice documentation, to apply the signals to the -* JTAG pins. -* -* PC Parallel port pin Signal name Port bit address -* 2 g_ucPinTDI 1 -* 3 g_ucPinTCK 2 -* 4 g_ucPinTMS 4 -* 5 g_ucPinENABLE 8 -* 6 g_ucPinTRST 16 -* 10 g_ucPinTDO 64 -* -* Parameters: -* - a_ucPins, which is actually a set of bit flags (defined above) -* that correspond to the bits of the data port. Each of the I/O port -* bits that drives an isp programming pin is assigned a flag -* (through a #define) corresponding to the signal it drives. To -* change the value of more than one pin at once, the flags are added -* together, much like file access flags are. -* -* The bit flags are only set if the pin is to be changed. Bits that -* do not have their flags set do not have their levels changed. The -* state of the port is always manintained in the static global -* variable g_siIspPins, so that each pin can be addressed individually -* without disturbing the others. -* -* - a_ucValue, which is either HIGH (0x01 ) or LOW (0x00 ). Only these two -* values are valid. Any non-zero number sets the pin(s) high. -* -*********************************************************************************/ - -void writePort(unsigned char a_ucPins, unsigned char a_ucValue) -{ - switch (a_ucPins) { - case JTAG_TCK: - ioctl(g_file_fd, FIRMWARE_JTAG_TCK, &a_ucValue); - break; - case JTAG_TDI: - ioctl(g_file_fd, FIRMWARE_JTAG_TDI, &a_ucValue); - break; - case JTAG_TMS: - ioctl(g_file_fd, FIRMWARE_JTAG_TMS, &a_ucValue); - break; - case JTAG_ENABLE: - ioctl(g_file_fd, FIRMWARE_JTAG_EN, &a_ucValue); - break; - case JTAG_TRST: - /* ioctl(g_file_fd, FIRMWARE_JTAG_TRST, &a_ucValue); */ - break; - default: - break; - } -} - -/********************************************************************************* -* -* readPort -* -* Returns the value of the TDO from the device. -* -**********************************************************************************/ -unsigned char readPort() -{ - unsigned char ucRet = 0; - - ioctl(g_file_fd, FIRMWARE_JTAG_TDO, &ucRet); - return (ucRet); -} - -/********************************************************************************* -* sclock -* -* Apply a pulse to TCK. -* -* This function is located here so that users can modify to slow down TCK if -* it is too fast (> 25MHZ). Users can change the IdleTime assignment from 0 to -* 1, 2... to effectively slowing down TCK by half, quarter... -* -*********************************************************************************/ -void sclock() -{ - unsigned short IdleTime = 0; /* change to > 0 if need to slow down TCK */ - unsigned short usIdleIndex = 0; - IdleTime++; - for (usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++) { - writePort(JTAG_TCK, 0x01); - } - for (usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++) { - writePort(JTAG_TCK, 0x00); - } -} -/******************************************************************************** -* -* ispVMDelay -* -* -* Users must implement a delay to observe a_usTimeDelay, where -* bit 15 of the a_usTimeDelay defines the unit. -* 1 = milliseconds -* 0 = microseconds -* Example: -* a_usTimeDelay = 0x0001 = 1 microsecond delay. -* a_usTimeDelay = 0x8001 = 1 millisecond delay. -* -* This subroutine is called upon to provide a delay from 1 millisecond to a few -* hundreds milliseconds each time. -* It is understood that due to a_usTimeDelay is defined as unsigned short, a 16 bits -* integer, this function is restricted to produce a delay to 64000 micro-seconds -* or 32000 milli-second maximum. The VME file will never pass on to this function -* a delay time > those maximum number. If it needs more than those maximum, the VME -* file will launch the delay function several times to realize a larger delay time -* cummulatively. -* It is perfectly alright to provide a longer delay than required. It is not -* acceptable if the delay is shorter. -* -* Delay function example--using the machine clock signal of the native CPU------ -* When porting ispVME to a native CPU environment, the speed of CPU or -* the system clock that drives the CPU is usually known. -* The speed or the time it takes for the native CPU to execute one for loop -* then can be calculated as follows: -* The for loop usually is compiled into the ASSEMBLY code as shown below: -* LOOP: DEC RA; -* JNZ LOOP; -* If each line of assembly code needs 4 machine cycles to execute, -* the total number of machine cycles to execute the loop is 2 x 4 = 8. -* Usually system clock = machine clock (the internal CPU clock). -* Note: Some CPU has a clock multiplier to double the system clock for - the machine clock. -* -* Let the machine clock frequency of the CPU be F, or 1 machine cycle = 1/F. -* The time it takes to execute one for loop = (1/F ) x 8. -* Or one micro-second = F(MHz)/8; -* -* Example: The CPU internal clock is set to 100Mhz, then one micro-second = 100/8 = 12 -* -* The C code shown below can be used to create the milli-second accuracy. -* Users only need to enter the speed of the cpu. -* -**********************************************************************************/ -void ispVMDelay(unsigned short a_usTimeDelay) -{ - if (a_usTimeDelay & 0x8000) { - a_usTimeDelay &= ~0x8000; /* change it to ms */ - usleep(a_usTimeDelay * 1000); /* Use usleep to improve accuracy */ - } else - usleep(a_usTimeDelay); - return; -} - -/********************************************************************************* -* -* calibration -* -* It is important to confirm if the delay function is indeed providing -* the accuracy required. Also one other important parameter needed -* checking is the clock frequency. -* Calibration will help to determine the system clock frequency -* and the loop_per_micro value for one micro-second delay of the target -* specific hardware. -* -**********************************************************************************/ -void calibration(void) -{ - /*Apply 2 pulses to TCK.*/ - writePort(JTAG_TCK, 0x00); - writePort(JTAG_TCK, 0x01); - writePort(JTAG_TCK, 0x00); - writePort(JTAG_TCK, 0x01); - writePort(JTAG_TCK, 0x00); - - /*Delay for 1 millisecond. Pass on 1000 or 0x8001 both = 1ms delay.*/ - ispVMDelay(0x8001); - - /*Apply 2 pulses to TCK*/ - writePort(JTAG_TCK, 0x01); - writePort(JTAG_TCK, 0x00); - writePort(JTAG_TCK, 0x01); - writePort(JTAG_TCK, 0x00); -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/include/debug_ispvme.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/include/debug_ispvme.h deleted file mode 100644 index 17c6b02261..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/include/debug_ispvme.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __FIRMWARE_UPGRADE_DEBUG_H__ -#define __FIRMWARE_UPGRADE_DEBUG_H__ - -#define DEBUG_INFO_LEN 20 -#define DEBUG_FILE "/.firmware_upgrade_debug" -#define DEBUG_ON_ALL "3" -#define DEBUG_ON_KERN "2" -#define DEBUG_ON_INFO "1" -#define DEBUG_OFF_INFO "0" - -enum debug_s { - DEBUG_OFF = 0, /* debug off */ - DEBUG_APP_ON, /* debug app on */ - DEBUG_KERN_ON, /* kernel debug on */ - DEBUG_ALL_ON, /* debug app and kernel debug on */ - DEBUG_IGNORE, /* ignore debug */ -}; - -extern int firmware_upgrade_debug(void); - -#endif /* End of __FIRMWARE_UPGRADE_DEBUG_H__ */ \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/include/firmware_app_ispvme.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/include/firmware_app_ispvme.h deleted file mode 100644 index e44214dfca..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/include/firmware_app_ispvme.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef __FIRMWARE_APP_H__ -#define __FIRMWARE_APP_H__ - -#include -#include -#include - -/* Agreement with PKG_MGMT module */ -#define ERR_FW_CHECK_CPLD_UPGRADE (440 - 256) -#define ERR_FW_CHECK_FPGA_UPGRADE (441 - 256) -#define ERR_FW_DO_CPLD_UPGRADE (442 - 256) -#define ERR_FW_DO_FPGA_UPGRADE (443 - 256) -#define ERR_FW_UPGRADE (444 - 256) - -#define FIRMWARE_FAILED -1 -#define FIRMWARE_SUCCESS 0 - -#define FIRMWARE_ACTION_CHECK 0 -#define FIRMWARE_ACTION_UPGRADE 1 - -#define mem_clear(data, size) memset((data), 0, (size)) - -#define dbg_print(debug, fmt, arg...) \ - if (debug == DEBUG_APP_ON || debug == DEBUG_ALL_ON) \ - { do{printf(fmt,##arg);} while(0); } - -#define FIRMWARE_FILE_DIR_LEN 128 -#define FIRMWARE_NAME_LEN 48 -#define FIRMWARE_MAX_SLOT_NUM 32 - -#define FIRMWARE_CPLD_NAME "cpld" -#define FIRMWARE_FPGA_NAME "fpga" - -#define FIRMWARE_CPLD_EPM1270F256 "EPM1270F256" -#define FIRMWARE_CPLD_5M1270 "5M1270" -#define FIRMWARE_CPLD_TEST "test" -#define FIRMWARE_FPGA_TEST "test" - -/* ioctl command */ -#define FIRMWARE_TYPE 'F' - -#define FIRMWARE_JTAG_TDI _IOR(FIRMWARE_TYPE, 0, char) -#define FIRMWARE_JTAG_TDO _IOR(FIRMWARE_TYPE, 1, char) -#define FIRMWARE_JTAG_TCK _IOR(FIRMWARE_TYPE, 2, char) -#define FIRMWARE_JTAG_TMS _IOR(FIRMWARE_TYPE, 3, char) -#define FIRMWARE_JTAG_EN _IOR(FIRMWARE_TYPE, 4, char) -#define FIRMWARE_SET_DEBUG_ON _IOW(FIRMWARE_TYPE, 5, int) /* debug on */ -#define FIRMWARE_SET_DEBUG_OFF _IOW(FIRMWARE_TYPE, 6, int) /* debug off */ -#define FIRMWARE_SET_GPIO_INFO _IOR(FIRMWARE_TYPE, 7, int) /* GPIO info */ - -#define FIRMWARE_MAX_SUB_SLOT_NUM (8) -#define FIRMWARE_MAX_CARD_SLOT_NUM ((FIRMWARE_MAX_SUB_SLOT_NUM) + (1))/* max slot num */ -#define FIRMWARE_CARD_NAME_MAX_LEN (64) -#define GPIO(p, v, d) { \ - .pin = p, \ - .val = v, \ - .dir = d, \ - }, - -enum firmware_type_s { - FIRMWARE_CPLD = 0, - FIRMWARE_FPGA, - FIRMWARE_OTHER, -}; - -typedef struct name_info_s { - char card_name[FIRMWARE_NAME_LEN]; /* card name */ - int type; /* upgrade file type */ - int slot; /* slot number correspoding to upgrade file */ - char chip_name[FIRMWARE_NAME_LEN]; /* chip name */ - char version[FIRMWARE_NAME_LEN]; /* version */ -} name_info_t; - -typedef struct cmd_info_s { - int size; - void *data; -} cmd_info_t; - -typedef struct gpio_group_s { - int pin; - int val; - int dir; -} gpio_group_t; - -typedef struct firmware_upg_gpio_info_s { - int tdi; - int tck; - int tms; - int tdo; - int jtag_en; - int select; - gpio_group_t jtag_5; - gpio_group_t jtag_4; - gpio_group_t jtag_3; - gpio_group_t jtag_2; - gpio_group_t jtag_1; -} firmware_upg_gpio_info_t; - -typedef struct firmware_card_info_s { - int dev_type; /* the type of card */ - int slot_num; - char card_name[FIRMWARE_CARD_NAME_MAX_LEN]; - firmware_upg_gpio_info_t gpio_info[FIRMWARE_MAX_CARD_SLOT_NUM]; /* private data */ -} firmware_card_info_t; - -typedef enum card_type_e { - RA_B6010_48GT4X = 0X4065, - RA_B6010_48GT4X_R = 0X4065, -} card_type_t; - -extern firmware_card_info_t* firmware_get_card_info(int dev_type); -extern int dfd_fpga_upgrade_do_upgrade(char* upg_file); -extern int dfd_fpga_upgrade_test(void); -extern int ispvme_test(void); -extern int ispvme_main(int argc, char *argv[]); -/* External fpga dump interface */ -extern int dfd_fpga_upgrade_dump_flash(int argc, char* argv[]); - -#endif /* End of __FIRMWARE_APP_H__ */ \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/ispvm_ui.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/ispvm_ui.c deleted file mode 100644 index a06f9de9a8..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/ispvm_ui.c +++ /dev/null @@ -1,845 +0,0 @@ -/************************************************************** -* -* Lattice Semiconductor Corp. Copyright 2008 -* -* ispVME Embedded allows programming of Lattice's suite of FPGA -* devices on embedded systems through the JTAG port. The software -* is distributed in source code form and is open to re - distribution -* and modification where applicable. -* -* ispVME Embedded C Source comprised with 3 modules: -* ispvm_ui.c is the module provides input and output support. -* ivm_core.c is the module interpret the VME file(s). -* hardware.c is the module access the JTAG port of the device(s). -* -* The optional module cable.c is for supporting Lattice's parallel -* port ispDOWNLOAD cable on DOS and Windows 95/98 O/S. It can be -* requested from Lattice's ispVMSupport. -* -***************************************************************/ - -/************************************************************** -* -* Revision History of ispvm_ui.c -* -* 3/6/07 ht Added functions vme_out_char(),vme_out_hex(), -* vme_out_string() to provide output resources. -* Consolidate all printf() calls into the added output -* functions. -* -* 09/11/07 NN Added Global variables initialization -* 09/24/07 NN Added a switch allowing users to do calibration. -* Calibration will help to determine the system clock frequency -* and the count value for one micro-second delay of the target -* specific hardware. -* Removed Delay Percent support -* 11/15/07 NN moved the checking of the File CRC to the end of processing -* 08/28/08 NN Added Calculate checksum support. -***************************************************************/ - -#include -#include -#include -#include -#include -#include "vmopcode.h" -#include "common.h" - -#define dbg_print(debug, fmt, arg...) \ - if (debug == DEBUG_APP_ON || debug == DEBUG_ALL_ON) \ - { do{printf(fmt,##arg);} while(0); } - -/*************************************************************** -* -* File pointer to the VME file. -* -***************************************************************/ - -FILE *g_pVMEFile = NULL; - -/*************************************************************** -* -* Functions declared in this ispvm_ui.c module -* -***************************************************************/ -unsigned char GetByte(void); -void vme_out_char(unsigned char charOut); -void vme_out_hex(unsigned char hexOut); -void vme_out_string(char *stringOut); -void ispVMMemManager(signed char cTarget, unsigned short usSize); -void ispVMFreeMem(void); -void error_handler(short a_siRetCode, char *pszMessage); -signed char ispVM(const char *a_pszFilename); - -/*************************************************************** -* -* Global variables. -* -***************************************************************/ -unsigned short g_usPreviousSize = 0; -unsigned short g_usExpectedCRC = 0; - -/*************************************************************** -* -* External variables and functions declared in ivm_core.c module. -* -***************************************************************/ -extern signed char ispVMCode(); -extern void ispVMCalculateCRC32(unsigned char a_ucData); -extern void ispVMStart(); -extern void ispVMEnd(); -extern void ispVMStateMachine(signed char NextState); -extern void writePort(unsigned char a_ucPins, unsigned char a_ucValue); -extern void sclock(); -extern unsigned char readPort(); -extern unsigned short g_usCalculatedCRC; -extern unsigned short g_usDataType; -extern unsigned char *g_pucOutMaskData, -*g_pucInData, -*g_pucOutData, -*g_pucHIRData, -*g_pucTIRData, -*g_pucHDRData, -*g_pucTDRData, -*g_pucOutDMaskData, -*g_pucIntelBuffer; -extern unsigned char *g_pucHeapMemory; -extern unsigned short g_iHeapCounter; -extern unsigned short g_iHEAPSize; -extern unsigned short g_usIntelDataIndex; -extern unsigned short g_usIntelBufferSize; -extern LVDSPair *g_pLVDSList; -/* 08/28/08 NN Added Calculate checksum support. */ -extern unsigned long g_usChecksum; -extern unsigned int g_uiChecksumIndex; -/*************************************************************** -* -* External variables and functions declared in hardware.c module. -* -***************************************************************/ -extern void calibration(void); -extern unsigned short g_usCpu_Frequency; - -static int is_debug_on = -1; - -/*************************************************************** -* -* Supported VME versions. -* -***************************************************************/ - -const char *const g_szSupportedVersions[] = { "__VME2.0", "__VME3.0", "____12.0", "____12.1", 0 }; - -/*************************************************************** -* -* GetByte -* -* Returns a byte to the caller. The returned byte depends on the -* g_usDataType register. If the HEAP_IN bit is set, then the byte -* is returned from the HEAP. If the LHEAP_IN bit is set, then -* the byte is returned from the intelligent buffer. Otherwise, -* the byte is returned directly from the VME file. -* -***************************************************************/ - -char* strlwr(char *str) -{ - char *orig = str; - /* process the string */ - for (; *str != '\0'; str++) - *str = tolower(*str); - return orig; -} - -unsigned char GetByte() -{ - unsigned char ucData = 0; - - if (g_usDataType & HEAP_IN) { - - /*************************************************************** - * - * Get data from repeat buffer. - * - ***************************************************************/ - - if (g_iHeapCounter > g_iHEAPSize) { - - /*************************************************************** - * - * Data over-run. - * - ***************************************************************/ - - return 0xFF; - } - - ucData = g_pucHeapMemory[g_iHeapCounter++]; - } - else if ( g_usDataType & LHEAP_IN ) { - - /*************************************************************** - * - * Get data from intel buffer. - * - ***************************************************************/ - - if (g_usIntelDataIndex >= g_usIntelBufferSize) { - - /*************************************************************** - * - * Data over-run. - * - ***************************************************************/ - - return 0xFF; - } - - ucData = g_pucIntelBuffer[g_usIntelDataIndex++]; - } - else { - - /*************************************************************** - * - * Get data from file. - * - ***************************************************************/ - - ucData = (unsigned char)fgetc(g_pVMEFile); - - - if (feof(g_pVMEFile)) { - - /*************************************************************** - * - * Reached EOF. - * - ***************************************************************/ - - return 0xFF; - } - /*************************************************************** - * - * Calculate the 32-bit CRC if the expected CRC exist. - * - ***************************************************************/ - if( g_usExpectedCRC != 0) - { - ispVMCalculateCRC32(ucData); - } - } - - return (ucData); -} - -/*************************************************************** -* -* vme_out_char -* -* Send a character out to the output resource if available. -* The monitor is the default output resource. -* -* -***************************************************************/ -void vme_out_char(unsigned char charOut) -{ - dbg_print(is_debug_on, "%c", charOut); -} -/*************************************************************** -* -* vme_out_hex -* -* Send a character out as in hex format to the output resource -* if available. The monitor is the default output resource. -* -* -***************************************************************/ -void vme_out_hex(unsigned char hexOut) -{ - dbg_print(is_debug_on, "%.2X", hexOut); -} -/*************************************************************** -* -* vme_out_string -* -* Send a text string out to the output resource if available. -* The monitor is the default output resource. -* -* -***************************************************************/ -void vme_out_string(char *stringOut) -{ - if (is_debug_on == -1) { - is_debug_on = firmware_upgrade_debug(); - } - - dbg_print(is_debug_on, stringOut); -} -/*************************************************************** -* -* ispVMMemManager -* -* Allocate memory based on cTarget. The memory size is specified -* by usSize. -* -***************************************************************/ - -void ispVMMemManager(signed char cTarget, unsigned short usSize) -{ - switch (cTarget) { - case XTDI: - case TDI: - if (g_pucInData != NULL) { - if (g_usPreviousSize == usSize) { /*memory exist*/ - break; - } - else { - free(g_pucInData); - g_pucInData = NULL; - } - } - g_pucInData = (unsigned char *)malloc(usSize / 8 + 2); - g_usPreviousSize = usSize; - case XTDO: - case TDO: - if (g_pucOutData != NULL) { - if (g_usPreviousSize == usSize) { /*already exist*/ - break; - } - else { - free(g_pucOutData); - g_pucOutData = NULL; - } - } - g_pucOutData = (unsigned char *)malloc(usSize / 8 + 2); - g_usPreviousSize = usSize; - break; - case MASK: - if (g_pucOutMaskData != NULL) { - if (g_usPreviousSize == usSize) { /*already allocated*/ - break; - } - else { - free(g_pucOutMaskData); - g_pucOutMaskData = NULL; - } - } - g_pucOutMaskData = (unsigned char *)malloc(usSize / 8 + 2); - g_usPreviousSize = usSize; - break; - case HIR: - if (g_pucHIRData != NULL) { - free(g_pucHIRData); - g_pucHIRData = NULL; - } - g_pucHIRData = (unsigned char *)malloc(usSize / 8 + 2); - break; - case TIR: - if (g_pucTIRData != NULL) { - free(g_pucTIRData); - g_pucTIRData = NULL; - } - g_pucTIRData = (unsigned char *)malloc(usSize / 8 + 2); - break; - case HDR: - if (g_pucHDRData != NULL) { - free(g_pucHDRData); - g_pucHDRData = NULL; - } - g_pucHDRData = (unsigned char *)malloc(usSize / 8 + 2); - break; - case TDR: - if (g_pucTDRData != NULL) { - free(g_pucTDRData); - g_pucTDRData = NULL; - } - g_pucTDRData = (unsigned char *)malloc(usSize / 8 + 2); - break; - case HEAP: - if (g_pucHeapMemory != NULL) { - free(g_pucHeapMemory); - g_pucHeapMemory = NULL; - } - g_pucHeapMemory = (unsigned char *)malloc(usSize + 2); - break; - case DMASK: - if (g_pucOutDMaskData != NULL) { - if (g_usPreviousSize == usSize) { /*already allocated*/ - break; - } - else { - free(g_pucOutDMaskData); - g_pucOutDMaskData = NULL; - } - } - g_pucOutDMaskData = (unsigned char *)malloc(usSize / 8 + 2); - g_usPreviousSize = usSize; - break; - case LHEAP: - if (g_pucIntelBuffer != NULL) { - free(g_pucIntelBuffer); - g_pucIntelBuffer = NULL; - } - g_pucIntelBuffer = (unsigned char *)malloc(usSize + 2); - break; - case LVDS: - if (g_pLVDSList != NULL) { - free(g_pLVDSList); - g_pLVDSList = NULL; - } - g_pLVDSList = (LVDSPair * )calloc(usSize, sizeof(LVDSPair)); - break; - default: - return; - } -} - -/*************************************************************** -* -* ispVMFreeMem -* -* Free memory that were dynamically allocated. -* -***************************************************************/ - -void ispVMFreeMem() -{ - if (g_pucHeapMemory != NULL) { - free(g_pucHeapMemory); - g_pucHeapMemory = NULL; - } - - if (g_pucOutMaskData != NULL) { - free(g_pucOutMaskData); - g_pucOutMaskData = NULL; - } - - if (g_pucInData != NULL) { - free(g_pucInData); - g_pucInData = NULL; - } - - if (g_pucOutData != NULL) { - free(g_pucOutData); - g_pucOutData = NULL; - } - - if (g_pucHIRData != NULL) { - free(g_pucHIRData); - g_pucHIRData = NULL; - } - - if (g_pucTIRData != NULL) { - free(g_pucTIRData); - g_pucTIRData = NULL; - } - - if (g_pucHDRData != NULL) { - free(g_pucHDRData); - g_pucHDRData = NULL; - } - - if (g_pucTDRData != NULL) { - free(g_pucTDRData); - g_pucTDRData = NULL; - } - - if (g_pucOutDMaskData != NULL) { - free(g_pucOutDMaskData); - g_pucOutDMaskData = NULL; - } - - if (g_pucIntelBuffer != NULL) { - free(g_pucIntelBuffer); - g_pucIntelBuffer = NULL; - } - - if (g_pLVDSList != NULL) { - free(g_pLVDSList); - g_pLVDSList = NULL; - } -} - -/*************************************************************** -* -* error_handler -* -* Reports the error message. -* -***************************************************************/ - -void error_handler(short a_siRetCode, char *pszMessage) -{ - const char *pszErrorMessage[] = { "pass", - "verification fail", - "can't find the file", - "wrong file type", - "file error", - "option error", - "crc verification error" }; - - strcpy(pszMessage, pszErrorMessage[-a_siRetCode]); -} -/*************************************************************** -* -* ispVM -* -* The entry point of the ispVM embedded. If the version and CRC -* are verified, then the VME will be processed. -* -***************************************************************/ - -signed char ispVM(const char *a_pszFilename) -{ - char szFileVersion[9] = { 0 }; - signed char cRetCode = 0; - signed char cIndex = 0; - signed char cVersionIndex = 0; - unsigned char ucReadByte = 0; - - /*************************************************************** - * - * Global variables initialization. - * - * 09/11/07 NN Added - ***************************************************************/ - g_pucHeapMemory = NULL; - g_iHeapCounter = 0; - g_iHEAPSize = 0; - g_usIntelDataIndex = 0; - g_usIntelBufferSize = 0; - g_usPreviousSize = 0; - - /*************************************************************** - * - * Open a file pointer to the VME file. - * - ***************************************************************/ - - - - if ((g_pVMEFile = fopen(a_pszFilename, "rb")) == NULL) { - return VME_FILE_READ_FAILURE; - } - g_usCalculatedCRC = 0; - g_usExpectedCRC = 0; - ucReadByte = GetByte(); - //dbg_print(is_debug_on, "data: 0x%x.\n", ucReadByte); - switch (ucReadByte) { - case FILE_CRC: - - /*************************************************************** - * - * Read and store the expected CRC to do the comparison at the end. - * Only versions 3.0 and higher support CRC protection. - * - ***************************************************************/ - - g_usExpectedCRC = (unsigned char)fgetc(g_pVMEFile); - g_usExpectedCRC <<= 8; - g_usExpectedCRC |= fgetc(g_pVMEFile); - - /*************************************************************** - * - * Read and store the version of the VME file. - * - ***************************************************************/ - - - for (cIndex = 0; cIndex < 8; cIndex++) { - szFileVersion[cIndex] = GetByte(); - } - break; - default: - - /*************************************************************** - * - * Read and store the version of the VME file. Must be version 2.0. - * - ***************************************************************/ - - szFileVersion[0] = (signed char)ucReadByte; - for (cIndex = 1; cIndex < 8; cIndex++) { - szFileVersion[cIndex] = GetByte(); - } - - break; - } - - /*************************************************************** - * - * Compare the VME file version against the supported version. - * - ***************************************************************/ - /* check the file version: the value of 0x03-0x0a */ - for (cVersionIndex = 0; g_szSupportedVersions[cVersionIndex] != 0; cVersionIndex++) { - for (cIndex = 0; cIndex < 8; cIndex++) { - if (szFileVersion[cIndex] != g_szSupportedVersions[cVersionIndex][cIndex]) { - cRetCode = VME_VERSION_FAILURE; - break; - } - cRetCode = 0; - } - - if (cRetCode == 0) { - - /*************************************************************** - * - * Found matching version, break. - * - ***************************************************************/ - - break; - } - } - - if (cRetCode < 0) { - - /*************************************************************** - * - * VME file version failed to match the supported versions. - * - ***************************************************************/ - - fclose(g_pVMEFile); - g_pVMEFile = NULL; - return VME_VERSION_FAILURE; - } - - /*************************************************************** - * - * Enable the JTAG port to communicate with the device. - * Set the JTAG state machine to the Test-Logic/Reset State. - * - ***************************************************************/ - ispVMStart(); - - - /*************************************************************** - * - * Process the VME file. - * - ***************************************************************/ - - cRetCode = ispVMCode(); - - /*************************************************************** - * - * Set the JTAG State Machine to Test-Logic/Reset state then disable - * the communication with the JTAG port. - * - ***************************************************************/ - - ispVMEnd(); - - fclose(g_pVMEFile); - g_pVMEFile = NULL; - - ispVMFreeMem(); - - /*************************************************************** - * - * Compare the expected CRC versus the calculated CRC. - * - ***************************************************************/ - - if (cRetCode == 0 && g_usExpectedCRC != 0 && (g_usExpectedCRC != g_usCalculatedCRC)) { - printf("Expected CRC: 0x%.4X\n", g_usExpectedCRC); - printf("Calculated CRC: 0x%.4X\n", g_usCalculatedCRC); - return VME_CRC_FAILURE; - } - - return (cRetCode); -} - -/*************************************************************** -* -* main -* -***************************************************************/ -extern int g_file_fd; -int ispvme_main(int argc, char *argv[]) -{ - unsigned short iCommandLineIndex = 0; - short siRetCode = 0; - char szExtension[5] = { 0 }; - char szCommandLineArg[300] = { 0 }; - short sicalibrate = 0; - - /* 08/28/08 NN Added Calculate checksum support. */ - g_usChecksum = 0; - g_uiChecksumIndex = 0; - - g_file_fd = open("/dev/firmware_cpld_ispvme0", O_RDWR); - if (g_file_fd < 0) { - printf("can't open device\r\n"); - return -1; - } - - vme_out_string(" Lattice Semiconductor Corp.\n"); - vme_out_string("\n ispVME(tm) V"); - vme_out_string(VME_VERSION_NUMBER); - vme_out_string(" Copyright 1998-2011.\n"); - vme_out_string("\nFor daisy chain programming of all in-system programmable devices\n\n"); - - if (argc < 2) { - vme_out_string("\nUsage: vme [option] vme_file [vme_file]\n"); - vme_out_string("Example: vme vme_file1.vme vme_file2.vme\n"); - vme_out_string("option -c: do the calibration.\n"); - vme_out_string("Example: vme -c\n"); - vme_out_string("Example: vme -c vme_file1.vme vme_file2.vme\n"); - vme_out_string("\n\n"); - close(g_file_fd); - return -1; /* Used by superiors to judge whether the upgrade is successful */ - //exit(1); - } - for (iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++) { - strcpy(szCommandLineArg, argv[iCommandLineIndex]); - if (!strcmp(strlwr(szCommandLineArg), "-c") && (iCommandLineIndex == 1)) { - sicalibrate = 1; - } else if (!strcmp(strlwr(szCommandLineArg), "-c") && (iCommandLineIndex != 1)) { - vme_out_string("Error: calibrate option -c must be the first argument\n\n"); - close(g_file_fd); - return -1; /* Used by superiors to judge whether the upgrade is successful */ - //exit(1); - } else { - strcpy(szExtension, &szCommandLineArg[strlen(szCommandLineArg) - 4]); - strlwr(szExtension); - if (strcmp(szExtension, ".vme")) { - vme_out_string("Error: VME files must end with the extension *.vme\n\n"); - close(g_file_fd); - return -1; /* Used by superiors to judge whether the upgrade is successful */ - //exit(1); - } - } - } - siRetCode = 0; - - if (sicalibrate) { - calibration(); - } - for (iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++) { /* Process all VME files sequentially */ - strcpy(szCommandLineArg, argv[iCommandLineIndex]); - if (!strcmp(strlwr(szCommandLineArg), "-c") && (iCommandLineIndex == 1)) { - - } else if (!strcmp(strlwr(szCommandLineArg), "-checksum")) { - - } else { - vme_out_string("Processing virtual machine file ("); - vme_out_string(szCommandLineArg); - vme_out_string(")......\n\n"); - siRetCode = ispVM(szCommandLineArg); - if (siRetCode < 0) { - break; - } - } - } - - if (siRetCode < 0) { - error_handler(siRetCode, szCommandLineArg); - vme_out_string("Failed due to "); - vme_out_string(szCommandLineArg); - vme_out_string("\n\n"); - vme_out_string("+=======+\n"); - vme_out_string("| FAIL! |\n"); - vme_out_string("+=======+\n\n"); - } else { - vme_out_string("+=======+\n"); - vme_out_string("| PASS! |\n"); - vme_out_string("+=======+\n\n"); - /* 08/28/08 NN Added Calculate checksum support. */ - if (g_usChecksum != 0) { - g_usChecksum &= 0xFFFF; - printf("Data Checksum: %.4X\n\n", (unsigned int)g_usChecksum); - g_usChecksum = 0; - } - } - close(g_file_fd); - return siRetCode; /* Used by superiors to judge whether the upgrade is successful */ - //exit(siRetCode); -} - -/** -* function:CPLD online upgrade channel test program -* input parameters: None -* output parameters:None -* return: 0 means test successfully -1 means test failed -*/ -int ispvme_test(void) -{ - int ret = 0; - unsigned char index = 0; - unsigned char indata = 0,outdata = 0; - unsigned char datasize = 8; - unsigned int tmpdata = 0; - char curbit = 0; - int nDevices = 0; - - g_file_fd = open("/dev/firmware_cpld_ispvme0", O_RDWR); - if (g_file_fd < 0) { - printf("can't open device\r\n"); - return -1; - } - - /* go to Shift-IR */ - ispVMStart(); - ispVMStateMachine(IDLE); - ispVMStateMachine(IRPAUSE); - ispVMStateMachine(SHIFTIR); - - /* Send plenty of ones into the IR registers,that makes sure all devices are in BYPASS! */ - for (index = 0; index < 100; index++) { - writePort(JTAG_TDI, 1); - sclock(); - } - - /* exit Shift-IR,and go to Shift-DR */ - ispVMStateMachine(IRPAUSE); - ispVMStateMachine(DRPAUSE); - ispVMStateMachine(SHIFTDR); - - /* Send plenty of zeros into the DR registers to flush them */ - for (index = 0; index < 100; index++) { - writePort(JTAG_TDI, 0); - sclock(); - } - - /* now send ones until we receive one back,to find out number of device(s) */ - for(index = 0; index < 100; index++){ - writePort(JTAG_TDI, 1); - sclock(); - curbit = readPort(); - if(1 == curbit){ - nDevices = index + 1; - break; - } - } - - /*flush again */ - for (index = 0; index < 100; index++) { - writePort(JTAG_TDI, 0); - sclock(); - } - - /* test data probe */ - indata = 0x5a; - for (index = 0; index < datasize + nDevices; index++) { - tmpdata <<= 1; - curbit = readPort(); - tmpdata |= curbit; - writePort(JTAG_TDI, ((indata << index) & 0x80) ? 0x01:0x00); - sclock(); - } - outdata = (tmpdata & 0xFF); - if(outdata != indata){ - ret = -1; - } - - /* go to Test-Logic-Reset */ - ispVMStateMachine(IDLE); - ispVMStart(); - - /* close ispvme */ - close(g_file_fd); - return ret; -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/ivm_core.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/ivm_core.c deleted file mode 100644 index 7d4f0ba137..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/ivm_core.c +++ /dev/null @@ -1,3033 +0,0 @@ -/*************************************************************** -* -* Lattice Semiconductor Corp. Copyright 2009 -* -* ispVME Embedded allows programming of Lattice's suite of FPGA -* devices on embedded systems through the JTAG port. The software -* is distributed in source code form and is open to re - distribution -* and modification where applicable. -* -* Revision History of ivm_core.c module: -* 4/25/06 ht Change some variables from unsigned short or int -* to long int to make the code compiler independent. -* 5/24/06 ht Support using RESET (TRST) pin as a special purpose -* control pin such as triggering the loading of known -* state exit. -* 3/6/07 ht added functions to support output to terminals -* -* 09/24/07 NN Type cast mismatch variables -* Moved the sclock() function to hardware.c -* 08/28/08 NN Added Calculate checksum support. -* 4/1/09 Nguyen replaced the recursive function call codes on -* the ispVMLCOUNT function -* -***************************************************************/ - -#include -#include -#include "vmopcode.h" -#include "common.h" - -/*************************************************************** -* -* Global variables used to specify the flow control and data type. -* -* g_usFlowControl: flow control register. Each bit in the -* register can potentially change the -* personality of the embedded engine. -* g_usDataType: holds the data type of the current row. -* -***************************************************************/ - -unsigned short g_usFlowControl = 0x0000; -unsigned short g_usDataType = 0x0000; - -/*************************************************************** -* -* Global variables used to specify the ENDDR and ENDIR. -* -* g_ucEndDR: the state that the device goes to after SDR. -* g_ucEndIR: the state that the device goes to after SIR. -* -***************************************************************/ - -unsigned char g_ucEndDR = DRPAUSE; -unsigned char g_ucEndIR = IRPAUSE; - -/*************************************************************** -* -* Global variables used to support header/trailer. -* -* g_usHeadDR: the number of lead devices in bypass. -* g_usHeadIR: the sum of IR length of lead devices. -* g_usTailDR: the number of tail devices in bypass. -* g_usTailIR: the sum of IR length of tail devices. -* -***************************************************************/ - -unsigned short g_usHeadDR = 0; -unsigned short g_usHeadIR = 0; -unsigned short g_usTailDR = 0; -unsigned short g_usTailIR = 0; - -/*************************************************************** -* -* Global variable to store the number of bits of data or instruction -* to be shifted into or out from the device. -* -***************************************************************/ - -unsigned short g_usiDataSize = 0; - -/*************************************************************** -* -* Stores the frequency. Default to 1 MHz. -* -***************************************************************/ - -int g_iFrequency = 1000; - -/*************************************************************** -* -* Stores the maximum amount of ram needed to hold a row of data. -* -***************************************************************/ - -unsigned short g_usMaxSize = 0; - -/*************************************************************** -* -* Stores the LSH or RSH value. -* -***************************************************************/ - -unsigned short g_usShiftValue = 0; - -/*************************************************************** -* -* Stores the current repeat loop value. -* -***************************************************************/ - -unsigned short g_usRepeatLoops = 0; - -/*************************************************************** -* -* Stores the current vendor. -* -***************************************************************/ - -signed char g_cVendor = LATTICE; - -/*************************************************************** -* -* Stores the VME file CRC. -* -***************************************************************/ - -unsigned short g_usCalculatedCRC = 0; - -/*************************************************************** -* -* Stores the Device Checksum. -* -***************************************************************/ -//08/28/08 NN Added Calculate checksum support. -unsigned long g_usChecksum = 0; -unsigned int g_uiChecksumIndex = 0; - -/*************************************************************** -* -* Stores the current state of the JTAG state machine. -* -***************************************************************/ - -signed char g_cCurrentJTAGState = 0; - -/*************************************************************** -* -* Global variables used to support looping. -* -* g_pucHeapMemory: holds the entire repeat loop. -* g_iHeapCounter: points to the current byte in the repeat loop. -* g_iHEAPSize: the current size of the repeat in bytes. -* -***************************************************************/ - -unsigned char *g_pucHeapMemory = NULL; -unsigned short g_iHeapCounter = 0; -unsigned short g_iHEAPSize = 0; - -/*************************************************************** -* -* Global variables used to support intelligent programming. -* -* g_usIntelDataIndex: points to the current byte of the -* intelligent buffer. -* g_usIntelBufferSize: holds the size of the intelligent -* buffer. -* -***************************************************************/ - -unsigned short g_usIntelDataIndex = 0; -unsigned short g_usIntelBufferSize = 0; - -/**************************************************************************** -* -* Holds the maximum size of each respective buffer. These variables are used -* to write the HEX files when converting VME to HEX. -* -*****************************************************************************/ - -unsigned short g_usTDOSize = 0; -unsigned short g_usMASKSize = 0; -unsigned short g_usTDISize = 0; -unsigned short g_usDMASKSize = 0; -unsigned short g_usLCOUNTSize = 0; -unsigned short g_usHDRSize = 0; -unsigned short g_usTDRSize = 0; -unsigned short g_usHIRSize = 0; -unsigned short g_usTIRSize = 0; -unsigned short g_usHeapSize = 0; - -/*************************************************************** -* -* Global variables used to store data. -* -* g_pucOutMaskData: local RAM to hold one row of MASK data. -* g_pucInData: local RAM to hold one row of TDI data. -* g_pucOutData: local RAM to hold one row of TDO data. -* g_pucHIRData: local RAM to hold the current SIR header. -* g_pucTIRData: local RAM to hold the current SIR trailer. -* g_pucHDRData: local RAM to hold the current SDR header. -* g_pucTDRData: local RAM to hold the current SDR trailer. -* g_pucIntelBuffer: local RAM to hold the current intelligent buffer. -* g_pucOutDMaskData: local RAM to hold one row of DMASK data. -* -***************************************************************/ - -unsigned char *g_pucOutMaskData = NULL, -*g_pucInData = NULL, -*g_pucOutData = NULL, -*g_pucHIRData = NULL, -*g_pucTIRData = NULL, -*g_pucHDRData = NULL, -*g_pucTDRData = NULL, -*g_pucIntelBuffer = NULL, -*g_pucOutDMaskData = NULL; - -/*************************************************************** -* -* JTAG state machine transition table. -* -***************************************************************/ - -struct { - unsigned char CurState; /* From this state */ - unsigned char NextState; /* Step to this state */ - unsigned char Pattern; /* The tragetory of TMS */ - unsigned char Pulses; /* The number of steps */ -} g_JTAGTransistions[25] = { - { RESET, RESET, 0xFC, 6 }, /* Transitions from RESET */ - { RESET, IDLE, 0x00, 1 }, - { RESET, DRPAUSE, 0x50, 5 }, - { RESET, IRPAUSE, 0x68, 6 }, - { IDLE, RESET, 0xE0, 3 }, /* Transitions from IDLE */ - { IDLE, DRPAUSE, 0xA0, 4 }, - { IDLE, IRPAUSE, 0xD0, 5 }, - { DRPAUSE, RESET, 0xF8, 5 }, /* Transitions from DRPAUSE */ - { DRPAUSE, IDLE, 0xC0, 3 }, - { DRPAUSE, IRPAUSE, 0xF4, 7 }, - { DRPAUSE, DRPAUSE, 0xE8, 6 }, /* 06/14/06 Support POLING STATUS LOOP*/ - { IRPAUSE, RESET, 0xF8, 5 }, /* Transitions from IRPAUSE */ - { IRPAUSE, IDLE, 0xC0, 3 }, - { IRPAUSE, DRPAUSE, 0xE8, 6 }, - { DRPAUSE, SHIFTDR, 0x80, 2 }, /* Extra transitions using SHIFTDR */ - { IRPAUSE, SHIFTDR, 0xE0, 5 }, - { SHIFTDR, DRPAUSE, 0x80, 2 }, - { SHIFTDR, IDLE, 0xC0, 3 }, - { IRPAUSE, SHIFTIR, 0x80, 2 }, /* Extra transitions using SHIFTIR */ - { SHIFTIR, IRPAUSE, 0x80, 2 }, - { SHIFTIR, IDLE, 0xC0, 3 }, - { DRPAUSE, DRCAPTURE, 0xE0, 4 }, /* 11/15/05 Support DRCAPTURE*/ - { DRCAPTURE, DRPAUSE, 0x80, 2 }, - { IDLE, DRCAPTURE, 0x80, 2 }, - { IRPAUSE, DRCAPTURE, 0xE0, 4 } -}; - -/*************************************************************** -* -* List to hold all LVDS pairs. -* -***************************************************************/ - -LVDSPair *g_pLVDSList = NULL; -unsigned short g_usLVDSPairCount = 0; - -/*************************************************************** -* -* Function prototypes. -* -***************************************************************/ - -signed char ispVMCode(); -signed char ispVMDataCode(); -long int ispVMDataSize(); -void ispVMData(unsigned char *Data); -signed char ispVMShift(signed char Code); -signed char ispVMAmble(signed char Code); -signed char ispVMLoop(unsigned short a_usLoopCount); -signed char ispVMBitShift(signed char mode, unsigned short bits); -void ispVMComment(unsigned short a_usCommentSize); -void ispVMHeader(unsigned short a_usHeaderSize); -signed char ispVMLCOUNT(unsigned short a_usCountSize); -void ispVMClocks(unsigned short Clocks); -void ispVMBypass(signed char ScanType, unsigned short Bits); -void ispVMStateMachine(signed char NextState); -void ispVMStart(); -void ispVMEnd(); -signed char ispVMSend(unsigned short int); -signed char ispVMRead(unsigned short int); -signed char ispVMReadandSave(unsigned short int); -signed char ispVMProcessLVDS(unsigned short a_usLVDSCount); - -/*************************************************************** -* -* External variables and functions in ispvm_ui.c module -* -***************************************************************/ -extern void vme_out_char(unsigned char charOut); -extern void vme_out_hex(unsigned char hexOut); -extern void vme_out_string(char *stringOut); -extern unsigned char GetByte(); -extern void ispVMMemManager(signed char types, unsigned short size); - -/*************************************************************** -* -* External variables and functions in hardware.c module -* -***************************************************************/ -extern void ispVMDelay(unsigned short int a_usMicroSecondDelay); -extern unsigned char readPort(); -extern void writePort(unsigned char pins, unsigned char value); -extern void sclock(); -extern signed char g_cCurrentJTAGState; -#ifdef VME_DEBUG - -/*************************************************************** -* -* GetState -* -* Returns the state as a string based on the opcode. Only used -* for debugging purposes. -* -***************************************************************/ - -const char* GetState(unsigned char a_ucState) -{ - switch (a_ucState) { - case RESET: - return ("RESET"); - case IDLE: - return ("IDLE"); - case IRPAUSE: - return ("IRPAUSE"); - case DRPAUSE: - return ("DRPAUSE"); - case SHIFTIR: - return ("SHIFTIR"); - case SHIFTDR: - return ("SHIFTDR"); - case DRCAPTURE: /* 11/15/05 support DRCAPTURE*/ - return ("DRCAPTURE"); - default: - break; - } - - return 0; -} - -/*************************************************************** -* -* PrintData -* -* Prints the data. Only used for debugging purposes. -* -***************************************************************/ - -void PrintData(unsigned short a_iDataSize, unsigned char *a_pucData) -{ - //09/11/07 NN added local variables initialization - unsigned short usByteSize = 0; - unsigned short usBitIndex = 0; - signed short usByteIndex = 0; - unsigned char ucByte = 0; - unsigned char ucFlipByte = 0; - - if (a_iDataSize % 8) { - //09/11/07 NN Type cast mismatch variables - usByteSize = (unsigned short)(a_iDataSize / 8 + 1); - } else { - //09/11/07 NN Type cast mismatch variables - usByteSize = (unsigned short)(a_iDataSize / 8);// 4 - } - printf("("); - //09/11/07 NN Type cast mismatch variables - for (usByteIndex = (signed short)(usByteSize - 1); usByteIndex >= 0; usByteIndex--) { - ucByte = a_pucData[usByteIndex]; - ucFlipByte = 0x00; - - /*************************************************************** - * - * Flip each byte. - * - ***************************************************************/ - - for (usBitIndex = 0; usBitIndex < 8; usBitIndex++) { - ucFlipByte <<= 1; - if (ucByte & 0x1) { - ucFlipByte |= 0x1; - } - - ucByte >>= 1; - } - - /*************************************************************** - * - * Print the flipped byte. - * - ***************************************************************/ - - printf("%.02X", ucFlipByte); - if ((usByteSize - usByteIndex) % 40 == 39) { - printf("\n\t\t"); - } - if (usByteIndex < 0) - break; - } - printf(")"); -} -#endif /* VME_DEBUG */ - -/*************************************************************** -* -* ispVMDataSize -* -* Returns a VME-encoded number, usually used to indicate the -* bit length of an SIR/SDR command. -* -***************************************************************/ - -long int ispVMDataSize() -{ - /* 09/11/07 NN added local variables initialization */ - long int iSize = 0; - signed char cCurrentByte = 0; - signed char cIndex = 0; - cIndex = 0; - - while ((cCurrentByte = GetByte()) & 0x80) { - iSize |= ((long int)(cCurrentByte & 0x7F)) << cIndex; - cIndex += 7; - } - iSize |= ((long int)(cCurrentByte & 0x7F)) << cIndex; - - return iSize; -} - -/*************************************************************** -* -* ispVMCode -* -* This is the heart of the embedded engine. All the high-level opcodes -* are extracted here. Once they have been identified, then it -* will call other functions to handle the processing. -* -***************************************************************/ - -signed char ispVMCode() -{ - /* 09/11/07 NN added local variables initialization */ - unsigned short iRepeatSize = 0; - signed char cOpcode = 0; - signed char cRetCode = 0; - unsigned char ucState = 0; - unsigned short usDelay = 0; - unsigned short usToggle = 0; - unsigned char usByte = 0; - - /*************************************************************** - * - * Check the compression flag only if this is the first time - * this function is entered. Do not check the compression flag if - * it is being called recursively from other functions within - * the embedded engine. - * - ***************************************************************/ - - if (!(g_usDataType & LHEAP_IN) && !(g_usDataType & HEAP_IN)) { - usByte = GetByte(); - if (usByte == 0xf1) { - g_usDataType |= COMPRESS; - } else if (usByte == 0xf2) { - g_usDataType &= ~COMPRESS; - } else { - return VME_INVALID_FILE; - } - } - - - /*************************************************************** - * - * Begin looping through all the VME opcodes. - * - ***************************************************************/ - while ((cOpcode = GetByte()) >= 0) { - switch (cOpcode) { - case STATE: - - /*************************************************************** - * - * Step the JTAG state machine. - * - ***************************************************************/ - - ucState = GetByte(); - /*************************************************************** - * - * Step the JTAG state machine to DRCAPTURE to support Looping. - * - ***************************************************************/ - - if ((g_usDataType & LHEAP_IN) && - (ucState == DRPAUSE) && - (g_cCurrentJTAGState == ucState)) { - ispVMStateMachine(DRCAPTURE); - } - - ispVMStateMachine(ucState); - -#ifdef VME_DEBUG - if (g_usDataType & LHEAP_IN) { - printf("LDELAY %s ", GetState(ucState)); - } else { - printf("STATE %s;\n", GetState(ucState)); - } -#endif /* VME_DEBUG */ - break; - case SIR: - case SDR: - case XSDR: - -#ifdef VME_DEBUG - switch (cOpcode) { - case SIR: - printf("SIR "); - break; - case SDR: - case XSDR: - if (g_usDataType & LHEAP_IN) { - printf("LSDR "); - } else { - printf("SDR "); - } - break; - } -#endif /* VME_DEBUG */ - /*************************************************************** - * - * Shift in data into the device. - * - ***************************************************************/ - cRetCode = ispVMShift(cOpcode); - if (cRetCode != 0) { - return (cRetCode); - } - break; - case WAIT: - - /*************************************************************** - * - * Observe delay. - * - ***************************************************************/ - - /* 9/11/07 NN Type cast mismatch variables */ - usDelay = (unsigned short)ispVMDataSize(); - ispVMDelay(usDelay); - -#ifdef VME_DEBUG - if (usDelay & 0x8000) { - - /*************************************************************** - * - * Since MSB is set, the delay time must be decoded to - * millisecond. The SVF2VME encodes the MSB to represent - * millisecond. - * - ***************************************************************/ - - usDelay &= ~0x8000; - if (g_usDataType & LHEAP_IN) { - printf("%.2E SEC;\n", (float)usDelay / 1000); - } else { - printf("RUNTEST %.2E SEC;\n", (float)usDelay / 1000); - } - } else { - - /*************************************************************** - * - * Since MSB is not set, the delay time is given as microseconds. - * - ***************************************************************/ - - if (g_usDataType & LHEAP_IN) { - printf("%.2E SEC;\n", (float)usDelay / 1000000); - } else { - printf("RUNTEST %.2E SEC;\n", (float)usDelay / 1000000); - } - } -#endif /* VME_DEBUG */ - break; - case TCK: - - /*************************************************************** - * - * Issue clock toggles. - * - ***************************************************************/ - - /* 09/11/07 NN Type cast mismatch variables */ - usToggle = (unsigned short)ispVMDataSize(); - ispVMClocks(usToggle); - -#ifdef VME_DEBUG - printf("RUNTEST %d TCK;\n", usToggle); -#endif /* VME_DEBUG */ - break; - case ENDDR: - - /*************************************************************** - * - * Set the ENDDR. - * - ***************************************************************/ - - g_ucEndDR = GetByte(); - -#ifdef VME_DEBUG - printf("ENDDR %s;\n", GetState(g_ucEndDR)); -#endif /* VME_DEBUG */ - break; - case ENDIR: - - /*************************************************************** - * - * Set the ENDIR. - * - ***************************************************************/ - - g_ucEndIR = GetByte(); - -#ifdef VME_DEBUG - printf("ENDIR %s;\n", GetState(g_ucEndIR)); -#endif /* VME_DEBUG */ - break; - case HIR: - case TIR: - case HDR: - case TDR: - -#ifdef VME_DEBUG - switch (cOpcode) { - case HIR: - printf("HIR "); - break; - case TIR: - printf("TIR "); - break; - case HDR: - printf("HDR "); - break; - case TDR: - printf("TDR "); - break; - } -#endif /* VME_DEBUG */ - - /*************************************************************** - * - * Set the header/trailer of the device in order to bypass - * successfully. - * - ***************************************************************/ - - cRetCode = ispVMAmble(cOpcode); - if (cRetCode != 0) { - return (cRetCode); - } - -#ifdef VME_DEBUG - printf(";\n"); -#endif /* VME_DEBUG */ - break; - case MEM: - - /*************************************************************** - * - * The maximum RAM required to support processing one row of the - * VME file. - * - ***************************************************************/ - - //09/11/07 NN Type cast mismatch variables - g_usMaxSize = (unsigned short)ispVMDataSize(); - -#ifdef VME_DEBUG - printf("// MEMSIZE %d\n", g_usMaxSize); -#endif /* VME_DEBUG */ - break; - case VENDOR: - - /*************************************************************** - * - * Set the VENDOR type. - * - ***************************************************************/ - - cOpcode = GetByte(); - switch (cOpcode) { - case LATTICE: -#ifdef VME_DEBUG - printf("// VENDOR LATTICE\n"); -#endif /* VME_DEBUG */ - g_cVendor = LATTICE; - break; - case ALTERA: -#ifdef VME_DEBUG - printf("// VENDOR ALTERA\n"); -#endif /* VME_DEBUG */ - g_cVendor = ALTERA; - break; - case XILINX: -#ifdef VME_DEBUG - printf("// VENDOR XILINX\n"); -#endif /* VME_DEBUG */ - g_cVendor = XILINX; - break; - default: - break; - } - break; - case SETFLOW: - - /*************************************************************** - * - * Set the flow control. Flow control determines the personality - * of the embedded engine. - * - ***************************************************************/ - - /* 09/11/07 NN Type cast mismatch variables */ - g_usFlowControl |= (unsigned short)ispVMDataSize(); - break; - case RESETFLOW: - - /*************************************************************** - * - * Unset the flow control. - * - ***************************************************************/ - - /* 09/11/07 NN Type cast mismatch variables */ - g_usFlowControl &= (unsigned short)~(ispVMDataSize()); - break; - case HEAP: - - /*************************************************************** - * - * Allocate heap size to store loops. - * - ***************************************************************/ - - cRetCode = GetByte(); - if (cRetCode != SECUREHEAP) { - return VME_INVALID_FILE; - } - /* 09/11/07 NN Type cast mismatch variables */ - g_iHEAPSize = (unsigned short)ispVMDataSize(); - - /**************************************************************************** - * - * Store the maximum size of the HEAP buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_iHEAPSize > g_usHeapSize) { - g_usHeapSize = g_iHEAPSize; - } - - ispVMMemManager(HEAP, (unsigned short)g_iHEAPSize); - break; - case REPEAT: - - /*************************************************************** - * - * Execute loops. - * - ***************************************************************/ - - g_usRepeatLoops = 0; - - /* 09/11/07 NN Type cast mismatch variables */ - iRepeatSize = (unsigned short)ispVMDataSize(); - - cRetCode = ispVMLoop((unsigned short)iRepeatSize); - if (cRetCode != 0) { - return (cRetCode); - } - break; - case ENDLOOP: - - /*************************************************************** - * - * Exit point from processing loops. - * - ***************************************************************/ - - return (cRetCode); - case ENDVME: - - /*************************************************************** - * - * The only valid exit point that indicates end of programming. - * - ***************************************************************/ - - return (cRetCode); - case SHR: - - /*************************************************************** - * - * Right-shift address. - * - ***************************************************************/ - - g_usFlowControl |= SHIFTRIGHT; - - /* 09/11/07 NN Type cast mismatch variables */ - g_usShiftValue = (unsigned short)(g_usRepeatLoops * (unsigned short)GetByte()); - break; - case SHL: - - /*************************************************************** - * - * Left-shift address. - * - ***************************************************************/ - - g_usFlowControl |= SHIFTLEFT; - - /* 09/11/07 NN Type cast mismatch variables */ - g_usShiftValue = (unsigned short)(g_usRepeatLoops * (unsigned short)GetByte()); - break; - case FREQUENCY: - - /*************************************************************** - * - * Set the frequency. - * - ***************************************************************/ - - /* 09/11/07 NN Type cast mismatch variables */ - g_iFrequency = (int)(ispVMDataSize()); - /* 10/23/08 NN changed to check if the frequency smaller than 1000 */ - if (g_iFrequency >= 1000) { - g_iFrequency = g_iFrequency / 1000; - if (g_iFrequency == 1) - g_iFrequency = 1000; -#ifdef VME_DEBUG - printf("FREQUENCY %.2E HZ;\n", (float)g_iFrequency * 1000); -#endif /* VME_DEBUG */ - } else { - if (g_iFrequency == 0) - g_iFrequency = 1000; -#ifdef VME_DEBUG - printf("FREQUENCY %.2E HZ;\n", (float)g_iFrequency); -#endif /* VME_DEBUG */ - } - break; - case LCOUNT: - - /*************************************************************** - * - * Process LCOUNT command. - * - ***************************************************************/ - - cRetCode = ispVMLCOUNT((unsigned short)ispVMDataSize()); - if (cRetCode != 0) { - return (cRetCode); - } - break; - case VUES: - - /*************************************************************** - * - * Set the flow control to verify USERCODE. - * - ***************************************************************/ - - g_usFlowControl |= VERIFYUES; - break; - case COMMENT: - - /*************************************************************** - * - * Display comment. - * - ***************************************************************/ - - ispVMComment((unsigned short)ispVMDataSize()); - break; - case LVDS: - - /*************************************************************** - * - * Process LVDS command. - * - ***************************************************************/ - - ispVMProcessLVDS((unsigned short)ispVMDataSize()); - break; - case HEADER: - - /*************************************************************** - * - * Discard header. - * - ***************************************************************/ - - ispVMHeader((unsigned short)ispVMDataSize()); - break; - /* 03/14/06 Support Toggle ispENABLE signal */ - case ispEN: - ucState = GetByte(); - if ((ucState == ON) || (ucState == 0x01)) - writePort(JTAG_ENABLE, 0x01); - else - writePort(JTAG_ENABLE, 0x00); - ispVMDelay(1); - break; - /* 05/24/06 support Toggle TRST pin */ - case TRST: - ucState = GetByte(); - if (ucState == 0x01) - writePort(JTAG_TRST, 0x01); - else - writePort(JTAG_TRST, 0x00); - ispVMDelay(1); - break; - default: - - /*************************************************************** - * - * Invalid opcode encountered. - * - ***************************************************************/ - -#ifdef VME_DEBUG - printf("\nINVALID OPCODE: 0x%.2X\n", cOpcode); -#endif /* VME_DEBUG */ - - return VME_INVALID_FILE; - } - } - - /*************************************************************** - * - * Invalid exit point. Processing the token 'ENDVME' is the only - * valid way to exit the embedded engine. - * - ***************************************************************/ - - return (VME_INVALID_FILE); -} - -/*************************************************************** -* -* ispVMDataCode -* -* Processes the TDI/TDO/MASK/DMASK etc of an SIR/SDR command. -* -***************************************************************/ - -signed char ispVMDataCode() -{ - /* 09/11/07 NN added local variables initialization */ - signed char cDataByte = 0; - signed char siDataSource = 0; /* source of data from file by default */ - - if (g_usDataType & HEAP_IN) { - siDataSource = 1; /* the source of data from memory */ - } - - /**************************************************************************** - * - * Clear the data type register. - * - *****************************************************************************/ - - g_usDataType &= ~(MASK_DATA + TDI_DATA + TDO_DATA + DMASK_DATA + CMASK_DATA); - - /**************************************************************************** - * - * Iterate through SIR/SDR command and look for TDI, TDO, MASK, etc. - * - *****************************************************************************/ - - while ((cDataByte = GetByte()) >= 0) { - - ispVMMemManager(cDataByte, g_usMaxSize); - switch (cDataByte) { - case TDI: - - /**************************************************************************** - * - * Store the maximum size of the TDI buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usiDataSize > g_usTDISize) { - g_usTDISize = g_usiDataSize; - } - /**************************************************************************** - * - * Updated data type register to indicate that TDI data is currently being - * used. Process the data in the VME file into the TDI buffer. - * - *****************************************************************************/ - - g_usDataType |= TDI_DATA; - ispVMData(g_pucInData); - break; - case XTDO: - - /**************************************************************************** - * - * Store the maximum size of the TDO buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usiDataSize > g_usTDOSize) { - g_usTDOSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Updated data type register to indicate that TDO data is currently being - * used. - * - *****************************************************************************/ - - g_usDataType |= TDO_DATA; - break; - case TDO: - - /**************************************************************************** - * - * Store the maximum size of the TDO buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usiDataSize > g_usTDOSize) { - g_usTDOSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Updated data type register to indicate that TDO data is currently being - * used. Process the data in the VME file into the TDO buffer. - * - *****************************************************************************/ - - g_usDataType |= TDO_DATA; - ispVMData(g_pucOutData); - break; - case MASK: - - /**************************************************************************** - * - * Store the maximum size of the MASK buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usiDataSize > g_usMASKSize) { - g_usMASKSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Updated data type register to indicate that MASK data is currently being - * used. Process the data in the VME file into the MASK buffer. - * - *****************************************************************************/ - - g_usDataType |= MASK_DATA; - ispVMData(g_pucOutMaskData); - break; - case DMASK: - - /**************************************************************************** - * - * Store the maximum size of the DMASK buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usiDataSize > g_usDMASKSize) { - g_usDMASKSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Updated data type register to indicate that DMASK data is currently being - * used. Process the data in the VME file into the DMASK buffer. - * - *****************************************************************************/ - - g_usDataType |= DMASK_DATA; - ispVMData(g_pucOutDMaskData); - break; - case CMASK: - - /**************************************************************************** - * - * Updated data type register to indicate that CMASK data is currently being - * used. Process the data in the VME file into the CMASK buffer. - * - *****************************************************************************/ - - g_usDataType |= CMASK_DATA; - ispVMData(g_pucOutMaskData); - break; - case CONTINUE: - return (0); - default: - - /**************************************************************************** - * - * Encountered invalid opcode. - * - *****************************************************************************/ - - return (VME_INVALID_FILE); - } - - switch (cDataByte) { - case TDI: - - /**************************************************************************** - * - * Left bit shift. Used when performing algorithm looping. - * - *****************************************************************************/ - - if (g_usFlowControl & SHIFTLEFT) { - ispVMBitShift(SHL, g_usShiftValue); - g_usFlowControl &= ~SHIFTLEFT; - } - - /**************************************************************************** - * - * Right bit shift. Used when performing algorithm looping. - * - *****************************************************************************/ - - if (g_usFlowControl & SHIFTRIGHT) { - ispVMBitShift(SHR, g_usShiftValue); - g_usFlowControl &= ~SHIFTRIGHT; - } - default: - break; - } - - if (siDataSource) { - g_usDataType |= HEAP_IN; /*restore data from memory*/ - } - } - - if (siDataSource) { /*fetch data from heap memory upon return*/ - g_usDataType |= HEAP_IN; - } - - if (cDataByte < 0) { - - /**************************************************************************** - * - * Encountered invalid opcode. - * - *****************************************************************************/ - - return (VME_INVALID_FILE); - } else { - return (0); - } -} - -/*************************************************************** -* -* ispVMData -* Extract one row of data operand from the current data type opcode. Perform -* the decompression if necessary. Extra RAM is not required for the -* decompression process. The decompression scheme employed in this module -* is on row by row basis. The format of the data stream: -* [compression code][compressed data stream] -* 0x00 --No compression -* 0x01 --Compress by 0x00. -* Example: -* Original stream: 0x000000000000000000000001 -* Compressed stream: 0x01000901 -* Detail: 0x01 is the code, 0x00 is the key, -* 0x09 is the count of 0x00 bytes, -* 0x01 is the uncompressed byte. -* 0x02 --Compress by 0xFF. -* Example: -* Original stream: 0xFFFFFFFFFFFFFFFFFFFFFF01 -* Compressed stream: 0x02FF0901 -* Detail: 0x02 is the code, 0xFF is the key, -* 0x09 is the count of 0xFF bytes, -* 0x01 is the uncompressed byte. -* 0x03 -* : : -* 0xFE -- Compress by nibble blocks. -* Example: -* Original stream: 0x84210842108421084210 -* Compressed stream: 0x0584210 -* Detail: 0x05 is the code, means 5 nibbles block. -* 0x84210 is the 5 nibble blocks. -* The whole row is 80 bits given by g_usiDataSize. -* The number of times the block repeat itself -* is found by g_usiDataSize/(4*0x05) which is 4. -* 0xFF -- Compress by the most frequently happen byte. -* Example: -* Original stream: 0x04020401030904040404 -* Compressed stream: 0xFF04(0,1,0x02,0,1,0x01,1,0x03,1,0x09,0,0,0) -* or: 0xFF044090181C240 -* Detail: 0xFF is the code, 0x04 is the key. -* a bit of 0 represent the key shall be put into -* the current bit position and a bit of 1 -* represent copying the next of 8 bits of data -* in. -* -***************************************************************/ - -void ispVMData(unsigned char *ByteData) -{ - /* 09/11/07 NN added local variables initialization */ - unsigned short size = 0; - unsigned short i, j, m, getData = 0; - unsigned char cDataByte = 0; - unsigned char compress = 0; - unsigned short FFcount = 0; - unsigned char compr_char = 0xFF; - unsigned short index = 0; - signed char compression = 0; - - /* convert number in bits to bytes */ - if (g_usiDataSize % 8 > 0) { - /* 09/11/07 NN Type cast mismatch variables */ - size = (unsigned short)(g_usiDataSize / 8 + 1); - } else { - /* 09/11/07 NN Type cast mismatch variables */ - size = (unsigned short)(g_usiDataSize / 8); - } - - /* If there is compression, then check if compress by key of 0x00 or 0xFF - or by other keys or by nibble blocks*/ - - if (g_usDataType & COMPRESS) { - compression = 1; - if (((compress = GetByte()) == VAR) && (g_usDataType & HEAP_IN)) { - getData = 1; - g_usDataType &= ~(HEAP_IN); - compress = GetByte(); - } - - switch (compress) { - case 0x00: - /* No compression */ - compression = 0; - break; - case 0x01: - /* Compress by byte 0x00 */ - compr_char = 0x00; - break; - case 0x02: - /* Compress by byte 0xFF */ - compr_char = 0xFF; - break; - case 0xFF: - /* Huffman encoding */ - compr_char = GetByte(); - i = 8; - for (index = 0; index < size; index++) { - ByteData[index] = 0x00; - if (i > 7) { - cDataByte = GetByte(); - i = 0; - } - if ((cDataByte << i++) & 0x80) - m = 8; - else { - ByteData[index] = compr_char; - m = 0; - } - - for (j = 0; j < m; j++) { - if (i > 7) { - cDataByte = GetByte(); - i = 0; - } - ByteData[index] |= ((cDataByte << i++) & 0x80) >> j; - } - } - size = 0; - break; - default: - for (index = 0; index < size; index++) - ByteData[index] = 0x00; - for (index = 0; index < compress; index++) { - if (index % 2 == 0) - cDataByte = GetByte(); - for (i = 0; i < size * 2 / compress; i++) { - /* 09/11/07 NN Type cast mismatch variables */ - j = (unsigned short)(index + (i * (unsigned short)compress)); - /* clear the nibble to zero first */ - if (j % 2) { - if (index % 2) - ByteData[j / 2] |= cDataByte & 0x0F; - else - ByteData[j / 2] |= cDataByte >> 4; - } else { - if (index % 2) - ByteData[j / 2] |= cDataByte << 4; - else - ByteData[j / 2] |= cDataByte & 0xF0; - } - } - } - size = 0; - break; - } - } - - FFcount = 0; - - /* Decompress by byte 0x00 or 0xFF */ - for (index = 0; index < size; index++) { - if (FFcount <= 0) { - cDataByte = GetByte(); - if ((cDataByte == VAR) && (g_usDataType & HEAP_IN) && !getData && !(g_usDataType & COMPRESS)) { - getData = 1; - g_usDataType &= ~(HEAP_IN); - cDataByte = GetByte(); - } - ByteData[index] = cDataByte; - if ((compression) && (cDataByte == compr_char)) /* decompression is on */ - /* 09/11/07 NN Type cast mismatch variables */ - FFcount = (unsigned short)ispVMDataSize(); /* The number of 0xFF or 0x00 bytes */ - } else { - FFcount--; /* Use up the 0xFF chain first */ - ByteData[index] = compr_char; - } - } - - if (getData) { - g_usDataType |= HEAP_IN; - getData = 0; - } -} - -/*************************************************************** -* -* ispVMShift -* -* Processes the SDR/XSDR/SIR commands. -* -***************************************************************/ - -signed char ispVMShift(signed char a_cCode) -{ - /* 09/11/07 NN added local variables initialization */ - unsigned short iDataIndex = 0; - unsigned short iReadLoop = 0; - signed char cRetCode = 0; - - cRetCode = 0; - /* 09/11/07 NN Type cast mismatch variables */ - g_usiDataSize = (unsigned short)ispVMDataSize(); - - g_usDataType &= ~(SIR_DATA + EXPRESS + SDR_DATA); /* clear the flags first */ - - switch (a_cCode) { - case SIR: - g_usDataType |= SIR_DATA; - /* 1/15/04 If performing cascading, then go directly to SHIFTIR. Else, - go to IRPAUSE before going to SHIFTIR */ - if (g_usFlowControl & CASCADE) { - ispVMStateMachine(SHIFTIR); - } else { - ispVMStateMachine(IRPAUSE); - ispVMStateMachine(SHIFTIR); - if (g_usHeadIR > 0) { - ispVMBypass(HIR, g_usHeadIR); - sclock(); - } - } - break; - case XSDR: - g_usDataType |= EXPRESS; /* mark simultaneous in and out */ - case SDR: - g_usDataType |= SDR_DATA; - /* 1/15/04 If already in SHIFTDR, then do not move state or shift in header. - This would imply that the previously shifted frame was a cascaded frame. */ - if (g_cCurrentJTAGState != SHIFTDR) { - /* 1/15/04 If performing cascading, then go directly to SHIFTDR. Else, - go to DRPAUSE before going to SHIFTDR */ - if (g_usFlowControl & CASCADE) { - if (g_cCurrentJTAGState == DRPAUSE) { - ispVMStateMachine(SHIFTDR); - /* 1/15/04 If cascade flag has been set and the current state is - DRPAUSE, this implies that the first cascaded frame is about to - be shifted in. The header must be shifted prior to shifting - the first cascaded frame. */ - if (g_usHeadDR > 0) { - ispVMBypass(HDR, g_usHeadDR); - sclock(); - } - } else { - ispVMStateMachine(SHIFTDR); - } - } else { - ispVMStateMachine(DRPAUSE); - ispVMStateMachine(SHIFTDR); - if (g_usHeadDR > 0) { - ispVMBypass(HDR, g_usHeadDR); - sclock(); - } - } - } - break; - default: - return (VME_INVALID_FILE); - } - - cRetCode = ispVMDataCode(); - if (cRetCode != 0) { - return (VME_INVALID_FILE); - } - -#ifdef VME_DEBUG - if (g_usDataType & TDI_DATA) { - printf("\n\t\tTDI "); - PrintData(g_usiDataSize, g_pucInData); - } - - if (g_usDataType & TDO_DATA) { - printf("\n\t\tTDO "); - PrintData(g_usiDataSize, g_pucOutData); - } - - if (g_usDataType & MASK_DATA) { - printf("\n\t\tMASK "); - PrintData(g_usiDataSize, g_pucOutMaskData); - } - - if (g_usDataType & DMASK_DATA) { - printf("\n\t\tDMASK "); - PrintData(g_usiDataSize, g_pucOutDMaskData); - } - - printf(";\n"); -#endif /* VME_DEBUG */ - if (g_usDataType & TDO_DATA || g_usDataType & DMASK_DATA) { - if (g_usDataType & DMASK_DATA) { - - cRetCode = ispVMReadandSave(g_usiDataSize); - - if (!cRetCode) { - if (g_usTailDR > 0) { - sclock(); - ispVMBypass(TDR, g_usTailDR); - } - ispVMStateMachine(DRPAUSE); - ispVMStateMachine(SHIFTDR); - if (g_usHeadDR > 0) { - ispVMBypass(HDR, g_usHeadDR); - sclock(); - } - for (iDataIndex = 0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++) - g_pucInData[iDataIndex] = g_pucOutData[iDataIndex]; - g_usDataType &= ~(TDO_DATA + DMASK_DATA); - cRetCode = ispVMSend(g_usiDataSize); - } - } else { - - cRetCode = ispVMRead(g_usiDataSize); - if (cRetCode == -1 && g_cVendor == XILINX) { - for (iReadLoop = 0; iReadLoop < 30; iReadLoop++) { - cRetCode = ispVMRead(g_usiDataSize); - if (!cRetCode) { - break; - } else { - ispVMStateMachine(DRPAUSE); /*Always DRPAUSE*/ - /*Bypass other devices when appropriate*/ - ispVMBypass(TDR, g_usTailDR); - ispVMStateMachine(g_ucEndDR); - ispVMStateMachine(IDLE); - ispVMDelay(1000); - } - } - } - } - } else { /* TDI only */ - cRetCode = ispVMSend(g_usiDataSize); - - } - - /* transfer the input data to the output buffer for the next verify */ - if ((g_usDataType & EXPRESS) || (a_cCode == SDR)) { - if (g_pucOutData) { - for (iDataIndex = 0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++) - g_pucOutData[iDataIndex] = g_pucInData[iDataIndex]; - } - } - - switch (a_cCode) { - case SIR: - /* 1/15/04 If not performing cascading, then shift ENDIR */ - if (!(g_usFlowControl & CASCADE)) { - if (g_usTailIR > 0) { - sclock(); - ispVMBypass(TIR, g_usTailIR); - } - ispVMStateMachine(g_ucEndIR); - } - break; - case XSDR: - case SDR: - /* 1/15/04 If not performing cascading, then shift ENDDR */ - if (!(g_usFlowControl & CASCADE)) { - if (g_usTailDR > 0) { - sclock(); - ispVMBypass(TDR, g_usTailDR); - } - ispVMStateMachine(g_ucEndDR); - } - break; - default: - break; - } - - return (cRetCode); -} - -/*************************************************************** -* -* ispVMAmble -* -* This routine is to extract Header and Trailer parameter for SIR and -* SDR operations. -* -* The Header and Trailer parameter are the pre-amble and post-amble bit -* stream need to be shifted into TDI or out of TDO of the devices. Mostly -* is for the purpose of bypassing the leading or trailing devices. ispVM -* supports only shifting data into TDI to bypass the devices. -* -* For a single device, the header and trailer parameters are all set to 0 -* as default by ispVM. If it is for multiple devices, the header and trailer -* value will change as specified by the VME file. -* -***************************************************************/ - -signed char ispVMAmble(signed char Code) -{ - signed char compress = 0; - /* 09/11/07 NN Type cast mismatch variables */ - g_usiDataSize = (unsigned short)ispVMDataSize(); - -#ifdef VME_DEBUG - printf("%d", g_usiDataSize); -#endif /* VME_DEBUG */ - - if (g_usiDataSize) { - - /**************************************************************************** - * - * Discard the TDI byte and set the compression bit in the data type register - * to false if compression is set because TDI data after HIR/HDR/TIR/TDR is not - * compressed. - * - *****************************************************************************/ - - GetByte(); - if (g_usDataType & COMPRESS) { - g_usDataType &= ~(COMPRESS); - compress = 1; - } - } - - switch (Code) { - case HIR: - - /**************************************************************************** - * - * Store the maximum size of the HIR buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usiDataSize > g_usHIRSize) { - g_usHIRSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Assign the HIR value and allocate memory. - * - *****************************************************************************/ - - g_usHeadIR = g_usiDataSize; - if (g_usHeadIR) { - ispVMMemManager(HIR, g_usHeadIR); - ispVMData(g_pucHIRData); - -#ifdef VME_DEBUG - printf(" TDI "); - PrintData(g_usHeadIR, g_pucHIRData); -#endif /* VME_DEBUG */ - } - break; - case TIR: - - /**************************************************************************** - * - * Store the maximum size of the TIR buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usiDataSize > g_usTIRSize) { - g_usTIRSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Assign the TIR value and allocate memory. - * - *****************************************************************************/ - - g_usTailIR = g_usiDataSize; - if (g_usTailIR) { - ispVMMemManager(TIR, g_usTailIR); - ispVMData(g_pucTIRData); - -#ifdef VME_DEBUG - printf(" TDI "); - PrintData(g_usTailIR, g_pucTIRData); -#endif /* VME_DEBUG */ - } - break; - case HDR: - - /**************************************************************************** - * - * Store the maximum size of the HDR buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usiDataSize > g_usHDRSize) { - g_usHDRSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Assign the HDR value and allocate memory. - * - *****************************************************************************/ - - g_usHeadDR = g_usiDataSize; - if (g_usHeadDR) { - ispVMMemManager(HDR, g_usHeadDR); - ispVMData(g_pucHDRData); - -#ifdef VME_DEBUG - printf(" TDI "); - PrintData(g_usHeadDR, g_pucHDRData); -#endif /* VME_DEBUG */ - } - break; - case TDR: - - /**************************************************************************** - * - * Store the maximum size of the TDR buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usiDataSize > g_usTDRSize) { - g_usTDRSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Assign the TDR value and allocate memory. - * - *****************************************************************************/ - - g_usTailDR = g_usiDataSize; - if (g_usTailDR) { - ispVMMemManager(TDR, g_usTailDR); - ispVMData(g_pucTDRData); - -#ifdef VME_DEBUG - printf(" TDI "); - PrintData(g_usTailDR, g_pucTDRData); -#endif /* VME_DEBUG */ - } - break; - default: - break; - } - - /**************************************************************************** - * - * Re-enable compression if it was previously set. - * - *****************************************************************************/ - - if (compress) { - g_usDataType |= COMPRESS; - } - - if (g_usiDataSize) { - Code = GetByte(); - if (Code == CONTINUE) { - return 0; - } else { - - /**************************************************************************** - * - * Encountered invalid opcode. - * - *****************************************************************************/ - - return VME_INVALID_FILE; - } - } - - return 0; -} - -/*************************************************************** -* -* ispVMLoop -* -* Perform the function call upon by the REPEAT opcode. -* Memory is to be allocated to store the entire loop from REPEAT to ENDLOOP. -* After the loop is stored then execution begin. The REPEATLOOP flag is set -* on the g_usFlowControl register to indicate the repeat loop is in session -* and therefore fetch opcode from the memory instead of from the file. -* -***************************************************************/ - -signed char ispVMLoop(unsigned short a_usLoopCount) -{ - /* 09/11/07 NN added local variables initialization */ - signed char cRetCode = 0; - unsigned short iHeapIndex = 0; - unsigned short iLoopIndex = 0; - - g_usShiftValue = 0; - for (iHeapIndex = 0; iHeapIndex < g_iHEAPSize; iHeapIndex++) { - g_pucHeapMemory[iHeapIndex] = GetByte(); - } - - if (g_pucHeapMemory[iHeapIndex - 1] != ENDLOOP) { - return (VME_INVALID_FILE); - } - - g_usFlowControl |= REPEATLOOP; - g_usDataType |= HEAP_IN; - - for (iLoopIndex = 0; iLoopIndex < a_usLoopCount; iLoopIndex++) { - g_iHeapCounter = 0; - cRetCode = ispVMCode(); - g_usRepeatLoops++; - if (cRetCode < 0) { - break; - } - } - - g_usDataType &= ~(HEAP_IN); - g_usFlowControl &= ~(REPEATLOOP); - return (cRetCode); -} - -/*************************************************************** -* -* ispVMBitShift -* -* Shift the TDI stream left or right by the number of bits. The data in -* *g_pucInData is of the VME format, so the actual shifting is the reverse of -* IEEE 1532 or SVF format. -* -***************************************************************/ - -signed char ispVMBitShift(signed char mode, unsigned short bits) -{ - /* 09/11/07 NN added local variables initialization */ - unsigned short i = 0; - unsigned short size = 0; - unsigned short tmpbits = 0; - - if (g_usiDataSize % 8 > 0) { - /* 09/11/07 NN Type cast mismatch variables */ - size = (unsigned short)(g_usiDataSize / 8 + 1); - } else { - /* 09/11/07 NN Type cast mismatch variables */ - size = (unsigned short)(g_usiDataSize / 8); - } - - switch (mode) { - case SHR: - for (i = 0; i < size; i++) { - if (g_pucInData[i] != 0) { - tmpbits = bits; - while (tmpbits > 0) { - g_pucInData[i] <<= 1; - if (g_pucInData[i] == 0) { - i--; - g_pucInData[i] = 1; - } - tmpbits--; - } - } - } - break; - case SHL: - for (i = 0; i < size; i++) { - if (g_pucInData[i] != 0) { - tmpbits = bits; - while (tmpbits > 0) { - g_pucInData[i] >>= 1; - if (g_pucInData[i] == 0) { - i--; - g_pucInData[i] = 8; - } - tmpbits--; - } - } - } - break; - default: - return (VME_INVALID_FILE); - } - - return (0); -} - -/*************************************************************** -* -* ispVMComment -* -* Displays the SVF comments. -* -***************************************************************/ - -void ispVMComment(unsigned short a_usCommentSize) -{ - char cCurByte = 0; - int count = 0; - for (; a_usCommentSize > 0; a_usCommentSize--) { - /**************************************************************************** - * - * Print character to the terminal. - * - *****************************************************************************/ - cCurByte = GetByte(); - vme_out_char(cCurByte); - count ++ ; - } - cCurByte = '\n'; - vme_out_char(cCurByte); -} - -/*************************************************************** -* -* ispVMHeader -* -* Iterate the length of the header and discard it. -* -***************************************************************/ - -void ispVMHeader(unsigned short a_usHeaderSize) -{ - for (; a_usHeaderSize > 0; a_usHeaderSize--) { - GetByte(); - } -} - -/*************************************************************** -* -* ispVMCalculateCRC32 -* -* Calculate the 32-bit CRC. -* -***************************************************************/ - -void ispVMCalculateCRC32(unsigned char a_ucData) -{ - /* 09/11/07 NN added local variables initialization */ - unsigned char ucIndex = 0; - unsigned char ucFlipData = 0; - unsigned short usCRCTableEntry = 0; - unsigned int crc_table[16] = { - 0x0000, 0xCC01, 0xD801, - 0x1400, 0xF001, 0x3C00, - 0x2800, 0xE401, 0xA001, - 0x6C00, 0x7800, 0xB401, - 0x5000, 0x9C01, 0x8801, - 0x4400 - }; - - for (ucIndex = 0; ucIndex < 8; ucIndex++) { - ucFlipData <<= 1; - if (a_ucData & 0x01) { - ucFlipData |= 0x01; - } - a_ucData >>= 1; - } - - /* 09/11/07 NN Type cast mismatch variables */ - usCRCTableEntry = (unsigned short)(crc_table[g_usCalculatedCRC & 0xF]); - g_usCalculatedCRC = (unsigned short)((g_usCalculatedCRC >> 4) & 0x0FFF); - g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[ucFlipData & 0xF]); - usCRCTableEntry = (unsigned short)(crc_table[g_usCalculatedCRC & 0xF]); - g_usCalculatedCRC = (unsigned short)((g_usCalculatedCRC >> 4) & 0x0FFF); - g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[(ucFlipData >> 4) & 0xF]); -} - -/*************************************************************** -* -* ispVMLCOUNT -* -* Process the intelligent programming loops. -* -***************************************************************/ - -signed char ispVMLCOUNT(unsigned short a_usCountSize) -{ - unsigned short usContinue = 1; - unsigned short usIntelBufferIndex = 0; - unsigned short usCountIndex = 0; - signed char cRetCode = 0; - signed char cRepeatHeap = 0; - signed char cOpcode = 0; - unsigned char ucState = 0; - unsigned short usDelay = 0; - unsigned short usToggle = 0; - unsigned char usByte = 0; - - g_usIntelBufferSize = (unsigned short)ispVMDataSize(); - - /**************************************************************************** - * - * Allocate memory for intel buffer. - * - *****************************************************************************/ - - ispVMMemManager(LHEAP, g_usIntelBufferSize); - - /**************************************************************************** - * - * Store the maximum size of the intelligent buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if (g_usIntelBufferSize > g_usLCOUNTSize) { - g_usLCOUNTSize = g_usIntelBufferSize; - } - - /**************************************************************************** - * - * Copy intel data to the buffer. - * - *****************************************************************************/ - - for (usIntelBufferIndex = 0; usIntelBufferIndex < g_usIntelBufferSize; usIntelBufferIndex++) { - g_pucIntelBuffer[usIntelBufferIndex] = GetByte(); - } - - /**************************************************************************** - * - * Set the data type register to get data from the intelligent data buffer. - * - *****************************************************************************/ - - g_usDataType |= LHEAP_IN; - - /**************************************************************************** - * - * If the HEAP_IN flag is set, temporarily unset the flag so data will be - * retrieved from the status buffer. - * - *****************************************************************************/ - - if (g_usDataType & HEAP_IN) { - g_usDataType &= ~HEAP_IN; - cRepeatHeap = 1; - } - -#ifdef VME_DEBUG - printf("LCOUNT %d;\n", a_usCountSize); -#endif /* VME_DEBUG */ - - /**************************************************************************** - * - * Iterate through the intelligent programming command. - * - *****************************************************************************/ - - for (usCountIndex = 0; usCountIndex < a_usCountSize; usCountIndex++) { - - /**************************************************************************** - * - * Initialize the intel data index to 0 before each iteration. - * - *****************************************************************************/ - - g_usIntelDataIndex = 0; - cOpcode = 0; - ucState = 0; - usDelay = 0; - usToggle = 0; - usByte = 0; - usContinue = 1; - - /*************************************************************** - * - * Begin looping through all the VME opcodes. - * - ***************************************************************/ - /*************************************************************** - * 4/1/09 Nguyen replaced the recursive function call codes on - * the ispVMLCOUNT function - * - ***************************************************************/ - while (usContinue) { - cOpcode = GetByte(); - switch (cOpcode) { - case HIR: - case TIR: - case HDR: - case TDR: - /*************************************************************** - * - * Set the header/trailer of the device in order to bypass - * successfully. - * - ***************************************************************/ - - ispVMAmble(cOpcode); - break; - case STATE: - - /*************************************************************** - * - * Step the JTAG state machine. - * - ***************************************************************/ - - ucState = GetByte(); - /*************************************************************** - * - * Step the JTAG state machine to DRCAPTURE to support Looping. - * - ***************************************************************/ - - if ((g_usDataType & LHEAP_IN) && - (ucState == DRPAUSE) && - (g_cCurrentJTAGState == ucState)) { - ispVMStateMachine(DRCAPTURE); - } - ispVMStateMachine(ucState); -#ifdef VME_DEBUG - printf("LDELAY %s ", GetState(ucState)); -#endif /* VME_DEBUG */ - break; - case SIR: -#ifdef VME_DEBUG - printf("SIR "); -#endif /* VME_DEBUG */ - /*************************************************************** - * - * Shift in data into the device. - * - ***************************************************************/ - - cRetCode = ispVMShift(cOpcode); - break; - case SDR: - -#ifdef VME_DEBUG - printf("LSDR "); -#endif /* VME_DEBUG */ - /*************************************************************** - * - * Shift in data into the device. - * - ***************************************************************/ - - cRetCode = ispVMShift(cOpcode); - break; - case WAIT: - - /*************************************************************** - * - * Observe delay. - * - ***************************************************************/ - - usDelay = (unsigned short)ispVMDataSize(); - ispVMDelay(usDelay); - -#ifdef VME_DEBUG - if (usDelay & 0x8000) { - - /*************************************************************** - * - * Since MSB is set, the delay time must be decoded to - * millisecond. The SVF2VME encodes the MSB to represent - * millisecond. - * - ***************************************************************/ - - usDelay &= ~0x8000; - printf("%.2E SEC;\n", (float)usDelay / 1000); - } else { - - /*************************************************************** - * - * Since MSB is not set, the delay time is given as microseconds. - * - ***************************************************************/ - - printf("%.2E SEC;\n", (float)usDelay / 1000000); - } -#endif /* VME_DEBUG */ - break; - case TCK: - - /*************************************************************** - * - * Issue clock toggles. - * - ***************************************************************/ - - usToggle = (unsigned short)ispVMDataSize(); - ispVMClocks(usToggle); - -#ifdef VME_DEBUG - printf("RUNTEST %d TCK;\n", usToggle); -#endif /* VME_DEBUG */ - break; - case ENDLOOP: - - /*************************************************************** - * - * Exit point from processing loops. - * - ***************************************************************/ - usContinue = 0; - break; - - case COMMENT: - - /*************************************************************** - * - * Display comment. - * - ***************************************************************/ - - ispVMComment((unsigned short)ispVMDataSize()); - break; - case ispEN: - ucState = GetByte(); - if ((ucState == ON) || (ucState == 0x01)) - writePort(JTAG_ENABLE, 0x01); - else - writePort(JTAG_ENABLE, 0x00); - ispVMDelay(1); - break; - case TRST: - if (GetByte() == 0x01) - writePort(JTAG_TRST, 0x01); - else - writePort(JTAG_TRST, 0x00); - ispVMDelay(1); - break; - default: - - /*************************************************************** - * - * Invalid opcode encountered. - * - ***************************************************************/ - -#ifdef VME_DEBUG - printf("\nINVALID OPCODE: 0x%.2X\n", cOpcode); -#endif /* VME_DEBUG */ - - return VME_INVALID_FILE; - } - } - if (cRetCode >= 0) { - /**************************************************************************** - * - * Break if intelligent programming is successful. - * - *****************************************************************************/ - - break; - } - - } - /**************************************************************************** - * - * If HEAP_IN flag was temporarily disabled, re-enable it before exiting. - * - *****************************************************************************/ - - if (cRepeatHeap) { - g_usDataType |= HEAP_IN; - } - - /**************************************************************************** - * - * Set the data type register to not get data from the intelligent data buffer. - * - *****************************************************************************/ - - g_usDataType &= ~LHEAP_IN; - return cRetCode; -} - -/*************************************************************** -* -* ispVMClocks -* -* Applies the specified number of pulses to TCK. -* -***************************************************************/ - -void ispVMClocks(unsigned short Clocks) -{ - unsigned short iClockIndex = 0; - for (iClockIndex = 0; iClockIndex < Clocks; iClockIndex++) { - sclock(); - } -} - -/*************************************************************** -* -* ispVMBypass -* -* This procedure takes care of the HIR, HDR, TIR, TDR for the -* purpose of putting the other devices into Bypass mode. The -* current state is checked to find out if it is at DRPAUSE or -* IRPAUSE. If it is at DRPAUSE, perform bypass register scan. -* If it is at IRPAUSE, scan into instruction registers the bypass -* instruction. -* -***************************************************************/ - -void ispVMBypass(signed char ScanType, unsigned short Bits) -{ - /* 09/11/07 NN added local variables initialization */ - unsigned short iIndex = 0; - unsigned short iSourceIndex = 0; - unsigned char cBitState = 0; - unsigned char cCurByte = 0; - unsigned char *pcSource = NULL; - - if (Bits <= 0) { - return; - } - - switch (ScanType) { - case HIR: - pcSource = g_pucHIRData; - break; - case TIR: - pcSource = g_pucTIRData; - break; - case HDR: - pcSource = g_pucHDRData; - break; - case TDR: - pcSource = g_pucTDRData; - break; - default: - break; - } - if (pcSource) { - iSourceIndex = 0; - cBitState = 0; - for (iIndex = 0; iIndex < Bits - 1; iIndex++) { - /* Scan instruction or bypass register */ - if (iIndex % 8 == 0) { - cCurByte = pcSource[iSourceIndex++]; - } - cBitState = (unsigned char)(((cCurByte << iIndex % 8) & 0x80) ? 0x01 : 0x00); - writePort(JTAG_TDI, cBitState); - sclock(); - } - - if (iIndex % 8 == 0) { - cCurByte = pcSource[iSourceIndex++]; - } - - cBitState = (unsigned char)(((cCurByte << iIndex % 8) & 0x80) ? 0x01 : 0x00); - writePort(JTAG_TDI, cBitState); - } -} - -/*************************************************************** -* -* ispVMStateMachine -* -* This procedure steps all devices in the daisy chain from a given -* JTAG state to the next desirable state. If the next state is TLR, -* the JTAG state machine is brute forced into TLR by driving TMS -* high and pulse TCK 6 times. -* -***************************************************************/ - -void ispVMStateMachine(signed char cNextJTAGState) -{ - /* 09/11/07 NN added local variables initialization */ - signed char cPathIndex = 0; - signed char cStateIndex = 0; - short int found = 0; - - if ((g_cCurrentJTAGState == cNextJTAGState) && (cNextJTAGState != RESET)) { - return; - } - - for (cStateIndex = 0; cStateIndex < 25; cStateIndex++) { - if ((g_cCurrentJTAGState == g_JTAGTransistions[cStateIndex].CurState) && (cNextJTAGState == g_JTAGTransistions[cStateIndex].NextState)) { - found = 1; - break; - } - } - if (found) { - g_cCurrentJTAGState = cNextJTAGState; - for (cPathIndex = 0; cPathIndex < g_JTAGTransistions[cStateIndex].Pulses; cPathIndex++) { - if ((g_JTAGTransistions[cStateIndex].Pattern << cPathIndex) & 0x80) { - writePort(JTAG_TMS, (unsigned char)0x01); - } else { - writePort(JTAG_TMS, (unsigned char)0x00); - } - sclock(); - } - - writePort(JTAG_TDI, 0x00); - writePort(JTAG_TMS, 0x00); - } -} - -/*************************************************************** -* -* ispVMStart -* -* Enable the port to the device and set the state to RESET (TLR). -* -***************************************************************/ - -void ispVMStart() -{ -#ifdef VME_DEBUG - printf("// ISPVM EMBEDDED ADDED\n"); - printf("STATE RESET;\n"); -#endif - - ispVMStateMachine(RESET); /* step devices to RESET state */ - -} - -/*************************************************************** -* -* ispVMEnd -* -* Set the state of devices to RESET to enable the devices and disable -* the port. -* -***************************************************************/ - -void ispVMEnd() -{ -#ifdef VME_DEBUG - printf("// ISPVM EMBEDDED ADDED\n"); - printf("STATE RESET;\n"); - printf("RUNTEST 1.00E-001 SEC;\n"); -#endif - - ispVMStateMachine(RESET); /* step devices to RESET state */ - ispVMDelay(1000); /* wake up devices */ -} - -/*************************************************************** -* -* ispVMSend -* -* Send the TDI data stream to devices. The data stream can be -* instructions or data. -* -***************************************************************/ - -signed char ispVMSend(unsigned short a_usiDataSize) -{ - /* 09/11/07 NN added local variables initialization */ - unsigned short iIndex = 0; - unsigned short iInDataIndex = 0; - unsigned char cCurByte = 0; - unsigned char cBitState = 0; - - for (iIndex = 0; iIndex < a_usiDataSize - 1; iIndex++) { - if (iIndex % 8 == 0) { - cCurByte = g_pucInData[iInDataIndex++]; - } - cBitState = (unsigned char)(((cCurByte << iIndex % 8) & 0x80) ? 0x01 : 0x00); - writePort(JTAG_TDI, cBitState); - sclock(); - } - - if (iIndex % 8 == 0) { - /* Take care of the last bit */ - cCurByte = g_pucInData[iInDataIndex]; - } - - cBitState = (unsigned char)(((cCurByte << iIndex % 8) & 0x80) ? 0x01 : 0x00); - - writePort(JTAG_TDI, cBitState); - if (g_usFlowControl & CASCADE) { - /* 1/15/04 Clock in last bit for the first n-1 cascaded frames */ - sclock(); - } - - return 0; -} - -/*************************************************************** -* -* ispVMRead -* -* Read the data stream from devices and verify. -* -***************************************************************/ - -signed char ispVMRead(unsigned short a_usiDataSize) -{ - /* 09/11/07 NN added local variables initialization */ - unsigned short usDataSizeIndex = 0; - unsigned short usErrorCount = 0; - unsigned short usLastBitIndex = 0; - unsigned char cDataByte = 0; - unsigned char cMaskByte = 0; - unsigned char cInDataByte = 0; - unsigned char cCurBit = 0; - unsigned char cByteIndex = 0; - unsigned short usBufferIndex = 0; - unsigned char ucDisplayByte = 0x00; - unsigned char ucDisplayFlag = 0x01; - char StrChecksum[256] = { 0 }; - unsigned char g_usCalculateChecksum = 0x00; - - /* 09/11/07 NN Type cast mismatch variables */ - usLastBitIndex = (unsigned short)(a_usiDataSize - 1); - - /**************************************************************************** - * - * If mask is not all zeros, then set the display flag to 0x00, otherwise - * it shall be set to 0x01 to indicate that data read from the device shall - * be displayed. If VME_DEBUG is defined, always display data. - * - *****************************************************************************/ - - - for (usDataSizeIndex = 0; usDataSizeIndex < (a_usiDataSize + 7) / 8; usDataSizeIndex++) { - - if (g_usDataType & MASK_DATA) { - if (g_pucOutMaskData[usDataSizeIndex] != 0x00) { - ucDisplayFlag = 0x00; - break; - } - } else if (g_usDataType & CMASK_DATA) { - g_usCalculateChecksum = 0x01; - ucDisplayFlag = 0x00; - break; - } else { - ucDisplayFlag = 0x00; - break; - } - } - - /**************************************************************************** - * - * Begin shifting data in and out of the device. - * - *****************************************************************************/ - for (usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++) { - if (cByteIndex == 0) { - - /*************************************************************** - * - * Grab byte from TDO buffer. - * - ***************************************************************/ - - if (g_usDataType & TDO_DATA) { - cDataByte = g_pucOutData[usBufferIndex]; - } - - /*************************************************************** - * - * Grab byte from MASK buffer. - * - ***************************************************************/ - - if (g_usDataType & MASK_DATA) { - cMaskByte = g_pucOutMaskData[usBufferIndex]; - } else { - cMaskByte = 0xFF; - } - - /*************************************************************** - * - * Grab byte from CMASK buffer. - * - ***************************************************************/ - - if (g_usDataType & CMASK_DATA) { - cMaskByte = 0x00; - g_usCalculateChecksum = 0x01; - } - - /*************************************************************** - * - * Grab byte from TDI buffer. - * - ***************************************************************/ - - if (g_usDataType & TDI_DATA) { - cInDataByte = g_pucInData[usBufferIndex]; - } - - usBufferIndex++; - } - - cCurBit = readPort(); - - if (ucDisplayFlag) { - ucDisplayByte <<= 1; - ucDisplayByte |= cCurBit; - } - - /**************************************************************************** - * - * Check if data read from port matches with expected TDO. - * - *****************************************************************************/ - - - if (g_usDataType & TDO_DATA) { - /* 08/28/08 NN Added Calculate checksum support. */ - if (g_usCalculateChecksum) { - if (cCurBit == 0x01) - g_usChecksum += (1 << (g_uiChecksumIndex % 8)); - g_uiChecksumIndex++; - } else { - if ((((cMaskByte << cByteIndex) & 0x80) ? 0x01 : 0x00)) { - if (cCurBit != (unsigned char)(((cDataByte << cByteIndex) & 0x80) ? 0x01 : 0x00)) { - usErrorCount++; - } - } - } - } - - /**************************************************************************** - * - * Write TDI data to the port. - * - *****************************************************************************/ - - writePort(JTAG_TDI, (unsigned char)(((cInDataByte << cByteIndex) & 0x80) ? 0x01 : 0x00)); - - if (usDataSizeIndex < usLastBitIndex) { - - /**************************************************************************** - * - * Clock data out from the data shift register. - * - *****************************************************************************/ - - sclock(); - } else if (g_usFlowControl & CASCADE) { - - /**************************************************************************** - * - * Clock in last bit for the first N - 1 cascaded frames. - * - *****************************************************************************/ - - sclock(); - } - - /*************************************************************** - * - * Increment the byte index. If it exceeds 7, then reset it back - * to zero. - * - ***************************************************************/ - - cByteIndex++; - if (cByteIndex >= 8) { - if (ucDisplayFlag) { - - /*************************************************************** - * - * Store displayed data in the TDO buffer. By reusing the TDO - * buffer to store displayed data, there is no need to allocate - * a buffer simply to hold display data. This will not cause any - * false verification errors because the true TDO byte has already - * been consumed. - * - ***************************************************************/ - - g_pucOutData[usBufferIndex - 1] = ucDisplayByte; - ucDisplayByte = 0; - } - - cByteIndex = 0; - } - /* 09/12/07 Nguyen changed to display the 1 bit expected data */ - else if (a_usiDataSize == 1) { - if (ucDisplayFlag) { - - /*************************************************************** - * - * Store displayed data in the TDO buffer. By reusing the TDO - * buffer to store displayed data, there is no need to allocate - * a buffer simply to hold display data. This will not cause any - * false verification errors because the true TDO byte has already - * been consumed. - * - ***************************************************************/ - - /**************************************************************************** - * - * Flip ucDisplayByte and store it in cDataByte. - * - *****************************************************************************/ - cDataByte = 0x00; - for (usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++) { - cDataByte <<= 1; - if (ucDisplayByte & 0x01) { - cDataByte |= 0x01; - } - ucDisplayByte >>= 1; - } - g_pucOutData[0] = cDataByte; - ucDisplayByte = 0; - } - - cByteIndex = 0; - } - } - if (ucDisplayFlag) { - - /**************************************************************************** - * - * Display data read from the device. - * - *****************************************************************************/ - -#ifdef VME_DEBUG - printf("RECIEVED TDO ("); -#else - vme_out_string("Display Data: 0x"); -#endif /* VME_DEBUG */ - - /* 09/11/07 NN Type cast mismatch variables */ - for (usDataSizeIndex = (unsigned short)((a_usiDataSize + 7) / 8); usDataSizeIndex > 0; usDataSizeIndex--) { - cMaskByte = g_pucOutData[usDataSizeIndex - 1]; - cDataByte = 0x00; - - /**************************************************************************** - * - * Flip cMaskByte and store it in cDataByte. - * - *****************************************************************************/ - - for (usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++) { - cDataByte <<= 1; - if (cMaskByte & 0x01) { - cDataByte |= 0x01; - } - cMaskByte >>= 1; - } -#ifdef VME_DEBUG - printf("%.2X", cDataByte); - if ((((a_usiDataSize + 7) / 8) - usDataSizeIndex) % 40 == 39) { - printf("\n\t\t"); - } -#else - vme_out_hex(cDataByte); -#endif /* VME_DEBUG */ - } - -#ifdef VME_DEBUG - printf(")\n\n"); -#else - vme_out_string("\n\n"); -#endif /* VME_DEBUG */ - /* 09/02/08 Nguyen changed to display the data Checksum */ - vme_out_string("g_usChecksum:"); - sprintf(StrChecksum, "%.4X\n\n", (unsigned int)g_usChecksum); - vme_out_string(StrChecksum); - vme_out_string("\n\n"); - if (g_usChecksum != 0) { - g_usChecksum &= 0xFFFF; - sprintf(StrChecksum, "Data Checksum: %.4X\n\n", (unsigned int)g_usChecksum); - vme_out_string(StrChecksum); - g_usChecksum = 0; - } - } - - if (usErrorCount > 0) { - - if (g_usFlowControl & VERIFYUES) { - vme_out_string("USERCODE verification failed. Continue programming......\n\n"); - g_usFlowControl &= ~(VERIFYUES); - return 0; - } else { - -#ifdef VME_DEBUG - printf("TOTAL ERRORS: %d\n", usErrorCount); -#endif /* VME_DEBUG */ - - return VME_VERIFICATION_FAILURE; - } - } else { - if (g_usFlowControl & VERIFYUES) { - vme_out_string("USERCODE verification passed. Programming aborted. \n\n"); - g_usFlowControl &= ~(VERIFYUES); - return 1; - } else { - return 0; - } - } -} - -/*************************************************************** -* -* ispVMReadandSave -* -* Support dynamic I/O. -* -***************************************************************/ - -signed char ispVMReadandSave(unsigned short int a_usiDataSize) -{ - /* 09/11/07 NN added local variables initialization */ - unsigned short int usDataSizeIndex = 0; - unsigned short int usLastBitIndex = 0; - unsigned short int usBufferIndex = 0; - unsigned short int usOutBitIndex = 0; - unsigned short int usLVDSIndex = 0; - unsigned char cDataByte = 0; - unsigned char cDMASKByte = 0; - unsigned char cInDataByte = 0; - unsigned char cCurBit = 0; - unsigned char cByteIndex = 0; - signed char cLVDSByteIndex = 0; - - /* 09/11/07 NN Type cast mismatch variables */ - usLastBitIndex = (unsigned short)(a_usiDataSize - 1); - - /*************************************************************** - * - * Iterate through the data bits. - * - ***************************************************************/ - - for (usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++) { - if (cByteIndex == 0) { - - /*************************************************************** - * - * Grab byte from DMASK buffer. - * - ***************************************************************/ - - if (g_usDataType & DMASK_DATA) { - cDMASKByte = g_pucOutDMaskData[usBufferIndex]; - } else { - cDMASKByte = 0x00; - } - - /*************************************************************** - * - * Grab byte from TDI buffer. - * - ***************************************************************/ - - if (g_usDataType & TDI_DATA) { - cInDataByte = g_pucInData[usBufferIndex]; - } - - usBufferIndex++; - } - - cCurBit = readPort(); - cDataByte = (unsigned char)(((cInDataByte << cByteIndex) & 0x80) ? 0x01 : 0x00); - - /*************************************************************** - * - * Initialize the byte to be zero. - * - ***************************************************************/ - - if (usOutBitIndex % 8 == 0) { - g_pucOutData[usOutBitIndex / 8] = 0x00; - } - - /*************************************************************** - * - * Use TDI, DMASK, and device TDO to create new TDI (actually - * stored in g_pucOutData). - * - ***************************************************************/ - - if ((((cDMASKByte << cByteIndex) & 0x80) ? 0x01 : 0x00)) { - - if (g_pLVDSList) { - for (usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++) { - if (g_pLVDSList[usLVDSIndex].usNegativeIndex == usDataSizeIndex) { - g_pLVDSList[usLVDSIndex].ucUpdate = 0x01; - break; - } - } - } - - /*************************************************************** - * - * DMASK bit is 1, use TDI. - * - ***************************************************************/ - - g_pucOutData[usOutBitIndex / 8] |= (unsigned char)(((cDataByte & 0x1) ? 0x01 : 0x00) << (7 - usOutBitIndex % 8)); - } else { - - /*************************************************************** - * - * DMASK bit is 0, use device TDO. - * - ***************************************************************/ - - g_pucOutData[usOutBitIndex / 8] |= (unsigned char)(((cCurBit & 0x1) ? 0x01 : 0x00) << (7 - usOutBitIndex % 8)); - } - - /*************************************************************** - * - * Shift in TDI in order to get TDO out. - * - ***************************************************************/ - - usOutBitIndex++; - writePort(JTAG_TDI, cDataByte); - if (usDataSizeIndex < usLastBitIndex) { - sclock(); - } - - /*************************************************************** - * - * Increment the byte index. If it exceeds 7, then reset it back - * to zero. - * - ***************************************************************/ - - cByteIndex++; - if (cByteIndex >= 8) { - cByteIndex = 0; - } - } - - /*************************************************************** - * - * If g_pLVDSList exists and pairs need updating, then update - * the negative-pair to receive the flipped positive-pair value. - * - ***************************************************************/ - - if (g_pLVDSList) { - for (usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++) { - if (g_pLVDSList[usLVDSIndex].ucUpdate) { - - /*************************************************************** - * - * Read the positive value and flip it. - * - ***************************************************************/ - - cDataByte = (unsigned char)(((g_pucOutData[g_pLVDSList[usLVDSIndex].usPositiveIndex / 8] << (g_pLVDSList[usLVDSIndex].usPositiveIndex % 8)) & 0x80) ? 0x01 : 0x00); - //09/11/07 NN Type cast mismatch variables - cDataByte = (unsigned char)(!cDataByte); - - /*************************************************************** - * - * Get the byte that needs modification. - * - ***************************************************************/ - - cInDataByte = g_pucOutData[g_pLVDSList[usLVDSIndex].usNegativeIndex / 8]; - - if (cDataByte) { - - /*************************************************************** - * - * Copy over the current byte and set the negative bit to 1. - * - ***************************************************************/ - - cDataByte = 0x00; - for (cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex--) { - cDataByte <<= 1; - if (7 - (g_pLVDSList[usLVDSIndex].usNegativeIndex % 8) == cLVDSByteIndex) { - - /*************************************************************** - * - * Set negative bit to 1. - * - ***************************************************************/ - - cDataByte |= 0x01; - } else if (cInDataByte & 0x80) { - cDataByte |= 0x01; - } - - cInDataByte <<= 1; - } - - /*************************************************************** - * - * Store the modified byte. - * - ***************************************************************/ - - g_pucOutData[g_pLVDSList[usLVDSIndex].usNegativeIndex / 8] = cDataByte; - } else { - - /*************************************************************** - * - * Copy over the current byte and set the negative bit to 0. - * - ***************************************************************/ - - cDataByte = 0x00; - for (cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex--) { - cDataByte <<= 1; - if (7 - (g_pLVDSList[usLVDSIndex].usNegativeIndex % 8) == cLVDSByteIndex) { - - /*************************************************************** - * - * Set negative bit to 0. - * - ***************************************************************/ - - cDataByte |= 0x00; - } else if (cInDataByte & 0x80) { - cDataByte |= 0x01; - } - - cInDataByte <<= 1; - } - - /*************************************************************** - * - * Store the modified byte. - * - ***************************************************************/ - - g_pucOutData[g_pLVDSList[usLVDSIndex].usNegativeIndex / 8] = cDataByte; - } - - break; - } - } - } - - return (0); -} - -signed char ispVMProcessLVDS(unsigned short a_usLVDSCount) -{ - unsigned short usLVDSIndex = 0; - - /*************************************************************** - * - * Allocate memory to hold LVDS pairs. - * - ***************************************************************/ - - ispVMMemManager(LVDS, a_usLVDSCount); - g_usLVDSPairCount = a_usLVDSCount; - -#ifdef VME_DEBUG - printf("LVDS %d (", a_usLVDSCount); -#endif /* VME_DEBUG */ - - /*************************************************************** - * - * Iterate through each given LVDS pair. - * - ***************************************************************/ - - for (usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++) { - - /*************************************************************** - * - * Assign the positive and negative indices of the LVDS pair. - * - ***************************************************************/ - - /* 09/11/07 NN Type cast mismatch variables */ - g_pLVDSList[usLVDSIndex].usPositiveIndex = (unsigned short)ispVMDataSize(); - /* 09/11/07 NN Type cast mismatch variables */ - g_pLVDSList[usLVDSIndex].usNegativeIndex = (unsigned short)ispVMDataSize(); - -#ifdef VME_DEBUG - if (usLVDSIndex < g_usLVDSPairCount - 1) { - printf("%d:%d, ", g_pLVDSList[usLVDSIndex].usPositiveIndex, g_pLVDSList[usLVDSIndex].usNegativeIndex); - } else { - printf("%d:%d", g_pLVDSList[usLVDSIndex].usPositiveIndex, g_pLVDSList[usLVDSIndex].usNegativeIndex); - } -#endif /* VME_DEBUG */ - - } - -#ifdef VME_DEBUG - printf(") -- %d;\n", a_usLVDSCount); -#endif /* VME_DEBUG */ - - return (0); -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/vmopcode.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/vmopcode.h deleted file mode 100644 index 1c0277306b..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade_ispvme/vmopcode.h +++ /dev/null @@ -1,192 +0,0 @@ -/*************************************************************** -* -* This is the include file for Lattice Semiconductor's ispVM -* Embedded software application. -* -***************************************************************/ - -/*************************************************************** -* -* VME version. -* -* History: -* -***************************************************************/ - -#define VME_VERSION_NUMBER "12.2" - -/*************************************************************** -* -* Maximum declarations. -* -***************************************************************/ - -#define VMEHEXMAX 60000L /* The hex file is split 60K per file. */ -#define SCANMAX 64000L /* The maximum SDR/SIR burst. */ - -/*************************************************************** -* -* Supported JTAG state transitions. -* -***************************************************************/ - -#define RESET 0x00 -#define IDLE 0x01 -#define IRPAUSE 0x02 -#define DRPAUSE 0x03 -#define SHIFTIR 0x04 -#define SHIFTDR 0x05 -#define DRCAPTURE 0x06 - -/*************************************************************** -* -* Flow control register bit definitions. A set bit indicates -* that the register currently exhibits the corresponding mode. -* -***************************************************************/ - -#define INTEL_PRGM 0x0001 /* Intelligent programming is in effect. */ -#define CASCADE 0x0002 /* Currently splitting large SDR. */ -#define REPEATLOOP 0x0008 /* Currently executing a repeat loop. */ -#define SHIFTRIGHT 0x0080 /* The next data stream needs a right shift. */ -#define SHIFTLEFT 0x0100 /* The next data stream needs a left shift. */ -#define VERIFYUES 0x0200 /* Continue if fail is in effect. */ - -/*************************************************************** -* -* DataType register bit definitions. A set bit indicates -* that the register currently holds the corresponding type of data. -* -***************************************************************/ - -#define EXPRESS 0x0001 /* Simultaneous program and verify. */ -#define SIR_DATA 0x0002 /* SIR is the active SVF command. */ -#define SDR_DATA 0x0004 /* SDR is the active SVF command. */ -#define COMPRESS 0x0008 /* Data is compressed. */ -#define TDI_DATA 0x0010 /* TDI data is present. */ -#define TDO_DATA 0x0020 /* TDO data is present. */ -#define MASK_DATA 0x0040 /* MASK data is present. */ -#define HEAP_IN 0x0080 /* Data is from the heap. */ -#define LHEAP_IN 0x0200 /* Data is from intel data buffer. */ -#define VARIABLE 0x0400 /* Data is from a declared variable. */ -#define CRC_DATA 0x0800 /* CRC data is pressent. */ -#define CMASK_DATA 0x1000 /* CMASK data is pressent. */ -#define RMASK_DATA 0x2000 /* RMASK data is pressent. */ -#define READ_DATA 0x4000 /* READ data is pressent. */ -#define DMASK_DATA 0x8000 /* DMASK data is pressent. */ - -/*************************************************************** -* -* Pin opcodes. -* -***************************************************************/ - -#define signalENABLE 0x1C /* ispENABLE pin. */ -#define signalTMS 0x1D /* TMS pin. */ -#define signalTCK 0x1E /* TCK pin. */ -#define signalTDI 0x1F /* TDI pin. */ -#define signalTRST 0x20 /* TRST pin. */ - -/*************************************************************** -* -* Supported vendors. -* -***************************************************************/ - -#define VENDOR 0x56 -#define LATTICE 0x01 -#define ALTERA 0x02 -#define XILINX 0x03 - -/*************************************************************** -* -* Opcode definitions. -* -* Note: opcodes must be unique. -* -***************************************************************/ - -#define ENDDATA 0x00 /* The end of the current SDR data stream. */ -#define RUNTEST 0x01 /* The duration to stay at the stable state. */ -#define ENDDR 0x02 /* The stable state after SDR. */ -#define ENDIR 0x03 /* The stable state after SIR. */ -#define ENDSTATE 0x04 /* The stable state after RUNTEST. */ -#define TRST 0x05 /* Assert the TRST pin. */ -#define HIR 0x06 /* The sum of the IR bits of the leading devices. */ -#define TIR 0x07 /* The sum of the IR bits of the trailing devices. */ -#define HDR 0x08 /* The number of leading devices. */ -#define TDR 0x09 /* The number of trailing devices. */ -#define ispEN 0x0A /* Assert the ispEN pin. */ -#define FREQUENCY 0x0B /* The maximum clock rate to run the JTAG state machine. */ -#define STATE 0x10 /* Move to the next stable state. */ -#define SIR 0x11 /* The instruction stream follows. */ -#define SDR 0x12 /* The data stream follows. */ -#define TDI 0x13 /* The following data stream feeds into the device. */ -#define TDO 0x14 /* The following data stream is compared against the device. */ -#define MASK 0x15 /* The following data stream is used as mask. */ -#define XSDR 0x16 /* The following data stream is for simultaneous program and verify. */ -#define XTDI 0x17 /* The following data stream is for shift in only. It must be stored for the next XSDR. */ -#define XTDO 0x18 /* There is not data stream. The data stream was stored from the previous XTDI. */ -#define MEM 0x19 /* The maximum memory needed to allocate in order hold one row of data. */ -#define WAIT 0x1A /* The duration of delay to observe. */ -#define TCK 0x1B /* The number of TCK pulses. */ -#define SHR 0x23 /* Set the flow control register for right shift. */ -#define SHL 0x24 /* Set the flow control register for left shift. */ -#define HEAP 0x32 /* The memory size needed to hold one loop. */ -#define REPEAT 0x33 /* The beginning of the loop. */ -#define LEFTPAREN 0x35 /* The beginning of data following the loop. */ -#define VAR 0x55 /* Plac holder for loop data. */ -#define SEC 0x1C /* The delay time in seconds that must be observed. */ -#define SMASK 0x1D /* The mask for TDI data. */ -#define MAX 0x1E /* The absolute maximum wait time. */ -#define ON 0x1F /* Assert the targeted pin. */ -#define OFF 0x20 /* Dis-assert the targeted pin. */ -#define SETFLOW 0x30 /* Change the flow control register. */ -#define RESETFLOW 0x31 /* Clear the flow control register. */ -#define CRC 0x47 /* The following data stream is used for CRC calculation. */ -#define CMASK 0x48 /* The following data stream is used as mask for CRC calculation. */ -#define RMASK 0x49 /* The following data stream is used as mask for read and save. */ -#define READ 0x50 /* The following data stream is used for read and save. */ -#define ENDLOOP 0x59 /* The end of the repeat loop. */ -#define SECUREHEAP 0x60 /* Used to secure the HEAP opcode. */ -#define VUES 0x61 /* Support continue if fail. */ -#define DMASK 0x62 /* The following data stream is used for dynamic I/O. */ -#define COMMENT 0x63 /* Support SVF comments in the VME file. */ -#define HEADER 0x64 /* Support header in VME file. */ -#define FILE_CRC 0x65 /* Support crc-protected VME file. */ -#define LCOUNT 0x66 /* Support intelligent programming. */ -#define LDELAY 0x67 /* Support intelligent programming. */ -#define LSDR 0x68 /* Support intelligent programming. */ -#define LHEAP 0x69 /* Memory needed to hold intelligent data buffer */ -#define CONTINUE 0x70 /* Allow continuation. */ -#define LVDS 0x71 /* Support LVDS. */ -#define ENDVME 0x7F /* End of the VME file. */ -#define HIGH 0x80 /* Assert the targeted pin. */ -#define LOW 0x81 /* Dis-assert the targeted pin. */ -#define ENDFILE 0xFF /* End of file. */ - -/*************************************************************** -* -* ispVM Embedded Return Codes. -* -***************************************************************/ - -#define VME_VERIFICATION_FAILURE -1 -#define VME_FILE_READ_FAILURE -2 -#define VME_VERSION_FAILURE -3 -#define VME_INVALID_FILE -4 -#define VME_ARGUMENT_FAILURE -5 -#define VME_CRC_FAILURE -6 - -/*************************************************************** -* -* Type definitions. -* -***************************************************************/ - -/* Support LVDS */ -typedef struct { - unsigned short usPositiveIndex; - unsigned short usNegativeIndex; - unsigned char ucUpdate; -} LVDSPair; \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/libextphy.so b/platform/centec-arm64/sonic-platform-modules-ragile/common/app/libextphy.so deleted file mode 100644 index 1ca09deac2..0000000000 Binary files a/platform/centec-arm64/sonic-platform-modules-ragile/common/app/libextphy.so and /dev/null differ diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/eepromutil/__init__.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/eepromutil/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/eepromutil/fantlv.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/eepromutil/fantlv.py deleted file mode 100644 index fa480bb50a..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/eepromutil/fantlv.py +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -class FantlvException(Exception): - def __init__(self, message='fantlverror', code=-100): - err = 'errcode: {0} message:{1}'.format(code, message) - Exception.__init__(self, err) - self.code = code - self.message = message - -class fan_tlv(object): - HEAD_INFO = "\x01\x7e\x01\xf1" - VERSION = 0x01 # E2PROM file init version is 0x01 - FLAG = 0x7E # new version E2PROM mark as 0x7E - HW_VER = 0X01 # consists of master version and revised version - TYPE = 0xf1 # hardware type define - TLV_LEN = 00 # vaild data length(16bit) - _FAN_TLV_HDR_LEN = 6 - _FAN_TLV_CRC_LEN = 2 - - _FAN_TLV_TYPE_NAME = 0x02 - _FAN_TLV_TYPE_SN = 0x03 - _FAN_TLV_TYPE_HW_INFO = 0x05 - _FAN_TLV_TYPE_DEV_TYPE = 0x06 - - _fandecodetime = 0 - - @property - def dstatus(self): - return self._dstatus - - @property - def typename(self): - return self._typename - - @property - def typesn(self): - return self._typesn - - @property - def typehwinfo(self): - return self._typehwinfo - - @property - def typedevtype(self): - return self._typedevtype - - @property - def fanbus(self): - return self._fanbus - - @property - def fanloc(self): - return self._fanloc - - @property - def fandecodetime(self): - return self._fandecodetime - - def __init__(self): - self._typename = "" - self._typesn = "" - self._typehwinfo = "" - self._typedevtype = "" - self._dstatus = 0 - - def strtoarr(self, str): - s = [] - if str is not None: - for index in range(len(str)): - s.append(str[index]) - return s - - def str_to_hex(self,rest_v): - value = 0 - for index in range(len(rest_v)): - value |= ord(rest_v[index]) << ((len(rest_v) - index - 1) * 8) - return value - - def hex_to_str(self,s): - len_t = len(s) - if len_t % 2 != 0: - return 0 - ret = "" - for t in range(0, int(len_t / 2)): - ret += chr(int(s[2 * t:2 * t + 2], 16)) - return ret - - def generate_fan_value(self): - bin_buffer = [chr(0xff)] * 256 - bin_buffer[0] = chr(self.VERSION) - bin_buffer[1] = chr(self.FLAG) - bin_buffer[2] = chr(self.HW_VER) - bin_buffer[3] = chr(self.TYPE) - - temp_t = "%08x" % self.typedevtype # handle devtype first - typedevtype_t = self.hex_to_str(temp_t) - total_len = len(self.typename) + len(self.typesn) + \ - len(self.typehwinfo) + len(typedevtype_t) + 8 - - bin_buffer[4] = chr(total_len >> 8) - bin_buffer[5] = chr(total_len & 0x00FF) - - index_start = 6 - bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_NAME) - bin_buffer[index_start + 1] = chr(len(self.typename)) - bin_buffer[index_start + 2: index_start + 2 + - len(self.typename)] = self.strtoarr(self.typename) - index_start = index_start + 2 + len(self.typename) - - bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_SN) - bin_buffer[index_start + 1] = chr(len(self.typesn)) - bin_buffer[index_start + 2:index_start + 2 + - len(self.typesn)] = self.strtoarr(self.typesn) - index_start = index_start + 2 + len(self.typesn) - - bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_HW_INFO) - bin_buffer[index_start + 1] = chr(len(self.typehwinfo)) - bin_buffer[index_start + 2:index_start + 2 + - len(self.typehwinfo)] = self.strtoarr(self.typehwinfo) - index_start = index_start + 2 + len(self.typehwinfo) - - bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_DEV_TYPE) - bin_buffer[index_start + 1] = chr(len(typedevtype_t)) - bin_buffer[index_start + 2:index_start + 2 + - len(typedevtype_t)] = self.strtoarr(typedevtype_t) - index_start = index_start + 2 + len(typedevtype_t) - - crcs = fan_tlv.fancrc(''.join(bin_buffer[0:index_start])) # 2bytes checking - bin_buffer[index_start] = chr(crcs >> 8) - bin_buffer[index_start + 1] = chr(crcs & 0x00ff) - # printvalue(bin_buffer) - return bin_buffer - - def decode(self, e2): - if e2[0:4] != self.HEAD_INFO: - raise FantlvException("Fan tlv head info error,not fan tlv type", -10) - ret = [] - self.VERSION = ord(e2[0]) - self.FLAG = ord(e2[1]) - self.HW_VER = ord(e2[2]) - self.TYPE = ord(e2[3]) - self.TLV_LEN = (ord(e2[4]) << 8) | ord(e2[5]) - - tlv_index = self._FAN_TLV_HDR_LEN - tlv_end = self._FAN_TLV_HDR_LEN + self.TLV_LEN - - # check sum - if len(e2) < self._FAN_TLV_HDR_LEN + self.TLV_LEN + 2: - raise FantlvException("Fan tlv eeprom len error!", -2) - sumcrc = fan_tlv.fancrc(e2[0:self._FAN_TLV_HDR_LEN + self.TLV_LEN]) - readcrc = ord(e2[self._FAN_TLV_HDR_LEN + self.TLV_LEN] - ) << 8 | ord(e2[self._FAN_TLV_HDR_LEN + self.TLV_LEN + 1]) - if sumcrc != readcrc: - raise FantlvException("Fan tlv eeprom checksum error!", -1) - else: - self._dstatus = 0 - while (tlv_index + 2) < len(e2) and tlv_index < tlv_end: - s = self.decoder( - e2[tlv_index:tlv_index + 2 + ord(e2[tlv_index + 1])]) - tlv_index += ord(e2[tlv_index + 1]) + 2 - ret.append(s) - - return ret - - @staticmethod - def fancrc(t): - sum = 0 - for index in range(len(t)): - sum += ord(t[index]) - return sum - - def decoder(self, t): - try: - name = "" - value = "" - _len = ord(t[1]) - if ord(t[0]) == self._FAN_TLV_TYPE_NAME: - name = "Product Name" - value = t[2:2 + ord(t[1])] - self._typename = value - elif ord(t[0]) == self._FAN_TLV_TYPE_SN: - name = "serial Number" - value = t[2:2 + ord(t[1])] - self._typesn = value - elif ord(t[0]) == self._FAN_TLV_TYPE_HW_INFO: - name = "hardware info" - value = t[2:2 + ord(t[1])] - self._typehwinfo = value - elif ord(t[0]) == self._FAN_TLV_TYPE_DEV_TYPE: - name = "dev type" - value = "0x" - for c in t[2:2 + ord(t[1])]: - value += "%02X" % (ord(c),) - self._typedevtype = int(value,16) - return {"name": name, "code": ord(t[0]), "value": value,"lens": _len} - except Exception as e: - print(e) - return None - - def __str__(self): - formatstr = "VERSION : 0x%02x \n" \ - " FLAG : 0x%02x \n" \ - " HW_VER : 0x%02x \n" \ - " TYPE : 0x%02x \n" \ - "typename : %s \n" \ - "typesn : %s \n" \ - "typehwinfo : %s \n" - return formatstr % (self.VERSION, self.FLAG, self.HW_VER, self.TYPE, self.typename, self.typesn, self.typehwinfo) - - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/eepromutil/fru.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/eepromutil/fru.py deleted file mode 100644 index 4848530a8e..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/eepromutil/fru.py +++ /dev/null @@ -1,957 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -import collections -from bitarray import bitarray -from datetime import datetime, timedelta -import sys - -__all__ = ["FruException", "FruUtil", "BaseArea", "BoardInfoArea", "ProductInfoArea", - "MultiRecordArea", "Field", "ipmifru"] - -__DEBUG__ = "N" - - -class FruException(Exception): - def __init__(self, message='fruerror', code=-100): - err = 'errcode: {0} message:{1}'.format(code, message) - Exception.__init__(self, err) - self.code = code - self.message = message - - -def e_print(err): - print("ERROR: " + err) - - -def d_print(debug_info): - if(__DEBUG__ == "Y"): - print(debug_info) - - -class FruUtil(): - @staticmethod - def decodeLength(value): - a = bitarray(8) - a.setall(True) - a[0:1] = 0 - a[1:2] = 0 - x = ord(a.tobytes()) - return x & ord(value) - - @staticmethod - def minToData(): - starttime = datetime(1996, 1, 1, 0, 0, 0) - endtime = datetime.now() - seconds = (endtime - starttime).total_seconds() - mins = seconds / 60 - m = int(round(mins)) - return m - - @staticmethod - def getTimeFormat(): - return datetime.now().strftime('%Y-%m-%d') - - @staticmethod - def getTypeLength(value): - if value is None: - return 0 - a = bitarray(8) - a.setall(False) - a[0:1] = 1 - a[1:2] = 1 - x = ord(a.tobytes()) - return x | len(value) - - @staticmethod - def checksum(b): - result = 0 - for i in range(len(b)): - result += ord(b[i]) - return (0x100 - (result & 0xff)) & 0xff - - -class BaseArea(object): - SUGGESTED_SIZE_COMMON_HEADER = 8 - SUGGESTED_SIZE_INTERNAL_USE_AREA = 72 - SUGGESTED_SIZE_CHASSIS_INFO_AREA = 32 - SUGGESTED_SIZE_BOARD_INFO_AREA = 80 - SUGGESTED_SIZE_PRODUCT_INFO_AREA = 80 - - INITVALUE = b'\x00' - resultvalue = INITVALUE * 256 - COMMON_HEAD_VERSION = b'\x01' - __childList = None - - def __init__(self, name="", size=0, offset=0): - self.__childList = [] - self._offset = offset - self.name = name - self._size = size - self._isPresent = False - self._data = b'\x00' * size - self.__dataoffset = 0 - - @property - def childList(self): - return self.__childList - - @childList.setter - def childList(self, value): - self.__childList = value - - @property - def offset(self): - return self._offset - - @offset.setter - def offset(self, value): - self._offset = value - - @property - def size(self): - return self._size - - @size.setter - def size(self, value): - self._size = value - - @property - def data(self): - return self._data - - @data.setter - def data(self, value): - self._data = value - - @property - def isPresent(self): - return self._isPresent - - @isPresent.setter - def isPresent(self, value): - self._isPresent = value - - -class InternalUseArea(BaseArea): - pass - - -class ChassisInfoArea(BaseArea): - pass - - -class BoardInfoArea(BaseArea): - _boardTime = None - _fields = None - _mfg_date = None - - def __str__(self): - formatstr = "version : %x\n" \ - "length : %d \n" \ - "language : %x \n" \ - "mfg_date : %s \n" \ - "boardManufacturer : %s \n" \ - "boardProductName : %s \n" \ - "boardSerialNumber : %s \n" \ - "boardPartNumber : %s \n" \ - "fruFileId : %s \n" - - tmpstr = formatstr % (ord(self.boardversion), self.size, - self.language, self.getMfgRealData(), - self.boardManufacturer, self.boardProductName, - self.boardSerialNumber, self.boardPartNumber, - self.fruFileId) - for i in range(1, 11): - valtmp = "boardextra%d" % i - if hasattr(self, valtmp): - valtmpval = getattr(self, valtmp) - tmpstr += "boardextra%d : %s \n" % (i, valtmpval) - else: - break - - return tmpstr - - def todict(self): - dic = collections.OrderedDict() - dic["boardversion"] = ord(self.boardversion) - dic["boardlength"] = self.size - dic["boardlanguage"] = self.language - dic["boardmfg_date"] = self.getMfgRealData() - dic["boardManufacturer"] = self.boardManufacturer - dic["boardProductName"] = self.boardProductName - dic["boardSerialNumber"] = self.boardSerialNumber - dic["boardPartNumber"] = self.boardPartNumber - dic["boardfruFileId"] = self.fruFileId - for i in range(1, 11): - valtmp = "boardextra%d" % i - if hasattr(self, valtmp): - valtmpval = getattr(self, valtmp) - dic[valtmp] = valtmpval - else: - break - return dic - - def decodedata(self): - index = 0 - self.areaversion = self.data[index] - index += 1 - d_print("decode length :%d class size:%d" % - ((ord(self.data[index]) * 8), self.size)) - index += 2 - - timetmp = self.data[index: index + 3] - self.mfg_date = ord(timetmp[0]) | ( - ord(timetmp[1]) << 8) | (ord(timetmp[2]) << 16) - d_print("decode getMfgRealData :%s" % self.getMfgRealData()) - index += 3 - - templen = FruUtil.decodeLength(self.data[index]) - self.boardManufacturer = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode boardManufacturer:%s" % self.boardManufacturer) - - templen = FruUtil.decodeLength(self.data[index]) - self.boardProductName = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode boardProductName:%s" % self.boardProductName) - - templen = FruUtil.decodeLength(self.data[index]) - self.boardSerialNumber = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode boardSerialNumber:%s" % self.boardSerialNumber) - - templen = FruUtil.decodeLength(self.data[index]) - self.boardPartNumber = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode boardPartNumber:%s" % self.boardPartNumber) - - templen = FruUtil.decodeLength(self.data[index]) - self.fruFileId = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode fruFileId:%s" % self.fruFileId) - - - for i in range(1, 11): - valtmp = "boardextra%d" % i - if self.data[index] != chr(0xc1): - templen = FruUtil.decodeLength(self.data[index]) - tmpval = self.data[index + 1: index + templen + 1] - setattr(self, valtmp, tmpval) - index += templen + 1 - d_print("decode boardextra%d:%s" % (i, tmpval)) - else: - break - - def recalcute(self): - d_print("boardInfoArea version:%x" % ord(self.boardversion)) - d_print("boardInfoArea length:%d" % self.size) - d_print("boardInfoArea language:%x" % self.language) - self.mfg_date = FruUtil.minToData() - d_print("boardInfoArea mfg_date:%x" % self.mfg_date) - - self.data = chr(ord(self.boardversion)) + \ - chr(self.size / 8) + chr(self.language) - - self.data += chr(self.mfg_date & 0xFF) - self.data += chr((self.mfg_date >> 8) & 0xFF) - self.data += chr((self.mfg_date >> 16) & 0xFF) - - d_print("boardInfoArea boardManufacturer:%s" % self.boardManufacturer) - typelength = FruUtil.getTypeLength(self.boardManufacturer) - self.data += chr(typelength) - self.data += self.boardManufacturer - - d_print("boardInfoArea boardProductName:%s" % self.boardProductName) - self.data += chr(FruUtil.getTypeLength(self.boardProductName)) - self.data += self.boardProductName - - d_print("boardInfoArea boardSerialNumber:%s" % self.boardSerialNumber) - self.data += chr(FruUtil.getTypeLength(self.boardSerialNumber)) - self.data += self.boardSerialNumber - - d_print("boardInfoArea boardPartNumber:%s" % self.boardPartNumber) - self.data += chr(FruUtil.getTypeLength(self.boardPartNumber)) - self.data += self.boardPartNumber - - d_print("boardInfoArea fruFileId:%s" % self.fruFileId) - self.data += chr(FruUtil.getTypeLength(self.fruFileId)) - self.data += self.fruFileId - - for i in range(1, 11): - valtmp = "boardextra%d" % i - if hasattr(self, valtmp): - valtmpval = getattr(self, valtmp) - d_print("boardInfoArea boardextra%d:%s" % (i, valtmpval)) - self.data += chr(FruUtil.getTypeLength(valtmpval)) - if valtmpval is None: - pass - else: - self.data += valtmpval - else: - break - - self.data += chr(0xc1) - - if len(self.data) > (self.size - 1): - incr = (len(self.data) - self.size) / 8 + 1 - self.size += incr * 8 - - self.data = self.data[0:1] + chr(self.size / 8) + self.data[2:] - d_print("self data:%d" % len(self.data)) - d_print("self size:%d" % self.size) - d_print("adjust size:%d" % (self.size - len(self.data) - 1)) - self.data = self.data.ljust((self.size - 1), self.INITVALUE) - - # checksum - checksum = FruUtil.checksum(self.data) - d_print("board info checksum:%x" % checksum) - self.data += chr(checksum) - - def getMfgRealData(self): - starttime = datetime(1996, 1, 1, 0, 0, 0) - mactime = starttime + timedelta(minutes=self.mfg_date) - return mactime - - @property - def language(self): - self._language = 25 - return self._language - - @property - def mfg_date(self): - return self._mfg_date - - @mfg_date.setter - def mfg_date(self, val): - self._mfg_date = val - - @property - def boardversion(self): - self._boardversion = self.COMMON_HEAD_VERSION - return self._boardversion - - @property - def fruFileId(self): - return self._FRUFileID - - @fruFileId.setter - def fruFileId(self, val): - self._FRUFileID = val - - @property - def boardPartNumber(self): - return self._boardPartNumber - - @boardPartNumber.setter - def boardPartNumber(self, val): - self._boardPartNumber = val - - @property - def boardSerialNumber(self): - return self._boardSerialNumber - - @boardSerialNumber.setter - def boardSerialNumber(self, val): - self._boardSerialNumber = val - - @property - def boardProductName(self): - return self._boradProductName - - @boardProductName.setter - def boardProductName(self, val): - self._boradProductName = val - - @property - def boardManufacturer(self): - return self._boardManufacturer - - @boardManufacturer.setter - def boardManufacturer(self, val): - self._boardManufacturer = val - - @property - def boardTime(self): - return self._boardTime - - @boardTime.setter - def boardTime(self, val): - self._boardTime = val - - @property - def fields(self): - return self._fields - - @fields.setter - def fields(self, val): - self._fields = val - - -class ProductInfoArea(BaseArea): - _productManufacturer = None - _productAssetTag = None - _FRUFileID = None - - def __str__(self): - formatstr = "version : %x\n" \ - "length : %d \n" \ - "language : %x \n" \ - "productManufacturer : %s \n" \ - "productName : %s \n" \ - "productPartModelName: %s \n" \ - "productVersion : %s \n" \ - "productSerialNumber : %s \n" \ - "productAssetTag : %s \n" \ - "fruFileId : %s \n" - - tmpstr = formatstr % (ord(self.areaversion), self.size, - self.language, self.productManufacturer, - self.productName, self.productPartModelName, - self.productVersion, self.productSerialNumber, - self.productAssetTag, self.fruFileId) - - for i in range(1, 11): - valtmp = "productextra%d" % i - if hasattr(self, valtmp): - valtmpval = getattr(self, valtmp) - tmpstr += "productextra%d : %s \n" % (i, valtmpval) - else: - break - - return tmpstr - - def todict(self): - dic = collections.OrderedDict() - dic["productversion"] = ord(self.areaversion) - dic["productlength"] = self.size - dic["productlanguage"] = self.language - dic["productManufacturer"] = self.productManufacturer - dic["productName"] = self.productName - dic["productPartModelName"] = self.productPartModelName - dic["productVersion"] = int(self.productVersion, 16) - dic["productSerialNumber"] = self.productSerialNumber - dic["productAssetTag"] = self.productAssetTag - dic["productfruFileId"] = self.fruFileId - for i in range(1, 11): - valtmp = "productextra%d" % i - if hasattr(self, valtmp): - valtmpval = getattr(self, valtmp) - dic[valtmp] = valtmpval - else: - break - return dic - - def decodedata(self): - index = 0 - self.areaversion = self.data[index] # 0 - index += 1 - d_print("decode length %d" % (ord(self.data[index]) * 8)) - d_print("class size %d" % self.size) - index += 2 - - templen = FruUtil.decodeLength(self.data[index]) - self.productManufacturer = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productManufacturer:%s" % self.productManufacturer) - - templen = FruUtil.decodeLength(self.data[index]) - self.productName = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productName:%s" % self.productName) - - templen = FruUtil.decodeLength(self.data[index]) - self.productPartModelName = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productPartModelName:%s" % self.productPartModelName) - - templen = FruUtil.decodeLength(self.data[index]) - self.productVersion = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productVersion:%s" % self.productVersion) - - templen = FruUtil.decodeLength(self.data[index]) - self.productSerialNumber = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productSerialNumber:%s" % self.productSerialNumber) - - templen = FruUtil.decodeLength(self.data[index]) - self.productAssetTag = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productAssetTag:%s" % self.productAssetTag) - - templen = FruUtil.decodeLength(self.data[index]) - self.fruFileId = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode fruFileId:%s" % self.fruFileId) - - for i in range(1, 11): - valtmp = "productextra%d" % i - if self.data[index] != chr(0xc1) and index < self.size - 1: - templen = FruUtil.decodeLength(self.data[index]) - if templen == 0: - break - tmpval = self.data[index + 1: index + templen + 1] - d_print("decode boardextra%d:%s" % (i, tmpval)) - setattr(self, valtmp, tmpval) - index += templen + 1 - else: - break - - @property - def productVersion(self): - return self._productVersion - - @productVersion.setter - def productVersion(self, name): - self._productVersion = name - - @property - def areaversion(self): - self._areaversion = self.COMMON_HEAD_VERSION - return self._areaversion - - @areaversion.setter - def areaversion(self, name): - self._areaversion = name - - @property - def language(self): - self._language = 25 - return self._language - - @property - def productManufacturer(self): - return self._productManufacturer - - @productManufacturer.setter - def productManufacturer(self, name): - self._productManufacturer = name - - @property - def productName(self): - return self._productName - - @productName.setter - def productName(self, name): - self._productName = name - - @property - def productPartModelName(self): - return self._productPartModelName - - @productPartModelName.setter - def productPartModelName(self, name): - self._productPartModelName = name - - @property - def productSerialNumber(self): - return self._productSerialNumber - - @productSerialNumber.setter - def productSerialNumber(self, name): - self._productSerialNumber = name - - @property - def productAssetTag(self): - return self._productAssetTag - - @productAssetTag.setter - def productAssetTag(self, name): - self._productAssetTag = name - - @property - def fruFileId(self): - return self._FRUFileID - - @fruFileId.setter - def fruFileId(self, name): - self._FRUFileID = name - - def recalcute(self): - d_print("product version:%x" % ord(self.areaversion)) - d_print("product length:%d" % self.size) - d_print("product language:%x" % self.language) - self.data = chr(ord(self.areaversion)) + \ - chr(self.size / 8) + chr(self.language) - - typelength = FruUtil.getTypeLength(self.productManufacturer) - self.data += chr(typelength) - self.data += self.productManufacturer - - self.data += chr(FruUtil.getTypeLength(self.productName)) - self.data += self.productName - - self.data += chr(FruUtil.getTypeLength(self.productPartModelName)) - self.data += self.productPartModelName - - self.data += chr(FruUtil.getTypeLength(self.productVersion)) - self.data += self.productVersion - - self.data += chr(FruUtil.getTypeLength(self.productSerialNumber)) - self.data += self.productSerialNumber - - self.data += chr(FruUtil.getTypeLength(self.productAssetTag)) - if self.productAssetTag is not None: - self.data += self.productAssetTag - - self.data += chr(FruUtil.getTypeLength(self.fruFileId)) - self.data += self.fruFileId - - # whether the extended field exists or not - for i in range(1, 11): - valtmp = "productextra%d" % i - if hasattr(self, valtmp): - valtmpval = getattr(self, valtmp) - d_print("boardInfoArea productextra%d:%s" % (i, valtmpval)) - self.data += chr(FruUtil.getTypeLength(valtmpval)) - if valtmpval is None: - pass - else: - self.data += valtmpval - else: - break - - self.data += chr(0xc1) - if len(self.data) > (self.size - 1): - incr = (len(self.data) - self.size) / 8 + 1 - self.size += incr * 8 - d_print("self.data:%d" % len(self.data)) - d_print("self.size:%d" % self.size) - - self.data = self.data[0:1] + chr(self.size / 8) + self.data[2:] - self.data = self.data.ljust((self.size - 1), self.INITVALUE) - checksum = FruUtil.checksum(self.data) - d_print("board info checksum:%x" % checksum) - self.data += chr(checksum) - - -class MultiRecordArea(BaseArea): - pass - - -class Field(object): - - def __init__(self, fieldType="ASCII", fieldData=""): - self.fieldData = fieldData - self.fieldType = fieldType - - @property - def data(self): - return self._data - - @property - def fieldType(self): - return self._fieldType - - @property - def fieldData(self): - return self._fieldData - - -class ipmifru(BaseArea): - _BoardInfoArea = None - _ProductInfoArea = None - _InternalUseArea = None - _ChassisInfoArea = None - _multiRecordArea = None - _productinfoAreaOffset = BaseArea.INITVALUE - _boardInfoAreaOffset = BaseArea.INITVALUE - _internalUserAreaOffset = BaseArea.INITVALUE - _chassicInfoAreaOffset = BaseArea.INITVALUE - _multiRecordAreaOffset = BaseArea.INITVALUE - _bindata = None - _bodybin = None - _version = BaseArea.COMMON_HEAD_VERSION - _zeroCheckSum = None - _frusize = 256 - - def __str__(self): - tmpstr = "" - if self.boardInfoArea.isPresent: - tmpstr += "\nboardinfoarea: \n" - tmpstr += self.boardInfoArea.__str__() - if self.productInfoArea.isPresent: - tmpstr += "\nproductinfoarea: \n" - tmpstr += self.productInfoArea.__str__() - return tmpstr - - def decodeBin(self, eeprom): - commonHead = eeprom[0:8] - d_print("decode version %x" % ord(commonHead[0])) - if self.COMMON_HEAD_VERSION != commonHead[0]: - raise FruException("HEAD VERSION error,not Fru format!", -10) - if FruUtil.checksum(commonHead[0:7]) != ord(commonHead[7]): - strtemp = "check header checksum error [cal:%02x data:%02x]" % ( - FruUtil.checksum(commonHead[0:7]), ord(commonHead[7])) - raise FruException(strtemp, -3) - if commonHead[1] != self.INITVALUE: - d_print("Internal Use Area is present") - self.internalUseArea = InternalUseArea( - name="Internal Use Area", size=self.SUGGESTED_SIZE_INTERNAL_USE_AREA) - self.internalUseArea.isPresent = True - self.internalUserAreaOffset = ord(commonHead[1]) - self.internalUseArea.data = eeprom[self.internalUserAreaOffset * 8: ( - self.internalUserAreaOffset * 8 + self.internalUseArea.size)] - if commonHead[2] != self.INITVALUE: - d_print("Chassis Info Area is present") - self.chassisInfoArea = ChassisInfoArea( - name="Chassis Info Area", size=self.SUGGESTED_SIZE_CHASSIS_INFO_AREA) - self.chassisInfoArea.isPresent = True - self.chassicInfoAreaOffset = ord(commonHead[2]) - self.chassisInfoArea.data = eeprom[self.chassicInfoAreaOffset * 8: ( - self.chassicInfoAreaOffset * 8 + self.chassisInfoArea.size)] - if commonHead[3] != self.INITVALUE: - self.boardInfoArea = BoardInfoArea( - name="Board Info Area", size=self.SUGGESTED_SIZE_BOARD_INFO_AREA) - self.boardInfoArea.isPresent = True - self.boardInfoAreaOffset = ord(commonHead[3]) - self.boardInfoArea.size = ord( - eeprom[self.boardInfoAreaOffset * 8 + 1]) * 8 - d_print("Board Info Area is present size:%d" % - (self.boardInfoArea.size)) - self.boardInfoArea.data = eeprom[self.boardInfoAreaOffset * 8: ( - self.boardInfoAreaOffset * 8 + self.boardInfoArea.size)] - if FruUtil.checksum(self.boardInfoArea.data[:-1]) != ord(self.boardInfoArea.data[-1:]): - strtmp = "check boardInfoArea checksum error[cal:%02x data:%02x]" % \ - (FruUtil.checksum( - self.boardInfoArea.data[:-1]), ord(self.boardInfoArea.data[-1:])) - raise FruException(strtmp, -3) - self.boardInfoArea.decodedata() - if commonHead[4] != self.INITVALUE: - d_print("Product Info Area is present") - self.productInfoArea = ProductInfoArea( - name="Product Info Area ", size=self.SUGGESTED_SIZE_PRODUCT_INFO_AREA) - self.productInfoArea.isPresent = True - self.productinfoAreaOffset = ord(commonHead[4]) - d_print("length offset value: %02x" % - ord(eeprom[self.productinfoAreaOffset * 8 + 1])) - self.productInfoArea.size = ord( - eeprom[self.productinfoAreaOffset * 8 + 1]) * 8 - d_print("Product Info Area is present size:%d" % - (self.productInfoArea.size)) - - self.productInfoArea.data = eeprom[self.productinfoAreaOffset * 8: ( - self.productinfoAreaOffset * 8 + self.productInfoArea.size)] - if FruUtil.checksum(self.productInfoArea.data[:-1]) != ord(self.productInfoArea.data[-1:]): - strtmp = "check productInfoArea checksum error [cal:%02x data:%02x]" % ( - FruUtil.checksum(self.productInfoArea.data[:-1]), ord(self.productInfoArea.data[-1:])) - raise FruException(strtmp, -3) - self.productInfoArea.decodedata() - if commonHead[5] != self.INITVALUE: - self.multiRecordArea = MultiRecordArea( - name="MultiRecord record Area ") - d_print("MultiRecord record present") - self.multiRecordArea.isPresent = True - self.multiRecordAreaOffset = ord(commonHead[5]) - self.multiRecordArea.data = eeprom[self.multiRecordAreaOffset * 8: ( - self.multiRecordAreaOffset * 8 + self.multiRecordArea.size)] - - def initDefault(self): - self.version = self.COMMON_HEAD_VERSION - self.internalUserAreaOffset = self.INITVALUE - self.chassicInfoAreaOffset = self.INITVALUE - self.boardInfoAreaOffset = self.INITVALUE - self.productinfoAreaOffset = self.INITVALUE - self.multiRecordAreaOffset = self.INITVALUE - self.PAD = self.INITVALUE - self.zeroCheckSum = self.INITVALUE - self.offset = self.SUGGESTED_SIZE_COMMON_HEADER - self.productInfoArea = None - self.internalUseArea = None - self.boardInfoArea = None - self.chassisInfoArea = None - self.multiRecordArea = None - # self.recalcute() - - @property - def version(self): - return self._version - - @version.setter - def version(self, name): - self._version = name - - @property - def internalUserAreaOffset(self): - return self._internalUserAreaOffset - - @internalUserAreaOffset.setter - def internalUserAreaOffset(self, obj): - self._internalUserAreaOffset = obj - - @property - def chassicInfoAreaOffset(self): - return self._chassicInfoAreaOffset - - @chassicInfoAreaOffset.setter - def chassicInfoAreaOffset(self, obj): - self._chassicInfoAreaOffset = obj - - @property - def productinfoAreaOffset(self): - return self._productinfoAreaOffset - - @productinfoAreaOffset.setter - def productinfoAreaOffset(self, obj): - self._productinfoAreaOffset = obj - - @property - def boardInfoAreaOffset(self): - return self._boardInfoAreaOffset - - @boardInfoAreaOffset.setter - def boardInfoAreaOffset(self, obj): - self._boardInfoAreaOffset = obj - - @property - def multiRecordAreaOffset(self): - return self._multiRecordAreaOffset - - @multiRecordAreaOffset.setter - def multiRecordAreaOffset(self, obj): - self._multiRecordAreaOffset = obj - - @property - def zeroCheckSum(self): - return self._zeroCheckSum - - @zeroCheckSum.setter - def zeroCheckSum(self, obj): - self._zeroCheckSum = obj - - @property - def productInfoArea(self): - return self._ProductInfoArea - - @productInfoArea.setter - def productInfoArea(self, obj): - self._ProductInfoArea = obj - - @property - def internalUseArea(self): - return self._InternalUseArea - - @internalUseArea.setter - def internalUseArea(self, obj): - self.internalUseArea = obj - - @property - def boardInfoArea(self): - return self._BoardInfoArea - - @boardInfoArea.setter - def boardInfoArea(self, obj): - self._BoardInfoArea = obj - - @property - def chassisInfoArea(self): - return self._ChassisInfoArea - - @chassisInfoArea.setter - def chassisInfoArea(self, obj): - self._ChassisInfoArea = obj - - @property - def multiRecordArea(self): - return self._multiRecordArea - - @multiRecordArea.setter - def multiRecordArea(self, obj): - self._multiRecordArea = obj - - @property - def bindata(self): - return self._bindata - - @bindata.setter - def bindata(self, obj): - self._bindata = obj - - @property - def bodybin(self): - return self._bodybin - - @bodybin.setter - def bodybin(self, obj): - self._bodybin = obj - - def recalcuteCommonHead(self): - self.bindata = "" - self.offset = self.SUGGESTED_SIZE_COMMON_HEADER - d_print("common Header %d" % self.offset) - d_print("fru eeprom size %d" % self._frusize) - if self.internalUseArea is not None and self.internalUseArea.isPresent: - self.internalUserAreaOffset = self.offset / 8 - self.offset += self.internalUseArea.size - d_print("internalUseArea is present offset:%d" % self.offset) - - if self.chassisInfoArea is not None and self.chassisInfoArea.isPresent: - self.chassicInfoAreaOffset = self.offset / 8 - self.offset += self.chassisInfoArea.size - d_print("chassisInfoArea is present offset:%d" % self.offset) - - if self.boardInfoArea is not None and self.boardInfoArea.isPresent: - self.boardInfoAreaOffset = self.offset / 8 - self.offset += self.boardInfoArea.size - d_print("boardInfoArea is present offset:%d" % self.offset) - d_print("boardInfoArea is present size:%d" % - self.boardInfoArea.size) - - if self.productInfoArea is not None and self.productInfoArea.isPresent: - self.productinfoAreaOffset = self.offset / 8 - self.offset += self.productInfoArea.size - d_print("productInfoArea is present offset:%d" % self.offset) - - if self.multiRecordArea is not None and self.multiRecordArea.isPresent: - self.multiRecordAreaOffset = self.offset / 8 - d_print("multiRecordArea is present offset:%d" % self.offset) - - if self.internalUserAreaOffset == self.INITVALUE: - self.internalUserAreaOffset = 0 - if self.productinfoAreaOffset == self.INITVALUE: - self.productinfoAreaOffset = 0 - if self.chassicInfoAreaOffset == self.INITVALUE: - self.chassicInfoAreaOffset = 0 - if self.boardInfoAreaOffset == self.INITVALUE: - self.boardInfoAreaOffset = 0 - if self.multiRecordAreaOffset == self.INITVALUE: - self.multiRecordAreaOffset = 0 - - self.zeroCheckSum = (0x100 - ord(self.version) - self.internalUserAreaOffset - self.chassicInfoAreaOffset - self.productinfoAreaOffset - - self.boardInfoAreaOffset - self.multiRecordAreaOffset) & 0xff - d_print("zerochecksum:%x" % self.zeroCheckSum) - self.data = self.version + chr(self.internalUserAreaOffset) + chr(self.chassicInfoAreaOffset) + chr( - self.boardInfoAreaOffset) + chr(self.productinfoAreaOffset) + chr(self.multiRecordAreaOffset) + self.INITVALUE + chr(self.zeroCheckSum) - - self.bindata = self.data + self.bodybin - totallen = len(self.bindata) - d_print("totallen %d" % totallen) - if (totallen < self._frusize): - self.bindata = self.bindata.ljust(self._frusize, self.INITVALUE) - else: - raise FruException('bin data more than %d' % self._frusize, -2) - - def recalcutebin(self): - self.bodybin = "" - if self.internalUseArea is not None and self.internalUseArea.isPresent: - d_print("internalUseArea present") - self.bodybin += self.internalUseArea.data - if self.chassisInfoArea is not None and self.chassisInfoArea.isPresent: - d_print("chassisInfoArea present") - self.bodybin += self.chassisInfoArea.data - if self.boardInfoArea is not None and self.boardInfoArea.isPresent: - d_print("boardInfoArea present") - self.boardInfoArea.recalcute() - self.bodybin += self.boardInfoArea.data - if self.productInfoArea is not None and self.productInfoArea.isPresent: - d_print("productInfoAreapresent") - self.productInfoArea.recalcute() - self.bodybin += self.productInfoArea.data - if self.multiRecordArea is not None and self.multiRecordArea.isPresent: - d_print("multiRecordArea present") - self.bodybin += self.productInfoArea.data - - def recalcute(self, fru_eeprom_size = 256): - self._frusize = fru_eeprom_size - self.recalcutebin() - self.recalcuteCommonHead() diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/__init__.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/baseutil.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/baseutil.py deleted file mode 100755 index 1cf74d32d2..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/baseutil.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: UTF-8 -*- -import os - -def get_machine_info(): - if not os.path.isfile('/host/machine.conf'): - return None - machine_vars = {} - with open('/host/machine.conf') as machine_file: - for line in machine_file: - tokens = line.split('=') - if len(tokens) < 2: - continue - machine_vars[tokens[0]] = tokens[1].strip() - return machine_vars - -def get_platform_info(machine_info): - if machine_info != None: - if 'onie_platform' in machine_info: - return machine_info['onie_platform'] - elif 'aboot_platform' in machine_info: - return machine_info['aboot_platform'] - return None - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/logutil.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/logutil.py deleted file mode 100755 index 2b001f21d7..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/logutil.py +++ /dev/null @@ -1,67 +0,0 @@ -# -*- coding: UTF-8 -*- - -import logging -from syslog import ( - syslog, - openlog, - LOG_WARNING, - LOG_CRIT, - LOG_DEBUG, - LOG_ERR, - LOG_PID, - LOG_INFO, -) - -class Logger(): - def __init__(self, prefix, filepath=None, syslog=False, dbg_mask=0x0): - self.logger = None - if syslog is False: - if filepath is None: - raise AttributeError("filepath needed") - - # init logging - formatter = logging.Formatter( "%(asctime)s %(levelname)s %(filename)s[%(funcName)s][%(lineno)s]: %(message)s") - handler = logging.FileHandler(self.filepath) - handler.setFormatter(formatter) - self.logger = logging.getLogger(__name__) - self.logger.setLevel(logging.DEBUG) - self.logger.addHandler(handler) - - self.prefix = prefix - self.use_syslog = syslog - self.dbg_mask = dbg_mask - - def info(self, s): - if self.use_syslog: - self._syslog(s, LOG_INFO) - else: - self.logger.info(s) - - def debug(self, dbg_lvl, s): - if dbg_lvl & self.dbg_mask: - if self.use_syslog: - self._syslog(s, LOG_DEBUG) - else: - self.logger.debug(s) - - def warn(self, s): - if self.use_syslog: - self._syslog(s, LOG_WARNING) - else: - self.logger.warning(s) - - def error(self, s): - if self.use_syslog: - self._syslog(s, LOG_ERR) - else: - self.logger.error(s) - - def crit(self, s): - if self.use_syslog: - self._syslog(s, LOG_CRIT) - else: - self.logger.critical(s) - - def _syslog(self, s, t): - openlog(self.prefix, LOG_PID) - syslog(t, s) diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/smbus.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/smbus.py deleted file mode 100755 index cfef713c3b..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/lib/rgutil/smbus.py +++ /dev/null @@ -1,774 +0,0 @@ -"""smbus2 - A drop-in replacement for smbus-cffi/smbus-python""" -# The MIT License (MIT) -# Copyright (c) 2017 Karl-Petter Lindegaard -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -import os -import sys -from fcntl import ioctl -from ctypes import c_uint32, c_uint8, c_uint16, c_char, POINTER, Structure, Array, Union, create_string_buffer, string_at - - -# Commands from uapi/linux/i2c-dev.h -I2C_SLAVE = 0x0703 # Use this slave address -I2C_SLAVE_FORCE = 0x0706 # Use this slave address, even if it is already in use by a driver! -I2C_FUNCS = 0x0705 # Get the adapter functionality mask -I2C_RDWR = 0x0707 # Combined R/W transfer (one STOP only) -I2C_SMBUS = 0x0720 # SMBus transfer. Takes pointer to i2c_smbus_ioctl_data -I2C_PEC = 0x0708 - -# SMBus transfer read or write markers from uapi/linux/i2c.h -I2C_SMBUS_WRITE = 0 -I2C_SMBUS_READ = 1 - -# Size identifiers uapi/linux/i2c.h -I2C_SMBUS_QUICK = 0 -I2C_SMBUS_BYTE = 1 -I2C_SMBUS_BYTE_DATA = 2 -I2C_SMBUS_WORD_DATA = 3 -I2C_SMBUS_PROC_CALL = 4 -I2C_SMBUS_BLOCK_DATA = 5 # This isn't supported by Pure-I2C drivers with SMBUS emulation, like those in RaspberryPi, OrangePi, etc :( -I2C_SMBUS_BLOCK_PROC_CALL = 7 # Like I2C_SMBUS_BLOCK_DATA, it isn't supported by Pure-I2C drivers either. -I2C_SMBUS_I2C_BLOCK_DATA = 8 -I2C_SMBUS_BLOCK_MAX = 32 - -# To determine what functionality is present (uapi/linux/i2c.h) -try: - from enum import IntFlag -except ImportError: - IntFlag = int - - -class I2cFunc(IntFlag): - """ - These flags identify the operations supported by an I2C/SMBus device. - - You can test these flags on your `smbus.funcs` - - On newer python versions, I2cFunc is an IntFlag enum, but it - falls back to class with a bunch of int constants on older releases. - """ - I2C = 0x00000001 - ADDR_10BIT = 0x00000002 - PROTOCOL_MANGLING = 0x00000004 # I2C_M_IGNORE_NAK etc. - SMBUS_PEC = 0x00000008 - NOSTART = 0x00000010 # I2C_M_NOSTART - SLAVE = 0x00000020 - SMBUS_BLOCK_PROC_CALL = 0x00008000 # SMBus 2.0 - SMBUS_QUICK = 0x00010000 - SMBUS_READ_BYTE = 0x00020000 - SMBUS_WRITE_BYTE = 0x00040000 - SMBUS_READ_BYTE_DATA = 0x00080000 - SMBUS_WRITE_BYTE_DATA = 0x00100000 - SMBUS_READ_WORD_DATA = 0x00200000 - SMBUS_WRITE_WORD_DATA = 0x00400000 - SMBUS_PROC_CALL = 0x00800000 - SMBUS_READ_BLOCK_DATA = 0x01000000 - SMBUS_WRITE_BLOCK_DATA = 0x02000000 - SMBUS_READ_I2C_BLOCK = 0x04000000 # I2C-like block xfer - SMBUS_WRITE_I2C_BLOCK = 0x08000000 # w/ 1-byte reg. addr. - SMBUS_HOST_NOTIFY = 0x10000000 - - SMBUS_BYTE = 0x00060000 - SMBUS_BYTE_DATA = 0x00180000 - SMBUS_WORD_DATA = 0x00600000 - SMBUS_BLOCK_DATA = 0x03000000 - SMBUS_I2C_BLOCK = 0x0c000000 - SMBUS_EMUL = 0x0eff0008 - - -# i2c_msg flags from uapi/linux/i2c.h -I2C_M_RD = 0x0001 - -# Pointer definitions -LP_c_uint8 = POINTER(c_uint8) -LP_c_uint16 = POINTER(c_uint16) -LP_c_uint32 = POINTER(c_uint32) - - -############################################################# -# Type definitions as in i2c.h - - -class i2c_smbus_data(Array): - """ - Adaptation of the i2c_smbus_data union in ``i2c.h``. - - Data for SMBus messages. - """ - _length_ = I2C_SMBUS_BLOCK_MAX + 2 - _type_ = c_uint8 - - -class union_i2c_smbus_data(Union): - _fields_ = [ - ("byte", c_uint8), - ("word", c_uint16), - ("block", i2c_smbus_data) - ] - - -union_pointer_type = POINTER(union_i2c_smbus_data) - - -class i2c_smbus_ioctl_data(Structure): - """ - As defined in ``i2c-dev.h``. - """ - _fields_ = [ - ('read_write', c_uint8), - ('command', c_uint8), - ('size', c_uint32), - ('data', union_pointer_type)] - __slots__ = [name for name, type in _fields_] - - @staticmethod - def create(read_write=I2C_SMBUS_READ, command=0, size=I2C_SMBUS_BYTE_DATA): - u = union_i2c_smbus_data() - return i2c_smbus_ioctl_data( - read_write=read_write, command=command, size=size, - data=union_pointer_type(u)) - - -############################################################# -# Type definitions for i2c_rdwr combined transactions - - -class i2c_msg(Structure): - """ - As defined in ``i2c.h``. - """ - _fields_ = [ - ('addr', c_uint16), - ('flags', c_uint16), - ('len', c_uint16), - ('buf', POINTER(c_char))] - - def __iter__(self): - """ Iterator / Generator - - :return: iterates over :py:attr:`buf` - :rtype: :py:class:`generator` which returns int values - """ - idx = 0 - while idx < self.len: - yield ord(self.buf[idx]) - idx += 1 - - def __len__(self): - return self.len - - def __bytes__(self): - return string_at(self.buf, self.len) - - def __repr__(self): - return 'i2c_msg(%d,%d,%r)' % (self.addr, self.flags, self.__bytes__()) - - def __str__(self): - s = self.__bytes__() - if sys.version_info.major >= 3: - s = ''.join(map(chr, s)) - return s - - @staticmethod - def read(address, length): - """ - Prepares an i2c read transaction. - - :param address: Slave address. - :type: address: int - :param length: Number of bytes to read. - :type: length: int - :return: New :py:class:`i2c_msg` instance for read operation. - :rtype: :py:class:`i2c_msg` - """ - arr = create_string_buffer(length) - return i2c_msg( - addr=address, flags=I2C_M_RD, len=length, - buf=arr) - - @staticmethod - def write(address, buf): - """ - Prepares an i2c write transaction. - - :param address: Slave address. - :type address: int - :param buf: Bytes to write. Either list of values or str. - :type buf: list - :return: New :py:class:`i2c_msg` instance for write operation. - :rtype: :py:class:`i2c_msg` - """ - if sys.version_info.major >= 3: - if type(buf) is str: - buf = bytes(map(ord, buf)) - else: - buf = bytes(buf) - else: - if type(buf) is not str: - buf = ''.join([chr(x) for x in buf]) - arr = create_string_buffer(buf, len(buf)) - return i2c_msg( - addr=address, flags=0, len=len(arr), - buf=arr) - - -class i2c_rdwr_ioctl_data(Structure): - """ - As defined in ``i2c-dev.h``. - """ - _fields_ = [ - ('msgs', POINTER(i2c_msg)), - ('nmsgs', c_uint32) - ] - __slots__ = [name for name, type in _fields_] - - @staticmethod - def create(*i2c_msg_instances): - """ - Factory method for creating a i2c_rdwr_ioctl_data struct that can - be called with ``ioctl(fd, I2C_RDWR, data)``. - - :param i2c_msg_instances: Up to 42 i2c_msg instances - :rtype: i2c_rdwr_ioctl_data - """ - n_msg = len(i2c_msg_instances) - msg_array = (i2c_msg * n_msg)(*i2c_msg_instances) - return i2c_rdwr_ioctl_data( - msgs=msg_array, - nmsgs=n_msg - ) - - -############################################################# - - -class SMBus(object): - - def __init__(self, bus=None, force=False): - """ - Initialize and (optionally) open an i2c bus connection. - - :param bus: i2c bus number (e.g. 0 or 1) - or an absolute file path (e.g. `/dev/i2c-42`). - If not given, a subsequent call to ``open()`` is required. - :type bus: int or str - :param force: force using the slave address even when driver is - already using it. - :type force: boolean - """ - self.fd = None - self.funcs = I2cFunc(0) - if bus is not None: - self.open(bus) - self.address = None - self.force = force - self._force_last = None - - def __enter__(self): - """Enter handler.""" - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - """Exit handler.""" - self.close() - - def open(self, bus): - """ - Open a given i2c bus. - - :param bus: i2c bus number (e.g. 0 or 1) - or an absolute file path (e.g. '/dev/i2c-42'). - :type bus: int or str - :raise TypeError: if type(bus) is not in (int, str) - """ - if isinstance(bus, int): - filepath = "/dev/i2c-{}".format(bus) - elif isinstance(bus, str): - filepath = bus - else: - raise TypeError("Unexpected type(bus)={}".format(type(bus))) - - self.fd = os.open(filepath, os.O_RDWR) - self.funcs = self._get_funcs() - - def close(self): - """ - Close the i2c connection. - """ - if self.fd: - os.close(self.fd) - self.fd = None - - def _set_address(self, address, force=None): - """ - Set i2c slave address to use for subsequent calls. - - :param address: - :type address: int - :param force: - :type force: Boolean - """ - force = force if force is not None else self.force - if self.address != address or self._force_last != force: - if force is True: - ioctl(self.fd, I2C_SLAVE_FORCE, address) - else: - ioctl(self.fd, I2C_SLAVE, address) - self.address = address - self._force_last = force - - def _get_funcs(self): - """ - Returns a 32-bit value stating supported I2C functions. - - :rtype: int - """ - f = c_uint32() - ioctl(self.fd, I2C_FUNCS, f) - return f.value - - def write_quick(self, i2c_addr, force=None): - """ - Perform quick transaction. Throws IOError if unsuccessful. - :param i2c_addr: i2c address - :type i2c_addr: int - :param force: - :type force: Boolean - """ - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=0, size=I2C_SMBUS_QUICK) - ioctl(self.fd, I2C_SMBUS, msg) - - def read_byte(self, i2c_addr, force=None): - """ - Read a single byte from a device. - - :rtype: int - :param i2c_addr: i2c address - :type i2c_addr: int - :param force: - :type force: Boolean - :return: Read byte value - """ - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_READ, command=0, size=I2C_SMBUS_BYTE - ) - ioctl(self.fd, I2C_SMBUS, msg) - return msg.data.contents.byte - - def write_byte(self, i2c_addr, value, force=None): - """ - Write a single byte to a device. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param value: value to write - :type value: int - :param force: - :type force: Boolean - """ - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=value, size=I2C_SMBUS_BYTE - ) - ioctl(self.fd, I2C_SMBUS, msg) - - def read_byte_data(self, i2c_addr, register, force=None): - """ - Read a single byte from a designated register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Register to read - :type register: int - :param force: - :type force: Boolean - :return: Read byte value - :rtype: int - """ - val_t = -1 - returnmsg="" - try: - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_READ, command=register, size=I2C_SMBUS_BYTE_DATA - ) - val_t = ioctl(self.fd, I2C_SMBUS, msg) - except Exception as e: - self.close() - returnmsg = str(e) - if val_t < 0: - return False, returnmsg - else: - return True, msg.data.contents.byte - - def write_byte_data(self, i2c_addr, register, value, force=None): - """ - Write a byte to a given register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Register to write to - :type register: int - :param value: Byte value to transmit - :type value: int - :param force: - :type force: Boolean - :rtype: None - """ - val_t = -1 - returnmsg = "" - try: - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_BYTE_DATA - ) - msg.data.contents.byte = value - val_t = ioctl(self.fd, I2C_SMBUS, msg) - except Exception as e: - returnmsg = str(e) - self.close() - if val_t < 0: - return False, returnmsg or "" - else: - return True, "" - - def write_byte_data_pec(self, i2c_addr, register, value, force=None): - """ - Write a byte to a given register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Register to write to - :type register: int - :param value: Byte value to transmit - :type value: int - :param force: - :type force: Boolean - :rtype: None - """ - val_t = -1 - returnmsg = "" - try: - val_t = ioctl(self.fd, I2C_PEC, 1) - if val_t < 0: - raise Exception("set pec mod error") - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_BYTE_DATA - ) - msg.data.contents.byte = value - val_t = ioctl(self.fd, I2C_SMBUS, msg) - except Exception as e: - returnmsg = str(e) - self.close() - if val_t < 0: - return False, returnmsg or "" - else: - return True, "" - - def read_word_data(self, i2c_addr, register, force=None): - """ - Read a single word (2 bytes) from a given register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Register to read - :type register: int - :param force: - :type force: Boolean - :return: 2-byte word - :rtype: int - """ - val_t = -1 - returnmsg = "" - try: - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_READ, command=register, size=I2C_SMBUS_WORD_DATA - ) - val_t = ioctl(self.fd, I2C_SMBUS, msg) - except Exception as e: - returnmsg = str(e) - self.close() - if val_t < 0: - return False, returnmsg or "" - else: - return True, msg.data.contents.word - - def write_word_data_pec(self, i2c_addr, register, value, force=None): - """ - Write a byte to a given register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Register to write to - :type register: int - :param value: Word value to transmit - :type value: int - :param force: - :type force: Boolean - :rtype: None - """ - val_t = -1 - returnmsg = "" - try: - val_t = ioctl(self.fd, I2C_PEC, 1) - if val_t < 0: - raise Exception("set pec mod error") - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_WORD_DATA - ) - msg.data.contents.word = value - val_t = ioctl(self.fd, I2C_SMBUS, msg) - except Exception as e: - returnmsg = str(e) - self.close() - if val_t < 0: - return False, returnmsg or "" - else: - return True, "" - - def write_word_data(self, i2c_addr, register, value, force=None): - """ - Write a byte to a given register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Register to write to - :type register: int - :param value: Word value to transmit - :type value: int - :param force: - :type force: Boolean - :rtype: None - """ - val_t = -1 - returnmsg = "" - try: - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_WORD_DATA - ) - msg.data.contents.word = value - val_t = ioctl(self.fd, I2C_SMBUS, msg) - except Exception as e: - returnmsg = str(e) - self.close() - if val_t < 0: - return False, returnmsg or "" - else: - return True, "" - - def process_call(self, i2c_addr, register, value, force=None): - """ - Executes a SMBus Process Call, sending a 16-bit value and receiving a 16-bit response - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Register to read/write to - :type register: int - :param value: Word value to transmit - :type value: int - :param force: - :type force: Boolean - :rtype: int - """ - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_PROC_CALL - ) - msg.data.contents.word = value - ioctl(self.fd, I2C_SMBUS, msg) - return msg.data.contents.word - - def read_block_data(self, i2c_addr, register, force=None): - """ - Read a block of up to 32-bytes from a given register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Start register - :type register: int - :param force: - :type force: Boolean - :return: List of bytes - :rtype: list - """ - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_READ, command=register, size=I2C_SMBUS_BLOCK_DATA - ) - ioctl(self.fd, I2C_SMBUS, msg) - length = msg.data.contents.block[0] - return msg.data.contents.block[1:length + 1] - - def write_block_data(self, i2c_addr, register, data, force=None): - """ - Write a block of byte data to a given register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Start register - :type register: int - :param data: List of bytes - :type data: list - :param force: - :type force: Boolean - :rtype: None - """ - length = len(data) - if length > I2C_SMBUS_BLOCK_MAX: - raise ValueError("Data length cannot exceed %d bytes" % I2C_SMBUS_BLOCK_MAX) - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_BLOCK_DATA - ) - msg.data.contents.block[0] = length - msg.data.contents.block[1:length + 1] = data - ioctl(self.fd, I2C_SMBUS, msg) - - def block_process_call(self, i2c_addr, register, data, force=None): - """ - Executes a SMBus Block Process Call, sending a variable-size data - block and receiving another variable-size response - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Register to read/write to - :type register: int - :param data: List of bytes - :type data: list - :param force: - :type force: Boolean - :return: List of bytes - :rtype: list - """ - length = len(data) - if length > I2C_SMBUS_BLOCK_MAX: - raise ValueError("Data length cannot exceed %d bytes" % I2C_SMBUS_BLOCK_MAX) - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_BLOCK_PROC_CALL - ) - msg.data.contents.block[0] = length - msg.data.contents.block[1:length + 1] = data - ioctl(self.fd, I2C_SMBUS, msg) - length = msg.data.contents.block[0] - return msg.data.contents.block[1:length + 1] - - def read_i2c_block_data(self, i2c_addr, register, length, force=None): - """ - Read a block of byte data from a given register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Start register - :type register: int - :param length: Desired block length - :type length: int - :param force: - :type force: Boolean - :return: List of bytes - :rtype: list - """ - if length > I2C_SMBUS_BLOCK_MAX: - raise ValueError("Desired block length over %d bytes" % I2C_SMBUS_BLOCK_MAX) - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_READ, command=register, size=I2C_SMBUS_I2C_BLOCK_DATA - ) - msg.data.contents.byte = length - ioctl(self.fd, I2C_SMBUS, msg) - return msg.data.contents.block[1:length + 1] - - def write_i2c_block_data(self, i2c_addr, register, data, force=None): - """ - Write a block of byte data to a given register. - - :param i2c_addr: i2c address - :type i2c_addr: int - :param register: Start register - :type register: int - :param data: List of bytes - :type data: list - :param force: - :type force: Boolean - :rtype: None - """ - length = len(data) - if length > I2C_SMBUS_BLOCK_MAX: - raise ValueError("Data length cannot exceed %d bytes" % I2C_SMBUS_BLOCK_MAX) - self._set_address(i2c_addr, force=force) - msg = i2c_smbus_ioctl_data.create( - read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_I2C_BLOCK_DATA - ) - msg.data.contents.block[0] = length - msg.data.contents.block[1:length + 1] = data - ioctl(self.fd, I2C_SMBUS, msg) - - def i2c_rdwr(self, *i2c_msgs): - """ - Combine a series of i2c read and write operations in a single - transaction (with repeated start bits but no stop bits in between). - - This method takes i2c_msg instances as input, which must be created - first with :py:meth:`i2c_msg.read` or :py:meth:`i2c_msg.write`. - - :param i2c_msgs: One or more i2c_msg class instances. - :type i2c_msgs: i2c_msg - :rtype: None - """ - ioctl_data = i2c_rdwr_ioctl_data.create(*i2c_msgs) - ioctl(self.fd, I2C_RDWR, ioctl_data) - - -class SMBusWrapper: - """ - Wrapper class around the SMBus. - Deprecated as of version 0.3.0. Please replace with :py:class:`SMBus`. - - Enables the user to wrap access to the :py:class:`SMBus` class in a - "with" statement. If auto_cleanup is True (default), the - :py:class:`SMBus` handle will be automatically closed - upon exit of the ``with`` block. - """ - def __init__(self, bus_number=0, auto_cleanup=True, force=False): - """ - :param auto_cleanup: Close bus when leaving scope. - :type auto_cleanup: Boolean - :param force: Force using the slave address even when driver is already using it. - :type force: Boolean - """ - self.bus_number = bus_number - self.auto_cleanup = auto_cleanup - self.force = force - - def __enter__(self): - self.bus = SMBus(bus=self.bus_number, force=self.force) - return self.bus - - def __exit__(self, exc_type, exc_val, exc_tb): - if self.auto_cleanup: - self.bus.close() diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/Makefile b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/Makefile deleted file mode 100644 index 78ef5b8b81..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -PWD = $(shell pwd) -EXTRA_CFLAGS:= -I$(M)/include -EXTRA_CFLAGS+= -Wall -KVERSION ?= $(shell uname -r) -KERNEL_SRC ?= /lib/modules/$(KVERSION) - -module_out_put_dir := $(PWD)/build -export module_out_put_dir - -ragile_common-objs := ragile_common_module.o dfd_tlveeprom.o -obj-m += ragile_platform.o -obj-m += i2c-mux-pca9641.o -obj-m += i2c-mux-pca954x.o -obj-m += ragile_common.o -obj-m += rtcpcf85063.o -#obj-m += tpm_tis_core.o -#obj-m += rg_spi_gpio.o -#obj-m += spi-gpio.o -#obj-m += tpm_tis_spi.o -obj-m += optoe.o -obj-m += rg_at24.o - -all : - $(MAKE) -C $(KERNEL_SRC)/build M=$(PWD) modules - @if [ ! -d $(module_out_put_dir) ]; then mkdir -p $(module_out_put_dir) ;fi - cp -p $(PWD)/*.ko $(module_out_put_dir) - -clean : - rm -rf $(module_out_put_dir) - rm -f ${PWD}/*.o ${PWD}/*.ko ${PWD}/*.mod.c ${PWD}/.*.cmd ${PWD}/.*.o.d - rm -f ${PWD}/Module.markers ${PWD}/Module.symvers ${PWD}/modules.order - rm -rf ${PWD}/.tmp_versions diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/dfd_tlveeprom.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/dfd_tlveeprom.c deleted file mode 100644 index 99bf3eed80..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/dfd_tlveeprom.c +++ /dev/null @@ -1,521 +0,0 @@ -/* - * Copyright (C) 2003-2014 FreeIPMI Core Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -/*****************************************************************************\ - * Copyright (C) 2007-2014 Lawrence Livermore National Security, LLC. - * Copyright (C) 2007 The Regents of the University of California. - * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). - * Written by Albert Chu - * UCRL-CODE-232183 - * - * This file is part of Ipmi-fru, a tool used for retrieving - * motherboard field replaceable unit (FRU) information. For details, - * see http://www.llnl.gov/linux/. - * - * Ipmi-fru is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 3 of the License, or (at your - * option) any later version. - * - * Ipmi-fru is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with Ipmi-fru. If not, see . -\*****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ragile.h" -#include "dfd_tlveeprom.h" - -/* using in is_valid_tlvinfo_header */ -static u_int32_t eeprom_size; - -/* - * List of TLV codes and names. - */ -static const struct tlv_code_desc tlv_code_list[] = { - { TLV_CODE_PRODUCT_NAME , "Product Name"}, - { TLV_CODE_PART_NUMBER , "Part Number"}, - { TLV_CODE_SERIAL_NUMBER , "Serial Number"}, - { TLV_CODE_MAC_BASE , "Base MAC Address"}, - { TLV_CODE_MANUF_DATE , "Manufacture Date"}, - { TLV_CODE_DEVICE_VERSION , "Device Version"}, - { TLV_CODE_LABEL_REVISION , "Label Revision"}, - { TLV_CODE_PLATFORM_NAME , "Platform Name"}, - { TLV_CODE_ONIE_VERSION , "ONIE Version"}, - { TLV_CODE_MAC_SIZE , "MAC Addresses"}, - { TLV_CODE_MANUF_NAME , "Manufacturer"}, - { TLV_CODE_MANUF_COUNTRY , "Country Code"}, - { TLV_CODE_VENDOR_NAME , "Vendor Name"}, - { TLV_CODE_DIAG_VERSION , "Diag Version"}, - { TLV_CODE_SERVICE_TAG , "Service Tag"}, - { TLV_CODE_VENDOR_EXT , "Vendor Extension"}, - { TLV_CODE_CRC_32 , "CRC-32"}, -}; - -#if 0 -#define OPENBMC_VPD_KEY_INVAIL_VAL 0 - -static const tlv_code_map_t tlv_code_map[] = { - { TLV_CODE_PRODUCT_NAME , OPENBMC_VPD_KEY_PRODUCT_NAME}, - { TLV_CODE_PART_NUMBER , OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM}, - { TLV_CODE_SERIAL_NUMBER , OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM}, - { TLV_CODE_MAC_BASE , OPENBMC_VPD_KEY_INVAIL_VAL}, - { TLV_CODE_MANUF_DATE , OPENBMC_VPD_KEY_BOARD_MFG_DATE}, - { TLV_CODE_DEVICE_VERSION , OPENBMC_VPD_KEY_PRODUCT_VER}, - { TLV_CODE_LABEL_REVISION , OPENBMC_VPD_KEY_PRODUCT_CUSTOM7}, - { TLV_CODE_PLATFORM_NAME , OPENBMC_VPD_KEY_PRODUCT_CUSTOM1}, - { TLV_CODE_ONIE_VERSION , OPENBMC_VPD_KEY_PRODUCT_CUSTOM2}, - { TLV_CODE_MAC_SIZE , OPENBMC_VPD_KEY_INVAIL_VAL}, - { TLV_CODE_MANUF_NAME , OPENBMC_VPD_KEY_PRODUCT_MFR}, - { TLV_CODE_MANUF_COUNTRY , OPENBMC_VPD_KEY_PRODUCT_CUSTOM3}, - { TLV_CODE_VENDOR_NAME , OPENBMC_VPD_KEY_PRODUCT_CUSTOM4}, - { TLV_CODE_DIAG_VERSION , OPENBMC_VPD_KEY_PRODUCT_CUSTOM8}, - { TLV_CODE_SERVICE_TAG , OPENBMC_VPD_KEY_PRODUCT_CUSTOM5}, - { TLV_CODE_VENDOR_EXT , OPENBMC_VPD_KEY_PRODUCT_CUSTOM6}, - { TLV_CODE_CRC_32 , OPENBMC_VPD_KEY_INVAIL_VAL}, -}; -#endif - -#define TLV_CODE_NUM (sizeof(tlv_code_list) / sizeof(tlv_code_list[0])) - -#if 0 -#define TLV_CODE_MAP_NUM (sizeof(tlv_code_map) / sizeof(tlv_code_map[0])) -#endif - -const unsigned long crc_table[] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, - 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, - 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, - 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, - 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, - 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, - 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, - 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, - 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, - 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, - 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, - 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, - 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, - 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, -}; - -static unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned len) -{ - unsigned i; - if (len < 1) - return 0xffffffff; - - for (i = 0; i != len; ++i) - { - crc = crc_table[(crc ^ buf[i]) & 0xff] ^ (crc >> 8); - } - - crc = crc ^ 0xffffffff; - - return crc; -} - -/* - * is_valid_tlv - * - * Perform basic sanity checks on a TLV field. The TLV is pointed to - * by the parameter provided. - * 1. The type code is not reserved (0x00 or 0xFF) - */ -static inline bool is_valid_tlv(tlvinfo_tlv_t *tlv) -{ - return ((tlv->type != 0x00) && (tlv->type != 0xFF)); -} - -/* - * is_valid_tlvinfo_header - * - * Perform sanity checks on the first 11 bytes of the TlvInfo EEPROM - * data pointed to by the parameter: - * 1. First 8 bytes contain null-terminated ASCII string "TlvInfo" - * 2. Version byte is 1 - * 3. Total length bytes contain value which is less than or equal - * to the allowed maximum (2048-11) - * - */ -static inline bool is_valid_tlvinfo_header(tlvinfo_header_t *hdr) -{ - int max_size = eeprom_size; - return((strcmp(hdr->signature, TLV_INFO_ID_STRING) == 0) && - (hdr->version == TLV_INFO_VERSION) && - (be16_to_cpu(hdr->totallen) <= max_size) ); -} - -/* - * decode_tlv_value - * - * Decode a single TLV value into a string. - - * The validity of EEPROM contents and the TLV field have been verified - * prior to calling this function. - */ -static void decode_tlv_value(tlvinfo_tlv_t *tlv, tlv_decode_value_t *decode_value) -{ - int i; - char *value; - u_int32_t length; - - value = (char *)decode_value->value; - - switch (tlv->type) { - case TLV_CODE_PRODUCT_NAME: - case TLV_CODE_PART_NUMBER: - case TLV_CODE_SERIAL_NUMBER: - case TLV_CODE_MANUF_DATE: - case TLV_CODE_LABEL_REVISION: - case TLV_CODE_PLATFORM_NAME: - case TLV_CODE_ONIE_VERSION: - case TLV_CODE_MANUF_NAME: - case TLV_CODE_MANUF_COUNTRY: - case TLV_CODE_VENDOR_NAME: - case TLV_CODE_DIAG_VERSION: - case TLV_CODE_SERVICE_TAG: - case TLV_CODE_VENDOR_EXT: - memcpy(value, tlv->value, tlv->length); - value[tlv->length] = 0; - length = tlv->length; - break; - case TLV_CODE_MAC_BASE: - length = sprintf(value, "%02X:%02X:%02X:%02X:%02X:%02X", - tlv->value[0], tlv->value[1], tlv->value[2], - tlv->value[3], tlv->value[4], tlv->value[5]); - break; - case TLV_CODE_DEVICE_VERSION: - length = sprintf(value, "%u", tlv->value[0]); - break; - case TLV_CODE_MAC_SIZE: - length = sprintf(value, "%u", (tlv->value[0] << 8) | tlv->value[1]); - break; - #if 0 - case TLV_CODE_VENDOR_EXT: - value[0] = 0; - length = 0; - for (i = 0; (i < (TLV_DECODE_VALUE_MAX_LEN/5)) && (i < tlv->length); i++) { - length += sprintf(value, "%s 0x%02X", value, tlv->value[i]); - } - break; - #endif - case TLV_CODE_CRC_32: - length = sprintf(value, "0x%02X%02X%02X%02X", tlv->value[0], - tlv->value[1], tlv->value[2], tlv->value[3]); - break; - default: - value[0] = 0; - length = 0; - for (i = 0; (i < (TLV_DECODE_VALUE_MAX_LEN/5)) && (i < tlv->length); i++) { - length += sprintf(value, "%s 0x%02X", value, tlv->value[i]); - } - break; - } - - decode_value->length = length; -} - -/* - * is_checksum_valid - * - * Validate the checksum in the provided TlvInfo EEPROM data. First, - * verify that the TlvInfo header is valid, then make sure the last - * TLV is a CRC-32 TLV. Then calculate the CRC over the EEPROM data - * and compare it to the value stored in the EEPROM CRC-32 TLV. - */ -static bool is_checksum_valid(u_int8_t *eeprom) -{ - tlvinfo_header_t *eeprom_hdr; - tlvinfo_tlv_t *eeprom_crc; - unsigned int calc_crc; - unsigned int stored_crc; - - eeprom_hdr = (tlvinfo_header_t *) eeprom; - - /* Is the eeprom header valid? */ - if (!is_valid_tlvinfo_header(eeprom_hdr)) { - return false; - } - - /* Is the last TLV a CRC? */ - eeprom_crc = (tlvinfo_tlv_t *) &eeprom[sizeof(tlvinfo_header_t) + - be16_to_cpu(eeprom_hdr->totallen) - (sizeof(tlvinfo_tlv_t) + 4)]; - if ((eeprom_crc->type != TLV_CODE_CRC_32) || (eeprom_crc->length != 4)) { - return false; - } - - /* Calculate the checksum */ - calc_crc = crc32(0xffffffffL, (const unsigned char *)eeprom, sizeof(tlvinfo_header_t) + - be16_to_cpu(eeprom_hdr->totallen) - 4); - stored_crc = ((eeprom_crc->value[0] << 24) | (eeprom_crc->value[1] << 16) | - (eeprom_crc->value[2] << 8) | eeprom_crc->value[3]); - - return (calc_crc == stored_crc); -} - -/* - * tlvinfo_find_tlv - * - * This function finds the TLV with the supplied code in the EERPOM. - * An offset from the beginning of the EEPROM is returned in the - * eeprom_index parameter if the TLV is found. - */ -static bool tlvinfo_find_tlv(u_int8_t *eeprom, u_int8_t tcode, int *eeprom_index) -{ - tlvinfo_header_t *eeprom_hdr; - tlvinfo_tlv_t *eeprom_tlv; - int eeprom_end; - - eeprom_hdr = (tlvinfo_header_t *) eeprom; - - /* Search through the TLVs, looking for the first one which matches the - supplied type code. */ - *eeprom_index = sizeof(tlvinfo_header_t); - eeprom_end = sizeof(tlvinfo_header_t) + be16_to_cpu(eeprom_hdr->totallen); - while (*eeprom_index < eeprom_end) { - eeprom_tlv = (tlvinfo_tlv_t *) &eeprom[*eeprom_index]; - if (!is_valid_tlv(eeprom_tlv)) { - return false; - } - - if (eeprom_tlv->type == tcode) { - return true; - } - - *eeprom_index += sizeof(tlvinfo_tlv_t) + eeprom_tlv->length; - } - - return false; -} - -/* - * tlvinfo_decode_tlv - * - * This function finds the TLV with the supplied code in the EERPOM - * and decodes the value into the buffer provided. - */ -static bool tlvinfo_decode_tlv(u_int8_t *eeprom, u_int8_t tcode, tlv_decode_value_t *decode_value) -{ - int eeprom_index; - tlvinfo_tlv_t *eeprom_tlv; - - /* Find the TLV and then decode it */ - if (tlvinfo_find_tlv(eeprom, tcode, &eeprom_index)) { - eeprom_tlv = (tlvinfo_tlv_t *) &eeprom[eeprom_index]; - decode_tlv_value(eeprom_tlv, decode_value); - return true; - } - - return false; -} - -/* - * parse_tlv_eeprom - * - * parse the EEPROM into memory, if it hasn't already been read. - */ -int parse_tlv_eeprom(u_int8_t *eeprom, u_int32_t size) -{ - unsigned int i; - bool ret; - tlvinfo_header_t *eeprom_hdr; - //tlv_info_vec_t tlv_info; - tlv_decode_value_t decode_value; - int j; - - eeprom_hdr = (tlvinfo_header_t *) eeprom; - eeprom_size = size; /* eeprom real size */ - - if (!is_valid_tlvinfo_header(eeprom_hdr)) { - DBG_ERROR("Failed to check tlv header.\n"); - return -1; - } - - if (!is_checksum_valid(eeprom)) { - DBG_ERROR("Failed to check tlv crc.\n"); - return -1; - } - - for (i = 0; i < TLV_CODE_NUM; i++) { - mem_clear((void *)&decode_value, sizeof(tlv_decode_value_t)); - ret = tlvinfo_decode_tlv(eeprom, tlv_code_list[i].m_code, &decode_value); - if (!ret) { - DBG_ERROR("No found type: %s\n", tlv_code_list[i].m_name); - continue; - } - - DBG_DEBUG("i: %d,Found type: %s tlv[%d]:%s\n", i, tlv_code_list[i].m_name, tlv_code_list[i].m_code, - decode_value.value); - for (j = 0; j < decode_value.length; j++) { - if ((j % 16) == 0) { - DBG_DEBUG("\n"); - } - DBG_DEBUG("%02x ", decode_value.value[j]); - } - DBG_DEBUG("\n\n"); - } - return 0; -} -static int dfd_parse_tlv_eeprom(u_int8_t *eeprom, u_int32_t size, u_int8_t main_type, tlv_decode_value_t *decode_value) -{ - bool ret; - tlvinfo_header_t *eeprom_hdr; - /* tlv_info_vec_t tlv_info; */ - int j; - - eeprom_hdr = (tlvinfo_header_t *) eeprom; - eeprom_size = size; /* eeprom real size */ - - if (!is_valid_tlvinfo_header(eeprom_hdr)) { - DBG_ERROR("Failed to check tlv header.\n"); - return -1; - } - - if (!is_checksum_valid(eeprom)) { - DBG_ERROR("Failed to check tlv crc.\n"); - return -1; - } - - ret = tlvinfo_decode_tlv(eeprom, main_type, decode_value); - if (!ret) { - DBG_ERROR("No found type: %d\n", main_type); - return -1; - } - - DBG_DEBUG("Found type: %d, value: %s\n", main_type,decode_value->value); - for (j = 0; j < decode_value->length; j++) { - if ((j % 16) == 0) { - DBG_DEBUG("\n"); - } - DBG_DEBUG("%02x ", decode_value->value[j]); - } - DBG_DEBUG("\n\n"); - - return 0; -} - -/* analyze the extended custom TLV format */ -static int tlvinfo_find_rg_ext_tlv(tlv_decode_value_t *ext_tlv_value, u_int8_t ext_type, - u_int8_t *buf, u_int8_t *buf_len) -{ - tlvinfo_tlv_t *eeprom_tlv; - int eeprom_end, eeprom_index; - - /* Search through the TLVs, looking for the first one which matches the - supplied type code. */ - DBG_DEBUG("ext_tlv_value->length: %d.\n", ext_tlv_value->length); - for (eeprom_index = 0; eeprom_index < ext_tlv_value->length; eeprom_index++) { - if ((eeprom_index % 16) == 0) { - DBG_DEBUG("\n"); - } - DBG_DEBUG("%02x ", ext_tlv_value->value[eeprom_index]); - } - - DBG_DEBUG("\n"); - - eeprom_index = 0; - eeprom_end = ext_tlv_value->length; - while (eeprom_index < eeprom_end) { - eeprom_tlv = (tlvinfo_tlv_t *) &(ext_tlv_value->value[eeprom_index]); - if (!is_valid_tlv(eeprom_tlv)) { - DBG_ERROR("tlv is not valid, eeprom_tlv->type 0x%x.\n", eeprom_tlv->type); - return -1; - } - - DBG_DEBUG("eeprom_tlv->length %d.\n", eeprom_tlv->length); - if (eeprom_tlv->type == ext_type) { - if (*buf_len >= eeprom_tlv->length) { - memcpy(buf, eeprom_tlv->value, eeprom_tlv->length); - DBG_DEBUG("eeprom_tlv->length %d.\n", eeprom_tlv->length); - *buf_len = eeprom_tlv->length; - return 0; - } - DBG_ERROR("buf_len %d small than info_len %d.\n", *buf_len, eeprom_tlv->length); - return -1; - } - - eeprom_index += sizeof(tlvinfo_tlv_t) + eeprom_tlv->length; - } - - DBG_ERROR("ext_type %d: tlv is not found.\n", ext_type); - return -1; -} - -/* get EEPROM information */ -int dfd_tlvinfo_get_e2prom_info(u_int8_t *eeprom, u_int32_t size, dfd_tlv_type_t *tlv_type, u_int8_t* buf, u_int8_t *buf_len) -{ - tlv_decode_value_t decode_value; - int ret; - - if (eeprom == NULL || tlv_type == NULL || buf == NULL) { - DBG_ERROR("Input para invalid.\n"); - return -1; - } - - mem_clear((void *)&decode_value, sizeof(tlv_decode_value_t)); - ret = dfd_parse_tlv_eeprom(eeprom, size, tlv_type->main_type, &decode_value); - if (ret) { - DBG_ERROR("dfd_parse_tlv_eeprom failed ret %d.\n", ret); - return ret; - } - - /* For non-extended types, return data directly */ - if (tlv_type->main_type != TLV_CODE_VENDOR_EXT) { - if (*buf_len >= decode_value.length) { - memcpy(buf, decode_value.value, decode_value.length); - *buf_len = decode_value.length; - return 0; - } - DBG_ERROR("buf_len %d small than info_len %d.\n", *buf_len, decode_value.length); - return -1; - } - DBG_DEBUG("info_len %d.\n", decode_value.length); - - /* For the extended type, continue with the secondary TLV analysis to obtain - the data corresponding to the sub-TLV type */ - return tlvinfo_find_rg_ext_tlv(&decode_value, tlv_type->ext_type, buf, buf_len); -} diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/dfd_tlveeprom.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/dfd_tlveeprom.h deleted file mode 100644 index 6c5b2e98be..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/dfd_tlveeprom.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef DFD_OPENBMC_TLVEEPROM_H -#define DFD_OPENBMC_TLVEEPROM_H - -#ifndef u_int8_t -#define u_int8_t unsigned char -#endif - -#ifndef u_int16_t -#define u_int16_t unsigned short -#endif - -#ifndef u_int32_t -#define u_int32_t unsigned int -#endif - -#ifndef be16_to_cpu -#define be16_to_cpu(x) ntohs(x) -#endif - -#ifndef cpu_to_be16 -#define cpu_to_be16(x) htons(x) -#endif - -/** - * The TLV Types. - * - * Keep these in sync with tlv_code_list in cmd_sys_eeprom.c - */ -#define TLV_CODE_PRODUCT_NAME 0x21 -#define TLV_CODE_PART_NUMBER 0x22 -#define TLV_CODE_SERIAL_NUMBER 0x23 -#define TLV_CODE_MAC_BASE 0x24 -#define TLV_CODE_MANUF_DATE 0x25 -#define TLV_CODE_DEVICE_VERSION 0x26 -#define TLV_CODE_LABEL_REVISION 0x27 -#define TLV_CODE_PLATFORM_NAME 0x28 -#define TLV_CODE_ONIE_VERSION 0x29 -#define TLV_CODE_MAC_SIZE 0x2A -#define TLV_CODE_MANUF_NAME 0x2B -#define TLV_CODE_MANUF_COUNTRY 0x2C -#define TLV_CODE_VENDOR_NAME 0x2D -#define TLV_CODE_DIAG_VERSION 0x2E -#define TLV_CODE_SERVICE_TAG 0x2F -#define TLV_CODE_VENDOR_EXT 0xFD -#define TLV_CODE_CRC_32 0xFE - -#define TLV_CODE_NAME_LEN 64 -/* - * Struct for displaying the TLV codes and names. - */ -struct tlv_code_desc { - u_int8_t m_code; - char m_name[TLV_CODE_NAME_LEN]; -}; -/* ONIE TLV Type and Extended TLV Type Definition */ -typedef struct dfd_tlv_type_s { - u_int8_t main_type;/* ONIE standard TLV TYPE type */ - u_int8_t ext_type; /* Extended TLV TYPE type */ -} dfd_tlv_type_t; - -/* Header Field Constants */ -#define TLV_INFO_ID_STRING "TlvInfo" -#define TLV_INFO_VERSION 0x01 -/*#define TLV_TOTAL_LEN_MAX (XXXXXXXX - sizeof(tlvinfo_header_t))*/ - -struct __attribute__ ((__packed__)) tlvinfo_header_s { - char signature[8]; /* 0x00 - 0x07 EEPROM Tag "TlvInfo" */ - u_int8_t version; /* 0x08 Structure version */ - u_int16_t totallen; /* 0x09 - 0x0A Length of all data which follows */ -}; -typedef struct tlvinfo_header_s tlvinfo_header_t; - -/* - * TlvInfo TLV: Layout of a TLV field - */ -struct __attribute__ ((__packed__)) tlvinfo_tlv_s { - u_int8_t type; - u_int8_t length; - u_int8_t value[0]; -}; -typedef struct tlvinfo_tlv_s tlvinfo_tlv_t; - -#define TLV_VALUE_MAX_LEN 255 -/* - * The max decode value is currently for the 'raw' type or the 'vendor - * extension' type, both of which have the same decode format. The - * max decode string size is computed as follows: - * - * strlen(" 0xFF") * TLV_VALUE_MAX_LEN + 1 - * - */ -#define TLV_DECODE_VALUE_MAX_LEN ((5 * TLV_VALUE_MAX_LEN) + 1) - -typedef struct tlv_decode_value_s { - u_int8_t value[TLV_DECODE_VALUE_MAX_LEN]; - u_int32_t length; -} tlv_decode_value_t; - -typedef enum dfd_tlvinfo_ext_tlv_type_e { - DFD_TLVINFO_EXT_TLV_TYPE_DEV_TYPE = 1, -} dfd_tlvinfo_ext_tlv_type_t; - -#if 0 -#define TLV_TIME_LEN 64 - -int ipmi_tlv_validate_fru_area(const uint8_t fruid, const char *fru_file_name, - sd_bus *bus_type, const bool bmc_fru); - -extern const char *get_vpd_key_names(int key_id); -extern std::string getService(sdbusplus::bus::bus& bus, - const std::string& intf, - const std::string& path); -extern std::string getFRUValue(const std::string& section, - const std::string& key, - const std::string& delimiter, - IPMIFruInfo& fruData); -#endif - -int dfd_tlvinfo_get_e2prom_info(u_int8_t *eeprom, u_int32_t size, dfd_tlv_type_t *tlv_type, u_int8_t* buf, u_int8_t *buf_len); - -#endif /* endif DFD_OPENBMC_TLVEEPROM_H */ diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/i2c-mux-pca954x.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/i2c-mux-pca954x.c deleted file mode 100644 index 4a2ffe136b..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/i2c-mux-pca954x.c +++ /dev/null @@ -1,3817 +0,0 @@ -/* - * I2C multiplexer - * - * Copyright (c) 2008-2009 Rodolfo Giometti - * Copyright (c) 2008-2009 Eurotech S.p.A. - * - * This module supports the PCA954x series of I2C multiplexer/switch chips - * made by Philips Semiconductors. - * This includes the: - * PCA9540, PCA9542, PCA9543, PCA9544, PCA9545, PCA9546, PCA9547 - * and PCA9548. - * - * These chips are all controlled via the I2C bus itself, and all have a - * single 8-bit register. The upstream "parent" bus fans out to two, - * four, or eight downstream busses or channels; which of these - * are selected is determined by the chip type and register contents. A - * mux can select only one sub-bus at a time; a switch can select any - * combination simultaneously. - * - * Based on: - * pca954x.c from Kumar Gala - * Copyright (C) 2006 - * - * Based on: - * pca954x.c from Ken Harrenstien - * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) - * - * Based on: - * i2c-virtual_cb.c from Brian Kuschak - * and - * pca9540.c from Jean Delvare . - * - * This file is licensed under the terms of the GNU General Public - * License version 2. This program is licensed "as is" without any - * warranty of any kind, whether express or implied. - */ - -#include -#include - -#define mem_clear(data, size) memset((data), 0, (size)) - -#if LINUX_VERSION_CODE > KERNEL_VERSION(4,0,36) -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PCA954X_MAX_NCHANS 8 - -#define PCA954X_IRQ_OFFSET 4 - -extern int pca9641_setmuxflag(int nr, int flag); - -int force_create_bus = 0; -module_param(force_create_bus, int, S_IRUGO | S_IWUSR); - -enum pca_type { - pca_9540, - pca_9542, - pca_9543, - pca_9544, - pca_9545, - pca_9546, - pca_9547, - pca_9548, -}; - -struct chip_desc { - u8 nchans; - u8 enable; /* used for muxes only */ - u8 has_irq; - enum muxtype { - pca954x_ismux = 0, - pca954x_isswi - } muxtype; -}; - -struct pca954x { - const struct chip_desc *chip; - - u8 last_chan; /* last register value */ - s32 idle_state; - u8 deselect; - struct i2c_client *client; - - struct irq_domain *irq; - unsigned int irq_mask; - raw_spinlock_t lock; -}; - -/* Provide specs for the PCA954x types we know about */ -static const struct chip_desc chips[] = { - [pca_9540] = { - .nchans = 2, - .enable = 0x4, - .muxtype = pca954x_ismux, - }, - [pca_9542] = { - .nchans = 2, - .enable = 0x4, - .has_irq = 1, - .muxtype = pca954x_ismux, - }, - [pca_9543] = { - .nchans = 2, - .has_irq = 1, - .muxtype = pca954x_isswi, - }, - [pca_9544] = { - .nchans = 4, - .enable = 0x4, - .has_irq = 1, - .muxtype = pca954x_ismux, - }, - [pca_9545] = { - .nchans = 4, - .has_irq = 1, - .muxtype = pca954x_isswi, - }, - [pca_9546] = { - .nchans = 4, - .muxtype = pca954x_isswi, - }, - [pca_9547] = { - .nchans = 8, - .enable = 0x8, - .muxtype = pca954x_ismux, - }, - [pca_9548] = { - .nchans = 8, - .muxtype = pca954x_isswi, - }, -}; - -static const struct i2c_device_id pca954x_id[] = { - { "pca9540", pca_9540 }, - { "pca9542", pca_9542 }, - { "pca9543", pca_9543 }, - { "pca9544", pca_9544 }, - { "pca9545", pca_9545 }, - { "pca9546", pca_9546 }, - { "pca9547", pca_9547 }, - { "pca9548", pca_9548 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, pca954x_id); - -#ifdef CONFIG_OF -static const struct of_device_id pca954x_of_match[] = { - { .compatible = "nxp,pca9540", .data = &chips[pca_9540] }, - { .compatible = "nxp,pca9542", .data = &chips[pca_9542] }, - { .compatible = "nxp,pca9543", .data = &chips[pca_9543] }, - { .compatible = "nxp,pca9544", .data = &chips[pca_9544] }, - { .compatible = "nxp,pca9545", .data = &chips[pca_9545] }, - { .compatible = "nxp,pca9546", .data = &chips[pca_9546] }, - { .compatible = "nxp,pca9547", .data = &chips[pca_9547] }, - { .compatible = "nxp,pca9548", .data = &chips[pca_9548] }, - {} -}; -MODULE_DEVICE_TABLE(of, pca954x_of_match); -#endif - -/* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() - for this as they will try to lock adapter a second time */ -static int pca954x_reg_write(struct i2c_adapter *adap, - struct i2c_client *client, u8 val) -{ - int ret = -ENODEV; - - if (adap->algo->master_xfer) { - struct i2c_msg msg; - char buf[1]; - - msg.addr = client->addr; - msg.flags = 0; - msg.len = 1; - buf[0] = val; - msg.buf = buf; - ret = __i2c_transfer(adap, &msg, 1); - - if (ret >= 0 && ret != 1) - ret = -EREMOTEIO; - } else { - union i2c_smbus_data data; - ret = adap->algo->smbus_xfer(adap, client->addr, - client->flags, - I2C_SMBUS_WRITE, - val, I2C_SMBUS_BYTE, &data); - } - - return ret; -} - -static u8 pca954x_regval(struct pca954x *data, u8 chan) -{ - /* We make switches look like muxes, not sure how to be smarter. */ - if (data->chip->muxtype == pca954x_ismux) - return chan | data->chip->enable; - else - return 1 << chan; -} - static int pca954x_setmuxflag(struct i2c_client *client, int flag) - { - struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); - pca9641_setmuxflag(adap->nr, flag); - return 0; - } - -static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan) -{ - struct pca954x *data = i2c_mux_priv(muxc); - struct i2c_client *client = data->client; - u8 regval; - int ret = 0; - regval = pca954x_regval(data, chan); - - /* we make switches look like muxes, not sure how to be smarter */ - - /* Only select the channel if its different from the last channel */ - if (data->last_chan != regval) { - pca954x_setmuxflag(client, 0); - ret = pca954x_reg_write(muxc->parent, client, regval); - data->last_chan = ret < 0 ? 0 : regval; - } - - return ret; -} - -typedef void (*pca954x_hw_do_reset_func_t)(int busid, int addr); -pca954x_hw_do_reset_func_t g_notify_to_do_reset = NULL; - -void pca954x_hw_do_reset_func_register(void* func) -{ - if (func == NULL) { - return ; - } - g_notify_to_do_reset = func; - return; -} -EXPORT_SYMBOL(pca954x_hw_do_reset_func_register); - -static int pca954x_hw_do_reset(int busid, int addr) -{ - if (g_notify_to_do_reset != NULL) { - (*g_notify_to_do_reset)(busid, addr); - return 0; - } - - return 0; -} -/***************************************9548 reset*****************************************/ -#define DEV_TYPE 0x4040 /* BT2575 */ -#define PCA9548_MAX_CPLD_NUM (32) /* PCA9548 max number */ -#define PCA9548_MAX_CPLD_LAYER (8) /* PCA9548 max layer */ -#define DFD_PID_BUF_LEN (32) -#define DFD_PRODUCT_ID_LENGTH (8) -#define CPLD_PCA9548_RESET 0x023500b0 /* bus:2, addr:0x35, offset:0xb0 */ -#define B6510_32CQ_CPLD_PCA9548_RESET 0x060d0060 /* bus:6, addr:0x0d, offset:0x60 */ - -#define DFD_PUB_CARDTYPE_FILE "/sys/module/ragile_common/parameters/dfd_my_type" -#define DFD_MAX_PRODUCT_NUM (32) - -#define I2C_RETRY_TIMES 5 -#define I2C_RETRY_WAIT_TIMES 10 /*delay 10ms*/ - -#define PCA9548_I2C_GET_BUS(addr) (((addr) >> 24) & 0x00ff) -#define PCA9548_I2C_GET_CLIENT(addr) (((addr) >> 16) & 0x00ff) -#define PCA9548_I2C_GET_OFFSET(addr) (addr & 0xffff) - -typedef enum pca9548_reset_type { - PCA9548_RESET_FUNC = 0, - PCA9548_RESET_GPIO = 1, -} pca9548_reset_type_t; - -typedef void (*pca954x_hw_do_reset_func_t_new)(int io_port, u8 value); -typedef u8 (*pca954x_get_umask_func_t)(int io_port); - -void pca954x_hw_do_reset_by_i2c(int addr, u8 value); -u8 pca954x_get_umask_by_i2c(int addr); -void pca954x_hw_do_reset_by_lpc(int io_port, u8 value); -u8 pca954x_get_umask_by_lpc(int io_port); - -typedef struct func_attr_s { - int cfg_offset[PCA9548_MAX_CPLD_LAYER]; - int umask[PCA9548_MAX_CPLD_LAYER]; - pca954x_hw_do_reset_func_t_new reset_func; /* 9548 reset function */ - pca954x_get_umask_func_t get_umask_func; /* get reset mask */ -} func_attr_t; - -typedef struct gpio_attr_s { - int gpio; - int gpio_init; - u8 reset_on; - u8 reset_off; -} gpio_attr_t; - -typedef struct pca9548_cfg_info_s { - int pca9548_reset_type; - int pca9548_bus; - int pca9548_addr; - int rst_delay_b; /* delay time before reset(us) */ - int rst_delay; /* reset time(us) */ - int rst_delay_a; /* delay time after reset(us) */ - union { - func_attr_t func_attr; - gpio_attr_t gpio_attr; - } attr; -} pca9548_cfg_info_t; - -typedef struct fpga_pcie_card_info_s { - int dev_type[DFD_MAX_PRODUCT_NUM]; /* dev type */ - pca9548_cfg_info_t pca9548_cfg_info[PCA9548_MAX_CPLD_NUM]; -} pca9548_card_info_t; - -static pca9548_card_info_t g_pca9548_card_info[] = { - { - .dev_type = {0x4040,0x4061,0x4071}, /*B6510,BT2575,TCS81*/ - .pca9548_cfg_info = { - /* psu fan */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 2, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 7, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 1, - .gpio_attr.reset_off = 0, - }, - }, - /* sff1 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* sff2 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - /* sff3 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - /* sff4 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - /* sff5 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(4), -1}, - }, - }, - /* sff6 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x75, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(5), -1}, - }, - }, - /* sff7 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x76, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(6), -1}, - }, - }, - }, - }, - { - .dev_type = {0x4041}, /*B6520*/ - .pca9548_cfg_info = { - /* psu fan */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 2, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 7, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 1, - .gpio_attr.reset_off = 0, - }, - }, - /* sff1 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* sff2 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - /* sff3 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - /* sff4 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - /* sff5 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(4), -1}, - }, - }, - /* sff6 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x75, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(5), -1}, - }, - }, - /* sff7 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x76, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(6), -1}, - }, - }, - /* sff8 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(7), -1}, - }, - }, - }, - }, - { - .dev_type = {0x4044,0x4072,0x4048}, /*B6920,TCS83,BS100R0*/ - .pca9548_cfg_info = { - /* 9548 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 2, - .pca9548_addr = 0x76, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x936, -1}, - .func_attr.umask = {BIT(4), -1}, - }, - }, - /* base board */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 8, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(4), -1}, - }, - }, - /* sff1 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 9, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* sff2 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 12, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - /* sff3 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 11, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - /* sff4 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 7, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - /* fanA */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 14, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb10, -1}, - .func_attr.umask = {BIT(5), -1}, - }, - }, - /* fanB */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 13, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb10, -1}, - .func_attr.umask = {BIT(7), -1}, - }, - }, - /* sff1 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 3, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 3, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 3, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 3, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* sff2 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - /* sff3 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 5, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 5, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 5, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 5, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - /* sff4 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 6, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 6, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 6, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 6, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - }, - }, - { - .dev_type = {0x4058,0x4073}, /* B6510-32CQ, TCS82 */ - .pca9548_cfg_info = { - /* psu */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x960, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* fan */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 2, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x960, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - }, - }, - { - .dev_type = {0x4065}, /* AS61-48E4T */ - .pca9548_cfg_info = { - /* SOC */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 0, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP+ */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - }, - }, - { - .dev_type = {0x4066}, /* AS61-48X4T */ - .pca9548_cfg_info = { - /* SOC */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 0, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP1 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 7, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP2 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 7, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP3 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 7, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP4 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP5 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP6 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP+ */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - }, - }, - { - .dev_type = {0x4087}, /* AS61-48E4T-LC */ - .pca9548_cfg_info = { - /* SOC */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 0, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP+ */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - }, - }, - { - .dev_type = {0x4088}, /* AS61-48E4T-LD */ - .pca9548_cfg_info = { - /* SOC */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 0, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP+ */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - }, - }, -}; -int g_pca954x_debug = 0; -module_param(g_pca954x_debug, int, S_IRUGO | S_IWUSR); - -#define PCA954X_DEBUG(fmt, args...) do { \ - if (g_pca954x_debug) { \ - printk(KERN_ERR "[PCA95x][VER][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \ - } \ -} while (0) - -/* x86 device get type method */ -static int dfd_get_my_dev_type_by_file(void) -{ - struct file *fp; - /* mm_segment_t fs;*/ - loff_t pos; - static int card_type; - char buf[DFD_PID_BUF_LEN]; - - if (card_type != 0) { - return card_type; - } - - fp= filp_open(DFD_PUB_CARDTYPE_FILE, O_RDONLY, 0); - if (IS_ERR(fp)) { - PCA954X_DEBUG("open file fail!\r\n"); - return -1; - } - /* fs = get_fs(); */ - /* set_fs(KERNEL_DS); */ - mem_clear(buf, DFD_PID_BUF_LEN); - pos = 0; - kernel_read(fp, buf, DFD_PRODUCT_ID_LENGTH + 1, &pos); - if (pos < 0) { - PCA954X_DEBUG("read file fail!\r\n"); - goto exit; - } - - card_type = simple_strtoul(buf, NULL, 10); - PCA954X_DEBUG("card_type 0x%x.\n", card_type); - -exit: - /* set_fs(fs); */ - filp_close(fp, NULL); - return card_type; -} - -static int drv_get_my_dev_type(void) -{ - static int type = -1; - - if (type > 0) { - return type; - } - type = dfd_get_my_dev_type_by_file(); - PCA954X_DEBUG("ko board type %d\r\n", type); - - return type; -} - -pca9548_card_info_t* pca9548_get_card_info(int dev_type) -{ - int i, j; - int size; - - size = ARRAY_SIZE(g_pca9548_card_info); - - PCA954X_DEBUG("Enter dev_type 0x%x size %d.\n", dev_type, size); - for (i = 0; i < size; i++) { - for(j = 0; j < DFD_MAX_PRODUCT_NUM; j++) { - if (g_pca9548_card_info[i].dev_type[j] == dev_type) { - PCA954X_DEBUG("match dev_type 0x%x.\n", dev_type); - return &g_pca9548_card_info[i]; - } - } - } - - PCA954X_DEBUG("dismatch dev_type 0x%x.\n", dev_type); - return NULL; -} - -pca9548_cfg_info_t* get_pca9548_cfg_info(int bus, int addr) -{ - int dev_type; - pca9548_card_info_t *info; - pca9548_cfg_info_t *pca9548_cfg_info; - int i; - int size; - - dev_type = drv_get_my_dev_type(); - if (dev_type < 0) { - PCA954X_DEBUG("drv_get_my_dev_type failed ret %d.\n", dev_type); - return NULL; - } - - info = pca9548_get_card_info(dev_type); - if (info == NULL) { - PCA954X_DEBUG("fpga_pcie_get_card_info dev_type %d failed.\n", dev_type); - return NULL; - } - - size = PCA9548_MAX_CPLD_NUM; - for (i = 0; i < size; i++) { - pca9548_cfg_info = &(info->pca9548_cfg_info[i]); - if ((pca9548_cfg_info->pca9548_bus == bus) && (pca9548_cfg_info->pca9548_addr == addr)) { - PCA954X_DEBUG("match dev_type 0x%x bus %d addr 0x%x.\n", dev_type, bus, addr); - return pca9548_cfg_info; - } - } - - PCA954X_DEBUG("dismatch dev_type 0x%x bus %d addr 0x%x.\n", dev_type, bus, addr); - return NULL; -} - -static void pca9548_gpio_init(gpio_attr_t *gpio_attr) -{ - if (gpio_attr->gpio_init == 0) { - PCA954X_DEBUG("gpio%d init.\n", gpio_attr->gpio); - gpio_request(gpio_attr->gpio, "pca9548_reset"); - gpio_direction_output(gpio_attr->gpio, gpio_attr->reset_off); - gpio_attr->gpio_init = 1; - } -} - -static void pca9548_gpio_free(gpio_attr_t *gpio_attr) -{ - if (gpio_attr == NULL) { - PCA954X_DEBUG("pca9548_gpio_free,params error\n"); - return ; - } - if (gpio_attr->gpio_init == 1) { - PCA954X_DEBUG("gpio%d release.\n", gpio_attr->gpio); - gpio_free(gpio_attr->gpio); - gpio_attr->gpio_init = 0; - } -} - -static int pca954x_do_gpio_reset(pca9548_cfg_info_t *cfg_info, struct i2c_adapter *adap, - struct i2c_client *client, u32 chan) -{ - struct i2c_mux_core *muxc = i2c_get_clientdata(client); - struct pca954x *data = i2c_mux_priv(muxc); - int ret = -1; - gpio_attr_t *tmp_gpio_attr; - int timeout; - int val; - struct i2c_adapter *adapter; - int adapter_timeout; - - if (cfg_info == NULL) { - PCA954X_DEBUG("pca9548 cfg info is null.\n"); - return ret; - } - - if (cfg_info->pca9548_reset_type == PCA9548_RESET_GPIO) { - tmp_gpio_attr = &(cfg_info->attr.gpio_attr); - timeout = cfg_info->rst_delay_a; - - pca9548_gpio_init(tmp_gpio_attr); - udelay(cfg_info->rst_delay_b); - /* reset on */ - PCA954X_DEBUG("set gpio%d %d.\n", tmp_gpio_attr->gpio, tmp_gpio_attr->reset_on); - __gpio_set_value(tmp_gpio_attr->gpio, tmp_gpio_attr->reset_on); - udelay(cfg_info->rst_delay); - /* reset off */ - PCA954X_DEBUG("set gpio%d %d.\n", tmp_gpio_attr->gpio, tmp_gpio_attr->reset_off); - __gpio_set_value(tmp_gpio_attr->gpio, tmp_gpio_attr->reset_off); - - while (timeout > 0) { - udelay(1); - val = __gpio_get_value(tmp_gpio_attr->gpio); - if (val == tmp_gpio_attr->reset_off) { - adapter = adap; - /* get bus info */ - while(i2c_parent_is_i2c_adapter(adapter)){ - adapter = to_i2c_adapter(adapter->dev.parent); - } - - adapter_timeout = adapter->timeout; - adapter->timeout = msecs_to_jiffies(50); - pca954x_reg_write(adap, client, data->last_chan); - adapter->timeout = adapter_timeout; - ret = 0; - PCA954X_DEBUG("pca954x_do_gpio_reset success.\n"); - break; - } - - if (timeout >= 1000 && (timeout % 1000 == 0)) { - /* 1MS schedule*/ - schedule(); - } - timeout--; - } - - if (ret) { - PCA954X_DEBUG("pca954x_do_gpio_reset failed.\n"); - } - pca9548_gpio_free(&(cfg_info->attr.gpio_attr)); - } else { - PCA954X_DEBUG("pca9548_reset_type invalid, pca954x_do_gpio_reset failed.\n"); - } - - return ret; -} - -static int pca954x_do_func_reset(pca9548_cfg_info_t *cfg_info, struct i2c_adapter *adap, - struct i2c_client *client, u32 chan) -{ - struct i2c_mux_core *muxc = i2c_get_clientdata(client); - struct pca954x *data = i2c_mux_priv(muxc); - int ret = -1; - func_attr_t *tmp_func_attr; - int timeout; - int val; - struct i2c_adapter *adapter; - int adapter_timeout; - int i; - u8 old_value; - - if (cfg_info == NULL) { - PCA954X_DEBUG("pca9548 cfg info is null.\n"); - return ret; - } - - if (cfg_info->pca9548_reset_type == PCA9548_RESET_FUNC) { - tmp_func_attr = &(cfg_info->attr.func_attr); - timeout = cfg_info->rst_delay_a; - - if ((tmp_func_attr->reset_func == NULL) || (tmp_func_attr->get_umask_func == NULL)) { - PCA954X_DEBUG("pca954x hw do reset func or get umask func is null.\n"); - return ret; - } - - for(i = 0; (i < PCA9548_MAX_CPLD_LAYER) && (tmp_func_attr->cfg_offset[i] != -1) - && (tmp_func_attr->umask[i] != -1); i++) { - old_value = (*tmp_func_attr->get_umask_func)(tmp_func_attr->cfg_offset[i]); - PCA954X_DEBUG("cfg info: offset:0x%x umask:0x%x, old_value:0x%x\n", - tmp_func_attr->cfg_offset[i], tmp_func_attr->umask[i],old_value); - (*tmp_func_attr->reset_func)(tmp_func_attr->cfg_offset[i], old_value & ~tmp_func_attr->umask[i]); - udelay(cfg_info->rst_delay); - (*tmp_func_attr->reset_func)(tmp_func_attr->cfg_offset[i], old_value | tmp_func_attr->umask[i]); - } - - while (timeout > 0) { - udelay(1); - val = (*tmp_func_attr->get_umask_func)(tmp_func_attr->cfg_offset[i - 1]); - val &= (tmp_func_attr->umask[i - 1]); - if (val == tmp_func_attr->umask[i - 1]) { - adapter = adap; - /* get bus info */ - while(i2c_parent_is_i2c_adapter(adapter)){ - adapter = to_i2c_adapter(adapter->dev.parent); - } - - adapter_timeout = adapter->timeout; - adapter->timeout = msecs_to_jiffies(50); - pca954x_reg_write(adap, client, data->last_chan); - adapter->timeout = adapter_timeout; - ret = 0; - PCA954X_DEBUG("pca954x_do_func_reset success.\n"); - break; - } - - if (timeout >= 1000 && (timeout % 1000 == 0)) { - /* 1MS schedule*/ - schedule(); - } - timeout--; - } - - if (ret) { - PCA954X_DEBUG("pca954x_do_func_reset failed.\n"); - } - } else { - PCA954X_DEBUG("pca9548_reset_type invalid, pca954x_do_func_reset failed.\n"); - } - - return ret; -} - -static int pca9548_reset_ctrl(pca9548_cfg_info_t *cfg_info, struct i2c_adapter *adap, - struct i2c_client *client, u32 chan) -{ - int ret = -1; - - if (cfg_info == NULL) { - PCA954X_DEBUG("pca9548 cfg info is null.\n"); - return ret; - } - - if (cfg_info->pca9548_reset_type == PCA9548_RESET_FUNC) { - ret = pca954x_do_func_reset(cfg_info, adap, client, chan); - } else if (cfg_info->pca9548_reset_type == PCA9548_RESET_GPIO) { - ret = pca954x_do_gpio_reset(cfg_info, adap, client, chan); - } - - if (ret < 0) { - PCA954X_DEBUG("pca9548_reset_ctrl failed.\n"); - } - return ret; -} - -static int pca954x_reset_i2c_read(uint32_t bus, uint32_t addr, uint32_t offset_addr, - unsigned char *buf, uint32_t size) -{ - struct file *fp; - /* mm_segment_t fs; */ - struct i2c_client client; - char i2c_path[32]; - int i ,j ; - int rv; - - rv = 0; - mem_clear(i2c_path, sizeof(i2c_path)); - snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", bus); - fp = filp_open(i2c_path, O_RDWR, S_IRUSR | S_IWUSR); - if (IS_ERR(fp)) { - PCA954X_DEBUG("i2c open fail.\n"); - return -1; - } - memcpy(&client, fp->private_data, sizeof(struct i2c_client)); - client.addr = addr; - /* fs = get_fs(); */ - /* set_fs(KERNEL_DS); */ - for (j = 0 ;j < size ;j++){ - for (i = 0; i < I2C_RETRY_TIMES; i++) { - rv = i2c_smbus_read_byte_data(&client, (offset_addr + j)); - if (rv < 0) { - PCA954X_DEBUG("i2c read failed, try again.\n"); - msleep(I2C_RETRY_WAIT_TIMES); - if (i >= (I2C_RETRY_TIMES - 1)) { - goto out; - } - continue; - } - *(buf + j) = (unsigned char)rv; - break; - } - } -out: - filp_close(fp, NULL); - /* set_fs(fs); */ - return rv; -} - -static int pca954x_reset_i2c_write(uint32_t bus, uint32_t dev_addr, uint32_t offset_addr, - uint8_t write_buf) -{ - struct file *fp; - /* mm_segment_t fs; */ - struct i2c_client client; - char i2c_path[32]; - int i; - int rv; - - rv = 0; - mem_clear(i2c_path, sizeof(i2c_path)); - snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", bus); - fp = filp_open(i2c_path, O_RDWR, S_IRUSR | S_IWUSR); - if (IS_ERR(fp)) { - PCA954X_DEBUG("i2c open fail.\n"); - return -1; - } - memcpy(&client, fp->private_data, sizeof(struct i2c_client)); - client.addr = dev_addr; - /* fs = get_fs(); */ - /* set_fs(KERNEL_DS); */ - for (i = 0; i < I2C_RETRY_TIMES; i++) { - rv = i2c_smbus_write_byte_data(&client, offset_addr, write_buf); - if (rv < 0) { - PCA954X_DEBUG("i2c write failed, try again.\n"); - msleep(I2C_RETRY_WAIT_TIMES); - if (i >= (I2C_RETRY_TIMES - 1)) { - goto out; - } - continue; - } - break; - } -out: - filp_close(fp, NULL); - /* set_fs(fs); */ - return rv; -} - -int pca954x_reset_reg_i2c_read_byte(int addr, u8 *value) -{ - int bus; - int client_addr; - int offset; - int ret; - - bus = PCA9548_I2C_GET_BUS(addr); - client_addr = PCA9548_I2C_GET_CLIENT(addr); - offset = PCA9548_I2C_GET_OFFSET(addr); - - ret = pca954x_reset_i2c_read(bus, client_addr, offset, value, 1); - if (ret < 0) { - PCA954X_DEBUG(" 0x%x read fail\r\n", addr); - goto end; - } -end: - return ret; -} - -int pca954x_reset_reg_i2c_write_byte(int addr, u8 value) -{ - int bus; - int client_addr; - int offset; - int ret; - - bus = PCA9548_I2C_GET_BUS(addr); - client_addr = PCA9548_I2C_GET_CLIENT(addr); - offset = PCA9548_I2C_GET_OFFSET(addr); - - ret = pca954x_reset_i2c_write(bus, client_addr, offset, value); - if (ret < 0) { - PCA954X_DEBUG(" 0x%x write fail\r\n", addr); - goto end; - } -end: - return ret; -} - -void pca954x_hw_do_reset_by_i2c(int addr, u8 value) -{ - int ret; - - PCA954X_DEBUG("write i2c cpld[0x%x], value[%d]\n", addr, value); - ret = pca954x_reset_reg_i2c_write_byte(addr, value); - if (ret < 0) { - PCA954X_DEBUG("write cpld pca9548 reset reg failed, ret = %d \n", ret); - } -} - -u8 pca954x_get_umask_by_i2c(int addr) -{ - u8 value = 0xFF; - int ret; - - ret = pca954x_reset_reg_i2c_read_byte(addr, &value); - PCA954X_DEBUG("read i2c cpld[0x%x], value[%d], ret = %d\n", addr, value, ret); - - return value; -} - -void pca954x_hw_do_reset_by_lpc(int io_port, u8 value) -{ - PCA954X_DEBUG("write lpc offset[0x%x], value[%d]\n", (u16)io_port, value); - outb(value, (u16)io_port); -} - -u8 pca954x_get_umask_by_lpc(int io_port) -{ - u8 value; - - value = inb(io_port); - PCA954X_DEBUG("read lpc offset[0x%x], value[%d]\n", (u16)io_port, value); - - return value; -} - -int pca954x_hw_do_reset_new(struct i2c_adapter *adap, - struct i2c_client *client, u32 chan) -{ - pca9548_cfg_info_t *cfg_info; - int ret = -1; - - cfg_info = get_pca9548_cfg_info(adap->nr, client->addr); - if (cfg_info == NULL && g_notify_to_do_reset == NULL) { - PCA954X_DEBUG("fpga_do_pca954x_reset_func do nothing.\n"); - return ret; - } - if(cfg_info != NULL) { - ret = pca9548_reset_ctrl(cfg_info, adap, client, chan); - } else { - ret = pca954x_hw_do_reset(adap->nr, client->addr); - } - if (ret < 0) { - PCA954X_DEBUG("pca954x_hw_do_reset failed.\n"); - } - return ret; -} -/******************************end 9548 reset***********************************/ - -static int pca954x_do_reset(struct i2c_adapter *adap, - void *client, u32 chan) -{ - struct i2c_client *new_client; - int ret = -1; - - PCA954X_DEBUG("do pca954x reset x86\n"); - new_client =(struct i2c_client *) client; - ret = pca954x_hw_do_reset_new(adap, new_client, chan); - if (ret < 0) { - PCA954X_DEBUG("pca954x_do_reset failed.\n"); - return ret; - } - - PCA954X_DEBUG("pca954x_do_reset success.\n"); - ret = 0; - return ret; -} -static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan) -{ - struct pca954x *data = i2c_mux_priv(muxc); - struct i2c_client *client = data->client; - s32 idle_state; - int ret, rv; - struct i2c_client * new_client; - - idle_state = READ_ONCE(data->idle_state); - if (idle_state >= 0) - /* Set the mux back to a predetermined channel */ - return pca954x_select_chan(muxc, idle_state); - - if (idle_state == MUX_IDLE_DISCONNECT) { - /* Deselect active channel */ - data->last_chan = 0; - ret = pca954x_reg_write(muxc->parent, client, - data->last_chan); - if (ret < 0) { - new_client =(struct i2c_client *) client; - dev_warn(&new_client->dev, "pca954x close chn failed, do reset.\n"); - rv = pca954x_do_reset(client->adapter, client, chan); - if (rv == 0) { - ret = 0; - } - } - return ret; - } - - /* otherwise leave as-is */ - - return 0; -} - -static ssize_t idle_state_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct i2c_mux_core *muxc = i2c_get_clientdata(client); - struct pca954x *data = i2c_mux_priv(muxc); - - return sprintf(buf, "%d\n", READ_ONCE(data->idle_state)); -} - -static ssize_t idle_state_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct i2c_mux_core *muxc = i2c_get_clientdata(client); - struct pca954x *data = i2c_mux_priv(muxc); - int val; - int ret; - - ret = kstrtoint(buf, 0, &val); - if (ret < 0) - return ret; - - if (val != MUX_IDLE_AS_IS && val != MUX_IDLE_DISCONNECT && - (val < 0 || val >= data->chip->nchans)) - return -EINVAL; - - i2c_lock_bus(muxc->parent, I2C_LOCK_SEGMENT); - - WRITE_ONCE(data->idle_state, val); - /* - * Set the mux into a state consistent with the new - * idle_state. - */ - if (data->last_chan || val != MUX_IDLE_DISCONNECT) - ret = pca954x_deselect_mux(muxc, 0); - - i2c_unlock_bus(muxc->parent, I2C_LOCK_SEGMENT); - - return ret < 0 ? ret : count; -} - -static DEVICE_ATTR_RW(idle_state); - -static irqreturn_t pca954x_irq_handler(int irq, void *dev_id) -{ - struct pca954x *data = dev_id; - unsigned long pending; - int ret, i; - - ret = i2c_smbus_read_byte(data->client); - if (ret < 0) - return IRQ_NONE; - - pending = (ret >> PCA954X_IRQ_OFFSET) & (BIT(data->chip->nchans) - 1); - for_each_set_bit(i, &pending, data->chip->nchans) - handle_nested_irq(irq_linear_revmap(data->irq, i)); - - return IRQ_RETVAL(pending); -} - -static int pca954x_init(struct i2c_client *client, struct pca954x *data) -{ - int ret; - - if (data->idle_state >= 0) - data->last_chan = pca954x_regval(data, data->idle_state); - else - data->last_chan = 0; /* Disconnect multiplexer */ - - ret = i2c_smbus_write_byte(client, data->last_chan); - if (ret < 0) - data->last_chan = 0; - return ret; -} - -static void pca954x_irq_mask(struct irq_data *idata) -{ - struct pca954x *data = irq_data_get_irq_chip_data(idata); - unsigned int pos = idata->hwirq; - unsigned long flags; - - raw_spin_lock_irqsave(&data->lock, flags); - - data->irq_mask &= ~BIT(pos); - if (!data->irq_mask) - disable_irq(data->client->irq); - - raw_spin_unlock_irqrestore(&data->lock, flags); -} - -static void pca954x_irq_unmask(struct irq_data *idata) -{ - struct pca954x *data = irq_data_get_irq_chip_data(idata); - unsigned int pos = idata->hwirq; - unsigned long flags; - - raw_spin_lock_irqsave(&data->lock, flags); - - if (!data->irq_mask) - enable_irq(data->client->irq); - data->irq_mask |= BIT(pos); - - raw_spin_unlock_irqrestore(&data->lock, flags); -} - -static int pca954x_irq_set_type(struct irq_data *idata, unsigned int type) -{ - if ((type & IRQ_TYPE_SENSE_MASK) != IRQ_TYPE_LEVEL_LOW) - return -EINVAL; - return 0; -} - -static struct irq_chip pca954x_irq_chip = { - .name = "i2c-mux-pca954x", - .irq_mask = pca954x_irq_mask, - .irq_unmask = pca954x_irq_unmask, - .irq_set_type = pca954x_irq_set_type, -}; - -static int pca954x_irq_setup(struct i2c_mux_core *muxc) -{ - struct pca954x *data = i2c_mux_priv(muxc); - struct i2c_client *client = data->client; - int c, err, irq; - - if (!data->chip->has_irq || client->irq <= 0) - return 0; - - raw_spin_lock_init(&data->lock); - - data->irq = irq_domain_add_linear(client->dev.of_node, - data->chip->nchans, - &irq_domain_simple_ops, data); - if (!data->irq) - return -ENODEV; - - for (c = 0; c < data->chip->nchans; c++) { - irq = irq_create_mapping(data->irq, c); - irq_set_chip_data(irq, data); - irq_set_chip_and_handler(irq, &pca954x_irq_chip, - handle_simple_irq); - } - - err = devm_request_threaded_irq(&client->dev, data->client->irq, NULL, - pca954x_irq_handler, - IRQF_ONESHOT | IRQF_SHARED, - "pca954x", data); - if (err) - goto err_req_irq; - - disable_irq(data->client->irq); - - return 0; -err_req_irq: - for (c = 0; c < data->chip->nchans; c++) { - irq = irq_find_mapping(data->irq, c); - irq_dispose_mapping(irq); - } - irq_domain_remove(data->irq); - - return err; -} - -/* - * I2C init/probing/exit functions - */ -static int pca954x_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); - struct device_node *of_node = client->dev.of_node; - bool idle_disconnect_dt; - struct gpio_desc *gpio; - int num; - struct i2c_mux_core *muxc; - struct pca954x *data; - const struct of_device_id *match; - int ret; - - if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) - return -ENODEV; - - muxc = i2c_mux_alloc(adap, &client->dev, - PCA954X_MAX_NCHANS, sizeof(*data), 0, - pca954x_select_chan, pca954x_deselect_mux); - if (!muxc) - return -ENOMEM; - data = i2c_mux_priv(muxc); - - i2c_set_clientdata(client, muxc); - data->client = client; - - /* Get the mux out of reset if a reset GPIO is specified. */ - gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW); - if (IS_ERR(gpio)) - return PTR_ERR(gpio); - data->idle_state = MUX_IDLE_AS_IS; - if (device_property_read_u32(&client->dev, "idle-state", &data->idle_state)) { - if (device_property_read_bool(&client->dev, "i2c-mux-idle-disconnect")) - data->idle_state = MUX_IDLE_DISCONNECT; - } - - /* - * Write the mux register at addr to verify - * that the mux is in fact present. This also - * initializes the mux to a channel - * or disconnected state. - */ - ret = pca954x_init(client, data); - if (ret < 0) { - dev_warn(&client->dev, "probe failed\n"); - return -ENODEV; - } - - match = of_match_device(of_match_ptr(pca954x_of_match), &client->dev); - if (match) - data->chip = of_device_get_match_data(&client->dev); - else - data->chip = &chips[id->driver_data]; - - data->last_chan = 0; /* force the first selection */ - - idle_disconnect_dt = of_node && - of_property_read_bool(of_node, "i2c-mux-idle-disconnect"); - - ret = pca954x_irq_setup(muxc); - if (ret) - goto fail_del_adapters; - - /* Now create an adapter for each channel */ - for (num = 0; num < data->chip->nchans; num++) { - ret = i2c_mux_add_adapter(muxc, 0, num, 0); - if (ret) - goto fail_del_adapters; - } - - device_create_file(&client->dev, &dev_attr_idle_state); - dev_info(&client->dev, - "registered %d multiplexed busses for I2C %s %s\n", - num, data->chip->muxtype == pca954x_ismux - ? "mux" : "switch", client->name); - - return 0; - -fail_del_adapters: - i2c_mux_del_adapters(muxc); - return ret; -} - -static int pca954x_remove(struct i2c_client *client) -{ - struct i2c_mux_core *muxc = i2c_get_clientdata(client); - struct pca954x *data = i2c_mux_priv(muxc); - int c, irq; - - if (data->irq) { - for (c = 0; c < data->chip->nchans; c++) { - irq = irq_find_mapping(data->irq, c); - irq_dispose_mapping(irq); - } - irq_domain_remove(data->irq); - } - device_remove_file(&client->dev, &dev_attr_idle_state); - - i2c_mux_del_adapters(muxc); - return 0; -} - -#ifdef CONFIG_PM_SLEEP -static int pca954x_resume(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct i2c_mux_core *muxc = i2c_get_clientdata(client); - struct pca954x *data = i2c_mux_priv(muxc); - int ret; - - ret = pca954x_init(client, data); - if (ret < 0) - dev_err(&client->dev, "failed to verify mux presence\n"); - - return ret; -} -#endif - -static SIMPLE_DEV_PM_OPS(pca954x_pm, NULL, pca954x_resume); - -static struct i2c_driver pca954x_driver = { - .driver = { - .name = "pca954x", - .pm = &pca954x_pm, - .of_match_table = of_match_ptr(pca954x_of_match), - }, - .probe = pca954x_probe, - .remove = pca954x_remove, - .id_table = pca954x_id, -}; - -module_i2c_driver(pca954x_driver); - -#else -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern int pca9641_setmuxflag(int nr, int flag); - -int force_create_bus = 0; -module_param(force_create_bus, int, S_IRUGO | S_IWUSR); - -#define PCA954X_MAX_NCHANS 8 - -enum pca_type { - pca_9540, - pca_9542, - pca_9543, - pca_9544, - pca_9545, - pca_9546, - pca_9547, - pca_9548, -}; - -struct pca954x { - enum pca_type type; - struct i2c_adapter *virt_adaps[PCA954X_MAX_NCHANS]; - - u8 last_chan; /* last register value */ -}; - -struct chip_desc { - u8 nchans; - u8 enable; /* used for muxes only */ - enum muxtype { - pca954x_ismux = 0, - pca954x_isswi - } muxtype; -}; - -/* Provide specs for the PCA954x types we know about */ -static const struct chip_desc chips[] = { - [pca_9540] = { - .nchans = 2, - .enable = 0x4, - .muxtype = pca954x_ismux, - }, - [pca_9543] = { - .nchans = 2, - .muxtype = pca954x_isswi, - }, - [pca_9544] = { - .nchans = 4, - .enable = 0x4, - .muxtype = pca954x_ismux, - }, - [pca_9545] = { - .nchans = 4, - .muxtype = pca954x_isswi, - }, - [pca_9547] = { - .nchans = 8, - .enable = 0x8, - .muxtype = pca954x_ismux, - }, - [pca_9548] = { - .nchans = 8, - .muxtype = pca954x_isswi, - }, -}; - -static const struct i2c_device_id pca954x_id[] = { - { "pca9540", pca_9540 }, - { "pca9542", pca_9540 }, - { "pca9543", pca_9543 }, - { "pca9544", pca_9544 }, - { "pca9545", pca_9545 }, - { "pca9546", pca_9545 }, - { "pca9547", pca_9547 }, - { "pca9548", pca_9548 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, pca954x_id); - -/* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() - for this as they will try to lock adapter a second time */ -static int pca954x_reg_write(struct i2c_adapter *adap, - struct i2c_client *client, u8 val) -{ - int ret = -ENODEV; - - if (adap->algo->master_xfer) { - struct i2c_msg msg; - char buf[1]; - - msg.addr = client->addr; - msg.flags = 0; - msg.len = 1; - buf[0] = val; - msg.buf = buf; - ret = adap->algo->master_xfer(adap, &msg, 1); - - if (ret >= 0 && ret != 1) - ret = -EREMOTEIO; - } else { - union i2c_smbus_data data; - ret = adap->algo->smbus_xfer(adap, client->addr, - client->flags, - I2C_SMBUS_WRITE, - val, I2C_SMBUS_BYTE, &data); - } - - return ret; -} - -static int pca954x_setmuxflag(struct i2c_adapter *adap, int flag) -{ - pca9641_setmuxflag(adap->nr, flag); - return 0; -} - -static int pca954x_select_chan(struct i2c_adapter *adap, - void *client, u32 chan) -{ - struct pca954x *data = i2c_get_clientdata(client); - const struct chip_desc *chip = &chips[data->type]; - u8 regval; - int ret = 0; - - /* we make switches look like muxes, not sure how to be smarter */ - if (chip->muxtype == pca954x_ismux) - regval = chan | chip->enable; - else - regval = 1 << chan; - - /* Only select the channel if its different from the last channel */ - if (data->last_chan != regval) { - pca954x_setmuxflag(adap, 0); - ret = pca954x_reg_write(adap, client, regval); - data->last_chan = ret < 0 ? 0 : regval; - } - - return ret; -} - -typedef void (*pca954x_hw_do_reset_func_t)(int busid, int addr); -pca954x_hw_do_reset_func_t g_notify_to_do_reset = NULL; - -void pca954x_hw_do_reset_func_register(void* func) -{ - if (func == NULL) { - return ; - } - g_notify_to_do_reset = func; - return; -} -EXPORT_SYMBOL(pca954x_hw_do_reset_func_register); - -static int pca954x_hw_do_reset(int busid, int addr) -{ - if (g_notify_to_do_reset != NULL) { - (*g_notify_to_do_reset)(busid, addr); - return 0; - } - return 0; -} -/***************************************9548 reset*****************************************/ -#define DEV_TYPE 0x4040 /* BT2575 */ -#define PCA9548_MAX_CPLD_NUM (32) /* PCA9548 max number */ -#define PCA9548_MAX_CPLD_LAYER (8) /* PCA9548 max layer */ -#define DFD_PID_BUF_LEN (32) -#define DFD_PRODUCT_ID_LENGTH (8) -#define CPLD_PCA9548_RESET 0x023500b0 /* bus:2, addr:0x35, offset:0xb0 */ -#define B6510_32CQ_CPLD_PCA9548_RESET 0x060d0060 /* bus:6, addr:0x0d, offset:0x60 */ -#define DFD_PUB_CARDTYPE_FILE "/sys/module/ragile_common/parameters/dfd_my_type" -#define DFD_MAX_PRODUCT_NUM (32) - -#define I2C_RETRY_TIMES 5 -#define I2C_RETRY_WAIT_TIMES 10 /*delay 10ms*/ - -#define PCA9548_I2C_GET_BUS(addr) (((addr) >> 24) & 0x00ff) -#define PCA9548_I2C_GET_CLIENT(addr) (((addr) >> 16) & 0x00ff) -#define PCA9548_I2C_GET_OFFSET(addr) (addr & 0xffff) - -typedef enum pca9548_reset_type { - PCA9548_RESET_FUNC = 0, - PCA9548_RESET_GPIO = 1, -} pca9548_reset_type_t; - -typedef void (*pca954x_hw_do_reset_func_t_new)(int io_port, u8 value); -typedef u8 (*pca954x_get_umask_func_t)(int io_port); - -void pca954x_hw_do_reset_by_i2c(int addr, u8 value); -u8 pca954x_get_umask_by_i2c(int addr); -void pca954x_hw_do_reset_by_lpc(int io_port, u8 value); -u8 pca954x_get_umask_by_lpc(int io_port); - -typedef struct func_attr_s { - int cfg_offset[PCA9548_MAX_CPLD_LAYER]; - int umask[PCA9548_MAX_CPLD_LAYER]; - pca954x_hw_do_reset_func_t_new reset_func; /* 9548 reset function */ - pca954x_get_umask_func_t get_umask_func; /* get reset mask */ -} func_attr_t; - -typedef struct gpio_attr_s { - int gpio; - int gpio_init; - u8 reset_on; - u8 reset_off; -} gpio_attr_t; - -typedef struct pca9548_cfg_info_s { - int pca9548_reset_type; - int pca9548_bus; - int pca9548_addr; - int rst_delay_b; /* delay time before reset(us) */ - int rst_delay; /* reset time(us) */ - int rst_delay_a; /* delay time after reset(us) */ - union { - func_attr_t func_attr; - gpio_attr_t gpio_attr; - } attr; -} pca9548_cfg_info_t; - -typedef struct fpga_pcie_card_info_s { - int dev_type[DFD_MAX_PRODUCT_NUM]; /* dev type */ - pca9548_cfg_info_t pca9548_cfg_info[PCA9548_MAX_CPLD_NUM]; -} pca9548_card_info_t; - -static pca9548_card_info_t g_pca9548_card_info[] = { - { - .dev_type = {0x4040,0x4061,0x4071}, /*B6510,BT2575,TCS81*/ - .pca9548_cfg_info = { - /* psu fan */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 2, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 7, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 1, - .gpio_attr.reset_off = 0, - }, - }, - /* sff1 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* sff2 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - /* sff3 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - /* sff4 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - /* sff5 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(4), -1}, - }, - }, - /* sff6 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x75, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(5), -1}, - }, - }, - /* sff7 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x76, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(6), -1}, - }, - }, - }, - }, - { - .dev_type = {0x4041}, /*B6520*/ - .pca9548_cfg_info = { - /* psu fan */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 2, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 7, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 1, - .gpio_attr.reset_off = 0, - }, - }, - /* sff1 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* sff2 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - /* sff3 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - /* sff4 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - /* sff5 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(4), -1}, - }, - }, - /* sff6 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x75, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(5), -1}, - }, - }, - /* sff7 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x76, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(6), -1}, - }, - }, - /* sff8 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 1, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_i2c, - .func_attr.get_umask_func = pca954x_get_umask_by_i2c, - .func_attr.cfg_offset = {CPLD_PCA9548_RESET, -1}, - .func_attr.umask = {BIT(7), -1}, - }, - }, - }, - }, - { - .dev_type = {0x4044,0x4072,0x4048}, /*B6920,TCS83,BS100R0*/ - .pca9548_cfg_info = { - /* 9548 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 2, - .pca9548_addr = 0x76, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x936, -1}, - .func_attr.umask = {BIT(4), -1}, - }, - }, - /* base board */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 8, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(4), -1}, - }, - }, - /* sff1 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 9, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* sff2 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 12, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - /* sff3 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 11, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - /* sff4 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 7, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x917, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - /* fanA */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 14, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb10, -1}, - .func_attr.umask = {BIT(5), -1}, - }, - }, - /* fanB */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 13, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb10, -1}, - .func_attr.umask = {BIT(7), -1}, - }, - }, - /* sff1 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 3, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 3, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 3, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 3, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* sff2 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - /* sff3 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 5, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 5, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 5, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 5, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(2), -1}, - }, - }, - /* sff4 */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 6, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 6, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 6, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 6, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0xb17, -1}, - .func_attr.umask = {BIT(3), -1}, - }, - }, - }, - }, - { - .dev_type = {0x4058,0x4073}, /* B6510-32CQ, TCS82 */ - .pca9548_cfg_info = { - /* psu */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 4, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x960, -1}, - .func_attr.umask = {BIT(0), -1}, - }, - }, - /* fan */ - { - .pca9548_reset_type = PCA9548_RESET_FUNC, - .pca9548_bus = 2, - .pca9548_addr = 0x77, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .func_attr.reset_func = pca954x_hw_do_reset_by_lpc, - .func_attr.get_umask_func = pca954x_get_umask_by_lpc, - .func_attr.cfg_offset = {0x960, -1}, - .func_attr.umask = {BIT(1), -1}, - }, - }, - }, - }, - { - .dev_type = {0x4065}, /* AS61-48E4T */ - .pca9548_cfg_info = { - /* SOC */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 0, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP+ */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - }, - }, - { - .dev_type = {0x4066}, /* AS61-48X4T */ - .pca9548_cfg_info = { - /* SOC */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 0, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP1 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 7, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP2 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 7, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP3 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 7, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP4 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x71, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP5 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x72, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP6 */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x73, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP+ */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - }, - }, - { - .dev_type = {0x4087}, /* AS61-48E4T-LC */ - .pca9548_cfg_info = { - /* SOC */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 0, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP+ */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - }, - }, - { - .dev_type = {0x4088}, /* AS61-48E4T-LD */ - .pca9548_cfg_info = { - /* SOC */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 0, - .pca9548_addr = 0x70, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - /* SFP+ */ - { - .pca9548_reset_type = PCA9548_RESET_GPIO, - .pca9548_bus = 8, - .pca9548_addr = 0x74, - .rst_delay_b = 0, - .rst_delay = 1000, - .rst_delay_a = 1000, - .attr = { - .gpio_attr.gpio = 509, - .gpio_attr.gpio_init = 0, - .gpio_attr.reset_on = 0, - .gpio_attr.reset_off = 1, - }, - }, - }, - }, -}; - -int g_pca954x_debug = 0; -module_param(g_pca954x_debug, int, S_IRUGO | S_IWUSR); - -#define PCA954X_DEBUG(fmt, args...) do { \ - if (g_pca954x_debug) { \ - printk(KERN_ERR "[PCA95x][VER][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \ - } \ -} while (0) - -/* x86 device get card method */ -static int dfd_get_my_dev_type_by_file(void) -{ - struct file *fp; - mm_segment_t fs; - loff_t pos; - static int card_type; - char buf[DFD_PID_BUF_LEN]; - - if (card_type != 0) { - return card_type; - } - - fp= filp_open(DFD_PUB_CARDTYPE_FILE, O_RDONLY, 0); - if (IS_ERR(fp)) { - PCA954X_DEBUG("open file fail!\r\n"); - return -1; - } - fs = get_fs(); - set_fs(KERNEL_DS); - mem_clear(buf, DFD_PID_BUF_LEN); - pos = 0; - vfs_read(fp, buf, DFD_PRODUCT_ID_LENGTH + 1, &pos); - if (pos < 0) { - PCA954X_DEBUG("read file fail!\r\n"); - goto exit; - } - - card_type = simple_strtoul(buf, NULL, 10); - PCA954X_DEBUG("card_type 0x%x.\n", card_type); - -exit: - set_fs(fs); - filp_close(fp, NULL); - return card_type; -} - -static int drv_get_my_dev_type(void) -{ - static int type = -1; - - if (type > 0) { - return type; - } - type = dfd_get_my_dev_type_by_file(); - PCA954X_DEBUG("ko board type %d\r\n", type); - - return type; -} - -pca9548_card_info_t* pca9548_get_card_info(int dev_type) -{ - int i, j; - int size; - - size = ARRAY_SIZE(g_pca9548_card_info); - - PCA954X_DEBUG("Enter dev_type 0x%x size %d.\n", dev_type, size); - for (i = 0; i < size; i++) { - for(j = 0; j < DFD_MAX_PRODUCT_NUM; j++) { - if (g_pca9548_card_info[i].dev_type[j] == dev_type) { - PCA954X_DEBUG("match dev_type 0x%x.\n", dev_type); - return &g_pca9548_card_info[i]; - } - } - } - - PCA954X_DEBUG("dismatch dev_type 0x%x.\n", dev_type); - return NULL; -} - -pca9548_cfg_info_t* get_pca9548_cfg_info(int bus, int addr) -{ - int dev_type; - pca9548_card_info_t *info; - pca9548_cfg_info_t *pca9548_cfg_info; - int i; - int size; - - dev_type = drv_get_my_dev_type(); - if (dev_type < 0) { - PCA954X_DEBUG("drv_get_my_dev_type failed ret %d.\n", dev_type); - return NULL; - } - - info = pca9548_get_card_info(dev_type); - if (info == NULL) { - PCA954X_DEBUG("fpga_pcie_get_card_info dev_type %d failed.\n", dev_type); - return NULL; - } - - size = PCA9548_MAX_CPLD_NUM; - for (i = 0; i < size; i++) { - pca9548_cfg_info = &(info->pca9548_cfg_info[i]); - if ((pca9548_cfg_info->pca9548_bus == bus) && (pca9548_cfg_info->pca9548_addr == addr)) { - PCA954X_DEBUG("match dev_type 0x%x bus %d addr 0x%x.\n", dev_type, bus, addr); - return pca9548_cfg_info; - } - } - - PCA954X_DEBUG("dismatch dev_type 0x%x bus %d addr 0x%x.\n", dev_type, bus, addr); - return NULL; -} - -static void pca9548_gpio_init(gpio_attr_t *gpio_attr) -{ - if (gpio_attr->gpio_init == 0) { - PCA954X_DEBUG("gpio%d init.\n", gpio_attr->gpio); - gpio_request(gpio_attr->gpio, "pca9548_reset"); - gpio_direction_output(gpio_attr->gpio, gpio_attr->reset_off); - gpio_attr->gpio_init = 1; - } -} - -static void pca9548_gpio_free(gpio_attr_t *gpio_attr) -{ - if (gpio_attr == NULL) { - PCA954X_DEBUG("pca9548_gpio_free,params error\n"); - return ; - } - if (gpio_attr->gpio_init == 1) { - PCA954X_DEBUG("gpio%d release.\n", gpio_attr->gpio); - gpio_free(gpio_attr->gpio); - gpio_attr->gpio_init = 0; - } -} - -static int pca954x_do_gpio_reset(pca9548_cfg_info_t *cfg_info, struct i2c_adapter *adap, - struct i2c_client *client, u32 chan) -{ - struct pca954x *data = i2c_get_clientdata(client); - int ret = -1; - gpio_attr_t *tmp_gpio_attr; - int timeout; - int val; - struct i2c_adapter *adapter; - int adapter_timeout; - - if (cfg_info == NULL) { - PCA954X_DEBUG("pca9548 cfg info is null.\n"); - return ret; - } - - if (cfg_info->pca9548_reset_type == PCA9548_RESET_GPIO) { - tmp_gpio_attr = &(cfg_info->attr.gpio_attr); - timeout = cfg_info->rst_delay_a; - - pca9548_gpio_init(tmp_gpio_attr); - udelay(cfg_info->rst_delay_b); - /* reset on */ - PCA954X_DEBUG("set gpio%d %d.\n", tmp_gpio_attr->gpio, tmp_gpio_attr->reset_on); - __gpio_set_value(tmp_gpio_attr->gpio, tmp_gpio_attr->reset_on); - udelay(cfg_info->rst_delay); - /* reset off */ - PCA954X_DEBUG("set gpio%d %d.\n", tmp_gpio_attr->gpio, tmp_gpio_attr->reset_off); - __gpio_set_value(tmp_gpio_attr->gpio, tmp_gpio_attr->reset_off); - - while (timeout > 0) { - udelay(1); - val = __gpio_get_value(tmp_gpio_attr->gpio); - if (val == tmp_gpio_attr->reset_off) { - adapter = adap; - /* get bus info */ - while(i2c_parent_is_i2c_adapter(adapter)){ - adapter = to_i2c_adapter(adapter->dev.parent); - } - - adapter_timeout = adapter->timeout; - adapter->timeout = msecs_to_jiffies(50); - pca954x_reg_write(adap, client, data->last_chan); - adapter->timeout = adapter_timeout; - ret = 0; - PCA954X_DEBUG("pca954x_do_gpio_reset success.\n"); - break; - } - - if (timeout >= 1000 && (timeout % 1000 == 0)) { - /* 1MS schedule*/ - schedule(); - } - timeout--; - } - - if (ret) { - PCA954X_DEBUG("pca954x_do_gpio_reset failed.\n"); - } - pca9548_gpio_free(&(cfg_info->attr.gpio_attr)); - } else { - PCA954X_DEBUG("pca9548_reset_type invalid, pca954x_do_gpio_reset failed.\n"); - } - - return ret; -} - -static int pca954x_do_func_reset(pca9548_cfg_info_t *cfg_info, struct i2c_adapter *adap, - struct i2c_client *client, u32 chan) -{ - struct pca954x *data = i2c_get_clientdata(client); - int ret = -1; - func_attr_t *tmp_func_attr; - int timeout; - int val; - struct i2c_adapter *adapter; - int adapter_timeout; - int i; - u8 old_value; - - if (cfg_info == NULL) { - PCA954X_DEBUG("pca9548 cfg info is null.\n"); - return ret; - } - - if (cfg_info->pca9548_reset_type == PCA9548_RESET_FUNC) { - tmp_func_attr = &(cfg_info->attr.func_attr); - timeout = cfg_info->rst_delay_a; - - if ((tmp_func_attr->reset_func == NULL) || (tmp_func_attr->get_umask_func == NULL)) { - PCA954X_DEBUG("pca954x hw do reset func or get umask func is null.\n"); - return ret; - } - - for(i = 0; (i < PCA9548_MAX_CPLD_LAYER) && (tmp_func_attr->cfg_offset[i] != -1) - && (tmp_func_attr->umask[i] != -1); i++) { - old_value = (*tmp_func_attr->get_umask_func)(tmp_func_attr->cfg_offset[i]); - PCA954X_DEBUG("cfg info: offset:0x%x umask:0x%x, old_value:0x%x\n", - tmp_func_attr->cfg_offset[i], tmp_func_attr->umask[i],old_value); - (*tmp_func_attr->reset_func)(tmp_func_attr->cfg_offset[i], old_value & ~tmp_func_attr->umask[i]); - udelay(cfg_info->rst_delay); - (*tmp_func_attr->reset_func)(tmp_func_attr->cfg_offset[i], old_value | tmp_func_attr->umask[i]); - } - - while (timeout > 0) { - udelay(1); - val = (*tmp_func_attr->get_umask_func)(tmp_func_attr->cfg_offset[i - 1]); - val &= (tmp_func_attr->umask[i - 1]); - if (val == tmp_func_attr->umask[i - 1]) { - adapter = adap; - /* get bus info */ - while(i2c_parent_is_i2c_adapter(adapter)){ - adapter = to_i2c_adapter(adapter->dev.parent); - } - - adapter_timeout = adapter->timeout; - adapter->timeout = msecs_to_jiffies(50); - pca954x_reg_write(adap, client, data->last_chan); - adapter->timeout = adapter_timeout; - ret = 0; - PCA954X_DEBUG("pca954x_do_func_reset success.\n"); - break; - } - - if (timeout >= 1000 && (timeout % 1000 == 0)) { - /* 1MS schedule*/ - schedule(); - } - timeout--; - } - - if (ret) { - PCA954X_DEBUG("pca954x_do_func_reset failed.\n"); - } - } else { - PCA954X_DEBUG("pca9548_reset_type invalid, pca954x_do_func_reset failed.\n"); - } - - return ret; -} - -static int pca9548_reset_ctrl(pca9548_cfg_info_t *cfg_info, struct i2c_adapter *adap, - struct i2c_client *client, u32 chan) -{ - int ret = -1; - - if (cfg_info == NULL) { - PCA954X_DEBUG("pca9548 cfg info is null.\n"); - return ret; - } - - if (cfg_info->pca9548_reset_type == PCA9548_RESET_FUNC) { - ret = pca954x_do_func_reset(cfg_info, adap, client, chan); - } else if (cfg_info->pca9548_reset_type == PCA9548_RESET_GPIO) { - ret = pca954x_do_gpio_reset(cfg_info, adap, client, chan); - } - - if (ret < 0) { - PCA954X_DEBUG("pca9548_reset_ctrl failed.\n"); - } - return ret; -} - -static int pca954x_reset_i2c_read(uint32_t bus, uint32_t addr, uint32_t offset_addr, - unsigned char *buf, uint32_t size) -{ - struct file *fp; - mm_segment_t fs; - struct i2c_client client; - char i2c_path[32]; - int i ,j ; - int rv; - - rv = 0; - mem_clear(i2c_path, sizeof(i2c_path)); - snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", bus); - fp = filp_open(i2c_path, O_RDWR, S_IRUSR | S_IWUSR); - if (IS_ERR(fp)) { - PCA954X_DEBUG("i2c open fail.\n"); - return -1; - } - memcpy(&client, fp->private_data, sizeof(struct i2c_client)); - client.addr = addr; - fs = get_fs(); - set_fs(KERNEL_DS); - for (j = 0 ;j < size ;j++){ - for (i = 0; i < I2C_RETRY_TIMES; i++) { - rv = i2c_smbus_read_byte_data(&client, (offset_addr + j)); - if (rv < 0) { - PCA954X_DEBUG("i2c read failed, try again.\n"); - msleep(I2C_RETRY_WAIT_TIMES); - if (i >= (I2C_RETRY_TIMES - 1)) { - goto out; - } - continue; - } - *(buf + j) = (unsigned char)rv; - break; - } - } -out: - filp_close(fp, NULL); - set_fs(fs); - return rv; -} - -static int pca954x_reset_i2c_write(uint32_t bus, uint32_t dev_addr, uint32_t offset_addr, - uint8_t write_buf) -{ - struct file *fp; - mm_segment_t fs; - struct i2c_client client; - char i2c_path[32]; - int i; - int rv; - - rv = 0; - mem_clear(i2c_path, sizeof(i2c_path)); - snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", bus); - fp = filp_open(i2c_path, O_RDWR, S_IRUSR | S_IWUSR); - if (IS_ERR(fp)) { - PCA954X_DEBUG("i2c open fail.\n"); - return -1; - } - memcpy(&client, fp->private_data, sizeof(struct i2c_client)); - client.addr = dev_addr; - fs = get_fs(); - set_fs(KERNEL_DS); - for (i = 0; i < I2C_RETRY_TIMES; i++) { - rv = i2c_smbus_write_byte_data(&client, offset_addr, write_buf); - if (rv < 0) { - PCA954X_DEBUG("i2c write failed, try again.\n"); - msleep(I2C_RETRY_WAIT_TIMES); - if (i >= (I2C_RETRY_TIMES - 1)) { - goto out; - } - continue; - } - break; - } -out: - filp_close(fp, NULL); - set_fs(fs); - return rv; -} - -int pca954x_reset_reg_i2c_read_byte(int addr, u8 *value) -{ - int bus; - int client_addr; - int offset; - int ret; - - bus = PCA9548_I2C_GET_BUS(addr); - client_addr = PCA9548_I2C_GET_CLIENT(addr); - offset = PCA9548_I2C_GET_OFFSET(addr); - - ret = pca954x_reset_i2c_read(bus, client_addr, offset, value, 1); - if (ret < 0) { - PCA954X_DEBUG(" 0x%x read fail\r\n", addr); - goto end; - } -end: - return ret; -} - -int pca954x_reset_reg_i2c_write_byte(int addr, u8 value) -{ - int bus; - int client_addr; - int offset; - int ret; - - bus = PCA9548_I2C_GET_BUS(addr); - client_addr = PCA9548_I2C_GET_CLIENT(addr); - offset = PCA9548_I2C_GET_OFFSET(addr); - - ret = pca954x_reset_i2c_write(bus, client_addr, offset, value); - if (ret < 0) { - PCA954X_DEBUG(" 0x%x write fail\r\n", addr); - goto end; - } -end: - return ret; -} - -void pca954x_hw_do_reset_by_i2c(int addr, u8 value) -{ - int ret; - - PCA954X_DEBUG("write i2c cpld[0x%x], value[%d]\n", addr, value); - ret = pca954x_reset_reg_i2c_write_byte(addr, value); - if (ret < 0) { - PCA954X_DEBUG("write cpld pca9548 reset reg failed, ret = %d \n", ret); - } -} - -u8 pca954x_get_umask_by_i2c(int addr) -{ - u8 value = 0xFF; - int ret; - - ret = pca954x_reset_reg_i2c_read_byte(addr, &value); - PCA954X_DEBUG("read i2c cpld[0x%x], value[%d], ret = %d\n", addr, value, ret); - - return value; -} - -void pca954x_hw_do_reset_by_lpc(int io_port, u8 value) -{ - PCA954X_DEBUG("write lpc offset[0x%x], value[%d]\n", (u16)io_port, value); - outb(value, (u16)io_port); -} - -u8 pca954x_get_umask_by_lpc(int io_port) -{ - u8 value; - - value = inb(io_port); - PCA954X_DEBUG("read lpc offset[0x%x], value[%d]\n", (u16)io_port, value); - - return value; -} - -int pca954x_hw_do_reset_new(struct i2c_adapter *adap, - struct i2c_client *client, u32 chan) -{ - pca9548_cfg_info_t *cfg_info; - int ret = -1; - - cfg_info = get_pca9548_cfg_info(adap->nr, client->addr); - if (cfg_info == NULL && g_notify_to_do_reset == NULL) { - PCA954X_DEBUG("fpga_do_pca954x_reset_func do nothing.\n"); - return ret; - } - if (cfg_info != NULL) { - ret = pca9548_reset_ctrl(cfg_info, adap, client, chan); - } else { - ret = pca954x_hw_do_reset(adap->nr, client->addr); - } - - if (ret < 0) { - PCA954X_DEBUG("pca954x_hw_do_reset failed.\n"); - } - return ret; -} -/******************************end 9548 reset***********************************/ - -static int pca954x_do_reset(struct i2c_adapter *adap, - void *client, u32 chan) -{ - struct i2c_client *new_client; - int ret = -1; - - PCA954X_DEBUG("do pca954x reset x86\n"); - new_client =(struct i2c_client *) client; - ret = pca954x_hw_do_reset_new(adap, new_client, chan); - if (ret < 0) { - PCA954X_DEBUG("pca954x_do_reset failed.\n"); - return ret; - } - - PCA954X_DEBUG("pca954x_do_reset success.\n"); - ret = 0; - return ret; -} - -static int pca954x_deselect_mux(struct i2c_adapter *adap, - void *client, u32 chan) -{ - struct pca954x *data = i2c_get_clientdata(client); - int ret, rv; - struct i2c_client * new_client; - - /* Deselect active channel */ - data->last_chan = 0; - - ret = pca954x_reg_write(adap, client, data->last_chan); - - if (ret < 0) { - new_client =(struct i2c_client *) client; - dev_warn(&new_client->dev, "pca954x close chn failed, do reset.\n"); - rv = pca954x_do_reset(adap, client, chan); - if (rv == 0) { - ret = 0; - } - - } - - pca954x_setmuxflag(adap, 1); - (void)pca954x_reg_write(adap, client, data->last_chan); - - return ret; -} - -/* - * I2C init/probing/exit functions - */ -static int pca954x_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); - struct pca954x_platform_data *pdata = dev_get_platdata(&client->dev); - struct gpio_desc *gpio; - int num, force, class; - struct pca954x *data; - int ret; - - if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) - return -ENODEV; - - data = devm_kzalloc(&client->dev, sizeof(struct pca954x), GFP_KERNEL); - if (!data) - return -ENOMEM; - - i2c_set_clientdata(client, data); - - /* Get the mux out of reset if a reset GPIO is specified. */ - gpio = devm_gpiod_get(&client->dev, "reset"); - if (!IS_ERR(gpio)) - gpiod_direction_output(gpio, 0); - - /* Write the mux register at addr to verify - * that the mux is in fact present. This also - * initializes the mux to disconnected state. - */ - if ((i2c_smbus_write_byte(client, 0) < 0) && (force_create_bus == 0)) { - dev_warn(&client->dev, "probe failed\n"); - return -ENODEV; - } - - data->type = id->driver_data; - data->last_chan = 0; /* force the first selection */ - - /* Now create an adapter for each channel */ - for (num = 0; num < chips[data->type].nchans; num++) { - force = 0; /* dynamic adap number */ - class = 0; /* no class by default */ - if (pdata) { - if (num < pdata->num_modes) { - /* force static number */ - force = pdata->modes[num].adap_id; - class = pdata->modes[num].class; - } else - /* discard unconfigured channels */ - break; - } - - data->virt_adaps[num] = - i2c_add_mux_adapter(adap, &client->dev, client, - force, num, class, pca954x_select_chan, pca954x_deselect_mux); - - if (data->virt_adaps[num] == NULL) { - ret = -ENODEV; - dev_err(&client->dev, - "failed to register multiplexed adapter" - " %d as bus %d\n", num, force); - goto virt_reg_failed; - } - } - - dev_info(&client->dev, - "registered %d multiplexed busses for I2C %s %s\n", - num, chips[data->type].muxtype == pca954x_ismux - ? "mux" : "switch", client->name); - - return 0; - -virt_reg_failed: - for (num--; num >= 0; num--) - i2c_del_mux_adapter(data->virt_adaps[num]); - return ret; -} - -static int pca954x_remove(struct i2c_client *client) -{ - struct pca954x *data = i2c_get_clientdata(client); - const struct chip_desc *chip = &chips[data->type]; - int i; - - for (i = 0; i < chip->nchans; ++i) - if (data->virt_adaps[i]) { - i2c_del_mux_adapter(data->virt_adaps[i]); - data->virt_adaps[i] = NULL; - } - - return 0; -} - -static struct i2c_driver pca954x_driver = { - .driver = { - .name = "pca954x", - .owner = THIS_MODULE, - }, - .probe = pca954x_probe, - .remove = pca954x_remove, - .id_table = pca954x_id, -}; - -module_i2c_driver(pca954x_driver); -#endif - -MODULE_AUTHOR("Rodolfo Giometti "); -MODULE_DESCRIPTION("PCA954x I2C mux/switch driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/i2c-mux-pca9641.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/i2c-mux-pca9641.c deleted file mode 100644 index b3f70bf140..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/i2c-mux-pca9641.c +++ /dev/null @@ -1,643 +0,0 @@ -/* - * I2C multiplexer driver for PCA9541 bus master selector - * - * Copyright (c) 2010 Ericsson AB. - * - * Author: Guenter Roeck - * - * Derived from: - * pca954x.c - * - * Copyright (c) 2008-2009 Rodolfo Giometti - * Copyright (c) 2008-2009 Eurotech S.p.A. - * - * This file is licensed under the terms of the GNU General Public - * License version 2. This program is licensed "as is" without any - * warranty of any kind, whether express or implied. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * The PCA9541 is a bus master selector. It supports two I2C masters connected - * to a single slave bus. - * - * Before each bus transaction, a master has to acquire bus ownership. After the - * transaction is complete, bus ownership has to be released. This fits well - * into the I2C multiplexer framework, which provides select and release - * functions for this purpose. For this reason, this driver is modeled as - * single-channel I2C bus multiplexer. - * - * This driver assumes that the two bus masters are controlled by two different - * hosts. If a single host controls both masters, platform code has to ensure - * that only one of the masters is instantiated at any given time. - */ - -#define PCA9541_CONTROL 0x01 -#define PCA9541_ISTAT 0x02 - -#define PCA9541_CTL_MYBUS (1 << 0) -#define PCA9541_CTL_NMYBUS (1 << 1) -#define PCA9541_CTL_BUSON (1 << 2) -#define PCA9541_CTL_NBUSON (1 << 3) -#define PCA9541_CTL_BUSINIT (1 << 4) -#define PCA9541_CTL_TESTON (1 << 6) -#define PCA9541_CTL_NTESTON (1 << 7) -#define PCA9541_ISTAT_INTIN (1 << 0) -#define PCA9541_ISTAT_BUSINIT (1 << 1) -#define PCA9541_ISTAT_BUSOK (1 << 2) -#define PCA9541_ISTAT_BUSLOST (1 << 3) -#define PCA9541_ISTAT_MYTEST (1 << 6) -#define PCA9541_ISTAT_NMYTEST (1 << 7) -#define PCA9641_ID 0x00 -#define PCA9641_ID_MAGIC 0x38 -#define PCA9641_CONTROL 0x01 -#define PCA9641_STATUS 0x02 -#define PCA9641_TIME 0x03 -#define PCA9641_CTL_LOCK_REQ BIT(0) -#define PCA9641_CTL_LOCK_GRANT BIT(1) -#define PCA9641_CTL_BUS_CONNECT BIT(2) -#define PCA9641_CTL_BUS_INIT BIT(3) -#define PCA9641_CTL_SMBUS_SWRST BIT(4) -#define PCA9641_CTL_IDLE_TIMER_DIS BIT(5) -#define PCA9641_CTL_SMBUS_DIS BIT(6) -#define PCA9641_CTL_PRIORITY BIT(7) -#define PCA9641_STS_OTHER_LOCK BIT(0) -#define PCA9641_STS_BUS_INIT_FAIL BIT(1) -#define PCA9641_STS_BUS_HUNG BIT(2) -#define PCA9641_STS_MBOX_EMPTY BIT(3) -#define PCA9641_STS_MBOX_FULL BIT(4) -#define PCA9641_STS_TEST_INT BIT(5) -#define PCA9641_STS_SCL_IO BIT(6) -#define PCA9641_STS_SDA_IO BIT(7) -#define PCA9641_RES_TIME 0x03 -#define BUSON (PCA9541_CTL_BUSON | PCA9541_CTL_NBUSON) -#define MYBUS (PCA9541_CTL_MYBUS | PCA9541_CTL_NMYBUS) -#define mybus(x) (!((x) & MYBUS) || ((x) & MYBUS) == MYBUS) -#define busoff(x) (!((x) & BUSON) || ((x) & BUSON) == BUSON) -#define BUSOFF(x, y) (!((x) & PCA9641_CTL_LOCK_GRANT) && \ - !((y) & PCA9641_STS_OTHER_LOCK)) -#define other_lock(x) ((x) & PCA9641_STS_OTHER_LOCK) -#define lock_grant(x) ((x) & PCA9641_CTL_LOCK_GRANT) - -#define PCA9641_RETRY_TIME 8 - -typedef struct i2c_muxs_struct_flag -{ - int nr; - char name[48]; - struct mutex update_lock; - int flag; -}i2c_mux_flag; - -i2c_mux_flag pca_flag = { - .flag = -1, -}; - -int pca9641_setmuxflag(int nr, int flag) -{ - if (pca_flag.nr == nr) { - pca_flag.flag = flag; - } - return 0; -} -EXPORT_SYMBOL(pca9641_setmuxflag); - -int g_debug = 0; -module_param(g_debug, int, S_IRUGO | S_IWUSR); - -#define PCA_DEBUG(fmt, args...) do { \ - if (g_debug) { \ - printk(KERN_ERR "[pca9641][VER][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \ - } \ -} while (0) - -/* arbitration timeouts, in jiffies */ -#define ARB_TIMEOUT (HZ / 8) /* 125 ms until forcing bus ownership */ -#define ARB2_TIMEOUT (HZ / 4) /* 250 ms until acquisition failure */ - -/* arbitration retry delays, in us */ -#define SELECT_DELAY_SHORT 50 -#define SELECT_DELAY_LONG 1000 - -struct pca9541 { - struct i2c_client *client; - unsigned long select_timeout; - unsigned long arb_timeout; -}; - -static const struct i2c_device_id pca9541_id[] = { - {"pca9541", 0}, - {"pca9641", 1}, - {} -}; - -MODULE_DEVICE_TABLE(i2c, pca9541_id); - -#ifdef CONFIG_OF -static const struct of_device_id pca9541_of_match[] = { - { .compatible = "nxp,pca9541" }, - { .compatible = "nxp,pca9641" }, - {} -}; -MODULE_DEVICE_TABLE(of, pca9541_of_match); -#endif - -/* - * Write to chip register. Don't use i2c_transfer()/i2c_smbus_xfer() - * as they will try to lock the adapter a second time. - */ -static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val) -{ - struct i2c_adapter *adap = client->adapter; - int ret; - - if (adap->algo->master_xfer) { - struct i2c_msg msg; - char buf[2]; - - msg.addr = client->addr; - msg.flags = 0; - msg.len = 2; - buf[0] = command; - buf[1] = val; - msg.buf = buf; - ret = __i2c_transfer(adap, &msg, 1); - } else { - union i2c_smbus_data data; - - data.byte = val; - ret = adap->algo->smbus_xfer(adap, client->addr, - client->flags, - I2C_SMBUS_WRITE, - command, - I2C_SMBUS_BYTE_DATA, &data); - } - - return ret; -} - -/* - * Read from chip register. Don't use i2c_transfer()/i2c_smbus_xfer() - * as they will try to lock adapter a second time. - */ -static int pca9541_reg_read(struct i2c_client *client, u8 command) -{ - struct i2c_adapter *adap = client->adapter; - int ret; - u8 val; - - if (adap->algo->master_xfer) { - struct i2c_msg msg[2] = { - { - .addr = client->addr, - .flags = 0, - .len = 1, - .buf = &command - }, - { - .addr = client->addr, - .flags = I2C_M_RD, - .len = 1, - .buf = &val - } - }; - ret = __i2c_transfer(adap, msg, 2); - if (ret == 2) - ret = val; - else if (ret >= 0) - ret = -EIO; - } else { - union i2c_smbus_data data; - - ret = adap->algo->smbus_xfer(adap, client->addr, - client->flags, - I2C_SMBUS_READ, - command, - I2C_SMBUS_BYTE_DATA, &data); - if (!ret) - ret = data.byte; - } - return ret; -} - -/* - * Arbitration management functions - */ - -/* Release bus. Also reset NTESTON and BUSINIT if it was set. */ -static void pca9541_release_bus(struct i2c_client *client) -{ - int reg; - - reg = pca9541_reg_read(client, PCA9541_CONTROL); - if (reg >= 0 && !busoff(reg) && mybus(reg)) - pca9541_reg_write(client, PCA9541_CONTROL, - (reg & PCA9541_CTL_NBUSON) >> 1); -} - -/* - * Arbitration is defined as a two-step process. A bus master can only activate - * the slave bus if it owns it; otherwise it has to request ownership first. - * This multi-step process ensures that access contention is resolved - * gracefully. - * - * Bus Ownership Other master Action - * state requested access - * ---------------------------------------------------- - * off - yes wait for arbitration timeout or - * for other master to drop request - * off no no take ownership - * off yes no turn on bus - * on yes - done - * on no - wait for arbitration timeout or - * for other master to release bus - * - * The main contention point occurs if the slave bus is off and both masters - * request ownership at the same time. In this case, one master will turn on - * the slave bus, believing that it owns it. The other master will request - * bus ownership. Result is that the bus is turned on, and master which did - * _not_ own the slave bus before ends up owning it. - */ - -/* Control commands per PCA9541 datasheet */ -static const u8 pca9541_control[16] = { - 4, 0, 1, 5, 4, 4, 5, 5, 0, 0, 1, 1, 0, 4, 5, 1 -}; - -/* - * Channel arbitration - * - * Return values: - * <0: error - * 0 : bus not acquired - * 1 : bus acquired - */ -static int pca9541_arbitrate(struct i2c_client *client) -{ - struct i2c_mux_core *muxc = i2c_get_clientdata(client); - struct pca9541 *data = i2c_mux_priv(muxc); - int reg; - - reg = pca9541_reg_read(client, PCA9541_CONTROL); - if (reg < 0) - return reg; - - if (busoff(reg)) { - int istat; - /* - * Bus is off. Request ownership or turn it on unless - * other master requested ownership. - */ - istat = pca9541_reg_read(client, PCA9541_ISTAT); - if (!(istat & PCA9541_ISTAT_NMYTEST) - || time_is_before_eq_jiffies(data->arb_timeout)) { - /* - * Other master did not request ownership, - * or arbitration timeout expired. Take the bus. - */ - pca9541_reg_write(client, - PCA9541_CONTROL, - pca9541_control[reg & 0x0f] - | PCA9541_CTL_NTESTON); - data->select_timeout = SELECT_DELAY_SHORT; - } else { - /* - * Other master requested ownership. - * Set extra long timeout to give it time to acquire it. - */ - data->select_timeout = SELECT_DELAY_LONG * 2; - } - } else if (mybus(reg)) { - /* - * Bus is on, and we own it. We are done with acquisition. - * Reset NTESTON and BUSINIT, then return success. - */ - if (reg & (PCA9541_CTL_NTESTON | PCA9541_CTL_BUSINIT)) - pca9541_reg_write(client, - PCA9541_CONTROL, - reg & ~(PCA9541_CTL_NTESTON - | PCA9541_CTL_BUSINIT)); - return 1; - } else { - /* - * Other master owns the bus. - * If arbitration timeout has expired, force ownership. - * Otherwise request it. - */ - data->select_timeout = SELECT_DELAY_LONG; - if (time_is_before_eq_jiffies(data->arb_timeout)) { - /* Time is up, take the bus and reset it. */ - pca9541_reg_write(client, - PCA9541_CONTROL, - pca9541_control[reg & 0x0f] - | PCA9541_CTL_BUSINIT - | PCA9541_CTL_NTESTON); - } else { - /* Request bus ownership if needed */ - if (!(reg & PCA9541_CTL_NTESTON)) - pca9541_reg_write(client, - PCA9541_CONTROL, - reg | PCA9541_CTL_NTESTON); - } - } - return 0; -} - -static int pca9541_select_chan(struct i2c_mux_core *muxc, u32 chan) -{ - struct pca9541 *data = i2c_mux_priv(muxc); - struct i2c_client *client = data->client; - int ret; - unsigned long timeout = jiffies + ARB2_TIMEOUT; - /* give up after this time */ - - data->arb_timeout = jiffies + ARB_TIMEOUT; - /* force bus ownership after this time */ - - do { - ret = pca9541_arbitrate(client); - if (ret) - return ret < 0 ? ret : 0; - - if (data->select_timeout == SELECT_DELAY_SHORT) - udelay(data->select_timeout); - else - msleep(data->select_timeout / 1000); - } while (time_is_after_eq_jiffies(timeout)); - - return -ETIMEDOUT; -} - -static int pca9541_release_chan(struct i2c_mux_core *muxc, u32 chan) -{ - struct pca9541 *data = i2c_mux_priv(muxc); - struct i2c_client *client = data->client; - pca9541_release_bus(client); - return 0; -} - -/* -* Arbitration management functions -*/ -static void pca9641_release_bus(struct i2c_client *client) -{ - pca9541_reg_write(client, PCA9641_CONTROL, 0x80); /* master 0x80 */ -} - -/* -* Channel arbitration -* -* Return values: -* <0: error -* 0 : bus not acquired -* 1 : bus acquired -*/ -static int pca9641_arbitrate(struct i2c_client *client) -{ - struct i2c_mux_core *muxc = i2c_get_clientdata(client); - struct pca9541 *data = i2c_mux_priv(muxc); - int reg_ctl, reg_sts; - - reg_ctl = pca9541_reg_read(client, PCA9641_CONTROL); - if (reg_ctl < 0) - return reg_ctl; - reg_sts = pca9541_reg_read(client, PCA9641_STATUS); - - if (BUSOFF(reg_ctl, reg_sts)) { - /* - * Bus is off. Request ownership or turn it on unless - * other master requested ownership. - */ - reg_ctl |= PCA9641_CTL_LOCK_REQ; - pca9541_reg_write(client, PCA9641_CONTROL, reg_ctl); - reg_ctl = pca9541_reg_read(client, PCA9641_CONTROL); - - if (lock_grant(reg_ctl)) { - /* - * Other master did not request ownership, - * or arbitration timeout expired. Take the bus. - */ - reg_ctl |= PCA9641_CTL_BUS_CONNECT - | PCA9641_CTL_LOCK_REQ; - pca9541_reg_write(client, PCA9641_CONTROL, reg_ctl); - data->select_timeout = SELECT_DELAY_SHORT; - - return 1; - } else { - /* - * Other master requested ownership. - * Set extra long timeout to give it time to acquire it. - */ - data->select_timeout = SELECT_DELAY_LONG * 2; - } - } else if (lock_grant(reg_ctl)) { - /* - * Bus is on, and we own it. We are done with acquisition. - */ - reg_ctl |= PCA9641_CTL_BUS_CONNECT | PCA9641_CTL_LOCK_REQ; - pca9541_reg_write(client, PCA9641_CONTROL, reg_ctl); - - return 1; - } else if (other_lock(reg_sts)) { - /* - * Other master owns the bus. - * If arbitration timeout has expired, force ownership. - * Otherwise request it. - */ - data->select_timeout = SELECT_DELAY_LONG; - reg_ctl |= PCA9641_CTL_LOCK_REQ; - pca9541_reg_write(client, PCA9641_CONTROL, reg_ctl); - } - return 0; -} - -int pca9641_select_chan(struct i2c_mux_core *muxc, u32 chan) -{ - struct pca9541 *data = i2c_mux_priv(muxc); - struct i2c_client *client = data->client; - int ret; - int result; - unsigned long timeout = jiffies + ARB2_TIMEOUT; - /* give up after this time */ - data->arb_timeout = jiffies + ARB_TIMEOUT; - /* force bus ownership after this time */ - for (result = 0 ; result < PCA9641_RETRY_TIME ; result ++) { - do { - ret = pca9641_arbitrate(client); - if (ret == 1) { - return 0; - } - if (data->select_timeout == SELECT_DELAY_SHORT) - udelay(data->select_timeout); - else - msleep(data->select_timeout / 1000); - } while (time_is_after_eq_jiffies(timeout)); - timeout = jiffies + ARB2_TIMEOUT; - } - return -ETIMEDOUT; -} -EXPORT_SYMBOL(pca9641_select_chan); - -static int pca9641_release_chan(struct i2c_mux_core *muxc, u32 chan) -{ - struct pca9541 *data = i2c_mux_priv(muxc); - struct i2c_client *client = data->client; - if (pca_flag.flag) { - pca9641_release_bus(client); - } - return 0; -} - -static int pca9641_detect_id(struct i2c_client *client) -{ - int reg; - - reg = pca9541_reg_read(client, PCA9641_ID); - if (reg == PCA9641_ID_MAGIC) - return 1; - else - return 0; -} - -/** - ** Limited: 20180827 supports one PCA9641 - **/ -static int pca9641_recordflag(struct i2c_adapter *adap) { - if (pca_flag.flag != -1) { - pr_err(" %s %d has init already!!!", __func__, __LINE__); - return -1 ; - } - pca_flag.nr = adap->nr; - PCA_DEBUG(" adap->nr:%d\n", adap->nr); - snprintf(pca_flag.name, sizeof(pca_flag.name),adap->name); - return 0; -} - -static void i2c_lock_adapter(struct i2c_adapter *adapter){ - struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); - if (parent) - i2c_lock_adapter(parent); - else - rt_mutex_lock(&adapter->bus_lock); -} - -void i2c_unlock_adapter(struct i2c_adapter *adapter) -{ - struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); - - if (parent) - i2c_unlock_adapter(parent); - else - rt_mutex_unlock(&adapter->bus_lock); -} -/* - * I2C init/probing/exit functions - */ -static int pca9541_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct i2c_adapter *adap = client->adapter; - struct i2c_mux_core *muxc; - struct pca9541 *data; - int force; - int ret = -ENODEV; - int detect_id; - - if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE_DATA)) - return -ENODEV; - - detect_id = pca9641_detect_id(client); - - /* - * I2C accesses are unprotected here. - * We have to lock the adapter before releasing the bus. - */ - #if 0 - i2c_lock_adapter(adap); - pca9541_release_bus(client); - i2c_unlock_adapter(adap); - #endif - if (detect_id == 0) { - i2c_lock_adapter(adap); - pca9541_release_bus(client); - i2c_unlock_adapter(adap); - } else { - i2c_lock_adapter(adap); - pca9641_release_bus(client); - i2c_unlock_adapter(adap); - } - - /* Create mux adapter */ - - if (detect_id == 0) { - muxc = i2c_mux_alloc(adap, &client->dev, 1, sizeof(*data), - I2C_MUX_ARBITRATOR, - pca9541_select_chan, pca9541_release_chan); - if (!muxc) - return -ENOMEM; - - data = i2c_mux_priv(muxc); - data->client = client; - - i2c_set_clientdata(client, muxc); - ret = i2c_mux_add_adapter(muxc, 0, 0, 0); - - if (ret) - return ret; - } else { - muxc = i2c_mux_alloc(adap, &client->dev, 1, sizeof(*data), - I2C_MUX_ARBITRATOR, - pca9641_select_chan, pca9641_release_chan); - if (!muxc) - return -ENOMEM; - - data = i2c_mux_priv(muxc); - data->client = client; - - i2c_set_clientdata(client, muxc); - - ret = i2c_mux_add_adapter(muxc, force, 0, 0); - if (ret) - return ret; - } - pca9641_recordflag(muxc->adapter[0]); - - dev_info(&client->dev, "registered master selector for I2C %s\n", - client->name); - - return 0; - -} - -static int pca9541_remove(struct i2c_client *client) -{ - struct i2c_mux_core *muxc = i2c_get_clientdata(client); - - i2c_mux_del_adapters(muxc); - return 0; -} - -static struct i2c_driver pca9641_driver = { - .driver = { - .name = "pca9641", - .of_match_table = of_match_ptr(pca9541_of_match), - }, - .probe = pca9541_probe, - .remove = pca9541_remove, - .id_table = pca9541_id, -}; - -module_i2c_driver(pca9641_driver); - -MODULE_AUTHOR("Guenter Roeck "); -MODULE_DESCRIPTION("PCA9541 I2C master selector driver"); -MODULE_LICENSE("GPL v2"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/optoe.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/optoe.c deleted file mode 100644 index 22c5d335e1..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/optoe.c +++ /dev/null @@ -1,1195 +0,0 @@ -/* - * optoe.c - A driver to read and write the EEPROM on optical transceivers - * (SFP, QSFP and similar I2C based devices) - * - * Copyright (C) 2014 Cumulus networks Inc. - * Copyright (C) 2017 Finisar Corp. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Freeoftware Foundation; either version 2 of the License, or - * (at your option) any later version. - */ - -/* - * Description: - * a) Optical transceiver EEPROM read/write transactions are just like - * the at24 eeproms managed by the at24.c i2c driver - * b) The register/memory layout is up to 256 128 byte pages defined by - * a "pages valid" register and switched via a "page select" - * register as explained in below diagram. - * c) 256 bytes are mapped at a time. 'Lower page 00h' is the first 128 - * bytes of address space, and always references the same - * location, independent of the page select register. - * All mapped pages are mapped into the upper 128 bytes - * (offset 128-255) of the i2c address. - * d) Devices with one I2C address (eg QSFP) use I2C address 0x50 - * (A0h in the spec), and map all pages in the upper 128 bytes - * of that address. - * e) Devices with two I2C addresses (eg SFP) have 256 bytes of data - * at I2C address 0x50, and 256 bytes of data at I2C address - * 0x51 (A2h in the spec). Page selection and paged access - * only apply to this second I2C address (0x51). - * e) The address space is presented, by the driver, as a linear - * address space. For devices with one I2C client at address - * 0x50 (eg QSFP), offset 0-127 are in the lower - * half of address 50/A0h/client[0]. Offset 128-255 are in - * page 0, 256-383 are page 1, etc. More generally, offset - * 'n' resides in page (n/128)-1. ('page -1' is the lower - * half, offset 0-127). - * f) For devices with two I2C clients at address 0x50 and 0x51 (eg SFP), - * the address space places offset 0-127 in the lower - * half of 50/A0/client[0], offset 128-255 in the upper - * half. Offset 256-383 is in the lower half of 51/A2/client[1]. - * Offset 384-511 is in page 0, in the upper half of 51/A2/... - * Offset 512-639 is in page 1, in the upper half of 51/A2/... - * Offset 'n' is in page (n/128)-3 (for n > 383) - * - * One I2c addressed (eg QSFP) Memory Map - * - * 2-Wire Serial Address: 1010000x - * - * Lower Page 00h (128 bytes) - * ===================== - * | | - * | | - * | | - * | | - * | | - * | | - * | | - * | | - * | | - * | | - * |Page Select Byte(127)| - * ===================== - * | - * | - * | - * | - * V - * ------------------------------------------------------------ - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * V V V V - * ------------ -------------- --------------- -------------- - * | | | | | | | | - * | Upper | | Upper | | Upper | | Upper | - * | Page 00h | | Page 01h | | Page 02h | | Page 03h | - * | | | (Optional) | | (Optional) | | (Optional | - * | | | | | | | for Cable | - * | | | | | | | Assemblies) | - * | ID | | AST | | User | | | - * | Fields | | Table | | EEPROM Data | | | - * | | | | | | | | - * | | | | | | | | - * | | | | | | | | - * ------------ -------------- --------------- -------------- - * - * The SFF 8436 (QSFP) spec only defines the 4 pages described above. - * In anticipation of future applications and devices, this driver - * supports access to the full architected range, 256 pages. - * - * The CMIS (Common Management Interface Specification) defines use of - * considerably more pages (at least to page 0xAF), which this driver - * supports. - * - * NOTE: This version of the driver ONLY SUPPORTS BANK 0 PAGES on CMIS - * devices. - * - **/ - -/* #define DEBUG 1 */ - -#undef EEPROM_CLASS -#ifdef CONFIG_EEPROM_CLASS -#define EEPROM_CLASS -#endif -#ifdef CONFIG_EEPROM_CLASS_MODULE -#define EEPROM_CLASS -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef EEPROM_CLASS -#include -#endif - -#include - -/* The maximum length of a port name */ -#define MAX_PORT_NAME_LEN 20 - -struct optoe_platform_data { - u32 byte_len; /* size (sum of all addr) */ - u16 page_size; /* for writes */ - u8 flags; - void *dummy1; /* backward compatibility */ - void *dummy2; /* backward compatibility */ - -#ifdef EEPROM_CLASS - struct eeprom_platform_data *eeprom_data; -#endif - char port_name[MAX_PORT_NAME_LEN]; -}; - -/* fundamental unit of addressing for EEPROM */ -#define OPTOE_PAGE_SIZE 128 -/* - * Single address devices (eg QSFP) have 256 pages, plus the unpaged - * low 128 bytes. If the device does not support paging, it is - * only 2 'pages' long. - */ -#define OPTOE_ARCH_PAGES 256 -#define ONE_ADDR_EEPROM_SIZE ((1 + OPTOE_ARCH_PAGES) * OPTOE_PAGE_SIZE) -#define ONE_ADDR_EEPROM_UNPAGED_SIZE (2 * OPTOE_PAGE_SIZE) -/* - * Dual address devices (eg SFP) have 256 pages, plus the unpaged - * low 128 bytes, plus 256 bytes at 0x50. If the device does not - * support paging, it is 4 'pages' long. - */ -#define TWO_ADDR_EEPROM_SIZE ((3 + OPTOE_ARCH_PAGES) * OPTOE_PAGE_SIZE) -#define TWO_ADDR_EEPROM_UNPAGED_SIZE (4 * OPTOE_PAGE_SIZE) -#define TWO_ADDR_NO_0X51_SIZE (2 * OPTOE_PAGE_SIZE) - -/* a few constants to find our way around the EEPROM */ -#define OPTOE_PAGE_SELECT_REG 0x7F -#define ONE_ADDR_PAGEABLE_REG 0x02 -#define QSFP_NOT_PAGEABLE (1<<2) -#define CMIS_NOT_PAGEABLE (1<<7) -#define TWO_ADDR_PAGEABLE_REG 0x40 -#define TWO_ADDR_PAGEABLE (1<<4) -#define TWO_ADDR_0X51_REG 92 -#define TWO_ADDR_0X51_SUPP (1<<6) -#define OPTOE_ID_REG 0 -#define OPTOE_READ_OP 0 -#define OPTOE_WRITE_OP 1 -#define OPTOE_EOF 0 /* used for access beyond end of device */ - -#define mem_clear(data, size) memset((data), 0, (size)) - -struct optoe_data { - struct optoe_platform_data chip; - int use_smbus; - char port_name[MAX_PORT_NAME_LEN]; - - /* - * Lock protects against activities from other Linux tasks, - * but not from changes by other I2C masters. - */ - struct mutex lock; - struct bin_attribute bin; - struct attribute_group attr_group; - - u8 *writebuf; - unsigned int write_max; - - unsigned int num_addresses; - -#ifdef EEPROM_CLASS - struct eeprom_device *eeprom_dev; -#endif - - /* dev_class: ONE_ADDR (QSFP) or TWO_ADDR (SFP) */ - int dev_class; - - struct i2c_client *client[]; -}; - -/* - * This parameter is to help this driver avoid blocking other drivers out - * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C - * clock, one 256 byte read takes about 1/43 second which is excessive; - * but the 1/170 second it takes at 400 kHz may be quite reasonable; and - * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. - * - * This value is forced to be a power of two so that writes align on pages. - */ -static unsigned int io_limit = OPTOE_PAGE_SIZE; - -/* - * specs often allow 5 msec for a page write, sometimes 20 msec; - * it's important to recover from write timeouts. - */ -static unsigned int write_timeout = 25; - -/* - * flags to distinguish one-address (QSFP family) from two-address (SFP family) - * If the family is not known, figure it out when the device is accessed - */ -#define ONE_ADDR 1 -#define TWO_ADDR 2 -#define CMIS_ADDR 3 - -static const struct i2c_device_id optoe_ids[] = { - { "optoe1", ONE_ADDR }, - { "optoe2", TWO_ADDR }, - { "optoe3", CMIS_ADDR }, - { "sff8436", ONE_ADDR }, - { "24c04", TWO_ADDR }, - { /* END OF LIST */ } -}; -MODULE_DEVICE_TABLE(i2c, optoe_ids); - -/*-------------------------------------------------------------------------*/ -/* - * This routine computes the addressing information to be used for - * a given r/w request. - * - * Task is to calculate the client (0 = i2c addr 50, 1 = i2c addr 51), - * the page, and the offset. - * - * Handles both single address (eg QSFP) and two address (eg SFP). - * For SFP, offset 0-255 are on client[0], >255 is on client[1] - * Offset 256-383 are on the lower half of client[1] - * Pages are accessible on the upper half of client[1]. - * Offset >383 are in 128 byte pages mapped into the upper half - * - * For QSFP, all offsets are on client[0] - * offset 0-127 are on the lower half of client[0] (no paging) - * Pages are accessible on the upper half of client[1]. - * Offset >127 are in 128 byte pages mapped into the upper half - * - * Callers must not read/write beyond the end of a client or a page - * without recomputing the client/page. Hence offset (within page) - * plus length must be less than or equal to 128. (Note that this - * routine does not have access to the length of the call, hence - * cannot do the validity check.) - * - * Offset within Lower Page 00h and Upper Page 00h are not recomputed - */ - -static uint8_t optoe_translate_offset(struct optoe_data *optoe, - loff_t *offset, struct i2c_client **client) -{ - unsigned int page = 0; - - *client = optoe->client[0]; - - /* if SFP style, offset > 255, shift to i2c addr 0x51 */ - if (optoe->dev_class == TWO_ADDR) { - if (*offset > 255) { - /* like QSFP, but shifted to client[1] */ - *client = optoe->client[1]; - *offset -= 256; - } - } - - /* - * if offset is in the range 0-128... - * page doesn't matter (using lower half), return 0. - * offset is already correct (don't add 128 to get to paged area) - */ - if (*offset < OPTOE_PAGE_SIZE) - return page; - - /* note, page will always be positive since *offset >= 128 */ - page = (*offset >> 7)-1; - /* 0x80 places the offset in the top half, offset is last 7 bits */ - *offset = OPTOE_PAGE_SIZE + (*offset & 0x7f); - - return page; /* note also returning client and offset */ -} - -static ssize_t optoe_eeprom_read(struct optoe_data *optoe, - struct i2c_client *client, - char *buf, unsigned int offset, size_t count) -{ - struct i2c_msg msg[2]; - u8 msgbuf[2]; - unsigned long timeout, read_time; - int status, i; - - mem_clear(msg, sizeof(msg)); - - switch (optoe->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* - * When we have a better choice than SMBus calls, use a - * combined I2C message. Write address; then read up to - * io_limit data bytes. msgbuf is u8 and will cast to our - * needs. - */ - i = 0; - msgbuf[i++] = offset; - - msg[0].addr = client->addr; - msg[0].buf = msgbuf; - msg[0].len = i; - - msg[1].addr = client->addr; - msg[1].flags = I2C_M_RD; - msg[1].buf = buf; - msg[1].len = count; - } - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - read_time = jiffies; - - switch (optoe->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_read_i2c_block_data(client, offset, - count, buf); - break; - case I2C_SMBUS_WORD_DATA: - status = i2c_smbus_read_word_data(client, offset); - if (status >= 0) { - buf[0] = status & 0xff; - if (count == 2) - buf[1] = status >> 8; - status = count; - } - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_read_byte_data(client, offset); - if (status >= 0) { - buf[0] = status; - status = count; - } - break; - default: - status = i2c_transfer(client->adapter, msg, 2); - if (status == 2) - status = count; - } - - dev_dbg(&client->dev, "eeprom read %zu@%d --> %d (%ld)\n", - count, offset, status, jiffies); - - if (status == count) /* happy path */ - return count; - - if (status == -ENXIO) /* no module present */ - return status; - - /* REVISIT: at HZ=100, this is sloooow */ - usleep_range(1000, 2000); - } while (time_before(read_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t optoe_eeprom_write(struct optoe_data *optoe, - struct i2c_client *client, - const char *buf, - unsigned int offset, size_t count) -{ - struct i2c_msg msg; - ssize_t status; - unsigned long timeout, write_time; - unsigned int next_page_start; - int i = 0; - - /* write max is at most a page - * (In this driver, write_max is actually one byte!) - */ - if (count > optoe->write_max) - count = optoe->write_max; - - /* shorten count if necessary to avoid crossing page boundary */ - next_page_start = roundup(offset + 1, OPTOE_PAGE_SIZE); - if (offset + count > next_page_start) - count = next_page_start - offset; - - switch (optoe->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* If we'll use I2C calls for I/O, set up the message */ - msg.addr = client->addr; - msg.flags = 0; - - /* msg.buf is u8 and casts will mask the values */ - msg.buf = optoe->writebuf; - - msg.buf[i++] = offset; - memcpy(&msg.buf[i], buf, count); - msg.len = i + count; - break; - } - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - write_time = jiffies; - - switch (optoe->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_write_i2c_block_data(client, - offset, count, buf); - if (status == 0) - status = count; - break; - case I2C_SMBUS_WORD_DATA: - if (count == 2) { - status = i2c_smbus_write_word_data(client, - offset, (u16)((buf[0])|(buf[1] << 8))); - } else { - /* count = 1 */ - status = i2c_smbus_write_byte_data(client, - offset, buf[0]); - } - if (status == 0) - status = count; - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_write_byte_data(client, offset, - buf[0]); - if (status == 0) - status = count; - break; - default: - status = i2c_transfer(client->adapter, &msg, 1); - if (status == 1) - status = count; - break; - } - - dev_dbg(&client->dev, "eeprom write %zu@%d --> %ld (%lu)\n", - count, offset, (long int) status, jiffies); - - if (status == count) - return count; - - /* REVISIT: at HZ=100, this is sloooow */ - usleep_range(1000, 2000); - } while (time_before(write_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe, - char *buf, loff_t off, - size_t count, int opcode) -{ - struct i2c_client *client; - ssize_t retval = 0; - uint8_t page = 0; - loff_t phy_offset = off; - int ret = 0; - - page = optoe_translate_offset(optoe, &phy_offset, &client); - dev_dbg(&client->dev, - "%s off %lld page:%d phy_offset:%lld, count:%ld, opcode:%d\n", - __func__, off, page, phy_offset, (long int) count, opcode); - if (page > 0) { - ret = optoe_eeprom_write(optoe, client, &page, - OPTOE_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_dbg(&client->dev, - "Write page register for page %d failed ret:%d!\n", - page, ret); - return ret; - } - } - - while (count) { - ssize_t status; - - if (opcode == OPTOE_READ_OP) { - status = optoe_eeprom_read(optoe, client, - buf, phy_offset, count); - } else { - status = optoe_eeprom_write(optoe, client, - buf, phy_offset, count); - } - if (status <= 0) { - if (retval == 0) - retval = status; - break; - } - buf += status; - phy_offset += status; - count -= status; - retval += status; - } - - if (page > 0) { - /* return the page register to page 0 (why?) */ - page = 0; - ret = optoe_eeprom_write(optoe, client, &page, - OPTOE_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_err(&client->dev, - "Restore page register to 0 failed:%d!\n", ret); - /* error only if nothing has been transferred */ - if (retval == 0) - retval = ret; - } - } - return retval; -} - -/* - * Figure out if this access is within the range of supported pages. - * Note this is called on every access because we don't know if the - * module has been replaced since the last call. - * If/when modules support more pages, this is the routine to update - * to validate and allow access to additional pages. - * - * Returns updated len for this access: - * - entire access is legal, original len is returned. - * - access begins legal but is too long, len is truncated to fit. - * - initial offset exceeds supported pages, return OPTOE_EOF (zero) - */ -static ssize_t optoe_page_legal(struct optoe_data *optoe, - loff_t off, size_t len) -{ - struct i2c_client *client = optoe->client[0]; - u8 regval; - int not_pageable; - int status; - size_t maxlen; - - if (off < 0) - return -EINVAL; - if (optoe->dev_class == TWO_ADDR) { - /* SFP case */ - /* if only using addr 0x50 (first 256 bytes) we're good */ - if ((off + len) <= TWO_ADDR_NO_0X51_SIZE) - return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= TWO_ADDR_EEPROM_SIZE) - return OPTOE_EOF; - /* in between, are pages supported? */ - status = optoe_eeprom_read(optoe, client, ®val, - TWO_ADDR_PAGEABLE_REG, 1); - if (status < 0) - return status; /* error out (no module?) */ - if (regval & TWO_ADDR_PAGEABLE) { - /* Pages supported, trim len to the end of pages */ - maxlen = TWO_ADDR_EEPROM_SIZE - off; - } else { - /* pages not supported, trim len to unpaged size */ - if (off >= TWO_ADDR_EEPROM_UNPAGED_SIZE) - return OPTOE_EOF; - - /* will be accessing addr 0x51, is that supported? */ - /* byte 92, bit 6 implies DDM support, 0x51 support */ - status = optoe_eeprom_read(optoe, client, ®val, - TWO_ADDR_0X51_REG, 1); - if (status < 0) - return status; - if (regval & TWO_ADDR_0X51_SUPP) { - /* addr 0x51 is OK */ - maxlen = TWO_ADDR_EEPROM_UNPAGED_SIZE - off; - } else { - /* addr 0x51 NOT supported, trim to 256 max */ - if (off >= TWO_ADDR_NO_0X51_SIZE) - return OPTOE_EOF; - maxlen = TWO_ADDR_NO_0X51_SIZE - off; - } - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, SFP, off %lld len %ld\n", - off, (long int) len); - } else { - /* QSFP case, CMIS case */ - /* if no pages needed, we're good */ - if ((off + len) <= ONE_ADDR_EEPROM_UNPAGED_SIZE) - return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= ONE_ADDR_EEPROM_SIZE) - return OPTOE_EOF; - /* in between, are pages supported? */ - status = optoe_eeprom_read(optoe, client, ®val, - ONE_ADDR_PAGEABLE_REG, 1); - if (status < 0) - return status; /* error out (no module?) */ - - if (optoe->dev_class == ONE_ADDR) { - not_pageable = QSFP_NOT_PAGEABLE; - } else { - not_pageable = CMIS_NOT_PAGEABLE; - } - dev_dbg(&client->dev, - "Paging Register: 0x%x; not_pageable mask: 0x%x\n", - regval, not_pageable); - - if (regval & not_pageable) { - /* pages not supported, trim len to unpaged size */ - if (off >= ONE_ADDR_EEPROM_UNPAGED_SIZE) - return OPTOE_EOF; - maxlen = ONE_ADDR_EEPROM_UNPAGED_SIZE - off; - } else { - /* Pages supported, trim len to the end of pages */ - maxlen = ONE_ADDR_EEPROM_SIZE - off; - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, QSFP, off %lld len %ld\n", - off, (long int) len); - } - return len; -} - -static ssize_t optoe_read_write(struct optoe_data *optoe, - char *buf, loff_t off, size_t len, int opcode) -{ - struct i2c_client *client = optoe->client[0]; - int chunk; - int status = 0; - ssize_t retval; - size_t pending_len = 0, chunk_len = 0; - loff_t chunk_offset = 0, chunk_start_offset = 0; - loff_t chunk_end_offset = 0; - - dev_dbg(&client->dev, - "%s: off %lld len:%ld, opcode:%s\n", - __func__, off, (long int) len, - (opcode == OPTOE_READ_OP) ? "r" : "w"); - if (unlikely(!len)) - return len; - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&optoe->lock); - - /* - * Confirm this access fits within the device suppored addr range - */ - status = optoe_page_legal(optoe, off, len); - if ((status == OPTOE_EOF) || (status < 0)) { - mutex_unlock(&optoe->lock); - return status; - } - len = status; - - /* - * For each (128 byte) chunk involved in this request, issue a - * separate call to sff_eeprom_update_client(), to - * ensure that each access recalculates the client/page - * and writes the page register as needed. - * Note that chunk to page mapping is confusing, is different for - * QSFP and SFP, and never needs to be done. Don't try! - */ - pending_len = len; /* amount remaining to transfer */ - retval = 0; /* amount transferred */ - for (chunk = off >> 7; chunk <= (off + len - 1) >> 7; chunk++) { - - /* - * Compute the offset and number of bytes to be read/write - * - * 1. start at an offset not equal to 0 (within the chunk) - * and read/write less than the rest of the chunk - * 2. start at an offset not equal to 0 and read/write the rest - * of the chunk - * 3. start at offset 0 (within the chunk) and read/write less - * than entire chunk - * 4. start at offset 0 (within the chunk), and read/write - * the entire chunk - */ - chunk_start_offset = chunk * OPTOE_PAGE_SIZE; - chunk_end_offset = chunk_start_offset + OPTOE_PAGE_SIZE; - - if (chunk_start_offset < off) { - chunk_offset = off; - if ((off + pending_len) < chunk_end_offset) - chunk_len = pending_len; - else - chunk_len = chunk_end_offset - off; - } else { - chunk_offset = chunk_start_offset; - if (pending_len < OPTOE_PAGE_SIZE) - chunk_len = pending_len; - else - chunk_len = OPTOE_PAGE_SIZE; - } - - dev_dbg(&client->dev, - "sff_r/w: off %lld, len %ld, chunk_start_offset %lld, chunk_offset %lld, chunk_len %ld, pending_len %ld\n", - off, (long int) len, chunk_start_offset, chunk_offset, - (long int) chunk_len, (long int) pending_len); - - /* - * note: chunk_offset is from the start of the EEPROM, - * not the start of the chunk - */ - status = optoe_eeprom_update_client(optoe, buf, - chunk_offset, chunk_len, opcode); - if (status != chunk_len) { - /* This is another 'no device present' path */ - dev_dbg(&client->dev, - "o_u_c: chunk %d c_offset %lld c_len %ld failed %d!\n", - chunk, chunk_offset, (long int) chunk_len, status); - if (status > 0) - retval += status; - if (retval == 0) - retval = status; - break; - } - buf += status; - pending_len -= status; - retval += status; - } - mutex_unlock(&optoe->lock); - - return retval; -} - -static ssize_t optoe_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct i2c_client *client = to_i2c_client(container_of(kobj, - struct device, kobj)); - struct optoe_data *optoe = i2c_get_clientdata(client); - - return optoe_read_write(optoe, buf, off, count, OPTOE_READ_OP); -} - -static ssize_t optoe_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct i2c_client *client = to_i2c_client(container_of(kobj, - struct device, kobj)); - struct optoe_data *optoe = i2c_get_clientdata(client); - - return optoe_read_write(optoe, buf, off, count, OPTOE_WRITE_OP); -} - -static int optoe_remove(struct i2c_client *client) -{ - struct optoe_data *optoe; - int i; - - optoe = i2c_get_clientdata(client); - sysfs_remove_group(&client->dev.kobj, &optoe->attr_group); - sysfs_remove_bin_file(&client->dev.kobj, &optoe->bin); - - for (i = 1; i < optoe->num_addresses; i++) - i2c_unregister_device(optoe->client[i]); - -#ifdef EEPROM_CLASS - eeprom_device_unregister(optoe->eeprom_dev); -#endif - - kfree(optoe->writebuf); - kfree(optoe); - return 0; -} - -static ssize_t show_dev_class(struct device *dev, - struct device_attribute *dattr, char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct optoe_data *optoe = i2c_get_clientdata(client); - ssize_t count; - - mutex_lock(&optoe->lock); - count = sprintf(buf, "%d\n", optoe->dev_class); - mutex_unlock(&optoe->lock); - - return count; -} - -static ssize_t set_dev_class(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct optoe_data *optoe = i2c_get_clientdata(client); - int dev_class; - - /* - * dev_class is actually the number of i2c addresses used, thus - * legal values are "1" (QSFP class) and "2" (SFP class) - * And... CMIS spec is 1 i2c address, but puts the pageable - * bit in a different location, so CMIS devices are "3" - */ - - if (kstrtoint(buf, 0, &dev_class) != 0 || - dev_class < 1 || dev_class > 3) - return -EINVAL; - - mutex_lock(&optoe->lock); - if (dev_class == TWO_ADDR) { - /* SFP family */ - /* if it doesn't exist, create 0x51 i2c address */ - if (!optoe->client[1]) { - optoe->client[1] = i2c_new_dummy_device(client->adapter, 0x51); - if (!optoe->client[1]) { - dev_err(&client->dev, - "address 0x51 unavailable\n"); - mutex_unlock(&optoe->lock); - return -EADDRINUSE; - } - } - optoe->bin.size = TWO_ADDR_EEPROM_SIZE; - optoe->num_addresses = 2; - } else { - /* one-address (eg QSFP) and CMIS family */ - /* if it exists, remove 0x51 i2c address */ - if (optoe->client[1]) - i2c_unregister_device(optoe->client[1]); - optoe->bin.size = ONE_ADDR_EEPROM_SIZE; - optoe->num_addresses = 1; - } - optoe->dev_class = dev_class; - mutex_unlock(&optoe->lock); - - return count; -} - -/* - * if using the EEPROM CLASS driver, we don't report a port_name, - * the EEPROM CLASS drive handles that. Hence all this code is - * only compiled if we are NOT using the EEPROM CLASS driver. - */ -#ifndef EEPROM_CLASS - -static ssize_t show_port_name(struct device *dev, - struct device_attribute *dattr, char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct optoe_data *optoe = i2c_get_clientdata(client); - ssize_t count; - - mutex_lock(&optoe->lock); - count = sprintf(buf, "%s\n", optoe->port_name); - mutex_unlock(&optoe->lock); - - return count; -} - -static ssize_t set_port_name(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct optoe_data *optoe = i2c_get_clientdata(client); - char port_name[MAX_PORT_NAME_LEN]; - - /* no checking, this value is not used except by show_port_name */ - - if (sscanf(buf, "%19s", port_name) != 1) - return -EINVAL; - - mutex_lock(&optoe->lock); - strcpy(optoe->port_name, port_name); - mutex_unlock(&optoe->lock); - - return count; -} - -static DEVICE_ATTR(port_name, 0644, show_port_name, set_port_name); -#endif /* if NOT defined EEPROM_CLASS, the common case */ - -static DEVICE_ATTR(dev_class, 0644, show_dev_class, set_dev_class); - -static struct attribute *optoe_attrs[] = { -#ifndef EEPROM_CLASS - &dev_attr_port_name.attr, -#endif - &dev_attr_dev_class.attr, - NULL, -}; - -static struct attribute_group optoe_attr_group = { - .attrs = optoe_attrs, -}; - -static int optoe_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - int err; - int use_smbus = 0; - struct optoe_platform_data chip; - struct optoe_data *optoe; - int num_addresses = 0; - char port_name[MAX_PORT_NAME_LEN]; - - if (client->addr != 0x50) { - dev_dbg(&client->dev, "probe, bad i2c addr: 0x%x\n", - client->addr); - err = -EINVAL; - goto exit; - } - - if (client->dev.platform_data) { - chip = *(struct optoe_platform_data *)client->dev.platform_data; - /* take the port name from the supplied platform data */ -#ifdef EEPROM_CLASS - strncpy(port_name, chip.eeprom_data->label, MAX_PORT_NAME_LEN); -#else - memcpy(port_name, chip.port_name, MAX_PORT_NAME_LEN); -#endif - dev_dbg(&client->dev, - "probe, chip provided, flags:0x%x; name: %s\n", - chip.flags, client->name); - } else { - if (!id->driver_data) { - err = -ENODEV; - goto exit; - } - dev_dbg(&client->dev, "probe, building chip\n"); - strcpy(port_name, "unitialized"); - chip.flags = 0; -#ifdef EEPROM_CLASS - chip.eeprom_data = NULL; -#endif - } - - /* Use I2C operations unless we're stuck with SMBus extensions. */ - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { - use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_WORD_DATA)) { - use_smbus = I2C_SMBUS_WORD_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_BYTE_DATA)) { - use_smbus = I2C_SMBUS_BYTE_DATA; - } else { - err = -EPFNOSUPPORT; - goto exit; - } - } - - /* - * Make room for two i2c clients - */ - num_addresses = 2; - - optoe = kzalloc(sizeof(struct optoe_data) + - num_addresses * sizeof(struct i2c_client *), - GFP_KERNEL); - if (!optoe) { - err = -ENOMEM; - goto exit; - } - - mutex_init(&optoe->lock); - - /* determine whether this is a one-address or two-address module */ - if ((strcmp(client->name, "optoe1") == 0) || - (strcmp(client->name, "sff8436") == 0)) { - /* one-address (eg QSFP) family */ - optoe->dev_class = ONE_ADDR; - chip.byte_len = ONE_ADDR_EEPROM_SIZE; - num_addresses = 1; - } else if ((strcmp(client->name, "optoe2") == 0) || - (strcmp(client->name, "24c04") == 0)) { - /* SFP family */ - optoe->dev_class = TWO_ADDR; - chip.byte_len = TWO_ADDR_EEPROM_SIZE; - num_addresses = 2; - } else if (strcmp(client->name, "optoe3") == 0) { - /* CMIS spec */ - optoe->dev_class = CMIS_ADDR; - chip.byte_len = ONE_ADDR_EEPROM_SIZE; - num_addresses = 1; - } else { /* those were the only choices */ - err = -EINVAL; - goto exit; - } - - dev_dbg(&client->dev, "dev_class: %d\n", optoe->dev_class); - optoe->use_smbus = use_smbus; - optoe->chip = chip; - optoe->num_addresses = num_addresses; - memcpy(optoe->port_name, port_name, MAX_PORT_NAME_LEN); - - /* - * Export the EEPROM bytes through sysfs, since that's convenient. - * By default, only root should see the data (maybe passwords etc) - */ - sysfs_bin_attr_init(&optoe->bin); - optoe->bin.attr.name = "eeprom"; - optoe->bin.attr.mode = 0444; - optoe->bin.read = optoe_bin_read; - optoe->bin.size = chip.byte_len; - - if (!use_smbus || - (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_WORD_DATA) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { - /* - * NOTE: AN-2079 - * Finisar recommends that the host implement 1 byte writes - * only since this module only supports 32 byte page boundaries. - * 2 byte writes are acceptable for PE and Vout changes per - * Application Note AN-2071. - */ - unsigned int write_max = 1; - - optoe->bin.write = optoe_bin_write; - optoe->bin.attr.mode |= 0200; - - if (write_max > io_limit) - write_max = io_limit; - if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) - write_max = I2C_SMBUS_BLOCK_MAX; - optoe->write_max = write_max; - - /* buffer (data + address at the beginning) */ - optoe->writebuf = kmalloc(write_max + 2, GFP_KERNEL); - if (!optoe->writebuf) { - err = -ENOMEM; - goto exit_kfree; - } - } else { - dev_warn(&client->dev, - "cannot write due to controller restrictions."); - } - - optoe->client[0] = client; - - /* SFF-8472 spec requires that the second I2C address be 0x51 */ - if (num_addresses == 2) { - optoe->client[1] = i2c_new_dummy_device(client->adapter, 0x51); - if (!optoe->client[1]) { - dev_err(&client->dev, "address 0x51 unavailable\n"); - err = -EADDRINUSE; - goto err_struct; - } - } - - /* create the sysfs eeprom file */ - err = sysfs_create_bin_file(&client->dev.kobj, &optoe->bin); - if (err) - goto err_struct; - - optoe->attr_group = optoe_attr_group; - - err = sysfs_create_group(&client->dev.kobj, &optoe->attr_group); - if (err) { - dev_err(&client->dev, "failed to create sysfs attribute group.\n"); - goto err_struct; - } - -#ifdef EEPROM_CLASS - optoe->eeprom_dev = eeprom_device_register(&client->dev, - chip.eeprom_data); - if (IS_ERR(optoe->eeprom_dev)) { - dev_err(&client->dev, "error registering eeprom device.\n"); - err = PTR_ERR(optoe->eeprom_dev); - goto err_sysfs_cleanup; - } -#endif - - i2c_set_clientdata(client, optoe); - - dev_info(&client->dev, "%zu byte %s EEPROM, %s\n", - optoe->bin.size, client->name, - optoe->bin.write ? "read/write" : "read-only"); - - if (use_smbus == I2C_SMBUS_WORD_DATA || - use_smbus == I2C_SMBUS_BYTE_DATA) { - dev_notice(&client->dev, - "Falling back to %s reads, performance will suffer\n", - use_smbus == I2C_SMBUS_WORD_DATA ? "word" : "byte"); - } - - return 0; - -#ifdef EEPROM_CLASS -err_sysfs_cleanup: - sysfs_remove_group(&client->dev.kobj, &optoe->attr_group); - sysfs_remove_bin_file(&client->dev.kobj, &optoe->bin); -#endif - -err_struct: - if (num_addresses == 2) { - if (optoe->client[1]) - i2c_unregister_device(optoe->client[1]); - } - - kfree(optoe->writebuf); -exit_kfree: - kfree(optoe); -exit: - dev_dbg(&client->dev, "probe error %d\n", err); - - return err; -} - -/*-------------------------------------------------------------------------*/ - -static struct i2c_driver optoe_driver = { - .driver = { - .name = "optoe", - .owner = THIS_MODULE, - }, - .probe = optoe_probe, - .remove = optoe_remove, - .id_table = optoe_ids, -}; - -static int __init optoe_init(void) -{ - - if (!io_limit) { - pr_err("optoe: io_limit must not be 0!\n"); - return -EINVAL; - } - - io_limit = rounddown_pow_of_two(io_limit); - return i2c_add_driver(&optoe_driver); -} -module_init(optoe_init); - -static void __exit optoe_exit(void) -{ - i2c_del_driver(&optoe_driver); -} -module_exit(optoe_exit); - -MODULE_DESCRIPTION("Driver for optical transceiver (SFP, QSFP, ...) EEPROMs"); -MODULE_AUTHOR("DON BOLLINGER "); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/ragile.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/ragile.h deleted file mode 100644 index b131829fe7..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/ragile.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef __RAGILE_H__ -#define __RAGILE_H__ - -#include -#include -#include -#include - -#define mem_clear(data, size) memset((data), 0, (size)) - -/* debug switch level */ -typedef enum { - DBG_START, - DBG_VERBOSE, - DBG_KEY, - DBG_WARN, - DBG_ERROR, - DBG_END, -} dbg_level_t; - -typedef enum dfd_cpld_id { - BCM_CPLD0 = 0, - BCM_CPLD1, - CPLD0_MAC0, - CPLD0_MAC1, - CPLD1_MAC0, - CPLD2_MAC1, -} dfd_cpld_id_t; - - typedef enum dfd_cpld_bus { - SMBUS_BUS = 0 , - GPIO_BUS = 1, - PCA9641_BUS = 2, -} dfd_cpld_bus_t; - - typedef struct dfd_i2c_dev_s { - int bus; /* bus number */ - int addr; /* bus address */ - } dfd_i2c_dev_t; - - typedef enum dfd_cpld_addr { - CPLD_ADDR_MIN = 0x31, - BCM_CPLD0_ADDR = 0x32, /* pca9641 up */ - CPLD0_MAC0_ADDR = 0x33, /* SMBUS down */ - CPLD0_MAC1_ADDR = 0x34, - CPLD1_MAC0_ADDR = 0x35, - CPLD2_MAC1_ADDR = 0x36, - BCM_CPLD1_ADDR = 0x37, - CPLD_ADDR_MAX, -} dfd_cpld_addr_t; - -typedef struct dfd_dev_head_info_s { - uint8_t ver; /* The version number defined by the E2PROM file, the initial version is 0x01 */ - uint8_t flag; /* The new version of E2PROM is identified as 0x7E */ - uint8_t hw_ver; /* It consists of two parts: the main version number and the revised version */ - uint8_t type; /* Hardware type definition information */ - int16_t tlv_len; /* Effective data length (16 bits) */ -} dfd_dev_head_info_t; - -typedef enum dfd_intf_e{ - DFD_INTF_GET_FAN_HW_VERSION, - DFD_INTF_GET_FAN_STATUS, - DFD_INTF_GET_FAN_SPEED_LEVEL, - DFD_INTF_GET_FAN_SPEED, - DFD_INTF_GET_FAN_ATTRIBUTE, - DFD_INTF_GET_FAN_SN, - DFD_INTF_GET_FAN_TYPE, - DFD_INTF_SET_FAN_SPEED_LEVEL, - DFD_INTF_GET_FAN_SUB_NUM, - DFD_INTF_GET_FAN_FAIL_BITMAP, -}dfd_intf_t; - -typedef struct dfd_dev_tlv_info_s { - uint8_t type; /* the type of data */ - uint8_t len; /* the length of data */ - uint8_t data[0]; /* data */ -} dfd_dev_tlv_info_t; - -typedef enum dfd_dev_info_type_e { - DFD_DEV_INFO_TYPE_MAC = 1, - DFD_DEV_INFO_TYPE_NAME = 2, - DFD_DEV_INFO_TYPE_SN = 3, - DFD_DEV_INFO_TYPE_PWR_CONS = 4, - DFD_DEV_INFO_TYPE_HW_INFO = 5, - DFD_DEV_INFO_TYPE_DEV_TYPE = 6, -} dfd_dev_tlv_type_t; - -struct sfp_drivers_t{ - /* addr = sff present bitmap addr, index from 0 */ - void (*get_number) (unsigned int *number); - int (*get_port_start) (void); - int (*get_port_end) (void); - bool (*is_qsfp_port) (const unsigned int port_num); - bool (*get_present) (unsigned long *bitmap); - bool (*read_sfp_eeprom) (const unsigned int port, - const unsigned char addr, - const unsigned char offset, - const uint32_t count, char *buf); - bool (*write_sfp_eeprom) (const unsigned int port, - const unsigned char addr, - const unsigned char offset, - const unsigned char count, - const char *buf); - bool (*read_sysfs) (const unsigned int bus, - const unsigned char addr, - const unsigned char offset, - const uint32_t count, char *buf); - bool (*write_sysfs) (const unsigned int bus, - const unsigned char addr, - const unsigned char offset, - const unsigned char count, - const char *buf); - bool (*read_block_sysfs) (const unsigned int bus, - const unsigned char addr, - const unsigned char offset, - const uint32_t count, char *buf); -}; - -extern int debuglevel; -extern int dfd_cpld_read_chipid(int cpldid , uint32_t addr, int32_t size, unsigned char *buf); -extern int dfd_cpld_read(int32_t addr, uint8_t *val); -extern int dfd_cpld_write(int32_t addr, uint8_t val); -extern int rg_i2c_read(uint32_t bus, uint32_t addr, uint32_t offset, uint32_t size, unsigned char *buf) ; -extern int rg_i2c_write(uint32_t bus, uint32_t addr, uint32_t offset, uint8_t buf); -extern int rg_i2c_read_block(uint32_t bus, uint32_t addr, uint32_t offset, uint32_t size, unsigned char *buf) ; -extern int ragile_setdebug(int val); -extern s32 platform_i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command); -extern s32 platform_i2c_smbus_read_i2c_block_data(const struct i2c_client *client, - u8 command, u8 length, u8 *values); -extern s32 platform_i2c_smbus_read_word_data(const struct i2c_client *client, u8 command); - -extern int sfp_drivers_register(struct sfp_drivers_t *drv); -extern int sfp_drivers_unregister(void); - -extern int sysfs_drivers_register(struct sfp_drivers_t *drv); -extern int sysfs_drivers_unregister(void); - -#define DBG_DEBUG(fmt, arg...) do { \ - if ( debuglevel > DBG_START && debuglevel < DBG_ERROR) { \ - printk(KERN_INFO "[DEBUG]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \ - } else if ( debuglevel >= DBG_ERROR ) { \ - printk(KERN_ERR "[DEBUG]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \ - } else { } \ -} while (0) - -#define DBG_INFO(fmt, arg...) do { \ - if ( debuglevel > DBG_KEY) { \ - printk(KERN_INFO "[INFO]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \ - } \ - } while (0) - -#define DBG_ERROR(fmt, arg...) do { \ - if ( debuglevel > DBG_START) { \ - printk(KERN_ERR "[ERROR]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \ - } \ - } while (0) - -#endif diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/ragile_common_module.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/ragile_common_module.c deleted file mode 100644 index b1c5a89495..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/ragile_common_module.c +++ /dev/null @@ -1,210 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ragile.h" -#include "dfd_tlveeprom.h" - -#define PLATFORM_I2C_RETRY_TIMES 3 - -#define DFD_TLVEEPROM_I2C_BUS (0) -#define DFD_TLVEEPROM_I2C_ADDR (0x56) -#define DFD_E2PROM_MAX_LEN (256) -#define DFD_CARDTYPE_EXT_TLVLEN (4) - -#define PLATFORM_CARDTYPE_RETRY_CNT (10) -#define PLATFORM_CARDTYPE_RETRY_TIMES (1000) - -int debuglevel = 0; -module_param(debuglevel, int, S_IRUGO | S_IWUSR); - -static int dfd_my_type = 0; -module_param(dfd_my_type, int, S_IRUGO | S_IWUSR); - -int g_common_debug_error = 0; -module_param(g_common_debug_error, int, S_IRUGO | S_IWUSR); - -int g_common_debug_verbose = 0; -module_param(g_common_debug_verbose, int, S_IRUGO | S_IWUSR); - -uint32_t dfd_my_type_i2c_bus = 0; -module_param(dfd_my_type_i2c_bus, int, S_IRUGO | S_IWUSR); - -uint32_t dfd_my_type_i2c_addr = 0; -module_param(dfd_my_type_i2c_addr, int, S_IRUGO | S_IWUSR); - -#define RAGILE_COMMON_DEBUG_VERBOSE(fmt, args...) do { \ - if (g_common_debug_verbose) { \ - printk(KERN_ERR "[RAGILE_COMMON][VER][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \ - } \ -} while (0) - -#define RAGILE_COMMON_DEBUG_ERROR(fmt, args...) do { \ - if (g_common_debug_error) { \ - printk(KERN_ERR "[RAGILE_COMMON][ERROR][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \ - } \ -} while (0) - -static int32_t dfd_i2c_read(char *dev, uint32_t addr, uint32_t offset_addr, unsigned char * -buf, int32_t size) -{ - struct file *fp; - mm_segment_t fs; - struct i2c_client client; - int i ,j ; - int rv; - s32 val_t; - - val_t = -1; - rv = 0; - fp = filp_open(dev, O_RDWR, S_IRUSR | S_IWUSR); - if (IS_ERR(fp)) { - DBG_ERROR("i2c open fail.\n"); - RAGILE_COMMON_DEBUG_ERROR("i2c open fail.\n"); - return -1; - } - memcpy(&client, fp->private_data, sizeof(struct i2c_client)); - client.addr = addr; - fs = get_fs(); - set_fs(KERNEL_DS); - for (j = 0 ;j < size ;j++){ - for (i = 0; i < PLATFORM_I2C_RETRY_TIMES; i++) { - if ((val_t = i2c_smbus_read_byte_data(&client, (offset_addr + j))) < 0) { - DBG_DEBUG("read try(%d)time offset_addr:%x \n", i, offset_addr); - continue; - } else { - * (buf + j) = val_t; - break; - } - } - if (val_t < 0) { - rv = -1; - break; - } - } - filp_close(fp, NULL); - set_fs(fs); - return rv; -} - -static int dfd_tlvinfo_get_cardtype(void) -{ - char i2c_path[16] = {0}; - int ret; - int cardtype; - u_int8_t eeprom[DFD_E2PROM_MAX_LEN]; - dfd_i2c_dev_t i2c_dev; - uint8_t buf[DFD_CARDTYPE_EXT_TLVLEN]; - uint8_t len; - dfd_tlv_type_t tlv_type; - - if (dfd_my_type_i2c_bus != 0) { - i2c_dev.bus = dfd_my_type_i2c_bus; - } else { - i2c_dev.bus = DFD_TLVEEPROM_I2C_BUS; - } - - if (dfd_my_type_i2c_addr != 0) { - i2c_dev.addr = dfd_my_type_i2c_addr; - } else { - i2c_dev.addr = DFD_TLVEEPROM_I2C_ADDR; - } - snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", i2c_dev.bus); - RAGILE_COMMON_DEBUG_VERBOSE("Read device eeprom info:(dev:%s, addr:%02x).\n", i2c_path, i2c_dev.addr); - - ret = dfd_i2c_read(i2c_path, i2c_dev.addr, 0, eeprom, DFD_E2PROM_MAX_LEN); - if (ret != 0) { - DBG_ERROR("Read eeprom info error(dev: %s, addr: %02x).\n", i2c_path, i2c_dev.addr); - RAGILE_COMMON_DEBUG_ERROR("Read eeprom info error(dev: %s, addr: %02x).\n", i2c_path, i2c_dev.addr); - return ret; - } - - tlv_type.main_type = TLV_CODE_VENDOR_EXT; - tlv_type.ext_type = DFD_TLVINFO_EXT_TLV_TYPE_DEV_TYPE; - len = sizeof(buf); - mem_clear(buf, len); - ret = dfd_tlvinfo_get_e2prom_info(eeprom, DFD_E2PROM_MAX_LEN, &tlv_type, buf, &len); - if (ret) { - DBG_ERROR("dfd_tlvinfo_get_e2prom_info failed ret %d.\n", ret); - return -1; - } - for (ret = 0; ret < 4; ret++) { - DBG_DEBUG("buf 0x%02x.\n", buf[ret]); - } - - cardtype = ntohl(*((uint32_t *)buf)); - DBG_DEBUG("cardtype 0x%x.\n", cardtype); - return cardtype; -} - -static int __dfd_get_my_card_type(void) -{ - return dfd_tlvinfo_get_cardtype(); -} - -/* Get its own card type */ -int dfd_get_my_card_type(void) -{ - int type; - int cnt; - - if (dfd_my_type != 0) { - DBG_DEBUG("my_type = 0x%x\r\n", dfd_my_type); - return dfd_my_type; - } - - cnt = PLATFORM_CARDTYPE_RETRY_CNT; - while (cnt--) { - type = __dfd_get_my_card_type(); - if (type < 0) { - RAGILE_COMMON_DEBUG_ERROR("__dfd_get_my_card_type fail cnt %d, ret %d.\n", cnt, type); - msleep(PLATFORM_CARDTYPE_RETRY_TIMES); - continue; - } - RAGILE_COMMON_DEBUG_VERBOSE("success to get type 0x%x.\n", type); - break; - } - - dfd_my_type = type; - return dfd_my_type; -} -EXPORT_SYMBOL(dfd_get_my_card_type); - -static int __init ragile_common_init(void) -{ - int ret; - - RAGILE_COMMON_DEBUG_VERBOSE("Enter.\n"); - ret = dfd_get_my_card_type(); - if (ret <= 0) { - RAGILE_COMMON_DEBUG_ERROR("dfd_get_my_card_type failed, ret %d.\n", ret); - printk(KERN_ERR "Warning: Device type get failed, please check the TLV-EEPROM!\n"); - return -1; - } - - RAGILE_COMMON_DEBUG_VERBOSE("Leave success type 0x%x.\n", ret); - return 0; -} - -static void __exit ragile_common_exit(void) -{ - RAGILE_COMMON_DEBUG_VERBOSE("Exit.\n"); -} - -module_init(ragile_common_init); -module_exit(ragile_common_exit); - -MODULE_DESCRIPTION("ragile Platform Support"); -MODULE_AUTHOR("tangjiamiao "); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/ragile_platform.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/ragile_platform.c deleted file mode 100644 index 06edcfdcb0..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/ragile_platform.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ragile.h" - -#define PLATFORM_I2C_RETRY_TIMES 3 - -s32 platform_i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command) -{ - int try; - s32 ret; - - ret = -1; - for (try = 0; try < PLATFORM_I2C_RETRY_TIMES; try++) { - if ((ret = i2c_smbus_read_byte_data(client, command)) >= 0 ) - break; - } - return ret; - -} -EXPORT_SYMBOL(platform_i2c_smbus_read_byte_data); - -s32 platform_i2c_smbus_read_i2c_block_data(const struct i2c_client *client, - u8 command, u8 length, u8 *values) -{ - int try; - s32 ret; - - ret = -1; - for (try = 0; try < PLATFORM_I2C_RETRY_TIMES; try++) { - if ((ret = i2c_smbus_read_i2c_block_data(client, command, length, values)) >= 0 ) - break; - } - return ret; -} -EXPORT_SYMBOL(platform_i2c_smbus_read_i2c_block_data); - -s32 platform_i2c_smbus_read_word_data(const struct i2c_client *client, u8 command) -{ - int try; - s32 ret; - - ret = -1; - for (try = 0; try < PLATFORM_I2C_RETRY_TIMES; try++) { - if ((ret = i2c_smbus_read_word_data(client, command)) >= 0 ) - break; - } - return ret; -} -EXPORT_SYMBOL(platform_i2c_smbus_read_word_data); - -static int __init ragile_platform_init(void) -{ - return 0; -} - -static void __exit ragile_platform_exit(void) -{ - -} - -module_init(ragile_platform_init); -module_exit(ragile_platform_exit); - -MODULE_DESCRIPTION("ragile Platform Support"); -MODULE_AUTHOR("tangjiamiao "); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/rg_at24.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/rg_at24.c deleted file mode 100755 index f5fd0bb0b3..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/rg_at24.c +++ /dev/null @@ -1,858 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * at24.c - handle most I2C EEPROMs - * - * Copyright (C) 2005-2007 David Brownell - * Copyright (C) 2008 Wolfram Sang, Pengutronix - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Address pointer is 16 bit. */ -#define AT24_FLAG_ADDR16 BIT(7) -/* sysfs-entry will be read-only. */ -#define AT24_FLAG_READONLY BIT(6) -/* sysfs-entry will be world-readable. */ -#define AT24_FLAG_IRUGO BIT(5) -/* Take always 8 addresses (24c00). */ -#define AT24_FLAG_TAKE8ADDR BIT(4) -/* Factory-programmed serial number. */ -#define AT24_FLAG_SERIAL BIT(3) -/* Factory-programmed mac address. */ -#define AT24_FLAG_MAC BIT(2) -/* Does not auto-rollover reads to the next slave address. */ -#define AT24_FLAG_NO_RDROL BIT(1) - -/* - * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. - * Differences between different vendor product lines (like Atmel AT24C or - * MicroChip 24LC, etc) won't much matter for typical read/write access. - * There are also I2C RAM chips, likewise interchangeable. One example - * would be the PCF8570, which acts like a 24c02 EEPROM (256 bytes). - * - * However, misconfiguration can lose data. "Set 16-bit memory address" - * to a part with 8-bit addressing will overwrite data. Writing with too - * big a page size also loses data. And it's not safe to assume that the - * conventional addresses 0x50..0x57 only hold eeproms; a PCF8563 RTC - * uses 0x51, for just one example. - * - * Accordingly, explicit board-specific configuration data should be used - * in almost all cases. (One partial exception is an SMBus used to access - * "SPD" data for DRAM sticks. Those only use 24c02 EEPROMs.) - * - * So this driver uses "new style" I2C driver binding, expecting to be - * told what devices exist. That may be in arch/X/mach-Y/board-Z.c or - * similar kernel-resident tables; or, configuration data coming from - * a bootloader. - * - * Other than binding model, current differences from "eeprom" driver are - * that this one handles write access and isn't restricted to 24c02 devices. - * It also handles larger devices (32 kbit and up) with two-byte addresses, - * which won't work on pure SMBus systems. - */ - -struct at24_client { - struct i2c_client *client; - struct regmap *regmap; -}; - -struct at24_data { - /* - * Lock protects against activities from other Linux tasks, - * but not from changes by other I2C masters. - */ - struct mutex lock; - - unsigned int write_max; - unsigned int num_addresses; - unsigned int offset_adj; - - u32 byte_len; - u16 page_size; - u8 flags; - - struct nvmem_device *nvmem; - struct regulator *vcc_reg; - void (*read_post)(unsigned int off, char *buf, size_t count); - - /* - * Some chips tie up multiple I2C addresses; dummy devices reserve - * them for us, and we'll use them with SMBus calls. - */ - struct at24_client client[]; -}; - -/* - * This parameter is to help this driver avoid blocking other drivers out - * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C - * clock, one 256 byte read takes about 1/43 second which is excessive; - * but the 1/170 second it takes at 400 kHz may be quite reasonable; and - * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. - * - * This value is forced to be a power of two so that writes align on pages. - */ -static unsigned int at24_io_limit = 128; -module_param_named(io_limit, at24_io_limit, uint, 0); -MODULE_PARM_DESC(at24_io_limit, "Maximum bytes per I/O (default 128)"); - -/* - * Specs often allow 5 msec for a page write, sometimes 20 msec; - * it's important to recover from write timeouts. - */ -static unsigned int at24_write_timeout = 25; -module_param_named(write_timeout, at24_write_timeout, uint, 0); -MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)"); - -struct at24_chip_data { - u32 byte_len; - u8 flags; - void (*read_post)(unsigned int off, char *buf, size_t count); -}; - -#define AT24_CHIP_DATA(_name, _len, _flags) \ - static const struct at24_chip_data _name = { \ - .byte_len = _len, .flags = _flags, \ - } - -#define AT24_CHIP_DATA_CB(_name, _len, _flags, _read_post) \ - static const struct at24_chip_data _name = { \ - .byte_len = _len, .flags = _flags, \ - .read_post = _read_post, \ - } - -static void at24_read_post_vaio(unsigned int off, char *buf, size_t count) -{ - int i; - - if (capable(CAP_SYS_ADMIN)) - return; - - /* - * Hide VAIO private settings to regular users: - * - BIOS passwords: bytes 0x00 to 0x0f - * - UUID: bytes 0x10 to 0x1f - * - Serial number: 0xc0 to 0xdf - */ - for (i = 0; i < count; i++) { - if ((off + i <= 0x1f) || - (off + i >= 0xc0 && off + i <= 0xdf)) - buf[i] = 0; - } -} - -/* needs 8 addresses as A0-A2 are ignored */ -AT24_CHIP_DATA(at24_data_24c00, 128 / 8, AT24_FLAG_TAKE8ADDR); -/* old variants can't be handled with this generic entry! */ -AT24_CHIP_DATA(at24_data_24c01, 1024 / 8, 0); -AT24_CHIP_DATA(at24_data_24cs01, 16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY); -AT24_CHIP_DATA(at24_data_24c02, 2048 / 8, AT24_FLAG_IRUGO); -AT24_CHIP_DATA(at24_data_24cs02, 16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY); -AT24_CHIP_DATA(at24_data_24mac402, 48 / 8, - AT24_FLAG_MAC | AT24_FLAG_READONLY); -AT24_CHIP_DATA(at24_data_24mac602, 64 / 8, - AT24_FLAG_MAC | AT24_FLAG_READONLY); -/* spd is a 24c02 in memory DIMMs */ -AT24_CHIP_DATA(at24_data_spd, 2048 / 8, - AT24_FLAG_READONLY | AT24_FLAG_IRUGO); -/* 24c02_vaio is a 24c02 on some Sony laptops */ -AT24_CHIP_DATA_CB(at24_data_24c02_vaio, 2048 / 8, - AT24_FLAG_READONLY | AT24_FLAG_IRUGO, - at24_read_post_vaio); -AT24_CHIP_DATA(at24_data_24c04, 4096 / 8, 0); -AT24_CHIP_DATA(at24_data_24cs04, 16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY); -/* 24rf08 quirk is handled at i2c-core */ -AT24_CHIP_DATA(at24_data_24c08, 8192 / 8, 0); -AT24_CHIP_DATA(at24_data_24cs08, 16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY); -AT24_CHIP_DATA(at24_data_24c16, 16384 / 8, 0); -AT24_CHIP_DATA(at24_data_24cs16, 16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY); -AT24_CHIP_DATA(at24_data_24c32, 32768 / 8, AT24_FLAG_ADDR16); -AT24_CHIP_DATA(at24_data_24cs32, 16, - AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); -AT24_CHIP_DATA(at24_data_24c64, 65536 / 8, AT24_FLAG_ADDR16 | AT24_FLAG_IRUGO); -AT24_CHIP_DATA(at24_data_24cs64, 16, - AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); -AT24_CHIP_DATA(at24_data_24c128, 131072 / 8, AT24_FLAG_ADDR16); -AT24_CHIP_DATA(at24_data_24c256, 262144 / 8, AT24_FLAG_ADDR16); -AT24_CHIP_DATA(at24_data_24c512, 524288 / 8, AT24_FLAG_ADDR16); -AT24_CHIP_DATA(at24_data_24c1024, 1048576 / 8, AT24_FLAG_ADDR16); -AT24_CHIP_DATA(at24_data_24c2048, 2097152 / 8, AT24_FLAG_ADDR16); -/* identical to 24c08 ? */ -AT24_CHIP_DATA(at24_data_INT3499, 8192 / 8, 0); - -static const struct i2c_device_id at24_ids[] = { - { "rg_24c00", (kernel_ulong_t)&at24_data_24c00 }, - { "rg_24c01", (kernel_ulong_t)&at24_data_24c01 }, - { "rg_24cs01", (kernel_ulong_t)&at24_data_24cs01 }, - { "rg_24c02", (kernel_ulong_t)&at24_data_24c02 }, - { "rg_24cs02", (kernel_ulong_t)&at24_data_24cs02 }, - { "rg_24mac402", (kernel_ulong_t)&at24_data_24mac402 }, - { "rg_24mac602", (kernel_ulong_t)&at24_data_24mac602 }, - { "rg_spd", (kernel_ulong_t)&at24_data_spd }, - { "rg_24c02-vaio", (kernel_ulong_t)&at24_data_24c02_vaio }, - { "rg_24c04", (kernel_ulong_t)&at24_data_24c04 }, - { "rg_24cs04", (kernel_ulong_t)&at24_data_24cs04 }, - { "rg_24c08", (kernel_ulong_t)&at24_data_24c08 }, - { "rg_24cs08", (kernel_ulong_t)&at24_data_24cs08 }, - { "rg_24c16", (kernel_ulong_t)&at24_data_24c16 }, - { "rg_24cs16", (kernel_ulong_t)&at24_data_24cs16 }, - { "rg_24c32", (kernel_ulong_t)&at24_data_24c32 }, - { "rg_24cs32", (kernel_ulong_t)&at24_data_24cs32 }, - { "rg_24c64", (kernel_ulong_t)&at24_data_24c64 }, - { "rg_24cs64", (kernel_ulong_t)&at24_data_24cs64 }, - { "rg_24c128", (kernel_ulong_t)&at24_data_24c128 }, - { "rg_24c256", (kernel_ulong_t)&at24_data_24c256 }, - { "rg_24c512", (kernel_ulong_t)&at24_data_24c512 }, - { "rg_24c1024", (kernel_ulong_t)&at24_data_24c1024 }, - { "rg_24c2048", (kernel_ulong_t)&at24_data_24c2048 }, - { "rg_at24", 0 }, - { /* END OF LIST */ } -}; -MODULE_DEVICE_TABLE(i2c, at24_ids); - -static const struct of_device_id at24_of_match[] = { - { .compatible = "atmel,24c00", .data = &at24_data_24c00 }, - { .compatible = "atmel,24c01", .data = &at24_data_24c01 }, - { .compatible = "atmel,24cs01", .data = &at24_data_24cs01 }, - { .compatible = "atmel,24c02", .data = &at24_data_24c02 }, - { .compatible = "atmel,24cs02", .data = &at24_data_24cs02 }, - { .compatible = "atmel,24mac402", .data = &at24_data_24mac402 }, - { .compatible = "atmel,24mac602", .data = &at24_data_24mac602 }, - { .compatible = "atmel,spd", .data = &at24_data_spd }, - { .compatible = "atmel,24c04", .data = &at24_data_24c04 }, - { .compatible = "atmel,24cs04", .data = &at24_data_24cs04 }, - { .compatible = "atmel,24c08", .data = &at24_data_24c08 }, - { .compatible = "atmel,24cs08", .data = &at24_data_24cs08 }, - { .compatible = "atmel,24c16", .data = &at24_data_24c16 }, - { .compatible = "atmel,24cs16", .data = &at24_data_24cs16 }, - { .compatible = "atmel,24c32", .data = &at24_data_24c32 }, - { .compatible = "atmel,24cs32", .data = &at24_data_24cs32 }, - { .compatible = "atmel,24c64", .data = &at24_data_24c64 }, - { .compatible = "atmel,24cs64", .data = &at24_data_24cs64 }, - { .compatible = "atmel,24c128", .data = &at24_data_24c128 }, - { .compatible = "atmel,24c256", .data = &at24_data_24c256 }, - { .compatible = "atmel,24c512", .data = &at24_data_24c512 }, - { .compatible = "atmel,24c1024", .data = &at24_data_24c1024 }, - { .compatible = "atmel,24c2048", .data = &at24_data_24c2048 }, - { /* END OF LIST */ }, -}; -MODULE_DEVICE_TABLE(of, at24_of_match); - -static const struct acpi_device_id __maybe_unused at24_acpi_ids[] = { - { "INT3499", (kernel_ulong_t)&at24_data_INT3499 }, - { "TPF0001", (kernel_ulong_t)&at24_data_24c1024 }, - { /* END OF LIST */ } -}; -MODULE_DEVICE_TABLE(acpi, at24_acpi_ids); - -/* - * This routine supports chips which consume multiple I2C addresses. It - * computes the addressing information to be used for a given r/w request. - * Assumes that sanity checks for offset happened at sysfs-layer. - * - * Slave address and byte offset derive from the offset. Always - * set the byte address; on a multi-master board, another master - * may have changed the chip's "current" address pointer. - */ -static struct at24_client *at24_translate_offset(struct at24_data *at24, - unsigned int *offset) -{ - unsigned int i; - - if (at24->flags & AT24_FLAG_ADDR16) { - i = *offset >> 16; - *offset &= 0xffff; - } else { - i = *offset >> 8; - *offset &= 0xff; - } - - return &at24->client[i]; -} - -static struct device *at24_base_client_dev(struct at24_data *at24) -{ - return &at24->client[0].client->dev; -} - -static size_t at24_adjust_read_count(struct at24_data *at24, - unsigned int offset, size_t count) -{ - unsigned int bits; - size_t remainder; - - /* - * In case of multi-address chips that don't rollover reads to - * the next slave address: truncate the count to the slave boundary, - * so that the read never straddles slaves. - */ - if (at24->flags & AT24_FLAG_NO_RDROL) { - bits = (at24->flags & AT24_FLAG_ADDR16) ? 16 : 8; - remainder = BIT(bits) - offset; - if (count > remainder) - count = remainder; - } - - if (count > at24_io_limit) - count = at24_io_limit; - - return count; -} - -static ssize_t at24_regmap_read(struct at24_data *at24, char *buf, - unsigned int offset, size_t count) -{ - unsigned long timeout, read_time; - struct at24_client *at24_client; - struct i2c_client *client; - struct regmap *regmap; - int ret; - - at24_client = at24_translate_offset(at24, &offset); - regmap = at24_client->regmap; - client = at24_client->client; - count = at24_adjust_read_count(at24, offset, count); - - /* adjust offset for mac and serial read ops */ - offset += at24->offset_adj; - - timeout = jiffies + msecs_to_jiffies(at24_write_timeout); - do { - /* - * The timestamp shall be taken before the actual operation - * to avoid a premature timeout in case of high CPU load. - */ - read_time = jiffies; - - ret = regmap_bulk_read(regmap, offset, buf, count); - dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", - count, offset, ret, jiffies); - if (!ret) - return count; - - usleep_range(1000, 1500); - } while (time_before(read_time, timeout)); - - return -ETIMEDOUT; -} - -/* - * Note that if the hardware write-protect pin is pulled high, the whole - * chip is normally write protected. But there are plenty of product - * variants here, including OTP fuses and partial chip protect. - * - * We only use page mode writes; the alternative is sloooow. These routines - * write at most one page. - */ - -static size_t at24_adjust_write_count(struct at24_data *at24, - unsigned int offset, size_t count) -{ - unsigned int next_page; - - /* write_max is at most a page */ - if (count > at24->write_max) - count = at24->write_max; - - /* Never roll over backwards, to the start of this page */ - next_page = roundup(offset + 1, at24->page_size); - if (offset + count > next_page) - count = next_page - offset; - - return count; -} - -static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf, - unsigned int offset, size_t count) -{ - unsigned long timeout, write_time; - struct at24_client *at24_client; - struct i2c_client *client; - struct regmap *regmap; - int ret; - - at24_client = at24_translate_offset(at24, &offset); - regmap = at24_client->regmap; - client = at24_client->client; - count = at24_adjust_write_count(at24, offset, count); - timeout = jiffies + msecs_to_jiffies(at24_write_timeout); - - do { - /* - * The timestamp shall be taken before the actual operation - * to avoid a premature timeout in case of high CPU load. - */ - write_time = jiffies; - - ret = regmap_bulk_write(regmap, offset, buf, count); - dev_dbg(&client->dev, "write %zu@%d --> %d (%ld)\n", - count, offset, ret, jiffies); - if (!ret) - return count; - - usleep_range(1000, 1500); - } while (time_before(write_time, timeout)); - - return -ETIMEDOUT; -} - -static int at24_read(void *priv, unsigned int off, void *val, size_t count) -{ - struct at24_data *at24; - struct device *dev; - char *buf = val; - int i, ret; - - at24 = priv; - dev = at24_base_client_dev(at24); - - if (unlikely(!count)) - return count; - - if (off + count > at24->byte_len) - return -EINVAL; - - ret = pm_runtime_get_sync(dev); - if (ret < 0) { - pm_runtime_put_noidle(dev); - return ret; - } - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&at24->lock); - - for (i = 0; count; i += ret, count -= ret) { - ret = at24_regmap_read(at24, buf + i, off + i, count); - if (ret < 0) { - mutex_unlock(&at24->lock); - pm_runtime_put(dev); - return ret; - } - } - - mutex_unlock(&at24->lock); - - pm_runtime_put(dev); - - if (unlikely(at24->read_post)) - at24->read_post(off, buf, i); - - return 0; -} - -static int at24_write(void *priv, unsigned int off, void *val, size_t count) -{ - struct at24_data *at24; - struct device *dev; - char *buf = val; - int ret; - - at24 = priv; - dev = at24_base_client_dev(at24); - - if (unlikely(!count)) - return -EINVAL; - - if (off + count > at24->byte_len) - return -EINVAL; - - ret = pm_runtime_get_sync(dev); - if (ret < 0) { - pm_runtime_put_noidle(dev); - return ret; - } - - /* - * Write data to chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&at24->lock); - - while (count) { - ret = at24_regmap_write(at24, buf, off, count); - if (ret < 0) { - mutex_unlock(&at24->lock); - pm_runtime_put(dev); - return ret; - } - buf += ret; - off += ret; - count -= ret; - } - - mutex_unlock(&at24->lock); - - pm_runtime_put(dev); - - return 0; -} - -static const struct at24_chip_data *at24_get_chip_data(struct device *dev) -{ - struct device_node *of_node = dev->of_node; - const struct at24_chip_data *cdata; - const struct i2c_device_id *id; - - id = i2c_match_id(at24_ids, to_i2c_client(dev)); - - /* - * The I2C core allows OF nodes compatibles to match against the - * I2C device ID table as a fallback, so check not only if an OF - * node is present but also if it matches an OF device ID entry. - */ - if (of_node && of_match_device(at24_of_match, dev)) - cdata = of_device_get_match_data(dev); - else if (id) - cdata = (void *)id->driver_data; - else - cdata = acpi_device_get_match_data(dev); - - if (!cdata) - return ERR_PTR(-ENODEV); - - return cdata; -} - -static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, - struct regmap_config *regmap_config) -{ - struct i2c_client *base_client, *dummy_client; - struct regmap *regmap; - struct device *dev; - - base_client = at24->client[0].client; - dev = &base_client->dev; - - dummy_client = devm_i2c_new_dummy_device(dev, base_client->adapter, - base_client->addr + index); - if (IS_ERR(dummy_client)) - return PTR_ERR(dummy_client); - - regmap = devm_regmap_init_i2c(dummy_client, regmap_config); - if (IS_ERR(regmap)) - return PTR_ERR(regmap); - - at24->client[index].client = dummy_client; - at24->client[index].regmap = regmap; - - return 0; -} - -static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len) -{ - if (flags & AT24_FLAG_MAC) { - /* EUI-48 starts from 0x9a, EUI-64 from 0x98 */ - return 0xa0 - byte_len; - } else if (flags & AT24_FLAG_SERIAL && flags & AT24_FLAG_ADDR16) { - /* - * For 16 bit address pointers, the word address must contain - * a '10' sequence in bits 11 and 10 regardless of the - * intended position of the address pointer. - */ - return 0x0800; - } else if (flags & AT24_FLAG_SERIAL) { - /* - * Otherwise the word address must begin with a '10' sequence, - * regardless of the intended address. - */ - return 0x0080; - } else { - return 0; - } -} - -static int at24_probe(struct i2c_client *client) -{ - struct regmap_config regmap_config = { }; - struct nvmem_config nvmem_config = { }; - u32 byte_len, page_size, flags, addrw; - const struct at24_chip_data *cdata; - struct device *dev = &client->dev; - bool i2c_fn_i2c, i2c_fn_block; - unsigned int i, num_addresses; - struct at24_data *at24; - struct regmap *regmap; - bool writable; - u8 test_byte; - int err; - - i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C); - i2c_fn_block = i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK); - - cdata = at24_get_chip_data(dev); - if (IS_ERR(cdata)) - return PTR_ERR(cdata); - - err = device_property_read_u32(dev, "pagesize", &page_size); - if (err) - /* - * This is slow, but we can't know all eeproms, so we better - * play safe. Specifying custom eeprom-types via device tree - * or properties is recommended anyhow. - */ - page_size = 1; - - flags = cdata->flags; - if (device_property_present(dev, "read-only")) - flags |= AT24_FLAG_READONLY; - if (device_property_present(dev, "no-read-rollover")) - flags |= AT24_FLAG_NO_RDROL; - - err = device_property_read_u32(dev, "address-width", &addrw); - if (!err) { - switch (addrw) { - case 8: - if (flags & AT24_FLAG_ADDR16) - dev_warn(dev, - "Override address width to be 8, while default is 16\n"); - flags &= ~AT24_FLAG_ADDR16; - break; - case 16: - flags |= AT24_FLAG_ADDR16; - break; - default: - dev_warn(dev, "Bad \"address-width\" property: %u\n", - addrw); - } - } - - err = device_property_read_u32(dev, "size", &byte_len); - if (err) - byte_len = cdata->byte_len; - - if (!i2c_fn_i2c && !i2c_fn_block) - page_size = 1; - - if (!page_size) { - dev_err(dev, "page_size must not be 0!\n"); - return -EINVAL; - } - - if (!is_power_of_2(page_size)) - dev_warn(dev, "page_size looks suspicious (no power of 2)!\n"); - - err = device_property_read_u32(dev, "num-addresses", &num_addresses); - if (err) { - if (flags & AT24_FLAG_TAKE8ADDR) - num_addresses = 8; - else - num_addresses = DIV_ROUND_UP(byte_len, - (flags & AT24_FLAG_ADDR16) ? 65536 : 256); - } - - if ((flags & AT24_FLAG_SERIAL) && (flags & AT24_FLAG_MAC)) { - dev_err(dev, - "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); - return -EINVAL; - } - - regmap_config.val_bits = 8; - regmap_config.reg_bits = (flags & AT24_FLAG_ADDR16) ? 16 : 8; - regmap_config.disable_locking = true; - - regmap = devm_regmap_init_i2c(client, ®map_config); - if (IS_ERR(regmap)) - return PTR_ERR(regmap); - - at24 = devm_kzalloc(dev, struct_size(at24, client, num_addresses), - GFP_KERNEL); - if (!at24) - return -ENOMEM; - - mutex_init(&at24->lock); - at24->byte_len = byte_len; - at24->page_size = page_size; - at24->flags = flags; - at24->read_post = cdata->read_post; - at24->num_addresses = num_addresses; - at24->offset_adj = at24_get_offset_adj(flags, byte_len); - at24->client[0].client = client; - at24->client[0].regmap = regmap; - - at24->vcc_reg = devm_regulator_get(dev, "vcc"); - if (IS_ERR(at24->vcc_reg)) - return PTR_ERR(at24->vcc_reg); - - writable = !(flags & AT24_FLAG_READONLY); - if (writable) { - at24->write_max = min_t(unsigned int, - page_size, at24_io_limit); - if (!i2c_fn_i2c && at24->write_max > I2C_SMBUS_BLOCK_MAX) - at24->write_max = I2C_SMBUS_BLOCK_MAX; - } - - /* use dummy devices for multiple-address chips */ - for (i = 1; i < num_addresses; i++) { - err = at24_make_dummy_client(at24, i, ®map_config); - if (err) - return err; - } - - /* - * If the 'label' property is not present for the AT24 EEPROM, - * then nvmem_config.id is initialised to NVMEM_DEVID_AUTO, - * and this will append the 'devid' to the name of the NVMEM - * device. This is purely legacy and the AT24 driver has always - * defaulted to this. However, if the 'label' property is - */ - nvmem_config.id = NVMEM_DEVID_AUTO; - - if (device_property_present(dev, "label")) { - err = device_property_read_string(dev, "label", - &nvmem_config.name); - if (err) - return err; - } else { - nvmem_config.name = dev_name(dev); - } - - nvmem_config.type = NVMEM_TYPE_EEPROM; - nvmem_config.dev = dev; - nvmem_config.read_only = !writable; - nvmem_config.root_only = !(flags & AT24_FLAG_IRUGO); - nvmem_config.owner = THIS_MODULE; - nvmem_config.compat = true; - nvmem_config.base_dev = dev; - nvmem_config.reg_read = at24_read; - nvmem_config.reg_write = at24_write; - nvmem_config.priv = at24; - nvmem_config.stride = 1; - nvmem_config.word_size = 1; - nvmem_config.size = byte_len; - - i2c_set_clientdata(client, at24); - - err = regulator_enable(at24->vcc_reg); - if (err) { - dev_err(dev, "Failed to enable vcc regulator\n"); - return err; - } - - /* enable runtime pm */ - pm_runtime_set_active(dev); - pm_runtime_enable(dev); - - at24->nvmem = devm_nvmem_register(dev, &nvmem_config); - if (IS_ERR(at24->nvmem)) { - pm_runtime_disable(dev); - if (!pm_runtime_status_suspended(dev)) - regulator_disable(at24->vcc_reg); - return PTR_ERR(at24->nvmem); - } - - /* - * Perform a one-byte test read to verify that the - * chip is functional. - */ - err = at24_read(at24, 0, &test_byte, 1); - if (err) { - pm_runtime_disable(dev); - if (!pm_runtime_status_suspended(dev)) - regulator_disable(at24->vcc_reg); - return -ENODEV; - } - - pm_runtime_idle(dev); - - if (writable) - dev_info(dev, "%u byte %s EEPROM, writable, %u bytes/write\n", - byte_len, client->name, at24->write_max); - else - dev_info(dev, "%u byte %s EEPROM, read-only\n", - byte_len, client->name); - - return 0; -} - -static int at24_remove(struct i2c_client *client) -{ - struct at24_data *at24 = i2c_get_clientdata(client); - - pm_runtime_disable(&client->dev); - if (!pm_runtime_status_suspended(&client->dev)) - regulator_disable(at24->vcc_reg); - pm_runtime_set_suspended(&client->dev); - - return 0; -} - -static int __maybe_unused at24_suspend(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct at24_data *at24 = i2c_get_clientdata(client); - - return regulator_disable(at24->vcc_reg); -} - -static int __maybe_unused at24_resume(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct at24_data *at24 = i2c_get_clientdata(client); - - return regulator_enable(at24->vcc_reg); -} - -static const struct dev_pm_ops at24_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, - pm_runtime_force_resume) - SET_RUNTIME_PM_OPS(at24_suspend, at24_resume, NULL) -}; - -static struct i2c_driver at24_driver = { - .driver = { - .name = "rg_at24", - .pm = &at24_pm_ops, - .of_match_table = at24_of_match, - .acpi_match_table = ACPI_PTR(at24_acpi_ids), - }, - .probe_new = at24_probe, - .remove = at24_remove, - .id_table = at24_ids, -}; - -static int __init at24_init(void) -{ - if (!at24_io_limit) { - pr_err("at24: at24_io_limit must not be 0!\n"); - return -EINVAL; - } - - at24_io_limit = rounddown_pow_of_two(at24_io_limit); - return i2c_add_driver(&at24_driver); -} -module_init(at24_init); - -static void __exit at24_exit(void) -{ - i2c_del_driver(&at24_driver); -} -module_exit(at24_exit); - -MODULE_DESCRIPTION("Driver for most I2C EEPROMs"); -MODULE_AUTHOR("David Brownell and Wolfram Sang"); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/rg_spi_gpio.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/rg_spi_gpio.c deleted file mode 100644 index aadb2902ad..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/rg_spi_gpio.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * EEPROMs access control driver for display configuration EEPROMs - * on DigsyMTC board. - * - * (C) 2011 DENX Software Engineering, Anatolij Gustschin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define GPIO_TPM_CLK 496 -#define GPIO_TPM_CS 500 -#define GPIO_TPM_DI 499 -#define GPIO_TPM_DO 498 - -#define EE_SPI_BUS_NUM 1 - -static struct spi_gpio_platform_data tpm_spi_gpio_data = { - .sck = GPIO_TPM_CLK, - .mosi = GPIO_TPM_DI, - .miso = GPIO_TPM_DO, - .num_chipselect = 2, -}; - -static void spi_gpio_release(struct device *dev) -{ - return; -} -static struct platform_device tpm_device = { - .name = "spi_gpio", - .id = 3, - .dev = { - .platform_data = &tpm_spi_gpio_data, - .release = spi_gpio_release, - } -}; - -static struct spi_board_info tpm_info = { - .modalias = "tpm_tis_spi", - .max_speed_hz = 1000000, - .bus_num = 3, - .chip_select = 0, /* 0 ,1 */ - .mode = SPI_MODE_0, - .controller_data = (void *)GPIO_TPM_CS, -}; - -static int __init tpm_devices_init(void) -{ - int ret; - struct spi_master *master; - - ret = platform_device_register(&tpm_device); - if (ret) { - printk("can't add spi-gpio device \n"); - return ret; - } - - master = spi_busnum_to_master(tpm_info.bus_num); - if( !master ) { - return -ENODEV; - } - printk(KERN_INFO "enter tpm_devices_init. \n"); - - spi_new_device(master, &tpm_info); - return 0 ; -} - -static void __exit tpm_devices_exit(void) -{ - platform_device_unregister(&tpm_device); -} - -module_init(tpm_devices_init); -module_exit(tpm_devices_exit); - -MODULE_DESCRIPTION("ragile spi gpio device Support"); -MODULE_AUTHOR("support@ragilenetworks.com"); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/rtcpcf85063.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/rtcpcf85063.c deleted file mode 100644 index bd61185036..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/rtcpcf85063.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - * An I2C driver for the PCF85063 RTC - * Copyright 2014 Rose Technology - * - * Author: Sren Andersen - * Maintainers: http://www.nslu2-linux.org/ - * - * based on the other drivers in this same directory. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ -#include -#include -#include -#include - -/* - * Information for this driver was pulled from the following datasheets. - * - * http://www.nxp.com/documents/data_sheet/PCF85063A.pdf - * http://www.nxp.com/documents/data_sheet/PCF85063TP.pdf - * -*/ - -#define PCF85063_REG_CTRL1 0x00 /* status */ -#define PCF85063_REG_CTRL1_CAP_SEL BIT(0) -#define PCF85063_REG_CTRL1_STOP BIT(5) -#define PCF85063_REG_CTRL2 0x01 -#define PCF85063_REG_CTRL2_COF 0x07 -#define PCF85063_REG_SC 0x04 /* datetime */ -#define PCF85063_REG_SC_OS 0x80 -#define PCF85063_REG_MN 0x05 -#define PCF85063_REG_HR 0x06 -#define PCF85063_REG_DM 0x07 -#define PCF85063_REG_DW 0x08 -#define PCF85063_REG_MO 0x09 -#define PCF85063_REG_YR 0x0A -#define PCF85063_SR 0x58 - -static struct i2c_driver pcf85063_driver; - -static int pcf85063_stop_clock(struct i2c_client *client, u8 *ctrl1) -{ - s32 ret; - - ret = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1); - if (ret < 0) { - dev_err(&client->dev, "Failing to stop the clock\n"); - return -EIO; - } - - /* stop the clock */ - ret |= PCF85063_REG_CTRL1_STOP; - - ret = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ret); - if (ret < 0) { - dev_err(&client->dev, "Failing to stop the clock\n"); - return -EIO; - } - - *ctrl1 = ret; - - return 0; -} - -static int pcf85063_start_clock(struct i2c_client *client, u8 ctrl1) -{ - s32 ret; - - /* start the clock */ - ctrl1 &= ~PCF85063_REG_CTRL1_STOP; - ret = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ctrl1); - if (ret < 0) { - dev_err(&client->dev, "Failing to start the clock\n"); - return -EIO; - } - - return 0; -} - -static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm) -{ - int rc; - u8 regs[7]; - - /* - * while reading, the time/date registers are blocked and not updated - * anymore until the access is finished. To not lose a second - * event, the access must be finished within one second. So, read all - * time/date registers in one turn. - */ - rc = i2c_smbus_read_i2c_block_data(client, PCF85063_REG_SC, - sizeof(regs), regs); - if (rc != sizeof(regs)) { - dev_err(&client->dev, "date/time register read error\n"); - return -EIO; - } - - /* if the clock has lost its power it makes no sense to use its time */ - if (regs[0] & PCF85063_REG_SC_OS) { - dev_warn(&client->dev, "Power loss detected, invalid time\n"); - return -EINVAL; - } - - tm->tm_sec = bcd2bin(regs[0] & 0x7F); - tm->tm_min = bcd2bin(regs[1] & 0x7F); - tm->tm_hour = bcd2bin(regs[2] & 0x3F); /* rtc hr 0-23 */ - tm->tm_mday = bcd2bin(regs[3] & 0x3F); - tm->tm_wday = regs[4] & 0x07; - tm->tm_mon = bcd2bin(regs[5] & 0x1F) - 1; /* rtc mn 1-12 */ - tm->tm_year = bcd2bin(regs[6]); - tm->tm_year += 100; - - return rtc_valid_tm(tm); -} - -static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_time *tm) -{ - int rc; - u8 regs[7]; - u8 ctrl1; - u8 cof; - s32 err; - - cof = 0; - cof |= PCF85063_REG_CTRL2_COF; - if ((tm->tm_year < 100) || (tm->tm_year > 199)) - return -EINVAL; - - /* reset rtc-pcf85063 */ - err = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, PCF85063_SR); - if (err < 0) { - dev_err(&client->dev, "Failing to reset rtc-pcf85063\n"); - return EIO; - } - - /* - * to accurately set the time, reset the divider chain and keep it in - * reset state until all time/date registers are written - */ - rc = pcf85063_stop_clock(client, &ctrl1); - if (rc != 0) - return rc; - - /* set CTRL1 CAP_SEL is 12.5pF */ - ctrl1 |= PCF85063_REG_CTRL1_CAP_SEL; - err = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ctrl1); - if (err < 0) { - dev_err(&client->dev, "Failing to write the PCF85063_REG_CTRL1\n"); - return -EIO; - } - /* set CTRL2 CLKOUT is LOW */ - err = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL2, cof); - if (err < 0) { - dev_err(&client->dev, "Failing to write the PCF85063_REG_CTRL2\n"); - return -EIO; - } - - /* hours, minutes and seconds */ - regs[0] = bin2bcd(tm->tm_sec) & 0x7F; /* clear OS flag */ - - regs[1] = bin2bcd(tm->tm_min); - regs[2] = bin2bcd(tm->tm_hour); - - /* Day of month, 1 - 31 */ - regs[3] = bin2bcd(tm->tm_mday); - - /* Day, 0 - 6 */ - regs[4] = tm->tm_wday & 0x07; - - /* month, 1 - 12 */ - regs[5] = bin2bcd(tm->tm_mon + 1); - - /* year and century */ - regs[6] = bin2bcd(tm->tm_year - 100); - - /* write all registers at once */ - rc = i2c_smbus_write_i2c_block_data(client, PCF85063_REG_SC, - sizeof(regs), regs); - if (rc < 0) { - dev_err(&client->dev, "date/time register write error\n"); - return rc; - } - - /* - * Write the control register as a separate action since the size of - * the register space is different between the PCF85063TP and - * PCF85063A devices. The rollover point can not be used. - */ - rc = pcf85063_start_clock(client, ctrl1); - if (rc != 0) - return rc; - - return 0; -} - -static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) -{ - return pcf85063_get_datetime(to_i2c_client(dev), tm); -} - -static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm) -{ - return pcf85063_set_datetime(to_i2c_client(dev), tm); -} - -static const struct rtc_class_ops pcf85063_rtc_ops = { - .read_time = pcf85063_rtc_read_time, - .set_time = pcf85063_rtc_set_time -}; - -static int pcf85063_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct rtc_device *rtc; - - dev_dbg(&client->dev, "%s\n", __func__); - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) - return -ENODEV; - - rtc = devm_rtc_device_register(&client->dev, - pcf85063_driver.driver.name, - &pcf85063_rtc_ops, THIS_MODULE); - - rtc->uie_unsupported = 1; - - return PTR_ERR_OR_ZERO(rtc); -} - -static const struct i2c_device_id pcf85063_id[] = { - { "rtcpcf85063", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, pcf85063_id); - -static const struct of_device_id pcf85063_of_match[] = { - { .compatible = "nxp,rtcpcf85063" }, - {} -}; -MODULE_DEVICE_TABLE(of, pcf85063_of_match); - -static struct i2c_driver pcf85063_driver = { - .driver = { - .name = "rtcpcf85063", - .of_match_table = of_match_ptr(pcf85063_of_match), - }, - .probe = pcf85063_probe, - .id_table = pcf85063_id, -}; - -module_i2c_driver(pcf85063_driver); - -MODULE_AUTHOR("Sren Andersen "); -MODULE_DESCRIPTION("PCF85063 RTC driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/spi-bitbang-txrx.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/spi-bitbang-txrx.h deleted file mode 100644 index 47bb9b898d..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/spi-bitbang-txrx.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Mix this utility code with some glue code to get one of several types of - * simple SPI master driver. Two do polled word-at-a-time I/O: - * - * - GPIO/parport bitbangers. Provide chipselect() and txrx_word[](), - * expanding the per-word routines from the inline templates below. - * - * - Drivers for controllers resembling bare shift registers. Provide - * chipselect() and txrx_word[](), with custom setup()/cleanup() methods - * that use your controller's clock and chipselect registers. - * - * Some hardware works well with requests at spi_transfer scope: - * - * - Drivers leveraging smarter hardware, with fifos or DMA; or for half - * duplex (MicroWire) controllers. Provide chipselect() and txrx_bufs(), - * and custom setup()/cleanup() methods. - */ - -/* - * The code that knows what GPIO pins do what should have declared four - * functions, ideally as inlines, before including this header: - * - * void setsck(struct spi_device *, int is_on); - * void setmosi(struct spi_device *, int is_on); - * int getmiso(struct spi_device *); - * void spidelay(unsigned); - * - * setsck()'s is_on parameter is a zero/nonzero boolean. - * - * setmosi()'s is_on parameter is a zero/nonzero boolean. - * - * getmiso() is required to return 0 or 1 only. Any other value is invalid - * and will result in improper operation. - * - * A non-inlined routine would call bitbang_txrx_*() routines. The - * main loop could easily compile down to a handful of instructions, - * especially if the delay is a NOP (to run at peak speed). - * - * Since this is software, the timings may not be exactly what your board's - * chips need ... there may be several reasons you'd need to tweak timings - * in these routines, not just to make it faster or slower to match a - * particular CPU clock rate. - */ - -static inline u32 -bitbang_txrx_be_cpha0(struct spi_device *spi, - unsigned nsecs, unsigned cpol, unsigned flags, - u32 word, u8 bits) -{ - /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */ - - u32 oldbit = (!(word & (1<<(bits-1)))) << 31; - /* clock starts at inactive polarity */ - for (word <<= (32 - bits); likely(bits); bits--) { - - /* setup MSB (to slave) on trailing edge */ - if ((flags & SPI_MASTER_NO_TX) == 0) { - if ((word & (1 << 31)) != oldbit) { - setmosi(spi, word & (1 << 31)); - oldbit = word & (1 << 31); - } - } - spidelay(nsecs); /* T(setup) */ - - setsck(spi, !cpol); - spidelay(nsecs); - - /* sample MSB (from slave) on leading edge */ - word <<= 1; - if ((flags & SPI_MASTER_NO_RX) == 0) - word |= getmiso(spi); - setsck(spi, cpol); - } - return word; -} - -static inline u32 -bitbang_txrx_be_cpha1(struct spi_device *spi, - unsigned nsecs, unsigned cpol, unsigned flags, - u32 word, u8 bits) -{ - /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */ - - u32 oldbit = (!(word & (1<<(bits-1)))) << 31; - /* clock starts at inactive polarity */ - for (word <<= (32 - bits); likely(bits); bits--) { - - /* setup MSB (to slave) on leading edge */ - setsck(spi, !cpol); - if ((flags & SPI_MASTER_NO_TX) == 0) { - if ((word & (1 << 31)) != oldbit) { - setmosi(spi, word & (1 << 31)); - oldbit = word & (1 << 31); - } - } - spidelay(nsecs); /* T(setup) */ - - setsck(spi, cpol); - spidelay(nsecs); - - /* sample MSB (from slave) on trailing edge */ - word <<= 1; - if ((flags & SPI_MASTER_NO_RX) == 0) - word |= getmiso(spi); - } - return word; -} diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/spi-gpio.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/spi-gpio.c deleted file mode 100644 index 07d543ceeb..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/spi-gpio.c +++ /dev/null @@ -1,546 +0,0 @@ -/* - * SPI master driver using generic bitbanged GPIO - * - * Copyright (C) 2006,2008 David Brownell - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -/* - * This bitbanging SPI master driver should help make systems usable - * when a native hardware SPI engine is not available, perhaps because - * its driver isn't yet working or because the I/O pins it requires - * are used for other purposes. - * - * platform_device->driver_data ... points to spi_gpio - * - * spi->controller_state ... reserved for bitbang framework code - * spi->controller_data ... holds chipselect GPIO - * - * spi->master->dev.driver_data ... points to spi_gpio->bitbang - */ - -struct spi_gpio { - struct spi_bitbang bitbang; - struct spi_gpio_platform_data pdata; - struct platform_device *pdev; - unsigned long cs_gpios[0]; -}; - -/*----------------------------------------------------------------------*/ - -/* - * Because the overhead of going through four GPIO procedure calls - * per transferred bit can make performance a problem, this code - * is set up so that you can use it in either of two ways: - * - * - The slow generic way: set up platform_data to hold the GPIO - * numbers used for MISO/MOSI/SCK, and issue procedure calls for - * each of them. This driver can handle several such busses. - * - * - The quicker inlined way: only helps with platform GPIO code - * that inlines operations for constant GPIOs. This can give - * you tight (fast!) inner loops, but each such bus needs a - * new driver. You'll define a new C file, with Makefile and - * Kconfig support; the C code can be a total of six lines: - * - * #define DRIVER_NAME "myboard_spi2" - * #define SPI_MISO_GPIO 119 - * #define SPI_MOSI_GPIO 120 - * #define SPI_SCK_GPIO 121 - * #define SPI_N_CHIPSEL 4 - * #include "spi-gpio.c" - */ - -#ifndef DRIVER_NAME -#define DRIVER_NAME "spi_gpio" - -#define GENERIC_BITBANG /* vs tight inlines */ - -/* all functions referencing these symbols must define pdata */ -#define SPI_MISO_GPIO ((pdata)->miso) -#define SPI_MOSI_GPIO ((pdata)->mosi) -#define SPI_SCK_GPIO ((pdata)->sck) - -#define SPI_N_CHIPSEL ((pdata)->num_chipselect) - -#endif - -/*----------------------------------------------------------------------*/ - -static inline struct spi_gpio *__pure -spi_to_spi_gpio(const struct spi_device *spi) -{ - const struct spi_bitbang *bang; - struct spi_gpio *spi_gpio; - - bang = spi_master_get_devdata(spi->master); - spi_gpio = container_of(bang, struct spi_gpio, bitbang); - return spi_gpio; -} - -static inline struct spi_gpio_platform_data *__pure -spi_to_pdata(const struct spi_device *spi) -{ - return &spi_to_spi_gpio(spi)->pdata; -} - -/* this is #defined to avoid unused-variable warnings when inlining */ -#define pdata spi_to_pdata(spi) - -static inline void setsck(const struct spi_device *spi, int is_on) -{ - gpio_set_value_cansleep(SPI_SCK_GPIO, is_on); -} - -static inline void setmosi(const struct spi_device *spi, int is_on) -{ - gpio_set_value_cansleep(SPI_MOSI_GPIO, is_on); -} - -static inline int getmiso(const struct spi_device *spi) -{ - return !!gpio_get_value_cansleep(SPI_MISO_GPIO); -} - -#undef pdata - -/* - * NOTE: this clocks "as fast as we can". It "should" be a function of the - * requested device clock. Software overhead means we usually have trouble - * reaching even one Mbit/sec (except when we can inline bitops), so for now - * we'll just assume we never need additional per-bit slowdowns. - */ -#define spidelay(nsecs) do {} while (0) - -#include "spi-bitbang-txrx.h" - -/* - * These functions can leverage inline expansion of GPIO calls to shrink - * costs for a txrx bit, often by factors of around ten (by instruction - * count). That is particularly visible for larger word sizes, but helps - * even with default 8-bit words. - * - * REVISIT overheads calling these functions for each word also have - * significant performance costs. Having txrx_bufs() calls that inline - * the txrx_word() logic would help performance, e.g. on larger blocks - * used with flash storage or MMC/SD. There should also be ways to make - * GCC be less stupid about reloading registers inside the I/O loops, - * even without inlined GPIO calls; __attribute__((hot)) on GCC 4.3? - */ - -static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi, - unsigned nsecs, u32 word, u8 bits) -{ - return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); -} - -static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi, - unsigned nsecs, u32 word, u8 bits) -{ - return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits); -} - -static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi, - unsigned nsecs, u32 word, u8 bits) -{ - return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits); -} - -static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, - unsigned nsecs, u32 word, u8 bits) -{ - return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits); -} - -/* - * These functions do not call setmosi or getmiso if respective flag - * (SPI_MASTER_NO_RX or SPI_MASTER_NO_TX) is set, so they are safe to - * call when such pin is not present or defined in the controller. - * A separate set of callbacks is defined to get highest possible - * speed in the generic case (when both MISO and MOSI lines are - * available), as optimiser will remove the checks when argument is - * constant. - */ - -static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi, - unsigned nsecs, u32 word, u8 bits) -{ - unsigned flags = spi->master->flags; - return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); -} - -static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi, - unsigned nsecs, u32 word, u8 bits) -{ - unsigned flags = spi->master->flags; - return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits); -} - -static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi, - unsigned nsecs, u32 word, u8 bits) -{ - unsigned flags = spi->master->flags; - return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits); -} - -static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, - unsigned nsecs, u32 word, u8 bits) -{ - unsigned flags = spi->master->flags; - return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits); -} - -/*----------------------------------------------------------------------*/ - -static void spi_gpio_chipselect(struct spi_device *spi, int is_active) -{ - struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); - unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; - - /* set initial clock polarity */ - if (is_active) - setsck(spi, spi->mode & SPI_CPOL); - - if (cs != SPI_GPIO_NO_CHIPSELECT) { - /* SPI is normally active-low */ - gpio_set_value_cansleep(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active); - } -} - -static int spi_gpio_setup(struct spi_device *spi) -{ - unsigned long cs; - int status = 0; - struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); - struct device_node *np = spi->master->dev.of_node; - - if (np) { - /* - * In DT environments, the CS GPIOs have already been - * initialized from the "cs-gpios" property of the node. - */ - cs = spi_gpio->cs_gpios[spi->chip_select]; - } else { - /* - * ... otherwise, take it from spi->controller_data - */ - cs = (uintptr_t) spi->controller_data; - } - - if (!spi->controller_state) { - if (cs != SPI_GPIO_NO_CHIPSELECT) { - status = gpio_request(cs, dev_name(&spi->dev)); - if (status) - return status; - status = gpio_direction_output(cs, - !(spi->mode & SPI_CS_HIGH)); - } - } - if (!status) { - /* in case it was initialized from static board data */ - spi_gpio->cs_gpios[spi->chip_select] = cs; - status = spi_bitbang_setup(spi); - } - - if (status) { - if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT) - gpio_free(cs); - } - return status; -} - -static void spi_gpio_cleanup(struct spi_device *spi) -{ - struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); - unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; - - if (cs != SPI_GPIO_NO_CHIPSELECT) - gpio_free(cs); - spi_bitbang_cleanup(spi); -} - -static int spi_gpio_alloc(unsigned pin, const char *label, bool is_in) -{ - int value; - - value = gpio_request(pin, label); - if (value == 0) { - if (is_in) - value = gpio_direction_input(pin); - else - value = gpio_direction_output(pin, 0); - } - return value; -} - -static int spi_gpio_request(struct spi_gpio_platform_data *pdata, - const char *label, u16 *res_flags) -{ - int value; - - /* NOTE: SPI_*_GPIO symbols may reference "pdata" */ - - if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) { - value = spi_gpio_alloc(SPI_MOSI_GPIO, label, false); - if (value) - goto done; - } else { - /* HW configuration without MOSI pin */ - *res_flags |= SPI_MASTER_NO_TX; - } - - if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) { - value = spi_gpio_alloc(SPI_MISO_GPIO, label, true); - if (value) - goto free_mosi; - } else { - /* HW configuration without MISO pin */ - *res_flags |= SPI_MASTER_NO_RX; - } - - value = spi_gpio_alloc(SPI_SCK_GPIO, label, false); - if (value) - goto free_miso; - - goto done; - -free_miso: - if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) - gpio_free(SPI_MISO_GPIO); -free_mosi: - if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) - gpio_free(SPI_MOSI_GPIO); -done: - return value; -} - -#ifdef CONFIG_OF -static const struct of_device_id spi_gpio_dt_ids[] = { - { .compatible = "spi-gpio" }, - {} -}; -MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids); - -static int spi_gpio_probe_dt(struct platform_device *pdev) -{ - int ret; - u32 tmp; - struct spi_gpio_platform_data *pdata; - struct device_node *np = pdev->dev.of_node; - const struct of_device_id *of_id = - of_match_device(spi_gpio_dt_ids, &pdev->dev); - - if (!of_id) - return 0; - - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) - return -ENOMEM; - - ret = of_get_named_gpio(np, "gpio-sck", 0); - if (ret < 0) { - dev_err(&pdev->dev, "gpio-sck property not found\n"); - goto error_free; - } - pdata->sck = ret; - - ret = of_get_named_gpio(np, "gpio-miso", 0); - if (ret < 0) { - dev_info(&pdev->dev, "gpio-miso property not found, switching to no-rx mode\n"); - pdata->miso = SPI_GPIO_NO_MISO; - } else - pdata->miso = ret; - - ret = of_get_named_gpio(np, "gpio-mosi", 0); - if (ret < 0) { - dev_info(&pdev->dev, "gpio-mosi property not found, switching to no-tx mode\n"); - pdata->mosi = SPI_GPIO_NO_MOSI; - } else - pdata->mosi = ret; - - ret = of_property_read_u32(np, "num-chipselects", &tmp); - if (ret < 0) { - dev_err(&pdev->dev, "num-chipselects property not found\n"); - goto error_free; - } - - pdata->num_chipselect = tmp; - pdev->dev.platform_data = pdata; - - return 1; - -error_free: - devm_kfree(&pdev->dev, pdata); - return ret; -} -#else -static inline int spi_gpio_probe_dt(struct platform_device *pdev) -{ - return 0; -} -#endif - -static int spi_gpio_probe(struct platform_device *pdev) -{ - int status; - struct spi_master *master; - struct spi_gpio *spi_gpio; - struct spi_gpio_platform_data *pdata; - u16 master_flags = 0; - bool use_of = 0; - int num_devices; - - status = spi_gpio_probe_dt(pdev); - if (status < 0) - return status; - if (status > 0) - use_of = 1; - - pdata = dev_get_platdata(&pdev->dev); -#ifdef GENERIC_BITBANG - if (!pdata || (!use_of && !pdata->num_chipselect)) - return -ENODEV; -#endif - - if (use_of && !SPI_N_CHIPSEL) - num_devices = 1; - else - num_devices = SPI_N_CHIPSEL; - - status = spi_gpio_request(pdata, dev_name(&pdev->dev), &master_flags); - if (status < 0) - return status; - - master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) + - (sizeof(unsigned long) * num_devices)); - if (!master) { - status = -ENOMEM; - goto gpio_free; - } - spi_gpio = spi_master_get_devdata(master); - platform_set_drvdata(pdev, spi_gpio); - - spi_gpio->pdev = pdev; - if (pdata) - spi_gpio->pdata = *pdata; - - master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); - master->flags = master_flags; - master->bus_num = pdev->id; - master->num_chipselect = num_devices; - master->setup = spi_gpio_setup; - master->cleanup = spi_gpio_cleanup; -#ifdef CONFIG_OF - master->dev.of_node = pdev->dev.of_node; - - if (use_of) { - int i; - struct device_node *np = pdev->dev.of_node; - - /* - * In DT environments, take the CS GPIO from the "cs-gpios" - * property of the node. - */ - - if (!SPI_N_CHIPSEL) - spi_gpio->cs_gpios[0] = SPI_GPIO_NO_CHIPSELECT; - else - for (i = 0; i < SPI_N_CHIPSEL; i++) { - status = of_get_named_gpio(np, "cs-gpios", i); - if (status < 0) { - dev_err(&pdev->dev, - "invalid cs-gpios property\n"); - goto gpio_free; - } - spi_gpio->cs_gpios[i] = status; - } - } -#endif - - spi_gpio->bitbang.master = master; - spi_gpio->bitbang.chipselect = spi_gpio_chipselect; - - if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) { - spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; - spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; - spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; - spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; - } else { - spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0; - spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1; - spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2; - spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3; - } - spi_gpio->bitbang.setup_transfer = spi_bitbang_setup_transfer; - spi_gpio->bitbang.flags = SPI_CS_HIGH; - - status = spi_bitbang_start(&spi_gpio->bitbang); - if (status < 0) { -gpio_free: - if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) - gpio_free(SPI_MISO_GPIO); - if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) - gpio_free(SPI_MOSI_GPIO); - gpio_free(SPI_SCK_GPIO); - spi_master_put(master); - } - - return status; -} - -static int spi_gpio_remove(struct platform_device *pdev) -{ - struct spi_gpio *spi_gpio; - struct spi_gpio_platform_data *pdata; - - spi_gpio = platform_get_drvdata(pdev); - pdata = dev_get_platdata(&pdev->dev); - - /* stop() unregisters child devices too */ - spi_bitbang_stop(&spi_gpio->bitbang); - - if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) - gpio_free(SPI_MISO_GPIO); - if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) - gpio_free(SPI_MOSI_GPIO); - gpio_free(SPI_SCK_GPIO); - spi_master_put(spi_gpio->bitbang.master); - - return 0; -} - -MODULE_ALIAS("platform:" DRIVER_NAME); - -static struct platform_driver spi_gpio_driver = { - .driver = { - .name = DRIVER_NAME, - .of_match_table = of_match_ptr(spi_gpio_dt_ids), - }, - .probe = spi_gpio_probe, - .remove = spi_gpio_remove, -}; -module_platform_driver(spi_gpio_driver); - -MODULE_DESCRIPTION("SPI master driver using generic bitbanged GPIO "); -MODULE_AUTHOR("David Brownell"); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm.h deleted file mode 100644 index a4fc2badf6..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm.h +++ /dev/null @@ -1,543 +0,0 @@ -/* - * Copyright (C) 2004 IBM Corporation - * Copyright (C) 2015 Intel Corporation - * - * Authors: - * Leendert van Doorn - * Dave Safford - * Reiner Sailer - * Kylene Hall - * - * Maintained by: - * - * Device driver for TCG/TCPA TPM (trusted platform module). - * Specifications at www.trustedcomputinggroup.org - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, version 2 of the - * License. - * - */ - -#ifndef __TPM_H__ -#define __TPM_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum tpm_const { - TPM_MINOR = 224, /* officially assigned */ - TPM_BUFSIZE = 4096, - TPM_NUM_DEVICES = 65536, - TPM_RETRY = 50, /* 5 seconds */ -}; - -enum tpm_timeout { - TPM_TIMEOUT = 5, /* msecs */ - TPM_TIMEOUT_RETRY = 100 /* msecs */ -}; - -/* TPM addresses */ -enum tpm_addr { - TPM_SUPERIO_ADDR = 0x2E, - TPM_ADDR = 0x4E, -}; - -/* Indexes the duration array */ -enum tpm_duration { - TPM_SHORT = 0, - TPM_MEDIUM = 1, - TPM_LONG = 2, - TPM_UNDEFINED, -}; - -#define TPM_WARN_RETRY 0x800 -#define TPM_WARN_DOING_SELFTEST 0x802 -#define TPM_ERR_DEACTIVATED 0x6 -#define TPM_ERR_DISABLED 0x7 -#define TPM_ERR_INVALID_POSTINIT 38 - -#define TPM_HEADER_SIZE 10 - -enum tpm2_const { - TPM2_PLATFORM_PCR = 24, - TPM2_PCR_SELECT_MIN = ((TPM2_PLATFORM_PCR + 7) / 8), - TPM2_TIMEOUT_A = 750, - TPM2_TIMEOUT_B = 2000, - TPM2_TIMEOUT_C = 200, - TPM2_TIMEOUT_D = 30, - TPM2_DURATION_SHORT = 20, - TPM2_DURATION_MEDIUM = 750, - TPM2_DURATION_LONG = 2000, -}; - -enum tpm2_structures { - TPM2_ST_NO_SESSIONS = 0x8001, - TPM2_ST_SESSIONS = 0x8002, -}; - -enum tpm2_return_codes { - TPM2_RC_HASH = 0x0083, /* RC_FMT1 */ - TPM2_RC_INITIALIZE = 0x0100, /* RC_VER1 */ - TPM2_RC_DISABLED = 0x0120, - TPM2_RC_TESTING = 0x090A, /* RC_WARN */ -}; - -enum tpm2_algorithms { - TPM2_ALG_SHA1 = 0x0004, - TPM2_ALG_KEYEDHASH = 0x0008, - TPM2_ALG_SHA256 = 0x000B, - TPM2_ALG_SHA384 = 0x000C, - TPM2_ALG_SHA512 = 0x000D, - TPM2_ALG_NULL = 0x0010, - TPM2_ALG_SM3_256 = 0x0012, -}; - -enum tpm2_command_codes { - TPM2_CC_FIRST = 0x011F, - TPM2_CC_SELF_TEST = 0x0143, - TPM2_CC_STARTUP = 0x0144, - TPM2_CC_SHUTDOWN = 0x0145, - TPM2_CC_CREATE = 0x0153, - TPM2_CC_LOAD = 0x0157, - TPM2_CC_UNSEAL = 0x015E, - TPM2_CC_FLUSH_CONTEXT = 0x0165, - TPM2_CC_GET_CAPABILITY = 0x017A, - TPM2_CC_GET_RANDOM = 0x017B, - TPM2_CC_PCR_READ = 0x017E, - TPM2_CC_PCR_EXTEND = 0x0182, - TPM2_CC_LAST = 0x018F, -}; - -enum tpm2_permanent_handles { - TPM2_RS_PW = 0x40000009, -}; - -enum tpm2_capabilities { - TPM2_CAP_TPM_PROPERTIES = 6, -}; - -enum tpm2_startup_types { - TPM2_SU_CLEAR = 0x0000, - TPM2_SU_STATE = 0x0001, -}; - -#define TPM_VID_INTEL 0x8086 -#define TPM_VID_WINBOND 0x1050 -#define TPM_VID_STM 0x104A - -#define TPM_PPI_VERSION_LEN 3 - -enum tpm_chip_flags { - TPM_CHIP_FLAG_REGISTERED = BIT(0), - TPM_CHIP_FLAG_TPM2 = BIT(1), - TPM_CHIP_FLAG_IRQ = BIT(2), - TPM_CHIP_FLAG_VIRTUAL = BIT(3), - TPM_CHIP_FLAG_ALWAYS_POWERED = BIT(5), -}; - -struct tpm_chip { - struct device dev; - struct cdev cdev; - - /* A driver callback under ops cannot be run unless ops_sem is held - * (sometimes implicitly, eg for the sysfs code). ops becomes null - * when the driver is unregistered, see tpm_try_get_ops. - */ - struct rw_semaphore ops_sem; - const struct tpm_class_ops *ops; - - unsigned int flags; - - int dev_num; /* /dev/tpm# */ - unsigned long is_open; /* only one allowed */ - - struct mutex tpm_mutex; /* tpm is processing */ - - unsigned long timeout_a; /* jiffies */ - unsigned long timeout_b; /* jiffies */ - unsigned long timeout_c; /* jiffies */ - unsigned long timeout_d; /* jiffies */ - bool timeout_adjusted; - unsigned long duration[3]; /* jiffies */ - bool duration_adjusted; - - struct dentry **bios_dir; - - const struct attribute_group *groups[3]; - unsigned int groups_cnt; -#ifdef CONFIG_ACPI - acpi_handle acpi_dev_handle; - char ppi_version[TPM_PPI_VERSION_LEN + 1]; -#endif /* CONFIG_ACPI */ -}; - -#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) - -static inline int tpm_read_index(int base, int index) -{ - outb(index, base); - return inb(base+1) & 0xFF; -} - -static inline void tpm_write_index(int base, int index, int value) -{ - outb(index, base); - outb(value & 0xFF, base+1); -} -struct tpm_input_header { - __be16 tag; - __be32 length; - __be32 ordinal; -} __packed; - -struct tpm_output_header { - __be16 tag; - __be32 length; - __be32 return_code; -} __packed; - -#define TPM_TAG_RQU_COMMAND cpu_to_be16(193) - -struct stclear_flags_t { - __be16 tag; - u8 deactivated; - u8 disableForceClear; - u8 physicalPresence; - u8 physicalPresenceLock; - u8 bGlobalLock; -} __packed; - -struct tpm_version_t { - u8 Major; - u8 Minor; - u8 revMajor; - u8 revMinor; -} __packed; - -struct tpm_version_1_2_t { - __be16 tag; - u8 Major; - u8 Minor; - u8 revMajor; - u8 revMinor; -} __packed; - -struct timeout_t { - __be32 a; - __be32 b; - __be32 c; - __be32 d; -} __packed; - -struct duration_t { - __be32 tpm_short; - __be32 tpm_medium; - __be32 tpm_long; -} __packed; - -struct permanent_flags_t { - __be16 tag; - u8 disable; - u8 ownership; - u8 deactivated; - u8 readPubek; - u8 disableOwnerClear; - u8 allowMaintenance; - u8 physicalPresenceLifetimeLock; - u8 physicalPresenceHWEnable; - u8 physicalPresenceCMDEnable; - u8 CEKPUsed; - u8 TPMpost; - u8 TPMpostLock; - u8 FIPS; - u8 operator; - u8 enableRevokeEK; - u8 nvLocked; - u8 readSRKPub; - u8 tpmEstablished; - u8 maintenanceDone; - u8 disableFullDALogicInfo; -} __packed; - -typedef union { - struct permanent_flags_t perm_flags; - struct stclear_flags_t stclear_flags; - bool owned; - __be32 num_pcrs; - struct tpm_version_t tpm_version; - struct tpm_version_1_2_t tpm_version_1_2; - __be32 manufacturer_id; - struct timeout_t timeout; - struct duration_t duration; -} cap_t; - -enum tpm_capabilities { - TPM_CAP_FLAG = cpu_to_be32(4), - TPM_CAP_PROP = cpu_to_be32(5), - CAP_VERSION_1_1 = cpu_to_be32(0x06), - CAP_VERSION_1_2 = cpu_to_be32(0x1A) -}; - -enum tpm_sub_capabilities { - TPM_CAP_PROP_PCR = cpu_to_be32(0x101), - TPM_CAP_PROP_MANUFACTURER = cpu_to_be32(0x103), - TPM_CAP_FLAG_PERM = cpu_to_be32(0x108), - TPM_CAP_FLAG_VOL = cpu_to_be32(0x109), - TPM_CAP_PROP_OWNER = cpu_to_be32(0x111), - TPM_CAP_PROP_TIS_TIMEOUT = cpu_to_be32(0x115), - TPM_CAP_PROP_TIS_DURATION = cpu_to_be32(0x120), - -}; - -struct tpm_getcap_params_in { - __be32 cap; - __be32 subcap_size; - __be32 subcap; -} __packed; - -struct tpm_getcap_params_out { - __be32 cap_size; - cap_t cap; -} __packed; - -struct tpm_readpubek_params_out { - u8 algorithm[4]; - u8 encscheme[2]; - u8 sigscheme[2]; - __be32 paramsize; - u8 parameters[12]; /*assuming RSA*/ - __be32 keysize; - u8 modulus[256]; - u8 checksum[20]; -} __packed; - -typedef union { - struct tpm_input_header in; - struct tpm_output_header out; -} tpm_cmd_header; - -struct tpm_pcrread_out { - u8 pcr_result[TPM_DIGEST_SIZE]; -} __packed; - -struct tpm_pcrread_in { - __be32 pcr_idx; -} __packed; - -struct tpm_pcrextend_in { - __be32 pcr_idx; - u8 hash[TPM_DIGEST_SIZE]; -} __packed; - -/* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 - * bytes, but 128 is still a relatively large number of random bytes and - * anything much bigger causes users of struct tpm_cmd_t to start getting - * compiler warnings about stack frame size. */ -#define TPM_MAX_RNG_DATA 128 - -struct tpm_getrandom_out { - __be32 rng_data_len; - u8 rng_data[TPM_MAX_RNG_DATA]; -} __packed; - -struct tpm_getrandom_in { - __be32 num_bytes; -} __packed; - -struct tpm_startup_in { - __be16 startup_type; -} __packed; - -typedef union { - struct tpm_getcap_params_out getcap_out; - struct tpm_readpubek_params_out readpubek_out; - u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)]; - struct tpm_getcap_params_in getcap_in; - struct tpm_pcrread_in pcrread_in; - struct tpm_pcrread_out pcrread_out; - struct tpm_pcrextend_in pcrextend_in; - struct tpm_getrandom_in getrandom_in; - struct tpm_getrandom_out getrandom_out; - struct tpm_startup_in startup_in; -} tpm_cmd_params; - -struct tpm_cmd_t { - tpm_cmd_header header; - tpm_cmd_params params; -} __packed; - -/* A string buffer type for constructing TPM commands. This is based on the - * ideas of string buffer code in security/keys/trusted.h but is heap based - * in order to keep the stack usage minimal. - */ - -enum tpm_buf_flags { - TPM_BUF_OVERFLOW = BIT(0), -}; - -struct tpm_buf { - struct page *data_page; - unsigned int flags; - u8 *data; -}; - -static inline int tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal) -{ - struct tpm_input_header *head; - - buf->data_page = alloc_page(GFP_HIGHUSER); - if (!buf->data_page) - return -ENOMEM; - - buf->flags = 0; - buf->data = kmap(buf->data_page); - - head = (struct tpm_input_header *) buf->data; - - head->tag = cpu_to_be16(tag); - head->length = cpu_to_be32(sizeof(*head)); - head->ordinal = cpu_to_be32(ordinal); - - return 0; -} - -static inline void tpm_buf_destroy(struct tpm_buf *buf) -{ - kunmap(buf->data_page); - __free_page(buf->data_page); -} - -static inline u32 tpm_buf_length(struct tpm_buf *buf) -{ - struct tpm_input_header *head = (struct tpm_input_header *) buf->data; - - return be32_to_cpu(head->length); -} - -static inline u16 tpm_buf_tag(struct tpm_buf *buf) -{ - struct tpm_input_header *head = (struct tpm_input_header *) buf->data; - - return be16_to_cpu(head->tag); -} - -static inline void tpm_buf_append(struct tpm_buf *buf, - const unsigned char *new_data, - unsigned int new_len) -{ - struct tpm_input_header *head = (struct tpm_input_header *) buf->data; - u32 len = tpm_buf_length(buf); - - /* Return silently if overflow has already happened. */ - if (buf->flags & TPM_BUF_OVERFLOW) - return; - - if ((len + new_len) > PAGE_SIZE) { - WARN(1, "tpm_buf: overflow\n"); - buf->flags |= TPM_BUF_OVERFLOW; - return; - } - - memcpy(&buf->data[len], new_data, new_len); - head->length = cpu_to_be32(len + new_len); -} - -static inline void tpm_buf_append_u8(struct tpm_buf *buf, const u8 value) -{ - tpm_buf_append(buf, &value, 1); -} - -static inline void tpm_buf_append_u16(struct tpm_buf *buf, const u16 value) -{ - __be16 value2 = cpu_to_be16(value); - - tpm_buf_append(buf, (u8 *) &value2, 2); -} - -static inline void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value) -{ - __be32 value2 = cpu_to_be32(value); - - tpm_buf_append(buf, (u8 *) &value2, 4); -} - -extern struct class *tpm_class; -extern dev_t tpm_devt; -extern const struct file_operations tpm_fops; -extern struct idr dev_nums_idr; - -enum tpm_transmit_flags { - TPM_TRANSMIT_UNLOCKED = BIT(0), -}; - -ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz, - unsigned int flags); -ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *cmd, int len, - unsigned int flags, const char *desc); -ssize_t tpm_getcap(struct tpm_chip *chip, __be32 subcap_id, cap_t *cap, - const char *desc); -int tpm_get_timeouts(struct tpm_chip *); -int tpm1_auto_startup(struct tpm_chip *chip); -int tpm_do_selftest(struct tpm_chip *chip); -unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); -int tpm_pm_suspend(struct device *dev); -int tpm_pm_resume(struct device *dev); -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, - wait_queue_head_t *queue, bool check_cancel); - -struct tpm_chip *tpm_chip_find_get(int chip_num); -__must_check int tpm_try_get_ops(struct tpm_chip *chip); -void tpm_put_ops(struct tpm_chip *chip); - -struct tpm_chip *tpm_chip_alloc(struct device *dev, - const struct tpm_class_ops *ops); -struct tpm_chip *tpmm_chip_alloc(struct device *pdev, - const struct tpm_class_ops *ops); -int tpm_chip_register(struct tpm_chip *chip); -void tpm_chip_unregister(struct tpm_chip *chip); - -void tpm_sysfs_add_device(struct tpm_chip *chip); - -int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); - -#ifdef CONFIG_ACPI -extern void tpm_add_ppi(struct tpm_chip *chip); -#else -static inline void tpm_add_ppi(struct tpm_chip *chip) -{ -} -#endif - -static inline inline u32 tpm2_rc_value(u32 rc) -{ - return (rc & BIT(7)) ? rc & 0xff : rc; -} - -int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); -int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash); -int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max); -int tpm2_seal_trusted(struct tpm_chip *chip, - struct trusted_key_payload *payload, - struct trusted_key_options *options); -int tpm2_unseal_trusted(struct tpm_chip *chip, - struct trusted_key_payload *payload, - struct trusted_key_options *options); -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, - u32 *value, const char *desc); - -int tpm2_auto_startup(struct tpm_chip *chip); -void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); -unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); -int tpm2_probe(struct tpm_chip *chip); -#endif diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm_tis_core.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm_tis_core.c deleted file mode 100644 index f9aa47ec7a..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm_tis_core.c +++ /dev/null @@ -1,855 +0,0 @@ -/* - * Copyright (C) 2005, 2006 IBM Corporation - * Copyright (C) 2014, 2015 Intel Corporation - * - * Authors: - * Leendert van Doorn - * Kylene Hall - * - * Maintained by: - * - * Device driver for TCG/TCPA TPM (trusted platform module). - * Specifications at www.trustedcomputinggroup.org - * - * This device driver implements the TPM interface as defined in - * the TCG TPM Interface Spec version 1.2, revision 1.0. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, version 2 of the - * License. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "tpm.h" -#include "tpm_tis_core.h" - -/* Before we attempt to access the TPM we must see that the valid bit is set. - * The specification says that this bit is 0 at reset and remains 0 until the - * 'TPM has gone through its self test and initialization and has established - * correct values in the other bits.' - */ -static int wait_startup(struct tpm_chip *chip, int l) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - unsigned long stop = jiffies + chip->timeout_a; - - do { - int rc; - u8 access; - - rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access); - if (rc < 0) - return rc; - - if (access & TPM_ACCESS_VALID) - return 0; - msleep(TPM_TIMEOUT); - } while (time_before(jiffies, stop)); - return -1; -} - -static int check_locality(struct tpm_chip *chip, int l) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int rc; - u8 access; - - rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access); - if (rc < 0) - return rc; - - if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == - (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) - return priv->locality = l; - - return -1; -} - -static void release_locality(struct tpm_chip *chip, int l, int force) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int rc; - u8 access; - - rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access); - if (rc < 0) - return; - - if (force || (access & - (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) == - (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) - tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); - -} - -static int request_locality(struct tpm_chip *chip, int l) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - unsigned long stop, timeout; - long rc; - - if (check_locality(chip, l) >= 0) - return l; - - rc = tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_REQUEST_USE); - if (rc < 0) - return rc; - - stop = jiffies + chip->timeout_a; - - if (chip->flags & TPM_CHIP_FLAG_IRQ) { -again: - timeout = stop - jiffies; - if ((long)timeout <= 0) - return -1; - rc = wait_event_interruptible_timeout(priv->int_queue, - (check_locality - (chip, l) >= 0), - timeout); - if (rc > 0) - return l; - if (rc == -ERESTARTSYS && freezing(current)) { - clear_thread_flag(TIF_SIGPENDING); - goto again; - } - } else { - /* wait for burstcount */ - do { - if (check_locality(chip, l) >= 0) - return l; - msleep(TPM_TIMEOUT); - } while (time_before(jiffies, stop)); - } - return -1; -} - -static u8 tpm_tis_status(struct tpm_chip *chip) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int rc; - u8 status; - - rc = tpm_tis_read8(priv, TPM_STS(priv->locality), &status); - if (rc < 0) - return 0; - - return status; -} - -static void tpm_tis_ready(struct tpm_chip *chip) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - - /* this causes the current command to be aborted */ - tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_COMMAND_READY); -} - -static int get_burstcount(struct tpm_chip *chip) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - unsigned long stop; - int burstcnt, rc; - u32 value; - - /* wait for burstcount */ - if (chip->flags & TPM_CHIP_FLAG_TPM2) - stop = jiffies + chip->timeout_a; - else - stop = jiffies + chip->timeout_d; - do { - rc = tpm_tis_read32(priv, TPM_STS(priv->locality), &value); - if (rc < 0) - return rc; - - burstcnt = (value >> 8) & 0xFFFF; - if (burstcnt) - return burstcnt; - msleep(TPM_TIMEOUT); - } while (time_before(jiffies, stop)); - return -EBUSY; -} - -static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int size = 0, burstcnt, rc; - - while (size < count && - wait_for_tpm_stat(chip, - TPM_STS_DATA_AVAIL | TPM_STS_VALID, - chip->timeout_c, - &priv->read_queue, true) == 0) { - burstcnt = get_burstcount(chip); - if (burstcnt < 0) { - dev_err(&chip->dev, "Unable to read burstcount\n"); - return burstcnt; - } - burstcnt = min_t(int, burstcnt, count - size); - - rc = tpm_tis_read_bytes(priv, TPM_DATA_FIFO(priv->locality), - burstcnt, buf + size); - if (rc < 0) - return rc; - - size += burstcnt; - } - return size; -} - -static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int size = 0; - int status; - u32 expected; - - if (count < TPM_HEADER_SIZE) { - size = -EIO; - goto out; - } - - size = recv_data(chip, buf, TPM_HEADER_SIZE); - /* read first 10 bytes, including tag, paramsize, and result */ - if (size < TPM_HEADER_SIZE) { - dev_err(&chip->dev, "Unable to read header\n"); - goto out; - } - - expected = be32_to_cpu(*(__be32 *) (buf + 2)); - if (expected > count || expected < TPM_HEADER_SIZE) { - size = -EIO; - goto out; - } - - size += recv_data(chip, &buf[TPM_HEADER_SIZE], - expected - TPM_HEADER_SIZE); - if (size < expected) { - dev_err(&chip->dev, "Unable to read remainder of result\n"); - size = -ETIME; - goto out; - } - - wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c, - &priv->int_queue, false); - status = tpm_tis_status(chip); - if (status & TPM_STS_DATA_AVAIL) { /* retry? */ - dev_err(&chip->dev, "Error left over data\n"); - size = -EIO; - goto out; - } - -out: - tpm_tis_ready(chip); - release_locality(chip, priv->locality, 0); - return size; -} - -/* - * If interrupts are used (signaled by an irq set in the vendor structure) - * tpm.c can skip polling for the data to be available as the interrupt is - * waited for here - */ -static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int rc, status, burstcnt; - size_t count = 0; - bool itpm = priv->flags & TPM_TIS_ITPM_POSSIBLE; - - if (request_locality(chip, 0) < 0) - return -EBUSY; - - status = tpm_tis_status(chip); - if ((status & TPM_STS_COMMAND_READY) == 0) { - tpm_tis_ready(chip); - if (wait_for_tpm_stat - (chip, TPM_STS_COMMAND_READY, chip->timeout_b, - &priv->int_queue, false) < 0) { - rc = -ETIME; - goto out_err; - } - } - - while (count < len - 1) { - burstcnt = get_burstcount(chip); - if (burstcnt < 0) { - dev_err(&chip->dev, "Unable to read burstcount\n"); - rc = burstcnt; - goto out_err; - } - burstcnt = min_t(int, burstcnt, len - count - 1); - rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), - burstcnt, buf + count); - if (rc < 0) - goto out_err; - - count += burstcnt; - - wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c, - &priv->int_queue, false); - status = tpm_tis_status(chip); - if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) { - rc = -EIO; - goto out_err; - } - } - - /* write last byte */ - rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]); - if (rc < 0) - goto out_err; - - wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c, - &priv->int_queue, false); - status = tpm_tis_status(chip); - if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) { - rc = -EIO; - goto out_err; - } - - return 0; - -out_err: - tpm_tis_ready(chip); - release_locality(chip, priv->locality, 0); - return rc; -} - -static void disable_interrupts(struct tpm_chip *chip) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - u32 intmask; - int rc; - - rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); - if (rc < 0) - intmask = 0; - - intmask &= ~TPM_GLOBAL_INT_ENABLE; - rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); - - devm_free_irq(chip->dev.parent, priv->irq, chip); - priv->irq = 0; - chip->flags &= ~TPM_CHIP_FLAG_IRQ; -} - -/* - * If interrupts are used (signaled by an irq set in the vendor structure) - * tpm.c can skip polling for the data to be available as the interrupt is - * waited for here - */ -static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int rc; - u32 ordinal; - unsigned long dur; - - rc = tpm_tis_send_data(chip, buf, len); - if (rc < 0) - return rc; - - /* go and do it */ - rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO); - if (rc < 0) - goto out_err; - - if (chip->flags & TPM_CHIP_FLAG_IRQ) { - ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); - - if (chip->flags & TPM_CHIP_FLAG_TPM2) - dur = tpm2_calc_ordinal_duration(chip, ordinal); - else - dur = tpm_calc_ordinal_duration(chip, ordinal); - - if (wait_for_tpm_stat - (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, dur, - &priv->read_queue, false) < 0) { - rc = -ETIME; - goto out_err; - } - } - return len; -out_err: - tpm_tis_ready(chip); - release_locality(chip, priv->locality, 0); - return rc; -} - -static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) -{ - int rc, irq; - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - - if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested) - return tpm_tis_send_main(chip, buf, len); - - /* Verify receipt of the expected IRQ */ - irq = priv->irq; - priv->irq = 0; - chip->flags &= ~TPM_CHIP_FLAG_IRQ; - rc = tpm_tis_send_main(chip, buf, len); - priv->irq = irq; - chip->flags |= TPM_CHIP_FLAG_IRQ; - if (!priv->irq_tested) - msleep(1); - if (!priv->irq_tested) - disable_interrupts(chip); - priv->irq_tested = true; - return rc; -} - -struct tis_vendor_timeout_override { - u32 did_vid; - unsigned long timeout_us[4]; -}; - -static const struct tis_vendor_timeout_override vendor_timeout_overrides[] = { - /* Atmel 3204 */ - { 0x32041114, { (TIS_SHORT_TIMEOUT*1000), (TIS_LONG_TIMEOUT*1000), - (TIS_SHORT_TIMEOUT*1000), (TIS_SHORT_TIMEOUT*1000) } }, -}; - -static bool tpm_tis_update_timeouts(struct tpm_chip *chip, - unsigned long *timeout_cap) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int i, rc; - u32 did_vid; - - rc = tpm_tis_read32(priv, TPM_DID_VID(0), &did_vid); - if (rc < 0) - return rc; - - for (i = 0; i != ARRAY_SIZE(vendor_timeout_overrides); i++) { - if (vendor_timeout_overrides[i].did_vid != did_vid) - continue; - memcpy(timeout_cap, vendor_timeout_overrides[i].timeout_us, - sizeof(vendor_timeout_overrides[i].timeout_us)); - return true; - } - - return false; -} - -/* - * Early probing for iTPM with STS_DATA_EXPECT flaw. - * Try sending command without itpm flag set and if that - * fails, repeat with itpm flag set. - */ -static int probe_itpm(struct tpm_chip *chip) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int rc = 0; - u8 cmd_getticks[] = { - 0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a, - 0x00, 0x00, 0x00, 0xf1 - }; - size_t len = sizeof(cmd_getticks); - u16 vendor; - - rc = tpm_tis_read16(priv, TPM_DID_VID(0), &vendor); - if (rc < 0) - return rc; - - /* probe only iTPMS */ - if (vendor != TPM_VID_INTEL) - return 0; - - rc = tpm_tis_send_data(chip, cmd_getticks, len); - if (rc == 0) - goto out; - - tpm_tis_ready(chip); - release_locality(chip, priv->locality, 0); - - rc = tpm_tis_send_data(chip, cmd_getticks, len); - if (rc == 0) { - dev_info(&chip->dev, "Detected an iTPM.\n"); - rc = 1; - } else - rc = -EFAULT; - -out: - tpm_tis_ready(chip); - release_locality(chip, priv->locality, 0); - - return rc; -} - -static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - - switch (priv->manufacturer_id) { - case TPM_VID_WINBOND: - return ((status == TPM_STS_VALID) || - (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY))); - case TPM_VID_STM: - return (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY)); - default: - return (status == TPM_STS_COMMAND_READY); - } -} - -static irqreturn_t tis_int_handler(int dummy, void *dev_id) -{ - struct tpm_chip *chip = dev_id; - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - u32 interrupt; - int i, rc; - - rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt); - if (rc < 0) - return IRQ_NONE; - - if (interrupt == 0) - return IRQ_NONE; - - priv->irq_tested = true; - if (interrupt & TPM_INTF_DATA_AVAIL_INT) - wake_up_interruptible(&priv->read_queue); - if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) - for (i = 0; i < 5; i++) - if (check_locality(chip, i) >= 0) - break; - if (interrupt & - (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT | - TPM_INTF_CMD_READY_INT)) - wake_up_interruptible(&priv->int_queue); - - /* Clear interrupts handled with TPM_EOI */ - rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), interrupt); - if (rc < 0) - return IRQ_NONE; - - tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt); - return IRQ_HANDLED; -} - -static int tpm_tis_gen_interrupt(struct tpm_chip *chip) -{ - const char *desc = "attempting to generate an interrupt"; - u32 cap2; - cap_t cap; - - if (chip->flags & TPM_CHIP_FLAG_TPM2) - return tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); - else - return tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc); -} - -/* Register the IRQ and issue a command that will cause an interrupt. If an - * irq is seen then leave the chip setup for IRQ operation, otherwise reverse - * everything and leave in polling mode. Returns 0 on success. - */ -static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, - int flags, int irq) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - u8 original_int_vec; - int rc; - u32 int_status; - - if (devm_request_irq(chip->dev.parent, irq, tis_int_handler, flags, - dev_name(&chip->dev), chip) != 0) { - dev_info(&chip->dev, "Unable to request irq: %d for probe\n", - irq); - return -1; - } - priv->irq = irq; - - rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), - &original_int_vec); - if (rc < 0) - return rc; - - rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); - if (rc < 0) - return rc; - - rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); - if (rc < 0) - return rc; - - /* Clear all existing */ - rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); - if (rc < 0) - return rc; - - /* Turn on */ - rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), - intmask | TPM_GLOBAL_INT_ENABLE); - if (rc < 0) - return rc; - - priv->irq_tested = false; - - /* Generate an interrupt by having the core call through to - * tpm_tis_send - */ - rc = tpm_tis_gen_interrupt(chip); - if (rc < 0) - return rc; - - /* tpm_tis_send will either confirm the interrupt is working or it - * will call disable_irq which undoes all of the above. - */ - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - rc = tpm_tis_write8(priv, original_int_vec, - TPM_INT_VECTOR(priv->locality)); - if (rc < 0) - return rc; - - return 1; - } - - return 0; -} - -/* Try to find the IRQ the TPM is using. This is for legacy x86 systems that - * do not have ACPI/etc. We typically expect the interrupt to be declared if - * present. - */ -static void tpm_tis_probe_irq(struct tpm_chip *chip, u32 intmask) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - u8 original_int_vec; - int i, rc; - - rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), - &original_int_vec); - if (rc < 0) - return; - - if (!original_int_vec) { - if (IS_ENABLED(CONFIG_X86)) - for (i = 3; i <= 15; i++) - if (!tpm_tis_probe_irq_single(chip, intmask, 0, - i)) - return; - } else if (!tpm_tis_probe_irq_single(chip, intmask, 0, - original_int_vec)) - return; -} - -void tpm_tis_remove(struct tpm_chip *chip) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - u32 reg = TPM_INT_ENABLE(priv->locality); - u32 interrupt; - int rc; - - rc = tpm_tis_read32(priv, reg, &interrupt); - if (rc < 0) - interrupt = 0; - - tpm_tis_write32(priv, reg, ~TPM_GLOBAL_INT_ENABLE & interrupt); - release_locality(chip, priv->locality, 1); -} -EXPORT_SYMBOL_GPL(tpm_tis_remove); - -static const struct tpm_class_ops tpm_tis = { - .flags = TPM_OPS_AUTO_STARTUP, - .status = tpm_tis_status, - .recv = tpm_tis_recv, - .send = tpm_tis_send, - .cancel = tpm_tis_ready, - .update_timeouts = tpm_tis_update_timeouts, - .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, - .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, - .req_canceled = tpm_tis_req_canceled, -}; - -int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, - const struct tpm_tis_phy_ops *phy_ops, - acpi_handle acpi_dev_handle) -{ - u32 vendor, intfcaps, intmask; - u8 rid; - int rc, probe; - struct tpm_chip *chip; - - chip = tpmm_chip_alloc(dev, &tpm_tis); - if (IS_ERR(chip)) - return PTR_ERR(chip); - -#ifdef CONFIG_ACPI - chip->acpi_dev_handle = acpi_dev_handle; -#endif - - /* Maximum timeouts */ - chip->timeout_a = msecs_to_jiffies(TIS_TIMEOUT_A_MAX); - chip->timeout_b = msecs_to_jiffies(TIS_TIMEOUT_B_MAX); - chip->timeout_c = msecs_to_jiffies(TIS_TIMEOUT_C_MAX); - chip->timeout_d = msecs_to_jiffies(TIS_TIMEOUT_D_MAX); - priv->phy_ops = phy_ops; - dev_set_drvdata(&chip->dev, priv); - - if (wait_startup(chip, 0) != 0) { - rc = -ENODEV; - goto out_err; - } - - /* Take control of the TPM's interrupt hardware and shut it off */ - rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); - if (rc < 0) - goto out_err; - - intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT | - TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT; - intmask &= ~TPM_GLOBAL_INT_ENABLE; - tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); - - if (request_locality(chip, 0) != 0) { - rc = -ENODEV; - goto out_err; - } - - rc = tpm2_probe(chip); - if (rc) - goto out_err; - - rc = tpm_tis_read32(priv, TPM_DID_VID(0), &vendor); - if (rc < 0) - goto out_err; - - priv->manufacturer_id = vendor; - - rc = tpm_tis_read8(priv, TPM_RID(0), &rid); - if (rc < 0) - goto out_err; - - dev_info(dev, "%s TPM (device-id 0x%X, rev-id %d)\n", - (chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2", - vendor >> 16, rid); - - if (!(priv->flags & TPM_TIS_ITPM_POSSIBLE)) { - probe = probe_itpm(chip); - if (probe < 0) { - rc = -ENODEV; - goto out_err; - } - - if (!!probe) - priv->flags |= TPM_TIS_ITPM_POSSIBLE; - } - - /* Figure out the capabilities */ - rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); - if (rc < 0) - goto out_err; - - dev_dbg(dev, "TPM interface capabilities (0x%x):\n", - intfcaps); - if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) - dev_dbg(dev, "\tBurst Count Static\n"); - if (intfcaps & TPM_INTF_CMD_READY_INT) - dev_dbg(dev, "\tCommand Ready Int Support\n"); - if (intfcaps & TPM_INTF_INT_EDGE_FALLING) - dev_dbg(dev, "\tInterrupt Edge Falling\n"); - if (intfcaps & TPM_INTF_INT_EDGE_RISING) - dev_dbg(dev, "\tInterrupt Edge Rising\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_LOW) - dev_dbg(dev, "\tInterrupt Level Low\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) - dev_dbg(dev, "\tInterrupt Level High\n"); - if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) - dev_dbg(dev, "\tLocality Change Int Support\n"); - if (intfcaps & TPM_INTF_STS_VALID_INT) - dev_dbg(dev, "\tSts Valid Int Support\n"); - if (intfcaps & TPM_INTF_DATA_AVAIL_INT) - dev_dbg(dev, "\tData Avail Int Support\n"); - - /* Very early on issue a command to the TPM in polling mode to make - * sure it works. May as well use that command to set the proper - * timeouts for the driver. - */ - if (tpm_get_timeouts(chip)) { - dev_err(dev, "Could not get TPM timeouts and durations\n"); - rc = -ENODEV; - goto out_err; - } - - /* INTERRUPT Setup */ - init_waitqueue_head(&priv->read_queue); - init_waitqueue_head(&priv->int_queue); - if (irq != -1) { - if (irq) { - tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED, - irq); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) - dev_err(&chip->dev, FW_BUG - "TPM interrupt not working, polling instead\n"); - } else { - tpm_tis_probe_irq(chip, intmask); - } - } - - return tpm_chip_register(chip); -out_err: - tpm_tis_remove(chip); - return rc; -} -EXPORT_SYMBOL_GPL(tpm_tis_core_init); - -#ifdef CONFIG_PM_SLEEP -static void tpm_tis_reenable_interrupts(struct tpm_chip *chip) -{ - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - u32 intmask; - int rc; - - /* reenable interrupts that device may have lost or - * BIOS/firmware may have disabled - */ - rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), priv->irq); - if (rc < 0) - return; - - rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); - if (rc < 0) - return; - - intmask |= TPM_INTF_CMD_READY_INT - | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT - | TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE; - - tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); -} - -int tpm_tis_resume(struct device *dev) -{ - struct tpm_chip *chip = dev_get_drvdata(dev); - int ret; - - if (chip->flags & TPM_CHIP_FLAG_IRQ) - tpm_tis_reenable_interrupts(chip); - - ret = tpm_pm_resume(dev); - if (ret) - return ret; - - /* TPM 1.2 requires self-test on resume. This function actually returns - * an error code but for unknown reason it isn't handled. - */ - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) - tpm_do_selftest(chip); - - return 0; -} -EXPORT_SYMBOL_GPL(tpm_tis_resume); -#endif - -MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)"); -MODULE_DESCRIPTION("TPM Driver"); -MODULE_VERSION("2.0"); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm_tis_core.h b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm_tis_core.h deleted file mode 100644 index e1c2193f2e..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm_tis_core.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (C) 2005, 2006 IBM Corporation - * Copyright (C) 2014, 2015 Intel Corporation - * - * Authors: - * Leendert van Doorn - * Kylene Hall - * - * Maintained by: - * - * Device driver for TCG/TCPA TPM (trusted platform module). - * Specifications at www.trustedcomputinggroup.org - * - * This device driver implements the TPM interface as defined in - * the TCG TPM Interface Spec version 1.2, revision 1.0. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, version 2 of the - * License. - */ - -#ifndef __TPM_TIS_CORE_H__ -#define __TPM_TIS_CORE_H__ - -#include "tpm.h" - -enum tis_access { - TPM_ACCESS_VALID = 0x80, - TPM_ACCESS_ACTIVE_LOCALITY = 0x20, - TPM_ACCESS_REQUEST_PENDING = 0x04, - TPM_ACCESS_REQUEST_USE = 0x02, -}; - -enum tis_status { - TPM_STS_VALID = 0x80, - TPM_STS_COMMAND_READY = 0x40, - TPM_STS_GO = 0x20, - TPM_STS_DATA_AVAIL = 0x10, - TPM_STS_DATA_EXPECT = 0x08, -}; - -enum tis_int_flags { - TPM_GLOBAL_INT_ENABLE = 0x80000000, - TPM_INTF_BURST_COUNT_STATIC = 0x100, - TPM_INTF_CMD_READY_INT = 0x080, - TPM_INTF_INT_EDGE_FALLING = 0x040, - TPM_INTF_INT_EDGE_RISING = 0x020, - TPM_INTF_INT_LEVEL_LOW = 0x010, - TPM_INTF_INT_LEVEL_HIGH = 0x008, - TPM_INTF_LOCALITY_CHANGE_INT = 0x004, - TPM_INTF_STS_VALID_INT = 0x002, - TPM_INTF_DATA_AVAIL_INT = 0x001, -}; - -enum tis_defaults { - TIS_MEM_LEN = 0x5000, - TIS_SHORT_TIMEOUT = 750, /* ms */ - TIS_LONG_TIMEOUT = 2000, /* 2 sec */ -}; - -/* Some timeout values are needed before it is known whether the chip is - * TPM 1.0 or TPM 2.0. - */ -#define TIS_TIMEOUT_A_MAX max(TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_A) -#define TIS_TIMEOUT_B_MAX max(TIS_LONG_TIMEOUT, TPM2_TIMEOUT_B) -#define TIS_TIMEOUT_C_MAX max(TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_C) -#define TIS_TIMEOUT_D_MAX max(TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_D) - -#define TPM_ACCESS(l) (0x0000 | ((l) << 12)) -#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12)) -#define TPM_INT_VECTOR(l) (0x000C | ((l) << 12)) -#define TPM_INT_STATUS(l) (0x0010 | ((l) << 12)) -#define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12)) -#define TPM_STS(l) (0x0018 | ((l) << 12)) -#define TPM_STS3(l) (0x001b | ((l) << 12)) -#define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12)) - -#define TPM_DID_VID(l) (0x0F00 | ((l) << 12)) -#define TPM_RID(l) (0x0F04 | ((l) << 12)) - -enum tpm_tis_flags { - TPM_TIS_ITPM_POSSIBLE = BIT(0), -}; - -struct tpm_tis_data { - u16 manufacturer_id; - int locality; - int irq; - bool irq_tested; - unsigned int flags; - wait_queue_head_t int_queue; - wait_queue_head_t read_queue; - const struct tpm_tis_phy_ops *phy_ops; -}; - -struct tpm_tis_phy_ops { - int (*read_bytes)(struct tpm_tis_data *data, u32 addr, u16 len, - u8 *result); - int (*write_bytes)(struct tpm_tis_data *data, u32 addr, u16 len, - const u8 *value); - int (*read16)(struct tpm_tis_data *data, u32 addr, u16 *result); - int (*read32)(struct tpm_tis_data *data, u32 addr, u32 *result); - int (*write32)(struct tpm_tis_data *data, u32 addr, u32 src); -}; - -static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr, - u16 len, u8 *result) -{ - return data->phy_ops->read_bytes(data, addr, len, result); -} - -static inline int tpm_tis_read8(struct tpm_tis_data *data, u32 addr, u8 *result) -{ - return data->phy_ops->read_bytes(data, addr, 1, result); -} - -static inline int tpm_tis_read16(struct tpm_tis_data *data, u32 addr, - u16 *result) -{ - return data->phy_ops->read16(data, addr, result); -} - -static inline int tpm_tis_read32(struct tpm_tis_data *data, u32 addr, - u32 *result) -{ - return data->phy_ops->read32(data, addr, result); -} - -static inline int tpm_tis_write_bytes(struct tpm_tis_data *data, u32 addr, - u16 len, const u8 *value) -{ - return data->phy_ops->write_bytes(data, addr, len, value); -} - -static inline int tpm_tis_write8(struct tpm_tis_data *data, u32 addr, u8 value) -{ - return data->phy_ops->write_bytes(data, addr, 1, &value); -} - -static inline int tpm_tis_write32(struct tpm_tis_data *data, u32 addr, - u32 value) -{ - return data->phy_ops->write32(data, addr, value); -} - -void tpm_tis_remove(struct tpm_chip *chip); -int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, - const struct tpm_tis_phy_ops *phy_ops, - acpi_handle acpi_dev_handle); - -#ifdef CONFIG_PM_SLEEP -int tpm_tis_resume(struct device *dev); -#endif - -#endif diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm_tis_spi.c b/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm_tis_spi.c deleted file mode 100644 index b990acdecb..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/modules/tpm_tis_spi.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2015 Infineon Technologies AG - * Copyright (C) 2016 STMicroelectronics SAS - * - * Authors: - * Peter Huewe - * Christophe Ricard - * - * Maintained by: - * - * Device driver for TCG/TCPA TPM (trusted platform module). - * Specifications at www.trustedcomputinggroup.org - * - * This device driver implements the TPM interface as defined in - * the TCG TPM Interface Spec version 1.3, revision 27 via _raw/native - * SPI access_. - * - * It is based on the original tpm_tis device driver from Leendert van - * Dorn and Kyleen Hall and Jarko Sakkinnen. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, version 2 of the - * License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include "tpm.h" -#include "tpm_tis_core.h" - -#define MAX_SPI_FRAMESIZE 64 -#define mem_clear(data, size) memset((data), 0, (size)) - -struct tpm_tis_spi_phy { - struct tpm_tis_data priv; - struct spi_device *spi_device; - u8 *iobuf; -}; - -static inline struct tpm_tis_spi_phy *to_tpm_tis_spi_phy(struct tpm_tis_data *data) -{ - return container_of(data, struct tpm_tis_spi_phy, priv); -} - -static int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, - u8 *in, const u8 *out) -{ - struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); - int ret = 0; - int i; - struct spi_message m; - struct spi_transfer spi_xfer; - u8 transfer_len; - - spi_bus_lock(phy->spi_device->master); - - while (len) { - transfer_len = min_t(u16, len, MAX_SPI_FRAMESIZE); - - phy->iobuf[0] = (in ? 0x80 : 0) | (transfer_len - 1); - phy->iobuf[1] = 0xd4; - phy->iobuf[2] = addr >> 8; - phy->iobuf[3] = addr; - - mem_clear(&spi_xfer, sizeof(spi_xfer)); - spi_xfer.tx_buf = phy->iobuf; - spi_xfer.rx_buf = phy->iobuf; - spi_xfer.len = 4; - spi_xfer.cs_change = 1; - - spi_message_init(&m); - spi_message_add_tail(&spi_xfer, &m); - ret = spi_sync_locked(phy->spi_device, &m); - if (ret < 0) - goto exit; - - if ((phy->iobuf[3] & 0x01) == 0) { - // handle SPI wait states - phy->iobuf[0] = 0; - - for (i = 0; i < TPM_RETRY; i++) { - spi_xfer.len = 1; - spi_message_init(&m); - spi_message_add_tail(&spi_xfer, &m); - ret = spi_sync_locked(phy->spi_device, &m); - if (ret < 0) - goto exit; - if (phy->iobuf[0] & 0x01) - break; - } - - if (i == TPM_RETRY) { - ret = -ETIMEDOUT; - goto exit; - } - } - - spi_xfer.cs_change = 0; - spi_xfer.len = transfer_len; - spi_xfer.delay_usecs = 5; - - if (in) { - spi_xfer.tx_buf = NULL; - } else if (out) { - spi_xfer.rx_buf = NULL; - memcpy(phy->iobuf, out, transfer_len); - out += transfer_len; - } - - spi_message_init(&m); - spi_message_add_tail(&spi_xfer, &m); - ret = spi_sync_locked(phy->spi_device, &m); - if (ret < 0) - goto exit; - - if (in) { - memcpy(in, phy->iobuf, transfer_len); - in += transfer_len; - } - - len -= transfer_len; - } - -exit: - spi_bus_unlock(phy->spi_device->master); - return ret; -} - -static int tpm_tis_spi_read_bytes(struct tpm_tis_data *data, u32 addr, - u16 len, u8 *result) -{ - return tpm_tis_spi_transfer(data, addr, len, result, NULL); -} - -static int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr, - u16 len, const u8 *value) -{ - return tpm_tis_spi_transfer(data, addr, len, NULL, value); -} - -static int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result) -{ - int rc; - - rc = data->phy_ops->read_bytes(data, addr, sizeof(u16), (u8 *)result); - if (!rc) - *result = le16_to_cpu(*result); - return rc; -} - -static int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result) -{ - int rc; - - rc = data->phy_ops->read_bytes(data, addr, sizeof(u32), (u8 *)result); - if (!rc) - *result = le32_to_cpu(*result); - return rc; -} - -static int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value) -{ - value = cpu_to_le32(value); - return data->phy_ops->write_bytes(data, addr, sizeof(u32), - (u8 *)&value); -} - -static const struct tpm_tis_phy_ops tpm_spi_phy_ops = { - .read_bytes = tpm_tis_spi_read_bytes, - .write_bytes = tpm_tis_spi_write_bytes, - .read16 = tpm_tis_spi_read16, - .read32 = tpm_tis_spi_read32, - .write32 = tpm_tis_spi_write32, -}; - -static int tpm_tis_spi_probe(struct spi_device *dev) -{ - struct tpm_tis_spi_phy *phy; - int irq; - - phy = devm_kzalloc(&dev->dev, sizeof(struct tpm_tis_spi_phy), - GFP_KERNEL); - if (!phy) - return -ENOMEM; - - phy->spi_device = dev; - - phy->iobuf = devm_kmalloc(&dev->dev, MAX_SPI_FRAMESIZE, GFP_KERNEL); - if (!phy->iobuf) - return -ENOMEM; - - /* If the SPI device has an IRQ then use that */ - if (dev->irq > 0) - irq = dev->irq; - else - irq = -1; - - return tpm_tis_core_init(&dev->dev, &phy->priv, irq, &tpm_spi_phy_ops, - NULL); -} - -static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume); - -static int tpm_tis_spi_remove(struct spi_device *dev) -{ - struct tpm_chip *chip = spi_get_drvdata(dev); - - tpm_chip_unregister(chip); - tpm_tis_remove(chip); - return 0; -} - -static const struct spi_device_id tpm_tis_spi_id[] = { - {"tpm_tis_spi", 0}, - {} -}; -MODULE_DEVICE_TABLE(spi, tpm_tis_spi_id); - -static const struct of_device_id of_tis_spi_match[] = { - { .compatible = "st,st33htpm-spi", }, - { .compatible = "infineon,slb9670", }, - { .compatible = "tcg,tpm_tis-spi", }, - {} -}; -MODULE_DEVICE_TABLE(of, of_tis_spi_match); - -static const struct acpi_device_id acpi_tis_spi_match[] = { - {"SMO0768", 0}, - {} -}; -MODULE_DEVICE_TABLE(acpi, acpi_tis_spi_match); - -static struct spi_driver tpm_tis_spi_driver = { - .driver = { - .owner = THIS_MODULE, - .name = "tpm_tis_spi", - .pm = &tpm_tis_pm, - .of_match_table = of_match_ptr(of_tis_spi_match), - .acpi_match_table = ACPI_PTR(acpi_tis_spi_match), - }, - .probe = tpm_tis_spi_probe, - .remove = tpm_tis_spi_remove, - .id_table = tpm_tis_spi_id, -}; -module_spi_driver(tpm_tis_spi_driver); - -MODULE_DESCRIPTION("TPM Driver for native SPI access"); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/device_i2c.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/script/device_i2c.py deleted file mode 100644 index 6a1ede0f2c..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/device_i2c.py +++ /dev/null @@ -1,285 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: UTF-8 -*- -import click -import os -import time -from ragileconfig import GLOBALCONFIG, GLOBALINITPARAM, GLOBALINITCOMMAND, MAC_LED_RESET, STARTMODULE, i2ccheck_params -from ragileutil import rgpciwr, os_system - -CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) - -class AliasedGroup(click.Group): - def get_command(self, ctx, cmd_name): - rv = click.Group.get_command(self, ctx, cmd_name) - if rv is not None: - return rv - else: - return None - matches = [x for x in self.list_commands(ctx) - if x.startswith(cmd_name)] - if not matches: - return None - elif len(matches) == 1: - return click.Group.get_command(self, ctx, matches[0]) - ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) - -def log_os_system(cmd): - u'''execute shell command''' - status, output = os_system(cmd) - if status: - print(output) - return status, output - -def write_sysfs_value(reg_name, value): - u'''write sysfs file''' - mb_reg_file = "/sys/bus/i2c/devices/" + reg_name - if (not os.path.isfile(mb_reg_file)): - print(mb_reg_file, 'not found !') - return False - try: - with open(mb_reg_file, 'w') as fd: - fd.write(value) - except Exception as error: - return False - return True - -def check_driver(): - u'''whether there is driver start with rg''' - status, output = log_os_system("lsmod | grep rg | wc -l") - #System execution error - if status: - return False - if output.isdigit() and int(output) > 0: - return True - else: - return False - -def get_pid(name): - ret = [] - for dirname in os.listdir('/proc'): - if dirname == 'curproc': - continue - try: - with open('/proc/{}/cmdline'.format(dirname), mode='r') as fd: - content = fd.read() - except Exception: - continue - if name in content: - ret.append(dirname) - return ret - -def start_avs_ctrl(): - if STARTMODULE.get("avscontrol", 0) == 1: - cmd = "nohup avscontrol.py start >/dev/null 2>&1 &" - rets = get_pid("avscontrol.py") - if len(rets) == 0: - os.system(cmd) - -def stop_avs_ctrl(): - if STARTMODULE.get('avscontrol', 0) == 1: - rets = get_pid("avscontrol.py") # - for ret in rets: - cmd = "kill "+ ret - os.system(cmd) - -def start_fan_ctrl(): - if STARTMODULE.get('fancontrol', 0) == 1: - cmd = "nohup fancontrol.py start >/dev/null 2>&1 &" - rets = get_pid("fancontrol.py") - if len(rets) == 0: - os.system(cmd) - -def stop_fan_ctrl(): - u'''disable fan timer service''' - if STARTMODULE.get('fancontrol', 0) == 1: - rets = get_pid("fancontrol.py") # - for ret in rets: - cmd = "kill "+ ret - os.system(cmd) - -def rm_dev(bus, loc): - cmd = "echo 0x%02x > /sys/bus/i2c/devices/i2c-%d/delete_device" % (loc, bus) - devpath = "/sys/bus/i2c/devices/%d-%04x"%(bus, loc) - if os.path.exists(devpath): - log_os_system(cmd) - -def add_dev(name, bus, loc): - if name == "lm75": - time.sleep(0.1) - pdevpath = "/sys/bus/i2c/devices/i2c-%d/" % (bus) - for i in range(1, 100):#wait for mother-bus generation, maximum wait time is 10s - if os.path.exists(pdevpath) == True: - break - time.sleep(0.1) - if i % 10 == 0: - click.echo("%%DEVICE_I2C-INIT: %s not found, wait 0.1 second ! i %d " % (pdevpath,i)) - - cmd = "echo %s 0x%02x > /sys/bus/i2c/devices/i2c-%d/new_device" % (name, loc, bus) - devpath = "/sys/bus/i2c/devices/%d-%04x"%(bus, loc) - if os.path.exists(devpath) == False: - os.system(cmd) - -def removedevs(): - devs = GLOBALCONFIG["DEVS"] - for index in range(len(devs)-1, -1, -1 ): - rm_dev(devs[index]["bus"] , devs[index]["loc"]) - -def adddevs(): - devs = GLOBALCONFIG["DEVS"] - for dev in range(0, devs.__len__()): - add_dev(devs[dev]["name"], devs[dev]["bus"] , devs[dev]["loc"]) - -def checksignaldriver(name): - modisexistcmd = "lsmod | grep %s | wc -l" % name - status, output = log_os_system(modisexistcmd) - #System execution error - if status: - return False - if output.isdigit() and int(output) > 0: - return True - else: - return False - -def adddriver(name, delay): - cmd = "modprobe %s" % name - if delay != 0: - time.sleep(delay) - if checksignaldriver(name) != True: - log_os_system(cmd) - -def removedriver(name, delay): - realname = name.lstrip().split(" ")[0]; - cmd = "rmmod -f %s" % realname - if checksignaldriver(realname): - log_os_system(cmd) - -def removedrivers(): - u'''remove all drivers''' - if GLOBALCONFIG is None: - click.echo("%%DEVICE_I2C-INIT: load global config failed.") - return - drivers = GLOBALCONFIG.get("DRIVERLISTS", None) - if drivers is None: - click.echo("%%DEVICE_I2C-INIT: load driver list failed.") - return - for index in range(len(drivers)-1, -1, -1 ): - delay = 0 - name = "" - if type(drivers[index]) == dict and "delay" in drivers[index]: - name = drivers[index].get("name") - delay = drivers[index]["delay"] - else: - name = drivers[index] - removedriver(name, delay) - -def adddrivers(): - u'''add drivers''' - if GLOBALCONFIG is None: - click.echo("%%DEVICE_I2C-INIT: load global config failed.") - return - drivers = GLOBALCONFIG.get("DRIVERLISTS", None) - if drivers is None: - click.echo("%%DEVICE_I2C-INIT: load driver list failed.") - return - for index in range(0 ,len(drivers)): - delay = 0 - name = "" - if type(drivers[index]) == dict and "delay" in drivers[index]: - name = drivers[index].get("name") - delay = drivers[index]["delay"] - else: - name = drivers[index] - adddriver(name, delay) - -def otherinit(): - for index in GLOBALINITPARAM: - delay = index.get('delay',0) - if delay !=0 : - time.sleep(1) - write_sysfs_value(index["loc"], index["value"]) - - for index in GLOBALINITCOMMAND: - log_os_system(index) - -def unload_driver(): - u'''remove devices and drivers''' - stop_avs_ctrl() # disable avs-control - stop_fan_ctrl() # disable fan-control service - removedevs() # remove other devices - removedrivers() # remove drivers - -def reload_driver(): - u'''reload devices and drivers''' - removedevs() # remove other devices - removedrivers() # remove drivers - time.sleep(1) - adddrivers() - adddevs() - - -def i2c_check(bus,retrytime = 6): - try: - i2cpath = "/sys/bus/i2c/devices/" + bus - while retrytime and not os.path.exists(i2cpath): - click.echo("%%DEVICE_I2C-HA: i2c bus abnormal, last bus %s is not exist." % i2cpath) - reload_driver() - retrytime -= 1 - time.sleep(1) - except Exception as e: - click.echo("%%DEVICE_I2C-HA: %s" % str(e)) - return - -def set_mac_leds(data): - '''write pci register''' - pcibus = MAC_LED_RESET.get("pcibus") - slot = MAC_LED_RESET.get("slot") - fn = MAC_LED_RESET.get("fn") - bar = MAC_LED_RESET.get("bar") - offset = MAC_LED_RESET.get("offset") - val = MAC_LED_RESET.get(data, None) - if val is None: - click.echo("%%DEVICE_I2C-INIT: set_mac_leds wrong input") - return - rgpciwr(pcibus, slot, fn, bar, offset, val) - -def load_driver(): - u'''load devices and drivers''' - adddrivers() - adddevs() - if STARTMODULE.get("i2ccheck",0) == 1: #i2c HA - busend = i2ccheck_params.get("busend") - retrytime = i2ccheck_params.get("retrytime") - i2c_check(busend,retrytime) - start_fan_ctrl() # enable fan - start_avs_ctrl() # avs voltage-adjustment - otherinit(); # other initialization, QSFP initialization - if STARTMODULE.get("macledreset", 0) == 1: - set_mac_leds("reset") - -@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS) -def main(): - '''device operator''' - pass - - -@main.command() -def start(): - '''load device ''' - if check_driver(): - unload_driver() - load_driver() - -@main.command() -def stop(): - '''stop device ''' - unload_driver() - -@main.command() -def restart(): - '''restart device''' - unload_driver() - load_driver() - -if __name__ == '__main__': - u'''device_i2c operation''' - main() diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/fancontrol.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/script/fancontrol.py deleted file mode 100755 index 3bddb3725d..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/fancontrol.py +++ /dev/null @@ -1,497 +0,0 @@ -#!/usr/bin/env python3.9 -# -*- coding: UTF-8 -*- -import click -import os -import time -import json -import traceback -from interface import Interface -import logging.handlers -from ragileutil import CompressedRotatingFileHandler - -CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) - -FILE_NAME = "/var/log/fancontrol.log" -MAX_LOG_BYTES = 20*1024*1024 -BACKUP_COUNT = 9 - -logger = logging.getLogger("fancontrol") -logger.setLevel(logging.DEBUG) -fanctrl_log = CompressedRotatingFileHandler(FILE_NAME, mode='a', maxBytes=MAX_LOG_BYTES, backupCount=BACKUP_COUNT, encoding=None, delay=0) -formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") -fanctrl_log.setFormatter(formatter) -logger.addHandler(fanctrl_log) - -DEBUG_FILE = "/etc/fancontrol_debug" -FAN_CTRL_CFG_FILE = "/usr/local/bin/fan_ctrl_cfg.json" -KEY_THERMAL = "Thermal" -KEY_FAN = "Fans" -KEY_PID = "PID" -KEY_OPEN_LOOP = "OpenLoop" -KEY_DEVICE = "Device" -KEY_FAN_ERROR = "FanError" - -KEY_FANERROR_PWM_MAX = "Fan_Pwmmax" - -KEY_INLET_TEMP = "INLET_TEMP" -KEY_OUTLET_TEMP = "OUTLET_TEMP" -KEY_SWITCH_TEMP = "SWITCH_TEMP" -KEY_TEMP = [KEY_INLET_TEMP, KEY_OUTLET_TEMP, KEY_SWITCH_TEMP] - -KEY_PID_PWM_MAX = "Pwm_Max" -KEY_PID_PWM_MIN = "Pwm_Min" -KEY_PID_SETPOINT = "SetPoint" -KEY_PID_P = "P" -KEY_PID_I = "I" -KEY_PID_D = "D" -KEY_PID_TEMP_MIN = "Temp_Min" -KEY_PID_TEMP_MAX = "Temp_Max" - -KEY_OPENLOOP_A = "a" -KEY_OPENLOOP_B = "b" -KEY_OPENLOOP_C = "c" -KEY_OPENLOOP_FIXUP = "fix_up" -KEY_OPENLOOP_PWM_MAX = "pwmMax" -KEY_OPENLOOP_PWM_MIN = "pwmMin" -KEY_OPENLOOP_TEMP_MIN = "tempMin" - -STATUS_HIGH_CRIT = 1 -STATUS_MISS_CRIT = 2 -STATUS_BAD_FAN = 4 -STATUS_LOW_FAN = 8 -STATUS_MISS_ERR = 16 - -class AliasedGroup(click.Group): - def get_command(self, ctx, cmd_name): - rv = click.Group.get_command(self, ctx, cmd_name) - if rv is not None: - return rv - else: - return None - matches = [x for x in self.list_commands(ctx) - if x.startswith(cmd_name)] - if not matches: - return None - elif len(matches) == 1: - return click.Group.get_command(self, ctx, matches[0]) - ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) - -def fanctrl_debug_log(s): - # s = s.decode('utf-8').encode('gb2312') - if os.path.isfile(DEBUG_FILE): - logger.debug(s) - -class OpenLoop(): - def __init__(self): - self.a = 0 - self.b = 0 - self.c = 0 - self.fix_up = 0 - self.pwmMax = 0 - self.pwmMin = 0 - self.temp = 0 - self.tempMin = 0 - - def calcPwm(self): - if self.temp < self.tempMin: - return self.pwmMin - pwm = self.a * self.temp * self.temp + self.b * self.temp + self.c - pwm = (pwm / 2.56) - pwm = min(pwm, self.pwmMax) - pwm = max(pwm, self.pwmMin) - return pwm - - -class FanPid(): - def __init__(self): - self.pwmMin = 30 - self.pwmMax = 100 - self.SetPoint = 89 - self.D = 0.196 - self.I = 0.196 - self.P = 1.176 - self.tempMin = 28.0 - self.tempMax = 45.0 - self.pwms = [30, 30] - self.temps = [-1, -1, -1] - self.last_temp = -1 - self.sensor = KEY_SWITCH_TEMP - - def calcPwm(self): - temp_delta = self.temps[2] - self.last_temp - temp_sp_delta = self.temps[2] - self.SetPoint - temp_last_delta = ((self.temps[2] - self.temps[1]) - (self.temps[1] - self.temps[0])) - - delta_pwm = self.P * temp_delta + self.I * temp_sp_delta + self.D * temp_last_delta - - self.temps[0] = self.temps[1] - self.temps[1] = self.temps[2] - self.last_temp = self.temps[2] - - self.pwms[0] = self.pwms[1] - self.pwms[1] = self.pwms[0] + delta_pwm - self.pwms[1] = max(self.pwms[1], self.pwmMin) - self.pwms[1] = min(self.pwms[1], self.pwmMax) - - return self.pwms[1] - -class FanControl(): - - def __init__(self): - self.status = 0 - self.fan_status = 0 - self.error_time = 0 - self.low_time = 0 - self.fan_pwm = 40 - self.fanerr_pwmmax = 0 - self.interface = Interface() - self.temps = {} - self.tempsMax = {} - self.tempsMin = {} - self.tempStatus = {} - self.tempCritTime = {} - self.tempMissTime = {} - - self.fans = {} - self.fanStatus = {} - self.fanErrTime = {} - self.fanLowTime = {} - - self.fanPid = None - self.openloop = None - - self.isBuildin = 0 - self.isLiquid = 0 - self.eeproms = {} - self.airflow = "" - self.pid_switch = 1 - self.openloop_switch = 1 - - def doGetAirFlow(self): - if self.isLiquid == 1: - return "Liquid" - # PSU and Fan is buildin using Tlve2 - if self.isBuildin == 1: - productName = self.interface.get_productname() - if productName != "": - tmp = productName.split("-") - fanairflow = tmp[-1] - if fanairflow == "R": - return "exhaust" - else: - return "intake" - elif self.isBuildin == 0: - return self.interface.get_airflow() - - return "" - - def doFanCtrlInit(self): - if os.path.isfile(FAN_CTRL_CFG_FILE): - fh = open(FAN_CTRL_CFG_FILE) - if not fh: - logger.error("Config file %s doesn't exist" % FAN_CTRL_CFG_FILE) - return False - cfg_json = json.load(fh) - if not cfg_json: - logger.error('Load config file %s failed' % FAN_CTRL_CFG_FILE) - fh.close() - return False - - cfg_keys = [KEY_THERMAL, KEY_FAN, KEY_PID, KEY_OPEN_LOOP, KEY_DEVICE, KEY_FAN_ERROR] - for key in cfg_keys: - if key not in cfg_json: - logger.error('Key %s not present in cfg file' % key) - return False - thermal_json = cfg_json[KEY_THERMAL] - fan_json = cfg_json[KEY_FAN] - pid_json = cfg_json[KEY_PID] - openloop_json = cfg_json[KEY_OPEN_LOOP] - device_json = cfg_json[KEY_DEVICE] - fan_error_json = cfg_json[KEY_FAN_ERROR] - - #init fanerror - self.fanerr_pwmmax = fan_error_json["Fan_Pwmmax"] - - # Get Airflow - self.isBuildin = device_json["Buildin"] - self.isLiquid = device_json["Liquid"] - self.airflow = self.doGetAirFlow() - if self.airflow == "": - logger.warning("Cannot get airflow from device!") - self.pid_switch = device_json["PID"] - self.openloop_switch = device_json["OpenLoop"] - if self.pid_switch == 0 and self.openloop_switch == 0: - logger.warning("No PID and OpenLoop found!") - # Init openloop - self.openloop = OpenLoop() - self.openloop.a = openloop_json[KEY_OPENLOOP_A] - self.openloop.b = openloop_json[KEY_OPENLOOP_B] - self.openloop.c = openloop_json[KEY_OPENLOOP_C] - self.openloop.fix_up = openloop_json[KEY_OPENLOOP_FIXUP] - self.openloop.pwmMax = openloop_json[KEY_OPENLOOP_PWM_MAX] - self.openloop.pwmMin = openloop_json[KEY_OPENLOOP_PWM_MIN] - self.openloop.tempMin = openloop_json[KEY_OPENLOOP_TEMP_MIN] - # Init PID - self.fanPid = FanPid() - self.fanPid.pwmMax = pid_json[KEY_PID_PWM_MAX] - self.fanPid.pwmMin = pid_json[KEY_PID_PWM_MIN] - self.fanPid.SetPoint = pid_json[KEY_PID_SETPOINT] - self.fanPid.P = pid_json[KEY_PID_P] - self.fanPid.I = pid_json[KEY_PID_I] - self.fanPid.D = pid_json[KEY_PID_D] - self.fanPid.tempMin = pid_json[KEY_PID_TEMP_MIN] - self.fanPid.tempMax = pid_json[KEY_PID_TEMP_MAX] - # Init thermal setting - for key, item in list(thermal_json.items()): - fanctrl_debug_log("%s %s " % (key,item)) - if key not in KEY_TEMP: - logger.error('Key %s not present in cfg file' % key) - return False - self.temps[item] = -1.0 - self.tempsMax[item] = self.interface.get_thermal_temp_max(item) - self.tempsMin[item] = self.interface.get_thermal_temp_min(item) - self.tempStatus[item] = 0 - self.tempMissTime[item] = [0, 0] - self.tempCritTime[item] = [0, 0] - if key == self.fanPid.sensor: - self.fanPid.sensor = item - - # Init fans setting - for key, item in list(fan_json.items()): - self.fans[key] = item - self.fanStatus[key] = 0 - self.fanErrTime[key] = [0, 0] - self.fanLowTime[key] = [0, 0] - fh.close() - else: - logger.error('%s is not a file' % FAN_CTRL_CFG_FILE) - return False - - fanctrl_debug_log("Device AirFlow: %s" % (self.airflow)) - self.updateThermal() - self.fanPid.last_temp = self.temps[self.fanPid.sensor] - for i in range(3): - self.fanPid.temps[i] = self.temps[self.fanPid.sensor] - return True - - def setFanSpeed(self, speed): - return self.interface.set_fan_speed_pwm(speed) - - def updateThermal(self): - for key in self.temps: - self.temps[key] = self.interface.get_thermal_temp(key) - fanctrl_debug_log("%s temps %d C" % (key, self.temps[key])) - - if self.temps[KEY_INLET_TEMP] >= self.tempsMax[KEY_INLET_TEMP] or self.temps[KEY_INLET_TEMP] <= -99999: - self.temps[KEY_INLET_TEMP] = self.tempsMax[KEY_INLET_TEMP] - self.openloop.temp = self.temps[KEY_INLET_TEMP] - self.fanPid.temps[2] = self.temps[KEY_INLET_TEMP] - - def checkThermal(self): - thermal_cnt = 0 - for key in self.temps: - if self.temps[key] <= -9999: - if self.tempStatus[key] & STATUS_MISS_CRIT != 0: - self.tempMissTime[key][0] = time.time() - else: - self.tempMissTime[key][1] = time.time() - self.tempStatus[key] = self.tempStatus[key] | STATUS_MISS_CRIT - if self.tempMissTime[key][1] - self.tempMissTime[key][0] > 15: - logger.warning("%s Read Invaild Temperautre %d " % (key, self.temps[key])) - self.tempStatus[key] = self.tempStatus[key] | STATUS_MISS_ERR - else: - self.tempStatus[key] = self.tempStatus[key] & ~(STATUS_MISS_CRIT | STATUS_MISS_ERR) - - if self.temps[key] >= self.tempsMax[key]: - self.tempCritTime[key][0] = time.time() - self.tempStatus[key] = self.tempStatus[key] | STATUS_HIGH_CRIT - logger.warning("%s Temperautre %d >= High Threshold %d" % (key, self.temps[key], self.tempsMax[key])) - elif self.tempStatus[key] & (STATUS_HIGH_CRIT) != 0: - self.tempCritTime[key][1] = time.time() - logger.warning("%s Temperautre %d Recovery" % (key, self.temps[key])) - if self.tempCritTime[key][1] - self.tempCritTime[key][0] > 300: - self.tempStatus[key] = self.tempStatus[key] & ~(STATUS_HIGH_CRIT) - - if self.tempStatus[key] & ~(STATUS_MISS_CRIT) != 0: - thermal_cnt = thermal_cnt + 1 - - self.status = thermal_cnt - fanctrl_debug_log("Thermal error num %d" % self.status) - - def checkFanSpeed(self): - fan_error_cnt = 0 - for key, item in list(self.fans.items()): - speed = self.interface.get_fan_speed_rpm(item) - rpm_max = self.interface.get_fan_rpm_max() - if self.fan_pwm == 100 and speed < rpm_max * 0.7: - if self.fanStatus[key] & STATUS_BAD_FAN != 0: - self.fanErrTime[key][0] = time.time() - else: - self.fanErrTime[key][1] = time.time() - - self.fanStatus[key] = self.fanStatus[key] | STATUS_BAD_FAN - if self.fanErrTime[key][1] - self.fanErrTime[key][0] >= 30: - logger.warning("%s PWM is %d but Speed %d <= %d RPM" % (item, self.fan_pwm, speed, rpm_max * 0.7)) - else: - self.fanStatus[key] = self.fanStatus[key] & ~(STATUS_BAD_FAN) - - if speed < 1000: - if self.fanStatus[key] & STATUS_LOW_FAN != 0: - self.fanLowTime[key][0] = time.time() - else: - self.fanLowTime[key][1] = time.time() - self.fanStatus[key] = self.fanStatus[key] | STATUS_LOW_FAN - if self.fanLowTime[key][1] - self.fanLowTime[key][0] > 30: - logger.warning("%s Speed %d <= %d RPM" % (item, speed, 1000)) - else: - self.fanStatus[key] = self.fanStatus[key] & ~(STATUS_LOW_FAN) - - fanctrl_debug_log("%s speed %d RPM" % (key, speed)) - - if self.fanStatus[key] != 0: - fan_error_cnt = fan_error_cnt + 1 - self.fan_status = fan_error_cnt - fanctrl_debug_log("Fan error num %d" % fan_error_cnt) - - def doApplyPolicy(self): - if self.isLiquid == 1: - return - - self.fan_pwm = 0 - if self.openloop_switch == 1: - openloop_pwm = int(self.openloop.calcPwm()) - fanctrl_debug_log("OpenLoop pwm %d" % (openloop_pwm)) - self.fan_pwm = max(self.fan_pwm, openloop_pwm) - - if self.pid_switch == 1: - pid_pwm = int(self.fanPid.calcPwm()) - fanctrl_debug_log("PID pwm %d" % (pid_pwm)) - self.fan_pwm = max(self.fan_pwm, pid_pwm) - - # Check fan presence - if self.interface.get_fan_presence() == False: - logger.warning("Fan presence check false, set fan pwm to 100") - self.fan_pwm = self.fanerr_pwmmax - if self.fan_status != 0 or self.status != 0: - self.fan_pwm = self.fanerr_pwmmax - fanctrl_debug_log("Fan Speed set to %d pwm" % self.fan_pwm) - for i in range(3): - ret = self.setFanSpeed(self.fan_pwm) - if ret == False: - logger.warning("Fan speed set %d pwm failed, retry %d times" % (self.fan_pwm, i + 1)) - continue - break - - def doBoardFanLedCtrl(self): - if self.interface.get_fan_status() != False and self.interface.get_fan_presence() != False and self.fan_status == 0: - fanctrl_debug_log("Fan status good setting LED to green") - self.interface.set_fan_board_led("green") - else: - fanctrl_debug_log("Fan status error setting LED to red") - self.interface.set_fan_board_led("red") - - def doBoardPsuLedCtrl(self): - if self.interface.get_psu_status() != False: - fanctrl_debug_log("PSU status good setting LED to green") - self.interface.set_psu_board_led("green") - else: - fanctrl_debug_log("PSU status error setting LED to red") - self.interface.set_psu_board_led("red") - - def doSysLedCtrl(self): - self.interface.set_sysled("green") - -def run(interval, fanCtrol): - loop = 0 - # waitForDocker() - fanCtrol.setFanSpeed(fanCtrol.fan_pwm) #init set fan speed to 50 pwm - fanCtrol.doFanCtrlInit() - if fanCtrol.airflow == "Liquid": - logger.warning('Liquid device stopping fancontrol') - return True - while True: - try: - if loop % 5 == 0: # Fan speed control - try: - fanCtrol.updateThermal() - except Exception as e: - logger.error('Failed: Update Thermal, %s' % str(e)) - logger.error('%s' % traceback.format_exc()) - time.sleep(3) - continue - - try: - fanCtrol.checkThermal() - except Exception as e: - logger.error('Failed: Check Thermal, %s' % str(e)) - logger.error('%s' % traceback.format_exc()) - time.sleep(3) - continue - - try: - fanCtrol.checkFanSpeed() - except Exception as e: - logger.error('Failed: Check Fan Speed, %s' % str(e)) - logger.error('%s' % traceback.format_exc()) - time.sleep(3) - continue - - try: - fanCtrol.doApplyPolicy() - except Exception as e: - logger.error('Failed: Apply Policy, %s' % str(e)) - logger.error('%s' % traceback.format_exc()) - time.sleep(3) - continue - - try: - fanCtrol.doBoardFanLedCtrl() - except Exception as e: - logger.error('Failed: Led Control, %s' % str(e)) - logger.error('%s' % traceback.format_exc()) - time.sleep(3) - continue - - try: - fanCtrol.doBoardPsuLedCtrl() - except Exception as e: - logger.error('Failed: Led Control, %s' % str(e)) - logger.error('%s' % traceback.format_exc()) - time.sleep(3) - continue - - try: - fanCtrol.doSysLedCtrl() - except Exception as e: - logger.error('Failed: Led Control, %s' % str(e)) - logger.error('%s' % traceback.format_exc()) - time.sleep(3) - continue - - time.sleep(interval) - loop += interval - except Exception as e: - traceback.print_exc() - logger.error(str(e)) - -@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS) -def main(): - '''device operator''' - pass - -@main.command() -def start(): - '''start fan control''' - logger.info("FANCTROL start") - fanCtrol = FanControl() - interval = 1 - run(interval, fanCtrol) - -@main.command() -def stop(): - '''stop fan control ''' - logger.info("FANCTROL stop") - -# device_i2c operation -if __name__ == '__main__': - main() diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/interface.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/script/interface.py deleted file mode 100644 index 140e09ec08..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/interface.py +++ /dev/null @@ -1,77 +0,0 @@ -from sonic_platform.chassis import Chassis - -class Interface(): - def __init__(self): - self.chassis = Chassis() - self.fan_list = self.chassis._fan_list - self.thermal_list = self.chassis._thermal_list - self.psu_list = self.chassis._psu_list - # Device - def get_productname(self): - return self.chassis.get_name() - - def set_sysled(self, color): - return self.thermal_list[0].set_sys_led(color) - - # Thermal - def get_thermal_temp_max(self, name): - for thermal in self.thermal_list: - if name == thermal.get_real_name(): - return thermal.get_high_threshold() - - def get_thermal_temp_min(self, name): - for thermal in self.thermal_list: - if name == thermal.get_real_name(): - return thermal.get_low_threshold() - - def get_thermal_temp(self, name): - for thermal in self.thermal_list: - if name == thermal.get_real_name(): - return thermal.get_temperature() - # Fans - def set_fan_speed_pwm(self, speed): - return self.fan_list[0].set_speed_pwm(speed) - - def get_fan_status(self): - for fan in self.fan_list: - if fan.get_status() == False: - return False - return True - - def get_fan_presence(self): - for fan in self.fan_list: - if fan.get_presence() == False: - return False - return True - - def set_fan_board_led(self, color): - return self.fan_list[0].set_status_led(color) - - def get_fan_speed_rpm(self, name): - for fan in self.fan_list: - if name == fan.get_name(): - return fan.get_speed_rpm() - return 0 - - def get_fan_rpm_max(self): - return self.fan_list[0].get_high_critical_threshold() - - def get_airflow(self): - tmp1 = self.fan_list[0].get_direction() - tmp2 = self.fan_list[0].get_direction() - for fan in self.fan_list: - tmp1 = fan.get_direction() - if tmp1 != tmp2: - return "F2B" - tmp2 = tmp1 - return tmp2 - # Psus - def get_psu_status(self): - for psu in self.psu_list: - if psu.get_powergood_status == False: - return False - return True - - def set_psu_board_led(self, color): - return self.psu_list[0].set_status_led(color) - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/platform_sensors.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/script/platform_sensors.py deleted file mode 100644 index ca20004308..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/platform_sensors.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/python3 -# * onboard sensors -# -import os -import sys -from sonic_platform.redfish_api import Redfish_Api - -def get_machine_info(): - if not os.path.isfile('/host/machine.conf'): - return None - machine_vars = {} - with open('/host/machine.conf') as machine_file: - for line in machine_file: - tokens = line.split('=') - if len(tokens) < 2: - continue - machine_vars[tokens[0]] = tokens[1].strip() - return machine_vars - -def get_platform_info(machine_info): - if machine_info is not None: - if 'onie_platform' in machine_info: - return machine_info['onie_platform'] - elif 'aboot_platform' in machine_info: - return machine_info['aboot_platform'] - return None - -PLATFORM_ROOT_PATH = '/usr/share/sonic/device' -platform = None - -def get_platform_name(): - global platform - platform = get_platform_info(get_machine_info()) - return platform - -val = get_platform_name() -sys.path.append("/".join([PLATFORM_ROOT_PATH, platform])) - -def print_console(str): - print(str) - -def print_platform(): - platform_info = get_platform_name() - print_console(platform_info) - print_console('Adapter: Ragile Platform Management Controller') - print_console("") - -def get_sensor(): - sensor = Redfish_Api().get_thresholdSensors() - ctrl = sensor["Sensors"] - list_sensor =[] - for item in ctrl: - name = item.get("@odata.id").split("/",9)[9] - now = item.get("Reading") - min = item.get("Thresholds").get("LowerFatal").get("Reading") - max = item.get("Thresholds").get("UpperFatal").get("Reading") - unit = item.get("ReadingUnits") - if unit == "Amps": - unit = "A" - if min == (-1000): - min = (min/1000) - elif unit == "Volts": - unit = "V" - tmp = {} - tmp["name"]= name - tmp["now"] = ("%.3f" % now) - tmp["min"] = ("%.3f" % min) - tmp["max"] = ("%.3f" % max) - tmp["unit"] = unit - list_sensor.append(tmp) - return list_sensor - -def print_boarddcdc(): - val_ret = get_sensor() - print_info_str = "" - toptile = "Onboard Sensors:" - errformat = " {id:<26} : {errmsg}" - formatstr = " {name:<26} : {now:<6} {unit:<1} (Min = {min:<6} {unit:<1} , Max = {max:<6} {unit:<1} )" - - if len(val_ret) != 0: - print_info_str += toptile + '\n' - for item in val_ret: - realformat = formatstr if item.get('errcode', 0) == 0 else errformat - print_info_str += realformat.format(**item) + '\n' - print_console(print_info_str) - -def getsensors(): - print_platform() - print_boarddcdc() - -if __name__ == "__main__": - getsensors() diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/ragilecommon.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/script/ragilecommon.py deleted file mode 100644 index 769427d679..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/ragilecommon.py +++ /dev/null @@ -1,1365 +0,0 @@ -# -*- coding: UTF-8 -*- -# ------------------------------------------------------------------------------- -# Name: Ragile python common module -# Purpose: called by other modules -# -# Author: support -# -# Created: 02/07/2018 -# Copyright: (c) rd 2018 -# ------------------------------------------------------------------------------- - -################################driver-load-adaption####################################################### -# need to export interface -################################################################################################### - -__all__ = [ - "fancontrol_loc", - "fancontrol_config_loc", - "GLOBALCONFIG", - "MONITOR_CONST", - "RAGILE_PART_NUMBER", - "RAGILE_LABEL_REVISION", - "RAGILE_ONIE_VERSION", - "RAGILE_MAC_SIZE", - "RAGILE_MANUF_NAME", - "RAGILE_MANUF_COUNTRY", - "RAGILE_VENDOR_NAME", - "RAGILE_DIAG_VERSION", - "RAGILE_SERVICE_TAG", - "DEV_LEDS", - "MEM_SLOTS", - "LOCAL_LED_CONTROL", - "FIRMWARE_TOOLS", - "STARTMODULE", - "i2ccheck_params", - "FANS_DEF", - "factest_module", - "MONITOR_TEMP_MIN", - "MONITOR_K", - "MONITOR_MAC_IN", - "MONITOR_DEFAULT_SPEED", - "MONITOR_MAX_SPEED", - "MONITOR_MIN_SPEED", - "MONITOR_MAC_ERROR_SPEED", - "MONITOR_FAN_TOTAL_NUM", - "MONITOR_MAC_UP_TEMP", - "MONITOR_MAC_LOWER_TEMP", - "MONITOR_MAC_MAX_TEMP", - "MONITOR_FALL_TEMP", - "MONITOR_MAC_WARNING_THRESHOLD", - "MONITOR_OUTTEMP_WARNING_THRESHOLD", - "MONITOR_BOARDTEMP_WARNING_THRESHOLD", - "MONITOR_CPUTEMP_WARNING_THRESHOLD", - "MONITOR_INTEMP_WARNING_THRESHOLD", - "MONITOR_MAC_CRITICAL_THRESHOLD", - "MONITOR_OUTTEMP_CRITICAL_THRESHOLD", - "MONITOR_BOARDTEMP_CRITICAL_THRESHOLD", - "MONITOR_CPUTEMP_CRITICAL_THRESHOLD", - "MONITOR_INTEMP_CRITICAL_THRESHOLD", - "MONITOR_CRITICAL_NUM", - "MONITOR_SHAKE_TIME", - "MONITOR_INTERVAL", - "MONITOR_MAC_SOURCE_SYSFS", - "MONITOR_MAC_SOURCE_PATH", - "MAC_AVS_PARAM", - "MAC_DEFAULT_PARAM", - "MONITOR_SYS_LED", - "MONITOR_SYS_FAN_LED", - "MONITOR_FANS_LED", - "MONITOR_SYS_PSU_LED", - "MONITOR_FAN_STATUS", - "MONITOR_PSU_STATUS", - "MONITOR_DEV_STATUS", - "MONITOR_DEV_STATUS_DECODE", - "DEV_MONITOR_PARAM", - "SLOT_MONITOR_PARAM", - "fanloc", - "PCA9548START", - "PCA9548BUSEND", - "RAGILE_CARDID", - "RAGILE_PRODUCTNAME", - "FAN_PROTECT", - "rg_eeprom", - "E2_LOC", - "E2_PROTECT", - "MAC_LED_RESET", - "INIT_PARAM", - "INIT_COMMAND", - "CPLDVERSIONS", - "DRIVERLISTS", - "DEVICE", - "E2TYPE", - "FRULISTS", - "fanlevel_6510", - "fanlevel_6520", - "fanlevel", - "TEMPIDCHANGE", - "FACTESTMODULE", - "item1", - "test_sys_reload_item", - "test_sys_item", - "test_temp_item", - "test_mem_item", - "test_hd_item", - "test_rtc_item", - "test_i2c_item", - "test_cpld_item", - "test_portframe_item", - "test_sysled_item", - "test_fan_item", - "test_power_item", - "test_usb_item", - "test_prbs_item", - "test_portbroadcast_item", - "test_debug_level", - "test_log_level", - "test_setmac", - "test_setrtc", - "log_level_critical", - "log_level_debug", - "log_level_error", - "log_level_info", - "log_level_notset", - "log_level_warning", - "test_e2_setmac_item", - "test_bmc_setmac_item", - "test_fan_setmac_item", - "alltest", - "looptest", - "diagtestall", - "menuList", - "TESTCASE", - "PCIe_DEV_LIST", - "PCIe_SPEED_ITEM", -] - -fancontrol_loc = "/usr/local/bin" -fancontrol_config_loc = "/usr/local/bin" - -GLOBALCONFIG = "GLOBALCONFIG" -MONITOR_CONST = "MONITOR_CONST" - -RAGILE_PART_NUMBER = "RJ000001" -RAGILE_LABEL_REVISION = "R01" -RAGILE_ONIE_VERSION = "2018.02" -RAGILE_MAC_SIZE = 3 -RAGILE_MANUF_NAME = "Ragile" -RAGILE_MANUF_COUNTRY = "CHN" -RAGILE_VENDOR_NAME = "Ragile" -RAGILE_DIAG_VERSION = "0.1.0.15" -RAGILE_SERVICE_TAG = "www.ragile.com" - -DEV_LEDS = {} -MEM_SLOTS = [] - -LOCAL_LED_CONTROL = {"CLOSE": {}, "OPEN": {}} - -FIRMWARE_TOOLS = {} -# start-up module -STARTMODULE = {"fancontrol": 1, "avscontrol": 1} - -i2ccheck_params = {"busend": "i2c-66", "retrytime": 6} - -################################################################################################### -##### fan board ID reference -################################################################################################### -FANS_DEF = { - 0x8100: "M6500-FAN-F", - 0x8101: "M6510-FAN-F", - 0x8102: "M6520-FAN-F", - 0x8103: "M6510-FAN-R", -} - -factest_module = { - "sysinfo_showfanmsg": 1, - "sysinfo_showPsumsg": 1, - "sysinfo_showrestfanmsg": 0, - "sysinfo_showrestpsumsg": 0, -} - -#################fan adjustment parameters ############################## -MONITOR_TEMP_MIN = 38 # temperature before speed-adjustment -MONITOR_K = 11 # adjustment algorithm -MONITOR_MAC_IN = 35 # temperature difference between mac and chip(backup) -MONITOR_DEFAULT_SPEED = 0x60 # default speed -MONITOR_MAX_SPEED = 0xFF # maximum speed -MONITOR_MIN_SPEED = 0x33 # minimum speed -MONITOR_MAC_ERROR_SPEED = 0xBB # MAC abnormal speed -MONITOR_FAN_TOTAL_NUM = 4 # 3+1 redundancy design, report to syslog if there is a error -MONITOR_MAC_UP_TEMP = 50 # MAC compared with inlet up -MONITOR_MAC_LOWER_TEMP = -50 # MAC compared with outlet down -MONITOR_MAC_MAX_TEMP = 100 # - -MONITOR_FALL_TEMP = 4 # adjustment reduced temperature -MONITOR_MAC_WARNING_THRESHOLD = 100 # 100 -MONITOR_OUTTEMP_WARNING_THRESHOLD = 85 -MONITOR_BOARDTEMP_WARNING_THRESHOLD = 85 -MONITOR_CPUTEMP_WARNING_THRESHOLD = 85 -MONITOR_INTEMP_WARNING_THRESHOLD = 70 # 70 - -MONITOR_MAC_CRITICAL_THRESHOLD = 105 # 105 -MONITOR_OUTTEMP_CRITICAL_THRESHOLD = 90 # 90 -MONITOR_BOARDTEMP_CRITICAL_THRESHOLD = 90 # 90 -MONITOR_CPUTEMP_CRITICAL_THRESHOLD = 100 # 100 -MONITOR_INTEMP_CRITICAL_THRESHOLD = 80 # 80 -MONITOR_CRITICAL_NUM = 3 # retry times -MONITOR_SHAKE_TIME = 20 # anti-shake times -MONITOR_INTERVAL = 60 - -# 1 get mac temperature from sysfs ,0 get mac temperature from bcmcmd -MONITOR_MAC_SOURCE_SYSFS = (0) -MONITOR_MAC_SOURCE_PATH = None # sysfs path - - -# default MAC AVS parameters -MAC_AVS_PARAM = { - 0x72: 0x0384, - 0x73: 0x037E, - 0x74: 0x0378, - 0x75: 0x0372, - 0x76: 0x036B, - 0x77: 0x0365, - 0x78: 0x035F, - 0x79: 0x0359, - 0x7A: 0x0352, - 0x7B: 0x034C, - 0x7C: 0x0346, - 0x7D: 0x0340, - 0x7E: 0x0339, - 0x7F: 0x0333, - 0x80: 0x032D, - 0x81: 0x0327, - 0x82: 0x0320, - 0x83: 0x031A, - 0x84: 0x0314, - 0x85: 0x030E, - 0x86: 0x0307, - 0x87: 0x0301, - 0x88: 0x02FB, - 0x89: 0x02F5, - 0x8A: 0x02EE, -} - -# default 6520 configuration -MAC_DEFAULT_PARAM = { - "type": 1, # type 1 represents default if out of range / 0 represents no voltage-adjustment if out of range - "default": 0x74, # should be used with type - "loopaddr": 0x00, # AVS loop address - "loop": 0x00, # AVS loop value - "open": 0x00, # diasble write-protection value - "close": 0x40, # enable write-protection value - "bus": 2, # AVSI2C bus address - "devno": 0x60, # AVS address - "addr": 0x21, # AVS voltage-adjustment address - "protectaddr": 0x10, # AVS write-protection address - "sdkreg": "DMU_PCU_OTP_CONFIG_8", # SDK register name - "sdktype": 1, # type 0 represents no shift operation / 1 represents shift operation - "macregloc": 24, # shift operation - "mask": 0xFF, # mask after shift -} - -MONITOR_SYS_LED = [ - {"bus": 2, "devno": 0x33, "addr": 0xB2, "yellow": 0x06, "red": 0x02, "green": 0x04}, - {"bus": 2, "devno": 0x32, "addr": 0x72, "yellow": 0x06, "red": 0x02, "green": 0x04}, -] - -MONITOR_SYS_FAN_LED = [ - {"bus": 2, "devno": 0x33, "addr": 0xB4, "yellow": 0x06, "red": 0x02, "green": 0x04}, -] - -MONITOR_FANS_LED = [ - {"bus": 2, "devno": 0x32, "addr": 0x23, "green": 0x09, "red": 0x0A}, - {"bus": 2, "devno": 0x32, "addr": 0x24, "green": 0x09, "red": 0x0A}, - {"bus": 2, "devno": 0x32, "addr": 0x25, "green": 0x09, "red": 0x0A}, - {"bus": 2, "devno": 0x32, "addr": 0x26, "green": 0x09, "red": 0x0A}, -] - - -MONITOR_SYS_PSU_LED = [ - {"bus": 2, "devno": 0x33, "addr": 0xB3, "yellow": 0x06, "red": 0x02, "green": 0x04}, -] - -MONITOR_FAN_STATUS = [ - {"status": "green", "minOkNum": 4, "maxOkNum": 4}, - {"status": "yellow", "minOkNum": 3, "maxOkNum": 3}, - {"status": "red", "minOkNum": 0, "maxOkNum": 2}, -] - -MONITOR_PSU_STATUS = [ - {"status": "green", "minOkNum": 2, "maxOkNum": 2}, - {"status": "yellow", "minOkNum": 1, "maxOkNum": 1}, - {"status": "red", "minOkNum": 0, "maxOkNum": 0}, -] - -MONITOR_DEV_STATUS = {} -MONITOR_DEV_STATUS_DECODE = {} -DEV_MONITOR_PARAM = {} -SLOT_MONITOR_PARAM = {} - - -fanloc = {"name": "fanset", "location": "0-0032/fan_speed_set"} -#####################MAC-Voltage-Adjustment-Parameters#################################### - - -####================================Adaption-Area================================ -#### RAGILE_COMMON common configuration head -#### "platform" specific configuration head -#### -PCA9548START = 11 -PCA9548BUSEND = 74 - -RAGILE_CARDID = 0x00004040 -RAGILE_PRODUCTNAME = "ragile_ra-b6510" - -FAN_PROTECT = {"bus": 0, "devno": 0x32, "addr": 0x19, "open": 0x00, "close": 0x0F} -rg_eeprom = "2-0057/eeprom" -E2_LOC = {"bus": 2, "devno": 0x57} -E2_PROTECT = {"bus": 2, "devno": 0x33, "addr": 0xB0, "open": 0, "close": 1} -MAC_LED_RESET = {"pcibus": 8, "slot": 0, "fn": 0, "bar": 0, "offset": 64, "reset": 0x98} - -INIT_PARAM = [ - {"loc": "1-0034/sfp_enable", "value": "01"}, - {"loc": "2-0035/sfp_enable2", "value": "ff"}, - {"loc": "2-0033/mac_led", "value": "ff"}, - {"loc": "1-0034/sfp_txdis1", "value": "00"}, - {"loc": "1-0034/sfp_txdis2", "value": "00"}, - {"loc": "1-0034/sfp_txdis3", "value": "00"}, - {"loc": "1-0036/sfp_txdis4", "value": "00"}, - {"loc": "1-0036/sfp_txdis5", "value": "00"}, - {"loc": "1-0036/sfp_txdis6", "value": "00"}, - {"loc": fanloc["location"], "value": "80"}, -] - -INIT_COMMAND = [] - -CPLDVERSIONS = [ - {"loc": "2-0033/cpld_version", "des": "MAC Board CPLDA"}, - {"loc": "2-0035/cpld_version", "des": "MAC Board CPLDB"}, - {"loc": "2-0037/cpld_version", "des": "CPU Board CPLD"}, -] - -## Driver List -## - -DRIVERLISTS = [] -DEVICE = [] -""" -DRIVERLISTS = [ - "i2c_dev", - "i2c_algo_bit", - "i2c_gpio", - "i2c_mux", - "i2c_mux_pca9641", - "i2c_mux_pca954x", # force_deselect_on_exit=1 - "eeprom", - "at24", - "ragile_platform", - "rg_cpld", - "rg_fan", - "rg_psu", - "csu550", - "rg_gpio_xeon", - #IPMIdriver - "ipmi_msghandler", - "ipmi_devintf", - "ipmi_si", -] - -DEVICE = [ - {"name":"pca9641","bus":0 ,"loc":0x10 }, - {"name":"pca9548","bus":2 ,"loc":0x70 }, - {"name":"lm75","bus": 2, "loc":0x48 }, - {"name":"lm75","bus": 2, "loc":0x49 }, - {"name":"lm75","bus": 2, "loc":0x4a }, - {"name":"24c02","bus":2 , "loc":0x57 }, - {"name":"rg_cpld","bus":2 ,"loc":0x33 }, - {"name":"rg_cpld","bus":2 ,"loc":0x35 }, - {"name":"rg_cpld","bus":2 ,"loc":0x37 }, - {"name":"pca9548","bus":1,"loc":0x70 }, - {"name":"pca9548","bus":1,"loc":0x71 }, - {"name":"pca9548","bus":1,"loc":0x72 }, - {"name":"pca9548","bus":1,"loc":0x73 }, - {"name":"pca9548","bus":1,"loc":0x74 }, - {"name":"pca9548","bus":1,"loc":0x75 }, - {"name":"pca9548","bus":1,"loc":0x76 }, - {"name":"pca9548","bus":1,"loc":0x77 }, - {"name":"rg_fan","bus":3,"loc":0x53 }, - {"name":"rg_fan","bus":4,"loc":0x53 }, - {"name":"rg_fan","bus":5,"loc":0x53 }, - #{"name":"rg_fan","bus":6,"loc":0x53 }, #specific fan - {"name":"rg_psu","bus":7 ,"loc":0x50 }, - {"name":"csu550","bus":7 ,"loc":0x58 }, - {"name":"rg_psu","bus":8 ,"loc":0x53 }, - {"name":"csu550","bus":8 ,"loc":0x5b }, -] -""" - -#####################FRU-Info-Adaption################################# -E2TYPE = { - "1": "tlveeprom", - "2": "x86cpueeprom", - "3": "bmceeprom", - "4": "cpueeprom", - "5": "maceeprom", - "6": "sloteeprom", - "7": "fanconnecteeprom", - "8": "M1HFANI-F", - "9": "M1HFANI-R", - "A": "M2HFANI-F", - "B": "M2HFANI-R", - "C": "psu", -} -FRULISTS = [] -################################Manufacturing-Test-Adaption-Area####################################################### -# need to export interface -fanlevel_6510 = { - "level": [51, 150, 255], - "low_speed": [500, 7500, 17000], - "high_speed": [11000, 22500, 28500], -} - -fanlevel_6520 = { - "level": [75, 150, 255], - "low_speed": [750, 4250, 6750], - "high_speed": [4500, 7500, 10000], -} - -fanlevel = fanlevel_6520 - -TEMPIDCHANGE = { - "lm75in": "inlet", - "lm75out": "outlet", - "lm75hot": "hot-point", - "inlet": "lm75in", - "outlet": "lm75out", - "hot-point": "lm75hot", -} - -# Manufacturing-Test module -FACTESTMODULE = {} - -##################################Manufacturing-Test-Menu -item1 = {"name": "Single Test", "deal": "test_signal", "childid": 1} -test_sys_reload_item = {"name": "reset-system", "deal": "test_sys_reload"} - -test_sys_item = {"name": "Product information test", "deal": "test_sysinfo"} -test_temp_item = {"name": "temperature test", "deal": "test_tempinfo"} -test_mem_item = {"name": "Memory test", "deal": "test_cpumemoryinfo"} -test_hd_item = {"name": "Hard disk test", "deal": "test_hard"} -test_rtc_item = {"name": "RTC test ", "deal": "test_rtc"} -test_i2c_item = {"name": "I2c test ", "deal": "test_i2c"} -test_cpld_item = {"name": "CPLD test", "deal": "test_cpld"} -test_portframe_item = { - "name": "Port transmit-receive frame test", - "deal": "test_portframe", -} -test_sysled_item = {"name": "System led test", "deal": "test_led"} -test_fan_item = {"name": "Fan status test", "deal": "test_fan"} -test_power_item = {"name": "PSU status test", "deal": "test_power"} -test_usb_item = {"name": "USB test", "deal": "test_usb"} -test_prbs_item = {"name": "PRBS test", "deal": "test_prbs"} -test_portbroadcast_item = {"name": "Port broadcast", "deal": "test_portbroadcast"} - -test_debug_level = {"name": "Change debug level", "deal": "test_setdebug"} -test_log_level = {"name": "Log output level", "deal": "test_loginfolevel"} -test_setmac = {"name": "setmac", "deal": "test_setmac"} -test_setrtc = {"name": "Set RTC", "deal": "test_set_rtc"} - -log_level_critical = {"name": "CRITICAL", "deal": "test_log_critical"} -log_level_debug = {"name": "DEBUG", "deal": "test_log_debug"} -log_level_error = {"name": "ERROR", "deal": "test_log_error"} -log_level_info = {"name": "INFO", "deal": "test_log_info"} -log_level_notset = {"name": "NOTSET", "deal": "test_log_notset"} -log_level_warning = {"name": "WARNING", "deal": "test_log_warning"} - - -test_e2_setmac_item = {"name": "E2SETMAC", "deal": "test_e2_setmac"} -test_bmc_setmac_item = {"name": "BMCSETMAC", "deal": "test_bmc_setmac"} -test_fan_setmac_item = {"name": "fan SETMAC", "deal": "test_fan_setmac"} - -alltest = [ - test_sys_item, - test_temp_item, - test_mem_item, - test_hd_item, - test_rtc_item, - test_i2c_item, - test_cpld_item, - test_portframe_item, - test_sysled_item, - test_fan_item, - test_power_item, - test_usb_item, - test_prbs_item, - test_portbroadcast_item, -] - -looptest = [ - test_sys_item, - test_temp_item, - test_mem_item, - test_hd_item, - test_rtc_item, - test_i2c_item, - test_cpld_item, - test_portframe_item, - test_fan_item, - test_power_item, - test_usb_item, - test_prbs_item, - test_portbroadcast_item, -] - -diagtestall = [] - -menuList = [ - { - "menuid": 0, - "value": [ - {"name": "Single test", "deal": "test_signal", "childid": 1}, - {"name": "All test", "deal": "test_all"}, - {"name": "Loop test", "deal": "test_loop"}, - # {"name":"Check loop-test result", "deal" :"test_loop_read"}, - # {"name":"Delete loop-test result", "deal" :"test_loop_delete"}, - # {"name":"Load configuration", "deal" :"test_config"}, - test_sys_reload_item, - {"name": "System Configuration", "deal": "test_sysconfig", "childid": 2}, - ], - }, - { - "menuid": 1, - "parentid": 0, - "value": [ - test_sys_item, - test_temp_item, - test_mem_item, - test_hd_item, - test_rtc_item, - test_i2c_item, - test_cpld_item, - test_portframe_item, - test_sysled_item, - test_fan_item, - test_power_item, - test_usb_item, - test_prbs_item, - test_portbroadcast_item, - ], - }, - { - "menuid": 2, - "parentid": 0, - "value": [test_debug_level, test_log_level, test_setmac, test_setrtc,], - }, - { - "menuid": 3, - "parentid": 2, - "value": [ - log_level_critical, - log_level_debug, - log_level_error, - log_level_info, - log_level_notset, - log_level_warning, - ], - }, - { - "menuid": 4, - "parentid": 2, - "value": [test_e2_setmac_item, test_bmc_setmac_item, test_fan_setmac_item,], - }, -] - - -TESTCASE = { - "CPLD": [ - { - "name": "CONNECT BOARD CPLD-A", - "cases": [ - {"name": "cpld32", "cmd": "grtd_test.py cpld_check 0 0x32 0xAA"}, - {"name": "cpld37", "cmd": "grtd_test.py cpld_check 2 0x37 0xAC"}, - ], - }, - { - "name": "MAC BOARD CPLD-A", - "cases": [ - {"name": "cpld33", "cmd": "grtd_test.py cpld_check 2 0x33 0xAB"}, - {"name": "cpld34", "cmd": "grtd_test.py cpld_check 1 0x34 0xAA"}, - ], - }, - { - "name": "MAC BOARD CPLD-B", - "cases": [ - {"name": "cpld36", "cmd": "grtd_test.py cpld_check 1 0x36 0xAA"}, - {"name": "cpld35", "cmd": "grtd_test.py cpld_check 2 0x35 0xAB"}, - ], - }, - ], - "TEMPERATURE": [ - { - "name": "-->temperature test", - "cases": [ - { - "name": "inlet", - "cmd": "grtd_test.py temp 2-0048/hwmon/hwmon1/temp1_input", - }, - { - "name": "outlet", - "cmd": "grtd_test.py temp 2-0049/hwmon/hwmon2/temp1_input", - }, - { - "name": "hot-point", - "cmd": "grtd_test.py temp 2-004a/hwmon/hwmon3/temp1_input", - }, - ], - } - ], - "MEMTORY": { - "cases": [ - {"name": "->memory test 1M", "cmd": "memtester 1M 1"}, - {"name": "->memory test 2M", "cmd": "memtester 2M 1"}, - {"name": "->memory test 8M", "cmd": "memtester 8M 1"}, - # {"name":"->memory test 16M","cmd":"memtester 16M 1"}, - # {"name":"->memory test 256M","cmd":"memtester 256M 1"}, - ] - }, - "SMARTCTLCMDS": { - "cases": [ - {"name": "->Check Hard Disk Info", "cmd": "smartctl -i /dev/sda"}, - {"name": "->Check Hard Disk Monitor Status", "cmd": "smartctl -H /dev/sda"}, - ] - }, - "LED": [ - { - "name": "Light Port Led test", - "cases": [ - { - "name": "-> Red Led Off", - "cmd": "grtd_test.py led loc 1-0034/sfp_led1_red,1-0034/sfp_led2_red,1-0034/sfp_led3_red,1-0034/sfp_led8_red,1-0036/sfp_led4_red,1-0036/sfp_led5_red,1-0036/sfp_led6_red,1-0036/sfp_led7_red 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00", - }, - { - "name": "-> Red Led On", - "cmd": "grtd_test.py led loc 1-0034/sfp_led1_red,1-0034/sfp_led2_red,1-0034/sfp_led3_red,1-0034/sfp_led8_red,1-0036/sfp_led4_red,1-0036/sfp_led5_red,1-0036/sfp_led6_red,1-0036/sfp_led7_red 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff", - }, - { - "name": "-> Recovery Red Led Off", - "cmd": "grtd_test.py led loc 1-0034/sfp_led1_red,1-0034/sfp_led2_red,1-0034/sfp_led3_red,1-0034/sfp_led8_red,1-0036/sfp_led4_red,1-0036/sfp_led5_red,1-0036/sfp_led6_red,1-0036/sfp_led7_red 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00", - }, - { - "name": "-> Yellow Led Off", - "cmd": "grtd_test.py led loc 1-0034/sfp_led1_yellow,1-0034/sfp_led2_yellow,1-0034/sfp_led3_yellow,1-0034/sfp_led8_yellow,1-0036/sfp_led4_yellow,1-0036/sfp_led5_yellow,1-0036/sfp_led6_yellow,1-0036/sfp_led7_yellow 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00", - }, - { - "name": "-> Yellow Led On", - "cmd": "grtd_test.py led loc 1-0034/sfp_led1_yellow,1-0034/sfp_led2_yellow,1-0034/sfp_led3_yellow,1-0034/sfp_led8_yellow,1-0036/sfp_led4_yellow,1-0036/sfp_led5_yellow,1-0036/sfp_led6_yellow,1-0036/sfp_led7_yellow 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff", - }, - { - "name": "-> Recovery Yellow Led Off", - "cmd": "grtd_test.py led loc 1-0034/sfp_led1_yellow,1-0034/sfp_led2_yellow,1-0034/sfp_led3_yellow,1-0034/sfp_led8_yellow,1-0036/sfp_led4_yellow,1-0036/sfp_led5_yellow,1-0036/sfp_led6_yellow,1-0036/sfp_led7_yellow 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00", - }, - ], - }, - { - "name": "fan 1 Led", - "cases": [ - { - "name": "-> LedOff", - "cmd": "grtd_test.py led loc 0-0032/fan0_led 0x0b", - }, - { - "name": "-> Red Led ", - "cmd": "grtd_test.py led loc 0-0032/fan0_led 0x0a", - }, - { - "name": "-> Green Led ", - "cmd": "grtd_test.py led loc 0-0032/fan0_led 0x09", - }, - { - "name": "-> Yellow Led ", - "cmd": "grtd_test.py led loc 0-0032/fan0_led 0x08", - }, - { - "name": "-> Red Led Flashing", - "cmd": "grtd_test.py led loc 0-0032/fan0_led 0x0e", - }, - { - "name": "-> Green Led Flashing", - "cmd": "grtd_test.py led loc 0-0032/fan0_led 0x0d", - }, - { - "name": "-> Yellow Led Flashing", - "cmd": "grtd_test.py led loc 0-0032/fan0_led 0x0c", - }, - { - "name": "-> Recovery Green Led ", - "cmd": "grtd_test.py led loc 0-0032/fan0_led 0x09", - }, - ], - }, - { - "name": "fan 2 Led", - "cases": [ - { - "name": "-> LedOff", - "cmd": "grtd_test.py led loc 0-0032/fan1_led 0x0b", - }, - { - "name": "-> Red Led ", - "cmd": "grtd_test.py led loc 0-0032/fan1_led 0x0a", - }, - { - "name": "-> Green Led ", - "cmd": "grtd_test.py led loc 0-0032/fan1_led 0x09", - }, - { - "name": "-> Yellow Led ", - "cmd": "grtd_test.py led loc 0-0032/fan1_led 0x08", - }, - { - "name": "-> Red Led Flashing", - "cmd": "grtd_test.py led loc 0-0032/fan1_led 0x0e", - }, - { - "name": "-> Green Led Flashing", - "cmd": "grtd_test.py led loc 0-0032/fan1_led 0x0d", - }, - { - "name": "-> Yellow Led Flashing", - "cmd": "grtd_test.py led loc 0-0032/fan1_led 0x0c", - }, - { - "name": "-> Recovery Green Led ", - "cmd": "grtd_test.py led loc 0-0032/fan1_led 0x09", - }, - ], - }, - { - "name": "fan 3 Led", - "cases": [ - { - "name": "-> LedOff", - "cmd": "grtd_test.py led loc 0-0032/fan2_led 0x0b", - }, - { - "name": "-> Red Led ", - "cmd": "grtd_test.py led loc 0-0032/fan2_led 0x0a", - }, - { - "name": "-> Green Led ", - "cmd": "grtd_test.py led loc 0-0032/fan2_led 0x09", - }, - { - "name": "-> Yellow Led ", - "cmd": "grtd_test.py led loc 0-0032/fan2_led 0x08", - }, - { - "name": "-> Red Led Flashing", - "cmd": "grtd_test.py led loc 0-0032/fan2_led 0x0e", - }, - { - "name": "-> Green Led Flashing", - "cmd": "grtd_test.py led loc 0-0032/fan2_led 0x0d", - }, - { - "name": "-> Yellow Led Flashing", - "cmd": "grtd_test.py led loc 0-0032/fan2_led 0x0c", - }, - { - "name": "-> Recovery Green Led ", - "cmd": "grtd_test.py led loc 0-0032/fan2_led 0x09", - }, - ], - }, - { - "name": "Front panel CPU Led", - "cases": [ - { - "name": "-> LedOff", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x00", - }, - { - "name": "-> Green Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x01", - }, - { - "name": "-> Red Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x02", - }, - { - "name": "-> Yellow Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x03", - }, - { - "name": "-> Green Led 1/4sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x11", - }, - { - "name": "-> Green Led 1/2sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x21", - }, - { - "name": "-> Green Led 1sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x41", - }, - { - "name": "-> Green Led 2sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x81", - }, - { - "name": "-> Red Led 1/4sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x12", - }, - { - "name": "-> Red Led 1/2sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x22", - }, - { - "name": "-> Red Led 1sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x42", - }, - { - "name": "-> Red Led 2sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x82", - }, - { - "name": "-> Yellow Led 1/4sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x13", - }, - { - "name": "-> Yellow Led 1/2sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x23", - }, - { - "name": "-> Yellow Led 1sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x43", - }, - { - "name": "-> Yellow Led 2sFlashing ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x83", - }, - { - "name": "-> Recovery Green Led ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_cpu 0x01", - }, - ], - }, - { - "name": "Front panel BMC Led", - "cases": [ - { - "name": "-> LedOff", - "cmd": "grtd_test.py led loc 2-0035/broad_front_bmc 0x00", - }, - { - "name": "-> Red Led Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_bmc 0x01", - }, - { - "name": "-> Red Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_bmc 0x02", - }, - { - "name": "-> Green Led Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_bmc 0x03", - }, - { - "name": "-> Green Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_bmc 0x04", - }, - { - "name": "-> Yellow Led Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_bmc 0x05", - }, - { - "name": "-> Yellow Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_bmc 0x06", - }, - { - "name": "-> Recovery Green Led ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_bmc 0x04", - }, - ], - }, - { - "name": "Front panel location Led", - "cases": [ - { - "name": "-> LedOff", - "cmd": "grtd_test.py led loc 2-0035/broad_front_lct 0xff", - }, - { - "name": "-> LedOn", - "cmd": "grtd_test.py led loc 2-0035/broad_front_lct 0xfe", - }, - { - "name": "->Recovery LedOff", - "cmd": "grtd_test.py led loc 2-0035/broad_front_lct 0xff", - }, - ], - }, - { - "name": "Front panel pwr Led", - "cases": [ - { - "name": "-> LedOff", - "cmd": "grtd_test.py led loc 2-0035/broad_front_pwr 0x00", - }, - { - "name": "-> Red Led Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_pwr 0x01", - }, - { - "name": "-> Red Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_pwr 0x02", - }, - { - "name": "-> Green Led Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_pwr 0x03", - }, - { - "name": "-> Green Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_pwr 0x04", - }, - { - "name": "-> Yellow Led Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_pwr 0x05", - }, - { - "name": "-> Yellow Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_pwr 0x06", - }, - { - "name": "-> Recovery Green Led ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_pwr 0x04", - }, - ], - }, - { - "name": "Front panel fan Led", - "cases": [ - { - "name": "-> LedOff", - "cmd": "grtd_test.py led loc 2-0035/broad_front_fan 0x00", - }, - { - "name": "-> Red Led Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_fan 0x01", - }, - { - "name": "-> Red Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_fan 0x02", - }, - { - "name": "-> Green Led Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_fan 0x03", - }, - { - "name": "-> Green Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_fan 0x04", - }, - { - "name": "-> Yellow Led Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_fan 0x05", - }, - { - "name": "-> Yellow Led not Flashing", - "cmd": "grtd_test.py led loc 2-0035/broad_front_fan 0x06", - }, - { - "name": "-> Recovery Green Led ", - "cmd": "grtd_test.py led loc 2-0035/broad_front_fan 0x04", - }, - ], - }, - ], - "I2C": [ - ####type 1 represents value obtained compated with value - ####type 2 represents return True or False - { - "name": "I2C device test", - "cases": [ - { - "name": " PCA9641 test", - "cmd": "grtd_test.py dev_rd 0 10 0", - "deal_type": 2, - }, - { - "name": " cpld32 test", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " cpld33 test", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " cpld34 test", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " cpld35 test", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " cpld36 test", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " cpld37 test", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " inlet LM75", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " outlet LM75", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " hot-point LM75", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " EEPROM", - "cmd": "grtd_test.py dev_rd 0 32 0", - "deal_type": 2, - }, - { - "name": " Port 1", - "cmd": "grtd_test.py dev_rd 11 0050 0", - "deal_type": 2, - }, - { - "name": " Port 2", - "cmd": "grtd_test.py dev_rd 12 0050 0", - "deal_type": 2, - }, - { - "name": " Port 3", - "cmd": "grtd_test.py dev_rd 13 0050 0", - "deal_type": 2, - }, - { - "name": " Port 4", - "cmd": "grtd_test.py dev_rd 14 0050 0", - "deal_type": 2, - }, - { - "name": " Port 5", - "cmd": "grtd_test.py dev_rd 15 0050 0", - "deal_type": 2, - }, - { - "name": " Port 6", - "cmd": "grtd_test.py dev_rd 16 0050 0", - "deal_type": 2, - }, - { - "name": " Port 7", - "cmd": "grtd_test.py dev_rd 17 0050 0", - "deal_type": 2, - }, - { - "name": " Port 8", - "cmd": "grtd_test.py dev_rd 18 0050 0", - "deal_type": 2, - }, - { - "name": " Port 9", - "cmd": "grtd_test.py dev_rd 19 0050 0", - "deal_type": 2, - }, - { - "name": " Port 10", - "cmd": "grtd_test.py dev_rd 20 0050 0", - "deal_type": 2, - }, - { - "name": " Port 11", - "cmd": "grtd_test.py dev_rd 21 0050 0", - "deal_type": 2, - }, - { - "name": " Port 12", - "cmd": "grtd_test.py dev_rd 22 0050 0", - "deal_type": 2, - }, - { - "name": " Port 13", - "cmd": "grtd_test.py dev_rd 23 0050 0", - "deal_type": 2, - }, - { - "name": " Port 14", - "cmd": "grtd_test.py dev_rd 24 0050 0", - "deal_type": 2, - }, - { - "name": " Port 15", - "cmd": "grtd_test.py dev_rd 25 0050 0", - "deal_type": 2, - }, - { - "name": " Port 16", - "cmd": "grtd_test.py dev_rd 26 0050 0", - "deal_type": 2, - }, - { - "name": " Port 17", - "cmd": "grtd_test.py dev_rd 27 0050 0", - "deal_type": 2, - }, - { - "name": " Port 18", - "cmd": "grtd_test.py dev_rd 28 0050 0", - "deal_type": 2, - }, - { - "name": " Port 19", - "cmd": "grtd_test.py dev_rd 29 0050 0", - "deal_type": 2, - }, - { - "name": " Port 20", - "cmd": "grtd_test.py dev_rd 30 0050 0", - "deal_type": 2, - }, - { - "name": " Port 21", - "cmd": "grtd_test.py dev_rd 31 0050 0", - "deal_type": 2, - }, - { - "name": " Port 22", - "cmd": "grtd_test.py dev_rd 32 0050 0", - "deal_type": 2, - }, - { - "name": " Port 23", - "cmd": "grtd_test.py dev_rd 33 0050 0", - "deal_type": 2, - }, - { - "name": " Port 24", - "cmd": "grtd_test.py dev_rd 34 0050 0", - "deal_type": 2, - }, - { - "name": " Port 25", - "cmd": "grtd_test.py dev_rd 35 0050 0", - "deal_type": 2, - }, - { - "name": " Port 26", - "cmd": "grtd_test.py dev_rd 36 0050 0", - "deal_type": 2, - }, - { - "name": " Port 27", - "cmd": "grtd_test.py dev_rd 37 0050 0", - "deal_type": 2, - }, - { - "name": " Port 28", - "cmd": "grtd_test.py dev_rd 38 0050 0", - "deal_type": 2, - }, - { - "name": " Port 29", - "cmd": "grtd_test.py dev_rd 39 0050 0", - "deal_type": 2, - }, - { - "name": " Port 30", - "cmd": "grtd_test.py dev_rd 40 0050 0", - "deal_type": 2, - }, - { - "name": " Port 31", - "cmd": "grtd_test.py dev_rd 41 0050 0", - "deal_type": 2, - }, - { - "name": " Port 32", - "cmd": "grtd_test.py dev_rd 42 0050 0", - "deal_type": 2, - }, - { - "name": " Port 33", - "cmd": "grtd_test.py dev_rd 43 0050 0", - "deal_type": 2, - }, - { - "name": " Port 34", - "cmd": "grtd_test.py dev_rd 44 0050 0", - "deal_type": 2, - }, - { - "name": " Port 35", - "cmd": "grtd_test.py dev_rd 45 0050 0", - "deal_type": 2, - }, - { - "name": " Port 36", - "cmd": "grtd_test.py dev_rd 46 0050 0", - "deal_type": 2, - }, - { - "name": " Port 37", - "cmd": "grtd_test.py dev_rd 47 0050 0", - "deal_type": 2, - }, - { - "name": " Port 38", - "cmd": "grtd_test.py dev_rd 48 0050 0", - "deal_type": 2, - }, - { - "name": " Port 39", - "cmd": "grtd_test.py dev_rd 49 0050 0", - "deal_type": 2, - }, - { - "name": " Port 40", - "cmd": "grtd_test.py dev_rd 50 0050 0", - "deal_type": 2, - }, - { - "name": " Port 41", - "cmd": "grtd_test.py dev_rd 51 0050 0", - "deal_type": 2, - }, - { - "name": " Port 42", - "cmd": "grtd_test.py dev_rd 52 0050 0", - "deal_type": 2, - }, - { - "name": " Port 43", - "cmd": "grtd_test.py dev_rd 53 0050 0", - "deal_type": 2, - }, - { - "name": " Port 44", - "cmd": "grtd_test.py dev_rd 54 0050 0", - "deal_type": 2, - }, - { - "name": " Port 45", - "cmd": "grtd_test.py dev_rd 55 0050 0", - "deal_type": 2, - }, - { - "name": " Port 46", - "cmd": "grtd_test.py dev_rd 56 0050 0", - "deal_type": 2, - }, - { - "name": " Port 47", - "cmd": "grtd_test.py dev_rd 57 0050 0", - "deal_type": 2, - }, - { - "name": " Port 48", - "cmd": "grtd_test.py dev_rd 58 0050 0", - "deal_type": 2, - }, - { - "name": " Port 49", - "cmd": "grtd_test.py dev_rd 59 0050 0", - "deal_type": 2, - }, - { - "name": " Port 50", - "cmd": "grtd_test.py dev_rd 60 0050 0", - "deal_type": 2, - }, - { - "name": " Port 51", - "cmd": "grtd_test.py dev_rd 61 0050 0", - "deal_type": 2, - }, - { - "name": " Port 52", - "cmd": "grtd_test.py dev_rd 62 0050 0", - "deal_type": 2, - }, - { - "name": " Port 53", - "cmd": "grtd_test.py dev_rd 63 0050 0", - "deal_type": 2, - }, - { - "name": " Port 54", - "cmd": "grtd_test.py dev_rd 64 0050 0", - "deal_type": 2, - }, - { - "name": " Port 55", - "cmd": "grtd_test.py dev_rd 65 0050 0", - "deal_type": 2, - }, - { - "name": " Port 56", - "cmd": "grtd_test.py dev_rd 66 0050 0", - "deal_type": 2, - }, - { - "name": " Port 57", - "cmd": "grtd_test.py dev_rd 67 0050 0", - "deal_type": 2, - }, - { - "name": " Port 58", - "cmd": "grtd_test.py dev_rd 68 0050 0", - "deal_type": 2, - }, - { - "name": " Port 59", - "cmd": "grtd_test.py dev_rd 69 0050 0", - "deal_type": 2, - }, - { - "name": " Port 60", - "cmd": "grtd_test.py dev_rd 70 0050 0", - "deal_type": 2, - }, - { - "name": " Port 61", - "cmd": "grtd_test.py dev_rd 71 0050 0", - "deal_type": 2, - }, - { - "name": " Port 62", - "cmd": "grtd_test.py dev_rd 72 0050 0", - "deal_type": 2, - }, - { - "name": " Port 63", - "cmd": "grtd_test.py dev_rd 73 0050 0", - "deal_type": 2, - }, - { - "name": " Port 64", - "cmd": "grtd_test.py dev_rd 74 0050 0", - "deal_type": 2, - }, - ], - }, - ], -} - -PCIe_DEV_LIST = [] -PCIe_SPEED_ITEM = [] - -################################Manufacturing-Test-Adaption-Area####################################################### diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/ragileconfig.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/script/ragileconfig.py deleted file mode 100644 index 90085fbf64..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/ragileconfig.py +++ /dev/null @@ -1,228 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: UTF-8 -*- -# ------------------------------------------------------------------------------- -# Name: ragileconfig.py -# Purpose: block the difference between various product/onie version for other module -# -# Author: rd -# -# Created: 02/07/2018 -# Copyright: (c) rd 2018 -# ------------------------------------------------------------------------------- -import sys -import os -import logging -from rgutil.baseutil import get_machine_info -from rgutil.baseutil import get_platform_info - -__all__ = [ - "getdeviceplatform", - "get_rjconfig_info", - "MONITOR_CONST", - "MAILBOX_DIR", - "DEVICE", - "GLOBALCONFIG", - "GLOBALINITPARAM", - "GLOBALINITCOMMAND", - "MAC_LED_RESET", - "STARTMODULE", - "fanloc", - "RAGILE_CARDID", - "RAGILE_PRODUCTNAME", - "RAGILE_PART_NUMBER", - "RAGILE_LABEL_REVISION", - "RAGILE_MAC_SIZE", - "RAGILE_MANUF_NAME", - "RAGILE_MANUF_COUNTRY", - "RAGILE_VENDOR_NAME", - "RAGILE_DIAG_VERSION", - "RAGILE_SERVICE_TAG", - "E2_PROTECT", - "E2_LOC", - "FAN_PROTECT", - "FANS_DEF", - "MONITOR_FANS_LED", - "MONITOR_SYS_FAN_LED", - "MONITOR_SYS_PSU_LED", - "MONITOR_FAN_STATUS", - "MONITOR_PSU_STATUS", - "MONITOR_DEV_STATUS", - "MONITOR_DEV_STATUS_DECODE", - "DEV_LEDS", - "MAC_AVS_PARAM", - "MAC_DEFAULT_PARAM", - "FRULISTS", - "rg_eeprom", - "i2ccheck_params", - "FANCTROLDEBUG", - "DEVMONITORDEBUG", -] - - -def getdeviceplatform(): - x = get_platform_info(get_machine_info()) - if x != None: - filepath = "/usr/share/sonic/device/" + x - return filepath - else: - return None - - -platform = get_platform_info(get_machine_info()) -platformpath = getdeviceplatform() -MAILBOX_DIR = "/sys/bus/i2c/devices/" -grtd_productfile = (platform + "_config").replace("-", "_") -common_productfile = "ragilecommon" -configfile_pre = "/usr/local/bin/" - -sys.path.append(platformpath) -sys.path.append(configfile_pre) - - -def get_rjconfig_info(attr_key): - rjconf_filename = platformpath + "/plugins" + "/rj.conf" - if not os.path.isfile(rjconf_filename): - return None - with open(rjconf_filename) as rjconf_file: - for line in rjconf_file: - tokens = line.split("=") - if len(tokens) < 2: - continue - if tokens[0] == attr_key: - return tokens[1].strip() - return None - - -#####BMC-Password### -OPENBMC_PASSWORD = get_rjconfig_info("OPENBMC_PASSWORD") -OPENBMC_PASSWORD = OPENBMC_PASSWORD if (OPENBMC_PASSWORD != None) else "0penBmc" - -############################################################################################ -## if there is no specific file, use common file -module_product = None -if os.path.exists(configfile_pre + grtd_productfile + ".py"): - module_product = __import__(grtd_productfile, globals(), locals(), [], 0) -elif os.path.exists(configfile_pre + common_productfile + ".py"): - module_product = __import__(common_productfile, globals(), locals(), [], 0) -else: - logging.info("No Configuration existed, quit") - exit(-1) -############################################################################################ - -DEVICE = module_product.DEVICE - -##########Driver loading needs parameters -# get different product configuration -RAGILE_GLOBALCONFIG = { - "DRIVERLISTS": module_product.DRIVERLISTS, - "QSFP": { - "startbus": module_product.PCA9548START, - "endbus": module_product.PCA9548BUSEND, - }, - "DEVS": DEVICE, -} -GLOBALCONFIG = RAGILE_GLOBALCONFIG -GLOBALINITPARAM = module_product.INIT_PARAM -GLOBALINITCOMMAND = module_product.INIT_COMMAND - -fancontrol_loc = module_product.fancontrol_loc -fancontrol_config_loc = module_product.fancontrol_config_loc -MAC_LED_RESET = module_product.MAC_LED_RESET -###########Stat-up module parameters -STARTMODULE = module_product.STARTMODULE -FIRMWARE_TOOLS = module_product.FIRMWARE_TOOLS - - -##########Manufacturing-Test need parameters -FACTESTMODULE = module_product.FACTESTMODULE -TESTCASE = module_product.TESTCASE -menuList = module_product.menuList -alltest = module_product.alltest -diagtestall = module_product.diagtestall -looptest = module_product.looptest -fanloc = module_product.fanloc -fanlevel = module_product.fanlevel # fan adjustment level -TEMPIDCHANGE = module_product.TEMPIDCHANGE -CPLDVERSIONS = module_product.CPLDVERSIONS -RAGILE_CARDID = module_product.RAGILE_CARDID -RAGILE_PRODUCTNAME = module_product.RAGILE_PRODUCTNAME - -RAGILE_PART_NUMBER = module_product.RAGILE_PART_NUMBER -RAGILE_LABEL_REVISION = module_product.RAGILE_LABEL_REVISION -RAGILE_ONIE_VERSION = module_product.RAGILE_ONIE_VERSION -RAGILE_MAC_SIZE = module_product.RAGILE_MAC_SIZE -RAGILE_MANUF_NAME = module_product.RAGILE_MANUF_NAME -RAGILE_MANUF_COUNTRY = module_product.RAGILE_MANUF_COUNTRY -RAGILE_VENDOR_NAME = module_product.RAGILE_VENDOR_NAME -RAGILE_DIAG_VERSION = module_product.RAGILE_DIAG_VERSION -RAGILE_SERVICE_TAG = module_product.RAGILE_SERVICE_TAG - -E2_PROTECT = module_product.E2_PROTECT -E2_LOC = module_product.E2_LOC -FAN_PROTECT = module_product.FAN_PROTECT - -FANS_DEF = module_product.FANS_DEF -MONITOR_SYS_LED = module_product.MONITOR_SYS_LED -MONITOR_FANS_LED = module_product.MONITOR_FANS_LED -MONITOR_SYS_FAN_LED = module_product.MONITOR_SYS_FAN_LED -MONITOR_SYS_PSU_LED = module_product.MONITOR_SYS_PSU_LED -MONITOR_FAN_STATUS = module_product.MONITOR_FAN_STATUS -MONITOR_PSU_STATUS = module_product.MONITOR_PSU_STATUS -MONITOR_DEV_STATUS = module_product.MONITOR_DEV_STATUS -MONITOR_DEV_STATUS_DECODE = module_product.MONITOR_DEV_STATUS_DECODE -DEV_MONITOR_PARAM = module_product.DEV_MONITOR_PARAM -SLOT_MONITOR_PARAM = module_product.SLOT_MONITOR_PARAM - - -DEV_LEDS = module_product.DEV_LEDS -MEM_SLOTS = module_product.MEM_SLOTS - -MAC_AVS_PARAM = module_product.MAC_AVS_PARAM -MAC_DEFAULT_PARAM = module_product.MAC_DEFAULT_PARAM -E2TYPE = module_product.E2TYPE -FRULISTS = module_product.FRULISTS -rg_eeprom = "%d-%04x/eeprom" % (E2_LOC["bus"], E2_LOC["devno"]) -factest_module = module_product.factest_module - -LOCAL_LED_CONTROL = module_product.LOCAL_LED_CONTROL - -PCIe_DEV_LIST = module_product.PCIe_DEV_LIST -PCIe_SPEED_ITEM = module_product.PCIe_SPEED_ITEM -i2ccheck_params = module_product.i2ccheck_params - - -class MONITOR_CONST: - TEMP_MIN = module_product.MONITOR_TEMP_MIN - K = module_product.MONITOR_K - MAC_IN = module_product.MONITOR_MAC_IN - DEFAULT_SPEED = module_product.MONITOR_DEFAULT_SPEED - MAX_SPEED = module_product.MONITOR_MAX_SPEED - MIN_SPEED = module_product.MONITOR_MIN_SPEED - MAC_ERROR_SPEED = module_product.MONITOR_MAC_ERROR_SPEED - FAN_TOTAL_NUM = module_product.MONITOR_FAN_TOTAL_NUM - MAC_UP_TEMP = module_product.MONITOR_MAC_UP_TEMP - MAC_LOWER_TEMP = module_product.MONITOR_MAC_LOWER_TEMP - MAC_MAX_TEMP = module_product.MONITOR_MAC_MAX_TEMP - - MAC_WARNING_THRESHOLD = module_product.MONITOR_MAC_WARNING_THRESHOLD - OUTTEMP_WARNING_THRESHOLD = module_product.MONITOR_OUTTEMP_WARNING_THRESHOLD - BOARDTEMP_WARNING_THRESHOLD = module_product.MONITOR_BOARDTEMP_WARNING_THRESHOLD - CPUTEMP_WARNING_THRESHOLD = module_product.MONITOR_CPUTEMP_WARNING_THRESHOLD - INTEMP_WARNING_THRESHOLD = module_product.MONITOR_INTEMP_WARNING_THRESHOLD - - MAC_CRITICAL_THRESHOLD = module_product.MONITOR_MAC_CRITICAL_THRESHOLD - OUTTEMP_CRITICAL_THRESHOLD = module_product.MONITOR_OUTTEMP_CRITICAL_THRESHOLD - BOARDTEMP_CRITICAL_THRESHOLD = module_product.MONITOR_BOARDTEMP_CRITICAL_THRESHOLD - CPUTEMP_CRITICAL_THRESHOLD = module_product.MONITOR_CPUTEMP_CRITICAL_THRESHOLD - INTEMP_CRITICAL_THRESHOLD = module_product.MONITOR_INTEMP_CRITICAL_THRESHOLD - CRITICAL_NUM = module_product.MONITOR_CRITICAL_NUM - SHAKE_TIME = module_product.MONITOR_SHAKE_TIME - MONITOR_INTERVAL = module_product.MONITOR_INTERVAL - MONITOR_FALL_TEMP = module_product.MONITOR_FALL_TEMP - - MONITOR_MAC_SOURCE_SYSFS = module_product.MONITOR_MAC_SOURCE_SYSFS - MONITOR_MAC_SOURCE_PATH = module_product.MONITOR_MAC_SOURCE_PATH - - -FANCTROLDEBUG = 0 # 1 means enable -DEVMONITORDEBUG = 0 # 1 means enable diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/ragileutil.py b/platform/centec-arm64/sonic-platform-modules-ragile/common/script/ragileutil.py deleted file mode 100644 index 365fcb56a7..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/ragileutil.py +++ /dev/null @@ -1,2088 +0,0 @@ -# -*- coding: UTF-8 -*- -# ------------------------------------------------------------------------- -# Name: ragileutil -# Purpose: common configuration and api -# -# Author: rd -# -# Created: 02/07/2018 -# Copyright: (c) rd 2018 -# ------------------------------------------------------------------------- -import sys - -if sys.version_info >= (3, 0): - import subprocess as commands -else: - import commands -import os -import re -import syslog -import time -import binascii -import tty -import termios -import threading -import click -import mmap -from ragileconfig import ( - rg_eeprom, - FRULISTS, - MAC_DEFAULT_PARAM, - MAC_AVS_PARAM, - FANS_DEF, - FAN_PROTECT, - E2_LOC, - E2_PROTECT, - RAGILE_SERVICE_TAG, - RAGILE_DIAG_VERSION, - STARTMODULE, - RAGILE_CARDID, - RAGILE_PRODUCTNAME, - RAGILE_PART_NUMBER, - RAGILE_LABEL_REVISION, - RAGILE_MAC_SIZE, - RAGILE_MANUF_NAME, - RAGILE_MANUF_COUNTRY, - RAGILE_VENDOR_NAME, - MAILBOX_DIR, -) - -try: - from eepromutil.fru import ipmifru -except Exception or SystemExit: - print("error") - -import logging.handlers -import shutil -import gzip -import glob - -__all__ = [ - "MENUID", - "MENUPARENT", - "MENUVALUE", - "CHILDID", - "MENUITEMNAME", - "MENUITEMDEAL", - "GOBACK", - "GOQUIT", - "file_name", - "CRITICAL", - "FATAL", - "ERROR", - "WARNING", - "WARN", - "INFO", - "DEBUG", - "NOTSET", - "levelNames", - "TLV_INFO_ID_STRING", - "TLV_INFO_VERSION", - "TLV_INFO_LENGTH", - "TLV_INFO_LENGTH_VALUE", - "TLV_CODE_PRODUCT_NAME", - "TLV_CODE_PART_NUMBER", - "TLV_CODE_SERIAL_NUMBER", - "TLV_CODE_MAC_BASE", - "TLV_CODE_MANUF_DATE", - "TLV_CODE_DEVICE_VERSION", - "TLV_CODE_LABEL_REVISION", - "TLV_CODE_PLATFORM_NAME", - "TLV_CODE_ONIE_VERSION", - "TLV_CODE_MAC_SIZE", - "TLV_CODE_MANUF_NAME", - "TLV_CODE_MANUF_COUNTRY", - "TLV_CODE_VENDOR_NAME", - "TLV_CODE_DIAG_VERSION", - "TLV_CODE_SERVICE_TAG", - "TLV_CODE_VENDOR_EXT", - "TLV_CODE_CRC_32", - "_TLV_DISPLAY_VENDOR_EXT", - "TLV_CODE_RJ_CARID", - "_TLV_INFO_HDR_LEN", - "SYSLOG_IDENTIFIER", - "log_info", - "log_debug", - "log_warning", - "log_error", - "CompressedRotatingFileHandler", - "SETMACException", - "checkinput", - "checkinputproduct", - "getInputSetmac", - "fan_tlv", - "AVSUTIL", - "I2CUTIL", - "BMC", - "getSdkReg", - "getfilevalue", - "get_sysfs_value", - "write_sysfs_value", - "RJPRINTERR", - "strtoint", - "inttostr", - "str_to_hex", - "hex_to_str", - "str_to_bin", - "bin_to_str", - "get_mac_temp", - "get_mac_temp_sysfs", - "restartDockerService", - "wait_dhcp", - "wait_sdk", - "wait_docker", - "getTLV_BODY", - "_crc32", - "printvalue", - "generate_value", - "getsyseeprombyId", - "fac_init_cardidcheck", - "isValidMac", - "util_setmac", - "getInputCheck", - "getrawch", - "upper_input", - "changeTypeValue", - "astrcmp", - "generate_ext", - "rgi2cget", - "rgi2cset", - "rgpcird", - "rgpciwr", - "rgsysset", - "rgi2cget_word", - "rgi2cset_word", - "fan_setmac", - "checkfansninput", - "checkfanhwinput", - "util_show_fanse2", - "get_fane2_sysfs", - "util_show_fane2", - "getPid", - "fac_fans_setmac_tlv", - "fac_fan_setmac_fru", - "fac_fans_setmac", - "fac_fan_setmac", - "writeToEEprom", - "get_local_eth0_mac", - "getonieversion", - "createbmcMac", - "fac_board_setmac", - "ipmi_set_mac", - "getInputValue", - "bmc_setmac", - "closeProtocol", - "checkSdkMem", - "getch", - "get_raw_input", - "getsysvalue", - "get_pmc_register", - "decoder", - "decode_eeprom", - "get_sys_eeprom", - "getCardId", - "getsysmeminfo", - "getsysmeminfo_detail", - "getDmiSysByType", - "gethwsys", - "getsysbios", - "searchDirByName", - "getUsbLocation", - "getusbinfo", - "get_cpu_info", - "get_version_config_info", - "io_rd", - "io_wr", -] - -MENUID = "menuid" -MENUPARENT = "parentid" -MENUVALUE = "value" -CHILDID = "childid" -MENUITEMNAME = "name" -MENUITEMDEAL = "deal" -GOBACK = "goBack" -GOQUIT = "quit" - -file_name = "/etc/init.d/opennsl-modules-3.16.0-5-amd64" -########################################################################## -# ERROR LOG LEVEL -########################################################################## -CRITICAL = 50 -FATAL = CRITICAL -ERROR = 40 -WARNING = 30 -WARN = WARNING -INFO = 20 -DEBUG = 10 -NOTSET = 0 - -levelNames = { - CRITICAL: "CRITICAL", - ERROR: "ERROR", - WARNING: "WARNING", - INFO: "INFO", - DEBUG: "DEBUG", - NOTSET: "NOTSET", - "CRITICAL": CRITICAL, - "ERROR": ERROR, - "WARN": WARNING, - "WARNING": WARNING, - "INFO": INFO, - "DEBUG": DEBUG, - "NOTSET": NOTSET, -} - -TLV_INFO_ID_STRING = "TlvInfo\x00" -TLV_INFO_VERSION = 0x01 -TLV_INFO_LENGTH = 0x00 -TLV_INFO_LENGTH_VALUE = 0xBA - -########################################################################## -# eeprom info -########################################################################## -TLV_CODE_PRODUCT_NAME = 0x21 -TLV_CODE_PART_NUMBER = 0x22 -TLV_CODE_SERIAL_NUMBER = 0x23 -TLV_CODE_MAC_BASE = 0x24 -TLV_CODE_MANUF_DATE = 0x25 -TLV_CODE_DEVICE_VERSION = 0x26 -TLV_CODE_LABEL_REVISION = 0x27 -TLV_CODE_PLATFORM_NAME = 0x28 -TLV_CODE_ONIE_VERSION = 0x29 -TLV_CODE_MAC_SIZE = 0x2A -TLV_CODE_MANUF_NAME = 0x2B -TLV_CODE_MANUF_COUNTRY = 0x2C -TLV_CODE_VENDOR_NAME = 0x2D -TLV_CODE_DIAG_VERSION = 0x2E -TLV_CODE_SERVICE_TAG = 0x2F -TLV_CODE_VENDOR_EXT = 0xFD -TLV_CODE_CRC_32 = 0xFE -_TLV_DISPLAY_VENDOR_EXT = 1 -TLV_CODE_RJ_CARID = 0x01 -_TLV_INFO_HDR_LEN = 11 - - -SYSLOG_IDENTIFIER = "UTILTOOL" - -# ========================== Syslog wrappers ========================== - - -def log_info(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_INFO, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - - -def log_debug(msg, also_print_to_console=False): - try: - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_DEBUG, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - except Exception as e: - print(str(e)) - - -def log_warning(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_WARNING, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - - -def log_error(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - - -class CompressedRotatingFileHandler(logging.handlers.RotatingFileHandler): - def doRollover(self): - """ - Do a rollover, as described in __init__(). - """ - if self.stream: - self.stream.close() - self.stream = None - if self.backupCount > 0: - for i in range(self.backupCount - 1, 0, -1): - sfn = "%s.%d.gz" % (self.baseFilename, i) - dfn = "%s.%d.gz" % (self.baseFilename, i + 1) - if os.path.exists(sfn): - if os.path.exists(dfn): - os.remove(dfn) - os.rename(sfn, dfn) - dfn = self.baseFilename + ".1.gz" - if os.path.exists(dfn): - os.remove(dfn) - # These two lines below are the only new lines. I commented out the os.rename(self.baseFilename, dfn) and - # replaced it with these two lines. - with open(self.baseFilename, "rb") as f_in, gzip.open(dfn, "wb") as f_out: - shutil.copyfileobj(f_in, f_out) - self.mode = "w" - self.stream = self._open() - - -class SETMACException(Exception): - def __init__(self, param="ERROR", errno="-1"): - err = "Setmac fail[%s]: %s" % (errno, param) - Exception.__init__(self, err) - self.param = param - self.errno = errno - - -def checkinput(b): - if b.isdigit() == False: - raise Exception("Ivalid Number") - if int(b) > 0xFF or int(b) < 0: - raise Exception("Out of area") - - -def checkinputproduct(b): - if b.isalnum() == False: - raise Exception("Invalid string") - - -def getInputSetmac(val): - bia = val.boardInfoArea - pia = val.productInfoArea - if bia != None: - a = raw_input("[Board Card]Product Serial Number:") - if len(a) != 13: - raise Exception("Invalid Serial Number length") - checkinputproduct(a) - bia.boardSerialNumber = a - b = raw_input("[Board Card]Product Version:(from 1-255)") - checkinput(b) - b = "%0x" % int(b) - bia.boardextra1 = b.upper() - if pia != None: - a = raw_input("[Product Area]Product Serial Number:") - if len(a) != 13: - raise Exception("Invalid Serial Number") - checkinputproduct(a) - pia.productSerialNumber = a - b = raw_input("[Product Area]Product Version:(from 1-255)") - checkinput(b) - b = "%0x" % int(b) - pia.productVersion = b.upper() - return val - - -class fan_tlv(object): - VERSION = 0x01 # E2PROM Version, start from 0x01 - FLAG = 0x7E # New E2PROM version flag is 0x7E - HW_VER = 0x01 # compose by master version and fixed version - TYPE = 0xF1 # hw type defination - TLV_LEN = 00 # data length (16bit) - _FAN_TLV_HDR_LEN = 6 - _FAN_TLV_CRC_LEN = 2 - - _FAN_TLV_TYPE_NAME = 0x02 - _FAN_TLV_TYPE_SN = 0x03 - _FAN_TLV_TYPE_HW_INFO = 0x05 - _FAN_TLV_TYPE_DEV_TYPE = 0x06 - - _fandecodetime = 0 - - @property - def dstatus(self): - return self._dstatus - - @property - def typename(self): - return self._typename - - @property - def typesn(self): - return self._typesn - - @property - def typehwinfo(self): - return self._typehwinfo - - @property - def typedevtype(self): - return self._typedevtype - - @property - def fanbus(self): - return self._fanbus - - @property - def fanloc(self): - return self._fanloc - - @property - def fandecodetime(self): - return self._fandecodetime - - def __init__(self): - self._typename = "" - self._typesn = "" - self._typehwinfo = "" - self._typedevtype = "" - self._dstatus = 0 - - def strtoarr(self, str): - s = [] - if str is not None: - for index in range(len(str)): - s.append(str[index]) - return s - - def generate_fan_value(self): - bin_buffer = [chr(0xFF)] * 256 - bin_buffer[0] = chr(self.VERSION) - bin_buffer[1] = chr(self.FLAG) - bin_buffer[2] = chr(self.HW_VER) - bin_buffer[3] = chr(self.TYPE) - - temp_t = "%08x" % self.typedevtype # handle devtype first - typedevtype_t = hex_to_str(temp_t) - total_len = ( - len(self.typename) - + len(self.typesn) - + len(self.typehwinfo) - + len(typedevtype_t) - + 8 - ) - - bin_buffer[4] = chr(total_len >> 8) - bin_buffer[5] = chr(total_len & 0x00FF) - - index_start = 6 - bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_NAME) - bin_buffer[index_start + 1] = chr(len(self.typename)) - bin_buffer[ - index_start + 2 : index_start + 2 + len(self.typename) - ] = self.strtoarr(self.typename) - index_start = index_start + 2 + len(self.typename) - - bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_SN) - bin_buffer[index_start + 1] = chr(len(self.typesn)) - bin_buffer[ - index_start + 2 : index_start + 2 + len(self.typesn) - ] = self.strtoarr(self.typesn) - index_start = index_start + 2 + len(self.typesn) - - bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_HW_INFO) - bin_buffer[index_start + 1] = chr(len(self.typehwinfo)) - bin_buffer[ - index_start + 2 : index_start + 2 + len(self.typehwinfo) - ] = self.strtoarr(self.typehwinfo) - index_start = index_start + 2 + len(self.typehwinfo) - - bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_DEV_TYPE) - bin_buffer[index_start + 1] = chr(len(typedevtype_t)) - bin_buffer[ - index_start + 2 : index_start + 2 + len(typedevtype_t) - ] = self.strtoarr(typedevtype_t) - index_start = index_start + 2 + len(typedevtype_t) - - crcs = fan_tlv.fancrc("".join(bin_buffer[0:index_start])) # check 2bytes - bin_buffer[index_start] = chr(crcs >> 8) - bin_buffer[index_start + 1] = chr(crcs & 0x00FF) - return bin_buffer - - def decode(self, e2): - ret = [] - self.VERSION = ord(e2[0]) - self.FLAG = ord(e2[1]) - self.HW_VER = ord(e2[2]) - self.TYPE = ord(e2[3]) - self.TLV_LEN = (ord(e2[4]) << 8) | ord(e2[5]) - - tlv_index = self._FAN_TLV_HDR_LEN - tlv_end = self._FAN_TLV_HDR_LEN + self.TLV_LEN - - # check checksum - if len(e2) < self._FAN_TLV_HDR_LEN + self.TLV_LEN + 2: - self._dstatus = -2 - return ret - sumcrc = fan_tlv.fancrc(e2[0 : self._FAN_TLV_HDR_LEN + self.TLV_LEN]) - readcrc = ord(e2[self._FAN_TLV_HDR_LEN + self.TLV_LEN]) << 8 | ord( - e2[self._FAN_TLV_HDR_LEN + self.TLV_LEN + 1] - ) - if sumcrc != readcrc: - self._dstatus = -1 - return ret - else: - self._dstatus = 0 - while (tlv_index + 2) < len(e2) and tlv_index < tlv_end: - s = self.decoder(e2[tlv_index : tlv_index + 2 + ord(e2[tlv_index + 1])]) - tlv_index += ord(e2[tlv_index + 1]) + 2 - ret.append(s) - - return ret - - @staticmethod - def fancrc(t): - sum = 0 - for index in range(len(t)): - sum += ord(t[index]) - return sum - - def decoder(self, t): - try: - name = "" - value = "" - if ord(t[0]) == self._FAN_TLV_TYPE_NAME: - name = "Product Name" - value = str(t[2 : 2 + ord(t[1])]) - self._typename = value - elif ord(t[0]) == self._FAN_TLV_TYPE_SN: - name = "serial Number" - value = str(t[2 : 2 + ord(t[1])]) - self._typesn = value - elif ord(t[0]) == self._FAN_TLV_TYPE_HW_INFO: - name = "hardware info" - value = str(t[2 : 2 + ord(t[1])]) - self._typehwinfo = value - elif ord(t[0]) == self._FAN_TLV_TYPE_DEV_TYPE: - name = "dev type" - value = str(t[2 : 2 + ord(t[1])]) - value = str_to_hex(value) - self._typedevtype = value - value = "0x08%x" % value - except Exception as e: - print(e) - return {"name": name, "code": ord(t[0]), "value": value} - - def __str__(self): - formatstr = ( - "VERSION : 0x%02x \n" - " FLAG : 0x%02x \n" - " HW_VER : 0x%02x \n" - " TYPE : 0x%02x \n" - "typename : %s \n" - "typesn : %s \n" - "typehwinfo : %s \n" - ) - return formatstr % ( - self.VERSION, - self.FLAG, - self.HW_VER, - self.TYPE, - self.typename, - self.typesn, - self.typehwinfo, - ) - - -class AVSUTIL: - @staticmethod - def mac_avs_chip(bus, devno, loc, open, close, loop, protectaddr, level, loopaddr): - # disable protection - rgi2cset(bus, devno, protectaddr, open) - rgi2cset(bus, devno, loopaddr, loop) - rgi2cset_word(bus, devno, loc, level) - ret, value = rgi2cget_word(bus, devno, loc) - if strtoint(value) == level: - ret = 0 - # enable protection - rgi2cset(bus, devno, protectaddr, close) - if ret == 0: - return True - return False - - @staticmethod - def macPressure_adj(macavs, avs_param, mac_def_param): - # check whether it within range - max_adj = max(avs_param.keys()) - min_adj = min(avs_param.keys()) - type = mac_def_param["type"] - level = 0 - if type == 0: - if macavs not in range(min_adj, max_adj + 1): - return False - else: - level = macavs - else: - if macavs not in range(min_adj, max_adj + 1): - level = mac_def_param["default"] - else: - level = macavs - ret = AVSUTIL.mac_avs_chip( - mac_def_param["bus"], - mac_def_param["devno"], - mac_def_param["addr"], - mac_def_param["open"], - mac_def_param["close"], - mac_def_param["loop"], - mac_def_param["protectaddr"], - avs_param[level], - mac_def_param["loopaddr"], - ) - return ret - - @staticmethod - def mac_adj(): - macavs = 0 - name = MAC_DEFAULT_PARAM["sdkreg"] - ret, status = getSdkReg(name) - if ret == False: - return False - status = strtoint(status) - # shift operation - if MAC_DEFAULT_PARAM["sdktype"] != 0: - status = (status >> MAC_DEFAULT_PARAM["macregloc"]) & MAC_DEFAULT_PARAM[ - "mask" - ] - macavs = status - ret = AVSUTIL.macPressure_adj(macavs, MAC_AVS_PARAM, MAC_DEFAULT_PARAM) - return ret - - -class I2CUTIL: - @staticmethod - def getvaluefromdevice(name): - ret = [] - for item in DEVICE: - if item["name"] == name: - ret.append(item) - return ret - - @staticmethod - def openFanE2Protect(): - rgi2cset( - FAN_PROTECT["bus"], - FAN_PROTECT["devno"], - FAN_PROTECT["addr"], - FAN_PROTECT["open"], - ) - - @staticmethod - def closeFanE2Protect(): - rgi2cset( - FAN_PROTECT["bus"], - FAN_PROTECT["devno"], - FAN_PROTECT["addr"], - FAN_PROTECT["close"], - ) - - @staticmethod - def writeToFanE2(bus, loc, rst_arr): - index = 0 - for item in rst_arr: - rgi2cset(bus, loc, index, ord(item)) - index += 1 - - @staticmethod - def writeToE2(bus, loc, rst_arr): - index = 0 - for item in rst_arr: - rgi2cset(bus, loc, index, ord(item)) - index += 1 - - @staticmethod - def getE2File(bus, loc): - return "/sys/bus/i2c/devices/%d-00%02x/eeprom" % (bus, loc) - - -class BMC(): - _instance_lock = threading.Lock() - - def __init__(self): - pass - - def __new__(cls, *args, **kwargs): - if not hasattr(Singleton, "_instance"): - with Singleton._instance_lock: - if not hasattr(Singleton, "_instance"): - Singleton._instance = object.__new__(cls) - return Singleton._instance - - -# Internal interface - - -def getSdkReg(reg): - try: - cmd = "bcmcmd -t 1 'getr %s ' < /dev/null" % reg - ret, result = os_system(cmd) - result_t = result.strip().replace("\r", "").replace("\n", "") - if ret != 0 or "Error:" in result_t: - return False, result - patt = r"%s.(.*):(.*)>drivshell" % reg - rt = re.findall(patt, result_t, re.S) - test = re.findall("=(.*)", rt[0][0])[0] - except Exception as e: - return False, "getsdk register error" - return True, test - - -def getfilevalue(location): - try: - with open(location, "r") as fd: - value = fd.read() - return True, value.strip() - except Exception as e: - return False, "error" - - -def get_sysfs_value(location): - pos_t = str(location) - name = get_pmc_register(pos_t) - return name - - -def write_sysfs_value(reg_name, value): - fileLoc = MAILBOX_DIR + reg_name - try: - if not os.path.isfile(fileLoc): - print(fileLoc, "not found !") - return False - with open(fileLoc, "w") as fd: - fd.write(value) - except Exception as error: - log_error("Unable to open " + fileLoc + "file !") - return False - return True - - -def RJPRINTERR(str): - print("\033[0;31m%s\033[0m" % str) - - -def strtoint(str): # convert Hex string to int such as "4040"/"0x4040"/"0X4040" = 16448 - value = 0 - rest_v = str.replace("0X", "").replace("0x", "") - for index in range(len(rest_v)): - value |= int(rest_v[index], 16) << ((len(rest_v) - index - 1) * 4) - return value - - -def inttostr(vl, len): # convert int to string such as 0x3030 = 00 - if type(vl) != int: - raise Exception(" type error") - index = 0 - ret_t = "" - while index < len: - ret = 0xFF & (vl >> index * 8) - ret_t += chr(ret) - index += 1 - return ret_t - - -def str_to_hex(rest_v): - value = 0 - for index in range(len(rest_v)): - value |= ord(rest_v[index]) << ((len(rest_v) - index - 1) * 8) - return value - - -def hex_to_str(s): - len_t = len(s) - if len_t % 2 != 0: - return 0 - ret = "" - for t in range(0, int(len_t / 2)): - ret += chr(int(s[2 * t : 2 * t + 2], 16)) - return ret - - -def str_to_bin(s): - return " ".join([bin(ord(c)).replace("0b", "") for c in s]) - - -def bin_to_str(s): - return "".join([chr(i) for i in [int(b, 2) for b in s.split(" ")]]) - - -def get_mac_temp(): - result = {} - # wait_docker() - # exec twice, get the second result - os_system('bcmcmd -t 1 "show temp" < /dev/null') - ret, log = os_system('bcmcmd -t 1 "show temp" < /dev/null') - if ret: - return False, result - else: - # decode obtained info - logs = log.splitlines() - for line in logs: - if "average" in line: - b = re.findall(r"\d+.\d+", line) - result["average"] = b[0] - elif "maximum" in line: - b = re.findall(r"\d+.\d+", line) - result["maximum"] = b[0] - return True, result - - -def get_mac_temp_sysfs(mactempconf): - try: - temp = -1000000 - temp_list = [] - mac_temp_loc = mactempconf.get("loc", []) - mac_temp_flag = mactempconf.get("flag", None) - if mac_temp_flag is not None: # check mac temperature vaild flag - gettype = mac_temp_flag.get("gettype") - okbit = mac_temp_flag.get("okbit") - okval = mac_temp_flag.get("okval") - if gettype == "io": - io_addr = mac_temp_flag.get("io_addr") - val = io_rd(io_addr) - if val is None: - raise Exception("get mac_flag by io failed.") - else: - bus = mac_temp_flag.get("bus") - loc = mac_temp_flag.get("loc") - offset = mac_temp_flag.get("offset") - ind, val = rgi2cget(bus, loc, offset) - if ind is not True: - raise Exception("get mac_flag by i2c failed.") - val_t = (int(val, 16) & (1 << okbit)) >> okbit - if val_t != okval: - raise Exception("mac_flag invalid, val_t:%d." % val_t) - for loc in mac_temp_loc: - temp_s = get_sysfs_value(loc) - if isinstance(temp_s, str) and temp_s.startswith("ERR"): - raise Exception("get mac temp error. loc:%s" % loc) - temp_t = int(temp_s) - if temp_t == -1000000: - raise Exception("mac temp invalid.loc:%s" % loc) - temp_list.append(temp_t) - temp_list.sort(reverse=True) - temp = temp_list[0] - except Exception as e: - return False, temp - return True, temp - - -def restartDockerService(force=False): - container_name = [ - "database", - "snmp", - "syncd", - "swss", - "dhcp_relay", - "radv", - "teamd", - "pmon", - ] - ret, status = os_system("docker ps") - if ret == 0: - for tmpname in container_name: - if tmpname not in status: - if force == True: - os_system("docker restart %s" % tmpname) - else: - os_system("systemctl restart %s" % tmpname) - - -def wait_dhcp(timeout): - time_cnt = 0 - while True: - try: - ret, status = os_system("systemctl status dhcp_relay.service") - if (ret == 0 and "running" in status) or "SUCCESS" in status: - break - else: - sys.stdout.write(".") - sys.stdout.flush() - time_cnt = time_cnt + 1 - if time_cnt > timeout: - raise Exception("wait_dhcp timeout") - time.sleep(1) - except Exception as e: - return False - return True - - -def wait_sdk(sdk_fpath, timeout): - time_cnt = 0 - while True: - try: - if os.path.exists(sdk_fpath): - break - else: - sys.stdout.write(".") - sys.stdout.flush() - time_cnt = time_cnt + 1 - if time_cnt > timeout: - raise Exception("wait_sdk timeout") - time.sleep(1) - except Exception as e: - return False - return True - - -def wait_docker(need_restart=False, timeout=180): - sdkcheck_params = STARTMODULE.get("sdkcheck", {}) - if sdkcheck_params.get("checktype") == "file": # pass file check - sdk_fpath = sdkcheck_params.get("sdk_fpath") - return wait_sdk(sdk_fpath, timeout) - return wait_dhcp(timeout) - - -def getTLV_BODY(type, productname): - x = [] - temp_t = "" - if type == TLV_CODE_MAC_BASE: - arr = productname.split(":") - for tt in arr: - temp_t += chr(int(tt, 16)) - elif type == TLV_CODE_DEVICE_VERSION: - temp_t = chr(productname) - elif type == TLV_CODE_MAC_SIZE: - temp_t = chr(productname >> 8) + chr(productname & 0x00FF) - else: - temp_t = productname - x.append(chr(type)) - x.append(chr(len(temp_t))) - for i in temp_t: - x.append(i) - return x - - -def _crc32(v): - return "0x%08x" % ( - binascii.crc32(v) & 0xFFFFFFFF - ) # get 8 bytes of crc32 %x return hex - - -def printvalue(b): - index = 0 - for i in range(0, len(b)): - if index % 16 == 0: - print(" ") - print("%02x " % ord(b[i])) - index += 1 - print("\n") - - -def generate_value(_t): - ret = [] - for i in TLV_INFO_ID_STRING: - ret.append(i) - ret.append(chr(TLV_INFO_VERSION)) - ret.append(chr(TLV_INFO_LENGTH)) - ret.append(chr(TLV_INFO_LENGTH_VALUE)) - - total_len = 0 - for key in _t: - x = getTLV_BODY(key, _t[key]) - ret += x - total_len += len(x) - ret[10] = chr(total_len + 6) - - ret.append(chr(0xFE)) - ret.append(chr(0x04)) - s = _crc32("".join(ret)) - for t in range(0, 4): - ret.append(chr(int(s[2 * t + 2 : 2 * t + 4], 16))) - totallen = len(ret) - if totallen < 256: - for left_t in range(0, 256 - totallen): - ret.append(chr(0x00)) - return (ret, True) - - -def getsyseeprombyId(id): - ret = get_sys_eeprom() - for item in ret: - if item["code"] == id: - return item - return None - - -def fac_init_cardidcheck(): - rest = getsyseeprombyId(TLV_CODE_RJ_CARID) # check cardId same or not - if rest is None: - print("need to program write bin file") - return False - else: - rest_v = rest["value"] - value = strtoint(rest_v) - if value == RAGILE_CARDID: - log_debug("check card ID pass") - else: - log_debug("check card ID error") - return False - return True - - -def isValidMac(mac): - if re.match(r"^\s*([0-9a-fA-F]{2,2}:){5,5}[0-9a-fA-F]{2,2}\s*$", mac): - return True - return False - - -# Internet cardsetmac - - -def util_setmac(eth, mac): - rulefile = "/etc/udev/rules.d/70-persistent-net.rules" - if isValidMac(mac) == False: - return False, "MAC invaild" - cmd = "ethtool -e %s | grep 0x0010 | awk '{print \"0x\"$13$12$15$14}'" % eth - ret, log = os_system(cmd) - log_debug(log) - magic = "" - if ret == 0 and len(log): - magic = log - macs = mac.upper().split(":") - - # chage ETH0 to value after setmac - ifconfigcmd = "ifconfig eth0 hw ether %s" % mac - log_debug(ifconfigcmd) - ret, status = os_system(ifconfigcmd) - if ret: - raise SETMACException("software set Internet card MAC error") - index = 0 - for item in macs: - cmd = "ethtool -E %s magic %s offset %d value 0x%s" % (eth, magic, index, item) - log_debug(cmd) - index += 1 - ret, log = os_system(cmd) - if ret != 0: - raise SETMACException("set hardware Internet card MAC error") - # get value after setting - cmd_t = "ethtool -e eth0 offset 0 length 6" - ret, log = os_system(cmd_t) - m = re.split(":", log)[-1].strip().upper() - mac_result = m.upper().split(" ") - - for ind, s in enumerate(macs): - if s != mac_result[ind]: - RJPRINTERR("MAC comparison error") - if os.path.exists(rulefile): - os.remove(rulefile) - print("MGMT MAC[%s]" % mac) - return True - - -def getInputCheck(tips): - str = raw_input(tips) - if ( - astrcmp(str, "y") - or astrcmp(str, "ye") - or astrcmp(str, "yes") - or astrcmp(str, "") - ): - return True - else: - return False - - -def getrawch(): - fd = sys.stdin.fileno() - old_settings = termios.tcgetattr(fd) - try: - tty.setraw(sys.stdin.fileno()) - ch = sys.stdin.read(1) - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - return ch - - -def upper_input(tips): - sys.stdout.write(tips) - sys.stdout.flush() - passwd = [] - while True: - ch = getrawch().upper() - if ch == "\r" or ch == "\n": - return "".join(passwd) - elif ch == "\b" or ord(ch) == 127: - if passwd: - del passwd[-1] - sys.stdout.write("\b \b") - else: - sys.stdout.write(ch) - passwd.append(ch) - - -def changeTypeValue(_value, type1, tips, example): - if type1 == TLV_CODE_PRODUCT_NAME: - while True: - print( - "please check (1)air from forward to backward/(2)air from backward to forward:" - ) - option = raw_input() - if option == "1": - _value[type1] = example + "-F-RJ" - print( - "check Product is air from forward to backward device,Product Name:%s" - % _value[type1] - ) - break - elif option == "2": - _value[type1] = example + "-R-RJ" - print( - "check Product is air from backward to forward device,Product Name:%s" - % _value[type1] - ) - break - else: - print("input incorrect, check please") - return True - print("Please input[%s]such as(%s):" % (tips, example)) - name = upper_input("") - if type1 == TLV_CODE_MAC_BASE: - if len(name) != 12: - raise SETMACException("MAC address length incorrect, check please") - release_mac = "" - for i in range(int(len(name) / 2)): - if i == 0: - release_mac += name[i * 2 : i * 2 + 2] - else: - release_mac += ":" + name[i * 2 : i * 2 + 2] - if isValidMac(release_mac) == True: - _value[type1] = release_mac - else: - raise SETMACException("MAC address invaild, check please") - elif type1 == TLV_CODE_DEVICE_VERSION: - if name.isdigit(): - _value[type1] = int(name) - else: - raise SETMACException("Version is not number, check please") - elif type1 == TLV_CODE_MAC_SIZE: - if name.isdigit(): - _value[type1] = int(name, 16) - else: - raise SETMACException("Version is not number, check please") - elif type1 == TLV_CODE_SERIAL_NUMBER: - if name.isalnum() == False: - raise SETMACException("Serial Number invaild string, check please") - elif len(name) != 13: - raise SETMACException("Serial Number length incorrect, check please") - else: - _value[type1] = name - elif type1 == TLV_CODE_VENDOR_EXT: - _value[type1] = name - else: - _value[type1] = name - return True - - -def astrcmp(str1, str2): - return str1.lower() == str2.lower() - - -def generate_ext(cardid): - s = "%08x" % cardid - ret = "" - for t in range(0, 4): - ret += chr(int(s[2 * t : 2 * t + 2], 16)) - ret = chr(0x01) + chr(len(ret)) + ret - return ret - - -def rgi2cget(bus, devno, address): - command_line = "i2cget -f -y %d 0x%02x 0x%02x " % (bus, devno, address) - retrytime = 6 - ret_t = "" - for i in range(retrytime): - ret, ret_t = os_system(command_line) - if ret == 0: - return True, ret_t - time.sleep(0.1) - return False, ret_t - - -def rgi2cset(bus, devno, address, byte): - command_line = "i2cset -f -y %d 0x%02x 0x%02x 0x%02x" % (bus, devno, address, byte) - retrytime = 6 - ret_t = "" - for i in range(retrytime): - ret, ret_t = os_system(command_line) - if ret == 0: - return True, ret_t - return False, ret_t - - -def rgpcird(pcibus, slot, fn, bar, offset): - """read pci register""" - if offset % 4 != 0: - return False - filename = "/sys/bus/pci/devices/0000:%02x:%02x.%x/resource%d" % (int(pcibus), int(slot), int(fn), int(bar)) - with open(filename, "r+") as file: - size = os.path.getsize(filename) - data = mmap.mmap(file.fileno(), size) - result = data[offset: offset + 4] - s = result[::-1] - val = 0 - for i in range(0, len(s)): - val = val << 8 | ord(s[i]) - data.close() - return "0x%08x" % val - - -def rgpciwr(pcibus, slot, fn, bar, offset, data): - """write pci register""" - ret = inttostr(data, 4) - filename = "/sys/bus/pci/devices/0000:%02x:%02x.%x/resource%d" % (int(pcibus), int(slot), int(fn), int(bar)) - with open(filename, "r+") as file: - size = os.path.getsize(filename) - data = mmap.mmap(file.fileno(), size) - data[offset: offset + 4] = ret - result = data[offset: offset + 4] - s = result[::-1] - val = 0 - for i in range(0, len(s)): - val = val << 8 | ord(s[i]) - data.close() - - -def rgsysset(location, value): - command_line = "echo 0x%02x > %s" % (value, location) - retrytime = 6 - ret_t = "" - for i in range(retrytime): - ret, ret_t = os_system(command_line) - if ret == 0: - return True, ret_t - return False, ret_t - - -def rgi2cget_word(bus, devno, address): - command_line = "i2cget -f -y %d 0x%02x 0x%02x w" % (bus, devno, address) - retrytime = 3 - ret_t = "" - for i in range(retrytime): - ret, ret_t = os_system(command_line) - if ret == 0: - return True, ret_t - return False, ret_t - - -def rgi2cset_word(bus, devno, address, byte): - command_line = "i2cset -f -y %d 0x%02x 0x%02x 0x%x w" % (bus, devno, address, byte) - os_system(command_line) - - -def fan_setmac(): - rgi2cset( - FAN_PROTECT["bus"], - FAN_PROTECT["devno"], - FAN_PROTECT["addr"], - FAN_PROTECT["open"], - ) - rgi2cset( - FAN_PROTECT["bus"], - FAN_PROTECT["devno"], - FAN_PROTECT["addr"], - FAN_PROTECT["close"], - ) - - -def checkfansninput(fan_sn, fansntemp): - if fan_sn in fansntemp: - RJPRINTERR("exist same Serial Number, please input again") - return False - if len(fan_sn) != 13: - RJPRINTERR("Serial Number length incorrect, please input again") - return False - return True - - -# check hw version -def checkfanhwinput(hw): - if len(hw) != 4: - RJPRINTERR("hardware version length incorrect, please input again") - return False - if hw.find(".") != 1: - RJPRINTERR("hardware version incorrect, please input again") - return False - return True - - -def util_show_fanse2(fans): - formatstr = "%-8s %-20s %-20s %-20s %-20s" - print(formatstr % ("id", "Name", "hardware version", "Serial Number", "Time")) - print( - formatstr - % ("------", "---------------", "---------------", "---------------", "----") - ) - for fan in fans: - # print fan.dstatus - if fan.dstatus < 0: - print("%-8s" % ("FAN%d" % (fans.index(fan) + 1))) - RJPRINTERR(" decode e2 error") - else: - print( - formatstr - % ( - "FAN%d" % (fans.index(fan) + 1), - fan.typename.replace(chr(0x00), ""), - fan.typehwinfo.replace(chr(0x00), ""), - fan.typesn.replace(chr(0x00), ""), - fan.fandecodetime, - ) - ) - - -def get_fane2_sysfs(bus, loc): - rg_fan_e2 = "%d-%04x/fan" % (bus, loc) - eeprom = get_sysfs_value(rg_fan_e2) - return eeprom - - -def util_show_fane2(): - ret = sorted(I2CUTIL.getvaluefromdevice("rg_fan")) - if len(ret) <= 0: - return None - fans = [] - for index in range(len(ret)): - t1 = int(round(time.time() * 1000)) - eeprom = get_fane2_sysfs(ret[index]["bus"], ret[index]["loc"]) - t2 = int(round(time.time() * 1000)) - fane2 = fan_tlv() - fane2.fandecodetime = t2 - t1 - fane2.decode(eeprom) - fans.append(fane2) - util_show_fanse2(fans) - - -def getPid(name): - ret = [] - for dirname in os.listdir("/proc"): - if dirname == "curproc": - continue - try: - with open("/proc/{}/cmdline".format(dirname), mode="rb") as fd: - content = fd.read() - except Exception: - continue - if name in content: - ret.append(dirname) - return ret - - -def fac_fans_setmac_tlv(ret): - if len(ret) <= 0: - return False - fans = [] - fansntemp = [] - for index in range(len(ret)): - item = ret[index] - log_debug(item) - eeprom = get_fane2_sysfs(item["bus"], item["loc"]) - fane2 = fan_tlv() - fane2.decode(eeprom) - fane2.fanbus = item["bus"] - fane2.fanloc = item["loc"] - log_debug("decode eeprom success") - - print("Fan[%d]-[%s]setmac" % ((index + 1), FANS_DEF[fane2.typedevtype])) - while True: - print("Please input[%s]:" % "Serial Number") - fan_sn = raw_input() - if checkfansninput(fan_sn, fansntemp) == False: - continue - fansntemp.append(fan_sn) - fan_sn = fan_sn + chr(0x00) - fane2.typesn = fan_sn + chr(0x00) - break - while True: - print("Please input[%s]:" % "hardware version") - hwinfo = raw_input() - if checkfanhwinput(hwinfo) == False: - continue - fan_hwinfo = hwinfo + chr(0x00) - fane2.typehwinfo = fan_hwinfo + chr(0x00) - break - log_debug(fane2.typedevtype) - fane2.typename = FANS_DEF[fane2.typedevtype] + chr(0x00) - fans.append(fane2) - print("\n") - print("\n*******************************\n") - - util_show_fanse2(fans) - if getInputCheck("check input correctly or not(Yes/No):") == True: - for fan in fans: - log_debug("ouput fan") - fac_fan_setmac(fan) - else: - print("setmac quit") - return False - - -def fac_fan_setmac_fru(ret): - fans = FRULISTS.get("fans") - - fanfrus = {} - newfrus = {} - - # getmsg - try: - for fan in fans: - print("===============%s ================getmessage" % fan.get("name")) - eeprom = getsysvalue(I2CUTIL.getE2File(fan.get("bus"), fan.get("loc"))) - fru = ipmifru() - fru.decodeBin(eeprom) - fanfrus[fan.get("name")] = fru - except Exception as e: - print(str(e)) - return False - - # setmsg - for fan in fans: - print("===============%s ================setmac" % fan.get("name")) - fruold = fanfrus.get(fan.get("name")) - newfru = getInputSetmac(fruold) - newfru.recalcute() - newfrus[fan.get("name")] = newfru - # writemsg - for fan in fans: - print("===============%s ================writeToE2" % fan.get("name")) - ret_t = newfrus.get(fan.get("name")) - I2CUTIL.openFanE2Protect() - I2CUTIL.writeToFanE2(fan.get("bus"), fan.get("loc"), ret_t.bindata) - I2CUTIL.closeFanE2Protect() - # check - try: - for fan in fans: - print("===============%s ================getmessage" % fan.get("name")) - eeprom = getsysvalue(I2CUTIL.getE2File(fan.get("bus"), fan.get("loc"))) - fru = ipmifru() - fru.decodeBin(eeprom) - except Exception as e: - print(str(e)) - return False - return True - - -def fac_fans_setmac(): - ret = I2CUTIL.getvaluefromdevice("rg_fan") - if ret is not None and len(ret) > 0: - return fac_fans_setmac_tlv(ret) - fans = FRULISTS.get("fans", None) - if fans is not None and len(fans) > 0: - return fac_fan_setmac_fru(ret) - return False - - -def fac_fan_setmac(item): - I2CUTIL.openFanE2Protect() - I2CUTIL.writeToFanE2(item.fanbus, item.fanloc, item.generate_fan_value()) - I2CUTIL.closeFanE2Protect() - - -def writeToEEprom(rst_arr): - dealtype = E2_PROTECT.get("gettype", None) - if dealtype is None: - rgi2cset( - E2_PROTECT["bus"], - E2_PROTECT["devno"], - E2_PROTECT["addr"], - E2_PROTECT["open"], - ) - elif dealtype == "io": - io_wr(E2_PROTECT["io_addr"], E2_PROTECT["open"]) - index = 0 - for item in rst_arr: - rgi2cset(E2_LOC["bus"], E2_LOC["devno"], index, ord(item)) - index += 1 - - if dealtype is None: - rgi2cset( - E2_PROTECT["bus"], - E2_PROTECT["devno"], - E2_PROTECT["addr"], - E2_PROTECT["close"], - ) - elif dealtype == "io": - io_wr(E2_PROTECT["io_addr"], E2_PROTECT["close"]) - # deal last drivers - os.system("rmmod at24 ") - os.system("modprobe at24 ") - os.system("rm -f /var/cache/sonic/decode-syseeprom/syseeprom_cache") - - -def get_local_eth0_mac(): - cmd = "ifconfig eth0 |grep HWaddr" - print(os_system(cmd)) - - -def getonieversion(): - if not os.path.isfile("/host/machine.conf"): - return "" - machine_vars = {} - with open("/host/machine.conf") as machine_file: - for line in machine_file: - tokens = line.split("=") - if len(tokens) < 2: - continue - machine_vars[tokens[0]] = tokens[1].strip() - return machine_vars.get("onie_version") - - -def createbmcMac(cpumac, num=2): - bcmvalue = strtoint(cpumac[cpumac.rindex(":") + 1 : len(cpumac)]) + num - # bmcmac = - t = cpumac.split(":") - t[5] = "%02x" % bcmvalue - bmcmac = ":".join(t) - return bmcmac.upper() - - -def fac_board_setmac(): - _value = {} - # default value - _value[TLV_CODE_VENDOR_EXT] = generate_ext(RAGILE_CARDID) # generate id - _value[TLV_CODE_PRODUCT_NAME] = RAGILE_PRODUCTNAME - _value[TLV_CODE_PART_NUMBER] = RAGILE_PART_NUMBER - _value[TLV_CODE_LABEL_REVISION] = RAGILE_LABEL_REVISION - _value[TLV_CODE_PLATFORM_NAME] = platform - _value[TLV_CODE_ONIE_VERSION] = getonieversion() - _value[TLV_CODE_MAC_SIZE] = RAGILE_MAC_SIZE - _value[TLV_CODE_MANUF_NAME] = RAGILE_MANUF_NAME - _value[TLV_CODE_MANUF_COUNTRY] = RAGILE_MANUF_COUNTRY - _value[TLV_CODE_VENDOR_NAME] = RAGILE_VENDOR_NAME - _value[TLV_CODE_DIAG_VERSION] = RAGILE_DIAG_VERSION - _value[TLV_CODE_SERVICE_TAG] = RAGILE_SERVICE_TAG - try: - if 0x00004052 == RAGILE_CARDID: - _value[TLV_CODE_PRODUCT_NAME] = RAGILE_PRODUCTNAME + "-RJ" - elif 0x00004051 == RAGILE_CARDID or 0x00004050 == RAGILE_CARDID: - changeTypeValue( - _value, TLV_CODE_PRODUCT_NAME, "Product name", RAGILE_PRODUCTNAME - ) - - changeTypeValue( - _value, TLV_CODE_SERIAL_NUMBER, "SN", "0000000000000" - ) # add serial number - changeTypeValue( - _value, TLV_CODE_DEVICE_VERSION, "hardware version", "101" - ) # hardware version - changeTypeValue( - _value, TLV_CODE_MAC_BASE, "MAC address", "58696cfb2108" - ) # MAC address - _value[TLV_CODE_MANUF_DATE] = time.strftime( - "%m/%d/%Y %H:%M:%S", time.localtime() - ) # add setmac time - rst, ret = generate_value(_value) - if ( - util_setmac("eth0", _value[TLV_CODE_MAC_BASE]) == True - ): # set Internet cardIP - writeToEEprom(rst) # write to e2 - # set BMC MAC - if "bmcsetmac" in FACTESTMODULE and FACTESTMODULE["bmcsetmac"] == 1: - bmcmac = createbmcMac(_value[TLV_CODE_MAC_BASE]) - if ipmi_set_mac(bmcmac) == True: - print("BMC MAC[%s]" % bmcmac) - else: - print("SET BMC MAC FAILED") - return False - else: - return False - except SETMACException as e: - # print(e) - RJPRINTERR("\n\n%s\n\n" % e) - return False - except ValueError as e: - return False - return True - - -def ipmi_set_mac(mac): - macs = mac.split(":") - cmdinit = "ipmitool raw 0x0c 0x01 0x01 0xc2 0x00" - cmdset = "ipmitool raw 0x0c 0x01 0x01 0x05" - for ind in range(len(macs)): - cmdset += " 0x%02x" % int(macs[ind], 16) - os_system(cmdinit) - ret, status = os_system(cmdset) - if ret: - RJPRINTERR("\n\n%s\n\n" % status) - return False - return True - - -def getInputValue(title, tips): - print("Please input[%s]such as(%s):" % (title, tips)) - name = raw_input() - - return name - - -def bmc_setmac(): - tips = "BMC MAC" - print("Please input value you want to change[%s]:" % tips) - name = raw_input() - if len(name) != 12: - RJPRINTERR("\nMAC address invaild, try again\n") - return False - release_mac = "" - for i in range(int(len(name) / 2)): - if i == 0: - release_mac += name[i * 2 : i * 2 + 2] - else: - release_mac += ":" + name[i * 2 : i * 2 + 2] - if isValidMac(release_mac) == True: - if ipmi_set_mac(release_mac) == True: - return True - else: - RJPRINTERR("\nMAC address invaild, try again\n") - return False - - -def closeProtocol(): - # disable LLDP - log_info("disable LLDP") - sys.stdout.write(".") - sys.stdout.flush() - os_system("systemctl stop lldp.service") - log_info("disable lldp service") - sys.stdout.write(".") - sys.stdout.flush() - os_system("systemctl stop bgp.service") - log_info("disable bgp service") - sys.stdout.write(".") - sys.stdout.flush() - # ret, status = os_system('bcmcmd "port ce,xe stp=disable"') - - -# check SDK memory must be 256M - - -def checkSdkMem(): - ind = 0 - file_data = "" - with open(file_name, "r") as f: - for line in f: - if "dmasize=16M" in line: - line = line.replace("dmasize=16M", "dmasize=256M") - ind = -1 - file_data += line - if ind == 0: - return - with open(file_name, "w") as f: - f.write(file_data) - print("change SDK memory to 256, reboot required") - os_system("sync") - os_system("reboot") - - -########################################################################## -# receives a character setting -########################################################################## - - -def getch(msg): - ret = "" - fd = sys.stdin.fileno() - old_ttyinfo = termios.tcgetattr(fd) - new_ttyinfo = old_ttyinfo[:] - new_ttyinfo[3] &= ~termios.ICANON - new_ttyinfo[3] &= ~termios.ECHO - sys.stdout.write(msg) - sys.stdout.flush() - try: - termios.tcsetattr(fd, termios.TCSANOW, new_ttyinfo) - ret = os.read(fd, 1) - finally: - # print "try to setting" - termios.tcsetattr(fd, termios.TCSANOW, old_ttyinfo) - return ret - - -def get_raw_input(): - ret = "" - fd = sys.stdin.fileno() - old_ttyinfo = termios.tcgetattr(fd) - new_ttyinfo = old_ttyinfo[:] - new_ttyinfo[3] &= ~termios.ICANON - new_ttyinfo[3] &= ~termios.ECHO - try: - termios.tcsetattr(fd, termios.TCSANOW, new_ttyinfo) - ret = raw_input("") - except Exception as e: - print(e) - finally: - termios.tcsetattr(fd, termios.TCSANOW, old_ttyinfo) - return ret - - -def getsysvalue(location): - retval = None - mb_reg_file = location - if not os.path.isfile(mb_reg_file): - print(mb_reg_file, "not found !") - return retval - try: - if not os.path.isfile(mb_reg_file): - print(mb_reg_file, "not found !") - return retval - with open(mb_reg_file, "r") as fd: - retval = fd.read() - except Exception as error: - log_error("Unable to open " + mb_reg_file + "file !") - retval = retval.rstrip("\r\n") - retval = retval.lstrip(" ") - # log_debug(retval) - return retval - - -# get file value - - -def get_pmc_register(reg_name): - retval = "ERR" - mb_reg_file = MAILBOX_DIR + reg_name - filepath = glob.glob(mb_reg_file) - if len(filepath) == 0: - return "%s %s notfound" % (retval, mb_reg_file) - mb_reg_file = filepath[0] - if not os.path.isfile(mb_reg_file): - return "%s %s notfound" % (retval, mb_reg_file) - try: - with open(mb_reg_file, "r") as fd: - retval = fd.read() - except Exception as error: - print("error") - retval = retval.rstrip("\r\n") - retval = retval.lstrip(" ") - return retval - - -# decode EEPROM - - -def decoder(s, t): - if ord(t[0]) == TLV_CODE_PRODUCT_NAME: - name = "Product Name" - value = str(t[2 : 2 + ord(t[1])]) - elif ord(t[0]) == TLV_CODE_PART_NUMBER: - name = "Part Number" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_SERIAL_NUMBER: - name = "Serial Number" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_MAC_BASE: - name = "Base MAC Address" - value = ":".join([binascii.b2a_hex(T) for T in t[2:8]]).upper() - elif ord(t[0]) == TLV_CODE_MANUF_DATE: - name = "Manufacture Date" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_DEVICE_VERSION: - name = "Device Version" - value = str(ord(t[2])) - elif ord(t[0]) == TLV_CODE_LABEL_REVISION: - name = "Label Revision" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_PLATFORM_NAME: - name = "Platform Name" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_ONIE_VERSION: - name = "ONIE Version" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_MAC_SIZE: - name = "MAC Addresses" - value = str((ord(t[2]) << 8) | ord(t[3])) - elif ord(t[0]) == TLV_CODE_MANUF_NAME: - name = "Manufacturer" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_MANUF_COUNTRY: - name = "Manufacture Country" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_VENDOR_NAME: - name = "Vendor Name" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_DIAG_VERSION: - name = "Diag Version" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_SERVICE_TAG: - name = "Service Tag" - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_VENDOR_EXT: - name = "Vendor Extension" - value = "" - if _TLV_DISPLAY_VENDOR_EXT: - value = t[2 : 2 + ord(t[1])] - elif ord(t[0]) == TLV_CODE_CRC_32 and len(t) == 6: - name = "CRC-32" - value = "0x%08X" % ( - ((ord(t[2]) << 24) | (ord(t[3]) << 16) | (ord(t[4]) << 8) | ord(t[5])), - ) - elif ord(t[0]) == TLV_CODE_RJ_CARID: - name = "rj_cardid" - value = "" - for c in t[2 : 2 + ord(t[1])]: - value += "%02X" % (ord(c),) - else: - name = "Unknown" - value = "" - for c in t[2 : 2 + ord(t[1])]: - value += "0x%02X " % (ord(c),) - return {"name": name, "code": ord(t[0]), "value": value} - - -def decode_eeprom(e): - total_len = (ord(e[9]) << 8) | ord(e[10]) - tlv_index = _TLV_INFO_HDR_LEN - tlv_end = _TLV_INFO_HDR_LEN + total_len - ret = [] - while (tlv_index + 2) < len(e) and tlv_index < tlv_end: - rt = decoder(None, e[tlv_index : tlv_index + 2 + ord(e[tlv_index + 1])]) - ret.append(rt) - if ord(e[tlv_index]) == TLV_CODE_CRC_32: - break - tlv_index += ord(e[tlv_index + 1]) + 2 - for item in ret: - if item["code"] == TLV_CODE_VENDOR_EXT: - rt = decoder(None, item["value"][0 : 0 + 2 + ord(item["value"][0 + 1])]) - ret.append(rt) - return ret - - -def get_sys_eeprom(): - eeprom = get_sysfs_value(rg_eeprom) - return decode_eeprom(eeprom) - - -# get card ID -def getCardId(): - ret = get_sys_eeprom() - for item in ret: - if item["code"] == TLV_CODE_RJ_CARID: - return item.get("value", None) - return None - - -# ==================================== -# execute shell command -# ==================================== -def os_system(cmd): - status, output = commands.getstatusoutput(cmd) - return status, output - - -########################################### -# get memory slot and number via DMI command -########################################### -def getsysmeminfo(): - ret, log = os_system("which dmidecode ") - if ret != 0 or len(log) <= 0: - error = "cmd find dmidecode" - return False, error - cmd = log + '|grep -P -A5 "Memory\s+Device"|grep Size|grep -v Range' - # get total number first - result = [] - ret1, log1 = os_system(cmd) - if ret1 == 0 and len(log1): - log1 = log1.lstrip() - arr = log1.split("\n") - # total = len(arr) # total slot number - for i in range(len(arr)): - val = re.sub("\D", "", arr[i]) - if val == "": - val = arr[i].lstrip() - val = re.sub("Size:", "", val).lstrip() - # print val - result.append({"slot": i + 1, "size": val}) - return True, result - return False, "error" - - -########################################### -# get memory slot and number via DMI command -# return various arrays -########################################### -def getsysmeminfo_detail(): - ret, log = os_system("which dmidecode ") - if ret != 0 or len(log) <= 0: - error = "cmd find dmidecode" - return False, error - cmd = log + ' -t 17 | grep -A21 "Memory Device"' # 17 - # get total number - ret1, log1 = os_system(cmd) - if ret1 != 0 or len(log1) <= 0: - return False, "command execution error[%s]" % cmd - result_t = log1.split("--") - mem_rets = [] - for item in result_t: - its = item.replace("\t", "").strip().split("\n") - ret = {} - for it in its: - if ":" in it: - key = it.split(":")[0].lstrip() - value = it.split(":")[1].lstrip() - ret[key] = value - mem_rets.append(ret) - return True, mem_rets - - -########################################### -# get BIOS info via DMI command -########################################### -def getDmiSysByType(type_t): - ret, log = os_system("which dmidecode ") - if ret != 0 or len(log) <= 0: - error = "cmd find dmidecode" - return False, error - cmd = log + " -t %s" % type_t - # get total number - ret1, log1 = os_system(cmd) - if ret1 != 0 or len(log1) <= 0: - return False, "command execution error[%s]" % cmd - its = log1.replace("\t", "").strip().split("\n") - ret = {} - for it in its: - if ":" in it: - key = it.split(":")[0].lstrip() - value = it.split(":")[1].lstrip() - ret[key] = value - return True, ret - - -def gethwsys(): - return getDmiSysByType(1) - - -########################################### -# get BIOS info via DMI command - - -def getsysbios(): - return getDmiSysByType(0) - - -def searchDirByName(name, dir): - result = [] - try: - files = os.listdir(dir) - for file in files: - if name in file: - result.append(os.path.join(dir, file)) - except Exception as e: - print(str(e)) - return result - - -def getUsbLocation(): - dir = "/sys/block/" - spect = "sd" - usbpath = "" - result = searchDirByName(spect, dir) - if len(result) <= 0: - return False, usbpath - for item in result: - with open(os.path.join(item, "removable"), "r") as fd: - value = fd.read() - if value.strip() == "1": # U-Disk found - usbpath = item - break - if usbpath == "": # no U-Disk found - log_debug("no usb found") - return False, usbpath - return True, usbpath - - -# judge USB file -def getusbinfo(): - ret, path = getUsbLocation() - if ret == False: - return False, "not usb exists" - str = os.path.join(path, "size") - ret, value = getfilevalue(str) - if ret == True: - return ( - True, - { - "id": os.path.basename(path), - "size": float(value) * 512 / 1024 / 1024 / 1024, - }, - ) - else: - return False, "Err" - - -def get_cpu_info(): - cmd = "cat /proc/cpuinfo |grep processor -A18" # 17 - - ret, log1 = os_system(cmd) - if ret != 0 or len(log1) <= 0: - return False, "command execution error[%s]" % cmd - result_t = log1.split("--") - mem_rets = [] - for item in result_t: - its = item.replace("\t", "").strip().split("\n") - ret = {} - for it in its: - if ":" in it: - key = it.split(":")[0].lstrip() - value = it.split(":")[1].lstrip() - ret[key] = value - mem_rets.append(ret) - return True, mem_rets - - -# read file -def get_version_config_info(attr_key, file_name=None): - if file_name is None: - version_conf_filename = "/root/version.json" - else: - version_conf_filename = file_name - if not os.path.isfile(version_conf_filename): - return None - with open(version_conf_filename) as rjconf_file: - for line in rjconf_file: - tokens = line.split("=") - if len(tokens) < 2: - continue - if tokens[0] == attr_key: - return tokens[1].strip() - return None - - -def io_rd(reg_addr, size=1): - path = "/dev/port" - ret = "" - fd = None - try: - reg_addr = int(reg_addr) - fd = os.open(path, os.O_RDWR|os.O_CREAT) - for i in range(size): - os.lseek(fd, reg_addr+i, os.SEEK_SET) - ret+="{:02x}".format(ord(os.read(fd, 1).decode('latin-1'))) - return ret - except Exception as e: - print(str(e)) - return None - finally: - if fd: os.close(fd) - - -def io_wr(reg_addr, reg_data): - u"""io write""" - fd = None - try: - regdata = 0 - regaddr = 0 - if type(reg_addr) == int: - regaddr = reg_addr - else: - regaddr = int(reg_addr, 16) - if type(reg_data) == int: - regdata = reg_data - else: - regdata = int(reg_data, 16) - devfile = "/dev/port" - fd = os.open(devfile, os.O_RDWR | os.O_CREAT) - os.lseek(fd, regaddr, os.SEEK_SET) - os.write(fd, regdata.to_bytes(2, 'little')) - return True - except ValueError as e: - print(e) - return False - except Exception as e: - print(e) - return False - finally: - if fd: os.close(fd) diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/sensors b/platform/centec-arm64/sonic-platform-modules-ragile/common/script/sensors deleted file mode 100755 index a2c72b123a..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/script/sensors +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -#docker exec -i pmon sensors "$@" - - -#To probe sensors not part of lm-sensors -if [ -r /usr/local/bin/platform_sensors.py ]; then - python /usr/local/bin/platform_sensors.py -fi diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/service/device_i2c.service b/platform/centec-arm64/sonic-platform-modules-ragile/common/service/device_i2c.service deleted file mode 100644 index c7f5776cb5..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/service/device_i2c.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description= Ragile Global Initialize I2c drivers. -After=local-fs.target -Before=pmon.service ntp.service -DefaultDependencies=no - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/device_i2c.py start -ExecStop=/usr/local/bin/device_i2c.py stop -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common/service/fancontrol.service b/platform/centec-arm64/sonic-platform-modules-ragile/common/service/fancontrol.service deleted file mode 100644 index aa686c9f9d..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common/service/fancontrol.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description= Fancontrol for Device. -After=privatenetwork.service -DefaultDependencies=no - -[Service] -ExecStart=/usr/local/bin/fancontrol.py start -Restart=on-failure - -[Install] -WantedBy=multi-user.target - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/Makefile b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/Makefile deleted file mode 100644 index 3202290737..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -PWD = $(shell pwd) -EXTRA_CFLAGS:= -I$(M)/include -EXTRA_CFLAGS+= -Wall -SUB_BUILD_DIR = $(PWD)/build -SERVICE_DIR = $(PWD)/service -INSTALL_DIR = $(SUB_BUILD_DIR)/$(KERNEL_SRC)/$(INSTALL_MOD_DIR) -INSTALL_SCRIPT_DIR = $(SUB_BUILD_DIR)/usr/local/bin -INSTALL_LIB_DIR = $(SUB_BUILD_DIR)/usr/lib/python3.9/dist-packages -INSTALL_SERVICE_DIR = $(SUB_BUILD_DIR)/lib/systemd/system -INSTALL_ETC_DIR = $(SUB_BUILD_DIR)/etc -UNSUPPORT_KERVER = 4.9.189 - -all: - @if [ ! -d ${INSTALL_LIB_DIR} ]; then mkdir -p ${INSTALL_LIB_DIR} ;fi - @if [ -d $(PWD)/lib/ ]; then cp -r $(PWD)/lib/* ${INSTALL_LIB_DIR} ;fi - @if [ ! -d ${INSTALL_SCRIPT_DIR} ]; then mkdir -p ${INSTALL_SCRIPT_DIR} ;fi - @if [ -d $(PWD)/script/ ]; then cp -r $(PWD)/script/* ${INSTALL_SCRIPT_DIR} ;fi - @if [ ! -d ${INSTALL_ETC_DIR} ]; then mkdir -p ${INSTALL_ETC_DIR} ;fi - @if [ -d $(INSTALL_SCRIPT_DIR) ]; then chmod +x $(INSTALL_SCRIPT_DIR)/* ;fi - @if [ ! -d ${INSTALL_SERVICE_DIR} ]; then mkdir -p ${INSTALL_SERVICE_DIR} ;fi - if [ -d $(SERVICE_DIR) ]; then cp -r $(SERVICE_DIR)/* $(INSTALL_SERVICE_DIR) ;fi -clean: - rm -rf $(SUB_BUILD_DIR) - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/fruutil/__init__.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/fruutil/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/fruutil/fru.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/fruutil/fru.py deleted file mode 100644 index 78e7e2bf2c..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/fruutil/fru.py +++ /dev/null @@ -1,1286 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -from bitarray import bitarray -from datetime import datetime, timedelta -import requests -import ConfigParser -import os -import collections - -CONFIG_FILE = "product.conf" -__DEBUG__ = "N" -conf = None - - -def e_print(err): - print("ERROR: " + err) - - -def d_print(debug_info): - if(__DEBUG__ == "Y"): - print(debug_info) - - -def p_print(prompt): - print("PROMPT: " + prompt) - - -class E2Exception(Exception): - - def __init__(self, message='e2 error', code=-100): - self.code = code - self.message = message - - -class BaseArea(): - SUGGESTED_SIZE_COMMON_HEADER = 8 - SUGGESTED_SIZE_INTERNAL_USE_AREA = 72 - SUGGESTED_SIZE_CHASSIS_INFO_AREA = 32 - SUGGESTED_SIZE_BOARD_INFO_AREA = 80 - SUGGESTED_SIZE_PRODUCT_INFO_AREA = 80 - - INITVALUE = b'\x00' - resultvalue = INITVALUE * 256 - COMMON_HEAD_VERSION = b'\x01' - __childList = None - - def __init__(self, name="", size=0, offset=0): - self.__childList = [] - self._offset = offset - self.name = name - self._size = size - self._isPresent = False - self._data = b'\x00' * size - self.__dataoffset = 0 - - @property - def childList(self): - return self.__childList - - @property - def offset(self): - return self._offset - - @property - def size(self): - return self._size - - @property - def data(self): - return self._data - - @property - def isPresent(self): - return self._isPresent - - @isPresent.setter - def isPresent(self, value): - self._isPresent = value - - -class InternalUseArea(BaseArea): - pass - - -class ChassisInfoArea(BaseArea): - pass - - -class BoardInfoArea(BaseArea): - - _boardextra1 = None - - def __str__(self): - formatstr = "version: %x\n" \ - "length: %d \n" \ - "language:%x \n" \ - "mfg_date:%s \n" \ - "boardManufacturer:%s \n" \ - "boardProductName:%s \n" \ - "boardSerialNumber:%s \n" \ - "boardPartNumber:%s \n" \ - "fruFileId:%s \n" \ - "boardextra1:%d \n" - - return formatstr % (ord(self.boardversion), self.size, self.language, self.getMfgRealData(), self.boardManufacturer, - self.boardProductName, self.boardSerialNumber, self.boardPartNumber, - self.fruFileId, int(self.boardextra1,16)) - # return json.load(self.__dict__) - def todict(self): - dic = collections.OrderedDict() - dic["boardversion"]= ord(self.boardversion) - dic["boardlength"]= self.size - dic["boardlanguage"]=self.language - dic["boardmfg_date"]=self.getMfgRealData() - dic["boardManufacturer"]=self.boardManufacturer - dic["boardProductName"]=self.boardProductName - dic["boardSerialNumber"]=self.boardSerialNumber - dic["boardPartNumber"]=self.boardPartNumber - dic["boardfruFileId"]=self.fruFileId - dic["boardextra1"]= int(self.boardextra1,16) - return dic - - def decodedata(self): - index = 0 - self.areaversion = self.data[index] - index += 1 - d_print("decode length :%d class size:%d" % - ((ord(self.data[index]) * 8), self.size)) - index += 2 - - timetmp = self.data[index: index + 3] - self.mfg_date = ord(timetmp[0]) | ( - ord(timetmp[1]) << 8) | (ord(timetmp[2]) << 16) - d_print("decode getMfgRealData :%s" % self.getMfgRealData()) - index += 3 - - templen = E2Util.decodeLength(self.data[index]) - self.boardManufacturer = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode boardManufacturer:%s" % self.boardManufacturer) - - templen = E2Util.decodeLength(self.data[index]) - self.boardProductName = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode boardProductName:%s" % self.boardProductName) - - templen = E2Util.decodeLength(self.data[index]) - self.boardSerialNumber = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode boardSerialNumber:%s" % self.boardSerialNumber) - - templen = E2Util.decodeLength(self.data[index]) - self.boardPartNumber = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode boardPartNumber:%s" % self.boardPartNumber) - - templen = E2Util.decodeLength(self.data[index]) - self.fruFileId = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode fruFileId:%s" % self.fruFileId) - - templen = E2Util.decodeLength(self.data[index]) - self.boardextra1 = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode boardextra1:%s" % self.boardextra1) - - def recalcute(self): - d_print("boardInfoArea version:%x" % ord(self.boardversion)) - d_print("boardInfoArea length:%d" % self.size) - d_print("boardInfoArea language:%x" % self.language) - self.mfg_date = E2Util.minToData() - d_print("boardInfoArea mfg_date:%x" % self.mfg_date) - - self.data = chr(ord(self.boardversion)) + \ - chr(self.size / 8) + chr(self.language) - - self.data += chr(self.mfg_date & 0xFF) - self.data += chr((self.mfg_date >> 8) & 0xFF) - self.data += chr((self.mfg_date >> 16) & 0xFF) - - d_print("boardInfoArea boardManufacturer:%s" % self.boardManufacturer) - typelength = E2Util.getTypeLength(self.boardManufacturer) - self.data += chr(typelength) - self.data += self.boardManufacturer - - d_print("boardInfoArea boardProductName:%s" % self.boardProductName) - self.data += chr(E2Util.getTypeLength(self.boardProductName)) - self.data += self.boardProductName - - d_print("boardInfoArea boardSerialNumber:%s" % self.boardSerialNumber) - self.data += chr(E2Util.getTypeLength(self.boardSerialNumber)) - self.data += self.boardSerialNumber - - d_print("boardInfoArea boardPartNumber:%s" % self.boardPartNumber) - self.data += chr(E2Util.getTypeLength(self.boardPartNumber)) - self.data += self.boardPartNumber - - d_print("boardInfoArea fruFileId:%s" % self.fruFileId) - self.data += chr(E2Util.getTypeLength(self.fruFileId)) - self.data += self.fruFileId - - if self.boardextra1 != None: - d_print("boardInfoArea boardextra1:%s" % self.boardextra1) - self.data += chr(E2Util.getTypeLength(self.boardextra1)) - self.data += self.boardextra1 - - self.data += chr(0xc1) - d_print("self.data:%d" % len(self.data)) - d_print("self.size:%d" % self.size) - - if len(self.data) > (self.size - 1): - incr = (len(self.data) - self.size) / 8 + 1 - self.size += incr * 8 - - for tianchong in range(self.size - len(self.data) - 1): - self.data += self.INITVALUE - - test = 0 - for index in range(len(self.data)): - test += ord(self.data[index]) - - # checksum - checksum = (0x100 - (test % 256)) if (test % 256) != 0 else 0 - d_print("board info checksum:%x" % checksum) - self.data += chr(checksum) - - def getMfgRealData(self): - starttime = datetime(1996, 1, 1, 0, 0, 0) - mactime = starttime + timedelta(minutes=self.mfg_date) - return mactime - - @property - def language(self): - self._language = 25 - return self._language - - @property - def mfg_date(self): - return self._mfg_date - - @property - def boardversion(self): - self._boardversion = self.COMMON_HEAD_VERSION - return self._boardversion - - @property - def fruFileId(self): - return self._FRUFileID - - @property - def boardextra1(self): - return self._boardextra1 - - @property - def boardPartNumber(self): - return self._boardPartNumber - - @property - def boardSerialNumber(self): - return self._boardSerialNumber - - @property - def boardProductName(self): - return self._boradProductName - - @property - def boardManufacturer(self): - return self._boardManufacturer - - @property - def boardTime(self): - return self._boardTime - - @property - def fields(self): - return self._fields - - -class ProductInfoArea(BaseArea): - _productExtra1 = None - _productExtra2 = None - _productExtra3 = None - _productManufacturer = None - _productAssetTag = None - _FRUFileID = None - - def __str__(self): - formatstr = "version: %x\n" \ - "length: %d \n" \ - "language::%x \n" \ - "productManufacturer:%s \n" \ - "productName:%s \n" \ - "productPartModelName:%s \n" \ - "productVersion:%d \n" \ - "productSerialNumber:%s \n" \ - "productAssetTag:%s \n" \ - "fruFileId:%s \n" \ - "productExtra1:%s \n"\ - "productExtra2:%s \n"\ - "productExtra3:%s \n" - - return formatstr % (ord(self.areaversion), self.size, self.language, self.productManufacturer, self.productName, - self.productPartModelName, int(self.productVersion, 16), self.productSerialNumber, - self.productAssetTag,self.fruFileId, self.productExtra1, - E2Util.decodeMac(self.productExtra2), E2Util.decodeMacLen(self.productExtra3)) - - def todict(self): - dic = collections.OrderedDict() - dic["productversion"]= ord(self.areaversion) - dic["productlength"]= self.size - dic["productlanguage"]=self.language - dic["productManufacturer"]=self.productManufacturer - dic["productName"]=self.productName - dic["productPartModelName"]=self.productPartModelName - dic["productVersion"]= int(self.productVersion, 16) - dic["productSerialNumber"]=self.productSerialNumber - dic["productAssetTag"]=self.productAssetTag - dic["productfruFileId"]= self.fruFileId - dic["productExtra1"]=self.productExtra1 - dic["productExtra2"]=E2Util.decodeMac(self.productExtra2) - dic["productExtra3"]= E2Util.decodeMacLen(self.productExtra3) - return dic - - def decodedata(self): - index = 0 - self.areaversion = self.data[index] # 0 - index += 1 - d_print("decode length %d" % (ord(self.data[index]) * 8)) - d_print("class size %d" % self.size) - index += 2 - - templen = E2Util.decodeLength(self.data[index]) - self.productManufacturer = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productManufacturer:%s" % self.productManufacturer) - - templen = E2Util.decodeLength(self.data[index]) - self.productName = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productName:%s" % self.productName) - - templen = E2Util.decodeLength(self.data[index]) - self.productPartModelName = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productPartModelName:%s" % self.productPartModelName) - - templen = E2Util.decodeLength(self.data[index]) - self.productVersion = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productVersion:%s" % self.productVersion) - - templen = E2Util.decodeLength(self.data[index]) - self.productSerialNumber = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productSerialNumber:%s" % self.productSerialNumber) - - - templen = E2Util.decodeLength(self.data[index]) - self.productAssetTag = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productAssetTag:%s" % self.productAssetTag) - - - templen = E2Util.decodeLength(self.data[index]) - self.fruFileId = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode fruFileId:%s" % self.fruFileId) - - if index < self.size and self.data[index] != chr(0xC1): # end - templen = E2Util.decodeLength(self.data[index]) - self.productExtra1 = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productExtra1:%s" % self.productExtra1) - if index < self.size and self.data[index] != chr(0xC1): # end - templen = E2Util.decodeLength(self.data[index]) - self.productExtra2 = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productExtra2:%s" % - E2Util.decodeMac(self.productExtra2)) - if index < self.size and self.data[index] != chr(0xC1): # end - templen = E2Util.decodeLength(self.data[index]) - self.productExtra3 = self.data[index + 1: index + templen + 1] - index += templen + 1 - d_print("decode productExtra3:%s" % - E2Util.decodeMacLen(self.productExtra3)) - - @property - def productVersion(self): - return self._productVersion - - @property - def areaversion(self): - self._areaversion = self.COMMON_HEAD_VERSION - return self._areaversion - - @property - def language(self): - self._language = 25 - return self._language - - @property - def productManufacturer(self): - return self._productManufacturer - - @property - def productName(self): - return self._productName - - @property - def productPartModelName(self): - return self._productPartModelName - - @property - def productSerialNumber(self): - return self._productSerialNumber - - @property - def productAssetTag(self): - return self._productAssetTag - - @property - def fruFileId(self): - return self._FRUFileID - - @property - def productExtra1(self): - return self._productExtra1 - - @property - def productExtra2(self): - return self._productExtra2 - - @property - def productExtra3(self): - return self._productExtra3 - - def recalcute(self): - d_print("product version:%x" % ord(self.areaversion)) - d_print("product length:%d" % self.size) - d_print("product language:%x" % self.language) - self.data = chr(ord(self.areaversion)) + \ - chr(self.size / 8) + chr(self.language) - - typelength = E2Util.getTypeLength(self.productManufacturer) - self.data += chr(typelength) - self.data += self.productManufacturer - - self.data += chr(E2Util.getTypeLength(self.productName)) - self.data += self.productName - - self.data += chr(E2Util.getTypeLength(self.productPartModelName)) - self.data += self.productPartModelName - - self.data += chr(E2Util.getTypeLength(self.productVersion)) - self.data += self.productVersion - - self.data += chr(E2Util.getTypeLength(self.productSerialNumber)) - self.data += self.productSerialNumber - - self.data += chr(E2Util.getTypeLength(self.productAssetTag)) - if self.productAssetTag != None: - self.data += self.productAssetTag - - self.data += chr(E2Util.getTypeLength(self.fruFileId)) - if self.fruFileId != None: - self.data += self.fruFileId - - if self.productExtra1 != None: - self.data += chr(E2Util.getTypeLength(self.productExtra1)) - self.data += self.productExtra1 - - if self.productExtra2 != None: - self.data += chr(E2Util.getTypeLength(self.productExtra2)) - self.data += self.productExtra2 - - if self.productExtra3 != None: - self.data += chr(E2Util.getTypeLength(self.productExtra3)) - self.data += self.productExtra3 - - self.data += chr(0xc1) - if len(self.data) > (self.size - 1): - incr = (len(self.data) - self.size) / 8 + 1 - self.size += incr * 8 - d_print("self.data:%d" % len(self.data)) - d_print("self.size:%d" % self.size) - for tianchong in range(self.size - len(self.data) - 1): - self.data += self.INITVALUE - test = 0 - for index in range(len(self.data)): - test += ord(self.data[index]) - checksum = (0x100 - (test % 256)) if (test % 256) != 0 else 0 - d_print("board info checksum:%x" % checksum) - self.data += chr(checksum) - - -class MultiRecordArea(BaseArea): - pass - - -class Field(): - - def __init__(self, fieldType="ASCII", fieldData=""): - self.fieldData = fieldData - self.fieldType = fieldType - - @property - def data(self): - return self._data - - @property - def fieldType(self): - return self._fieldType - - @property - def fieldData(self): - return self._fieldData - - -class CommonArea(BaseArea): - _internalUserAreaOffset = None - _InternalUseArea = None - _ChassisInfoArea = None - _multiRecordArea = None - _chassicInfoAreaOffset = None - _multiRecordAreaOffset = None - - def decodeBin(self, eeprom): - commonHead = eeprom[0:8] - d_print("decode version %x" % ord(commonHead[0])) - if self.COMMON_HEAD_VERSION != commonHead[0]: - print ("not equal") - if E2Util.checksum(commonHead[0:7]) != ord(commonHead[7]): - print ("check sum error") - sys.exit(-1) - if commonHead[1] != self.INITVALUE: - d_print("Internal Use Area is present") - self.internalUseArea = InternalUseArea( - name="Internal Use Area", size=self.SUGGESTED_SIZE_INTERNAL_USE_AREA) - self.internalUseArea.isPresent = True - self.internalUserAreaOffset = ord(commonHead[1]) - self.internalUseArea.data = eeprom[self.internalUserAreaOffset * 8: ( - self.internalUserAreaOffset * 8 + self.internalUseArea.size)] - if commonHead[2] != self.INITVALUE: - d_print("Chassis Info Area is present") - self.chassisInfoArea = ChassisInfoArea( - name="Chassis Info Area", size=self.SUGGESTED_SIZE_CHASSIS_INFO_AREA) - self.chassisInfoArea.isPresent = True - self.chassicInfoAreaOffset = ord(commonHead[2]) - self.chassisInfoArea.data = eeprom[self.chassicInfoAreaOffset * 8: ( - self.chassicInfoAreaOffset * 8 + self.chassisInfoArea.size)] - if commonHead[3] != self.INITVALUE: - self.boardInfoArea = BoardInfoArea( - name="Board Info Area", size=self.SUGGESTED_SIZE_BOARD_INFO_AREA) - self.boardInfoArea.isPresent = True - self.boardInfoAreaOffset = ord(commonHead[3]) - self.boardInfoArea.size = ord( - eeprom[self.boardInfoAreaOffset * 8 + 1]) * 8 - d_print("Board Info Area is present size:%d" % - (self.boardInfoArea.size)) - self.boardInfoArea.data = eeprom[self.boardInfoAreaOffset * 8: ( - self.boardInfoAreaOffset * 8 + self.boardInfoArea.size)] - if E2Util.checksum(self.boardInfoArea.data[:-1]) != ord(self.boardInfoArea.data[-1:]): - print ("check boardInfoArea checksum error[cal:%02x data:%02x]" % (E2Util.checksum(self.boardInfoArea.data[:-1]), ord(self.boardInfoArea.data[-1:]))) - sys.exit(-1) - self.boardInfoArea.decodedata() - if commonHead[4] != self.INITVALUE: - d_print("Product Info Area is present") - self.productInfoArea = ProductInfoArea( - name="Product Info Area ", size=self.SUGGESTED_SIZE_PRODUCT_INFO_AREA) - self.productInfoArea.isPresent = True - self.productinfoAreaOffset = ord(commonHead[4]) - - self.productInfoArea.size = ord( - eeprom[self.productinfoAreaOffset * 8 + 1]) * 8 - d_print("Product Info Area is present size:%d" % - (self.productInfoArea.size)) - - self.productInfoArea.data = eeprom[self.productinfoAreaOffset * 8: ( - self.productinfoAreaOffset * 8 + self.productInfoArea.size)] - if E2Util.checksum(self.productInfoArea.data[:-1]) != ord(self.productInfoArea.data[-1:]): - print ("check productInfoArea checksum error [cal:%02x data:%02x]" % (E2Util.checksum(self.productInfoArea.data[:-1]), ord(self.productInfoArea.data[-1:]))) - sys.exit(-1) - self.productInfoArea.decodedata() - if commonHead[5] != self.INITVALUE: - self.multiRecordArea = MultiRecordArea( - name="MultiRecord record Area ") - d_print("MultiRecord record present") - self.multiRecordArea.isPresent = True - self.multiRecordAreaOffset = ord(commonHead[5]) - self.multiRecordArea.data = eeprom[self.multiRecordAreaOffset * 8: ( - self.multiRecordAreaOffset * 8 + self.multiRecordArea.size)] - # self.recalcute() - - def initDefault(self): - self.version = self.COMMON_HEAD_VERSION - self.internalUserAreaOffset = self.INITVALUE - self.chassicInfoAreaOffset = self.INITVALUE - self.boardInfoAreaOffset = self.INITVALUE - self.productinfoAreaOffset = self.INITVALUE - self.multiRecordAreaOffset = self.INITVALUE - self.PAD = self.INITVALUE - self.zeroCheckSum = self.INITVALUE - self.offset = self.SUGGESTED_SIZE_COMMON_HEADER - self.productInfoArea = None - self.internalUseArea = None - self.boardInfoArea = None - self.chassisInfoArea = None - self.multiRecordArea = None - self.recalcute() - - @property - def version(self): - return self._version - - @property - def internalUserAreaOffset(self): - return self._internalUserAreaOffset - - @property - def chassicInfoAreaOffset(self): - return self._chassicInfoAreaOffset - - @property - def productinfoAreaOffset(self): - return self._productinfoAreaOffset - - @property - def boardInfoAreaOffset(self): - return self._boardInfoAreaOffset - - @property - def multiRecordAreaOffset(self): - return self._multiRecordAreaOffset - - @property - def PAD(self): - return self._PAD - - @property - def zeroCheckSum(self): - return self._zeroCheckSum - - @property - def productInfoArea(self): - return self._ProductInfoArea - - @property - def internalUseArea(self): - return self._InternalUseArea - - @property - def boardInfoArea(self): - return self._BoardInfoArea - - @property - def chassisInfoArea(self): - return self._ChassisInfoArea - - @property - def multiRecordArea(self): - return self._multiRecordArea - - @property - def bindata(self): - return self._bindata - - def recalcuteCommonHead(self): - self.offset = self.SUGGESTED_SIZE_COMMON_HEADER - d_print("common Header %d" % self.offset) - if self.internalUseArea != None and self.internalUseArea.isPresent: - self.internalUserAreaOffset = self.offset / 8 - self.offset += self.internalUseArea.size - d_print("internalUseArea is present offset:%d" % self.offset) - if self.chassisInfoArea != None and self.chassisInfoArea.isPresent: - self.chassicInfoAreaOffset = self.offset / 8 - self.offset += self.chassisInfoArea.size - d_print("chassisInfoArea is present offset:%d" % self.offset) - if self.boardInfoArea != None and self.boardInfoArea.isPresent: - self.boardInfoAreaOffset = self.offset / 8 - self.offset += self.boardInfoArea.size - d_print("boardInfoArea is present offset:%d" % self.offset) - - if self.productInfoArea != None and self.productInfoArea.isPresent: - self.productinfoAreaOffset = self.offset / 8 - self.offset += self.productInfoArea.size - d_print("productInfoArea is present offset:%d" % self.offset) - if self.multiRecordArea != None and self.multiRecordArea.isPresent: - self.multiRecordAreaOffset = self.offset / 8 - d_print("multiRecordArea is present offset:%d" % self.offset) - - if self.internalUserAreaOffset == self.INITVALUE: - self.internalUserAreaOffset = 0 - if self.productinfoAreaOffset == self.INITVALUE: - self.productinfoAreaOffset = 0 - if self.chassicInfoAreaOffset == self.INITVALUE: - self.chassicInfoAreaOffset = 0 - if self.boardInfoAreaOffset == self.INITVALUE: - self.boardInfoAreaOffset = 0 - if self.multiRecordAreaOffset == self.INITVALUE: - self.multiRecordAreaOffset = 0 - self.zeroCheckSum = (0x100 - ord(self.version) - self.internalUserAreaOffset - self.chassicInfoAreaOffset - self.productinfoAreaOffset \ - - self.boardInfoAreaOffset - self.multiRecordAreaOffset)&0xff - d_print("zerochecksum:%x" % self.zeroCheckSum) - self.data = self.version + chr(self.internalUserAreaOffset) + chr(self.chassicInfoAreaOffset) + chr( - self.boardInfoAreaOffset) + chr(self.productinfoAreaOffset) + chr(self.multiRecordAreaOffset) + self.PAD + chr(self.zeroCheckSum) - - def recalcutebin(self): - self.bindata = "" - self.bindata += self.data - if self.internalUseArea != None and self.internalUseArea.isPresent: - d_print("internalUseArea is present") - self.bindata += self.internalUseArea.data - if self.chassisInfoArea != None and self.chassisInfoArea.isPresent: - d_print("chassisInfoArea is present") - self.bindata += self.chassisInfoArea.data - if self.boardInfoArea != None and self.boardInfoArea.isPresent: - d_print("boardInfoArea is present") - self.boardInfoArea.recalcute() - self.bindata += self.boardInfoArea.data - if self.productInfoArea != None and self.productInfoArea.isPresent: - d_print("productInfoArea is present") - self.productInfoArea.recalcute() - self.bindata += self.productInfoArea.data - if self.multiRecordArea != None and self.multiRecordArea.isPresent: - d_print("multiRecordArea is present") - self.bindata += self.productInfoArea.data - totallen = len(self.bindata) - if (totallen < 256): - for left_t in range(0, 256 - totallen): - self.bindata += chr(0x00) - - def recalcute(self): - self.recalcuteCommonHead() - self.recalcutebin() - - -class E2Util(): - - BOARDINFOAREAISPRESETN = 'boardinfoarea.ispresent' - BOARDINFOAREABOARDMANUFACTURER = 'boardinfoarea.boardmanufacturer' - BOARDINFOAREABORADPRODUCTNAME = 'boardinfoarea.boradproductname' - BOARDINFOAREABOARDSERIALNUMBER = 'boardinfoarea.boardserialnumber' - BOARDINFOAREABOARDPARTNUMBER = 'boardinfoarea.boardpartnumber' - BOARDINFOAREAFRUFILEID = 'boardinfoarea.frufileid' - BOARDINFOAREAFEXTRA1 = 'boardinfoarea.boardextra1' - - PRODUCTINFOAREAISPRESENT = "productInfoArea.ispresent" - PRODUCTINFOAREAPRODUCTMANUFACTURER = 'productinfoarea.productmanufacturer' - PRODUCTINFOAREAPRODUCTNAME = 'productinfoarea.productname' - PRODUCTINFOAREAPRODUCTPARTMODELNAME = 'productinfoarea.productpartmodelname' - PRODUCTINFOAREAPRODUCTVERSION = 'productinfoarea.productversion' - PRODUCTINFOAREAPRODUCTSERIALNUMBER = 'productinfoarea.productserialnumber' - PRODUCTINFOAREAPRODUCTASSETTAG = 'productinfoarea.productassettag' - PRODUCTINFOAREAFRUFILEID = 'productinfoarea.frufileid' - PRODUCTINFOAREAEXTRA1 = 'productinfoarea.productextra1' - PRODUCTINFOAREAEXTRA2 = 'productinfoarea.productextra2' - PRODUCTINFOAREAEXTRA3 = 'productinfoarea.productextra3' - - @staticmethod - def equals(x, typeV): - if x.strip()[-1] == typeV: - return True - else: - return False - - @staticmethod - def decodeBinByValue(retval): - fru = CommonArea() - fru.initDefault() - fru.decodeBin(retval) - return fru - - @staticmethod - def getBoardInfoAreaByProperty(prop): - boardinfoarea = None - try: - boradispresent = prop[E2Util.BOARDINFOAREAISPRESETN] - if (boradispresent == "1"): - boardinfoarea = BoardInfoArea(name="Board Info Area", - size=0) - boardinfoarea.isPresent = True - boardinfoarea.boardManufacturer = prop[E2Util.BOARDINFOAREABOARDMANUFACTURER] - boardinfoarea.boardProductName = prop[E2Util.BOARDINFOAREABORADPRODUCTNAME] - boardinfoarea.boardSerialNumber = prop[E2Util.BOARDINFOAREABOARDSERIALNUMBER] - boardinfoarea.boardPartNumber = prop[E2Util.BOARDINFOAREABOARDPARTNUMBER] - boardinfoarea.fruFileId = prop[E2Util.BOARDINFOAREAFRUFILEID] - boardinfoarea.boardextra1 = prop[E2Util.BOARDINFOAREAFEXTRA1] - boardinfoarea.recalcute() - else: - boardinfoarea = None - return boardinfoarea - except Exception as e: - raise e - return None - - @staticmethod - def getProductInfoAreaByProperty(prop): - productInfoArea = None - try: - productispresent = prop[E2Util.PRODUCTINFOAREAISPRESENT] - if (productispresent == "1"): - productInfoArea = ProductInfoArea(name="Product Info Area ", - size=0) - productInfoArea.isPresent = True - - productInfoArea.productManufacturer = prop[E2Util.PRODUCTINFOAREAPRODUCTMANUFACTURER] - productInfoArea.productName = prop[E2Util.PRODUCTINFOAREAPRODUCTNAME] - productInfoArea.productPartModelName = prop[E2Util.PRODUCTINFOAREAPRODUCTPARTMODELNAME] - productInfoArea.productVersion = prop[E2Util.PRODUCTINFOAREAPRODUCTVERSION] - productInfoArea.productSerialNumber = prop[E2Util.PRODUCTINFOAREAPRODUCTSERIALNUMBER] - # productInfoArea.fruFileId = prop[E2Util.PRODUCTINFOAREAFRUFILEID] - val_t = E2Util.getTimeFormat() - if val_t != None: - productInfoArea.productExtra1 = val_t - if prop.__contains__(E2Util.PRODUCTINFOAREAEXTRA2): - # Extra2 Special Processing (MAC address) - macaddr = prop[E2Util.PRODUCTINFOAREAEXTRA2] - if macaddr != None: - productInfoArea.productExtra2 = E2Util.encodeMac( - macaddr) - if prop.__contains__(E2Util.PRODUCTINFOAREAEXTRA3): - # Extra3 Special Processing - productInfoArea.productExtra3 = E2Util.encodeMacLen( - prop[E2Util.PRODUCTINFOAREAEXTRA3]) - productInfoArea.recalcute() - else: - productInfoArea = None - - except Exception as e: - print ("error") - productInfoArea = None - return productInfoArea - - @staticmethod - def generateBinBySetMac(bia, pia): - fru = CommonArea() - fru.initDefault() - if bia != None: - fru.boardInfoArea = bia - if pia != None: - fru.productInfoArea = pia - fru.recalcute() - return fru - - @staticmethod - def generateBinByInput(prop): - bia = E2Util.getBoardInfoAreaByProperty(prop) - pia = E2Util.getProductInfoAreaByProperty(prop) - fru = CommonArea() - fru.initDefault() - if bia != None: - fru.boardInfoArea = bia - if pia != None: - fru.productInfoArea = pia - fru.recalcute() - return fru - - @staticmethod - def defaultBinByConfig(product, typeVal): - filename = CONFIG_FILE - dir = os.path.dirname(os.path.realpath(__file__)) - if filename in os.listdir(dir): - filename = os.path.join(dir, filename) - return E2Util.generateBinByConfig(filename, product, typeVal) - - @staticmethod - def generateBinByConfig(filename, product, typeVal): - fileconf = E2Util.getConfig(filename) - if product not in fileconf.ProductsTypes: - raise E2Exception("product type not in Success") - productParts = fileconf.getProductSections(product) - if len(productParts) <= 0: - raise E2Exception("config file has no product config") - # print typeVal - ret_t = filter(lambda x: E2Util.equals(x, typeVal), productParts) - if len(ret_t) <= 0: - raise E2Exception("config file has no child eeprom config") - # print "".join(ret_t) - bia = E2Util.getBoardInfoAreaConfigFile(fileconf, "".join(ret_t)) - pia = E2Util.getProductInfoAreaConfigFile(fileconf, "".join(ret_t)) - - fru = CommonArea() - fru.initDefault() - - if bia != None: - fru.boardInfoArea = bia - if pia != None: - fru.productInfoArea = pia - fru.recalcute() - return fru - - @staticmethod - def getProductInfoAreaConfigFile(conf, part): - pia = None - try: - productispresent = conf.getProductName( - E2Util.PRODUCTINFOAREAISPRESENT, part) - if (productispresent == "1"): - pia = ProductInfoArea(name="Product Info Area ", - size=0) - pia.isPresent = True - - pia.productManufacturer = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTMANUFACTURER, part) - pia.productName = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTNAME, part) - pia.productPartModelName = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTPARTMODELNAME, part) - pia.productVersion = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTVERSION, part) - pia.productSerialNumber = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTSERIALNUMBER, part) - pia.productAssetTag = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTASSETTAG, part) - # print pia.productAssetTag - pia.fruFileId = conf.getProductName( - E2Util.PRODUCTINFOAREAFRUFILEID, part) - val_t = E2Util.getTimeFormat() - if val_t != None: - pia.productExtra1 = val_t - # Extra2 Special Processing (MAC address) - macaddr = conf.getProductName( - E2Util.PRODUCTINFOAREAEXTRA2, part) - if macaddr != None: - pia.productExtra2 = E2Util.encodeMac(macaddr) - # Extra3 Special Processing - pia.productExtra3 = E2Util.encodeMacLen(conf.getProductName( - E2Util.PRODUCTINFOAREAEXTRA3, part)) - pia.recalcute() - else: - pia = None - - except Exception as e: - print (e) - pia = None - return pia - - @staticmethod - def getBoardInfoAreaConfigFile(conf, part): - boardinfoarea = None - try: - boradispresent = conf.getProductName( - E2Util.BOARDINFOAREAISPRESETN, part) - if (boradispresent == "1"): - boardinfoarea = BoardInfoArea(name="Board Info Area", - size=0) - boardinfoarea.isPresent = True - boardinfoarea.boardManufacturer = conf.getProductName( - E2Util.BOARDINFOAREABOARDMANUFACTURER, part) - boardinfoarea.boardProductName = conf.getProductName( - E2Util.BOARDINFOAREABORADPRODUCTNAME, part) - boardinfoarea.boardSerialNumber = conf.getProductName( - E2Util.BOARDINFOAREABOARDSERIALNUMBER, part) - boardinfoarea.boardPartNumber = conf.getProductName( - E2Util.BOARDINFOAREABOARDPARTNUMBER, part) - boardinfoarea.fruFileId = conf.getProductName( - E2Util.BOARDINFOAREAFRUFILEID, part) - boardinfoarea.boardextra1 = conf.getProductName( - E2Util.BOARDINFOAREAFEXTRA1, part) - boardinfoarea.recalcute() - else: - boardinfoarea = None - except Exception as e: - print (e) - boardinfoarea = None - return boardinfoarea - - @staticmethod - def decodeBinName(filename): - retval = None - try: - with open(filename, 'rb') as fd: - retval = fd.read() - except Exception: - print ("open file error") - return None - return E2Util.decodeBinByValue(retval) - - - @staticmethod - def decodeMac(encodedata): - if encodedata == None: - return None - ret = "" - for i in range(len(encodedata)): - ret += "%02x" % ord(encodedata[i]) - return ret.upper() - - @staticmethod - def strtoint(strtmp): - value = 0 - rest_v = strtmp.replace("0X", "").replace("0x", "") - for index in range(len(rest_v)): - value |= int(rest_v[index], 16) << ((len(rest_v) - index - 1) * 4) - return value - - @staticmethod - def decodeMacLen(lenstr): - if lenstr == None: - return None - maclen = ord(lenstr[0]) << 8 | ord(lenstr[1]) - return maclen - - @staticmethod - def encodeMac(macaddr): - ret_t = "" - if len(macaddr) != 12: - return None - for i in range(6): - tt = macaddr[2 * i: 2 * i + 2] - ret_t += chr(int(tt, 16)) - return ret_t - - @staticmethod - def encodeMacLen(strlem): - val_t = int(strlem) - temp_t = chr(val_t >> 8) + chr(val_t & 0x00ff) - return temp_t - - @staticmethod - def loadconfig(): - global conf - conf = E2Config() - return conf - - @staticmethod - def getConfig(filename): - return E2Config(filename) - - - @staticmethod - def getdefaultconfig(): - filename = CONFIG_FILE - dir = os.path.dirname(os.path.realpath(__file__)) - if filename in os.listdir(dir): - filename = os.path.join(dir, filename) - config = E2Util.getConfig(filename) - ret = {} - for i in config.ProductsTypes: - ret[config.getProductName(i)] = i - return ret - - @staticmethod - def createFruBin(filename, boardinfoarea, productInfoArea): - fru = CommonArea() - fru.initDefault() - - if boardinfoarea != None: - fru.boardInfoArea = boardinfoarea - if productInfoArea != None: - fru.productInfoArea = productInfoArea - - fru.recalcute() - E2Util.write_bin_file(filename, fru.bindata) - - @staticmethod - def createpartbin(part): - try: - bia = None - pia = None - - boradispresent = conf.getProductName( - E2Util.BOARDINFOAREAISPRESETN, part) - if (boradispresent == "1"): - bia = BoardInfoArea(name="Board Info Area", - size=0) - bia.isPresent = True - bia.boardManufacturer = conf.getProductName( - E2Util.BOARDINFOAREABOARDMANUFACTURER, part) - bia.boardProductName = conf.getProductName( - E2Util.BOARDINFOAREABORADPRODUCTNAME, part) - bia.boardSerialNumber = conf.getProductName( - E2Util.BOARDINFOAREABOARDSERIALNUMBER, part) - bia.boardPartNumber = conf.getProductName( - E2Util.BOARDINFOAREABOARDPARTNUMBER, part) - bia.fruFileId = conf.getProductName( - E2Util.BOARDINFOAREAFRUFILEID, part) - bia.boardextra1 = conf.getProductName( - E2Util.BOARDINFOAREAFEXTRA1, part) - bia.recalcute() - - productispresent = conf.getProductName( - E2Util.PRODUCTINFOAREAISPRESENT, part) - if (productispresent == "1"): - pia = ProductInfoArea(name="Product Info Area ", - size=0) - pia.isPresent = True - - pia.productManufacturer = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTMANUFACTURER, part) - pia.productName = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTNAME, part) - pia.productPartModelName = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTPARTMODELNAME, part) - pia.productVersion = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTVERSION, part) - pia.productSerialNumber = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTSERIALNUMBER, part) - pia.productAssetTag = conf.getProductName( - E2Util.PRODUCTINFOAREAPRODUCTASSETTAG, part) - pia.fruFileId = conf.getProductName( - E2Util.PRODUCTINFOAREAFRUFILEID, part) - val_t = E2Util.getTimeFormat() - if val_t != None: - pia.productExtra1 = val_t - # Extra2 Special Processing (MAC address - macaddr = conf.getProductName( - E2Util.PRODUCTINFOAREAEXTRA2, part) - if macaddr != None: - pia.productExtra2 = E2Util.encodeMac(macaddr) - # Extra3 Special Processing - pia.productExtra3 = E2Util.encodeMacLen(conf.getProductName( - E2Util.PRODUCTINFOAREAEXTRA3, part)) - pia.recalcute() - - filename = conf.getPartBinName(part) - print ("filename", filename) - E2Util.createFruBin(filename, bia, pia) - except Exception as e: - print (e) - - @staticmethod - def checksum(b): - result = 0 - for i in range(len(b)): - result += ord(b[i]) - return (0x100 - (result % 256)) if (result % 256) != 0 else 0 - - @staticmethod - def decodeLength(value): - a = bitarray(8) - a.setall(True) - a[0:1] = 0 - a[1:2] = 0 - x = ord(a.tobytes()) - return x & ord(value) - - @staticmethod - def getTypeLength(value): - if value == None: - return 0 - a = bitarray(8) - a.setall(False) - a[0:1] = 1 - a[1:2] = 1 - x = ord(a.tobytes()) - return x | len(value) - - @staticmethod - def minToData(): - starttime = datetime(1996, 1, 1, 0, 0, 0) - endtime = datetime.now() - seconds = (endtime - starttime).total_seconds() - mins = seconds / 60 - m = int(round(mins)) - return m - - @staticmethod - def mfgToTime(val): - starttime = datetime(1996, 1, 1, 0, 0, 0) - - - @staticmethod - def getTimeFormat(): - return datetime.now().strftime('%Y-%m-%d') - - @staticmethod - def printbinvalue(b): - index = 0 - print (" ",) - for width in range(16): - print ("%02x " % width,) - print ("") - for i in range(0, len(b)): - if index % 16 == 0: - print (" ") - print (" %02x " % i,) - print ("%02x " % ord(b[i]),) - index += 1 - print ("") - - @staticmethod - def write_bin_file(filename, _value): - retname = "test/" + filename - with open(retname, 'wb') as filep: - for x in _value: - filep.write(str(x)) - filep.close() - - @staticmethod - def getRemoteConfig(url): - res = requests.get(url) - print (res.content) - f = open('bin.conf', 'w') - f.write(res.content) - f.close() - return res.text - - -class E2Config(): - _CONFIG_PRODUCT_SECTON = "products" - _CONFIG_TYPENAME_SECTON = "typename" - - def __init__(self, filename=CONFIG_FILE): - cf = ConfigParser.ConfigParser() - cf.read(filename) - if os.path.exists(filename) != True: - raise E2Exception("init E2Config error") - self.configparse = cf - self.Sections = cf.sections() - self.ProductsTypes = cf.options(self._CONFIG_PRODUCT_SECTON) - - def getProductPartItem(self, section): - return self.configparse.options(section) - - def getPartBinName(self, part): - part = part.rstrip() - fileprename = self.getProductName( - part[-1:], self._CONFIG_TYPENAME_SECTON) - return (part + "_" + fileprename + ".bin").lower().replace("-", "_") - - def getProductName(self, name, section=_CONFIG_PRODUCT_SECTON): - try: - return self.configparse.get(section, name) - except Exception: - return None - - def loadFile(self): - pass - - def getProductSections(self, typeindex): - typename = self.getProductName(typeindex) - return filter(lambda x: typename in x, self.Sections) - - @property - def ProductsTypes(self): - return self._productTypes - - @property - def Sections(self): - return self._sections - - @property - def configparse(self): - return self._configparse - - -def main(arg): - '''create bin''' - E2Util.loadconfig() - if len(arg) < 1: - usage() - sys.exit(1) - producttype = arg[0] - d_print(producttype) - if producttype not in conf.ProductsTypes: - usage() - sys.exit(1) - - productParts = conf.getProductSections(producttype) - print ("productParts", productParts) - print ("prudct name: %s" % conf.getProductName(producttype)) - if len(productParts) <= 0: - print ("product config not found") - for part in productParts: - print (" generate file: %s" % conf.getPartBinName(part)) - E2Util.createpartbin(part) - - -def usage(): - print("Usage: [e2.py product ]") - print(" example: e2.py 1 ") - print(" userless-product :") - for card in conf.ProductsTypes: - print (" %s %s" % (card, conf.getProductName(card))) - - -if __name__ == '__main__': - # main(sys.argv[1:]) - main(["1"]) - main(["2"]) - main(["3"]) - main(["4"]) - main(["5"]) - main(["6"]) diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/fruutil/product.conf b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/fruutil/product.conf deleted file mode 100644 index 3028246e1d..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/fruutil/product.conf +++ /dev/null @@ -1,67 +0,0 @@ -[products] -6 = BMCEEPROM -17 = CPUM-C7EDN6-U2 -26 = EMMC-CARD -33 = RA-B6010-48GT4X -# 1 TLV EEPROM 0x56 -# 2 X86 CPU EEPROM -# 3 BMC EEPROM -# 4 CPU BASE_BOARD EEPROM 0x57 -# 5 MAC BOARD EEPROM -# 6.Line card EEPROM (128) -# 7.Fan adapter EEPROM -# 8.Fan the small plate EEPROM -# 9.PSU FRU EEPROM -[typename] -1= tlveeprom -2= x86cpueeprom -3= bmceeprom -4= cpueeprom -5= maceeprom -6= sloteeprom -7= fanconnecteeprom -8= M1HFANI-F -9= M1HFANI-R -A= M2HFANI-F -B= M2HFANI-R -C= psu -M = RA-EMMC-CARD -Q = ibvbeeprom - -[BMCEEPROM-3] -boardinfoarea.ispresent = 1 -boardinfoarea.boardManufacturer = Ragile -boardinfoarea.boradProductName = BMC -boardinfoarea.boardSerialNumber = 0000000000000 -boardinfoarea.boardPartNumber = BMC -boardinfoarea.FRUFileID = 6-3 -boardinfoarea.boardextra1 = AA - -[RA-B6010-48GT4X-4] -productInfoArea.ispresent = 1 -productInfoArea.productManufacturer = Ragile -productInfoArea.productName = RA-B6010-48GT4X -productInfoArea.productPartModelName = RA-B6010-48GT4X -productInfoArea.productVersion = 00 -productInfoArea.productSerialNumber = 0000000000000 -productInfoArea.FRUFileID = 33-4 -productInfoArea.productExtra1 = 2020-12-20 -productInfoArea.productExtra2 = 1a2b3c4d5e6f -productInfoArea.productExtra3 = 2 - -boardinfoarea.ispresent = 1 -boardinfoarea.boardManufacturer = Ragile -boardinfoarea.boradProductName = RA-B6010-48GT4X -boardinfoarea.boardSerialNumber = 0000000000000 -boardinfoarea.boardPartNumber = RA-B6010-48GT4X -boardinfoarea.FRUFileID = 33-4 -boardinfoarea.boardextra1 = AA - -[EMMC-CARD-M] -boardinfoarea.ispresent = 1 -boardinfoarea.boardManufacturer = Ragile -boardinfoarea.boradProductName = EMMC-CARD -boardinfoarea.boardSerialNumber = 0000000000000 -boardinfoarea.boardPartNumber = RA-EMMC-CARD -boardinfoarea.FRUFileID = 26-M -boardinfoarea.boardextra1 = AA \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/logutil/__init__.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/logutil/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/logutil/logutil.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/logutil/logutil.py deleted file mode 100644 index 0d9f6ff94c..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/logutil/logutil.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- -import os -import syslog -import logging -import subprocess -import shlex - -SYSLOG_IDENTIFIER = "LOGUTIL" - -# ========================== Syslog wrappers ========================== - -def log_info(msg,log_type=SYSLOG_IDENTIFIER, also_print_to_console=False): - syslog.openlog(log_type) - syslog.syslog(syslog.LOG_INFO, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - - -def log_debug(msg, log_type=SYSLOG_IDENTIFIER, also_print_to_console=False): - try: - syslog.openlog(log_type) - syslog.syslog(syslog.LOG_DEBUG, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - except Exception as e: - print(str(e)) - - -def log_warning(msg, log_type=SYSLOG_IDENTIFIER, also_print_to_console=False): - syslog.openlog(log_type) - syslog.syslog(syslog.LOG_WARNING, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - -def log_error(msg, log_type=SYSLOG_IDENTIFIER, also_print_to_console=False): - syslog.openlog(log_type) - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - -restful_logger_path = "/var/log/bmc_restful.log" -def bmc_restful_logger(message): - if not os.path.isfile(restful_logger_path): - cmd = "sudo touch %s && sudo chmod +x %s" % ( - restful_logger_path, restful_logger_path) - subprocess.Popen( - shlex.split(cmd), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - logging.basicConfig(filename=restful_logger_path, - filemode='a', - format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', - datefmt='%H:%M:%S', - level=logging.INFO) - - logging.info(message) diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/redfishutil/redfish_api.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/redfishutil/redfish_api.py deleted file mode 100644 index 25ba521733..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/redfishutil/redfish_api.py +++ /dev/null @@ -1,304 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -import shlex -import datetime -import os -import ssl -import subprocess -import syslog - -class Redfish_Api(): - BmcBaseUrl = 'http://240.1.1.1:8080' - ThermalUrl = '/redfish/v1/Chassis/1/Thermal' - PowerUrl = '/redfish/v1/Chassis/1/Power' - ThresholdSensorsUrl = '/redfish/v1/Chassis/1/ThresholdSensors' - FanSpeedUrl = '/redfish/v1/Chassis/1/Thermal/Actions/Oem/Ragile/Fan.SetSpeed' - BoardsUrl = '/redfish/v1/Chassis/1/Boards/' - BoardLedUrl = "/redfish/v1/Chassis/1/Boards/{}/Actions/Oem/Ragile/Boards.SetLED" - - # Maximum time in seconds that you allow the connection to the server to take. - connect_timeout = 30 - # Maximum time in seconds that you allow the whole operation to take - operation_timeout = 300 - - default_prefix='/redfish/v1/' - session = None - __DEBUG__ = "N" - __DUMP_RESP__ = "N" - RST_STATUS = "status" - RST_SUCCESS = "OK" - refish_logger = None - - def redfish_log_debug(self, msg): - if (self.__DEBUG__ == "Y"): - syslog.openlog("redfis_api") - syslog.syslog(syslog.LOG_DEBUG, msg) - syslog.closelog() - - def redfish_log_error(self, msg): - syslog.openlog("redfish_api") - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - def __init__(self): - pass - - def get_full_url(self, url): - return self.BmcBaseUrl + url - - def _exec_cmd(self, cmd): - self.redfish_log_debug("Cmd: %s" % cmd) - p = subprocess.Popen(shlex.split(cmd), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - p.wait() - self.redfish_log_debug("Cmd return: %d" % p.returncode) - str_stdout = p.stdout.read().decode('utf-8') - str_stderr = p.stderr.read().decode('utf-8') - self.redfish_log_debug("Cmd stdout: %s" % str_stdout) - if p.returncode !=0: - self.redfish_log_error("Cmd: %s, failed! error msg:%s" % (cmd, str_stderr)) - return None - else: - try: - ret = json.loads(str_stdout) - return ret - except Exception as e: - self.redfish_log_error("Cmd: %s, failed! stdout msg:%s" % (cmd, str_stdout)) - return None - - def _redfish_get(self, url): - self.redfish_log_debug("Get info from %s." % url) - result = None - try: - cmd_get="curl --connect-timeout %d -m %d -X GET %s" % (self.connect_timeout, self.operation_timeout, self.get_full_url(url)) - result = self._exec_cmd(cmd_get) - return result - except Exception as e: - self.redfish_log_error("error_message: %s" % e) - return None - - def _redfish_post(self, url, playload): - self.redfish_log_debug("post url: %s" % url) - self.redfish_log_debug("Playload: %s" % playload) - - playload_json = json.dumps(playload) - result = False - try: - cmd_post="curl --connect-timeout %d -m %d -X POST %s -d \'%s\'" % (self.connect_timeout, self.operation_timeout, self.get_full_url(url), playload_json) - ret_msg = self._exec_cmd(cmd_post) - if ret_msg == None: - return False - elif ret_msg["success"] == False: - redfish_log_error("Url: '%s', Playload: '%s', Bmc return failed, error_message: %s" % (url, playload_json, ret_msg["Message"])) - result = False - else: - result = True - return result - except Exception as e: - redfish_log_error("error_message: %s" % e) - return False - - def get_thermal(self): - """Get thermal info - :returns: class 'redfish.rest.v1.RestResponse' or None when failed - """ - return self._redfish_get(self.ThermalUrl) - - def get_power(self): - """Get power info - :returns: class 'redfish.rest.v1.RestResponse' or None when failed - """ - return self._redfish_get(self.PowerUrl) - - def get_thresholdSensors(self): - """Get thresholdSensors info - :returns: class 'redfish.rest.v1.RestResponse' or None when failed - """ - return self._redfish_get(self.ThresholdSensorsUrl) - - def post_odata(self, odata_id, playload): - """post odata info - :params odata_id: the specified odata_id path - :type odata_id: string - :playload: info to post - :type: dictionary - :returns: True or False - """ - if odata_id is None or playload is None: - print("post failed: odata_id or playload is None") - return False - return self._redfish_post(odata_id, playload) - - def get_odata(self, odata_id): - """Get odata info - :params odata_id: the specified odata_id path - :type odata_id: string - :returns: class 'redfish.rest.v1.RestResponse' or None when failed - """ - if odata_id is None: - print("Get odata_id failed: odata_id is None") - return None - return self._redfish_get(odata_id) - - def post_fanSpeed(self, playload): - """post odata info - :playload: info to post - :type: dictionary - :returns: True or False - """ - if playload is None: - print("post failed: playload is None") - return False - return self._redfish_post(self.FanSpeedUrl, playload) - - def get_board(self, board_name="indicatorboard"): - """Get board info - :board_name: name of board, default is "indicatorboard" - :type: string - :returns: class'redfish.rest.v1.RestResponse' or None when failed - """ - if board_name is None : - print("get failed: board_name is None") - return None - return self._redfish_get(self.BoardsUrl + board_name) - - def post_boardLed(self, playload, board_name="indicatorboard"): - """post boardLed info - :board_name: name of board, default is "indicatorboard" - :type: string - :playload: info to post - :type: dictionary - :returns: True or False - """ - if board_name is None or playload is None: - print("post failed: playload is None") - return False - return self._redfish_post(self.BoardLedUrl.format(board_name), playload) - - ''' not supported currently - def post_thermal(self, playload): - """post thermal info - :playload: info to post - :type: dictionary - :returns: True or False - """ - if playload is None: - print("post_thermal failed: playload is None") - return None - return self._redfish_post(self.ThermalUrl, playload) - - def post_power(self, playload): - """post power info - :playload: info to post - :type: dictionary - :returns: True or False - """ - if playload is None: - print("post_power failed: playload is None") - return None - return self._redfish_post(self.PowerUrl, playload) - - def post_thresholdSensors(self, playload): - """post thresholdSensors info - :playload: info to post - :type: dictionary - :returns: True or False - """ - if playload is None: - print("post_thresholdSensors failed: playload is None") - return None - return self._redfish_post(self.ThresholdSensorsUrl, playload) - - def get_fanSpeed(self): - """Get board led info - :returns: class'redfish.rest.v1.RestResponse' or None when failed - """ - return self._redfish_get(self.FanSpeedUrl) - - def post_board(self, playload, board_name="indicatorboard"): - """post board info - :board_name: name of board, default is "indicatorboard" - :type: string - :playload: info to post - :type: dictionary - :returns: True or False - """ - if board_name is None or playload is None: - print("post failed: playload is None") - return False - return self._redfish_post(self.BoardsUrl + board_name, playload) - - def get_boardLed(self, board_name="indicatorboard"): - """Get boardLed info - :board_name: name of board, default is "indicatorboard" - :type: string - :returns: class'redfish.rest.v1.RestResponse' or None when failed - """ - if board_name is None : - print("get failed: board_name is None") - return None - return self._redfish_get(self.BoardsUrl % board_name) - - ''' - -''' -if __name__ == '__main__': - redfish = Redfish_Api() - - ### get - # boards - ret = redfish.get_board() - if ret is None: - print("get failed: board") - else: - print("get succeeded, board:%s" % ret) - - ret = redfish.get_thresholdSensors() - if ret is None: - print("get failed: threshold") - else: - print("get succeeded, threshold:%s" % ret) - - ret = redfish.get_power() - if ret is None: - print("get failed: power") - else: - print("get succeeded, power:%s" % ret) - - ret = redfish.get_thermal() - if ret is None: - print("get failed:thermal") - else: - print("get succeeded,thermal:%s" % ret) - - # get playload - resp = redfish.get_thresholdSensors() - if (resp != None): - print(resp["@odata.id"]) - print(resp["@odata.type"]) - print(resp["Id"]) - print(resp["Name"]) - else: - print("Failed: get_thresholdSensors") - - ### post - # fanSpeed - playload = {} - playload["FanName"] = 'Fan0' - playload["FanSpeedLevelPercents"] = "70" - print("post fanSpeed:%s" % redfish.post_fanSpeed(playload)) - - #{"LEDs": [{"IndicatorLEDColor": "green","LEDType": "sys"},{"IndicatorLEDColor": "off","LEDType": "pwr"},{"IndicatorLEDColor": "green","LEDType": "fan"}]} - playload = {} - led = {} - led1 = {} - led_list = [] - led["IndicatorLEDColor"] = "green" - led["LEDType"] = "sys" - led1["IndicatorLEDColor"] = "off" - led1["LEDType"] = "pwr" - led_list.append(led) - led_list.append(led1) - playload["LEDs"] = led_list - # boardsLed - print("post boardLed:%s" % redfish.post_boardLed(playload)) -''' diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/rjutil/__init__.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/rjutil/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/rjutil/ragileutil.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/rjutil/ragileutil.py deleted file mode 100644 index b704d384b0..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/rjutil/ragileutil.py +++ /dev/null @@ -1,290 +0,0 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- - -import os -import re -import time -import mmap -configfile_pre = "/usr/local/bin/" -import sys -sys.path.append(configfile_pre) -from ragileconfig import * -import subprocess -import pexpect -import shlex - -SYSLOG_IDENTIFIER = "UTILTOOL" - -def os_system(cmd): - status, output = subprocess.getstatusoutput(cmd) - return status, output - -def get_machine_info(): - if not os.path.isfile('/host/machine.conf'): - return None - machine_vars = {} - with open('/host/machine.conf') as machine_file: - for line in machine_file: - tokens = line.split('=') - if len(tokens) < 2: - continue - machine_vars[tokens[0]] = tokens[1].strip() - return machine_vars - -def get_platform_info(machine_info): - if machine_info != None: - if machine_info.__contains__('onie_platform'): - return machine_info['onie_platform'] - elif machine_info.__contains__('aboot_platform'): - return machine_info['aboot_platform'] - return None - -''' -def cpld_version_restful(url): - if url == "" or len(url) <=0: - print("invalid url") - return - bmc = BMCMessage() - value = bmc.getBmcValue(url) - json_dicts=json.dumps(value,indent=4) - return json_dicts -''' - -def lpc_cpld_rd(reg_addr): - try: - regaddr = 0 - if type(reg_addr) == int: - regaddr = reg_addr - else: - regaddr = int(reg_addr, 16) - devfile = "/dev/lpc_cpld" - fd = os.open(devfile, os.O_RDWR|os.O_CREAT) - os.lseek(fd, regaddr, os.SEEK_SET) - str = os.read(fd, 1) - os.close(fd) - return "%02x" % ord(str) - except ValueError: - return None - except Exception as e: - print (e) - return None - - -def my_log(txt): - if DEBUG == True: - print ("[RAGILE]:",) - print (txt) - return - -def log_os_system(cmd, show): - my_log (' Run :'+ cmd) - status, output = subprocess.getstatusoutput(cmd) - my_log (" with result :" + str(status)) - my_log (" output :" + output) - if status: - log_error('Failed :%s msg:%s'%(cmd,output)) - if show: - print ('Failed :'+ cmd) - return status, output - -def password_command(cmd, password, exec_timeout=30): - - newkey = 'continue connecting' - log_os_system("rm -rf ~/.ssh", 0) - msg = "" - try_times = 3 - try_times_conter = try_times - while try_times_conter: - child = pexpect.spawn(cmd) - if try_times != try_times_conter: - time.sleep(5) - try_times_conter -= 1 - try: - i = child.expect([pexpect.TIMEOUT, newkey, 'password: ',"refused",pexpect.EOF],timeout=30) - # If the login times out, print an error message and exit. - if i == 0: # Timeout - msg = 'connect to BMC timeout' - continue - # no public key - if i == 1: - child.sendline ('yes') - i = child.expect([pexpect.TIMEOUT, 'password: '],timeout=30) - if i == 0: # Timeout - msg = 'connect to BMC timeout' - continue - if i == 1:# Go below and enter the logic of the password - i = 2 - if i == 2: # Enter the password - child.sendline (password) - i = child.expect([pexpect.EOF, pexpect.TIMEOUT], exec_timeout) - if i == 0: - return True,child.before - if i == 1: - msg = str(child.before)+"\nBMC run commands timeout" - return False,msg - if i == 3: # BMC Connection refused - msg = 'connect to BMC failed' - continue - if i == 4: - msg = child.before - except Exception as e: - msg = str(child.before)+"\nconnect to BMC failed" - - return False,msg - -def password_command_realtime(ssh_header, ssh_cmd, password,key_words, exec_timeout=30): - - key_word_end = key_words.get("key_word_end") - key_word_pass = key_words.get("key_word_pass") - key_word_noshow = key_words.get("key_word_noshow") - # Prevents waiting caused by BMC restart - key_word_exit = key_words.get("key_word_exit") - - if None in [key_word_end,key_word_pass]: - print ("Missing parameters") - return False - - newkey = 'continue connecting' - log_os_system("rm -rf ~/.ssh", 0) - msg = "" - try_times = 3 - key_word_pass_flag = False - try_times_conter = try_times - child = pexpect.spawn(ssh_header) - try: - i = child.expect([pexpect.TIMEOUT,newkey, 'password: ',"refused",pexpect.EOF],timeout=30) - # If the login times out, print an error message and exit. - if i == 0: # Timeout - msg = 'connect to BMC timeout' - # no public key - if i == 1: - child.sendline ('yes') - i = child.expect([pexpect.TIMEOUT, 'password: '],timeout=30) - if i == 0: # Timeout - msg = 'connect to BMC timeout' - if i == 1:# Go below and enter the logic of the password - i = 2 - - if i == 2: # Enter the password - child.sendline (password) - i = child.expect([pexpect.EOF, "\r",pexpect.TIMEOUT], exec_timeout) - if i == 0: - print (child.before) - return key_word_pass_flag - if i == 1: - child.sendline(ssh_cmd) - # amount received is similar to root@switch2 in order to avoid misjudgment about the end of execution - usr_symble_first = True - bmc_str_tmp="" - while True: - i = child.expect([pexpect.EOF,"\r","\n",key_word_end, pexpect.TIMEOUT], exec_timeout) - if i == 0: - return key_word_pass_flag - elif i in [1,2]: - if key_word_noshow == None or key_word_noshow not in child.before: - bmc_str, times = re.subn("\r|\n","",child.before) - if len(bmc_str) > 1: - print (bmc_str) - bmc_str_tmp=bmc_str_tmp + bmc_str - # print bmc_str_tmp - # if key_word_pass in child.before: - if re.search(key_word_pass,bmc_str_tmp) != None: - key_word_pass_flag = True - if key_word_exit != None and key_word_exit in child.before: - # Give the BMC time to execute the last command - time.sleep(3) - return key_word_pass_flag - elif i == 3 : - if usr_symble_first: - usr_symble_first = False - else: - return key_word_pass_flag - - if i == 3: # BMC Connection refused - msg = 'connect to BMC failed' - if i == 4: - msg = child.before - except Exception as e: - print (e) - msg = str(child.before)+"\nconnect to BMC error" - print (msg) - - return False - -def get_sys_execute2(cmd, key_word_pass): - # key_word_pass_flag1 = False - key_word_pass_flag = False - filename = "/tmp/diag_excute_out" - cmd = cmd + "|tee %s" % filename - p = subprocess.Popen(shlex.split(cmd), shell=False) - p.wait() - with open(filename, 'r') as f: - str1 = f.read() - if key_word_pass in str1: - key_word_pass_flag = True - # if key_word_pass_flag1 and "100%" in str1: - # key_word_pass_flag = True - log_os_system("rm %s"%filename,0) - return key_word_pass_flag - - -BMC_PATH = "PATH=/usr/sbin/:/bin/:/usr/bin/:/sbin" -RETURN_KEY1 = "code" -RETURN_KEY2 = "msg" -DEBUG = False - -def rgi2cget(bus, devno, address): - command_line = "i2cget -f -y %d 0x%02x 0x%02x " % (bus, devno, address) - retrytime = 6 - ret_t = "" - for i in range(retrytime): - ret, ret_t = os_system(command_line) - if ret == 0: - return True, ret_t - time.sleep(0.1) - return False, ret_t - -def strtoint(str): # Hexadecimal string to int,"4040"/"0x4040"/"0X4040" = 16448 - value = 0 - rest_v = str.replace("0X", "").replace("0x", "") - for index in range(len(rest_v)): - value |= int(rest_v[index], 16) << ((len(rest_v) - index - 1) * 4) - return value - -def pci_read(pcibus, slot, fn , bar, offset): - if offset % 4 != 0: - return None - filename = "/sys/bus/pci/devices/0000:%02x:%02x.%x/resource%d" % (int(pcibus), int(slot), int(fn), int(bar)) - file = open(filename, "r+") - size = os.path.getsize(filename) - data = mmap.mmap(file.fileno(), size) - result = data[offset: offset + 4] - s = result[::-1] - val = 0 - for i in range(0, len(s)): - val = val << 8 | ord(s[i]) - data.close() - file.close() - return val - -########################################### -# Run the DMI command to obtain the BIOS information -########################################### -def getDmiSysByType(type_t): - ret, log = os_system("which dmidecode ") - if ret != 0 or len(log) <= 0: - error = "cmd find dmidecode" - return False, error - cmd = log + " -t %s" % type_t - # Get the total first - ret1, log1 = os_system(cmd) - if ret != 0 or len(log1) <= 0: - return False, "Command error[%s]" % cmd - its = log1.replace("\t", "").strip().split("\n") - ret = {} - for it in its: - if ":" in it: - key = it.split(":")[0].lstrip() - value = it.split(":")[1].lstrip() - ret[key] = value - return True, ret diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/sonic_fwmgr/__init__.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/sonic_fwmgr/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/sonic_fwmgr/fwgmr_base.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/sonic_fwmgr/fwgmr_base.py deleted file mode 100644 index 50a4ca7bc6..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/lib/sonic_fwmgr/fwgmr_base.py +++ /dev/null @@ -1,141 +0,0 @@ -# fwgmr_base.py -# -# Base class for creating platform-specific firmware management interfaces for SONiC -# -try: - import abc -except ImportError as e: - raise ImportError("%s - required module not found" % str(e)) - -class FwMgrUtilBase(object): - - """Base class for Platform-specific FwMgrUtil class""" - __metaclass__ = abc.ABCMeta - - def __init__(self): - """TODO: to be defined1. """ - pass - - @abc.abstractmethod - def get_bmc_version(self): - """Get BMC version from SONiC - :returns: version string - """ - return - - @abc.abstractmethod - def get_cpld_version(self): - """Get CPLD version from SONiC - :returns: dict like {'CPLD_1': version_string, 'CPLD_2': version_string} - """ - return - - @abc.abstractmethod - def get_onie_version(self): - """Get ONiE version from SONiC - :returns: version string - """ - return - - @abc.abstractmethod - def get_uboot_version(self): - """Get UBOOT version from SONiC - :returns: version string - """ - return - - # @fw_type MANDATORY, firmware type, should be one of the strings: 'cpld', 'fpga', 'bios', 'bmc' - # @fw_path MANDATORY, target firmware file - # @fw_extra OPTIONAL, extra information string, - # for fw_type 'cpld' and 'fpga': it can be used to indicate specific cpld, such as 'cpld1', 'cpld2', ... - # or 'cpld_fan_come_board', etc. For fw_type 'bios' and 'bmc', value should be one of 'master' - # or 'slave' or 'both'. For BMC, 'pingpong' stands for alternative upgrade policy. - @abc.abstractmethod - def firmware_upgrade(self, fw_type, fw_path, fw_extra): - return - - # Get last firmware upgrade information, inlcudes: - # 1) FwType: cpld/fpga/bios/bmc(passed by method 'firmware_upgrade'), string - # 2) FwPath: path and file name of firmware(passed by method 'firmware_upgrade'), string - # 3) FwExtra: designated string, econdings of this string is determined by vendor(passed by method 'firmware_upgrade') - # 4) Result: indicates whether the upgrade action is performed and success/failure status if performed. Values should be one of: "DONE"/"FAILED"/"NOT_PERFORMED". - # dict object: - # { - # "FwType": "cpld", - # "FwExtra": "specific_encoded_string" - # "Result": "DONE"/"FAILED"/"NOT_PERFORMED" - # } - @abc.abstractmethod - def get_last_upgrade_result(self): - return - - # Program FPGA and/or CPLD firmware only, but do not refresh them - # - # @param fw_type value can be: FPGA, CPLD - # @param fw_path a string of firmware file path, seperated by ':' - # @param fw_extra a string of firmware subtype, i.e CPU_CPLD, BOARD_CPLD, - # FAN_CPLD, LC_CPLD, etc. Subtypes are seperated by ':', - # the sequence should match the file nanmes in param @fw_path - # @return True when all required firmware is program succefully, - # False otherwise. - # - # Example: - # self.firmware_program("CPLD", "/cpu_cpld.vme:/lc_cpld", \ - # "CPU_CPLD:LC_CPLD") - # or - # self.firmware_program("FPGA", "/fpga.bin", "FPGA") - @abc.abstractmethod - def firmware_program(self, fw_type, fw_path, fw_extra=None): - return - - # Refresh firmware and take extra action when necessary. - # @param fpga_list a list of FPGA names - # @param cpld_list a list of CPLD names - # @return True if refresh succefully - # - # @Note extra action: - # 1) response OK to restful call - # 2) shutdown eth0.4088(keep eth0 working) - # 3) shutdown SFP power - # 4) power off all(CPU, switch, gearbox) - # 5) if power off fpga is supported: - # power off fpga - # else: - # refresh fpga - # 6) refresh linecard cpld, fan cpld - # 7) refresh cpu cpld, baseboard cpld - # 8) power on all - # 9) bring up eth0.4088 - # - # Example: - # self.firmware_refresh(["FPGA"], ["CPU_CPLD", "LC_CPLD"], "/tmp/fw/refresh.vme") - # or - # self.firmware_refresh(["FPGA"], None, None) - # or - # self.firmware_refresh(None, ["FAN_CPLD", "LC1_CPLD", "BOARD_CPLD"], "/tmp/fw/refresh.vme") - @abc.abstractmethod - def firmware_refresh(self, fpga_list, cpld_list, fw_extra=None): - return - - # Get booting flash of running BMC. - # @return a string, "master" or "slave" - @abc.abstractmethod - def get_running_bmc(self): - return - - # Set booting flash of BMC - # @param flash should be "master" or "slave" - @abc.abstractmethod - def set_bmc_boot_flash(self, flash): - return - - # Reboot BMC - @abc.abstractmethod - def reboot_bmc(self): - return - - # Get booting uboot image of current running host OS - # @return a string, "master" or "slave" - @abc.abstractmethod - def get_current_uboot(self): - return diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/ctccmd b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/ctccmd deleted file mode 100755 index 2c4410a16d..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/ctccmd +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/bash - -docker exec -i syncd ctc_shell -e "$@" \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/privatenetwork.py b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/privatenetwork.py deleted file mode 100644 index b169662e99..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/privatenetwork.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- -import sys -import os -import re -try: - from sonic_platform import get_machine_info - from sonic_platform import get_platform_info -except ImportError : - try: - from sonic_device_util import get_machine_info - from sonic_device_util import get_platform_info - except ImportError: - from sonic_py_common import device_info - def get_machine_info(): - print("get_machine_info is null") - return False - def get_platform_info(x): - return device_info.get_platform() - -def start(): - x = get_platform_info(get_machine_info()) - print (x) - str = re.findall(r"-(.+?)_",x) - print (str[0]) - if str[0] == 'ragile': - print ("Start privatenetwork.sh") - os.system("/usr/local/bin/privatenetwork.sh start") - else: - print ("Not set private network.") -def stop(): - x = get_platform_info(get_machine_info()) - print (x) - str = re.findall(r"-(.+?)_",x) - print (str[0]) - if str[0] == 'ragile': - print ("Stop privatenetwork.sh") - os.system("/usr/local/bin/privatenetwork.sh stop") - else: - print ("Not stop private network.") -def main(): - print (sys.argv[1]) - if sys.argv[1]=='start': - start() - elif sys.argv[1]=='stop': - stop() - else: - print ("Error parameter!\nRequired parameters : start or stop.") -if __name__ == '__main__': - main() diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/privatenetwork.sh b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/privatenetwork.sh deleted file mode 100644 index 4105dcbfff..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/privatenetwork.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -function load_eth0.4088(){ - try_times_remain=5 - state_up=$(ip -d link show eth0.4088 | awk '/state UP/{print $2}') - while [ -z "$state_up" ] && [ $try_times_remain -ne 0 ] - do - ((try_times_remain-=1)) - ip link add link eth0 name eth0.4088 type vlan id 4088 || true - ip addr add 240.1.1.2/30 brd 240.1.1.3 dev eth0.4088 || true - ip link set dev eth0.4088 up || true - state_up=$(ip -d link show eth0.4088 | awk '/state UP/{print $2}') - sleep 1 - done -} - -function unload_eth0.4088(){ - ip link set dev eth0.4088 down - ip link del eth0.4088 -} - -if [ "$1" = "start" ];then - load_eth0.4088 -elif [ "$1" = "stop" ];then - unload_eth0.4088 -fi diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/update_machine_config.sh b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/update_machine_config.sh deleted file mode 100644 index 933e7cc357..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/script/update_machine_config.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//') -mkdir -p /mnt/onie-boot -mount $onie_dev /mnt/onie-boot -onie_grub_cfg=/mnt/onie-boot/onie/grub/grub-machine.cfg - -if [ ! -e $onie_grub_cfg ]; then - echo "$onie_grub_cfg not found" -else - oldoniebuilddate=`cat /host/machine.conf|grep "onie_build_date="` - oniebuilddate=`cat $onie_grub_cfg|grep "onie_build_date="|sed "s/\"//g"` - onieversion=`cat $onie_grub_cfg|grep "onie_version="` - oniekernelversion=`cat $onie_grub_cfg|grep "onie_kernel_version="` - if [ "$oldoniebuilddate" != "$oniebuilddate" ]; then - echo "update /home/machine.conf" - sed -i "s/onie_build_date=.*/$oniebuilddate/" /host/machine.conf - sed -i "s/onie_version=.*/$onieversion/" /host/machine.conf - sed -i "s/onie_kernel_version=.*/$oniekernelversion/" /host/machine.conf - sed -i "s/\"//g" /host/machine.conf - fi -fi -umount /mnt/onie-boot - - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/service/privatenetwork.service b/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/service/privatenetwork.service deleted file mode 100644 index a962613ad1..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/common_custom/common_ragile/service/privatenetwork.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Update interfaces configuration for adding eth0 private subnetwork -After=network.target ra-b6010-48gt4x_platform.service -DefaultDependencies=no - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/privatenetwork.py start -ExecStop=/usr/local/bin/privatenetwork.py stop -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/debian/changelog b/platform/centec-arm64/sonic-platform-modules-ragile/debian/changelog deleted file mode 100755 index 4cbb334fd2..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/debian/changelog +++ /dev/null @@ -1,6 +0,0 @@ -sonic-centec-platform-modules (1.3) unstable; urgency=low - - * Add support for ragile ra-b6010-48gt4x - - -- sonic_rd Mon, 21 Sep 2020 13:34:33 +0800 - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/debian/compat b/platform/centec-arm64/sonic-platform-modules-ragile/debian/compat deleted file mode 100644 index f599e28b8a..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/debian/compat +++ /dev/null @@ -1 +0,0 @@ -10 diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/debian/control b/platform/centec-arm64/sonic-platform-modules-ragile/debian/control deleted file mode 100644 index 5c32698717..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/debian/control +++ /dev/null @@ -1,11 +0,0 @@ -Source: sonic-centec-platform-modules -Section: main -Priority: extra -Maintainer: shil -Build-Depends: debhelper (>= 8.0.0), bzip2 -Standards-Version: 3.9.3 - -Package: platform-modules-ra-b6010-48gt4x -Architecture: arm64 -Description: kernel modules for platform devices such as fan, led, sfp - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/debian/platform-modules-ra-b6010-48gt4x.init b/platform/centec-arm64/sonic-platform-modules-ragile/debian/platform-modules-ra-b6010-48gt4x.init deleted file mode 100644 index 33db82a450..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/debian/platform-modules-ra-b6010-48gt4x.init +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -# This script load/unload centec kernel modules - -function install_python_api_package() -{ - device="/usr/share/sonic/device" - platform=$(/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform) - - rv=$(pip3 show sonic-platform > /dev/null 2>/dev/null) - if [ $? -ne 0 ]; then - echo -n "Install sonic_platform-1.0-py3-none-any.whl ..." - rv=$(pip3 install $device/$platform/sonic_platform-1.0-py3-none-any.whl) - fi -} - -function load_kernel_modules() -{ - hwaddr=`fw_printenv ethaddr | awk -F = '{print $2}'` - if [ "$hwaddr" != "" ]; then - ifconfig eth0 hw ether $hwaddr - fi - depmod -a - modprobe dal - modprobe psample -} - -function remove_kernel_modules() -{ - modprobe -r dal -} - -case "$1" in -start) - echo -n "Load Centec kernel modules... " - - load_kernel_modules - install_python_api_package - - echo "done." - ;; - -stop) - echo -n "Unload Centec kernel modules... " - - remove_kernel_modules - - echo "done." - ;; - -force-reload|restart) - echo "Not supported" - ;; - -*) - echo "Usage: /etc/init.d/platform-modules-ra-b6010-48gt4x {start|stop}" - exit 1 - ;; -esac - -exit 0 - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/debian/platform-modules-ra-b6010-48gt4x.install b/platform/centec-arm64/sonic-platform-modules-ragile/debian/platform-modules-ra-b6010-48gt4x.install deleted file mode 100644 index 3ad193101a..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/debian/platform-modules-ra-b6010-48gt4x.install +++ /dev/null @@ -1,2 +0,0 @@ -ra-b6010-48gt4x/modules/sonic_platform-1.0-py3-none-any.whl usr/share/sonic/device/arm64-ragile_ra-b6010-48gt4x-r0 - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/debian/platform-modules-ra-b6010-48gt4x.postinst b/platform/centec-arm64/sonic-platform-modules-ragile/debian/platform-modules-ra-b6010-48gt4x.postinst deleted file mode 100644 index eef57df148..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/debian/platform-modules-ra-b6010-48gt4x.postinst +++ /dev/null @@ -1,8 +0,0 @@ -systemctl enable ra-b6010-48gt4x_platform.service -systemctl start ra-b6010-48gt4x_platform.service -systemctl enable device_i2c.service -systemctl start device_i2c.service -systemctl enable privatenetwork.service -systemctl start privatenetwork.service -systemctl enable fancontrol.service -systemctl start fancontrol.service diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/debian/rules b/platform/centec-arm64/sonic-platform-modules-ragile/debian/rules deleted file mode 100755 index 7676379cfa..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/debian/rules +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. - -include /usr/share/dpkg/pkg-info.mk - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -export INSTALL_MOD_DIR:=extra - -PYTHON = python3.9 - -PACKAGE_PRE_NAME := platform-modules -KVERSION ?= $(shell uname -r) -KERNEL_SRC := /lib/modules/$(KVERSION) -MOD_SRC_DIR:= $(shell pwd) -MODULE_DIRS:= ra-b6010-48gt4x -MODULE_DIR := common -CUSTOMS_DIRS := common_custom/common_ragile -SERVICE_DIR := service -CLASSES_DIR := classes -CONFIG_DIR := config -KDAL_DIR := ../../centec/centec-dal/ -export KERNEL_SRC - - - -clean: - dh_testdir - dh_testroot - dh_clean - -build: - #make modules -C $(KERNEL_SRC)/build M=$(MODULE_SRC) - (for mod in $(KDAL_DIR); do \ - make modules -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/; \ - done) - (for mod in $(MODULE_DIRS); do \ - make modules -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \ - cd $${mod}; $(PYTHON) setup.py bdist_wheel -d $(MOD_SRC_DIR)/$${mod}/modules; \ - cd -; \ - done) - make -C $(MODULE_DIR); - make -C $(CUSTOMS_DIRS); - -binary: binary-arch binary-indep - # Nothing to do - -binary-arch: - # Nothing to do - -binary-indep: - dh_testdir - dh_installdirs - - # Custom package commands - (for mod in $(MODULE_DIRS); do \ - dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod} $(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ - dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod} lib/systemd/system; \ - dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod} etc; \ - dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod} boot; \ - cp -r $(MOD_SRC_DIR)/$(MODULE_DIR)/build/* debian/$(PACKAGE_PRE_NAME)-$${mod}/; \ - cp -r $(MOD_SRC_DIR)/$(CUSTOMS_DIRS)/build/* debian/$(PACKAGE_PRE_NAME)-$${mod}/; \ - cp $(MOD_SRC_DIR)/$${mod}/config/* debian/$(PACKAGE_PRE_NAME)-$${mod}/usr/local/bin/; \ - cp $(MOD_SRC_DIR)/$${mod}/modules/*.ko debian/$(PACKAGE_PRE_NAME)-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ - cp $(MOD_SRC_DIR)/$(KDAL_DIR)/*.ko debian/$(PACKAGE_PRE_NAME)-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ - cp $(MOD_SRC_DIR)/$${mod}/$(MODULE_DIR)/*.ko debian/$(PACKAGE_PRE_NAME)-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ - cp $(MOD_SRC_DIR)/$${mod}/$(SERVICE_DIR)/*.service debian/$(PACKAGE_PRE_NAME)-$${mod}/lib/systemd/system/; \ - cp $(MOD_SRC_DIR)/${CONFIG_DIR}/* debian/$(PACKAGE_PRE_NAME)-$${mod}/etc/; \ - cd -; \ - done) - - # Resuming debhelper scripts - dh_testroot - dh_install - dh_installchangelogs - dh_installdocs - dh_systemd_enable - dh_installinit - dh_systemd_start - dh_link - dh_fixperms - dh_compress - dh_strip - dh_installdeb - dh_gencontrol - dh_md5sums - dh_builddeb -.PHONY: build binary binary-arch binary-indep clean diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/config/arm64_ragile_ra_b6010_48gt4x_r0_config.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/config/arm64_ragile_ra_b6010_48gt4x_r0_config.py deleted file mode 100755 index 72b115967a..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/config/arm64_ragile_ra_b6010_48gt4x_r0_config.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- -from ragilecommon import * -PCA9548START = -1 -PCA9548BUSEND = -2 - -RAGILE_CARDID = 0x00004065 -RAGILE_PRODUCTNAME = "RA-B6010-48GT4X" -RAGILE_PART_NUMBER = "01016994" -RAGILE_LABEL_REVISION = "R01" -RAGILE_ONIE_VERSION = "2018.05-rc1" -RAGILE_MAC_SIZE = 3 -RAGILE_MANUF_NAME = "Ragile" -RAGILE_MANUF_COUNTRY = "USA" -RAGILE_VENDOR_NAME = "Ragile" -RAGILE_DIAG_VERSION = "0.1.0.15" -RAGILE_SERVICE_TAG = "www.ragilenetworks.com" - -LOCAL_LED_CONTROL = { - "CLOSE":{}, - "OPEN":{} -} - -MACLED_PARAMS = [] - -# start system modules -STARTMODULE = { - "i2ccheck":0, - "fancontrol":0, - "avscontrol":0, - "avscontrol_restful":0, - "sfptempmodule":0, - "sfptempmodule_interval":3, - "macledreset": 0, - "macledreset_interval": 5, - "macledset_param":MACLED_PARAMS, - } - -FRULISTS = [ - {"name":"mmceeprom","bus":5,"loc":0x50, "E2PRODUCT":'2', "E2TYPE":'5' , "CANRESET":'1'}, - {"name":"cpueeprom","bus":5,"loc":0x57,"E2PRODUCT":'2', "E2TYPE":'4', "CANRESET":'1' }, - ] - -# rg_eeprom = "1-0056/eeprom" -E2_LOC = {"bus":1, "devno":0x56} -E2_PROTECT = {} - - -CPLDVERSIONS = [ - {"bus":2, "devno":0x0d, "name":"CPU_CPLD"}, - {"bus":3, "devno":0x30, "name":"MAC_BOARD_CPLD_1"}, -] - -FIRMWARE_TOOLS = {"cpld": [{"channel":"0","cmd":"firmware_upgrade %s cpld %s cpld", "successtips":"CPLD Upgrade succeeded!"} - ], - } - -# drivers list -DRIVERLISTS = [ - {"name":"i2c_dev", "delay":0}, - {"name":"i2c_algo_bit","delay":0}, - {"name":"spi-bitbang", "delay":0}, - {"name":"i2c_mux", "delay":0}, - {"name":"rtcpcf85063", "delay":0}, - {"name":"i2c_mux_pca954x", "delay":0}, # force_deselect_on_exit=1 - {"name":"ragile_common dfd_my_type=0x4065", "delay":0}, - {"name":"firmware_driver", "delay":0}, - {"name":"rg_cpld", "delay":0}, - {"name":"rg_at24", "delay":0}, - #{"name":"spi-gpio", "delay":0}, - #{"name":"rg_spi_gpio", "delay":0}, - #{"name":"tpm_tis_core", "delay":0}, - #{"name":"tpm_tis_spi", "delay":0}, - {"name":"optoe", "delay":0}, -] - -DEVICE = [ - {"name":"rtcpcf85063","bus":1,"loc":0x51 }, - {"name":"rg_24c02","bus":1,"loc":0x56 }, - {"name":"rg_cpld","bus":3,"loc":0x30 }, - {"name":"rg_24c02","bus":5,"loc":0x50 }, - {"name":"rg_24c02","bus":5,"loc":0x57 }, -] - -INIT_PARAM = [ - {"loc":"3-0030/tx_write_protect","value": "59","delay":1}, - {"loc":"3-0030/tx_disable","value": "00"}, - {"loc":"3-0030/tx_write_protect","value": "4e"}, -] - -INIT_COMMAND = [ - "hwclock -s", -] - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/config/fan_ctrl_cfg.json b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/config/fan_ctrl_cfg.json deleted file mode 100644 index 86fcf892f0..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/config/fan_ctrl_cfg.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "Device": { - "Liquid": 0, - "Buildin": 1, - "PID": 0, - "OpenLoop": 1 - }, - "Thermal": { - "INLET_TEMP": "INLET_TEMP", - "OUTLET_TEMP": "OUTLET_TEMP", - "SWITCH_TEMP": "TPS53688_TEMP" - }, - "Fans": { - "Fan1" : "Fantray1_1", - "Fan2" : "Fantray2_1" - }, - "PID": { - "Pwm_Max": 99, - "Pwm_Min": 30, - "SetPoint" : 90, - "P": 1.5, - "I": 1, - "D": 0.3, - "Temp_Min": 28.0, - "Temp_Max": 45.0, - "Sensor": "TPS53688_TEMP" - }, - "OpenLoop": { - "a": -0.06, - "b": 10.3, - "c": -142.0, - "fix_up": -8, - "pwmMax": 99, - "pwmMin": 30, - "tempMin": 25 - }, - "FanError": { - "Fan_Pwmmax":99 - } -} \ No newline at end of file diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/modules/Makefile b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/modules/Makefile deleted file mode 100644 index 9310841c64..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/modules/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-m += rg_cpld.o diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/modules/rg_cpld.c b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/modules/rg_cpld.c deleted file mode 100644 index becd53c19a..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/modules/rg_cpld.c +++ /dev/null @@ -1,340 +0,0 @@ -/* - * rg_cpld.c - A driver for control rg_cpld base on rg_cpld.c - * - * Copyright (c) 1998, 1999 Frodo Looijaard - * Copyright (c) 2018 wk - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* debug switch level */ -typedef enum { - DBG_START, - DBG_VERBOSE, - DBG_KEY, - DBG_WARN, - DBG_ERROR, - DBG_END, -} dbg_level_t; - -static int debuglevel = 0; -module_param(debuglevel, int, S_IRUGO | S_IWUSR); - -#define DBG_DEBUG(fmt, arg...) do { \ - if ( debuglevel > DBG_START && debuglevel < DBG_ERROR) { \ - printk(KERN_INFO "[DEBUG]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \ - } else if ( debuglevel >= DBG_ERROR ) { \ - printk(KERN_ERR "[DEBUG]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \ - } else { } \ -} while (0) - -#define DBG_ERROR(fmt, arg...) do { \ - if ( debuglevel > DBG_START) { \ - printk(KERN_ERR "[ERROR]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \ - } \ - } while (0) - -#define CPLD_SIZE 256 -#define CPLD_I2C_RETRY_TIMES 5 /* changed the number of retry time to 5 */ -#define CPLD_I2C_RETRY_WAIT_TIME 10 /* Delay 10ms before operation */ - -struct cpld_data { - struct i2c_client *client; - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 data[CPLD_SIZE]; /* Register value */ -}; - -static s32 cpld_i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command) -{ - int try; - s32 ret; - - ret = -1; - for (try = 0; try < CPLD_I2C_RETRY_TIMES; try++) { - if ((ret = i2c_smbus_read_byte_data(client, command) ) >= 0 ) - break; - msleep(CPLD_I2C_RETRY_WAIT_TIME); - } - return ret; -} - -static s32 cpld_i2c_smbus_read_i2c_block_data(const struct i2c_client *client, - u8 command, u8 length, u8 *values) -{ - int try; - s32 ret; - - ret = -1; - for (try = 0; try < CPLD_I2C_RETRY_TIMES; try++) { - if ((ret = i2c_smbus_read_i2c_block_data(client, command, length, values) ) >= 0 ) - break; - msleep(CPLD_I2C_RETRY_WAIT_TIME); - } - return ret; -} - -static ssize_t set_cpld_sysfs_value(struct device *dev, struct device_attribute *da, const char *buf, size_t -count) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - unsigned long val; - int err; - - err = kstrtoul(buf, 16, &val); - if (err) - return err; - if ((val < 0) || (val > 0xff)) { - DBG_ERROR("please enter 0x00 ~ 0xff\n"); - return -1; - } - mutex_lock(&data->update_lock); - data->data[0] = (u8)val; - DBG_DEBUG("pos: 0x%02x count = %ld, data = 0x%02x\n", attr->index, count, data->data[0]); - i2c_smbus_write_byte_data(client, attr->index, data->data[0]); - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_cpld_version(struct device *dev, struct device_attribute *da, char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - s32 status; - - status = -1; - mutex_lock(&data->update_lock); - status = cpld_i2c_smbus_read_i2c_block_data(client, 0, 4, data->data); - if (status < 0) { - mutex_unlock(&data->update_lock); - return 0; - } - mutex_unlock(&data->update_lock); - return sprintf(buf, "%02x %02x %02x %02x \n", data->data[0], data->data[1], data->data[2], - data->data[3]); -} - -static ssize_t show_cpld_sysfs_value(struct device *dev, struct device_attribute *da, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - s32 status; - - status = -1; - mutex_lock(&data->update_lock); - status = cpld_i2c_smbus_read_byte_data(client, attr->index); - if (status < 0) { - mutex_unlock(&data->update_lock); - return 0; - } - data->data[0] = status; - DBG_DEBUG("cpld reg pos:0x%x value:0x%02x\n", attr->index, data->data[0]); - mutex_unlock(&data->update_lock); - return sprintf(buf, "%02x\n", data->data[0]); -} - -/* sys */ -static SENSOR_DEVICE_ATTR(cpld_version, S_IRUGO, show_cpld_version, NULL, 0); - -/* sfp */ -static SENSOR_DEVICE_ATTR(sfp_presence1, S_IRUGO, show_cpld_sysfs_value, NULL, 0x30); -static SENSOR_DEVICE_ATTR(cable_led1, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x20); -static SENSOR_DEVICE_ATTR(cable_led2, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x21); -static SENSOR_DEVICE_ATTR(cable_led3, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x22); -static SENSOR_DEVICE_ATTR(cable_led4, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x23); -static SENSOR_DEVICE_ATTR(cable_led5, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x24); -static SENSOR_DEVICE_ATTR(cable_led6, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x25); -static SENSOR_DEVICE_ATTR(sfp_led1, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x26); -static SENSOR_DEVICE_ATTR(sfp_drop_record1, S_IRUGO , show_cpld_sysfs_value, NULL, 0x38); -static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO , show_cpld_sysfs_value, NULL, 0x50); -static SENSOR_DEVICE_ATTR(sfp_rx_loss1, S_IRUGO , show_cpld_sysfs_value, NULL, 0x70); -/* tx-disbale */ -static SENSOR_DEVICE_ATTR(tx_disable, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x90); -static SENSOR_DEVICE_ATTR(tx_write_protect, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x0e); - -static struct attribute *mac_cpld_0x30_sysfs_attrs[] = { - &sensor_dev_attr_cpld_version.dev_attr.attr, - &sensor_dev_attr_sfp_presence1.dev_attr.attr, - &sensor_dev_attr_cable_led1.dev_attr.attr, - &sensor_dev_attr_cable_led2.dev_attr.attr, - &sensor_dev_attr_cable_led3.dev_attr.attr, - &sensor_dev_attr_cable_led4.dev_attr.attr, - &sensor_dev_attr_cable_led5.dev_attr.attr, - &sensor_dev_attr_cable_led6.dev_attr.attr, - &sensor_dev_attr_sfp_led1.dev_attr.attr, - &sensor_dev_attr_tx_disable.dev_attr.attr, - &sensor_dev_attr_tx_write_protect.dev_attr.attr, - &sensor_dev_attr_sfp_drop_record1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, - &sensor_dev_attr_sfp_rx_loss1.dev_attr.attr, - NULL -}; - -static const struct attribute_group mac_cpld_0x30_sysfs_group = { - .attrs = mac_cpld_0x30_sysfs_attrs, -}; - -struct cpld_attr_match_group { - int bus_nr; /* I2C-BUS number */ - unsigned short addr; /* device adress */ - const struct attribute_group *attr_group_ptr;/* SYS attribute pointer */ - const struct attribute_group *attr_hwmon_ptr;/* HWMON Attribute pointer */ -}; - -static struct cpld_attr_match_group g_cpld_attr_match[] = { - {3, 0x30, &mac_cpld_0x30_sysfs_group, NULL}, - -}; - -static const struct attribute_group *cpld_get_attr_group(struct i2c_client *client, int is_hwmon) -{ - int i; - struct cpld_attr_match_group *group; - - for (i = 0; i < ARRAY_SIZE(g_cpld_attr_match); i++) { - group = &g_cpld_attr_match[i]; - DBG_DEBUG("is_hwmon %d i %d client(nr:%d,addr:0x%x), group(nr:%d,addr:0x0%x) .\n", is_hwmon, - i, client->adapter->nr, client->addr, group->bus_nr, group->addr); - if ((client->addr == group->addr) && (client->adapter->nr == group->bus_nr)) { - DBG_DEBUG("is_hwmon %d i %d nr %d addr %d .\n", is_hwmon, i, client->adapter->nr, client->addr); - return (is_hwmon) ? (group->attr_hwmon_ptr) : (group->attr_group_ptr); - } - } - - DBG_DEBUG("is_hwmon %d nr %d addr %d dismatch, return NULL.\n", is_hwmon, client->adapter->nr, client->addr); - return NULL; -} - -static int cpld_probe(struct i2c_client *client, const struct i2c_device_id *id) -{ - struct cpld_data *data; - int status; - const struct attribute_group *sysfs_group, *hwmon_group; - - status = -1; - DBG_DEBUG("=========cpld_probe(addr:0x%x, nr:%d)===========\n", client->addr, client->adapter->nr); - data = devm_kzalloc(&client->dev, sizeof(struct cpld_data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - - data->client = client; - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - - sysfs_group = NULL; - sysfs_group = cpld_get_attr_group(client, 0); - if (sysfs_group) { - status = sysfs_create_group(&client->dev.kobj, sysfs_group); - DBG_DEBUG("=========(addr:0x%x, nr:%d) sysfs_create_group status %d===========\n", client->addr, client->adapter->nr, status); - if (status != 0) { - DBG_ERROR("sysfs_create_group status %d.\n", status); - goto error; - } - } else { - DBG_DEBUG("=========(addr:0x%x, nr:%d) no sysfs_create_group \n", client->addr, client->adapter->nr); - } - - hwmon_group = NULL; - hwmon_group = cpld_get_attr_group(client, 1); - if (hwmon_group) { - data->hwmon_dev = hwmon_device_register_with_groups(&client->dev, client->name, data, (const struct attribute_group **)hwmon_group); - if (IS_ERR(data->hwmon_dev)) { - sysfs_remove_group(&client->dev.kobj, (const struct attribute_group *)sysfs_group); - DBG_ERROR("hwmon_device_register_with_groups failed ret %ld.\n", PTR_ERR(data->hwmon_dev)); - return PTR_ERR(data->hwmon_dev); - } - DBG_DEBUG("=========(addr:0x%x, nr:%d) hwmon_device_register_with_groups success===========\n", client->addr, client->adapter->nr); - if (status != 0) { - DBG_ERROR("sysfs_create_group status %d.\n", status); - goto error; - } - } else { - DBG_DEBUG("=========(addr:0x%x, nr:%d) no hwmon_device_register_with_groups \n", client->addr, client->adapter->nr); - } - -error: - return status; - -} - -static int cpld_remove(struct i2c_client *client) -{ - struct cpld_data *data = i2c_get_clientdata(client); - const struct attribute_group *sysfs_group, *hwmon_group; - - DBG_DEBUG("=========cpld_remove(addr:0x%x, nr:%d)===========\n", client->addr, client->adapter->nr); - - /* To be added the corresponding uninstall operation */ - sysfs_group = NULL; - sysfs_group = cpld_get_attr_group(client, 0); - if (sysfs_group) { - DBG_DEBUG("=========(addr:0x%x, nr:%d) do sysfs_remove_group \n", client->addr, client->adapter->nr); - sysfs_remove_group(&client->dev.kobj, (const struct attribute_group *)sysfs_group); - } else { - DBG_DEBUG("=========(addr:0x%x, nr:%d) no sysfs_remove_group \n", client->addr, client->adapter->nr); - } - - hwmon_group = NULL; - hwmon_group = cpld_get_attr_group(client, 1); - if (hwmon_group) { - DBG_DEBUG("=========(addr:0x%x, nr:%d) do hwmon_device_unregister \n", client->addr, client->adapter->nr); - hwmon_device_unregister(data->hwmon_dev); - } else { - DBG_DEBUG("=========(addr:0x%x, nr:%d) no hwmon_device_unregister \n", client->addr, client->adapter->nr); - } - - return 0; -} - -static const struct i2c_device_id cpld_id[] = { - { "rg_cpld", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, cpld_id); - -static struct i2c_driver rg_cpld_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "rg_cpld", - }, - .probe = cpld_probe, - .remove = cpld_remove, - .id_table = cpld_id, -}; - -module_i2c_driver(rg_cpld_driver); -MODULE_AUTHOR("wk "); -MODULE_DESCRIPTION("ragile CPLD driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/service/ra-b6010-48gt4x_platform.service b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/service/ra-b6010-48gt4x_platform.service deleted file mode 100644 index bd13cf98ae..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/service/ra-b6010-48gt4x_platform.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Centec modules init -After=local-fs.target -Before=syncd.service - -[Service] -Type=oneshot -ExecStart=-/etc/init.d/platform-modules-ra-b6010-48gt4x start -ExecStop=-/etc/init.d/platform-modules-ra-b6010-48gt4x stop -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/setup.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/setup.py deleted file mode 100644 index 01f97dfd43..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -from setuptools import setup - -setup( - name='sonic_platform', - version='1.0', - description='Module to initialize centec ra-b6010-48gt4x platforms', - - packages=['sonic_platform'], - package_dir={'sonic_platform': 'sonic_platform'}, -) - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/__init__.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/__init__.py deleted file mode 100644 index 4bfefa0fb6..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -__all__ = ["platform", "chassis"] -from sonic_platform import * - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/chassis.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/chassis.py deleted file mode 100644 index 8cdf84cf38..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/chassis.py +++ /dev/null @@ -1,444 +0,0 @@ - -#!/usr/bin/env python - -try: - import time - from sonic_platform_base.chassis_base import ChassisBase - from sonic_platform.eeprom import Eeprom - from sonic_platform.thermal import Thermal - from sonic_platform.fan_drawer import FanDrawer - from sonic_platform.sfp import Sfp - from sonic_platform.psu import Psu - from .component import Component -except ImportError as e: - raise ImportError(str(e) + "- required module not found") - -NUM_FAN_TRAY = 2 -NUM_FAN = 2 -NUM_THERMAL = 5 -NUM_PORT = 52 -NUM_PSU = 2 - -class Chassis(ChassisBase): - - port_dict = {} - STATUS_INSERTED = "1" - STATUS_REMOVED = "0" - - def __init__(self): - ChassisBase.__init__(self) - # Initialize EEPROM - self._eeprom = Eeprom() - #firmware - for i in range(0,2): - self._component_list.append(Component(i)) - # Initialize FAN - for i in range(NUM_FAN_TRAY): - fandrawer = FanDrawer(i) - self._fan_drawer_list.append(fandrawer) - self._fan_list.extend(fandrawer._fan_list) - # Initialize THERMAL - for index in range(0, NUM_THERMAL): - thermal = Thermal(index) - self._thermal_list.append(thermal) - # Initialize SFP - for index in range(0, NUM_PORT + 1): - sfp = Sfp(index) - self._sfp_list.append(sfp) - if sfp.get_presence(): - self.port_dict[index] = self.STATUS_INSERTED - else: - self.port_dict[index] = self.STATUS_REMOVED - # Initialize PSU - for index in range(0, NUM_PSU): - psu = Psu(index) - self._psu_list.append(psu) - -############################################## -# Device methods -############################################## - - def get_name(self): - """ - Retrieves the name of the chassis - Returns: - string: The name of the chassis - """ - name = '' - sys_eeprom = self.get_eeprom() - if sys_eeprom is None: - return '' - - e = sys_eeprom.read_eeprom() - name = sys_eeprom.modelstr(e) - if name is None: - return '' - return name - - def get_presence(self): - """ - Retrieves the presence of the chassis - Returns: - bool: True if chassis is present, False if not - """ - return True - - def get_model(self): - """ - Retrieves the model number (or part number) of the chassis - Returns: - string: Model/part number of chassis - """ - model = '' - sys_eeprom = self.get_eeprom() - if sys_eeprom is None: - return '' - - e = sys_eeprom.read_eeprom() - model = sys_eeprom.modelnumber(e) - if model is None: - return '' - return model - - def get_serial_number(self): - """ - Retrieves the hardware serial number for the chassis - - Returns: - A string containing the hardware serial number for this chassis. - """ - serial_number = '' - sys_eeprom = self.get_eeprom() - if sys_eeprom is None: - return '' - - e = sys_eeprom.read_eeprom() - serial_number = sys_eeprom.serial_number_str(e) - if serial_number is None: - return '' - - return serial_number - - def get_revision(self): - """ - Retrieves the hardware revision of the device - - Returns: - string: Revision value of device - """ - device_version = '' - sys_eeprom = self.get_eeprom() - if sys_eeprom is None: - return '' - - e = sys_eeprom.read_eeprom() - device_version = sys_eeprom.deviceversion(e) - if device_version is None: - return '' - - return device_version - - def get_serial(self): - """ - Retrieves the serial number of the chassis (Service tag) - Returns: - string: Serial number of chassis - """ - return self.get_serial_number() - - def get_status(self): - """ - Retrieves the operational status of the chassis - Returns: - bool: A boolean value, True if chassis is operating properly - False if not - """ - return True - - def get_position_in_parent(self): - """ - Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position - for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned - Returns: - integer: The 1-based relative physical position in parent device or -1 if cannot determine the position - """ - return -1 - - def is_replaceable(self): - """ - Indicate whether this device is replaceable. - Returns: - bool: True if it is replaceable. - """ - return False - - def initizalize_system_led(self): - return True - - def get_status_led(self): - """ - Gets the state of the system LED - - Returns: - A string, one of the valid LED color strings which could be vendor - specified. - """ - return 'green' - - def set_status_led(self, color): - return False -############################################## -# Chassis methods -############################################## - - def get_base_mac(self): - """ - Retrieves the base MAC address for the chassis - - Returns: - A string containing the MAC address in the format - 'XX:XX:XX:XX:XX:XX' - """ - base_mac = '' - sys_eeprom = self.get_eeprom() - if sys_eeprom is None: - return '' - - e = sys_eeprom.read_eeprom() - base_mac = sys_eeprom.base_mac_addr(e) - if base_mac is None: - return '' - - return base_mac.upper() - - def get_system_eeprom_info(self): - """ - Retrieves the full content of system EEPROM information for the chassis - - Returns: - A dictionary where keys are the type code defined in - OCP ONIE TlvInfo EEPROM format and values are their corresponding - values. - Ex. { '0x21':'AG9064', '0x22':'V1.0', '0x23':'AG9064-0109867821', - '0x24':'001c0f000fcd0a', '0x25':'02/03/2018 16:22:00', - '0x26':'01', '0x27':'REV01', '0x28':'AG9064-C2358-16G'} - """ - sys_eeprom_dict = dict() - sys_eeprom = self.get_eeprom() - if sys_eeprom is None: - return {} - - e = sys_eeprom.read_eeprom() - if sys_eeprom._TLV_HDR_ENABLED: - if not sys_eeprom.is_valid_tlvinfo_header(e): - return {} - total_len = (e[9] << 8) | e[10] - tlv_index = sys_eeprom._TLV_INFO_HDR_LEN - tlv_end = sys_eeprom._TLV_INFO_HDR_LEN + total_len - else: - tlv_index = sys_eeprom.eeprom_start - tlv_end = sys_eeprom._TLV_INFO_MAX_LEN - - while (tlv_index + 2) < len(e) and tlv_index < tlv_end: - if not sys_eeprom.is_valid_tlv(e[tlv_index:]): - break - - tlv = e[tlv_index:tlv_index + 2 + e[tlv_index + 1]] - name, value = sys_eeprom.decoder(None, tlv) - sys_eeprom_dict[name] = value - - if e[tlv_index] == sys_eeprom._TLV_CODE_QUANTA_CRC or \ - e[tlv_index] == sys_eeprom._TLV_CODE_CRC_32: - break - tlv_index += e[tlv_index + 1] + 2 - - return sys_eeprom_dict - - def get_thermal_manager(self): - """ - Retrieves thermal manager class on this chassis - :return: A class derived from ThermalManagerBase representing the - specified thermal manager. ThermalManagerBase is returned as default - """ - return False - - def get_reboot_cause(self): - """ - Retrieves the cause of the previous reboot - Returns: - A tuple (string, string) where the first element is a string - containing the cause of the previous reboot. This string must be - one of the predefined strings in this class. If the first string - is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used - to pass a description of the reboot cause. - """ - return (None, None) - - def get_module(self, index): - """ - Retrieves module represented by (0-based) index - - Args: - index: An integer, the index (0-based) of the module to - retrieve - - Returns: - An object dervied from ModuleBase representing the specified - module - """ - module = None - - try: - if self.get_num_modules(): - module = self._module_list[index] - except IndexError: - sys.stderr.write("Module index {} out of range (0-{})\n".format( - index, len(self._module_list)-1)) - - return module - - def get_fan_drawer(self, index): - """ - Retrieves fan drawers represented by (0-based) index - - Args: - index: An integer, the index (0-based) of the fan drawer to - retrieve - - Returns: - An object dervied from FanDrawerBase representing the specified fan - drawer - """ - fan_drawer = None - - try: - if self.get_num_fan_drawers(): - fan_drawer = self._fan_drawer_list[index] - except IndexError: - sys.stderr.write("Fan drawer index {} out of range (0-{})\n".format( - index, len(self._fan_drawer_list)-1)) - - return fan_drawer - - def get_change_event(self, timeout=0): - """ - Returns a nested dictionary containing all devices which have - experienced a change at chassis level - - Args: - timeout: Timeout in milliseconds (optional). If timeout == 0, - this method will block until a change is detected. - - Returns: - (bool, dict): - - bool: True if call successful, False if not; - - dict: A nested dictionary where key is a device type, - value is a dictionary with key:value pairs in the format of - {'device_id':'device_event'}, where device_id is the device ID - for this device and device_event. - The known devices's device_id and device_event was defined as table below. - ----------------------------------------------------------------- - device | device_id | device_event | annotate - ----------------------------------------------------------------- - 'fan' '' '0' Fan removed - '1' Fan inserted - - 'sfp' '' '0' Sfp removed - '1' Sfp inserted - '2' I2C bus stuck - '3' Bad eeprom - '4' Unsupported cable - '5' High Temperature - '6' Bad cable - - 'voltage' '' '0' Vout normal - '1' Vout abnormal - -------------------------------------------------------------------- - Ex. {'fan':{'0':'0', '2':'1'}, 'sfp':{'11':'0', '12':'1'}, - 'voltage':{'U20':'0', 'U21':'1'}} - Indicates that: - fan 0 has been removed, fan 2 has been inserted. - sfp 11 has been removed, sfp 12 has been inserted. - monitored voltage U20 became normal, voltage U21 became abnormal. - Note: For sfp, when event 3-6 happened, the module will not be avalaible, - XCVRD shall stop to read eeprom before SFP recovered from error status. - """ - - change_event_dict = {"fan": {}, "sfp": {}, "voltage": {}} - - start_time = time.time() - forever = False - - if timeout == 0: - forever = True - elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs - else: - print("get_change_event:Invalid timeout value", timeout) - return False, change_event_dict - - end_time = start_time + timeout - if start_time > end_time: - print( - "get_change_event:" "time wrap / invalid timeout value", - timeout, - ) - return False, change_event_dict # Time wrap or possibly incorrect timeout - try: - while timeout >= 0: - # check for sfp - sfp_change_dict = self.get_transceiver_change_event() - # check for fan - # fan_change_dict = self.get_fan_change_event() - # check for voltage - # voltage_change_dict = self.get_voltage_change_event() - - if sfp_change_dict: - change_event_dict["sfp"] = sfp_change_dict - # change_event_dict["fan"] = fan_change_dict - # change_event_dict["voltage"] = voltage_change_dict - return True, change_event_dict - if forever: - time.sleep(1) - else: - timeout = end_time - time.time() - if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity - else: - if timeout > 0: - time.sleep(timeout) - return True, change_event_dict - except Exception as e: - print(e) - print("get_change_event: Should not reach here.") - return False, change_event_dict - - def get_transceiver_change_event(self): - current_port_dict = {} - ret_dict = {} - - # Check for OIR events and return ret_dict - for index in range(0, NUM_PORT + 1): - if self._sfp_list[index].get_presence(): - current_port_dict[index] = self.STATUS_INSERTED - else: - current_port_dict[index] = self.STATUS_REMOVED - - if len(self.port_dict) == 0: # first time - self.port_dict = current_port_dict - return {} - - if current_port_dict == self.port_dict: - return {} - - # Update reg value - for index, status in current_port_dict.items(): - if self.port_dict[index] != status: - ret_dict[index] = status - #ret_dict[str(index)] = status - self.port_dict = current_port_dict - for index, status in ret_dict.items(): - if int(status) == 1: - pass - #self._sfp_list[int(index)].check_sfp_optoe_type() - return ret_dict diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/component.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/component.py deleted file mode 100755 index be84ca63d6..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/component.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python - -try: - import subprocess - from sonic_platform_base.component_base import ComponentBase - import sonic_platform.hwaccess as hwaccess -except ImportError as e: - raise ImportError(str(e) + "- required module not found") - -def get_cpld_version(bus, i2caddr): - return '{}{}{}{}'.format(hwaccess.i2c_get(bus, i2caddr, 1), - hwaccess.i2c_get(bus, i2caddr, 2), - hwaccess.i2c_get(bus, i2caddr, 3), - hwaccess.i2c_get(bus, i2caddr, 0) - ) - -def get_cpu_cpld_version(): - return get_cpld_version(2, 0x0d) - -def get_cpld1_version(): - return get_cpld_version(3, 0x30) - -COMPONENT_LIST= [ - ['CPU CPLD', - 'cpu board', - get_cpu_cpld_version - ], - - ['MAC1 CPLD', - 'mac1 board', - get_cpld1_version - ] - ] - -class Component(ComponentBase): - """ Ragile Platform-specific Component class""" - - def __init__(self, component_index=0): - ComponentBase.__init__(self) - self.index = component_index - - def get_name(self): - """ - Retrieves the name of the component - - Returns: - A string containing the name of the component - """ - return COMPONENT_LIST[self.index][0] - - def get_description(self): - """ - Retrieves the description of the component - - Returns: - A string containing the description of the component - """ - return COMPONENT_LIST[self.index][1] - - def get_firmware_version(self): - """ - Retrieves the firmware version of the component - - Returns: - A string containing the firmware version of the component - """ - return COMPONENT_LIST[self.index][2]() - - def install_firmware(self, image_path): - """ - Installs firmware to the component - - Args: - image_path: A string, path to firmware image - - Returns: - A boolean, True if install was successful, False if not - """ - try: - successtips = "CPLD Upgrade succeeded!" - status, output = subprocess.getstatusoutput("which firmware_upgrade") - if status or len(output) <= 0: - logger.error("no upgrade tool.") - return False - cmdstr = "%s %s cpld %d cpld"%(output,image_path,self.slot) - ret, log = subprocess.getstatusoutput(cmdstr) - if ret == 0 and successtips in log: - return True - logger.error("upgrade failed. ret:%d, log:\n%s" % (ret, log)) - except Exception as e: - logger.error(str(e)) - return False - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/eeprom.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/eeprom.py deleted file mode 100644 index af5da656b7..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/eeprom.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -try: - from sonic_eeprom import eeprom_tlvinfo - import binascii -except ImportError as e: - raise ImportError(str(e) + "- required module not found") - -class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): - """Platform-specific Eeprom class""" - - def __init__(self): - eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" - if eeprom_path is None: - raise ValueError("get eeprom path failed") - - super(Eeprom, self).__init__(eeprom_path, 0, "", True) - - - def modelnumber(self, e): - ''' - Returns the value field of the model(part) number TLV as a string - ''' - (is_valid, t) = self.get_tlv_field(e, self._TLV_CODE_PART_NUMBER) - if not is_valid: - return super(Eeprom, self).part_number_str(e) - - return t[2].decode("ascii") - - def deviceversion(self, e): - ''' - Returns the value field of the Device Version as a string - ''' - (is_valid, t) = self.get_tlv_field(e, self._TLV_CODE_DEVICE_VERSION) - if not is_valid: - return "N/A" - - return str(ord(t[2])) diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/fan.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/fan.py deleted file mode 100644 index 3548ee0b46..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/fan.py +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/env python - -import time - -try: - from sonic_platform_base.fan_base import FanBase - from .redfish_api import Redfish_Api -except ImportError as e: - raise ImportError(str(e) + "- required module not found") - -FAN_NAME_LIST = ["1", "2"] - -class Fan(FanBase): - """Platform-specific Fan class""" - - def __init__(self, fan_tray_index, fan_index=0): - self.fan_index = fan_index - self.fan_tray_index = fan_tray_index - self.redfish = Redfish_Api() - self.pinf = {} - self._fan_list = [] - FanBase.__init__(self) - self.begin = time.time() - - def get_power_3s(self): - self.elapsed = time.time() - if not self.pinf or self.elapsed - self.begin >= 3: - self.begin = time.time() - self.pinf = self.redfish.get_thermal() - - def get_speed_pwm(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fan_tray_index] - speed = output.get("Oem").get("Ragile").get("FanSpeedLevelPercents") - return int(speed) - - def get_speed_rpm(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fan_tray_index] - speed = output.get("Reading") - return int(speed) - - def get_high_critical_threshold(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fan_tray_index] - high = output.get("UpperThresholdFatal") - return int(high) - - def get_low_critical_threshold(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fan_tray_index] - low = output.get("LowerThresholdFatal") - return int(low) - - def set_speed_pwm(self, speed): - post_url = '/redfish/v1/Chassis/1/Thermal/Actions/Oem/Ragile/Fan.SetSpeed' - playload = {} - playload["FanName"] = "Fan0" - playload["FanSpeedLevelPercents"] = str(speed) - return self.redfish.post_odata(post_url, playload) - - def get_status_led(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fan_tray_index] - led = output.get("Oem").get("Ragile").get("IndicatorLEDColor") - return led - - def set_status_led(self, color): - playload = {} - led = {} - led_list = [] - led["IndicatorLEDColor"] = color - led["LEDType"] = "fan" - led_list.append(led) - playload["LEDs"] = led_list - # boardsLed - return self.redfish.post_boardLed(playload) - - def get_direction(self): - return "intake" - - def get_name(self): - fan_name = FAN_NAME_LIST[self.fan_index] - return "Fantray{}_{}".format(self.fan_tray_index+1, fan_name) - - def get_model(self): - """ - Retrieves the part number of the FAN - Returns: - string: Part number of FAN - """ - return 'N/A' - - def get_position_in_parent(self): - """ - Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position - for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned - Returns: - integer: The 1-based relative physical position in parent device or -1 if cannot determine the position - """ - return -1 - - def is_replaceable(self): - """ - Indicate whether this device is replaceable. - Returns: - bool: True if it is replaceable. - """ - return False - - def get_revision(self): - """ - Retrieves the hardware revision of the device - - Returns: - string: Revision value of device - """ - return 'N/A' - - def get_serial(self): - """ - Retrieves the serial number of the FAN - Returns: - string: Serial number of FAN - """ - return 'N/A' - - def get_presence(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fan_tray_index] - state = output.get("Status").get("Status").get("State") - if state == "Enabled" or state == "UnavailableOffline": - return True - return False - - def get_status(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fan_tray_index] - if output.get("Status").get("Status").get("Health") == "OK": - return True - return False - - def get_speed(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fan_tray_index] - speed = output.get("Reading") - speed_percentage = round((speed*100)/17500) - if speed_percentage > 100: - speed_percentage = 100 - return speed_percentage - else: - return speed_percentage - - def get_speed_tolerance(self): - """ - Retrieves the speed tolerance of the fan - Returns: - An integer, the percentage of variance from target speed which is - considered tolerable - """ - return 30 - - def get_target_speed(self): - """ - Retrieves the target (expected) speed of the fan - Returns: - An integer, the percentage of full fan speed, in the range 0 (off) - to 100 (full speed) - """ - return self.get_speed_pwm() diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/fan_drawer.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/fan_drawer.py deleted file mode 100755 index 95010bf7e9..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/fan_drawer.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -import time - -try: - from sonic_platform_base.fan_drawer_base import FanDrawerBase - from sonic_platform.fan import Fan - from .redfish_api import Redfish_Api -except ImportError as e: - raise ImportError(str(e) + "- required module not found") - - -class FanDrawer(FanDrawerBase): - - FANS_PER_FANTRAY = 1 - - def __init__(self, fantray_index=0): - FanDrawerBase.__init__(self) - self.fantrayindex = fantray_index - self.redfish = Redfish_Api() - self.pinf = {} - self.begin = time.time() - for i in range(self.FANS_PER_FANTRAY): - self._fan_list.append(Fan(fantray_index, i)) - - def get_power_3s(self): - self.elapsed = time.time() - if not self.pinf or self.elapsed - self.begin >= 3: - self.begin = time.time() - self.pinf = self.redfish.get_thermal() - - def get_name(self): - return "FanTray{}".format(self.fantrayindex+1) - - def get_presence(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fantrayindex] - state = output.get("Status").get("Status").get("State") - if state == "Enabled" or state == "UnavailableOffline": - return True - return False - - def get_model(self): - """ - Retrieves the part number of the FAN - Returns: - string: Part number of FAN - """ - return 'N/A' - - def get_serial(self): - """ - Retrieves the serial number of the FAN - Returns: - string: Serial number of FAN - """ - return 'N/A' - - def get_revision(self): - """ - Retrieves the hardware revision of the device - - Returns: - string: Revision value of device - """ - return 'N/A' - - def get_status(self): - """ - Retrieves the operational status of the FAN - Returns: - bool: True if FAN is operating properly, False if not - """ - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fantrayindex] - if output.get("Status").get("Status").get("Health") == "OK": - return True - return False - - def get_position_in_parent(self): - """ - Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position - for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned - Returns: - integer: The 1-based relative physical position in parent device or -1 if cannot determine the position - """ - return -1 - - def is_replaceable(self): - """ - Indicate whether this device is replaceable. - Returns: - bool: True if it is replaceable. - """ - return False - - def get_status_led(self): - self.get_power_3s() - ctrl = self.pinf["Fans"] - output = ctrl[self.fantrayindex] - led = output.get("Oem").get("Ragile").get("IndicatorLEDColor") - return led - - def set_status_led(self, color): - playload = {} - led = {} - led_list = [] - led["IndicatorLEDColor"] = color - led["LEDType"] = "fan" - led_list.append(led) - playload["LEDs"] = led_list - # boardsLed - return self.redfish.post_boardLed(playload) - - def get_maximum_consumed_power(self): - """ - Retrives the maximum power drawn by Fan Drawer - - Returns: - A float, with value of the maximum consumable power of the - component. - """ - return 'N/A' diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/hwaccess.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/hwaccess.py deleted file mode 100755 index 7a04e766ae..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/hwaccess.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python - -import struct -import mmap -import subprocess - -# Read PCI device - -def pci_mem_read(mm, offset): - mm.seek(offset) - read_data_stream = mm.read(4) - return struct.unpack('I',read_data_stream)[0] - -def pci_get_value(resource, offset): - with open(resource, 'r+b') as fd: - mm = mmap.mmap(fd.fileno(), 0) - val = pci_mem_read(mm, offset) - mm.close() - return val - -def pci_mem_write(memmap, offset, data): - """ Write PCI device """ - memmap.seek(offset) - memmap.write(struct.pack('I', data)) - -def pci_set_value(resource, val, offset): - """ Set a value to PCI device """ - with open(resource, 'w+b') as filed: - memmap = None - try: - memmap = mmap.mmap(filed.fileno(), 0) - pci_mem_write(memmap, offset, val) - except EnvironmentError: - print("error") - if memmap is not None: - memmap.close() - -# Read I2C device - -def i2c_get(bus, i2caddr, ofs): - try: - valx = int(subprocess.check_output(['/usr/sbin/i2cget','-f', '-y', str(bus), str(i2caddr), str(ofs)]), 16) - return "{:02x}".format(valx) - except (FileNotFoundError, subprocess.CalledProcessError): - return -1 - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/platform.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/platform.py deleted file mode 100644 index 7225a71b03..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/platform.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python - -try: - from sonic_platform_base.platform_base import PlatformBase - from sonic_platform.chassis import Chassis -except ImportError as e: - raise ImportError(str(e) + "- required module not found") - - -class Platform(PlatformBase): - - def __init__(self): - PlatformBase.__init__(self) - self._chassis = Chassis() - diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/psu.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/psu.py deleted file mode 100644 index 256b3b79f1..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/psu.py +++ /dev/null @@ -1,231 +0,0 @@ -#!/usr/bin/env python - -import time -import imp -import os -import sys - -try: - from sonic_platform_base.psu_base import PsuBase - from .redfish_api import Redfish_Api -except ImportError as e: - raise ImportError("%s - required module not found" % e) - -class Psu(PsuBase): - """Platform-specific Psu class""" - - def __init__(self, index=0): - PsuBase.__init__(self) - self.redfish = Redfish_Api() - self.pinf = {} - self.psu_index = index - self._fan_list = [] - self._thermal_list = [] - self.begin = time.time() - - def get_power_3s(self): - self.elapsed = time.time() - if not self.pinf or self.elapsed - self.begin >= 3: - self.begin = time.time() - self.pinf = self.redfish.get_power() - - def get_presence(self): - return True - - def get_fan(self, index): - """ - Retrieves fan module represented by (0-based) index - - Args: - index: An integer, the index (0-based) of the fan module to - retrieve - - Returns: - An object dervied from FanBase representing the specified fan - module - """ - return None - - def get_powergood_status(self): - self.get_power_3s() - ctrl = self.pinf["PowerSupplies"] - output = ctrl[self.psu_index] - if output.get("Status").get("Health") == "OK": - return True - else: - return False - - def get_name(self): - """ - Retrieves the name of the device - - Returns: - string: The name of the device - """ - return "PSU {}".format(self.psu_index + 1) - - def get_serial(self): - self.get_power_3s() - ctrl = self.pinf["PowerSupplies"] - output = ctrl[self.psu_index] - serial = output.get("SerialNumber") - return serial - - def get_model(self): - self.get_power_3s() - ctrl = self.pinf["PowerSupplies"] - output = ctrl[self.psu_index] - model = output.get("Model") - return model - - def get_revision(self): - self.get_power_3s() - ctrl = self.pinf["PowerSupplies"] - output = ctrl[self.psu_index] - manufacturer = output.get("Manufacturer") - return manufacturer - - def get_voltage(self): - self.get_power_3s() - ctrl = self.pinf["PowerSupplies"] - output = ctrl[self.psu_index] - voltage = output.get("Oem").get("Ragile").get("OutputVoltage") - return voltage - - def get_input_current(self): - self.get_power_3s() - ctrl = self.pinf["PowerSupplies"] - output = ctrl[self.psu_index] - current = output.get("Oem").get("Ragile").get("OutputAmperage") - return current - - def get_input_voltage(self): - self.get_power_3s() - ctrl = self.pinf["PowerSupplies"] - output = ctrl[self.psu_index] - voltage = output.get("Oem").get("Ragile").get("OutputVoltage") - return voltage - - def get_current(self): - self.get_power_3s() - ctrl = self.pinf["PowerSupplies"] - output = ctrl[self.psu_index] - current = output.get("Oem").get("Ragile").get("OutputAmperage") - return current - - def get_power(self): - self.get_power_3s() - ctrl = self.pinf["PowerSupplies"] - output = ctrl[self.psu_index] - current = output.get("Oem").get("Ragile").get("OutputAmperage") - voltage = output.get("Oem").get("Ragile").get("OutputVoltage") - power = float(current)*float(voltage) - return round(power,2) - - def get_temperature(self): - """ - Retrieves current temperature reading from PSU - - Returns: - A float number of current temperature in Celsius up to nearest thousandth - of one degree Celsius, e.g. 30.125 - """ - # no temperature sensor - value = 35 - return round(float(value), 1) - - def get_status_led(self): - return "BuildIn" - - def set_status_led(self, color): - playload = {} - led = {} - led_list = [] - led["IndicatorLEDColor"] = color - led["LEDType"] = "pwr" - led_list.append(led) - playload["LEDs"] = led_list - # boardsLed - return self.redfish.post_boardLed(playload) - - def get_maximum_supplied_power(self): - """ - Retrieves the maximum supplied power by PSU - - Returns: - A float number, the maximum power output in Watts. - e.g. 1200.1 - """ - return False - - def get_position_in_parent(self): - """ - Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position - for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned - Returns: - integer: The 1-based relative physical position in parent device or -1 if cannot determine the position - """ - return -1 - - def is_replaceable(self): - """ - Indicate whether this device is replaceable. - Returns: - bool: True if it is replaceable. - """ - return False - - def get_status(self): - """ - Retrieves the operational status of the PSU - - Returns: - bool: True if PSU is operating properly, False if not - """ - return self.get_powergood_status() - - def get_temperature_high_threshold(self): - """ - Retrieves the high threshold temperature of PSU - - Returns: - A float number, the high threshold temperature of PSU in Celsius - up to nearest thousandth of one degree Celsius, e.g. 30.125 - """ - value = 75 - return round(float(value), 1) - - def get_voltage_high_threshold(self): - """ - Retrieves the high threshold PSU voltage output - - Returns: - A float number, the high threshold output voltage in volts, - e.g. 12.1 - """ - value = 14.52 - return str(round(float(value), 2)) - - def get_voltage_low_threshold(self): - """ - Retrieves the low threshold PSU voltage output - - Returns: - A float number, the low threshold output voltage in volts, - e.g. 12.1 - """ - value = 9.72 - return str(round(float(value), 2)) - - def get_thermal(self, index): - """ - Retrieves thermal unit represented by (0-based) index - - Args: - index: An integer, the index (0-based) of the thermal to - retrieve - - Returns: - An object dervied from ThermalBase representing the specified thermal - """ - return None diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/redfish_api.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/redfish_api.py deleted file mode 100755 index 28ba1025d5..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/redfish_api.py +++ /dev/null @@ -1,304 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -import shlex -import json -import os -import ssl -import subprocess -import syslog - -class Redfish_Api(): - BmcBaseUrl = 'http://240.1.1.1:8080' - ThermalUrl = '/redfish/v1/Chassis/1/Thermal' - PowerUrl = '/redfish/v1/Chassis/1/Power' - ThresholdSensorsUrl = '/redfish/v1/Chassis/1/ThresholdSensors' - FanSpeedUrl = '/redfish/v1/Chassis/1/Thermal/Actions/Oem/Ragile/Fan.SetSpeed' - BoardsUrl = '/redfish/v1/Chassis/1/Boards/' - BoardLedUrl = "/redfish/v1/Chassis/1/Boards/{}/Actions/Oem/Ragile/Boards.SetLED" - - # Maximum time in seconds that you allow the connection to the server to take. - connect_timeout = 30 - # Maximum time in seconds that you allow the whole operation to take - operation_timeout = 300 - - default_prefix='/redfish/v1/' - session = None - __DEBUG__ = "N" - __DUMP_RESP__ = "N" - RST_STATUS = "status" - RST_SUCCESS = "OK" - refish_logger = None - - def redfish_log_debug(self, msg): - if (self.__DEBUG__ == "Y"): - syslog.openlog("redfis_api") - syslog.syslog(syslog.LOG_DEBUG, msg) - syslog.closelog() - - def redfish_log_error(self, msg): - syslog.openlog("redfish_api") - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - def __init__(self): - pass - - def get_full_url(self, url): - return self.BmcBaseUrl + url - - def _exec_cmd(self, cmd): - self.redfish_log_debug("Cmd: %s" % cmd) - p = subprocess.Popen(shlex.split(cmd), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - p.wait() - self.redfish_log_debug("Cmd return: %d" % p.returncode) - str_stdout = p.stdout.read().decode('utf-8') - str_stderr = p.stderr.read().decode('utf-8') - self.redfish_log_debug("Cmd stdout: %s" % str_stdout) - if p.returncode !=0: - self.redfish_log_error("Cmd: %s, failed! error msg:%s" % (cmd, str_stderr)) - return None - else: - try: - ret = json.loads(str_stdout) - return ret - except Exception as e: - self.redfish_log_error("Cmd: %s, failed! stdout msg:%s" % (cmd, str_stdout)) - return None - - def _redfish_get(self, url): - self.redfish_log_debug("Get info from %s." % url) - result = None - try: - cmd_get="curl --connect-timeout %d -m %d -X GET %s" % (self.connect_timeout, self.operation_timeout, self.get_full_url(url)) - result = self._exec_cmd(cmd_get) - return result - except Exception as e: - self.redfish_log_error("error_message: %s" % e) - return None - - def _redfish_post(self, url, playload): - self.redfish_log_debug("post url: %s" % url) - self.redfish_log_debug("Playload: %s" % playload) - - playload_json = json.dumps(playload) - result = False - try: - cmd_post="curl --connect-timeout %d -m %d -X POST %s -d \'%s\'" % (self.connect_timeout, self.operation_timeout, self.get_full_url(url), playload_json) - ret_msg = self._exec_cmd(cmd_post) - if ret_msg == None: - return False - elif ret_msg["success"] == False: - redfish_log_error("Url: '%s', Playload: '%s', Bmc return failed, error_message: %s" % (url, playload_json, ret_msg["Message"])) - result = False - else: - result = True - return result - except Exception as e: - redfish_log_error("error_message: %s" % e) - return False - - def get_thermal(self): - """Get thermal info - :returns: class 'redfish.rest.v1.RestResponse' or None when failed - """ - return self._redfish_get(self.ThermalUrl) - - def get_power(self): - """Get power info - :returns: class 'redfish.rest.v1.RestResponse' or None when failed - """ - return self._redfish_get(self.PowerUrl) - - def get_thresholdSensors(self): - """Get thresholdSensors info - :returns: class 'redfish.rest.v1.RestResponse' or None when failed - """ - return self._redfish_get(self.ThresholdSensorsUrl) - - def post_odata(self, odata_id, playload): - """post odata info - :params odata_id: the specified odata_id path - :type odata_id: string - :playload: info to post - :type: dictionary - :returns: True or False - """ - if odata_id is None or playload is None: - print("post failed: odata_id or playload is None") - return False - return self._redfish_post(odata_id, playload) - - def get_odata(self, odata_id): - """Get odata info - :params odata_id: the specified odata_id path - :type odata_id: string - :returns: class 'redfish.rest.v1.RestResponse' or None when failed - """ - if odata_id is None: - print("Get odata_id failed: odata_id is None") - return None - return self._redfish_get(odata_id) - - def post_fanSpeed(self, playload): - """post odata info - :playload: info to post - :type: dictionary - :returns: True or False - """ - if playload is None: - print("post failed: playload is None") - return False - return self._redfish_post(self.FanSpeedUrl, playload) - - def get_board(self, board_name="indicatorboard"): - """Get board info - :board_name: name of board, default is "indicatorboard" - :type: string - :returns: class'redfish.rest.v1.RestResponse' or None when failed - """ - if board_name is None : - print("get failed: board_name is None") - return None - return self._redfish_get(self.BoardsUrl + board_name) - - def post_boardLed(self, playload, board_name="indicatorboard"): - """post boardLed info - :board_name: name of board, default is "indicatorboard" - :type: string - :playload: info to post - :type: dictionary - :returns: True or False - """ - if board_name is None or playload is None: - print("post failed: playload is None") - return False - return self._redfish_post(self.BoardLedUrl.format(board_name), playload) - - ''' not supported currently - def post_thermal(self, playload): - """post thermal info - :playload: info to post - :type: dictionary - :returns: True or False - """ - if playload is None: - print("post_thermal failed: playload is None") - return None - return self._redfish_post(self.ThermalUrl, playload) - - def post_power(self, playload): - """post power info - :playload: info to post - :type: dictionary - :returns: True or False - """ - if playload is None: - print("post_power failed: playload is None") - return None - return self._redfish_post(self.PowerUrl, playload) - - def post_thresholdSensors(self, playload): - """post thresholdSensors info - :playload: info to post - :type: dictionary - :returns: True or False - """ - if playload is None: - print("post_thresholdSensors failed: playload is None") - return None - return self._redfish_post(self.ThresholdSensorsUrl, playload) - - def get_fanSpeed(self): - """Get board led info - :returns: class'redfish.rest.v1.RestResponse' or None when failed - """ - return self._redfish_get(self.FanSpeedUrl) - - def post_board(self, playload, board_name="indicatorboard"): - """post board info - :board_name: name of board, default is "indicatorboard" - :type: string - :playload: info to post - :type: dictionary - :returns: True or False - """ - if board_name is None or playload is None: - print("post failed: playload is None") - return False - return self._redfish_post(self.BoardsUrl + board_name, playload) - - def get_boardLed(self, board_name="indicatorboard"): - """Get boardLed info - :board_name: name of board, default is "indicatorboard" - :type: string - :returns: class'redfish.rest.v1.RestResponse' or None when failed - """ - if board_name is None : - print("get failed: board_name is None") - return None - return self._redfish_get(self.BoardsUrl % board_name) - - ''' - -''' -if __name__ == '__main__': - redfish = Redfish_Api() - - ### get - # boards - ret = redfish.get_board() - if ret is None: - print("get failed: board") - else: - print("get succeeded, board:%s" % ret) - - ret = redfish.get_thresholdSensors() - if ret is None: - print("get failed: threshold") - else: - print("get succeeded, threshold:%s" % ret) - - ret = redfish.get_power() - if ret is None: - print("get failed: power") - else: - print("get succeeded, power:%s" % ret) - - ret = redfish.get_thermal() - if ret is None: - print("get failed:thermal") - else: - print("get succeeded,thermal:%s" % ret) - - # get playload - resp = redfish.get_thresholdSensors() - if (resp != None): - print(resp["@odata.id"]) - print(resp["@odata.type"]) - print(resp["Id"]) - print(resp["Name"]) - else: - print("Failed: get_thresholdSensors") - - ### post - # fanSpeed - playload = {} - playload["FanName"] = 'Fan0' - playload["FanSpeedLevelPercents"] = "70" - print("post fanSpeed:%s" % redfish.post_fanSpeed(playload)) - - #{"LEDs": [{"IndicatorLEDColor": "green","LEDType": "sys"},{"IndicatorLEDColor": "off","LEDType": "pwr"},{"IndicatorLEDColor": "green","LEDType": "fan"}]} - playload = {} - led = {} - led1 = {} - led_list = [] - led["IndicatorLEDColor"] = "green" - led["LEDType"] = "sys" - led1["IndicatorLEDColor"] = "off" - led1["LEDType"] = "pwr" - led_list.append(led) - led_list.append(led1) - playload["LEDs"] = led_list - # boardsLed - print("post boardLed:%s" % redfish.post_boardLed(playload)) -''' diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/sfp.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/sfp.py deleted file mode 100644 index 29dd0cb079..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/sfp.py +++ /dev/null @@ -1,325 +0,0 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- - -############################################################################# -# -# Module contains an implementation of SONiC Platform Base API and -# provides the platform information -# -# -# *_device.py config version instruction: -# ver 1.0 - platform api: -# "presence_cpld": { -# "dev_id": { -# [dev_id]: { -# "offset": { -# [offset]: [port_id] -# } -# } -# } -# } -# "reset_cpld": { -# "dev_id": { -# [dev_id]: { -# "offset": { -# [offset]: [port_id] -# } -# } -# } -# } -# ver 2.0 - wb_plat: -# "presence_path": "/xx/wb_plat/xx[port_id]/present" -# "eeprom_path": "/sys/bus/i2c/devices/i2c-[bus]/[bus]-0050/eeprom" -# "reset_path": "/xx/wb_plat/xx[port_id]/reset" -############################################################################# -import sys -import time -import os -import syslog -import traceback -from abc import abstractmethod - -configfile_pre = "/usr/local/bin/" -sys.path.append(configfile_pre) - -try: - from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase - -except ImportError as error: - raise ImportError(str(error) + "- required module not found") from error - -LOG_DEBUG_LEVEL = 1 -LOG_WARNING_LEVEL = 2 -LOG_ERROR_LEVEL = 3 - - -class Sfp(SfpOptoeBase): - - OPTOE_DRV_TYPE1 = 1 - OPTOE_DRV_TYPE2 = 2 - OPTOE_DRV_TYPE3 = 3 - - # index must start at 1 - def __init__(self, index): - SfpOptoeBase.__init__(self) - self.sfp_type = None - self.log_level_config = LOG_WARNING_LEVEL - # Init instance of SfpCust - self._sfp_api = SfpV2(index) - - def get_eeprom_path(self): - return self._sfp_api._get_eeprom_path() - - def read_eeprom(self, offset, num_bytes): - return self._sfp_api.read_eeprom(offset, num_bytes) - - def write_eeprom(self, offset, num_bytes, write_buffer): - return self._sfp_api.write_eeprom(offset, num_bytes, write_buffer) - - def get_presence(self): - return self._sfp_api.get_presence() - - def get_transceiver_info(self): - # temporary solution for a sonic202111 bug - transceiver_info = super().get_transceiver_info() - try: - if transceiver_info["vendor_rev"] is not None: - transceiver_info["hardware_rev"] = transceiver_info["vendor_rev"] - except BaseException: - print(traceback.format_exc()) - return None - return transceiver_info - - def set_optoe_write_max(self, write_max): - """ - This func is declared and implemented by SONiC but we're not supported - so override it as NotImplemented - """ - self._sfplog(LOG_DEBUG_LEVEL, "set_optoe_write_max NotImplemented") - - def refresh_xcvr_api(self): - """ - Updates the XcvrApi associated with this SFP - """ - self._xcvr_api = self._xcvr_api_factory.create_xcvr_api() - class_name = self._xcvr_api.__class__.__name__ - optoe_type = None - # set sfp_type - if 'CmisApi' in class_name: - self.sfp_type = 'QSFP-DD' - optoe_type = self.OPTOE_DRV_TYPE3 - elif 'Sff8472Api' in class_name: - self.sfp_type = 'SFP' - optoe_type = self.OPTOE_DRV_TYPE2 - elif ('Sff8636Api' in class_name or 'Sff8436Api' in class_name): - self.sfp_type = 'QSFP' - optoe_type = self.OPTOE_DRV_TYPE1 - # set optoe driver - if optoe_type is not None: - self._sfp_api.set_optoe_type(optoe_type) - - def _sfplog(self, log_level, msg): - if log_level >= self.log_level_config: - try: - syslog.openlog("Sfp") - if log_level == LOG_DEBUG_LEVEL: - syslog.syslog(syslog.LOG_DEBUG, msg) - elif log_level == LOG_WARNING_LEVEL: - syslog.syslog(syslog.LOG_DEBUG, msg) - elif log_level == LOG_ERROR_LEVEL: - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - except BaseException: - print(traceback.format_exc()) - - -class SfpCust(): - def __init__(self, index): - self.eeprom_path = None - self._init_config(index) - - def _init_config(self, index): - self.log_level_config = LOG_WARNING_LEVEL - self._port_id = index - self.eeprom_retry_times = 5 - self.eeprom_retry_break_sec = 0.2 - - def _get_eeprom_path(self): - return self.eeprom_path or None - - @abstractmethod - def get_presence(self): - pass - - def read_eeprom(self, offset, num_bytes): - try: - for i in range(self.eeprom_retry_times): - with open(self._get_eeprom_path(), mode='rb', buffering=0) as f: - f.seek(offset) - result = f.read(num_bytes) - # temporary solution for a sonic202111 bug - if len(result) < num_bytes: - result = result[::-1].zfill(num_bytes)[::-1] - if result is not None: - return bytearray(result) - time.sleep(self.eeprom_retry_break_sec) - continue - - except BaseException: - self._sfplog(LOG_ERROR_LEVEL, traceback.format_exc()) - return None - - def write_eeprom(self, offset, num_bytes, write_buffer): - try: - for i in range(self.eeprom_retry_times): - ret = SfpOptoeBase.write_eeprom(self, offset, num_bytes, write_buffer) - if ret is False: - time.sleep(self.eeprom_retry_break_sec) - continue - break - - return ret - except BaseException: - self._sfplog(LOG_ERROR_LEVEL, traceback.format_exc()) - return False - - @abstractmethod - def set_optoe_type(self, optoe_type): - pass - - @abstractmethod - def set_reset(self, reset): - pass - - def _convert_str_range_to_int_arr(self, range_str): - if not range_str: - return [] - - int_range_strs = range_str.split(',') - range_res = [] - for int_range_str in int_range_strs: - if '-' in int_range_str: - range_s = int(int_range_str.split('-')[0]) - range_e = int(int_range_str.split('-')[1]) + 1 - else: - range_s = int(int_range_str) - range_e = int(int_range_str) + 1 - - range_res = range_res + list(range(range_s, range_e)) - - return range_res - - def _sfplog(self, log_level, msg): - if log_level >= self.log_level_config: - try: - syslog.openlog("SfpCust") - if log_level == LOG_DEBUG_LEVEL: - syslog.syslog(syslog.LOG_DEBUG, msg) - elif log_level == LOG_WARNING_LEVEL: - syslog.syslog(syslog.LOG_DEBUG, msg) - elif log_level == LOG_ERROR_LEVEL: - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - except BaseException: - print(traceback.format_exc()) - - -class SfpV2(SfpCust): - def _init_config(self, index): - super()._init_config(index) - # init eeprom path - sfp_pt2ee_path_list = [0] * 53 - sfp_pt2ee_path_list[49:53] = [9, 10, 11, 12] - - eeprom_path_config = "/sys/bus/i2c/devices/i2c-%d/%d-0050/eeprom" - eeprom_path_key = sfp_pt2ee_path_list[self._port_id] - self.eeprom_path = None if eeprom_path_config is None or eeprom_path_key == 0 else eeprom_path_config % ( - eeprom_path_key, eeprom_path_key) - self._sfplog(LOG_DEBUG_LEVEL, "Done init eeprom path: %s" % self.eeprom_path) - - # init presence path - self.presence_path = "/sys/bus/i2c/devices/3-0030/sfp_presence1" - self.presence_val_is_present = 0 - self._sfplog(LOG_DEBUG_LEVEL, "Done init presence path: %s" % self.presence_path) - - # init optoe driver path - optoe_driver_path = "/sys/bus/i2c/devices/i2c-%d/%d-0050/dev_class" - optoe_driver_key = sfp_pt2ee_path_list[self._port_id] - self.dev_class_path = None if optoe_driver_path is None or optoe_driver_key == 0 else optoe_driver_path % ( - optoe_driver_key, optoe_driver_key) - self._sfplog(LOG_DEBUG_LEVEL, "Done init optoe driver path: %s" % self.dev_class_path) - - # init reset path - self.reset_val_is_reset = 0 - - new_device_path = "/sys/bus/i2c/devices/i2c-%d/new_device" - new_device_key = sfp_pt2ee_path_list[self._port_id] - self.new_class_path = None if new_device_path is None or new_device_key == 0 else new_device_path % new_device_key - self._sfplog(LOG_DEBUG_LEVEL, "Done init new_class path: %s" % self.new_class_path) - - if sfp_pt2ee_path_list[self._port_id] != 0: - self.add_new_sfp_device(self._port_id, 0x50) - self._sfplog(LOG_DEBUG_LEVEL, "Done add_new_sfp_device 0x50 port %d" % self._port_id) - - def sfp_add_dev(self, new_device_path, devaddr, devtype): - try: - # Write device address to new_device file - nd_file = open(new_device_path, "w") - nd_str = "%s %s" % (devtype, hex(devaddr)) - nd_file.write(nd_str) - nd_file.close() - except Exception as err: - self._sfplog(LOG_ERROR_LEVEL, ("Error writing to new device file: %s" % str(err))) - return 1 - else: - return 0 - - def add_new_sfp_device(self, port_num, devid): - if os.path.exists(self.dev_class_path): - return - - ret = self.sfp_add_dev(self.new_class_path, devid, "optoe2") - if ret != 0: - self._sfplog(LOG_ERROR_LEVEL, "Error adding sfp device") - - def get_presence(self): - sfp_ls = [49, 50, 51, 52] - if self._port_id not in sfp_ls or self.presence_path is None: - self._sfplog(LOG_ERROR_LEVEL, "presence_path is None!") - return False - try: - with open(self.presence_path, "rb") as data: - presence_data = data.read(2) - if presence_data == "": - return False - result = int(presence_data, 16) - - # ModPrsL is active low - presence_offset = sfp_ls.index(self._port_id) - if result & (1 << presence_offset) == 0: - return True - return False - except BaseException: - self._sfplog(LOG_ERROR_LEVEL, traceback.format_exc()) - return False - - def set_reset(self, reset): - return True - - def set_optoe_type(self, optoe_type): - if self.dev_class_path is None: - self._sfplog(LOG_ERROR_LEVEL, "dev_class_path is None!") - return False - try: - with open(self.dev_class_path, "r+") as dc_file: - dc_file_val = dc_file.read(1) - if int(dc_file_val) != optoe_type: - dc_str = "%s" % str(optoe_type) - dc_file.write(dc_str) - # dc_file.close() - except BaseException: - self._sfplog(LOG_ERROR_LEVEL, traceback.format_exc()) - return False - return True diff --git a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/thermal.py b/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/thermal.py deleted file mode 100644 index 5fded8d9dd..0000000000 --- a/platform/centec-arm64/sonic-platform-modules-ragile/ra-b6010-48gt4x/sonic_platform/thermal.py +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env python - -import os -import re -import os.path -import time - -try: - from sonic_platform_base.thermal_base import ThermalBase - from .redfish_api import Redfish_Api -except ImportError as e: - raise ImportError(str(e) + "- required module not found") - - -class Thermal(ThermalBase): - """Platform-specific Thermal class""" - - def __init__(self, thermal_index): - ThermalBase.__init__(self) - self.index = thermal_index - self.high_threshold = float(112) - self.redfish = Redfish_Api() - self.pinf = {} - self.begin = time.time() - - def get_power_3s(self): - self.elapsed = time.time() - if not self.pinf or self.elapsed - self.begin >= 3: - self.begin = time.time() - self.pinf = self.redfish.get_thermal() - - def get_temperature(self): - self.get_power_3s() - ctrl = self.pinf["Temperatures"] - output = ctrl[self.index] - temp = output.get("ReadingCelsius") - return temp - - def get_high_threshold(self): - self.get_power_3s() - ctrl = self.pinf["Temperatures"] - output = ctrl[self.index] - temp = output.get("UpperThresholdFatal") - return temp - - def get_low_threshold(self): - self.get_power_3s() - ctrl = self.pinf["Temperatures"] - output = ctrl[self.index] - temp = output.get("LowerThresholdFatal") - return temp - - def get_high_critical_threshold(self): - self.get_power_3s() - ctrl = self.pinf["Temperatures"] - output = ctrl[self.index] - temp = output.get("UpperThresholdFatal") - return temp - - def get_low_critical_threshold(self): - self.get_power_3s() - ctrl = self.pinf["Temperatures"] - output = ctrl[self.index] - temp = output.get("LowerThresholdFatal") - return temp - - def get_name(self): - self.get_power_3s() - ctrl = self.pinf["Temperatures"] - output = ctrl[self.index].get("Name") - name = output.split("/",3)[2] - if name == "SWITCH_TEMP": - name = "ASIC_TEMP" - return "{}".format(name) - - def get_real_name(self): - self.get_power_3s() - ctrl = self.pinf["Temperatures"] - output = ctrl[self.index].get("Name") - name = output.split("/",3)[2] - return "{}".format(name) - - def get_presence(self): - self.get_power_3s() - ctrl = self.pinf["Temperatures"] - output = ctrl[self.index] - if output.get("Status").get("Status").get("State") == "Enabled": - return True - return False - - def get_status(self): - self.get_power_3s() - ctrl = self.pinf["Temperatures"] - output = ctrl[self.index] - if output.get("Status").get("Status").get("Health") == "OK": - return True - return False - - def set_sys_led(self, color): - playload = {} - led = {} - led_list = [] - led["IndicatorLEDColor"] = color - led["LEDType"] = "sys" - led_list.append(led) - playload["LEDs"] = led_list - # boardsLed - return self.redfish.post_boardLed(playload) - - def get_minimum_recorded(self): - """ - Retrieves the minimum recorded temperature of thermal - - Returns: - A float number, the minimum recorded temperature of thermal in Celsius - up to nearest thousandth of one degree Celsius, e.g. 30.125 - """ - return "N/A" - - def get_maximum_recorded(self): - """ - Retrieves the maximum recorded temperature of thermal - - Returns: - A float number, the maximum recorded temperature of thermal in Celsius - up to nearest thousandth of one degree Celsius, e.g. 30.125 - """ - return "N/A" - - def get_model(self): - """ - Retrieves the model number (or part number) of the Thermal - - Returns: - string: Model/part number of Thermal - """ - return "N/A" - - def get_serial(self): - """ - Retrieves the serial number of the Thermal - - Returns: - string: Serial number of Thermal - """ - return "N/A" - - def get_revision(self): - """ - Retrieves the hardware revision of the device - - Returns: - string: Revision value of device - """ - return "N/A" - - def get_position_in_parent(self): - """ - Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position - for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned - Returns: - integer: The 1-based relative physical position in parent device or -1 if cannot determine the position - """ - return -1 - - def is_replaceable(self): - """ - Indicate whether this device is replaceable. - Returns: - bool: True if it is replaceable. - """ - return False diff --git a/platform/centec-arm64/sonic_fit.its b/platform/centec-arm64/sonic_fit.its index a953f67f77..0f96550c88 100644 --- a/platform/centec-arm64/sonic_fit.its +++ b/platform/centec-arm64/sonic_fit.its @@ -48,18 +48,6 @@ algo = "crc32"; }; }; - ctc_fdtb6010 { - description = "dtb for ra-b6010-48gt4x-r0"; - data = /incbin/("./ra-b6010-48gt4x-r0.dtb"); - type = "flat_dt"; - arch = "arm64"; - os = "linux"; - compression = "none"; - load = <0x88000000>; - hash { - algo = "crc32"; - }; - }; }; configurations { default = "arm64-centec_e530_24x2c-r0"; @@ -98,12 +86,5 @@ ramdisk = "initramfs"; fdt = "ctc_fdt"; }; - - arm64-ragile_ra-b6010-48gt4x-r0 { - description = "config for ragile_ra-b6010-48gt4x"; - kernel = "kernel_ctc"; - ramdisk = "initramfs"; - fdt = "ctc_fdtb6010"; - }; }; }; diff --git a/platform/centec-arm64/tsingma-bsp/debian/rules b/platform/centec-arm64/tsingma-bsp/debian/rules index 88167489cc..39744906e3 100755 --- a/platform/centec-arm64/tsingma-bsp/debian/rules +++ b/platform/centec-arm64/tsingma-bsp/debian/rules @@ -17,7 +17,6 @@ KERNEL_SRC := /lib/modules/$(KVERSION) MOD_SRC_DIR:= $(shell pwd) MODULE_DIRS:= ctc5236-mc ctc5236_switch ctcmac ctc_wdt ehci-ctc gpio-ctc i2c-ctc pinctrl-ctc pwm-ctc rtc-sd2405 sdhci-ctc5236 spi-ctc-qspi ctc-phy DTS_DIR := ctc-dts -DTS_DIR0 := ra-b6010-48gt4x MODULE_DIR := src UTILS_DIR := utils SERVICE_DIR := service @@ -37,7 +36,6 @@ build: make modules -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$(MODULE_DIR)/$${mod}; \ done) make -C $(MOD_SRC_DIR)/$(MODULE_DIR)/$(DTS_DIR) - make -C $(MOD_SRC_DIR)/$(MODULE_DIR)/$(DTS_DIR0) binary: binary-arch binary-indep # Nothing to do diff --git a/platform/centec-arm64/tsingma-bsp/debian/tsingma-bsp.install b/platform/centec-arm64/tsingma-bsp/debian/tsingma-bsp.install index 5914f9f1ce..e072cb1751 100644 --- a/platform/centec-arm64/tsingma-bsp/debian/tsingma-bsp.install +++ b/platform/centec-arm64/tsingma-bsp/debian/tsingma-bsp.install @@ -13,6 +13,5 @@ src/rtc-sd2405/rtc-sd2405.ko /lib/modules/5.10.0-18-2-arm64/kernel/extra src/sdhci-ctc5236/sdhci-ctc5236.ko /lib/modules/5.10.0-18-2-arm64/kernel/extra src/spi-ctc-qspi/spi-ctc-qspi.ko /lib/modules/5.10.0-18-2-arm64/kernel/extra src/ctc-dts/e530-ctc5236.dtb /boot/ -src/ra-b6010-48gt4x/ra-b6010-48gt4x-r0.dtb /boot/ src/config/fw_env.config /etc/ src/config/tsingma-bsp.service /lib/systemd/system diff --git a/platform/centec-arm64/tsingma-bsp/src/ctcmac/ctcmac.c b/platform/centec-arm64/tsingma-bsp/src/ctcmac/ctcmac.c index 277b41c2ab..ea28b561ec 100755 --- a/platform/centec-arm64/tsingma-bsp/src/ctcmac/ctcmac.c +++ b/platform/centec-arm64/tsingma-bsp/src/ctcmac/ctcmac.c @@ -1736,8 +1736,7 @@ static bool ctcmac_new_page(struct ctcmac_priv_rx_q *rxq, struct page *page; dma_addr_t addr; - //page = dev_alloc_page(); - page = __dev_alloc_pages(GFP_DMA | GFP_ATOMIC | __GFP_NOWARN, 0); + page = dev_alloc_page(); if (unlikely(!page)) return false; diff --git a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/Makefile b/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/Makefile deleted file mode 100755 index 8808f1d78b..0000000000 --- a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -ra-b6010-48gt4x-r0.dtb: ra-b6010-48gt4x-r0.dts ctc5236.dtsi ctc5236-clock.dtsi - cpp -nostdinc -I. -undef -x assembler-with-cpp ra-b6010-48gt4x-r0.dts > tmp.dts - dtc -O dtb -o ra-b6010-48gt4x-r0.dtb tmp.dts - rm tmp.dts -rf - \ No newline at end of file diff --git a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/arm-gic.h b/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/arm-gic.h deleted file mode 100755 index ef79498bdd..0000000000 --- a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/arm-gic.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 OR MIT */ -/* - * This header provides constants for the ARM GIC. - */ - -#ifndef _DT_BINDINGS_INTERRUPT_CONTROLLER_ARM_GIC_H -#define _DT_BINDINGS_INTERRUPT_CONTROLLER_ARM_GIC_H - -#include "irq.h" - -/* interrupt specifier cell 0 */ - -#define GIC_SPI 0 -#define GIC_PPI 1 - -/* - * Interrupt specifier cell 2. - * The flags in irq.h are valid, plus those below. - */ -#define GIC_CPU_MASK_RAW(x) ((x) << 8) -#define GIC_CPU_MASK_SIMPLE(num) GIC_CPU_MASK_RAW((1 << (num)) - 1) - -#endif diff --git a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ctc5236-clks.h b/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ctc5236-clks.h deleted file mode 100755 index 56d91da313..0000000000 --- a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ctc5236-clks.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * ctc5236 clock tree IDs - * - * (C) Copyright 2004-2017 Centec Networks (suzhou) Co., LTD. - * - * Jay Cao - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * This program is distributed "as is" WITHOUT ANY WARRANTY of any - * kind, whether express or implied; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef __CTC5236_CLKS_H -#define __CTC5236_CLKs_H - -#define CLKID_UNUSED 0 -#define CLKID_PLL_FIXED 1 -#define CLKID_UART0 2 - -#endif /* __CTC5236_CLKS_H */ diff --git a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ctc5236-clock.dtsi b/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ctc5236-clock.dtsi deleted file mode 100755 index ae6b00c00b..0000000000 --- a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ctc5236-clock.dtsi +++ /dev/null @@ -1,63 +0,0 @@ -/* - * dts file for Centec CTC5236(TsingMa) SoC - * - * (C) Copyright 2004-2017 Centec Networks (suzhou) Co., LTD. - * - * Jay Cao - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - */ - - osc: oscillator { - #clock-cells = <0>; - compatible = "fixed-clock"; - clock-frequency = <50000000>; - }; - - sup_clk: sup_clk_12m { - #clock-cells = <0>; - compatible = "fixed-clock"; - clock-frequency = <1200000000>; - clock-output-names = "sup_clk"; - }; - - uart_clk: uart_clk_20m { - #clock-cells = <0>; - compatible = "fixed-clock"; - clock-frequency = <20000000>; - clock-output-names = "uart_clk"; - }; - - i2c_clk: clkm { - #clock-cells = <0>; - compatible = "fixed-clock"; - clock-frequency = <50000000>; - clock-output-names = "i2c_clk"; - }; - wdog_clk:wdog_clk{ - #clock-cells = <0>; - compatible = "fixed-clock"; - clock-frequency = <1000000>; - clock-output-names = "wdog_clk"; - }; - timer_clk:timer_clk{ - #clock-cells = <0>; - compatible = "fixed-clock"; - clock-frequency = <500000000>; - clock-output-names = "timer_clk"; - }; - mmc_clk:mmc_clk{ - #clock-cells = <0>; - compatible = "fixed-clock"; - clock-frequency = <100000000>; - clock-output-names = "mmc_clk"; - }; - spi_clk:spi_clk{ - #clock-cells = <0>; - compatible = "fixed-clock"; - clock-frequency = <100000000>; - clock-output-names = "spi_clk"; - }; diff --git a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ctc5236.dtsi b/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ctc5236.dtsi deleted file mode 100755 index bacf2eb17d..0000000000 --- a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ctc5236.dtsi +++ /dev/null @@ -1,428 +0,0 @@ -/* - * dts file for Centec CTC5236(TsingMa) SoC - * - * (C) Copyright 2004-2017 Centec Networks (suzhou) Co., LTD. - * - * Jay Cao - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - */ - -#include "arm-gic.h" -#include "ctc5236-clks.h" -#include "../pinctrl-ctc/pinctrl-ctc.h" - -/ { - compatible = "centec,ctc5236"; - #address-cells = <2>; - #size-cells = <2>; - interrupt-parent = <&gic>; - - cpus { - #address-cells = <2>; - #size-cells = <0>; - - cpu-map { - cluster0 { - core0 { - cpu = <&cpu0>; - }; - core1 { - cpu = <&cpu1>; - }; - }; - }; - - cpu0: cpu@0 { - device_type = "cpu"; - compatible = "arm,cortex-a53", "arm,armv8"; - reg = <0 0x000>; - enable-method = "spin-table"; - cpu-release-addr = <0 0x0010fff0>; - }; - - cpu1: cpu@1 { - device_type = "cpu"; - compatible = "arm,cortex-a53", "arm,armv8"; - reg = <0 0x001>; - enable-method = "spin-table"; - cpu-release-addr = <0 0x0010fff0>; - }; - }; - - gic: interrupt-controller@31201000 { - compatible = "arm,gic-400"; - #interrupt-cells = <3>; - interrupt-controller; - reg = <0x0 0x31201000 0 0x1000>, - <0x0 0x31202000 0 0x2000>, - <0x0 0x31204000 0 0x2000>, - <0x0 0x31206000 0 0x2000>; - interrupts = ; - }; - - timer { - compatible = "arm,armv8-timer"; - interrupt-parent = <&gic>; - interrupts = , - , - , - ; - }; - - soc: soc { - compatible = "simple-bus"; - #address-cells = <2>; - #size-cells = <2>; - ranges; - - #include "ctc5236-clock.dtsi" - ocram: sram@00100000 { - compatible = "mmio-sram"; - reg = <0x0 0x00100000 0x0 0x10000>; - }; - - memory-controller@30600000 { - compatible = "ctc,ctc5236-ddr-ctrl"; - reg = <0x0 0x30600000 0x0 0x100000>; - interrupts = , - , - , - ; - ctc,sysctrl = <&sysctrl>; - }; - - sysctrl: sysctrl@33200000 { - compatible = "ctc,ctc5236-sysctrl", "syscon"; - reg = <0x0 0x33200000 0x0 0x100000>; - little-endian; - }; - - serial0: serial@33000000 { - compatible = "arm,pl011","arm,primecell"; - reg = <0x0 0x33000000 0x0 0x1000>; - interrupts = ; - clocks = <&uart_clk>, <&sup_clk>; - clock-names = "uart_clk", "apb_pclk"; - status="disabled"; - }; - serial1: serial@33001000 { - compatible = "arm,pl011","arm,primecell"; - reg = <0x0 0x33001000 0x0 0x1000>; - interrupts = ; - clocks = <&uart_clk>, <&sup_clk>; - clock-names = "uart_clk", "apb_pclk"; - status="disabled"; - }; - serial2: serial@33002000 { - compatible = "arm,pl011","arm,primecell"; - reg = <0x0 0x33002000 0x0 0x1000>; - interrupts = ; - clocks = <&uart_clk>, <&sup_clk>; - clock-names = "uart_clk", "apb_pclk"; - status="disabled"; - }; - mdio: mdio@33620000 { - compatible = "ctc,mdio"; - reg = <0x0 0x33620000 0x0 0x10000>; - #address-cells = <1>; - #size-cells = <0>; - status = "disabled"; - }; - - enet0: ethernet@33410000 { - compatible = "ctc,mac"; - device_type = "network"; - #address-cells = <2>; - #size-cells = <2>; - interrupt-parent = <&gic>; - status = "disabled"; - local-mac-address = [00 00 00 00 00 00]; - index = <0x00>; - reg = <0x0 0x33410000 0x0 0x10000>, - <0x0 0x33400000 0x0 0x10000>; - interrupts = , - , - , - , - ; - ctc,sysctrl = <&sysctrl>; - }; - - enet1: ethernet@33420000 { - compatible = "ctc,mac"; - device_type = "network"; - #address-cells = <2>; - #size-cells = <2>; - interrupt-parent = <&gic>; - status = "disabled"; - local-mac-address = [00 00 00 00 00 00]; - index = <0x01>; - reg = <0x0 0x33420000 0x0 0x10000>, - <0x0 0x33400000 0x0 0x10000>; - interrupts = , - , - , - , - ; - ctc,sysctrl = <&sysctrl>; - }; - - ehci0: usb@30500000 { - compatible = "ctc-ehci"; - reg = <0x0 0x30500000 0x0 0x1000>; - interrupts = ; - ctc,sysctrl = <&sysctrl>; - status = "disabled"; - }; - - ohci0: usb@30580000 { - compatible = "generic-ohci"; - reg = <0x0 0x30580000 0x0 0x1000>; - interrupts = ; - status = "disabled"; - }; - - spi: spi@33100000 { - compatible = "arm,pl022","arm,primecell"; - #address-cells = <1>; - #size-cells = <0>; - reg = <0x0 0x33100000 0x0 0x100000>; - clocks = <&spi_clk>, <&sup_clk>; - clock-names = "spi_clk", "apb_pclk"; - num-cs = <4>; - interrupts = ; - ctc,sysctrl = <&sysctrl>; - status ="disabled"; - }; - - qspi: qspi@10000000 { - compatible = "ctc, igdaxi001a-qspi"; - #address-cells = <1>; - #size-cells = <0>; - reg = <0x0 0x10000000 0x0 0x10000>; - pclk = <500000000>; - num-cs = <2>; - idle-cycle = <2>; - post-cycle = <1>; - pre-cycle = <2>; - interrupts = ; - status = "disabled"; - }; - switch: switch@31100000 { - compatible = "centec,dal-localbus"; - reg = <0x0 0x31100000 0x0 0x1000>, - <0x0 0x33290000 0x0 0x10000>; - interrupts = , - , - , - , - , - , - , - ; - status ="disabled"; - }; - switch1: switch1@31101000 { - compatible = "centec,switch"; - reg = <0x0 0x31101000 0x0 0x1000>; - status ="disabled"; - }; - - i2c0: i2c0@33700000{ - compatible = "ctc,i2c"; - #address-cells = <1>; - #size-cells = <0>; - reg = <0x0 0x33700000 0x0 0x1000>; - interrupts = ; - clocks = <&i2c_clk>; - ctc,sysctrl = <&sysctrl>; - i2c-num = <0>; - status ="disabled"; - }; - - i2c1: i2c1@33701000{ - compatible = "ctc,i2c"; - #address-cells = <1>; - #size-cells = <0>; - reg = <0x0 0x33701000 0x0 0x1000>; - interrupts = ; - clocks = <&i2c_clk>; - ctc,sysctrl = <&sysctrl>; - i2c-num = <1>; - status ="disabled"; - }; - - pcie: pcie@20000000 { - compatible = "centec,ctc5236-pcie"; - reg = <0x0 0x20000000 0x0 0x10000000 - 0x0 0x30000000 0x0 0x1000>; - reg-names = "cfg", "ctrl"; - #address-cells = <3>; - #size-cells = <2>; - #interrupt-cells = <1>; - device_type = "pci"; - interrupt-parent = <&gic>; - interrupts = , - , - ; - interrupt-names = "msi","aer","pme"; - msi-parent = <&pcie>; - bus-range = <0 0xff>; - ranges = <0x42000000 0 0x00000000 0 0x40000000 0 0x20000000 - 0x02000000 0 0x20000000 0 0x60000000 0 0x20000000>; - num-lanes = <1>; - ctc,sysctrl = <&sysctrl>; - status ="disabled"; - }; - - wtd0: wtd0@33500000{ - compatible = "arm,sp805-wdt", "arm,primecell"; - #address-cells = <1>; - #size-cells = <0>; - reg = <0x0 0x33500000 0x0 0x1000>; - clocks = <&wdog_clk>, <&sup_clk>; - clock-names = "wdog_clk", "apb_pclk"; - ctc,sysctrl = <&sysctrl>; - interrupts = ; - status="disabled"; - }; - wtd1: wtd1@33501000{ - compatible = "arm,sp805-wdt", "arm,primecell"; - #address-cells = <1>; - #size-cells = <0>; - reg = <0x0 0x33501000 0x0 0x1000>; - clocks = <&wdog_clk>, <&sup_clk>; - clock-names = "wdog_clk", "apb_pclk"; - ctc,sysctrl = <&sysctrl>; - interrupts = ; - status="disabled"; - }; - - sdhci: sdhci@30400000 { - compatible = "centec,ctc5236-sdhci"; - status = "disabled"; - interrupt-parent = <&gic>; - interrupts = ; - clocks = <&mmc_clk>; - clock-names = "mmc_clk"; - ctc,sysctrl = <&sysctrl>; - reg = <0x0 0x30400000 0x0 0x1000>; - }; - - timer0: timer0@33600000{ - compatible = "snps,dw-apb-timer"; - reg = <0x0 0x33600000 0x0 0x20>; - clocks = <&timer_clk>; - clock-names = "timer"; - interrupts = ; - DivNum = <0x3c>; - status="disabled"; - }; - timer1: timer1@33600020{ - compatible = "snps,dw-apb-timer"; - reg = <0x0 0x33600020 0x0 0x20>; - clocks = <&timer_clk>; - clock-names = "timer"; - interrupts = ; - DivNum = <0x3c>; - status="disabled"; - }; - - pwm: pwm@33200240{ - compatible = "centec-pwm"; - ctc,sysctrl = <&sysctrl>; - #pwm-cells = <2>; - - status="disabled"; - }; - - fan: fan-ctc5236 { - compatible = "fan-ctc5236"; - pwms = <&pwm 0 1000000>, - <&pwm 1 1000000>, - <&pwm 2 1000000>, - <&pwm 3 1000000>; - pwm-names = "pwm1","pwm2","pwm3","pwm4"; - }; - - gpio0: gpio@33610000 { - compatible = "ctc,apb-gpio"; - reg = <0x0 0x33610000 0x0 0x10000>; - #address-cells = <1>; - #size-cells = <0>; - ctc,sysctrl = <&sysctrl>; - - porta: gpio-port@0 { - compatible = "ctc,apb-gpio-porta"; - gpio-controller; - #gpio-cells = <2>; - ctc,nr-gpios = <16>; - reg = <0>; - interrupt-controller; - #interrupt-cells = <2>; - interrupts = ; - }; - portb: gpio-port@1 { - compatible = "ctc,apb-gpio-portb"; - gpio-controller; - #gpio-cells = <2>; - ctc,nr-gpios = <18>; - reg = <1>; - interrupt-controller; - #interrupt-cells = <2>; - interrupts = ; - }; - }; - - pinctrl: pinctrl { - compatible = "ctc,ctc5236-pinctrl"; - #address-cells = <0x2>; - #size-cells = <0x2>; - ctc,pinctrl-bank0 = <16>; - ctc,pinctrl-bank1 = <8>; - ctc,sysctrl = <&sysctrl>; - - spi { - spi_pin: spi_pin { - ctc,pins = <0 0 PIN_FUNC_SPI>, - <0 2 PIN_FUNC_SPI>, - <0 3 PIN_FUNC_SPI>, - <0 4 PIN_FUNC_SPI>, - <0 5 PIN_FUNC_SPI>, - <0 6 PIN_FUNC_SPI>, - <0 7 PIN_FUNC_SPI>; - }; - }; - - uart2 { - uart2_pin: uart2_pin { - ctc,pins = <0 10 PIN_FUNC_UART>, - <0 11 PIN_FUNC_UART>, - <0 12 PIN_FUNC_UART>, - <0 13 PIN_FUNC_UART>, - <0 14 PIN_FUNC_UART>, - <0 15 PIN_FUNC_UART>; - }; - }; - - fc { - fc_pin: fc_pin { - ctc,pins = <1 0 PIN_FUNC_FC>, - <1 1 PIN_FUNC_FC>, - <1 2 PIN_FUNC_FC>, - <1 3 PIN_FUNC_FC>, - <1 4 PIN_FUNC_FC>, - <1 5 PIN_FUNC_FC>, - <1 6 PIN_FUNC_FC>, - <1 7 PIN_FUNC_FC>; - }; - }; - }; - }; - -}; - diff --git a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/irq.h b/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/irq.h deleted file mode 100755 index 9e3d183e13..0000000000 --- a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/irq.h +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 OR MIT */ -/* - * This header provides constants for most IRQ bindings. - * - * Most IRQ bindings include a flags cell as part of the IRQ specifier. - * In most cases, the format of the flags cell uses the standard values - * defined in this header. - */ - -#ifndef _DT_BINDINGS_INTERRUPT_CONTROLLER_IRQ_H -#define _DT_BINDINGS_INTERRUPT_CONTROLLER_IRQ_H - -#define IRQ_TYPE_NONE 0 -#define IRQ_TYPE_EDGE_RISING 1 -#define IRQ_TYPE_EDGE_FALLING 2 -#define IRQ_TYPE_EDGE_BOTH (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING) -#define IRQ_TYPE_LEVEL_HIGH 4 -#define IRQ_TYPE_LEVEL_LOW 8 - -#endif diff --git a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ra-b6010-48gt4x-r0.dts b/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ra-b6010-48gt4x-r0.dts deleted file mode 100755 index 2a68ecb8d9..0000000000 --- a/platform/centec-arm64/tsingma-bsp/src/ra-b6010-48gt4x/ra-b6010-48gt4x-r0.dts +++ /dev/null @@ -1,328 +0,0 @@ -/* - * dts file for Centec CTC5236(TsingMa) SoC E530-24X2C Board - * - * (C) Copyright 2004-2018 Centec Networks (suzhou) Co., LTD. - * - * liuht - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - */ - -/dts-v1/; -#include "ctc5236.dtsi" - -/ { - model = " CTC5236(TsingMa) E530 Board"; - compatible = "ctc5236,e530-ctc5236"; - - memory@0 { - device_type = "memory"; - reg = <0 0x80000000 0x1 0x00000000>; - }; - - chosen { - stdout-path = "serial0:115200n8"; - }; - - aliases { - serial0 = &serial0; - serial1 = &serial1; - ethernet0 = &enet0; - ethernet1 = &enet1; - - i2c0 = &i2c1; - /* 0 0x70 */ - i2c1 = &imux1; - i2c2 = &imux2; - i2c3 = &imux3; - i2c4 = &imux4; - i2c5 = &imux5; - i2c6 = &imux6; - i2c7 = &imux7; - i2c8 = &imux8; - /* 8 0x74 */ - i2c9 = &imux9; - i2c10 = &imux10; - i2c11 = &imux11; - i2c12 = &imux12; - i2c13 = &imux13; - i2c14 = &imux14; - i2c15 = &imux15; - i2c16 = &imux16; - }; - -}; - -&serial0 { - status = "okay"; -}; - -&serial1 { - status = "okay"; -}; - -&mdio { - status = "okay"; - phy0: ethernet-phy@0 { - index = <0x00>; - reg = <0x00>; - }; -}; - -&enet0 { - status = "okay"; - phy-handle = <&phy0>; - auto-nego-mode= "sgmii-mac"; -}; - -&qspi { - status = "okay"; - - qspiflash0: mx25u3235f@0 { - compatible = "jedec,spi-nor"; - reg = <0x0>; - spi-cpha; - spi-cpol; - spi-max-frequency = <25000000>; - - partitions { - compatible = "fixed-partitions"; - #address-cells = <1>; - #size-cells = <1>; - - partition@0 { - label = "u-boot"; - reg = <0x0 0x300000>; - }; - partition@300000 { - label = "uboot-env"; - reg = <0x300000 0x10000>; - }; - partition@310000 { - label = "onie"; - reg = <0x310000 0x1cf0000>; - }; - }; - }; - - qspiflash1: mx25u3235f@1 { - compatible = "jedec,spi-nor"; - reg = <0x1>; - spi-cpha; - spi-cpol; - spi-max-frequency = <25000000>; - - partitions { - compatible = "fixed-partitions"; - #address-cells = <1>; - #size-cells = <1>; - - partition@0 { - label = "u-boot1"; - reg = <0x0 0x300000>; - }; - partition@300000 { - label = "uboot1-env"; - reg = <0x300000 0x10000>; - }; - partition@310000 { - label = "onie1"; - reg = <0x310000 0x1cf0000>; - }; - }; - }; -}; - -&spi { - status = "disabled"; - pinctrl-names = "default"; - pinctrl-0 = <&spi_pin>; - - clock0: ad9559@1 { - compatible = "analog,ad9559"; - reg = <1>; - spi-max-frequency = <25000000>; - }; -}; - -&switch { - status = "okay"; -}; - -&switch1 { - status = "okay"; -}; - - -&i2c1{ - status = "okay"; - clock-frequency = <95000>; - - pca9548@70 { - compatible = "nxp,pca9548"; - reg = <0x70>; - #address-cells = <1>; - #size-cells = <0>; - - imux1:i2c@0 { - reg = <0>; - }; - imux2:i2c@1 { - #address-cells = <1>; - #size-cells = <0>; - reg = <1>; - }; - imux3:i2c@2 { - #address-cells = <1>; - #size-cells = <0>; - reg = <2>; - }; - imux4:i2c@3 { - #address-cells = <1>; - #size-cells = <0>; - reg = <3>; - }; - imux5:i2c@4 { - #address-cells = <1>; - #size-cells = <0>; - reg = <4>; - }; - imux6:i2c@5 { - #address-cells = <1>; - #size-cells = <0>; - reg = <5>; - }; - imux7:i2c@6 { - #address-cells = <1>; - #size-cells = <0>; - reg = <6>; - }; - imux8:i2c@7 { - #address-cells = <1>; - #size-cells = <0>; - reg = <7>; - pca9548@74 { - #address-cells = <1>; - #size-cells = <0>; - compatible = "nxp,pca9548"; - reg = <0x74>; - imux9:i2c@0 { - #address-cells = <1>; - #size-cells = <0>; - reg = <0>; - }; - imux10:i2c@1 { - #address-cells = <1>; - #size-cells = <0>; - reg = <1>; - }; - imux11:i2c@2 { - #address-cells = <1>; - #size-cells = <0>; - reg = <2>; - }; - imux12:i2c@3 { - #address-cells = <1>; - #size-cells = <0>; - reg = <3>; - }; - imux13:i2c@4 { - #address-cells = <1>; - #size-cells = <0>; - reg = <4>; - }; - imux14:i2c@5 { - #address-cells = <1>; - #size-cells = <0>; - reg = <5>; - }; - imux15:i2c@6 { - #address-cells = <1>; - #size-cells = <0>; - reg = <6>; - }; - imux16:i2c@7 { - #address-cells = <1>; - #size-cells = <0>; - reg = <7>; - }; - }; - }; - }; -}; - -&ehci0 { - status = "okay"; -}; - -&ohci0 { - status = "okay"; -}; - -&wtd0{ - status = "okay"; -}; - -&wtd1{ - status = "disabled"; -}; - -&sdhci { - bus-width = <8>; - max-frequency = <100000000>; - non-removable; - no-sd; - no-sdio; - voltage-ranges = <3300 3300>; - status = "okay"; -}; - -&timer0 { - status = "okay"; -}; - -&soc { - ctc-irq { - compatible = "centec,ctc-irq"; - device_type = "ctc-irq"; - interrupt-parent=<&porta>; - interrupts = < 0 IRQ_TYPE_LEVEL_LOW>, - < 1 IRQ_TYPE_LEVEL_LOW>, - <15 IRQ_TYPE_LEVEL_LOW>, - < 6 IRQ_TYPE_LEVEL_HIGH>, - < 7 IRQ_TYPE_LEVEL_HIGH>; - }; -}; - -&pwm { - status = "disabled"; -}; - - -&pinctrl { - spi { - spi_pin: spi_pin { - status = "disabled"; - ctc,pins = <0 0 PIN_FUNC_SPI>, - <0 2 PIN_FUNC_SPI>, - <0 3 PIN_FUNC_SPI>, - <0 5 PIN_FUNC_SPI>; - }; - }; - - pwm0 { - pwm0_pin: pwm0_pin { - ctc,pins = <0 8 PIN_FUNC_PWM>, - <0 9 PIN_FUNC_PWM>, - <0 10 PIN_FUNC_PWM>, - <0 11 PIN_FUNC_PWM>, - <0 12 PIN_FUNC_PWM>, - <0 13 PIN_FUNC_PWM>, - <0 14 PIN_FUNC_PWM>, - <0 15 PIN_FUNC_PWM>; - }; - }; -};