Skip to content

Commit 86842e0

Browse files
committed
VelocityPCI-CLI v5.3
1 parent e7737b3 commit 86842e0

Some content is hidden

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

90 files changed

+44059
-17
lines changed

CONTRIBUTING.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Contributing
2+
3+
Contributions are most welcome but it would be very much appreciated if
4+
you follow the following guidelines.
5+
6+
## Style
7+
8+
It's simply polite to match the style of the code you are contributing to.
9+
Code that does not follow the style will not be looked upon kindly. This
10+
code largely follows the [Linux Kernel Style][1] so please read that
11+
document and take heed of its wisdom.
12+
13+
## Pull Requests
14+
15+
Please create the pull request basing the branch devel on this repo.
16+
Make sure the comparing changes include your bug fixes or new features.
17+
We follow kernel style as documented [here][1]. It is highly recommended
18+
that the patches be checked with the checkpatch.pl script in the Linux
19+
Kernel tree with no obivous style problems. Once the patches go through
20+
the review, they will be merged into the branch devel.
21+
22+
## Pitfalls
23+
24+
* In the code, ensure to avoid accessing the GAS directly except in an
25+
appropriate platform file or a new command that calls switchtec_gas_map().
26+
Also, be aware that on Linux, using the GAS directly requires full root
27+
privilages where as all other commands only require access to the device file.
28+
29+
30+
[1]: https://www.kernel.org/doc/html/latest/process/coding-style.html

LICENSE

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
MIT License
21

3-
Copyright (c) 2025 Microchip Technology
2+
Copyright (c) 2025, Microchip Technology
43

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
1414

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile.in

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
2+
# @configure_input@
3+
4+
########################################################################
5+
##
6+
## Microsemi Switchtec(tm) PCIe Management Library
7+
## Copyright (c) 2017, Microsemi Corporation
8+
##
9+
## Permission is hereby granted, free of charge, to any person obtaining a
10+
## copy of this software and associated documentation files (the "Software"),
11+
## to deal in the Software without restriction, including without limitation
12+
## the rights to use, copy, modify, merge, publish, distribute, sublicense,
13+
## and/or sell copies of the Software, and to permit persons to whom the
14+
## Software is furnished to do so, subject to the following conditions:
15+
##
16+
## The above copyright notice and this permission notice shall be included
17+
## in all copies or substantial portions of the Software.
18+
##
19+
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20+
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22+
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23+
## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24+
## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25+
## OTHER DEALINGS IN THE SOFTWARE.
26+
##
27+
########################################################################
28+
29+
OBJDIR ?= build
30+
31+
DESTDIR ?=
32+
PREFIX ?= /usr/local
33+
RPMBUILD ?= rpmbuild
34+
35+
BINDIR ?= $(DESTDIR)$(PREFIX)/bin
36+
LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
37+
INCDIR ?= $(DESTDIR)$(PREFIX)/include
38+
SYSCONFDIR ?= $(DESTDIR)/etc
39+
40+
CC=@CC@
41+
WINDRES=@WINDRES@
42+
override CPPFLAGS+=@CPPFLAGS@
43+
override CPPFLAGS+=-I. -Iinc -I$(OBJDIR) -DCOMPLETE_ENV=\"SWITCHTEC_COMPLETE\"
44+
override CFLAGS+=-g -Wall -Wno-initializer-overrides @CFLAGS@
45+
DEPFLAGS= -MT $@ -MMD -MP -MF $(OBJDIR)/$*.d
46+
LDLIBS=@LIBS@ -lm
47+
override LDFLAGS+=@LDFLAGS@
48+
49+
LIB_SRCS=$(wildcard lib/*.c) $(wildcard lib/platform/*.c)
50+
ifeq ($(UT), yes)
51+
CLI_SRCS=$(wildcard cli/*.c) $(wildcard tests/common/*.c)
52+
else
53+
CLI_SRCS=$(wildcard cli/*.c)
54+
endif
55+
56+
LIB_OBJS=$(addprefix $(OBJDIR)/, $(patsubst %.c,%.o, $(LIB_SRCS)))
57+
CLI_OBJS=$(addprefix $(OBJDIR)/, $(patsubst %.c,%.o, $(CLI_SRCS)))
58+
59+
STLIBNAME ?= libswitchtec.a
60+
61+
MACHINE=$(shell $(CC) -dumpmachine)
62+
63+
ifeq ($(findstring mingw,$(MACHINE)),mingw)
64+
MINGW := YES
65+
endif
66+
67+
ifeq ($(MINGW), YES)
68+
EXENAME ?= switchtec.exe
69+
INSTEXENAME ?= switchtec
70+
SHLIBNAME ?= switchtec.dll
71+
IMPLIBNAME ?= libswitchtec.dll.a
72+
override LDFLAGS += -Wl,--out-implib,$(IMPLIBNAME)
73+
LDLIBS += -lsetupapi -lws2_32
74+
SHLDLIBS = $(LDLIBS)
75+
override CPPFLAGS += -DNTDDI_VERSION=NTDDI_VISTA -D_WIN32_WINNT=_WIN32_WINNT_VISTA
76+
override CFLAGS += -D__USE_MINGW_ANSI_STDIO
77+
else
78+
EXENAME ?= switchtec
79+
INSTEXENAME ?= $(EXENAME)
80+
SHLIBNAME ?= libswitchtec.so
81+
IMPLIBNAME ?= $(SHLIBNAME)
82+
LDCONFIG=ldconfig
83+
override CFLAGS += -fPIC
84+
endif
85+
86+
ifneq ($(WINDRES), )
87+
CLI_OBJS += $(OBJDIR)/cli/cli.o
88+
LIB_OBJS += $(OBJDIR)/lib/lib.o
89+
endif
90+
91+
ifneq ($(V), 1)
92+
Q=@
93+
else
94+
NQ=:
95+
endif
96+
97+
ifeq ($(W), 1)
98+
CFLAGS += -Werror
99+
endif
100+
101+
compile: $(STLIBNAME) $(SHLIBNAME) $(EXENAME) examples/temp
102+
103+
clean:
104+
$(Q)rm -rf $(STLIBNAME) $(SHLIBNAME) $(EXENAME) $(OBJDIR) *.a \
105+
examples/temp examples/*.o
106+
107+
distclean: clean
108+
$(Q)rm -rf config.log config.status *.lib *.exe *.so *.dll build* \
109+
Makefile autom4te.cache *.tar* switchtec.spec
110+
111+
$(OBJDIR)/version.h $(OBJDIR)/version.mk: FORCE $(OBJDIR)
112+
@$(SHELL_PATH) ./VERSION-GEN
113+
-include $(OBJDIR)/version.mk
114+
115+
$(OBJDIR):
116+
ifeq ($(UT), yes)
117+
$(Q)mkdir -p $(OBJDIR)/cli $(OBJDIR)/lib $(OBJDIR)/lib/platform $(OBJDIR)/tests/ $(OBJDIR)/tests/common
118+
else
119+
$(Q)mkdir -p $(OBJDIR)/cli $(OBJDIR)/lib $(OBJDIR)/lib/platform
120+
endif
121+
122+
$(OBJDIR)/%.o: %.c | $(OBJDIR)
123+
@$(NQ) echo " CC $<"
124+
$(Q)$(COMPILE.c) $(DEPFLAGS) $< -o $@
125+
126+
$(OBJDIR)/%.o: %.rc $(OBJDIR)/version.h | $(OBJDIR)
127+
@$(NQ) echo " RC $<"
128+
$(Q)$(WINDRES) $(CPPFLAGS) $< $@
129+
130+
$(STLIBNAME): $(LIB_OBJS)
131+
@$(NQ) echo " AR $@"
132+
$(Q)$(AR) rDsc $@ $^
133+
134+
$(SHLIBNAME): $(LIB_OBJS)
135+
@$(NQ) echo " LD $@"
136+
$(Q)$(LINK.o) -shared -Wl,-soname,$@.$(MAJOR_VER) $^ $(SHLDLIBS) -o $@
137+
138+
$(EXENAME): $(CLI_OBJS) $(STLIBNAME)
139+
@$(NQ) echo " LD $@"
140+
$(Q)$(LINK.o) $^ $(LDLIBS) -o $@
141+
142+
examples/%.o: examples/%.c
143+
@$(NQ) echo " CC $<"
144+
$(Q)$(COMPILE.c) $(DEPFLAGS) $< -o $@
145+
146+
examples/%: examples/%.o | $(SHLIBNAME)
147+
@$(NQ) echo " LD $@"
148+
$(Q)$(LINK.o) $^ $(IMPLIBNAME) $(LDLIBS) -o $@
149+
150+
install-bash-completion:
151+
@$(NQ) echo " INSTALL $(SYSCONFDIR)/bash_completion.d/bash-switchtec-completion.sh"
152+
$(Q)install -d $(SYSCONFDIR)/bash_completion.d
153+
$(Q)install -m 644 -T ./completions/bash-switchtec-completion.sh \
154+
$(SYSCONFDIR)/bash_completion.d/switchtec
155+
156+
install-bin: compile
157+
$(Q)install -d $(BINDIR) $(LIBDIR)
158+
159+
@$(NQ) echo " INSTALL $(BINDIR)/$(INSTEXENAME)"
160+
$(Q)install $(EXENAME) $(BINDIR)/$(INSTEXENAME)
161+
@$(NQ) echo " INSTALL $(LIBDIR)/$(STLIBNAME)"
162+
$(Q)install -m 0664 $(STLIBNAME) $(LIBDIR)
163+
@$(NQ) echo " INSTALL $(LIBDIR)/$(IMPLIBNAME).$(VERSION)"
164+
$(Q)install $(IMPLIBNAME) $(LIBDIR)/$(IMPLIBNAME).$(VERSION)
165+
ifneq ($(MINGW), YES)
166+
@$(NQ) echo " INSTALL $(LIBDIR)/$(IMPLIBNAME)"
167+
$(Q)ln -fs $(IMPLIBNAME).$(MAJOR_VER) $(LIBDIR)/$(IMPLIBNAME)
168+
endif
169+
@$(NQ) echo " INSTALL $(INCDIR)/switchtec"
170+
@$(Q)mkdir -p $(INCDIR)
171+
@$(Q)cp -r inc/switchtec $(INCDIR)
172+
173+
install-pkg: install-bin install-bash-completion
174+
175+
install: install-bin install-bash-completion
176+
ifneq ($(MINGW), YES)
177+
@$(NQ) echo " LDCONFIG"
178+
$(Q)$(LDCONFIG) $(LIBDIR)
179+
endif
180+
181+
uninstall:
182+
ifneq ($(MINGW), YES)
183+
@$(NQ) echo " LDCONFIG"
184+
$(Q)$(LDCONFIG) $(LIBDIR)
185+
endif
186+
187+
switchtec.spec: switchtec.spec.in $(OBJDIR)/version.mk
188+
sed -e 's/@@VERSION@@/$(VERSION)/g' < $< | sed -e 's/@@RELEASE@@/$(RELEASE)/g' > $@+
189+
mv $@+ $@
190+
191+
PKG=switchtec-$(VERSION)-$(RELEASE)
192+
dist: switchtec.spec
193+
git archive --format=tar --prefix=$(PKG)/ HEAD > $(PKG).tar
194+
@echo $(VERSION)-$(RELEASE) > version
195+
tar -rf $(PKG).tar --xform="s%^%$(PKG)/%" switchtec.spec version
196+
xz -f $(PKG).tar
197+
rm -f version
198+
199+
rpm: dist
200+
$(RPMBUILD) -ta $(PKG).tar.xz
201+
202+
doc:
203+
make -C doc
204+
205+
.PHONY: clean compile install unintsall install-bin install-bash-completion doc
206+
.PHONY: FORCE dist rpm
207+
208+
209+
-include $(patsubst %.o,%.d,$(LIB_OBJS) $(CLI_OBJS))

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# VelocityPCI Management CLI and Library
2+
3+
## Summary
4+
5+
The code hosted here provides an easy to use CLI and C library for
6+
communicating with Microchip's VelocityPCI management interface. It
7+
utilizes the switchtec kernel module which, with luck, will be upstream
8+
for 4.11. Otherwise it can be obtained from the [switchtec-kernel]
9+
github repository and compiled for other supported kernels.
10+
11+
Currently the following features are supported:
12+
13+
* Show status for each port on all partitions
14+
* Measure bandwidth and latency for each port
15+
* Display and wait on event occurrances
16+
* Setup and show event counters for various types of events
17+
* Dump firmware logs
18+
* Send a hard reset command to the switch
19+
* Update and readback firmware as well as display image version and CRC info
20+
* A simple ncurses GUI that shows salient information for the switch
21+
* Display and configure manufacturing settings
22+
23+
Detailed documentation for the project can be found on the [Github
24+
Pages] site.
25+
26+
[switchtec-kernel]: https://github.com/Microsemi/switchtec-kernel
27+
[github pages]: https://github.com/MicrochipTech/velocitypci-cli/
28+
29+
## Dependencies
30+
31+
This program has an optional build dependencies on the following libraries:
32+
33+
* libncurses5-dev (without it, 'switchtec gui' will not work)
34+
* libssl-dev (without it, some of the commands in 'switchtec mfg' will not work)
35+
36+
## Installation
37+
38+
Installation is simple, with:
39+
40+
~~~
41+
./configure
42+
make
43+
sudo make install
44+
~~~~
45+
46+
## Building on Windows
47+
48+
MSYS2 should be used to build velocitypci-cli on windows seeing it
49+
provides a reasonably compatible compiler. (Visual C++ still is
50+
missing full support of C99.) To setup an environment:
51+
52+
1. Install MSYS2 by following the instructions at: http://www.msys2.org/
53+
2. In an MSYS2 shell, run the following:
54+
55+
~~~
56+
pacman -S --needed base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain git
57+
~~~
58+
59+
3. Close the MSYS2 shell, open an MINGW64 shell, checkout the project
60+
and follow the above installation instructions as usual.
61+
62+
## Demos
63+
64+
### CLI Demo
65+
[![asciicast](https://asciinema.org/a/98042.png)](https://asciinema.org/a/98042)
66+
67+
### Firmware Demo
68+
[![asciicast](https://asciinema.org/a/96442.png)](https://asciinema.org/a/96442)
69+
70+
## Appendix
71+
72+
### Configuration Files
73+
The config.h file included in this project is auto-generated by GNU Autoconf, a tool used to create portable configuration scripts for software packages.
74+
75+
### Why This Does Not Impact the MIT License
76+
77+
* The config.h file is generated based on the configure script, which is authored by the project maintainers and licensed under the MIT License.
78+
79+
* The use of GNU Autoconf to generate config.h does not impose any restrictions or change the licensing terms of the project. The MIT License remains fully applicable to all source code and files authored by the project maintainers.
80+
81+
* Files generated by GNU Autoconf, such as config.h, are considered part of the build process and do not affect the permissive nature of the MIT License applied to the project.
82+
83+
These files are distributed as part of the project to ensure ease of use and portability. Their inclusion does not affect the licensing of the project’s source code, which remains under the MIT License.

0 commit comments

Comments
 (0)