-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DellEMC] S6100-Fix i2C ISMT issue (#4330)
* [DellEMC] S6100-Fix i2C ISMT issue * Modified the retry condition for bit bang
- Loading branch information
1 parent
0409a32
commit a40fe3b
Showing
4 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
platform/broadcom/sonic-platform-modules-dell/s6100/scripts/pcisysfs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:]) | ||
|
59 changes: 59 additions & 0 deletions
59
platform/broadcom/sonic-platform-modules-dell/s6100/scripts/s6100_bitbang_reset.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters