Skip to content

Commit 88370e9

Browse files
committed
Adding VSI devmem cmds back
Signed-off-by: Sayan Bandyopadhyay <[email protected]>
1 parent 67bbe27 commit 88370e9

File tree

1 file changed

+61
-67
lines changed

1 file changed

+61
-67
lines changed

ipu-plugin/pkg/ipuplugin/lifecycleservice.go

Lines changed: 61 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"strings"
2626
"time"
2727

28-
kh "golang.org/x/crypto/ssh/knownhosts"
29-
3028
"github.com/intel/ipu-opi-plugins/ipu-plugin/pkg/p4rtclient"
3129
"github.com/intel/ipu-opi-plugins/ipu-plugin/pkg/types"
3230
"github.com/intel/ipu-opi-plugins/ipu-plugin/pkg/utils"
@@ -140,6 +138,7 @@ type ExecutableHandler interface {
140138
validate() bool
141139
nmcliSetupIpAddress(link netlink.Link, ipStr string, ipAddr *netlink.Addr) error
142140
SetupAccApfs() error
141+
AddAccApfsToGroupOne() error
143142
}
144143

145144
type ExecutableHandlerImpl struct{}
@@ -1000,84 +999,75 @@ func skipIMCReboot() (bool, string) {
1000999

10011000
}
10021001

1003-
// Note: To evaluate, if we really need this api, since it
1004-
// can break, if the format of config changes in cp_init.cfg
1005-
// this api queries the param->acc_apf in /etc/dpcp/cp_init.cfg.
1006-
// The param(acc_apf) appears in 3 lines in that file, and we run
1007-
// the command to fetch the value in the second line.
1008-
func queryNumAccApfsInIMCConfig() (int, error) {
1009-
1010-
log.Infof("queryNumAccApfsInIMCConfig")
1011-
//remove duplicate entries, and ensure host-key(ssh-keyscan) is present.
1012-
sshCmds := "ssh-keygen -R 192.168.0.1; ssh-keyscan 192.168.0.1 >> /root/.ssh/known_hosts"
1013-
1014-
_, err := utils.ExecuteScript(sshCmds)
1015-
if err != nil {
1016-
log.Errorf("error->%v, for ssh key commands->%v", err, sshCmds)
1017-
return 0, fmt.Errorf("error->%v, for ssh key commands->%v", err, sshCmds)
1018-
}
1019-
1020-
hostKeyCallback, err := kh.New("/root/.ssh/known_hosts")
1021-
if err != nil {
1022-
log.Errorf("error->%v, unable to create hostkeycallback function: ", err)
1023-
return 0, fmt.Errorf("error->%v, unable to create hostkeycallback function: ", err)
1024-
}
1025-
1026-
config := &ssh.ClientConfig{
1027-
User: "root",
1028-
Auth: []ssh.AuthMethod{
1029-
ssh.Password(""),
1030-
},
1031-
HostKeyCallback: hostKeyCallback,
1032-
}
1033-
1034-
// Connect to the remote server.
1035-
client, err := ssh.Dial("tcp", imcAddress, config)
1036-
if err != nil {
1037-
return 0, fmt.Errorf("failed to dial remote server: %s", err)
1038-
}
1039-
defer client.Close()
1002+
func (e *ExecutableHandlerImpl) validate() bool {
10401003

1041-
// Start a session.
1042-
session, err := client.NewSession()
1043-
if err != nil {
1044-
return 0, fmt.Errorf("failed to create session: %s", err)
1004+
if noReboot, infoStr := skipIMCReboot(); !noReboot {
1005+
fmt.Printf("IMC reboot required : %v\n", infoStr)
1006+
return false
10451007
}
1046-
defer session.Close()
10471008

1048-
commands := `grep "acc_apf = " /etc/dpcp/cp_init.cfg | sed -n 2p | awk '/acc_apf = / {print $3}'`
1009+
return true
1010+
}
10491011

1050-
// Run a command on the remote server and capture the output.
1051-
outputBytes, err := session.CombinedOutput(commands)
1012+
func (e *ExecutableHandlerImpl) AddAccApfsToGroupOne() error {
1013+
vsiList, err := utils.GetAvailableAccVsiList()
10521014
if err != nil {
1053-
log.Errorf("queryNumAccApfsInIMCConfig: error from command->%v", err)
1054-
return 0, fmt.Errorf("queryNumAccApfsInIMCConfig: error from command->%v", err)
1055-
}
1015+
log.Errorf("AddAccApfsToGroupOne: unable to reach the IMC %v", err)
1016+
return fmt.Errorf("AddAccApfsToGroupOne: unable to reach the IMC %v", err)
1017+
}
1018+
if len(vsiList) == 0 {
1019+
log.Errorf("no APFs initialized on ACC")
1020+
return fmt.Errorf("no APFs initialized on ACC")
1021+
}
1022+
log.Infof("AddAccApfsToGroupOne, vsiList->%v", vsiList)
1023+
/* Steps from script(for reference)
1024+
VSI_GROUP_INIT=$(printf "0x%x" $((0x8000050000000000 + IDPF_VPORT_VSI_HEX)))
1025+
VSI_GROUP_WRITE=$(printf "0x%x" $((0xA000050000000000 + IDPF_VPORT_VSI_HEX)))
1026+
devmem 0x20292002a0 64 ${VSI_GROUP_INIT}
1027+
devmem 0x2029200388 64 0x1
1028+
devmem 0x20292002a0 64 ${VSI_GROUP_WRITE}
1029+
*/
1030+
for i := 0; i < len(vsiList); i++ {
1031+
log.Infof("Add to VSI Group 1, vsi->%v", vsiList[i])
1032+
hexStr := vsiList[i]
1033+
// skip "0x" prefix
1034+
hexStr = hexStr[2:]
1035+
1036+
// Convert to hex value
1037+
hexVal, err := strconv.ParseInt(hexStr, 16, 64)
1038+
if err != nil {
1039+
log.Errorf("error decoding hex: %v", err)
1040+
return fmt.Errorf("error decoding hex: %v", err)
1041+
}
10561042

1057-
outputStr := strings.TrimSuffix(string(outputBytes), "\n")
1058-
//to skip the semicolon, for example, if output is-> 48;
1059-
outputStr = outputStr[:len(outputStr)-1]
1043+
// Check bounds before converting to uint64
1044+
if hexVal < 0 {
1045+
log.Errorf("hex value out of range: %v", hexVal)
1046+
return fmt.Errorf("hex value out of range: %v", hexVal)
1047+
}
10601048

1061-
numAccApfs, err := strconv.Atoi(outputStr)
1049+
var vsiGroupInit, vsiGroupWrite uint64
10621050

1063-
if err != nil {
1064-
log.Errorf("queryNumAccApfsInIMCConfig: Error converting string to int: %v", err)
1065-
return 0, fmt.Errorf("queryNumAccApfsInIMCConfig: Error converting string to int: %v", err)
1066-
}
1067-
log.Infof("queryNumAccApfsInIMCConfig ->%v", numAccApfs)
1051+
vsiGroupInit = 0x8000050000000000 + uint64(hexVal)
1052+
vsiGroupWrite = 0xA000050000000000 + uint64(hexVal)
10681053

1069-
return numAccApfs, nil
1054+
vsiGroupInitString := fmt.Sprintf("0x%X", vsiGroupInit)
1055+
vsiGroupWriteString := fmt.Sprintf("0x%X", vsiGroupWrite)
10701056

1071-
}
1057+
devMemCmd1 := "devmem 0x20292002a0 64 " + vsiGroupInitString
1058+
devMemCmd2 := "devmem 0x2029200388 64 0x1"
1059+
devMemCmd3 := "devmem 0x20292002a0 64 " + vsiGroupWriteString
10721060

1073-
func (e *ExecutableHandlerImpl) validate() bool {
1061+
devMemCmd := devMemCmd1 + "; " + devMemCmd2 + "; " + devMemCmd3 + "; "
1062+
log.Infof("devMemCmd->%v", devMemCmd)
10741063

1075-
if noReboot, infoStr := skipIMCReboot(); !noReboot {
1076-
fmt.Printf("IMC reboot required : %v\n", infoStr)
1077-
return false
1064+
_, err = utils.ExecuteScript(fmt.Sprintf(`ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 [email protected] "%s"`, devMemCmd))
1065+
if err != nil {
1066+
log.Errorf("err exec devMemCmd->%v", err)
1067+
return fmt.Errorf("err exec devMemCmd->%v", err)
1068+
}
10781069
}
1079-
1080-
return true
1070+
return nil
10811071
}
10821072

10831073
func (e *ExecutableHandlerImpl) SetupAccApfs() error {
@@ -1187,6 +1177,10 @@ func (s *LifeCycleServiceServer) Init(ctx context.Context, in *pb.InitRequest) (
11871177
} else {
11881178
log.Info("not forcing state")
11891179
}
1180+
if err := ExecutableHandlerGlobal.AddAccApfsToGroupOne(); err != nil {
1181+
log.Fatalf("error from->AddAccApfsToGroupOne: %v", err)
1182+
return nil, fmt.Errorf("error from->AddAccApfsToGroupOne: %v", err)
1183+
}
11901184
if err := ExecutableHandlerGlobal.SetupAccApfs(); err != nil {
11911185
log.Errorf("error from SetupAccApfs %v", err)
11921186
return nil, fmt.Errorf("error from SetupAccApfs %v", err)

0 commit comments

Comments
 (0)