svn commit: r241401 - head/tools/tools/cxgbetool
Navdeep Parhar
np at FreeBSD.org
Wed Oct 10 17:29:52 UTC 2012
Author: np
Date: Wed Oct 10 17:29:51 2012
New Revision: 241401
URL: http://svn.freebsd.org/changeset/base/241401
Log:
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.)
Modified:
head/tools/tools/cxgbetool/cxgbetool.c
Modified: head/tools/tools/cxgbetool/cxgbetool.c
==============================================================================
--- head/tools/tools/cxgbetool/cxgbetool.c Wed Oct 10 17:15:34 2012 (r241400)
+++ head/tools/tools/cxgbetool/cxgbetool.c Wed Oct 10 17:29:51 2012 (r241401)
@@ -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);
More information about the svn-src-head
mailing list