Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - How to access mpc85xx_dev_t structure.: (9 Items)
   
How to access mpc85xx_dev_t structure.  
Hi All,

We have mpc8548 target board with QNX6.4.1 version.
The io-pkt is started from one of the start-up script using the following command.
io-pkt-v4-hc -dmpc85xx mac=00:01:02:03:04:05,verbose -ptcpip

My requirement is need to manage a device (Layer-2 switch) connected over MDIO bus. After walking through the QNX stack 
code , we identified that mpc85xx_dev_t structure has function pointers for Read and Write functions to access PHYs 
connected over MDIO bus. To proceed further, we would like confirm the approach we are planning to take is feasible and 
meets my requirement. 

Approach:
------------
 Write a resource manager and get mpc85xx structure instance by using OS call and then access the device registers by 
using mpc85xx->mdi->Read and mpc85xx->mdi->Write functions calls. 
 Here we are assuming that when we mount this resource manager with io-pkt, the resource manager runs as a thread in io-
pkt process so it is possible to use the  mpc85xx->mdi->Read  function pointer with out any memory corruption. I mean 
the pointer value in io-pkt stack is valid in resource manager thread. Is this assumption correct ?


Please clarify the following points.

1) is it feasible to access device registers with above approcah ?
2) If feasible, how do I get mpc85xx structure in my resource manager ?

Please suggest if there is a better way of implementation.

Thanks in advance.

- Ramakrishna
RE: How to access mpc85xx_dev_t structure.  
For most hardware, you need to have a single device
driver which as sole owner of the hardware, provides
access to that hardware to multiple clients.

Having two separate entities, which know nothing about 
each other, accessing the same hardware, is a pretty 
good receipe for chaos - see:

http://en.wikipedia.org/wiki/Race_condition#Computing

I might suggest that to accomplish what you want to
do - execute the driver MDI read and write functions - 
you add support for these in the driver devctl.c

I have done something similar in the past for other
drivers, when clients wanted to access hardware resource
of the hardware managed by the driver.

This technique assures that the hardware does not
get scrambled by two different people trying to talk
to it at the same time.

--
aboyd
Re: RE: How to access mpc85xx_dev_t structure.  
Hi Aboyd,

Thanks for your suggestion. It looks appropriate to extend the devctl in mpc driver. I am going to try the approach 
suggested by you but one limitaion I see is, if I upgrade the QNX version to higher one in future It mandates all 
changes done now needs to be merged and tested again. 

Is there any possiblity that in future QNX releases contain mpc driver with devctl support for read and write ?

I came accross a line saying that "emu phy is used for managing switches via MDIO bus.  Could you please point to me to 
more details on emu phy. Is it really useful to manage the device/configure PHYs from multiple clients.

Regards,
Ramakrishna
RE: RE: How to access mpc85xx_dev_t structure.  
 
> (released) mpc driver with devctl support for read and write ?

Create a PR and assign it to Bert and he will prioritize it.
 
--
aboyd
 
Re: RE: RE: How to access mpc85xx_dev_t structure.  
Hi Aboyd,

I have extended the ioctl support for MDI read & write in mpc85xx driver. It is working fine and able to manage the 
device via MDIO bus. 

Please comment on the following 3 steps for the approcah taken to experiment this.
Basically, we wanted to avoid the steps 1 & 2 below completely and interface name hard coding (tsec0) in step 3 when we 
upgrade QNX version from 6.4.1 to higher. 
So that client software will just open socket and invoke ioctl command with required data.

Please suggest if any the steps given below are wrong or can be improved. 

1) Currently, I have defined MACROs for MDIO read and write ioctl commands as follows.

#define SIOCG_MDI_READ   _IOWR('i', 61, struct ifreq)   /* Read mii */
#define SIOCS_MDI_WRITE  _IOW('i', 62, struct ifreq)    /* write mii */

2) I have declared a new data structure as follows and used it in MDIO read and write ioctls.

typedef struct {
   uint8_t phy_addr;
   uint8_t reg_addr;
   uint16_t value;
} test_data_t;

typedef struct {
   char ifr_name[IFNAMSIZ];
   union {
       test_data_t mdio_data;
   } data;
} interface_data_t;

3) Now I am filling the data structure (interface_data_t) based on MDIO read or write call and invoking the 
corresponding ioctl.

code snippet:
{
  interface_data_t itf_data;

  fd = socket(AF_INET, SOCK_DGRAM, 0);

  strcpy(itf_data.ifr_name, "tsec0");
  itf_data.data.mdio_data.phy_addr = 0x03;
  itf_data.data.mdio_data.reg_addr = 0x00;

  ioctl(fd, SIOCG_MDI_READ, &itf_data)
}

I am  new to create a PR in QNX forum, Please let me how to create a PR.
Sorry for the big mail and thanks for your time.

Regards,
Ramakrishna


RE: RE: RE: How to access mpc85xx_dev_t structure.  
 
In addition to the application code, I presume you have
modified the driver devctl.c for the mdio read/write
ioctls.  

Remember that although the mpc85xx_mii_read() and 
mpc85xx_mii_write() functions are internally mutexed,
if both you and the driver are performing a sequence
of reads and writes involving the same PHY registers,
you can still trip over each other, because there is
not overall mutex for the entire sequence of accesses.

Not sure if this is a problem for what you want to
do or not.  Hopefully not.

Anyways, you should have your support person/TAM/FAE/etc
create a PR and assign this to Bert Gemin for prioritization,
because even although it might be convenient for development
to occur in an random and chaotic fashion, it's really
better for it to be organized and controlled.

--
aboyd
Re: How to access mpc85xx_dev_t structure.  
> mac=00:01:02:03:04:05
>    
A bit off topic, but that's a MAC address out of the globally unique 
(OUI) scope, and I don't think that's what you intended...

/P
Re: How to access mpc85xx_dev_t structure.  
Yes, you are correct. Actually it is read from u-boot environmental variable and passed as mac=$MACADDR. My intention is
 to show the command I am using to start io-pkt.

Thanks,
Ramakrishna
Re: How to access mpc85xx_dev_t structure.  
If it's simply control the MDIO bus(read/write through MDIO bus), I guess what you can do is to extend the devctl in 
devctl.c and your application simply use this new added devctl to control the MDIO bus access.