This commit is contained in:
parent
e32b777bb6
commit
1137c635c3
|
@ -5,7 +5,10 @@ set(CMAKE_CXX_STANDARD 14)
|
|||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions -frtti -D_FM_ARCH_64 -DFM_SUPPORT_FM10000 -D_GNU_SOURCE")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -frtti -D_FM_ARCH_64 -DFM_SUPPORT_FM10000 -D_GNU_SOURCE")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
|
||||
set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -Wl,--no-as-needed")
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN")
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
|
||||
include_directories(src)
|
||||
|
||||
|
|
|
@ -10,9 +10,11 @@ fi
|
|||
mkdir build
|
||||
export CC=clang
|
||||
export CXX=clang++
|
||||
export CFLAGS="-ggdb -O1"
|
||||
export CXXFLAGS="-ggdb -O1"
|
||||
export CFLAGS="-ggdb -O0"
|
||||
export CXXFLAGS="-ggdb -O0"
|
||||
git clean -f -d -x
|
||||
./autogen.sh
|
||||
./configure --enable-static --enable-shared --prefix "$(pwd)/build"
|
||||
./configure --enable-shared --prefix "$(pwd)/build"
|
||||
make clean
|
||||
make -j$(nproc)
|
||||
make install
|
2
deps/IES
vendored
2
deps/IES
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 3776b9148f56c026c834476a9990a398b4c64cdb
|
||||
Subproject commit e2392eadf724573b5657f1f3cc4348e389a12c6a
|
|
@ -285,11 +285,15 @@ bool FM10K::FM10K::initialize() const {
|
|||
auto pcieDevice = dynamic_cast<PCIEDevice*>(m_device.get());
|
||||
if(pcieDevice != nullptr){
|
||||
ies.replaceConfigEntry("api.platform.config.switch.0.uioDevName", IES::TlvType::Null, "");
|
||||
ies.replaceConfigEntry("api.platform.config.switch.0.resource4DevName", IES::TlvType::Text, pcieDevice->getDeviceEntry().getDevicePath());
|
||||
ies.replaceConfigEntry("api.platform.config.switch.0.resource4DevName", IES::TlvType::Text, pcieDevice->getDeviceEntry().getPath());
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
//TODO UIO support
|
||||
|
||||
|
||||
//ies.addConfigEntry("api.platform.lib.config.debug", IES::TlvType::Text, "I2C_RW,I2C_MUX,DUMP_CFG");
|
||||
//ies.addConfigEntry("api.debug.initLoggingCategories", IES::TlvType::Text, "FM_LOG_CAT_LOGGING|FM_LOG_CAT_LINK_STATE|FM_LOG_CAT_ALOS|FM_LOG_CAT_DEBUG|FM_LOG_CAT_PHY|FM_LOG_CAT_PLATFORM|FM_LOG_CAT_EVENT|FM_LOG_CAT_SWITCH|FM_LOG_CAT_MAILBOX|FM_LOG_CAT_PORT|FM_LOG_CAT_SERDES|FM_LOG_CAT_EVENT_INTR|FM_LOG_CAT_STATE_MACHINE|FM_LOG_CAT_GENERAL|FM_LOG_CAT_API|FM_LOG_CAT_PORT_AUTONEG");
|
||||
|
||||
return ies.init();
|
||||
}
|
||||
|
|
|
@ -24,14 +24,6 @@ bool FM10K::IES::init() {
|
|||
return true;
|
||||
}
|
||||
|
||||
/*if(fmOSInitialize() != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(fmSetLoggingType(FM_LOG_TYPE_CONSOLE, 0, nullptr) != FM_OK){
|
||||
std::abort();
|
||||
}*/
|
||||
|
||||
if(!writePlatformConfiguration()){
|
||||
std::abort();
|
||||
}
|
||||
|
@ -54,7 +46,34 @@ bool FM10K::IES::init() {
|
|||
std::abort();
|
||||
}
|
||||
|
||||
fmCreateSemaphore("seq", FM_SEM_BINARY, &IES_Static::semaphore, 0);
|
||||
|
||||
|
||||
if(fmOSInitialize() != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
/*
|
||||
if(fmSetLoggingType(FM_LOG_TYPE_CONSOLE, 0, nullptr) != FM_OK){
|
||||
std::abort();
|
||||
}*/
|
||||
|
||||
if(fmSetLoggingVerbosity(FM_LOG_VERBOSITY_DEFAULT | FM_LOG_VERBOSITY_FILE) != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(fmEnableLoggingLevel(FM_LOG_LEVEL_ALL_VERBOSE) != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
//if(fmEnableLoggingCategory(FM_LOG_CAT_ALL) != FM_OK){
|
||||
/*if(fmSetLoggingFilter(FM_LOG_CAT_PORT | FM_LOG_CAT_SWITCH | FM_LOG_CAT_SERDES | FM_LOG_CAT_STATE_MACHINE | FM_LOG_CAT_PLATFORM | FM_LOG_CAT_EVENT_INTR, FM_LOG_LEVEL_ALL_VERBOSE,
|
||||
nullptr, nullptr) != FM_OK){
|
||||
std::abort();
|
||||
}*/
|
||||
|
||||
if(fmCreateSemaphore("seq", FM_SEM_BINARY, &IES_Static::semaphore, 0) != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(fmInitialize(eventHandler) != FM_OK){
|
||||
std::abort();
|
||||
|
@ -68,6 +87,201 @@ bool FM10K::IES::init() {
|
|||
std::abort();
|
||||
}
|
||||
|
||||
uint32_t defaultVlan = 1;
|
||||
|
||||
//Initialize VLANs
|
||||
for(uint32_t vlan = 0; vlan < FM10000_MAX_VLAN; ++vlan){
|
||||
fmCreateVlan(IES_Static::sw, vlan);
|
||||
}
|
||||
|
||||
{
|
||||
fm_bool vr = FM_ENABLED;
|
||||
fmSetVlanAttribute(IES_Static::sw, 0, FM_VLAN_REFLECT, &vr);
|
||||
}
|
||||
|
||||
{
|
||||
fm_status err;
|
||||
fm_int port;
|
||||
fm_switchInfo swInfo;
|
||||
fm_bool pi = FM_DISABLED;
|
||||
fm_bool vr = FM_ENABLED;
|
||||
fmGetSwitchInfo(IES_Static::sw, &swInfo);
|
||||
/* init non cpu ports and put them into their own vlan, make sure */
|
||||
/* the parser goes to l4, no vlan boundary check, and routable */
|
||||
for(fm_int cpi = 1; cpi < swInfo.numCardPorts; ++cpi){
|
||||
err = fmMapCardinalPort(IES_Static::sw, cpi, &port, nullptr);
|
||||
if(err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("cpi=%d, port=%d\n", cpi, port);
|
||||
|
||||
|
||||
err = fmGetPortAttribute(IES_Static::sw, port, FM_PORT_INTERNAL, &pi);
|
||||
if (err != FM_OK) {
|
||||
printf("skip port %d\n", port);
|
||||
continue;
|
||||
}
|
||||
if (pi == FM_ENABLED) {
|
||||
printf("skip internal port %d\n", port);
|
||||
continue;
|
||||
}
|
||||
|
||||
fm_bool is_pcie = FALSE;
|
||||
fm_bool is_fibm = FALSE;
|
||||
err = fmIsPciePort(IES_Static::sw, port, &is_pcie);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
err = fmIsSpecialPort(IES_Static::sw, port, &is_fibm);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
err = fmSetVlanAttribute(IES_Static::sw, defaultVlan, FM_VLAN_REFLECT, &vr);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
err = fmSetPortState(IES_Static::sw, port, FM_PORT_STATE_UP, 0);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
printf("set port %d to UP\n", port);
|
||||
|
||||
err = fmAddVlanPort(IES_Static::sw, defaultVlan, port, FALSE);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("add port %d to default vlan %u\n", port, defaultVlan);
|
||||
|
||||
err = fmSetVlanPortState(IES_Static::sw, defaultVlan, port, FM_STP_STATE_FORWARDING);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("set STP state of port %d in vlan %u to forwarding\n", port, defaultVlan);
|
||||
|
||||
err = fmSetPortAttribute(IES_Static::sw, port, FM_PORT_DEF_VLAN, &defaultVlan);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("set pvid for port %d to vlan %u\n", port, defaultVlan);
|
||||
|
||||
|
||||
//This drops unknown vlans that violate constraints
|
||||
fm_bool bv = FM_DISABLED;
|
||||
err = fmSetPortAttribute(IES_Static::sw, port, FM_PORT_DROP_BV, &bv);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("set FM_PORT_DROP_BV for port %d to %d\n", port, bv);
|
||||
|
||||
{
|
||||
fm_int pc = FM_PORT_PARSER_STOP_AFTER_L2;//FM_PORT_PARSER_STOP_AFTER_L4;
|
||||
err = fmSetPortAttribute(IES_Static::sw, port, FM_PORT_PARSER, &pc);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("set FM_PORT_PARSER for port %d to %d\n", port, pc);
|
||||
}
|
||||
|
||||
{
|
||||
//Only switch, not routing
|
||||
fm_bool re = FM_DISABLED;
|
||||
err = fmSetPortAttribute(IES_Static::sw, port, FM_PORT_ROUTABLE, &re);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("set FM_PORT_ROUTABLE for port %d to %d\n", port, re);
|
||||
}
|
||||
{
|
||||
if(!is_fibm && !is_pcie){
|
||||
fm_int fs = 9000;
|
||||
err = fmSetPortAttribute(IES_Static::sw, port, FM_PORT_MAX_FRAME_SIZE, &fs);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("set FM_PORT_MAX_FRAME_SIZE for port %d to %d\n", port, fs);
|
||||
}
|
||||
}
|
||||
{
|
||||
// enable learning only for Ethernet ports
|
||||
fm_int le = !is_pcie;
|
||||
err = fmSetPortAttribute(IES_Static::sw, port, FM_PORT_LEARNING, &le);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
printf("set FM_PORT_LEARNING for port %d to %d\n", port, le);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* port cpu port on default vlan */
|
||||
{
|
||||
fm_int port;
|
||||
auto err = fmGetCpuPort(IES_Static::sw, &port);
|
||||
if(err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("find cpu port %d\n", port);
|
||||
|
||||
err = fmAddVlanPort(IES_Static::sw, defaultVlan, port, FALSE);
|
||||
if(err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("add port %d to default vlan %u\n", port, defaultVlan);
|
||||
|
||||
err = fmSetPortAttribute(IES_Static::sw, port, FM_PORT_DEF_VLAN, &defaultVlan);
|
||||
if(err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("set pvid for port %d to vlan %u\n", port, defaultVlan);
|
||||
|
||||
{
|
||||
fm_int pc = FM_PORT_PARSER_STOP_AFTER_L2;//FM_PORT_PARSER_STOP_AFTER_L4;
|
||||
err = fmSetPortAttribute(IES_Static::sw, port, FM_PORT_PARSER, &pc);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
printf("set FM_PORT_PARSER for port %d to %d\n", port, pc);
|
||||
}
|
||||
{
|
||||
fm_int le = FM_ENABLED;
|
||||
err = fmSetPortAttribute(IES_Static::sw, port, FM_PORT_LEARNING, &le);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
|
||||
printf("set FM_PORT_LEARNING for port %d to %d\n", port, le);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
|
||||
fm_int bf = FM_BCAST_FWD;
|
||||
fm_int mf = FM_MCAST_FWD;
|
||||
fm_int uf = FM_UCAST_FWD;
|
||||
auto err = fmSetSwitchAttribute(IES_Static::sw, FM_BCAST_FLOODING, &bf);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
err = fmSetSwitchAttribute(IES_Static::sw, FM_MCAST_FLOODING, &mf);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
err = fmSetSwitchAttribute(IES_Static::sw, FM_UCAST_FLOODING, &uf);
|
||||
if (err != FM_OK){
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
printf("Switch is UP, all ports are now enabled\n");
|
||||
|
||||
//TODO: setup routing
|
||||
|
||||
|
||||
//Restore cwd
|
||||
if(chdir(tempcwd) != 0){
|
||||
|
@ -125,12 +339,15 @@ bool FM10K::IES::replaceConfigEntry(const std::string &key, FM10K::IES::TlvType
|
|||
return false;
|
||||
}
|
||||
|
||||
if(type == TlvType::Null){
|
||||
m_configuration.erase(key);
|
||||
}else{
|
||||
m_configuration[key] = {type, value};
|
||||
for(auto& e : m_configuration){
|
||||
if(e.first == key){
|
||||
e.second = {type, value};
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
m_configuration.push_back({key, {type, value}});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -138,11 +355,15 @@ bool FM10K::IES::addConfigEntry(const std::string &key, FM10K::IES::TlvType type
|
|||
if(m_initialized){
|
||||
return false;
|
||||
}
|
||||
if(m_configuration.find(key) != m_configuration.end()){
|
||||
return false;
|
||||
|
||||
for(auto& e : m_configuration){
|
||||
if(e.first == key){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_configuration[key] = {type, value};
|
||||
m_configuration.push_back({key, {type, value}});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -172,6 +393,9 @@ std::string FM10K::IES::getPlatformConfiguration() const {
|
|||
output += "# Autogenerated file. Do not edit, changes WILL NOT be preserved.\n\n";
|
||||
|
||||
for(auto& it : m_configuration){
|
||||
if(it.second.first == TlvType::Null){
|
||||
continue;
|
||||
}
|
||||
output += it.first;
|
||||
output += " ";
|
||||
switch (it.second.first) {
|
||||
|
@ -217,6 +441,8 @@ FM10K::IES::~IES() {
|
|||
rmdir(m_tempPath.c_str());
|
||||
m_tempPath.clear();
|
||||
}
|
||||
|
||||
teardown();
|
||||
}
|
||||
|
||||
const std::string &FM10K::IES::getTempPath() {
|
||||
|
@ -242,12 +468,22 @@ bool FM10K::IES::writePlatformConfiguration() {
|
|||
return false;
|
||||
}
|
||||
f << getPlatformConfiguration();
|
||||
if(f.fail()){
|
||||
return false;
|
||||
}
|
||||
f.close();
|
||||
return f.fail();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string FM10K::IES::getPlatformConfigurationPath() {
|
||||
return getTempPath() + "/fm_platform_attributes.cfg";
|
||||
}
|
||||
|
||||
void FM10K::IES::teardown() {
|
||||
if(m_initialized){
|
||||
fmTerminate();
|
||||
m_initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
FM10K::IES::IES() = default;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <memory>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct _fm_eventPort;
|
||||
|
||||
|
@ -48,11 +49,12 @@ namespace FM10K {
|
|||
|
||||
std::string getPlatformConfigurationPath();
|
||||
bool init();
|
||||
void teardown();
|
||||
|
||||
private:
|
||||
IES();
|
||||
|
||||
std::map<std::string, std::pair<TlvType, std::string>> m_configuration{};
|
||||
std::vector<std::pair<std::string, std::pair<TlvType, std::string>>> m_configuration{};
|
||||
bool m_initialized = false;
|
||||
std::string m_tempPath{};
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "IES.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "IES_SDK.h"
|
||||
|
||||
|
@ -15,12 +16,14 @@
|
|||
namespace FM10K {
|
||||
namespace IES_Static {
|
||||
using TlvType = FM10K::IES::TlvType;
|
||||
static std::unordered_map<std::string, std::map<std::string, std::pair<TlvType, std::string>>> knownConfigurations = {
|
||||
static std::unordered_map<std::string, std::vector<std::pair<std::string, std::pair<TlvType, std::string>>>> knownConfigurations = {
|
||||
{"FM10840_B0_AUTO_100G", {
|
||||
{"api.platform.config.numSwitches", {TlvType::Integer, "1"}},
|
||||
|
||||
{"api.platform.config.platformName", {TlvType::Text, "rrc_2x100gm"}},
|
||||
|
||||
{"api.platform.config.debug", {TlvType::Text, "CONFIG,MOD_STATE,MOD_INTR,MOD_TYPE,PLAT_LOG"}},
|
||||
|
||||
|
||||
{"api.platform.config.switch.0.switchNumber", {TlvType::Integer, "0"}},
|
||||
|
||||
|
@ -64,7 +67,7 @@ namespace FM10K {
|
|||
{"api.platform.config.switch.0.bootCfg.pep.6.bar4Allowed", {TlvType::Boolean, "1"}},
|
||||
|
||||
|
||||
{"api.platform.config.switch.0.portIndex.0.portMapping", {TlvType::Text, "\"LOG = 0 PCIE=8\""}},
|
||||
{"api.platform.config.switch.0.portIndex.0.portMapping", {TlvType::Text, "\"LOG=0 PCIE=8\""}},
|
||||
|
||||
|
||||
{"api.platform.config.switch.0.portIndex.1.lane.0.portMapping", {TlvType::Text, "\"LOG=1 EPL=1 LANE=0\""}},
|
||||
|
@ -101,8 +104,6 @@ namespace FM10K {
|
|||
{"api.platform.config.switch.0.portIndex.5.speed", {TlvType::Integer, SPEED_50G}}, //? second PCIe group
|
||||
{"api.platform.config.switch.0.portIndex.6.speed", {TlvType::Integer, SPEED_50G}}, //? second PCIe group
|
||||
|
||||
{"api.platform.config.switch.0.portIndex.2.speed", {TlvType::Integer, SPEED_100G}},
|
||||
|
||||
{"api.platform.config.switch.0.port.default.ethernetMode", {TlvType::Text, "DISABLED"}},
|
||||
|
||||
|
||||
|
@ -130,6 +131,7 @@ namespace FM10K {
|
|||
|
||||
{"api.platform.lib.config.bus0.i2cDevName", {TlvType::Text, "switchI2C"}},
|
||||
|
||||
{"api.platform.lib.config.pcaMux.count", {TlvType::Integer, "1"}},
|
||||
|
||||
{"api.platform.lib.config.pcaMux.0.model", {TlvType::Text, "PCA9545"}},
|
||||
{"api.platform.lib.config.pcaMux.0.addr", {TlvType::Integer, "0x58"}},
|
||||
|
@ -170,6 +172,8 @@ namespace FM10K {
|
|||
{"api.platform.lib.config.xcvrState.default.lpMode.pin", {TlvType::Integer, "0"}},
|
||||
|
||||
|
||||
{"api.platform.lib.config.hwResourceId.count", {TlvType::Integer, "4"}},
|
||||
|
||||
{"api.platform.config.switch.0.portIndex.1.hwResourceId", {TlvType::Integer, "0"}},
|
||||
{"api.platform.config.switch.0.portIndex.2.hwResourceId", {TlvType::Integer, "1"}},
|
||||
|
||||
|
|
23
src/fsmd.cpp
23
src/fsmd.cpp
|
@ -2,9 +2,13 @@
|
|||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <csignal>
|
||||
#include <unistd.h>
|
||||
#include <thread>
|
||||
#include "device/PCIEDevice.h"
|
||||
#include "fm10k/FM10K.h"
|
||||
#include "fm10k/registers/Register.h"
|
||||
#include "fm10k/IES.h"
|
||||
|
||||
template <typename T> std::string tohex(T v){
|
||||
std::stringstream o;
|
||||
|
@ -13,6 +17,13 @@ template <typename T> std::string tohex(T v){
|
|||
return o.str();
|
||||
}
|
||||
|
||||
static bool stopLoop = false;
|
||||
|
||||
static void int_handler(int sig){
|
||||
stopLoop = true;
|
||||
std::cout << "STOPPING DUE TO SIGNAL " << sig << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto entries = PCIEDevice::DeviceEntry::find();
|
||||
|
||||
|
@ -45,11 +56,23 @@ int main() {
|
|||
|
||||
if(fm10k.initialize()){
|
||||
std::cout << "success" << std::endl;
|
||||
|
||||
signal(SIGINT, int_handler);
|
||||
signal(SIGTERM, int_handler);
|
||||
do{
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::yield();
|
||||
//TODO: check work
|
||||
std::this_thread::sleep_for(1000ms);
|
||||
} while (!stopLoop);
|
||||
|
||||
}else{
|
||||
std::cout << "fail" << std::endl;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
FM10K::IES::getInstance().teardown();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue