On 11/14/2014 06:45 AM, Mike Holmes wrote:
On 13 November 2014 07:18, Maxim Uvarov <[email protected]
<mailto:[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]
<mailto:[email protected]>>
---
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 360636d..90d525b 100644
--- a/platform/linux-generic/include/api/odp_packet_io.h
+++ b/platform/linux-generic/include/api/odp_packet_io.h
@@ -135,6 +135,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);
+/*
Sorry just caught this, it needs to be /** for doxygen to recognize it
Ok, I need to add this to validation script before applying else.
Maxim.
+ * 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);
+
+/*
Needs to be /** for doxygen to recognize it
+ * 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 f35193f..651815d 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 <http://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)
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 <http://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 <http://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
[email protected] <mailto:[email protected]>
http://lists.linaro.org/mailman/listinfo/lng-odp
--
*Mike Holmes*
Linaro Sr Technical Manager
LNG - ODP
_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp