Skip to content

Commit

Permalink
Merge pull request #1 from westermo/basic-help
Browse files Browse the repository at this point in the history
Basic help
  • Loading branch information
wkz committed Jan 31, 2016
2 parents 9687ff5 + 72799b5 commit e32d53e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 5 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,49 @@ phytool
=======

Linux MII register access


Usage
-----

phytool read iface/phy/reg
phytool write iface/phy/reg val
phytool print iface/phy[/reg]

The PHY argument is either in clause-22 direct adressing syntax, or in
clause-45 syntax `port:dev`. Where `port` is the MDIO port address and
`dev` is the device's PHY address (0x1-0xA), MAC register (0x10-0x1A),
the global register (0x1B), or the global2 register (0x1C)

Some devices have a SERDES specific page on `dev` address 0xF


Examples
--------

~ # phytool read eth4/0/4
0x0de1

~ # phytool print eth4/0
ieee-phy: id:0x01410eb1

ieee-phy: reg:BMCR(0x00) val:0x0800
flags: reset loopback aneg-enable power-down isolate aneg-restart collision-test
speed: 10-half
○ ○ ○ ○ ◉ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
0 8 0 0

ieee-phy: reg:BMSR(0x01) val:0x7949
link capabilities: 100-b4 100-f 100-h 10-f 10-h 100-t2-f 100-t2-h
flags: ext-status aneg-complete remote-fault aneg-capable link jabber ext-register
○ ◉ ◉ ◉ ◉ ○ ○ ◉ ○ ◉ ○ ○ ◉ ○ ○ ◉
7 9 4 9


Origin & References
-------------------

phytool is developed and maintained by Tobias Waldekranz.
Please file bug fixes and pull requests at [GitHub][]

[GitHub]: https://github.com/wkz/phytool
35 changes: 30 additions & 5 deletions phytool.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

#include "phytool.h"

extern char *__progname;


static int __phy_op(const struct loc *loc, uint16_t *val, int cmd)
{
static int sd = -1;
Expand Down Expand Up @@ -227,17 +230,39 @@ static struct printer printer[] = {
{ .name = NULL }
};

static int usage(int code)
{
printf("\nUsage:\n"
"\t%s read iface/phy/reg\n"
"\t%s write iface/phy/reg val\n"
"\t%s print iface/phy[/reg]\n"
"\nExamples:\n"
"\t%s read eth0/0/4\n"
"\t%s read eth1-2/1:0x10/4\n"
"\t%s print eth1-2/1:0x10\n"
"\n"
"The PHY argument is either in clause-22 direct adressing syntax, or in\n"
"clause-45 syntax `port:dev`. Where `port` is the MDIO port address and\n"
"`dev` is the device's PHY address (0x0-0xA), MAC register (0x10-0x1A),\n"
"the global register (0x1B), or the global2 register (0x1C).\n\n"
"Some devices have a SERDES specific page on `dev` address 0xF.\n\n"
"Bug report address: https://github.com/wkz/phytool/issues\n\n",
__progname, __progname, __progname, __progname, __progname, __progname);

return code;
}

int main(int argc, char **argv)
{
char *bin = basename(argv[0]);
struct printer *p;

if (argc < 2)
return 1;
return usage(1);

for (p = printer; p->name; p++)
if (!strcmp(bin, p->name))
for (p = printer; p->name; p++) {
if (!strcmp(__progname, p->name))
break;
}

if (!p->name)
p = printer;
Expand All @@ -250,5 +275,5 @@ int main(int argc, char **argv)
return phytool_print(p->print, argc - 2, &argv[2]);

fprintf(stderr, "error: unknown command \"%s\"\n", argv[1]);
return 1;
return usage(1);
}

0 comments on commit e32d53e

Please sign in to comment.