On Tue, Nov 11, 2014 at 12:14 PM, Maxim Uvarov <[email protected]>
wrote:

> Implement pktio mtu functions:
> odp_pktio_mtu() to get mtu value;
> odp_pktio_set_mtu() to set mtu value.
>
> Signed-off-by: Maxim Uvarov <[email protected]>
>
    Reviewed-by: Bill Fischofer <[email protected]>

> ---
>  platform/linux-generic/include/api/odp_packet_io.h | 20 +++++++++
>  .../linux-generic/include/odp_packet_io_internal.h |  4 ++
>  platform/linux-generic/odp_packet_io.c             | 50
> ++++++++++++++++++++++
>  3 files changed, 74 insertions(+)
>
> diff --git a/platform/linux-generic/include/api/odp_packet_io.h
> b/platform/linux-generic/include/api/odp_packet_io.h
> index 360636d..b784705 100644
> --- a/platform/linux-generic/include/api/odp_packet_io.h
> +++ b/platform/linux-generic/include/api/odp_packet_io.h
> @@ -135,6 +135,26 @@ void odp_pktio_set_input(odp_packet_t pkt,
> odp_pktio_t id);
>   */
>  odp_pktio_t odp_pktio_get_input(odp_packet_t pkt);
>
> +/*
> + * Configure the MTU for a packet IO interface.
> + *
> + * @param[in] id   ODP packet IO handle.
> + * @param[in] mtu  The MTU to be applied.
> + *
> + * @return 0 on success, -1 on error.
> + */
> +int odp_pktio_set_mtu(odp_pktio_t id, unsigned int mtu);
> +
> +/*
> + * Get the currently configured MTU of a packet IO interface.
> + *
> + * @param[in]      id   ODP packet IO handle.
> + * @param[out] mtu  Pointer to location in which to store the MTU value.
> + *
> + * @return 0 on success, -1 on error.
> + */
> +int odp_pktio_mtu(odp_pktio_t id, unsigned int *mtu);
> +
>  /**
>   * @}
>   */
> diff --git a/platform/linux-generic/include/odp_packet_io_internal.h
> b/platform/linux-generic/include/odp_packet_io_internal.h
> index 23633ed..ff73970 100644
> --- a/platform/linux-generic/include/odp_packet_io_internal.h
> +++ b/platform/linux-generic/include/odp_packet_io_internal.h
> @@ -21,6 +21,8 @@ extern "C" {
>  #include <odp_spinlock.h>
>  #include <odp_packet_socket.h>
>
> +#include <linux/if.h>
> +
>  /**
>   * Packet IO types
>   */
> @@ -38,6 +40,8 @@ struct pktio_entry {
>         odp_pktio_type_t type;          /**< pktio type */
>         pkt_sock_t pkt_sock;            /**< using socket API for IO */
>         pkt_sock_mmap_t pkt_sock_mmap;  /**< using socket mmap API for IO
> */
> +       char name[IFNAMSIZ];            /**< name of pktio provided to
> +                                               pktio_open() */
>  };
>
>  typedef union {
> diff --git a/platform/linux-generic/odp_packet_io.c
> b/platform/linux-generic/odp_packet_io.c
> index f35193f..20fe10a 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -20,6 +20,7 @@
>  #include <odp_debug.h>
>
>  #include <string.h>
> +#include <sys/ioctl.h>
>
>  typedef struct {
>         pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES];
> @@ -203,6 +204,7 @@ odp_pktio_t odp_pktio_open(const char *dev,
> odp_buffer_pool_t pool)
>         return ODP_PKTIO_INVALID;
>
>  done:
> +       strncpy(pktio_entry->s.name, dev, IFNAMSIZ);
>         unlock_entry(pktio_entry);
>         return id;
>  }
> @@ -476,3 +478,51 @@ int pktin_deq_multi(queue_entry_t *qentry,
> odp_buffer_hdr_t *buf_hdr[], int num)
>
>         return nbr;
>  }
> +
> +int odp_pktio_set_mtu(odp_pktio_t id, unsigned int mtu)
> +{
> +       pktio_entry_t *pktio_entry = get_entry(id);
> +       int sockfd;
> +       struct ifreq ifr;
> +       int ret;
> +
> +       if (pktio_entry->s.pkt_sock_mmap.sockfd)
> +               sockfd = pktio_entry->s.pkt_sock_mmap.sockfd;
> +       else
> +               sockfd = pktio_entry->s.pkt_sock.sockfd;
> +
> +       strncpy(ifr.ifr_name, pktio_entry->s.name, IFNAMSIZ);
> +       ifr.ifr_mtu = mtu;
> +
> +       ret = ioctl(sockfd, SIOCSIFMTU, (caddr_t)&ifr);
> +       if (ret != 0) {
> +               ODP_ERR("ioctl SIOCSIFMTU error\n");
> +               return -1;
> +       }
> +
> +       return 0;
> +}
> +
> +int odp_pktio_mtu(odp_pktio_t id, unsigned int *mtu)
> +{
> +       pktio_entry_t *pktio_entry = get_entry(id);
> +       int sockfd;
> +       struct ifreq ifr;
> +       int ret;
> +
> +       if (pktio_entry->s.pkt_sock_mmap.sockfd)
> +               sockfd = pktio_entry->s.pkt_sock_mmap.sockfd;
> +       else
> +               sockfd = pktio_entry->s.pkt_sock.sockfd;
> +
> +       strncpy(ifr.ifr_name, pktio_entry->s.name, IFNAMSIZ);
> +
> +       ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
> +       if (ret != 0) {
> +               ODP_ERR("ioctl SIOCGIFMTU error\n");
> +               return -1;
> +       }
> +
> +       *mtu = ifr.ifr_mtu;
> +       return 0;
> +}
> --
> 1.8.5.1.163.gd7aced9
>
>
> _______________________________________________
> lng-odp mailing list
> [email protected]
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to