Skip to content

Commit b1b739b

Browse files
authored
Add support for any number of ports in virtual switch using lane map (sonic-net#407)
1 parent 60f97c3 commit b1b739b

File tree

4 files changed

+99
-112
lines changed

4 files changed

+99
-112
lines changed

vslib/inc/sai_vs.h

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ extern const char *g_interface_lane_map_file;
100100
extern std::map<uint32_t,std::string> g_lane_to_ifname;
101101
extern std::map<std::string,std::vector<uint32_t>> g_ifname_to_lanes;
102102
extern std::vector<uint32_t> g_lane_order;
103+
extern std::vector<std::vector<uint32_t>> g_laneMap;
104+
105+
extern void getPortLaneMap(
106+
_Inout_ std::vector<std::vector<uint32_t>> &laneMap);
103107

104108
extern const sai_acl_api_t vs_acl_api;
105109
extern const sai_bfd_api_t vs_bfd_api;

vslib/src/sai_vs_interfacequery.cpp

+79
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int g_vs_boot_type = SAI_VS_COLD_BOOT;
2929
std::map<uint32_t,std::string> g_lane_to_ifname;
3030
std::map<std::string,std::vector<uint32_t>> g_ifname_to_lanes;
3131
std::vector<uint32_t> g_lane_order;
32+
std::vector<std::vector<uint32_t>> g_laneMap;
3233

3334
const char *g_boot_type = NULL;
3435
const char *g_warm_boot_read_file = NULL;
@@ -604,11 +605,89 @@ void load_interface_lane_map()
604605
}
605606

606607
g_ifname_to_lanes[ifname] = lanevec;
608+
g_laneMap.push_back(lanevec);
607609
}
608610

609611
SWSS_LOG_NOTICE("loaded %zu lanes and %zu interfaces", g_lane_to_ifname.size(), g_ifname_to_lanes.size());
610612
}
611613

614+
void getPortLaneMap(
615+
_Inout_ std::vector<std::vector<uint32_t>> &laneMap)
616+
{
617+
SWSS_LOG_ENTER();
618+
619+
laneMap.clear();
620+
621+
for (auto v: g_laneMap)
622+
{
623+
size_t s = v.size();
624+
625+
if (s != 1 && s != 2 && s != 4)
626+
{
627+
SWSS_LOG_THROW("invald number of lanes for interface: %zu", s);
628+
}
629+
630+
laneMap.push_back(v);
631+
}
632+
633+
if (g_laneMap.size())
634+
{
635+
SWSS_LOG_NOTICE("got port lane map with %zu interfaces", laneMap.size());
636+
return;
637+
}
638+
639+
const uint32_t default_port_count = 32;
640+
641+
sai_uint32_t default_lanes[] = {
642+
29,30,31,32,
643+
25,26,27,28,
644+
37,38,39,40,
645+
33,34,35,36,
646+
41,42,43,44,
647+
45,46,47,48,
648+
5,6,7,8,
649+
1,2,3,4,
650+
9,10,11,12,
651+
13,14,15,16,
652+
21,22,23,24,
653+
17,18,19,20,
654+
49,50,51,52,
655+
53,54,55,56,
656+
61,62,63,64,
657+
57,58,59,60,
658+
65,66,67,68,
659+
69,70,71,72,
660+
77,78,79,80,
661+
73,74,75,76,
662+
105,106,107,108,
663+
109,110,111,112,
664+
117,118,119,120,
665+
113,114,115,116,
666+
121,122,123,124,
667+
125,126,127,128,
668+
85,86,87,88,
669+
81,82,83,84,
670+
89,90,91,92,
671+
93,94,95,96,
672+
97,98,99,100,
673+
101,102,103,104
674+
};
675+
676+
// populate default lane map
677+
678+
for (size_t i = 0; i < default_port_count; i++)
679+
{
680+
std::vector<uint32_t> portLanes;
681+
682+
for(int j = 0; j < 4; j++)
683+
portLanes.push_back(default_lanes[4*i + j]);
684+
685+
laneMap.push_back(portLanes);
686+
}
687+
688+
SWSS_LOG_NOTICE("populated default port lane map with %zu interfaces", laneMap.size());
689+
}
690+
612691
sai_status_t sai_api_initialize(
613692
_In_ uint64_t flags,
614693
_In_ const sai_service_method_table_t *service_method_table)

vslib/src/sai_vs_switch_BCM56850.cpp

+8-55
Original file line numberDiff line numberDiff line change
@@ -145,62 +145,13 @@ static sai_status_t create_ports()
145145
{
146146
SWSS_LOG_ENTER();
147147

148-
// TODO currently port information is hardcoded
149-
// but later on we can read this from config file
150-
151-
const uint32_t port_count = 32;
152-
153148
SWSS_LOG_INFO("create ports");
154149

155-
sai_uint32_t lanes[] = {
156-
29,30,31,32,
157-
25,26,27,28,
158-
37,38,39,40,
159-
33,34,35,36,
160-
41,42,43,44,
161-
45,46,47,48,
162-
5,6,7,8,
163-
1,2,3,4,
164-
9,10,11,12,
165-
13,14,15,16,
166-
21,22,23,24,
167-
17,18,19,20,
168-
49,50,51,52,
169-
53,54,55,56,
170-
61,62,63,64,
171-
57,58,59,60,
172-
65,66,67,68,
173-
69,70,71,72,
174-
77,78,79,80,
175-
73,74,75,76,
176-
105,106,107,108,
177-
109,110,111,112,
178-
117,118,119,120,
179-
113,114,115,116,
180-
121,122,123,124,
181-
125,126,127,128,
182-
85,86,87,88,
183-
81,82,83,84,
184-
89,90,91,92,
185-
93,94,95,96,
186-
97,98,99,100,
187-
101,102,103,104
188-
};
189-
190-
if (g_lane_order.size() != port_count * 4)
191-
{
192-
SWSS_LOG_ERROR("only supported lane count is %d, using default", port_count * 4);
193-
}
194-
else if (g_ifname_to_lanes.size() != port_count)
195-
{
196-
SWSS_LOG_ERROR("only supported interface count is %d, using default", port_count);
197-
}
198-
else
199-
{
200-
SWSS_LOG_NOTICE("replacing lane numbers from %s", g_interface_lane_map_file);
150+
std::vector<std::vector<uint32_t>> laneMap;
201151

202-
memcpy(lanes, g_lane_order.data(), port_count * 4);
203-
}
152+
getPortLaneMap(laneMap);
153+
154+
uint32_t port_count = (uint32_t)laneMap.size();
204155

205156
port_list.clear();
206157

@@ -223,9 +174,11 @@ static sai_status_t create_ports()
223174

224175
CHECK_STATUS(vs_generic_set(SAI_OBJECT_TYPE_PORT, port_id, &attr));
225176

177+
std::vector<uint32_t> lanes = laneMap.at(i);
178+
226179
attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
227-
attr.value.u32list.count = 4;
228-
attr.value.u32list.list = &lanes[4 * i];
180+
attr.value.u32list.count = (uint32_t)lanes.size();
181+
attr.value.u32list.list = lanes.data();
229182

230183
CHECK_STATUS(vs_generic_set(SAI_OBJECT_TYPE_PORT, port_id, &attr));
231184

vslib/src/sai_vs_switch_MLNX2700.cpp

+8-57
Original file line numberDiff line numberDiff line change
@@ -142,64 +142,13 @@ static sai_status_t create_ports()
142142
{
143143
SWSS_LOG_ENTER();
144144

145-
/*
146-
* TODO currently port information is hardcoded but later on we can read
147-
* this from profile.ini and use correct lane mapping.
148-
*/
149-
150-
const uint32_t port_count = 32;
151-
152145
SWSS_LOG_INFO("create ports");
153146

154-
sai_uint32_t lanes[] = {
155-
64,65,66,67,
156-
68,69,70,71,
157-
72,73,74,75,
158-
76,77,78,79,
159-
80,81,82,83,
160-
84,85,86,87,
161-
88,89,90,91,
162-
92,93,94,95,
163-
96,97,98,99,
164-
100,101,102,103,
165-
104,105,106,107,
166-
108,109,110,111,
167-
112,113,114,115,
168-
116,117,118,119,
169-
120,121,122,123,
170-
124,125,126,127,
171-
56,57,58,59,
172-
60,61,62,63,
173-
48,49,50,51,
174-
52,53,54,55,
175-
40,41,42,43,
176-
44,45,46,47,
177-
32,33,34,35,
178-
36,37,38,39,
179-
24,25,26,27,
180-
28,29,30,31,
181-
16,17,18,19,
182-
20,21,22,23,
183-
8,9,10,11,
184-
12,13,14,15,
185-
0,1,2,3,
186-
4,5,6,7,
187-
};
188-
189-
if (g_lane_order.size() != port_count * 4)
190-
{
191-
SWSS_LOG_ERROR("only supported lane count is %d, using default", port_count * 4);
192-
}
193-
else if (g_ifname_to_lanes.size() != port_count)
194-
{
195-
SWSS_LOG_ERROR("only supported interface count is %d, using default", port_count);
196-
}
197-
else
198-
{
199-
SWSS_LOG_NOTICE("replacing lane numbers from %s", g_interface_lane_map_file);
147+
std::vector<std::vector<uint32_t>> laneMap;
200148

201-
memcpy(lanes, g_lane_order.data(), port_count * 4);
202-
}
149+
getPortLaneMap(laneMap);
150+
151+
uint32_t port_count = (uint32_t)laneMap.size();
203152

204153
port_list.clear();
205154

@@ -222,9 +171,11 @@ static sai_status_t create_ports()
222171

223172
CHECK_STATUS(vs_generic_set(SAI_OBJECT_TYPE_PORT, port_id, &attr));
224173

174+
std::vector<uint32_t> lanes = laneMap.at(i);
175+
225176
attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
226-
attr.value.u32list.count = 4;
227-
attr.value.u32list.list = &lanes[4 * i];
177+
attr.value.u32list.count = (uint32_t)lanes.size();
178+
attr.value.u32list.list = lanes.data();
228179

229180
CHECK_STATUS(vs_generic_set(SAI_OBJECT_TYPE_PORT, port_id, &attr));
230181

0 commit comments

Comments
 (0)