Example #1
0
static int do_one_xcvr(int skfd, char *ifname, int maybe)
{
    struct mii_data *mii = (struct mii_data *)&ifr.ifr_data;

    /* Get the vitals from the interface. */
    strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
    if (ioctl(skfd, SIOCGMIIPHY, &ifr) < 0) {
	if (!maybe || (errno != ENODEV))
	    fprintf(stderr, "SIOCGMIIPHY on '%s' failed: %s\n",
		    ifname, strerror(errno));
	return 1;
    }

    if (override_phy >= 0) {
	printf("using the specified MII index %d.\n", override_phy);
	mii->phy_id = override_phy;
    }

    if (opt_reset) {
	printf("resetting the transceiver...\n");
	mdio_write(skfd, MII_BMCR, MII_BMCR_RESET);
    }
    if (nway_advertise) {
	mdio_write(skfd, MII_ANAR, nway_advertise | 1);
	opt_restart = 1;
    }
    if (opt_restart) {
	printf("restarting autonegotiation...\n");
	mdio_write(skfd, MII_BMCR, 0x0000);
	mdio_write(skfd, MII_BMCR, MII_BMCR_AN_ENA|MII_BMCR_RESTART);
    }
    if (fixed_speed) {
	int bmcr = 0;
	if (fixed_speed & (MII_AN_100BASETX_FD|MII_AN_100BASETX_HD))
	    bmcr |= MII_BMCR_100MBIT;
	if (fixed_speed & (MII_AN_100BASETX_FD|MII_AN_10BASET_FD))
	    bmcr |= MII_BMCR_DUPLEX;
	mdio_write(skfd, MII_BMCR, bmcr);
    }

    if (!opt_restart && !opt_reset && !fixed_speed && !nway_advertise)
	show_basic_mii(skfd, mii->phy_id);

    return 0;
}
Example #2
0
static void watch_one_xcvr(int skfd, char *ifname, int index)
{
    struct mii_data *mii = (struct mii_data *)&ifr.ifr_data;
    static int status[MAX_ETH] = { 0, /* ... */ };
    int now;

    /* Get the vitals from the interface. */
    strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
    if (ioctl(skfd, SIOCGMIIPHY, &ifr) < 0) {
	if (errno != ENODEV)
	    fprintf(stderr, "SIOCGMIIPHY on '%s' failed: %s\n",
		    ifname, strerror(errno));
	return;
    }
    now = (mdio_read(skfd, MII_BMCR) |
	   (mdio_read(skfd, MII_BMSR) << 16));
    if (status[index] && (status[index] != now))
	show_basic_mii(skfd, mii->phy_id);
    status[index] = now;
}
Example #3
0
int do_one_xcvr(int skfd)
{
	u16 *data = (u16 *)(&ifr.ifr_data);
	u32 *data32 = (u32 *)(&ifr.ifr_data);
	unsigned phy_id = data[0];

	if (override_phy >= 0) {
		printf("Using the specified MII PHY index %d.\n", override_phy);
		phy_id = override_phy;
	}

	if (opt_g || opt_G || msg_level >= 0) {
		if (ioctl(skfd, SIOCGPARAMS, &ifr) < 0) {
			fprintf(stderr, "SIOCGPARAMS on %s failed: %s\n", ifr.ifr_name,
					strerror(errno));
			return -1;
		}
	}
	if (opt_g) {
		int i;
		printf("Driver general parameter settings:");
		for (i = 0; i*sizeof(u32) < sizeof(ifr.ifr_ifru); i++) {
			printf(" %d", data32[i]);
		}
		printf(".\n");
	}
	if (opt_G) {
		/* Set up to four arbitrary driver parameters from the -G parameter.
		   The format is comma separated integers, with a missing element
		   retaining the previous value.
		*/
		char *str = opt_G_string;
		int i;
		for (i = 0; str && i < 4; i++) {
			char *endstr;
			u32 newval = strtol(str, &endstr, 0);
			if (debug)
				printf(" parse string '%s'  value %d end '%s'.\n",
					   str, newval, endstr);
			if (str == endstr) {
				if (endstr[0] == ',') /* No parameter */
					str = endstr+1;
				else {
					fprintf(stderr, "Invalid driver parameter '%s'.\n", str);
					str = index(str, ',');
				}
			} else if (endstr[0] == ',') {
				data32[i] = newval;
				str = endstr + 1;
			} else if (endstr[0] == 0) {
				data32[i] = newval;
				break;
			}
		}
		printf("Setting new driver general parameters:");
		for (i = 0; i*sizeof(u32) < sizeof(ifr.ifr_ifru); i++) {
			printf(" %d", data32[i]);
		}
		printf(".\n");
		if (ioctl(skfd, SIOCSPARAMS, &ifr) < 0) {
			fprintf(stderr, "SIOCSPARAMS on %s failed: %s\n", ifr.ifr_name,
					strerror(errno));
			return -1;
		}
	}
	if (msg_level >= 0) {
		data32[0] = msg_level;
		if (ioctl(skfd, SIOCSPARAMS, &ifr) < 0) {
			fprintf(stderr, "SIOCSPARAMS on %s failed: %s\n", ifr.ifr_name,
					strerror(errno));
			return -1;
		}
	}

	if (opt_reset) {
		printf("Resetting the transceiver...\n");
		mdio_write(skfd, phy_id, 0, 0x8000);
	}
	/* Note: PHY addresses > 32 are pseudo-MII devices, usually built-in. */
	if (phy_id < 64  &&  nway_advertise > 0) {
		printf(" Setting the media capability advertisement register of "
			   "PHY #%d to 0x%4.4x.\n", phy_id, nway_advertise | 1);
		mdio_write(skfd, phy_id, 4, nway_advertise | 1);
		mdio_write(skfd, phy_id, 0, 0x1000);
	}

	if (opt_restart) {
		printf("Restarting negotiation...\n");
		mdio_write(skfd, phy_id, 0, 0x0000);
		mdio_write(skfd, phy_id, 0, 0x1200);
	}
	/* To force 100baseTx-HD do  mdio_write(skfd, phy_id, 0, 0x2000); */
	if (fixed_speed >= 0) {
		int reg0_val = 0;
		if (fixed_speed & 0x0180) 		/* 100mpbs */
			reg0_val |=  0x2000;
		if ((fixed_speed & 0x0140) &&		/* A full duplex type and */
			! (fixed_speed & 0x0820)) 		/* no half duplex types. */
			reg0_val |= 0x0100;
		printf("Setting the speed to \"fixed\", Control register %4.4x.\n",
			   reg0_val);
		mdio_write(skfd, phy_id, 0, reg0_val);
	}
	if (set_BMCR >= 0) {
		printf("Setting the Basic Mode Control Register to 0x%4.4x.\n",
			   set_BMCR);
		mdio_write(skfd, phy_id, 0, set_BMCR);
	}

	if (opt_watch && opt_status)
		monitor_status(skfd, phy_id);

	show_basic_mii(skfd, phy_id);
#ifdef LIBMII
	if (verbose)
		show_mii_details(skfd, phy_id);
#else
	if (verbose || debug) {
		int mii_reg, mii_val;
		printf(" MII PHY #%d transceiver registers:", phy_id);
		for (mii_reg = 0; mii_reg < 32; mii_reg++) {
			mii_val = mdio_read(skfd, phy_id, mii_reg);
			printf("%s %4.4x", (mii_reg % 8) == 0 ? "\n  " : "",
				   mii_val);
		}
		printf("\n");
	}
#endif

	if (opt_watch)
		monitor_mii(skfd, phy_id);
	if (opt_status &&
		(mdio_read(skfd, phy_id, 1) & 0x0004) == 0)
		exit(2);
	return 0;
}
Example #4
0
int
do_one_xcvr(int skfd)
{
   u16 *data = (u16 *)(&ifr.ifr_data);
   unsigned phy_id = data[0];

   if (override_phy >= 0)
   {
      printf("Using the specified MII PHY index %d.\n", override_phy);
      phy_id = override_phy;
   }

   if (opt_G)
   {
      /* Set an undefined general-purpose value.
         Modify this code section to do special hacks such as
         mdio_write(skfd, phy_id, 19, opt_G_value);
       */
#if 0 // hkim
      u32 *data = (u32 *)(&ifr.ifr_data);
      data[0] = opt_G_value;
      if (ioctl(skfd, SIOCSPARAMS, &ifr) < 0)
      {
         fprintf(stderr, "SIOCSPARAMS on %s failed: %s\n", ifr.ifr_name, strerror(errno));
         return -1;
      }
#else
      fprintf(stderr, "SIOCSPARAMS not supported\n");
      return -1;
#endif
   }

   if (opt_reset)
   {
      printf("Resetting the transceiver...\n");
      mdio_write(skfd, phy_id, 0, 0x8000);
   }

   /* Note: PHY addresses > 32 are pseudo-MII devices, usually built-in. */
   if (phy_id < 64  &&  nway_advertise >= 0)
   {
      printf(" Setting the media capability advertisement register of "
             "PHY #%d to 0x%4.4x.\n", phy_id, nway_advertise | 1);
      mdio_write(skfd, phy_id, 4, nway_advertise | 1);
      mdio_write(skfd, phy_id, 0, 0x1000);
   }

   if (opt_restart)
   {
      printf("Restarting negotiation...\n");
      mdio_write(skfd, phy_id, 0, 0x0000);
      mdio_write(skfd, phy_id, 0, 0x1200);
   }
   
   /* To force 100baseTx-HD do  mdio_write(skfd, phy_id, 0, 0x2000); */

   if (fixed_speed >= 0)
   {
      int reg0_val = 0;
      if (fixed_speed & 0x0180)        /* 100mpbs */
         reg0_val |=  0x2000;

      if (fixed_speed & 0x0140)        /* Full duplex */
         reg0_val |= 0x0100;

      printf("Setting the speed to \"fixed\", Control register %4.4x.\n", reg0_val);
      mdio_write(skfd, phy_id, 0, reg0_val);
   }

   show_basic_mii(skfd, phy_id);
#ifdef LIBMII
   if(verbose)
      show_mii_details(skfd, phy_id);
#else
   if (verbose || debug)
   {
      int mii_reg, mii_val;
      printf(" MII PHY #%d transceiver registers:", phy_id);
      for (mii_reg = 0; mii_reg < 32; mii_reg++)
      {
         mii_val = mdio_read(skfd, phy_id, mii_reg);
         printf("%s %4.4x", (mii_reg % 8) == 0 ? "\n  " : "", mii_val);
      }
      printf("\n");
   }
#endif

   if (opt_watch)
      monitor_mii(skfd, phy_id);
   if (opt_status && (mdio_read(skfd, phy_id, 1) & 0x0004) == 0)
      exit(2);
   return 0;
}