Skip to content

Commit 449a092

Browse files
authored
sonic-sairedis: Add support to sonic-sairedis for gearbox phys (#632)
* builds on support for multiple switches in sonic-sairedis * new vslib switch BCM81724 implements a virtual gearbox phy. * support for launching second (BCM81724 is supported by its own syncd) * simple refactoring of tests to support switches by part number, still working with sairedis to support multiple switch in tests so BCM81724 will be a separate pull request) * changed example context_config.json to reflect renaming of phy REDIS tables (see sonic-swss-common commit 292b08a3a80b24b23663020b37e6260039a311c0) Note that a future commit to sonic-buildimage will be required to trigger launch of physyncd (launching is based on device config files which are currently not present in sonic-buildimage). Testing done in multiple environments (broadcom fork and pure upstream). Example CLI output based on changes pushed to sonic-utilities (commit a6c4456) running in VS switch supporting BCM81724: root@sonic:/home/admin# show gearbox interfaces status PHY Id Interface MAC Lanes MAC Lane Speed PHY Lanes PHY Lane Speed Line Lanes Line Lane Speed Oper Admin -------- ----------- ----------- ---------------- ----------- ---------------- ------------ ----------------- ------ ------- 1 Ethernet0 25,26,27,28 10G 200,201 20G 206 40G up up 1 Ethernet4 29,30,31,32 10G 202,203 20G 207 40G up up 1 Ethernet8 33,34,35,36 10G 204,205 20G 208 40G up up HLD is located at https://github.com/Azure/SONiC/blob/master/doc/gearbox/gearbox_mgr_design.md Signed-off-by: [email protected]
1 parent ccbb3bc commit 449a092

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+747
-13
lines changed

lib/src/context_config.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
{
2222
"guid" : 1,
2323
"name" : "syncd1",
24-
"dbAsic" : "ASIC_DB2",
25-
"dbCounters" : "COUNTERS_DB2",
26-
"dbFlex": "FLEX_COUNTER_DB2",
27-
"dbState" : "STATE_DB2",
24+
"dbAsic" : "GB_ASIC_DB",
25+
"dbCounters" : "GB_COUNTERS_DB",
26+
"dbFlex": "GB_FLEX_COUNTER_DB",
27+
"dbState" : "STATE_DB",
2828
"switches": [
2929
{
3030
"index" : 0,

lib/src/sai_redis_switch.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
#include "sai_redis.h"
22

3+
sai_status_t redis_switch_mdio_read(
4+
_In_ sai_object_id_t switch_id,
5+
_In_ uint32_t device_addr,
6+
_In_ uint32_t start_reg_addr,
7+
_In_ uint32_t number_of_registers,
8+
_Out_ uint32_t *reg_val)
9+
{
10+
SWSS_LOG_ENTER();
11+
12+
return SAI_STATUS_NOT_IMPLEMENTED;
13+
}
14+
15+
sai_status_t redis_switch_mdio_write(
16+
_In_ sai_object_id_t switch_id,
17+
_In_ uint32_t device_addr,
18+
_In_ uint32_t start_reg_addr,
19+
_In_ uint32_t number_of_registers,
20+
_In_ const uint32_t *reg_val)
21+
{
22+
SWSS_LOG_ENTER();
23+
24+
return SAI_STATUS_NOT_IMPLEMENTED;
25+
}
26+
327
REDIS_GENERIC_QUAD(SWITCH,switch);
428
REDIS_GENERIC_STATS(SWITCH,switch);
529

syncd/SaiSwitch.cpp

+29-3
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,19 @@ SaiSwitch::SaiSwitch(
5959

6060
helperInternalOids();
6161

62-
helperCheckLaneMap();
62+
if (getSwitchType() == SAI_SWITCH_TYPE_NPU)
63+
{
64+
helperCheckLaneMap();
65+
}
6366

6467
helperLoadColdVids();
6568

6669
helperPopulateWarmBootVids();
6770

68-
saiGetMacAddress(m_default_mac_address);
71+
if (getSwitchType() == SAI_SWITCH_TYPE_NPU)
72+
{
73+
saiGetMacAddress(m_default_mac_address);
74+
}
6975

7076
if (warmBoot)
7177
{
@@ -131,6 +137,26 @@ void SaiSwitch::getDefaultMacAddress(
131137
memcpy(mac, m_default_mac_address, sizeof(sai_mac_t));
132138
}
133139

140+
sai_switch_type_t SaiSwitch::getSwitchType() const
141+
{
142+
SWSS_LOG_ENTER();
143+
144+
sai_attribute_t attr;
145+
146+
attr.id = SAI_SWITCH_ATTR_TYPE;
147+
148+
sai_status_t status = m_vendorSai->get(SAI_OBJECT_TYPE_SWITCH, m_switch_rid, 1, &attr);
149+
150+
if (status != SAI_STATUS_SUCCESS)
151+
{
152+
SWSS_LOG_THROW("failed to get switch type");
153+
}
154+
155+
SWSS_LOG_ERROR("switch type: '%s'", (attr.value.s32 == SAI_SWITCH_TYPE_NPU ? "SAI_SWITCH_TYPE_NPU" : "SAI_SWITCH_TYPE_PHY"));
156+
157+
return (sai_switch_type_t) attr.value.s32;
158+
}
159+
134160
#define MAX_HARDWARE_INFO_LENGTH 0x1000
135161

136162
std::string SaiSwitch::saiGetHardwareInfo() const
@@ -885,7 +911,7 @@ void SaiSwitch::helperPopulateWarmBootVids()
885911
{
886912
sai_object_id_t vid = m_translator->translateRidToVid(rid, m_switch_vid);
887913

888-
m_warmBootDiscoveredVids.insert(vid);
914+
m_warmBootDiscoveredVids.insert(vid);
889915
}
890916
}
891917

syncd/SaiSwitch.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace syncd
4141
sai_object_id_t getVid() const;
4242
sai_object_id_t getRid() const;
4343

44+
sai_switch_type_t getSwitchType() const;
4445
std::string getHardwareInfo() const;
4546

4647
std::unordered_map<sai_object_id_t, sai_object_id_t> getVidToRidMap() const;

syncd/scripts/physyncd_start.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Script to start syncd using supervisord
4+
#
5+
6+
exec "/usr/bin/physyncd_startup.py"
7+

syncd/scripts/physyncd_startup.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/python
2+
3+
'''
4+
Copyright 2019 Broadcom. The term "Broadcom" refers to Broadcom Inc.
5+
and/or its subsidiaries.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
'''
19+
import os
20+
import json
21+
import subprocess
22+
23+
24+
def physyncd_enable(gearbox_config):
25+
i = 1
26+
for phy in gearbox_config['phys']:
27+
subprocess.Popen(["/bin/bash", "-c", "/bin/bash -c {}".format('"exec /usr/bin/syncd -p /etc/sai.d/pai.profile -x /usr/share/sonic/hwsku/context_config.json -g {}"'.format(i))], close_fds=True)
28+
i += 1
29+
30+
def main():
31+
32+
# Only privileged users can execute this command
33+
if os.geteuid() != 0:
34+
sys.exit("Root privileges required for this operation")
35+
36+
""" Loads json file """
37+
try:
38+
with open('/usr/share/sonic/hwsku/gearbox_config.json') as file_object:
39+
gearbox_config=json.load(file_object)
40+
except:
41+
sys.exit("No external PHY / gearbox supported on this platform, existing physycd application")
42+
43+
physyncd_enable(gearbox_config)
44+
45+
46+
if __name__== "__main__":
47+
main()
48+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ if SAITHRIFT
1919
vssyncd_LDADD += -lrpcserver -lthrift
2020
endif
2121

22-
TESTS = aspellcheck.pl conflictnames.pl swsslogentercheck.sh brcm.pl mlnx.pl
22+
TESTS = aspellcheck.pl conflictnames.pl swsslogentercheck.sh BCM56850.pl MLNX2700.pl

vslib/inc/SwitchBCM81724.h

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
3+
Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or
4+
its subsidiaries.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
*/
19+
20+
#pragma once
21+
22+
#include "SwitchStateBase.h"
23+
24+
namespace saivs
25+
{
26+
class SwitchBCM81724:
27+
public SwitchStateBase
28+
{
29+
public:
30+
31+
SwitchBCM81724(
32+
_In_ sai_object_id_t switch_id,
33+
_In_ std::shared_ptr<RealObjectIdManager> manager,
34+
_In_ std::shared_ptr<SwitchConfig> config);
35+
36+
SwitchBCM81724(
37+
_In_ sai_object_id_t switch_id,
38+
_In_ std::shared_ptr<RealObjectIdManager> manager,
39+
_In_ std::shared_ptr<SwitchConfig> config,
40+
_In_ std::shared_ptr<WarmBootState> warmBootState);
41+
42+
virtual ~SwitchBCM81724();
43+
44+
protected:
45+
46+
virtual sai_status_t create_port_dependencies(_In_ sai_object_id_t port_id) override;
47+
48+
virtual sai_status_t create_qos_queues_per_port(_In_ sai_object_id_t port_id) override;
49+
50+
virtual sai_status_t create_qos_queues() override;
51+
52+
virtual sai_status_t set_switch_mac_address() override;
53+
54+
virtual sai_status_t create_default_vlan() override;
55+
56+
virtual sai_status_t create_default_1q_bridge() override;
57+
58+
virtual sai_status_t create_default_virtual_router() override;
59+
60+
virtual sai_status_t create_default_stp_instance() override;
61+
62+
virtual sai_status_t create_default_trap_group() override;
63+
64+
virtual sai_status_t create_ingress_priority_groups_per_port(
65+
_In_ sai_object_id_t port_id) override;
66+
67+
virtual sai_status_t create_ingress_priority_groups() override;
68+
69+
virtual sai_status_t create_vlan_members() override;
70+
71+
virtual sai_status_t create_bridge_ports() override;
72+
73+
virtual sai_status_t set_acl_entry_min_prio() override;
74+
75+
virtual sai_status_t set_acl_capabilities() override;
76+
77+
virtual sai_status_t set_maximum_number_of_childs_per_scheduler_group() override;
78+
79+
virtual sai_status_t set_number_of_ecmp_groups() override;
80+
81+
virtual sai_status_t create_cpu_port();
82+
83+
virtual sai_status_t create_ports();
84+
85+
protected : // refresh
86+
87+
virtual sai_status_t refresh_port_list(
88+
_In_ const sai_attr_metadata_t *meta) override;
89+
90+
virtual sai_status_t refresh_bridge_port_list(
91+
_In_ const sai_attr_metadata_t *meta,
92+
_In_ sai_object_id_t bridge_id) override;
93+
94+
virtual sai_status_t refresh_vlan_member_list(
95+
_In_ const sai_attr_metadata_t *meta,
96+
_In_ sai_object_id_t vlan_id) override;
97+
98+
protected:
99+
100+
virtual sai_status_t refresh_read_only( _In_ const sai_attr_metadata_t *meta, _In_ sai_object_id_t object_id) override;
101+
virtual sai_status_t set_switch_default_attributes();
102+
virtual sai_status_t initialize_default_objects() override;
103+
};
104+
}

vslib/inc/SwitchConfig.h

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <string>
77
#include <memory>
88

9+
extern "C" {
10+
#include "sai.h" // for sai_switch_type_t
11+
}
12+
913
namespace saivs
1014
{
1115
typedef enum _sai_vs_switch_type_t
@@ -14,6 +18,8 @@ namespace saivs
1418

1519
SAI_VS_SWITCH_TYPE_BCM56850,
1620

21+
SAI_VS_SWITCH_TYPE_BCM81724,
22+
1723
SAI_VS_SWITCH_TYPE_MLNX2700,
1824

1925
} sai_vs_switch_type_t;
@@ -38,6 +44,10 @@ namespace saivs
3844

3945
public:
4046

47+
static bool parseSaiSwitchType(
48+
_In_ const char* saiSwitchTypeStr,
49+
_Out_ sai_switch_type_t& saiSwitchType);
50+
4151
static bool parseSwitchType(
4252
_In_ const char* switchTypeStr,
4353
_Out_ sai_vs_switch_type_t& switchType);
@@ -51,6 +61,8 @@ namespace saivs
5161

5262
public:
5363

64+
sai_switch_type_t m_saiSwitchType;
65+
5466
sai_vs_switch_type_t m_switchType;
5567

5668
sai_vs_boot_type_t m_bootType;

vslib/inc/saivs.h

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ extern "C" {
55
}
66

77
#define SAI_KEY_VS_SWITCH_TYPE "SAI_VS_SWITCH_TYPE"
8+
#define SAI_KEY_VS_SAI_SWITCH_TYPE "SAI_VS_SAI_SWITCH_TYPE"
9+
10+
#define SAI_VALUE_SAI_SWITCH_TYPE_NPU "SAI_SWITCH_TYPE_NPU"
11+
#define SAI_VALUE_SAI_SWITCH_TYPE_PHY "SAI_SWITCH_TYPE_PHY"
812

913
/**
1014
* @def SAI_KEY_VS_INTERFACE_LANE_MAP_FILE
@@ -31,6 +35,7 @@ extern "C" {
3135
#define SAI_KEY_VS_HOSTIF_USE_TAP_DEVICE "SAI_VS_HOSTIF_USE_TAP_DEVICE"
3236

3337
#define SAI_VALUE_VS_SWITCH_TYPE_BCM56850 "SAI_VS_SWITCH_TYPE_BCM56850"
38+
#define SAI_VALUE_VS_SWITCH_TYPE_BCM81724 "SAI_VS_SWITCH_TYPE_BCM81724"
3439
#define SAI_VALUE_VS_SWITCH_TYPE_MLNX2700 "SAI_VS_SWITCH_TYPE_MLNX2700"
3540

3641
/*

vslib/src/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ libSaiVS_a_SOURCES = \
4545
SelectableFd.cpp \
4646
SwitchState.cpp \
4747
SwitchBCM56850.cpp \
48+
SwitchBCM81724.cpp \
4849
SwitchMLNX2700.cpp
4950

5051
libsaivs_la_SOURCES = \

vslib/src/Sai.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ sai_status_t Sai::initialize(
9494
return SAI_STATUS_FAILURE;
9595
}
9696

97+
auto sai_switch_type = service_method_table->profile_get_value(0, SAI_KEY_VS_SAI_SWITCH_TYPE);
98+
sai_switch_type_t saiSwitchType;
99+
100+
if (sai_switch_type == NULL)
101+
{
102+
SWSS_LOG_NOTICE("failed to obtain service method table value: %s", SAI_KEY_VS_SAI_SWITCH_TYPE);
103+
saiSwitchType = SAI_SWITCH_TYPE_NPU;
104+
}
105+
else if (!SwitchConfig::parseSaiSwitchType(sai_switch_type, saiSwitchType))
106+
{
107+
return SAI_STATUS_FAILURE;
108+
}
109+
97110
auto *laneMapFile = service_method_table->profile_get_value(0, SAI_KEY_VS_INTERFACE_LANE_MAP_FILE);
98111

99112
m_laneMapContainer = LaneMapFileParser::parseLaneMapFile(laneMapFile);
@@ -128,6 +141,7 @@ sai_status_t Sai::initialize(
128141

129142
auto sc = std::make_shared<SwitchConfig>();
130143

144+
sc->m_saiSwitchType = saiSwitchType;
131145
sc->m_switchType = switchType;
132146
sc->m_bootType = bootType;
133147
sc->m_switchIndex = 0;
@@ -161,7 +175,10 @@ sai_status_t Sai::initialize(
161175

162176
startUnittestThread();
163177

164-
startFdbAgingThread();
178+
if (saiSwitchType == SAI_SWITCH_TYPE_NPU)
179+
{
180+
startFdbAgingThread();
181+
}
165182

166183
m_apiInitialized = true;
167184

0 commit comments

Comments
 (0)