summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authornp <np@FreeBSD.org>2012-10-10 17:29:51 +0000
committernp <np@FreeBSD.org>2012-10-10 17:29:51 +0000
commit6764c204386b7e2539d22a9829cb9a90a4a7d52e (patch)
tree648de8759767a310f742f83afbb0c230fa4dffcf /tools
parent99dca09c832a8b3e5b75d7cb0e7b52c9443df3a8 (diff)
downloadFreeBSD-src-6764c204386b7e2539d22a9829cb9a90a4a7d52e.zip
FreeBSD-src-6764c204386b7e2539d22a9829cb9a90a4a7d52e.tar.gz
Add an "i2c" subcommand to cxgbetool. You can use this to read
information from the transceivers connected to the ports of a cxgbe(4) based card. # cxgbetool t4nex0 i2c <port_id> <dev_addr> <addr> [<count>] For example: # cxgbetool t4nex0 i2c 0 0xa0 3 0x10 [16] (As per SFF-8472 the SFP+ module is at 0xa0 and bit 4 in the value at address 3 indicates it's a 10Gbase-SR module, which it is.)
Diffstat (limited to 'tools')
-rw-r--r--tools/tools/cxgbetool/cxgbetool.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/tools/cxgbetool/cxgbetool.c b/tools/tools/cxgbetool/cxgbetool.c
index 92ac978..74ebd8c 100644
--- a/tools/tools/cxgbetool/cxgbetool.c
+++ b/tools/tools/cxgbetool/cxgbetool.c
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <stdio.h>
#include <sys/ioctl.h>
+#include <limits.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -86,6 +87,7 @@ usage(FILE *fp)
"\tfilter <idx> delete|clear delete a filter\n"
"\tfilter list list all filters\n"
"\tfilter mode [<match>] ... get/set global filter mode\n"
+ "\ti2c <port> <devaddr> <addr> [<len>] read from i2c device\n"
"\tloadfw <fw-image.bin> install firmware\n"
"\tmemdump <addr> <len> dump a memory range\n"
"\treg <address>[=<val>] read/write register\n"
@@ -1522,6 +1524,60 @@ read_tcb(int argc, const char *argv[])
}
static int
+read_i2c(int argc, const char *argv[])
+{
+ char *p;
+ long l;
+ struct t4_i2c_data i2cd;
+ int rc, i;
+
+ if (argc < 3 || argc > 4) {
+ warnx("incorrect number of arguments.");
+ return (EINVAL);
+ }
+
+ p = str_to_number(argv[0], &l, NULL);
+ if (*p || l > UCHAR_MAX) {
+ warnx("invalid port id \"%s\"", argv[0]);
+ return (EINVAL);
+ }
+ i2cd.port_id = l;
+
+ p = str_to_number(argv[1], &l, NULL);
+ if (*p || l > UCHAR_MAX) {
+ warnx("invalid i2c device address \"%s\"", argv[1]);
+ return (EINVAL);
+ }
+ i2cd.dev_addr = l;
+
+ p = str_to_number(argv[2], &l, NULL);
+ if (*p || l > UCHAR_MAX) {
+ warnx("invalid byte offset \"%s\"", argv[2]);
+ return (EINVAL);
+ }
+ i2cd.offset = l;
+
+ if (argc == 4) {
+ p = str_to_number(argv[3], &l, NULL);
+ if (*p || l > sizeof(i2cd.data)) {
+ warnx("invalid number of bytes \"%s\"", argv[3]);
+ return (EINVAL);
+ }
+ i2cd.len = l;
+ } else
+ i2cd.len = 1;
+
+ rc = doit(CHELSIO_T4_GET_I2C, &i2cd);
+ if (rc != 0)
+ return (rc);
+
+ for (i = 0; i < i2cd.len; i++)
+ printf("0x%x [%u]\n", i2cd.data[i], i2cd.data[i]);
+
+ return (0);
+}
+
+static int
run_cmd(int argc, const char *argv[])
{
int rc = -1;
@@ -1547,6 +1603,8 @@ run_cmd(int argc, const char *argv[])
rc = memdump(argc, argv);
else if (!strcmp(cmd, "tcb"))
rc = read_tcb(argc, argv);
+ else if (!strcmp(cmd, "i2c"))
+ rc = read_i2c(argc, argv);
else {
rc = EINVAL;
warnx("invalid command \"%s\"", cmd);
OpenPOWER on IntegriCloud