Skip to content

Commit

Permalink
Dell S6100 Port I2C changes to 201811 branch (#5150)
Browse files Browse the repository at this point in the history
* Dell S6100 Port I2C changes to 201811 branch

* Update s6100_i2c_enumeration.sh
  • Loading branch information
santhosh-kt authored Aug 18, 2020
1 parent e1e9719 commit a2cb920
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 234 deletions.
2 changes: 2 additions & 0 deletions device/dell/x86_64-dell_s6100_c2538-r0/platform_reboot
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python
import sys
import os
import subprocess
import struct

PORT_RES = '/dev/port'
Expand Down Expand Up @@ -28,5 +29,6 @@ if __name__ == "__main__":
print "CPLD upgrade detected. Power-cycling the unit.."
os.system('io_rd_wr.py --set --val 05 --offset 210; io_rd_wr.py --set --val 00 --offset 211; io_rd_wr.py --set --val 03 --offset 213')

subprocess.check_output(['/usr/share/sonic/device/x86_64-dell_s6100_c2538-r0/fast-reboot_plugin'])
portio_reg_write(PORT_RES, 0xcf9, 0xe)

Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
s6100/scripts/iom_power_*.sh usr/local/bin
s6100/scripts/s6100_platform.sh usr/local/bin
s6100/scripts/s6100_i2c_enumeration.sh usr/local/bin
s6100/scripts/s6100_bitbang_reset.sh usr/local/bin
s6100/scripts/pcisysfs.py usr/bin
common/dell_i2c_utils.sh usr/local/bin
common/io_rd_wr.py usr/local/bin
common/fstrim.timer etc/systemd/system
common/fstrim.service etc/systemd/system
s6100/scripts/fast-reboot_plugin usr/share/sonic/device/x86_64-dell_s6100_c2538-r0
s6100/scripts/warm-reboot_plugin usr/share/sonic/device/x86_64-dell_s6100_c2538-r0
common/dell_lpc_mon.sh usr/local/bin
s6100/scripts/platform_sensors.py usr/local/bin
s6100/scripts/platform_watchdog_enable.sh usr/local/bin
s6100/scripts/platform_watchdog_disable.sh usr/local/bin
s6100/scripts/sensors usr/bin
s6100/systemd/platform-modules-s6100.service etc/systemd/system
s6100/systemd/s6100-i2c-enumerate.service etc/systemd/system
s6100/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-dell_s6100_c2538-r0
s6100/systemd/s6100-lpc-monitor.service etc/systemd/system
tools/flashrom/flashrom usr/local/bin/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/usr/local/bin/s6100_i2c_enumeration.sh deinit & > /dev/null
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#! /usr/bin/python

import struct
import sys
import getopt
from os import *
from mmap import *

def usage():
''' This is the Usage Method '''

print '\t\t pcisysfs.py --get --offset <offset> --res <resource>'
print '\t\t pcisysfs.py --set --val <val> --offset <offset> --res <resource>'
sys.exit(1)

def pci_mem_read(mm,offset):
mm.seek(offset)
read_data_stream=mm.read(4)
print ""
reg_val=struct.unpack('I',read_data_stream)
print "reg_val read:%x"%reg_val
return reg_val

def pci_mem_write(mm,offset,data):
mm.seek(offset)
#print "data to write:%x"%data
mm.write(struct.pack('I',data))

def pci_set_value(resource,val,offset):
fd=open(resource,O_RDWR)
mm=mmap(fd,0)
pci_mem_write(mm,offset,val)
close(fd)

def pci_get_value(resource,offset):
fd=open(resource,O_RDWR)
mm=mmap(fd,0)
pci_mem_read(mm,offset)
close(fd)

def main(argv):

''' The main function will read the user input from the
command line argument and process the request '''

opts = ''
val = ''
choice = ''
resource = ''
offset = ''

try:
opts, args = getopt.getopt(argv, "hgsv:" , \
["val=","res=","offset=","help", "get", "set"])

except getopt.GetoptError:
usage()

for opt,arg in opts:

if opt in ('-h','--help'):
choice = 'help'

elif opt in ('-g', '--get'):
choice = 'get'

elif opt in ('-s', '--set'):
choice = 'set'

elif opt == '--res':
resource = arg

elif opt == '--val':
val = int(arg,16)

elif opt == '--offset':
offset = int(arg,16)

if choice == 'set' and val != '' and offset !='' and resource !='':
pci_set_value(resource,val,offset)

elif choice == 'get' and offset != '' and resource !='':
pci_get_value(resource,offset)

else:
usage()

#Calling the main method
if __name__ == "__main__":
main(sys.argv[1:])

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Script to unfreeze a stuck I2C controller, by bit-banging a STOP cycle on the bus

bit_bang_recovery()
{

# Clear the ERRSTS
pcisysfs.py --set --val 0xffffffff --offset 0x018 --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0

#Enable I2C bit-banging
pcisysfs.py --set --val 0x80000000 --offset 0x388 --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0

count=1
while [ $count -le 9 ];
do
# Bit-bang an I2C STOP cycle

# SCL=0, SDA=0
pcisysfs.py --set --val 0x80000000 --offset 0x388 --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0

sleep 0.01

# SCL=1, SDA=0
pcisysfs.py --set --val 0x80000002 --offset 0x388 --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0

sleep 0.01

# SCL=1, SDA=1
pcisysfs.py --set --val 0x80000003 --offset 0x388 --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0

sleep 1

# Check I2C DBSTS register
mctrl=$((`pcisysfs.py --get --offset 0x108 --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0 | sed 's/^.*:/0x/'`))
msts=$((`pcisysfs.py --get --offset 0x10c --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0 | sed 's/^.*:/0x/'`))
dbsts=$((`pcisysfs.py --get --offset 0x38c --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0 | sed 's/^.*:/0x/'`))
msts_ip=$((msts&0x1))

mctrl=$((10#$mctrl))
if [ $msts_ip = 0 ]; then
logger -p NOTICE "I2C_bitbang-Bit banging done on I2C bus"
logger -p NOTICE "After I2C_bitbang- MCTRL:$(printf "0x%x" $mctrl)","MSTS:$(printf "0x%x" $msts)","DBSTS:$(printf "0x%x" $dbsts)"
break
fi
count=$(( $count + 1 ))
done

#Disable I2C bit-banging
pcisysfs.py --set --val 0x00000003 --offset 0x388 --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0

}

mctrl=$((`pcisysfs.py --get --offset 0x108 --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0 | sed 's/^.*:/0x/'`))
msts=$((`pcisysfs.py --get --offset 0x10c --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0 | sed 's/^.*:/0x/'`))
dbsts=$((`pcisysfs.py --get --offset 0x38c --res /sys/devices/pci0000\:00/0000\:00\:13.0/resource0 | sed 's/^.*:/0x/'`))
logger -p NOTICE "Before I2C_bitbang- MCTRL:$(printf "0x%x" $mctrl)","MSTS:$(printf "0x%x" $msts)","DBSTS:$(printf "0x%x" $dbsts)"
sleep 2
bit_bang_recovery
Loading

0 comments on commit a2cb920

Please sign in to comment.