diff mbox

[PATCHv5,1/3] pktio: add MTU manipulation functions

Message ID 1416473054-10656-2-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit 553a993f5e323e89050b0f7b74009e9b4227157c
Headers show

Commit Message

Maxim Uvarov Nov. 20, 2014, 8:44 a.m. UTC
Implement pktio mtu functions:
odp_pktio_mtu() to get mtu value;
odp_pktio_set_mtu() to set mtu value.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Reviewed-by Mike Holmes <mike.holmes@linaro.org>
---
 platform/linux-generic/include/api/odp_packet_io.h | 23 ++++++++
 .../linux-generic/include/odp_packet_io_internal.h |  4 ++
 platform/linux-generic/odp_packet_io.c             | 66 ++++++++++++++++++++++
 3 files changed, 93 insertions(+)

Comments

Anders Roxell Nov. 21, 2014, 10:29 a.m. UTC | #1
On 2014-11-20 11:44, Maxim Uvarov 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 <maxim.uvarov@linaro.org>
> Reviewed-by Mike Holmes <mike.holmes@linaro.org>

Fix Mikes Reviewed-by and I'm fine with this patch.

Should be "Reviewed-by: Mike..."

Reviewed-by: Anders Roxell <anders.roxell@linaro.org>

> ---
>  platform/linux-generic/include/api/odp_packet_io.h | 23 ++++++++
>  .../linux-generic/include/odp_packet_io_internal.h |  4 ++
>  platform/linux-generic/odp_packet_io.c             | 66 ++++++++++++++++++++++
>  3 files changed, 93 insertions(+)
> 
> diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h
> index 47daeda..667395c 100644
> --- a/platform/linux-generic/include/api/odp_packet_io.h
> +++ b/platform/linux-generic/include/api/odp_packet_io.h
> @@ -126,6 +126,29 @@ 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 value of MTU that the interface will be configured to
> + *		   use.
> + *
> + * @retval  0 on success.
> + * @retval -1 if specified mtu can not be handled.
> + * @retval -1 on any other error or illegal input parameters.
> + */
> +int odp_pktio_set_mtu(odp_pktio_t id, int mtu);
> +
> +/**
> + * Return the currently configured MTU value of a packet IO interface.
> + *
> + * @param[in] id  ODP packet IO handle.
> + *
> + * @retval MTU value >0 on success.
> + * @retval -1 on any error or not existance pktio id.
> + */
> +int odp_pktio_mtu(odp_pktio_t id);
> +
> +/**
>   * @}
>   */
>  
> diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
> index 23633ed..0bc1e21 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 f78b7fd..c523350 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,67 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num)
>  	queue_enq_multi(qentry, tmp_hdr_tbl, pkts);
>  	return nbr;
>  }
> +
> +int odp_pktio_set_mtu(odp_pktio_t id, int mtu)
> +{
> +	pktio_entry_t *entry;
> +	int sockfd;
> +	struct ifreq ifr;
> +	int ret;
> +
> +	if (mtu <= 0) {
> +		ODP_DBG("illegal MTU value %d\n", mtu);
> +		return -1;
> +	}
> +
> +	entry = get_entry(id);
> +	if (entry == NULL) {
> +		ODP_DBG("pktio entry %d does not exist\n", id);
> +		return -1;
> +	}
> +
> +	if (entry->s.pkt_sock_mmap.sockfd)
> +		sockfd = entry->s.pkt_sock_mmap.sockfd;
> +	else
> +		sockfd = entry->s.pkt_sock.sockfd;
> +
> +	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
> +	ifr.ifr_mtu = mtu;
> +
> +	ret = ioctl(sockfd, SIOCSIFMTU, (caddr_t)&ifr);
> +	if (ret < 0) {
> +		ODP_DBG("ioctl SIOCSIFMTU error\n");
> +		return -1;
> +	}
> +
> +	return 0;
> +}
> +
> +int odp_pktio_mtu(odp_pktio_t id)
> +{
> +	pktio_entry_t *entry;
> +	int sockfd;
> +	struct ifreq ifr;
> +	int ret;
> +
> +	entry = get_entry(id);
> +	if (entry == NULL) {
> +		ODP_DBG("pktio entry %d does not exist\n", id);
> +		return -1;
> +	}
> +
> +	if (entry->s.pkt_sock_mmap.sockfd)
> +		sockfd = entry->s.pkt_sock_mmap.sockfd;
> +	else
> +		sockfd = entry->s.pkt_sock.sockfd;
> +
> +	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
> +
> +	ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
> +	if (ret < 0) {
> +		ODP_DBG("ioctl SIOCGIFMTU error\n");
> +		return -1;
> +	}
> +
> +	return ifr.ifr_mtu;
> +}
> -- 
> 1.8.5.1.163.gd7aced9
> 
> 
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h
index 47daeda..667395c 100644
--- a/platform/linux-generic/include/api/odp_packet_io.h
+++ b/platform/linux-generic/include/api/odp_packet_io.h
@@ -126,6 +126,29 @@  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 value of MTU that the interface will be configured to
+ *		   use.
+ *
+ * @retval  0 on success.
+ * @retval -1 if specified mtu can not be handled.
+ * @retval -1 on any other error or illegal input parameters.
+ */
+int odp_pktio_set_mtu(odp_pktio_t id, int mtu);
+
+/**
+ * Return the currently configured MTU value of a packet IO interface.
+ *
+ * @param[in] id  ODP packet IO handle.
+ *
+ * @retval MTU value >0 on success.
+ * @retval -1 on any error or not existance pktio id.
+ */
+int odp_pktio_mtu(odp_pktio_t id);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index 23633ed..0bc1e21 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 f78b7fd..c523350 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,67 @@  int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num)
 	queue_enq_multi(qentry, tmp_hdr_tbl, pkts);
 	return nbr;
 }
+
+int odp_pktio_set_mtu(odp_pktio_t id, int mtu)
+{
+	pktio_entry_t *entry;
+	int sockfd;
+	struct ifreq ifr;
+	int ret;
+
+	if (mtu <= 0) {
+		ODP_DBG("illegal MTU value %d\n", mtu);
+		return -1;
+	}
+
+	entry = get_entry(id);
+	if (entry == NULL) {
+		ODP_DBG("pktio entry %d does not exist\n", id);
+		return -1;
+	}
+
+	if (entry->s.pkt_sock_mmap.sockfd)
+		sockfd = entry->s.pkt_sock_mmap.sockfd;
+	else
+		sockfd = entry->s.pkt_sock.sockfd;
+
+	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
+	ifr.ifr_mtu = mtu;
+
+	ret = ioctl(sockfd, SIOCSIFMTU, (caddr_t)&ifr);
+	if (ret < 0) {
+		ODP_DBG("ioctl SIOCSIFMTU error\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+int odp_pktio_mtu(odp_pktio_t id)
+{
+	pktio_entry_t *entry;
+	int sockfd;
+	struct ifreq ifr;
+	int ret;
+
+	entry = get_entry(id);
+	if (entry == NULL) {
+		ODP_DBG("pktio entry %d does not exist\n", id);
+		return -1;
+	}
+
+	if (entry->s.pkt_sock_mmap.sockfd)
+		sockfd = entry->s.pkt_sock_mmap.sockfd;
+	else
+		sockfd = entry->s.pkt_sock.sockfd;
+
+	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
+
+	ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
+	if (ret < 0) {
+		ODP_DBG("ioctl SIOCGIFMTU error\n");
+		return -1;
+	}
+
+	return ifr.ifr_mtu;
+}