net: add rte prefix to ether structures
[dpdk.git] / drivers / net / mlx5 / mlx5_nl.c
index 58bbfed..ce4c937 100644 (file)
 
 /* Add/remove MAC address through Netlink */
 struct mlx5_nl_mac_addr {
-       struct ether_addr (*mac)[];
+       struct rte_ether_addr (*mac)[];
        /**< MAC address handled by the device. */
        int mac_n; /**< Number of addresses in the array. */
 };
 
-/** Data structure used by mlx5_nl_ifindex_cb(). */
+/** Data structure used by mlx5_nl_cmdget_cb(). */
 struct mlx5_nl_ifindex_data {
        const char *name; /**< IB device name (in). */
        uint32_t ibindex; /**< IB device index (out). */
        uint32_t ifindex; /**< Network interface index (out). */
+       uint32_t portnum; /**< IB device max port number. */
 };
 
 /**
@@ -364,7 +365,7 @@ mlx5_nl_mac_addr_cb(struct nlmsghdr *nh, void *arg)
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 static int
-mlx5_nl_mac_addr_list(struct rte_eth_dev *dev, struct ether_addr (*mac)[],
+mlx5_nl_mac_addr_list(struct rte_eth_dev *dev, struct rte_ether_addr (*mac)[],
                      int *mac_n)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
@@ -423,7 +424,7 @@ error:
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 static int
-mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct ether_addr *mac,
+mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
                        int add)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
@@ -495,7 +496,7 @@ error:
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 int
-mlx5_nl_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
+mlx5_nl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
                     uint32_t index)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
@@ -523,7 +524,7 @@ mlx5_nl_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 int
-mlx5_nl_mac_addr_remove(struct rte_eth_dev *dev, struct ether_addr *mac,
+mlx5_nl_mac_addr_remove(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
                        uint32_t index)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
@@ -541,7 +542,7 @@ mlx5_nl_mac_addr_remove(struct rte_eth_dev *dev, struct ether_addr *mac,
 void
 mlx5_nl_mac_addr_sync(struct rte_eth_dev *dev)
 {
-       struct ether_addr macs[MLX5_MAX_MAC_ADDRESSES];
+       struct rte_ether_addr macs[MLX5_MAX_MAC_ADDRESSES];
        int macs_n = 0;
        int i;
        int ret;
@@ -582,7 +583,7 @@ mlx5_nl_mac_addr_flush(struct rte_eth_dev *dev)
        int i;
 
        for (i = MLX5_MAX_MAC_ADDRESSES - 1; i >= 0; --i) {
-               struct ether_addr *m = &dev->data->mac_addrs[i];
+               struct rte_ether_addr *m = &dev->data->mac_addrs[i];
 
                if (BITFIELD_ISSET(priv->mac_own, i))
                        mlx5_nl_mac_addr_remove(dev, m, i);
@@ -695,12 +696,13 @@ mlx5_nl_allmulti(struct rte_eth_dev *dev, int enable)
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 static int
-mlx5_nl_ifindex_cb(struct nlmsghdr *nh, void *arg)
+mlx5_nl_cmdget_cb(struct nlmsghdr *nh, void *arg)
 {
        struct mlx5_nl_ifindex_data *data = arg;
        size_t off = NLMSG_HDRLEN;
        uint32_t ibindex = 0;
        uint32_t ifindex = 0;
+       uint32_t portnum = 0;
        int found = 0;
 
        if (nh->nlmsg_type !=
@@ -725,6 +727,9 @@ mlx5_nl_ifindex_cb(struct nlmsghdr *nh, void *arg)
                case RDMA_NLDEV_ATTR_NDEV_INDEX:
                        ifindex = *(uint32_t *)payload;
                        break;
+               case RDMA_NLDEV_ATTR_PORT_INDEX:
+                       portnum = *(uint32_t *)payload;
+                       break;
                default:
                        break;
                }
@@ -733,6 +738,7 @@ mlx5_nl_ifindex_cb(struct nlmsghdr *nh, void *arg)
        if (found) {
                data->ibindex = ibindex;
                data->ifindex = ifindex;
+               data->portnum = portnum;
        }
        return 0;
 error:
@@ -751,15 +757,15 @@ error:
  *   Netlink socket of the RDMA kind (NETLINK_RDMA).
  * @param[in] name
  *   IB device name.
- *
+ * @param[in] pindex
+ *   IB device port index, starting from 1
  * @return
  *   A valid (nonzero) interface index on success, 0 otherwise and rte_errno
  *   is set.
  */
 unsigned int
-mlx5_nl_ifindex(int nl, const char *name)
+mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex)
 {
-       static const uint32_t pindex = 1;
        uint32_t seq = random();
        struct mlx5_nl_ifindex_data data = {
                .name = name,
@@ -785,7 +791,7 @@ mlx5_nl_ifindex(int nl, const char *name)
        ret = mlx5_nl_send(nl, &req.nh, seq);
        if (ret < 0)
                return 0;
-       ret = mlx5_nl_recv(nl, seq, mlx5_nl_ifindex_cb, &data);
+       ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
        if (ret < 0)
                return 0;
        if (!data.ibindex)
@@ -808,7 +814,7 @@ mlx5_nl_ifindex(int nl, const char *name)
        ret = mlx5_nl_send(nl, &req.nh, seq);
        if (ret < 0)
                return 0;
-       ret = mlx5_nl_recv(nl, seq, mlx5_nl_ifindex_cb, &data);
+       ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
        if (ret < 0)
                return 0;
        if (!data.ifindex)
@@ -819,6 +825,51 @@ error:
        return 0;
 }
 
+/**
+ * Get the number of physical ports of given IB device.
+ *
+ * @param nl
+ *   Netlink socket of the RDMA kind (NETLINK_RDMA).
+ * @param[in] name
+ *   IB device name.
+ *
+ * @return
+ *   A valid (nonzero) number of ports on success, 0 otherwise
+ *   and rte_errno is set.
+ */
+unsigned int
+mlx5_nl_portnum(int nl, const char *name)
+{
+       uint32_t seq = random();
+       struct mlx5_nl_ifindex_data data = {
+               .name = name,
+               .ibindex = 0,
+               .ifindex = 0,
+               .portnum = 0,
+       };
+       struct nlmsghdr req = {
+               .nlmsg_len = NLMSG_LENGTH(0),
+               .nlmsg_type = RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
+                                              RDMA_NLDEV_CMD_GET),
+               .nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP,
+       };
+       int ret;
+
+       ret = mlx5_nl_send(nl, &req, seq);
+       if (ret < 0)
+               return 0;
+       ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
+       if (ret < 0)
+               return 0;
+       if (!data.ibindex) {
+               rte_errno = ENODEV;
+               return 0;
+       }
+       if (!data.portnum)
+               rte_errno = EINVAL;
+       return data.portnum;
+}
+
 /**
  * Process switch information from Netlink message.
  *
@@ -836,12 +887,11 @@ mlx5_nl_switch_info_cb(struct nlmsghdr *nh, void *arg)
        struct mlx5_switch_info info = {
                .master = 0,
                .representor = 0,
-               .port_name_new = 0,
+               .name_type = MLX5_PHYS_PORT_NAME_TYPE_NOTSET,
                .port_name = 0,
                .switch_id = 0,
        };
        size_t off = NLMSG_LENGTH(sizeof(struct ifinfomsg));
-       bool port_name_set = false;
        bool switch_id_set = false;
        bool num_vf_set = false;
 
@@ -859,9 +909,7 @@ mlx5_nl_switch_info_cb(struct nlmsghdr *nh, void *arg)
                        num_vf_set = true;
                        break;
                case IFLA_PHYS_PORT_NAME:
-                       port_name_set =
-                               mlx5_translate_port_name((char *)payload,
-                                                        &info);
+                       mlx5_translate_port_name((char *)payload, &info);
                        break;
                case IFLA_PHYS_SWITCH_ID:
                        info.switch_id = 0;
@@ -875,17 +923,8 @@ mlx5_nl_switch_info_cb(struct nlmsghdr *nh, void *arg)
                off += RTA_ALIGN(ra->rta_len);
        }
        if (switch_id_set) {
-               if (info.port_name_new) {
-                       /* New representors naming schema. */
-                       if (port_name_set) {
-                               info.master = (info.port_name == -1);
-                               info.representor = (info.port_name != -1);
-                       }
-               } else {
-                       /* Legacy representors naming schema. */
-                       info.master = (!port_name_set || num_vf_set);
-                       info.representor = port_name_set && !num_vf_set;
-               }
+               /* We have some E-Switch configuration. */
+               mlx5_nl_check_switch_info(num_vf_set, &info);
        }
        assert(!(info.master && info.representor));
        memcpy(arg, &info, sizeof(info));