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.)
This commit is contained in:
np 2012-10-10 17:29:51 +00:00
parent 99dca09c83
commit 6764c20438

View File

@ -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"
@ -1521,6 +1523,60 @@ read_tcb(int argc, const char *argv[])
return (read_mem(addr, TCB_SIZE, show_tcb));
}
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[])
{
@ -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);