qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v3 1/4] rocker: Add support for phys name


From: sfeldma
Subject: [Qemu-devel] [PATCH v3 1/4] rocker: Add support for phys name
Date: Fri, 29 May 2015 07:01:46 -0700

From: David Ahern <address@hidden>

v2:

Review comment from Stefan Hajnoczi:

 - use private ROCKER_IFNAMSIZ = 16 to avoid breaking Windows build
   as Windows does not include <net/if.h>

v1:

Add ROCKER_TLV_CMD_PORT_SETTINGS_PHYS_NAME to port settings. This attribute
exports the port name to the guest OS allowing it to name interfaces with
sensible defaults.

Mostly done by Scott for phys_id support; adapted to phys_name by David.

Signed-off-by: Scott Feldman <address@hidden>
Signed-off-by: David Ahern <address@hidden>
---
 docs/specs/rocker.txt     |    1 +
 hw/net/rocker/rocker.c    |   23 ++++++++++++++++++++++-
 hw/net/rocker/rocker_fp.c |    7 ++++++-
 hw/net/rocker/rocker_fp.h |    1 +
 hw/net/rocker/rocker_hw.h |    1 +
 5 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/docs/specs/rocker.txt b/docs/specs/rocker.txt
index 1e7e1e1..0af5c61 100644
--- a/docs/specs/rocker.txt
+++ b/docs/specs/rocker.txt
@@ -420,6 +420,7 @@ Other properties for front-panel ports are available via 
DMA CMD descriptors:
                LEARNING        1       MAC address learning on port
                                                1 = enabled
                                                0 = disabled
+               PHYS_NAME       <var>   Physical port name (string)
 
        Set PORT_SETTINGS descriptor:
 
diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
index 55b6c46..e74c027 100644
--- a/hw/net/rocker/rocker.c
+++ b/hw/net/rocker/rocker.c
@@ -238,6 +238,7 @@ static int cmd_get_port_settings(Rocker *r,
     uint8_t duplex;
     uint8_t autoneg;
     uint8_t learning;
+    char *phys_name;
     MACAddr macaddr;
     enum rocker_world_type mode;
     size_t tlv_size;
@@ -265,6 +266,7 @@ static int cmd_get_port_settings(Rocker *r,
     fp_port_get_macaddr(fp_port, &macaddr);
     mode = world_type(fp_port_get_world(fp_port));
     learning = fp_port_get_learning(fp_port);
+    phys_name = fp_port_get_name(fp_port);
 
     tlv_size = rocker_tlv_total_size(0) +                 /* nest */
                rocker_tlv_total_size(sizeof(uint32_t)) +  /*   pport */
@@ -273,7 +275,8 @@ static int cmd_get_port_settings(Rocker *r,
                rocker_tlv_total_size(sizeof(uint8_t)) +   /*   autoneg */
                rocker_tlv_total_size(sizeof(macaddr.a)) + /*   macaddr */
                rocker_tlv_total_size(sizeof(uint8_t)) +   /*   mode */
-               rocker_tlv_total_size(sizeof(uint8_t));    /*   learning */
+               rocker_tlv_total_size(sizeof(uint8_t)) +   /*   learning */
+               rocker_tlv_total_size(strlen(phys_name));
 
     if (tlv_size > desc_buf_size(info)) {
         return -ROCKER_EMSGSIZE;
@@ -290,6 +293,8 @@ static int cmd_get_port_settings(Rocker *r,
     rocker_tlv_put_u8(buf, &pos, ROCKER_TLV_CMD_PORT_SETTINGS_MODE, mode);
     rocker_tlv_put_u8(buf, &pos, ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING,
                       learning);
+    rocker_tlv_put(buf, &pos, ROCKER_TLV_CMD_PORT_SETTINGS_PHYS_NAME,
+                   strlen(phys_name), phys_name);
     rocker_tlv_nest_end(buf, &pos, nest);
 
     return desc_set_buf(info, tlv_size);
@@ -1277,6 +1282,22 @@ static int pci_rocker_init(PCIDevice *dev)
         goto err_duplicate;
     }
 
+    /* Rocker name is passed in port name requests to OS with the intention
+     * that the name is used in interface names. Limit the length of the
+     * rocker name to avoid naming problems in the OS. Also, adding the
+     * port number as p# and unganged breakout b#, where # is at most 2
+     * digits, so leave room for it too (-1 for string terminator, -3 for
+     * p# and -3 for b#)
+     */
+#define ROCKER_IFNAMSIZ 16
+#define MAX_ROCKER_NAME_LEN  (ROCKER_IFNAMSIZ - 1 - 3 - 3)
+    if (strlen(r->name) > MAX_ROCKER_NAME_LEN) {
+        fprintf(stderr,
+                "rocker: name too long; please shorten to at most %d chars\n",
+                MAX_ROCKER_NAME_LEN);
+        return -EINVAL;
+    }
+
     if (memcmp(&r->fp_start_macaddr, &zero, sizeof(zero)) == 0) {
         memcpy(&r->fp_start_macaddr, &dflt, sizeof(dflt));
         r->fp_start_macaddr.a[4] += (sw_index++);
diff --git a/hw/net/rocker/rocker_fp.c b/hw/net/rocker/rocker_fp.c
index 2f1e3b3..393e9e7 100644
--- a/hw/net/rocker/rocker_fp.c
+++ b/hw/net/rocker/rocker_fp.c
@@ -41,6 +41,11 @@ struct fp_port {
     NICConf conf;
 };
 
+char *fp_port_get_name(FpPort *port)
+{
+    return port->name;
+}
+
 bool fp_port_get_link_up(FpPort *port)
 {
     return !qemu_get_queue(port->nic)->link_down;
@@ -201,7 +206,7 @@ FpPort *fp_port_alloc(Rocker *r, char *sw_name,
 
     /* front-panel switch port names are 1-based */
 
-    port->name = g_strdup_printf("%s.%d", sw_name, port->pport);
+    port->name = g_strdup_printf("%sp%d", sw_name, port->pport);
 
     memcpy(port->conf.macaddr.a, start_mac, sizeof(port->conf.macaddr.a));
     port->conf.macaddr.a[5] += index;
diff --git a/hw/net/rocker/rocker_fp.h b/hw/net/rocker/rocker_fp.h
index a5f28f1..92a6861 100644
--- a/hw/net/rocker/rocker_fp.h
+++ b/hw/net/rocker/rocker_fp.h
@@ -26,6 +26,7 @@ typedef struct fp_port FpPort;
 
 int fp_port_eg(FpPort *port, const struct iovec *iov, int iovcnt);
 
+char *fp_port_get_name(FpPort *port);
 bool fp_port_get_link_up(FpPort *port);
 void fp_port_get_macaddr(FpPort *port, MACAddr *macaddr);
 void fp_port_set_macaddr(FpPort *port, MACAddr *macaddr);
diff --git a/hw/net/rocker/rocker_hw.h b/hw/net/rocker/rocker_hw.h
index c9c85a7..fe639ba 100644
--- a/hw/net/rocker/rocker_hw.h
+++ b/hw/net/rocker/rocker_hw.h
@@ -179,6 +179,7 @@ enum {
     ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR,       /* binary */
     ROCKER_TLV_CMD_PORT_SETTINGS_MODE,          /* u8 */
     ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING,      /* u8 */
+    ROCKER_TLV_CMD_PORT_SETTINGS_PHYS_NAME,     /* binary */
 
     __ROCKER_TLV_CMD_PORT_SETTINGS_MAX,
     ROCKER_TLV_CMD_PORT_SETTINGS_MAX = __ROCKER_TLV_CMD_PORT_SETTINGS_MAX - 1,
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]