linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Xilinx Temac link detect
@ 2008-02-21 17:36 khollan
  2008-03-06 20:44 ` khollan
  0 siblings, 1 reply; 5+ messages in thread
From: khollan @ 2008-02-21 17:36 UTC (permalink / raw)
  To: linuxppc-embedded


Hi 

Is there a good way to detect if the ethernet link is active at boot time,
so I can decided to setup the dchp and other network required stuff in an
init script.  When I try to setup this stuff and the cable is disconnected
it hangs.

Thanks

Kevin
-- 
View this message in context: http://www.nabble.com/Xilinx-Temac-link-detect-tp15616042p15616042.html
Sent from the linuxppc-embedded mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Xilinx Temac link detect
  2008-02-21 17:36 Xilinx Temac link detect khollan
@ 2008-03-06 20:44 ` khollan
  2008-03-06 22:14   ` John Linn
  0 siblings, 1 reply; 5+ messages in thread
From: khollan @ 2008-03-06 20:44 UTC (permalink / raw)
  To: linuxppc-embedded



I figure I could write a C program to talk to the ioctl in the TEMAC driver
and read the PHY register.  Does anyone have example code for talking to
network ioctl's?

Thanks

Kevin
-- 
View this message in context: http://www.nabble.com/Xilinx-Temac-link-detect-tp15616042p15883376.html
Sent from the linuxppc-embedded mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Xilinx Temac link detect
  2008-03-06 20:44 ` khollan
@ 2008-03-06 22:14   ` John Linn
  2008-03-07 14:29     ` Koss, Mike (Mission Systems)
  0 siblings, 1 reply; 5+ messages in thread
From: John Linn @ 2008-03-06 22:14 UTC (permalink / raw)
  To: khollan, linuxppc-embedded

Hi Kevin,

I couldn't find any example laying around, so I took a shot at it based
on other non-network examples we had. I've not personally done it so
bear that in mind.

I have not tried to compile any of this, just stole parts for places and
pasted in.

Hope it helps,
John

#include <ioctl.h>

	/*
 	 * FD of the IIC device opened.
 	 */
	int Fdtemac;

	struct mii_ioctl_data ioctl_data;=09

	/*
	 * Open the device.
	 */
	Fdtemac =3D open("/dev/TBD", O_RDWR);
	if(Fdtemac < 0)
	{
		printf("Cannot open the temac device\n");
		return -1;
	}

	/* setup the inputs to the ioctl call */

	ioctl_data.phy_num =3D TBD;
	ioctl_data.reg_num =3D TBD;
=09
	/*
	 * Read the phy register
	 */
	Register =3D ioctl(Fdtemac, SIOCGMIIREG, &ioctl_data);
	if(Status < 0)
	{
		/* failure */
		return 0;
	}

	/* results should be in ioctl_data.val_out I think

}

>From the temac linux adapter, a snippet showing the the ioctl function.

xenet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
    struct mii_ioctl_data *data =3D (struct mii_ioctl_data *)
&rq->ifr_data;

    case SIOCGMIIREG:   /* Read GMII PHY register. */
        ret =3D XTemac_PhyRead(&lp->Emac, data->phy_id,
                       data->reg_num, &data->val_out);
}

from linux/mii.h

/* This structure is used in all SIOCxMIIxxx ioctl calls */
struct mii_ioctl_data {
	__u16		phy_id;
	__u16		reg_num;
	__u16		val_in;
	__u16		val_out;
};

from linux/if.h

struct ifreq=20
{
#define IFHWADDRLEN	6
	union
	{
		char	ifrn_name[IFNAMSIZ];		/* if name, e.g.
"en0" */
	} ifr_ifrn;
=09
	union {
		struct	sockaddr ifru_addr;
		struct	sockaddr ifru_dstaddr;
		struct	sockaddr ifru_broadaddr;
		struct	sockaddr ifru_netmask;
		struct  sockaddr ifru_hwaddr;
		short	ifru_flags;
		int	ifru_ivalue;
		int	ifru_mtu;
		struct  ifmap ifru_map;
		char	ifru_slave[IFNAMSIZ];	/* Just fits the size */
		char	ifru_newname[IFNAMSIZ];
		void __user *	ifru_data;
		struct	if_settings ifru_settings;
	} ifr_ifru;
};

-----Original Message-----
From: linuxppc-embedded-bounces+john.linn=3Dxilinx.com@ozlabs.org
[mailto:linuxppc-embedded-bounces+john.linn=3Dxilinx.com@ozlabs.org] On
Behalf Of khollan
Sent: Thursday, March 06, 2008 1:44 PM
To: linuxppc-embedded@ozlabs.org
Subject: Re: Xilinx Temac link detect



I figure I could write a C program to talk to the ioctl in the TEMAC
driver
and read the PHY register.  Does anyone have example code for talking to
network ioctl's?

Thanks

Kevin
--=20
View this message in context:
http://www.nabble.com/Xilinx-Temac-link-detect-tp15616042p15883376.html
Sent from the linuxppc-embedded mailing list archive at Nabble.com.

_______________________________________________
Linuxppc-embedded mailing list
Linuxppc-embedded@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-embedded

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Xilinx Temac link detect
  2008-03-06 22:14   ` John Linn
@ 2008-03-07 14:29     ` Koss, Mike (Mission Systems)
  2008-03-10 20:34       ` khollan
  0 siblings, 1 reply; 5+ messages in thread
From: Koss, Mike (Mission Systems) @ 2008-03-07 14:29 UTC (permalink / raw)
  To: John Linn, khollan, linuxppc-embedded

Here's a snippet from a program I use to debug an ethernet driver that I
have using ioctl's. The ethernet ioctl interface is slightly different
from a "normal" ioctl in that it uses sockets and not a file descriptor.
The ioctl's I use are added to the ioctl interface in the driver, using
the defined device-specific range (that was supposed to disappear in
2.5.x or 2.6.x). With this I read/write my phy register's to test out
the interface between my TEMAC and my PHY.=20

#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <net/if.h>
#include <linux/sockios.h>

int main (int argc, char **argv)
{
   int   driver_fd =3D -1;
   int   cmd       =3D 0;
   int   res;
   char* buffer    =3D NULL;
   struct ifreq ifr;

   if (argc < 3)
   {
      printf ("Usage %s <devname> <ioctl>\n", argv [0]);
      exit (1);
   }

   driver_fd =3D socket(AF_INET, SOCK_DGRAM, 0);
   if (driver_fd =3D=3D -1)
   {
      printf ("Could not open %s: %s\n", TEMAC_DRIVER_NAME, strerror
(errno));
      exit (1);
   }

   memset(&ifr, 0, sizeof(struct ifreq));
   strcpy(ifr.ifr_name, argv[1]);

   cmd =3D atoi (argv [2]);
   if (SIOCDEVPRIVATE + 3 =3D=3D cmd) {
      if (argc !=3D 4) {
         printf("usage %s <devname> 35315 <phy reg>\n", argv[0]);
         exit(1);
      }

      ifr.ifr_ifindex =3D atoi(argv[3]);
   }
   if (SIOCDEVPRIVATE + 4 =3D=3D cmd) {
      if (argc !=3D 5) {
         printf("usage %s <devname> 35316 <phy reg> <val>\n", argv[0]);
         exit(1);
      }

      ifr.ifr_ifindex =3D atoi(argv[3]) << 16;
      ifr.ifr_ifindex |=3D atoi(argv[4]);
   }
   printf("Performing ioctl %d:\n", cmd);

   res =3D ioctl(driver_fd, cmd, &ifr);

   if (res =3D=3D -1)
   {
      printf ("Error from %d: %s\n", driver_fd, strerror (errno));
      exit (1);
   }

   return 0;
}

-----Original Message-----
From: John Linn [mailto:John.Linn@xilinx.com]=20
Sent: Thursday, March 06, 2008 5:15 PM
To: khollan; linuxppc-embedded@ozlabs.org
Subject: RE: Xilinx Temac link detect

Hi Kevin,

I couldn't find any example laying around, so I took a shot at it based
on other non-network examples we had. I've not personally done it so
bear that in mind.

I have not tried to compile any of this, just stole parts for places and
pasted in.

Hope it helps,
John

#include <ioctl.h>

	/*
 	 * FD of the IIC device opened.
 	 */
	int Fdtemac;

	struct mii_ioctl_data ioctl_data;=09

	/*
	 * Open the device.
	 */
	Fdtemac =3D open("/dev/TBD", O_RDWR);
	if(Fdtemac < 0)
	{
		printf("Cannot open the temac device\n");
		return -1;
	}

	/* setup the inputs to the ioctl call */

	ioctl_data.phy_num =3D TBD;
	ioctl_data.reg_num =3D TBD;
=09
	/*
	 * Read the phy register
	 */
	Register =3D ioctl(Fdtemac, SIOCGMIIREG, &ioctl_data);
	if(Status < 0)
	{
		/* failure */
		return 0;
	}

	/* results should be in ioctl_data.val_out I think

}

>From the temac linux adapter, a snippet showing the the ioctl function.

xenet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
    struct mii_ioctl_data *data =3D (struct mii_ioctl_data *)
&rq->ifr_data;

    case SIOCGMIIREG:   /* Read GMII PHY register. */
        ret =3D XTemac_PhyRead(&lp->Emac, data->phy_id,
                       data->reg_num, &data->val_out); }

from linux/mii.h

/* This structure is used in all SIOCxMIIxxx ioctl calls */ struct
mii_ioctl_data {
	__u16		phy_id;
	__u16		reg_num;
	__u16		val_in;
	__u16		val_out;
};

from linux/if.h

struct ifreq
{
#define IFHWADDRLEN	6
	union
	{
		char	ifrn_name[IFNAMSIZ];		/* if name, e.g.
"en0" */
	} ifr_ifrn;
=09
	union {
		struct	sockaddr ifru_addr;
		struct	sockaddr ifru_dstaddr;
		struct	sockaddr ifru_broadaddr;
		struct	sockaddr ifru_netmask;
		struct  sockaddr ifru_hwaddr;
		short	ifru_flags;
		int	ifru_ivalue;
		int	ifru_mtu;
		struct  ifmap ifru_map;
		char	ifru_slave[IFNAMSIZ];	/* Just fits the size */
		char	ifru_newname[IFNAMSIZ];
		void __user *	ifru_data;
		struct	if_settings ifru_settings;
	} ifr_ifru;
};

-----Original Message-----
From: linuxppc-embedded-bounces+john.linn=3Dxilinx.com@ozlabs.org
[mailto:linuxppc-embedded-bounces+john.linn=3Dxilinx.com@ozlabs.org] On
Behalf Of khollan
Sent: Thursday, March 06, 2008 1:44 PM
To: linuxppc-embedded@ozlabs.org
Subject: Re: Xilinx Temac link detect



I figure I could write a C program to talk to the ioctl in the TEMAC
driver and read the PHY register.  Does anyone have example code for
talking to network ioctl's?

Thanks

Kevin
--
View this message in context:
http://www.nabble.com/Xilinx-Temac-link-detect-tp15616042p15883376.html
Sent from the linuxppc-embedded mailing list archive at Nabble.com.

_______________________________________________
Linuxppc-embedded mailing list
Linuxppc-embedded@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-embedded

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Xilinx Temac link detect
  2008-03-07 14:29     ` Koss, Mike (Mission Systems)
@ 2008-03-10 20:34       ` khollan
  0 siblings, 0 replies; 5+ messages in thread
From: khollan @ 2008-03-10 20:34 UTC (permalink / raw)
  To: linuxppc-embedded



Koss, Mike (Mission Systems) wrote:
> 
> Here's a snippet from a program I use to debug an ethernet driver that I
> have using ioctl's. The ethernet ioctl interface is slightly different
> from a "normal" ioctl in that it uses sockets and not a file descriptor.
> The ioctl's I use are added to the ioctl interface in the driver, using
> the defined device-specific range (that was supposed to disappear in
> 2.5.x or 2.6.x). With this I read/write my phy register's to test out
> the interface between my TEMAC and my PHY. 
> 
> 
Thanks for the example, everything working great now.

Kevin
-- 
View this message in context: http://www.nabble.com/Xilinx-Temac-link-detect-tp15616042p15954121.html
Sent from the linuxppc-embedded mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-03-10 20:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-21 17:36 Xilinx Temac link detect khollan
2008-03-06 20:44 ` khollan
2008-03-06 22:14   ` John Linn
2008-03-07 14:29     ` Koss, Mike (Mission Systems)
2008-03-10 20:34       ` khollan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).