Example #1
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 #2
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;
}