Jorge Almeida wrote: > Hello Jan. > > > In attach follows a patch for the link beat functionality for the rt_8139too > driver and SOCK_RAW.
Fine. I added my comments below.
>
> For more drivers to support this it must be implemented in the driver (like
> rt_8139too) but it think is easy.
Yep.
>
> For the other sockets the only thing to do is add two or three code lines in
> the ioctl function.
>
>
> To get the link bit of one board use something like this:
>
> bool CRtEthernetComm::CheckLinkBeat( int n_if_index )
> {
> int nReturn = -1;
> struct rtnet_device_monitoring sMonitoring;
> sMonitoring.ifindex = n_if_index;
>
> nReturn = rt_dev_ioctl(m_nFileDescriptor,
> RTNET_RTIOC_MONITORING_LINK_BEAT, &sMonitoring);
> if(nReturn < 0)
> {
> CPrint::Instance()->Print( "Error retrieving link beat information.
> Error = %d\n",nReturn);
> return false;
> }
> if(sMonitoring.link_beat == 1)
> return true;
>
> return false;
> }
>
>
> I've already test it adn it works fine.
> Plese test it in one of your boards, or anyone that reads this e-mail.
>
> Greetings
>
<snipped a lot of redundant text...>
> ------------------------------------------------------------------------
>
> Index: stack/include/rtnet.h
> ===================================================================
> --- stack/include/rtnet.h (revision 1087)
> +++ stack/include/rtnet.h (working copy)
> @@ -52,6 +52,14 @@
> void *arg;
> };
>
> +/*
> + * Monitoring Device structure
> + */
> +struct rtnet_device_monitoring
> +{
> + int ifindex;
> + int link_beat;
> +};
So, is this the final structure for the request or do you plan to attach
more information already? The question is what primary purpose it should
be optimised for. If performance doesn't matter that much, we could
bundle as much information as make sense for an enhanced device status
(as you suggested yesterday).
But then I would really prefer to keep the structure close to ifreq,
i.e. identification via name, embedded information in the existing space
(there is room, just takes some overloading of types). This would allow
to reuse existing code to pass the information up/down. We do not
perform user-safe argument passing yet, but once we do, I would like to
concentrate on as few different spots as possible.
>
> /* sub-classes: RTDM_CLASS_NETWORK */
> #define RTDM_SUBCLASS_RTNET 0
> @@ -70,6 +78,13 @@
> #define RTNET_RTIOC_EXTPOOL _IOW(RTIOC_TYPE_NETWORK, 0x14, unsigned int)
> #define RTNET_RTIOC_SHRPOOL _IOW(RTIOC_TYPE_NETWORK, 0x15, unsigned int)
>
> +
> +/* RTnet Monitoring Ioctls */
> +// this must be different from RTIOC_TYPE_NETWORK
> +#define RTIOC_TYPE_NETWORK_MONITORING 152
I would prefer to not define a new RTIOC class for this, rather keep it
under RTIOC_TYPE_NETWORK.
> +
> +#define RTNET_RTIOC_MONITORING_LINK_BEAT _IOW(RTIOC_TYPE_NETWORK_MONITORING,
> 0x01, struct rtnet_device_monitoring )
> +
> /* socket transmission priorities */
> #define SOCK_MAX_PRIO 0
> #define SOCK_DEF_PRIO SOCK_MAX_PRIO + \
> Index: stack/include/rtnet_socket.h
> ===================================================================
> --- stack/include/rtnet_socket.h (revision 1087)
> +++ stack/include/rtnet_socket.h (working copy)
> @@ -103,5 +103,7 @@
> extern int rt_socket_if_ioctl(struct rtdm_dev_context *context,
> rtdm_user_info_t *user_info,
> int request, void *arg);
> -
> +extern int rt_socket_monitoring_ioctl(struct rtdm_dev_context *context,
> + rtdm_user_info_t *user_info,
> + int request, void *arg);
> #endif /* __RTNET_SOCKET_H_ */
> Index: stack/packet/af_packet.c
> ===================================================================
> --- stack/packet/af_packet.c (revision 1087)
> +++ stack/packet/af_packet.c (working copy)
> @@ -243,12 +243,16 @@
> struct rtsocket *sock = (struct rtsocket *)&sockctx->dev_private;
> struct _rtdm_setsockaddr_args *setaddr = arg;
> struct _rtdm_getsockaddr_args *getaddr = arg;
> + struct rtnet_device_monitoring* test = (struct
> rtnet_device_monitoring*)arg;
>
> -
> /* fast path for common socket IOCTLs */
> if (_IOC_TYPE(request) == RTIOC_TYPE_NETWORK)
> return rt_socket_common_ioctl(sockctx, user_info, request, arg);
>
> + /* fast path for monitoring socket IOCTLs */
> + if ( _IOC_TYPE(request) == RTIOC_TYPE_NETWORK_MONITORING)
> + return rt_socket_monitoring_ioctl(sockctx, user_info, request, arg);
> +
Again, this is the WRONG place to dispatch, move to rt_socket_if_ioctl.
> switch (request) {
> case _RTIOC_BIND:
> return rt_packet_bind(sock, setaddr->addr, setaddr->addrlen);
> Index: stack/socket.c
> ===================================================================
> --- stack/socket.c (revision 1087)
> +++ stack/socket.c (working copy)
> @@ -229,7 +229,6 @@
> struct ifreq *ifr = arg;
> int ret = 0;
>
> -
> if (request == SIOCGIFCONF) {
> struct ifconf *ifc = arg;
> struct ifreq *cur_ifr = ifc->ifc_req;
> @@ -289,8 +288,30 @@
> return ret;
> }
>
> +/***
> + * rt_socket_monitoring_ioctl
> + */
> +int rt_socket_monitoring_ioctl(struct rtdm_dev_context *sockctx,
> + rtdm_user_info_t *user_info,
> + int request, void *arg)
> +{
> + struct rtnet_device *rtdev = NULL;
> + struct rtnet_device_monitoring* psDevMonit = arg;
> +
> + rtdev = rtdev_get_by_index(psDevMonit->ifindex);
> + if(rtdev == NULL)
> + return -ENODEV;
> + if(rtdev->do_ioctl != NULL)
> + return rtdev->do_ioctl( rtdev, request, arg);
> + else
> + {
> + rtdev_dereference(rtdev);
> + return -ENOSYS;
> + }
> +}
>
> EXPORT_SYMBOL(rt_socket_init);
> EXPORT_SYMBOL(rt_socket_cleanup);
> EXPORT_SYMBOL(rt_socket_common_ioctl);
> EXPORT_SYMBOL(rt_socket_if_ioctl);
> +EXPORT_SYMBOL(rt_socket_monitoring_ioctl);
> Index: drivers/rt_8139too.c
> ===================================================================
> --- drivers/rt_8139too.c (revision 1087)
> +++ drivers/rt_8139too.c (working copy)
> @@ -525,6 +525,7 @@
> static int rtl8139_interrupt (rtdm_irq_t *irq_handle);
> static int rtl8139_start_xmit (struct rtskb *skb, struct rtnet_device
> *rtdev);
>
> +static int rtl8139_ioctl(struct rtnet_device *rtdev, unsigned int request,
> void * cmd);
>
> static void rtl8139_init_ring (struct rtnet_device *rtdev);
> static void rtl8139_set_rx_mode (struct rtnet_device *rtdev);
> @@ -834,6 +835,7 @@
> rtdev->stop = rtl8139_close;
> rtdev->hard_header = &rt_eth_header;
> rtdev->hard_start_xmit = rtl8139_start_xmit;
> + rtdev->do_ioctl = rtl8139_ioctl;
>
> /*rtdev->set_multicast_list = rtl8139_set_rx_mode; */
> rtdev->features |= NETIF_F_SG|NETIF_F_HW_CSUM;
> @@ -1341,6 +1343,32 @@
> return 0;
> }
>
> +static int rtl8139_ioctl(struct rtnet_device *rtdev, unsigned int request,
> void * cmd)
> +{
> + struct rtl8139_private *tp = rtdev->priv;
> + void *ioaddr = tp->mmio_addr;
> + int nReturn = 0;
> + struct rtnet_device_monitoring* psDeviceMonit = cmd;
> + switch( request )
> + {
> + case RTNET_RTIOC_MONITORING_LINK_BEAT :
> + {
> + if(RTL_R16 (CSCR) & CSCR_LinkOKBit)
> + psDeviceMonit->link_beat = 1;
> + else
> + psDeviceMonit->link_beat = 0;
> + break;
> + }
> + default :
> + {
> + rtdm_printk("rtl8139_ioctl: IOCTL not implemented.\n");
Please remove this after completing the debug phase.
> + nReturn = -ENOIOCTLCMD;
Not good. This is an internal error code of the kernel we are about to
pass to user-space now. EOPNOTSUPP is commonly used in this context.
> + break;
> + }
> + }
> + rtdev_dereference(rtdev);
> + return nReturn;
> +}
>
> static void rtl8139_tx_interrupt (struct rtnet_device *rtdev,
> struct rtl8139_private *tp,
> @@ -1661,7 +1689,7 @@
> an first get an additional status bit from CSCR. */
> if (status & RxUnderrun)
> link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
> -
> +
Noise++ :)
> /* The chip takes special action when we clear RxAckBits,
> * so we clear them later in rtl8139_rx_interrupt
> */
And /please/ adopt the coding style you find in RTnet for you patches.
Jan
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ RTnet-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/rtnet-developers

