ucmd_net100.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* net100: ring-3 command. Force 100BASE-TX or restore auto/1G.
  2. *
  3. * This is the diagnostic fallback for a marginal 1000M pair/jack: 100BASE-TX
  4. * uses only two pairs, so a link that reports 1000M but loses DHCP/ARP
  5. * broadcasts can still be fully usable. The driver keeps the setting until
  6. * `net100 off` or reboot. */
  7. #include "ucmd_lib.h"
  8. static int arg_is(const char *arg, const char *word)
  9. {
  10. unsigned int i = 0;
  11. while (arg[i] && word[i] && arg[i] == word[i])
  12. i++;
  13. return arg[i] == '\0' && word[i] == '\0';
  14. }
  15. static void usage(void)
  16. {
  17. u_puts("net100: usage net100 [on|off] (on = force 100M, off = auto/1G)\n");
  18. }
  19. void _start(const char *arg)
  20. {
  21. struct sys_netinfo n;
  22. unsigned int mbps;
  23. int r;
  24. if (!arg || !arg[0] || arg_is(arg, "on") || arg_is(arg, "100"))
  25. mbps = 100;
  26. else if (arg_is(arg, "off") || arg_is(arg, "auto") ||
  27. arg_is(arg, "1000"))
  28. mbps = 0;
  29. else {
  30. usage();
  31. u_exit(1);
  32. }
  33. if (u_syscall1(SYS_NET_INFO, (int)&n) != 1) {
  34. u_puts("net100: no NIC found\n");
  35. u_exit(1);
  36. }
  37. r = u_syscall1(SYS_NET_SPEED, (int)mbps);
  38. if (r == -1) {
  39. u_puts("net100: speed control not supported by ");
  40. u_puts(n.name);
  41. u_putc('\n');
  42. u_exit(1);
  43. }
  44. if (r == -2) {
  45. u_puts("net100: NIC is busy (see ps)\n");
  46. u_exit(1);
  47. }
  48. u_puts(mbps == 100 ? "net100: forcing 100M\n"
  49. : "net100: restoring auto/1G\n");
  50. u_syscall0(SYS_NET_PRINT_INFO);
  51. if (r == -3) {
  52. u_puts("net100: link did not come up; check the cable/port\n");
  53. u_exit(1);
  54. }
  55. if (r == -4) {
  56. u_puts("net100: link is up but not at 100M\n");
  57. u_exit(1);
  58. }
  59. u_exit(0);
  60. }