Commit 3179698d authored by David S. Miller's avatar David S. Miller

Merge branch 'liquidio-switchdev-support'

Vijaya Mohan Guvva says:

====================
liquidio: switchdev support for LiquidIO NIC

patch1 of this patch set adds switchdev support for SRIOV capable
LiquidIO NIC, so that for every SRIOV VF on LiquidIO, a representor
netdev is created on hypervisor. It also has changes to send representor
interface configurations like admin state and MTU to LiquidIO firmware and
to retrieve HW counted VF stats for VF representor.

patch2 adds support for switchdev enable/disable from devlink

Patchset Change Log:
  V2 -> V3:
    * Use mac address as the physical switchID.
    * Check for eswitch_mode before returning switchID

  V1 -> V2:
    * Name the representors "pfXvfY".
    * Drop patch3 (ethtool support for switchdev ports) that was in V1
      because it's not necessary.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 2278f514 d4be8ebe
......@@ -53,6 +53,7 @@ config THUNDER_NIC_RGX
config LIQUIDIO
tristate "Cavium LiquidIO support"
depends on 64BIT
depends on MAY_USE_DEVLINK
imply PTP_1588_CLOCK
select FW_LOADER
select LIBCRC32C
......
......@@ -17,7 +17,7 @@ liquidio-$(CONFIG_LIQUIDIO) += lio_ethtool.o \
octeon_droq.o \
octeon_nic.o
liquidio-objs := lio_main.o octeon_console.o $(liquidio-y)
liquidio-objs := lio_main.o octeon_console.o lio_vf_rep.o $(liquidio-y)
obj-$(CONFIG_LIQUIDIO_VF) += liquidio_vf.o
......
......@@ -21,6 +21,7 @@
#include <linux/firmware.h>
#include <net/vxlan.h>
#include <linux/kthread.h>
#include <net/switchdev.h>
#include "liquidio_common.h"
#include "octeon_droq.h"
#include "octeon_iq.h"
......@@ -34,6 +35,7 @@
#include "cn68xx_device.h"
#include "cn23xx_pf_device.h"
#include "liquidio_image.h"
#include "lio_vf_rep.h"
MODULE_AUTHOR("Cavium Networks, <support@cavium.com>");
MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Driver");
......@@ -1602,6 +1604,8 @@ static int liquidio_stop_nic_module(struct octeon_device *oct)
oct->cmd_resp_state = OCT_DRV_OFFLINE;
spin_unlock_bh(&oct->cmd_resp_wqlock);
lio_vf_rep_destroy(oct);
for (i = 0; i < oct->ifcount; i++) {
lio = GET_LIO(oct->props[i].netdev);
for (j = 0; j < oct->num_oqs; j++)
......@@ -1612,6 +1616,12 @@ static int liquidio_stop_nic_module(struct octeon_device *oct)
for (i = 0; i < oct->ifcount; i++)
liquidio_destroy_nic_device(oct, i);
if (oct->devlink) {
devlink_unregister(oct->devlink);
devlink_free(oct->devlink);
oct->devlink = NULL;
}
dev_dbg(&oct->pci_dev->dev, "Network interfaces stopped\n");
return 0;
}
......@@ -3309,6 +3319,86 @@ static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx,
return 0;
}
static int
liquidio_eswitch_mode_get(struct devlink *devlink, u16 *mode)
{
struct lio_devlink_priv *priv;
struct octeon_device *oct;
priv = devlink_priv(devlink);
oct = priv->oct;
*mode = oct->eswitch_mode;
return 0;
}
static int
liquidio_eswitch_mode_set(struct devlink *devlink, u16 mode)
{
struct lio_devlink_priv *priv;
struct octeon_device *oct;
int ret = 0;
priv = devlink_priv(devlink);
oct = priv->oct;
if (!(oct->fw_info.app_cap_flags & LIQUIDIO_SWITCHDEV_CAP))
return -EINVAL;
if (oct->eswitch_mode == mode)
return 0;
switch (mode) {
case DEVLINK_ESWITCH_MODE_SWITCHDEV:
oct->eswitch_mode = mode;
ret = lio_vf_rep_create(oct);
break;
case DEVLINK_ESWITCH_MODE_LEGACY:
lio_vf_rep_destroy(oct);
oct->eswitch_mode = mode;
break;
default:
ret = -EINVAL;
}
return ret;
}
static const struct devlink_ops liquidio_devlink_ops = {
.eswitch_mode_get = liquidio_eswitch_mode_get,
.eswitch_mode_set = liquidio_eswitch_mode_set,
};
static int
lio_pf_switchdev_attr_get(struct net_device *dev, struct switchdev_attr *attr)
{
struct lio *lio = GET_LIO(dev);
struct octeon_device *oct = lio->oct_dev;
if (oct->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
return -EOPNOTSUPP;
switch (attr->id) {
case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
attr->u.ppid.id_len = ETH_ALEN;
ether_addr_copy(attr->u.ppid.id,
(void *)&lio->linfo.hw_addr + 2);
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
static const struct switchdev_ops lio_pf_switchdev_ops = {
.switchdev_port_attr_get = lio_pf_switchdev_attr_get,
};
static const struct net_device_ops lionetdevops = {
.ndo_open = liquidio_open,
.ndo_stop = liquidio_stop,
......@@ -3438,6 +3528,8 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
u32 resp_size, ctx_size, data_size;
u32 ifidx_or_pfnum;
struct lio_version *vdata;
struct devlink *devlink;
struct lio_devlink_priv *lio_devlink;
/* This is to handle link status changes */
octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
......@@ -3583,6 +3675,7 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
* netdev tasks.
*/
netdev->netdev_ops = &lionetdevops;
SWITCHDEV_SET_OPS(netdev, &lio_pf_switchdev_ops);
lio = GET_LIO(netdev);
......@@ -3769,6 +3862,26 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
octeon_free_soft_command(octeon_dev, sc);
}
devlink = devlink_alloc(&liquidio_devlink_ops,
sizeof(struct lio_devlink_priv));
if (!devlink) {
dev_err(&octeon_dev->pci_dev->dev, "devlink alloc failed\n");
goto setup_nic_wait_intr;
}
lio_devlink = devlink_priv(devlink);
lio_devlink->oct = octeon_dev;
if (devlink_register(devlink, &octeon_dev->pci_dev->dev)) {
devlink_free(devlink);
dev_err(&octeon_dev->pci_dev->dev,
"devlink registration failed\n");
goto setup_nic_wait_intr;
}
octeon_dev->devlink = devlink;
octeon_dev->eswitch_mode = DEVLINK_ESWITCH_MODE_LEGACY;
return 0;
setup_nic_dev_fail:
......@@ -3863,6 +3976,7 @@ static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs)
}
if (!num_vfs) {
lio_vf_rep_destroy(oct);
ret = lio_pci_sriov_disable(oct);
} else if (num_vfs > oct->sriov_info.max_vfs) {
dev_err(&oct->pci_dev->dev,
......@@ -3874,6 +3988,10 @@ static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs)
ret = octeon_enable_sriov(oct);
dev_info(&oct->pci_dev->dev, "oct->pf_num:%d num_vfs:%d\n",
oct->pf_num, num_vfs);
ret = lio_vf_rep_create(oct);
if (ret)
dev_info(&oct->pci_dev->dev,
"vf representor create failed");
}
return ret;
......
This diff is collapsed.
/**********************************************************************
* Author: Cavium, Inc.
*
* Contact: support@cavium.com
* Please include "LiquidIO" in the subject.
*
* Copyright (c) 2003-2017 Cavium, Inc.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, Version 2, as
* published by the Free Software Foundation.
*
* This file is distributed in the hope that it will be useful, but
* AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
* NONINFRINGEMENT. See the GNU General Public License for more
* details.
*
* This file may also be available under a different license from Cavium.
* Contact Cavium, Inc. for more information
**********************************************************************/
/*! \file octeon_vf_main.h
* \brief Host Driver: This file defines vf_rep related macros and structures
*/
#ifndef __LIO_VF_REP_H__
#define __LIO_VF_REP_H__
#define LIO_VF_REP_REQ_TMO_MS 5000
#define LIO_VF_REP_STATS_POLL_TIME_MS 200
struct lio_vf_rep_desc {
struct net_device *parent_ndev;
struct net_device *ndev;
struct octeon_device *oct;
struct lio_vf_rep_stats stats;
struct cavium_wk stats_wk;
atomic_t ifstate;
int ifidx;
};
struct lio_vf_rep_sc_ctx {
struct completion complete;
};
int lio_vf_rep_create(struct octeon_device *oct);
void lio_vf_rep_destroy(struct octeon_device *oct);
#endif
......@@ -89,6 +89,9 @@ enum octeon_tag_type {
#define VF_DRV_REMOVED -1
#define VF_DRV_MACADDR_CHANGED 2
#define OPCODE_NIC_VF_REP_PKT 0x15
#define OPCODE_NIC_VF_REP_CMD 0x16
#define CORE_DRV_TEST_SCATTER_OP 0xFFF5
/* Application codes advertised by the core driver initialization packet. */
......@@ -111,6 +114,7 @@ enum octeon_tag_type {
/* App specific capabilities from firmware to pf driver */
#define LIQUIDIO_TIME_SYNC_CAP 0x1
#define LIQUIDIO_SWITCHDEV_CAP 0x2
static inline u32 incr_index(u32 index, u32 count, u32 max)
{
......@@ -909,4 +913,50 @@ struct lio_time {
s64 sec; /* seconds */
s64 nsec; /* nanoseconds */
};
struct lio_vf_rep_stats {
u64 tx_packets;
u64 tx_bytes;
u64 tx_dropped;
u64 rx_packets;
u64 rx_bytes;
u64 rx_dropped;
};
enum lio_vf_rep_req_type {
LIO_VF_REP_REQ_NONE,
LIO_VF_REP_REQ_STATE,
LIO_VF_REP_REQ_MTU,
LIO_VF_REP_REQ_STATS
};
enum {
LIO_VF_REP_STATE_DOWN,
LIO_VF_REP_STATE_UP
};
struct lio_vf_rep_req {
u8 req_type;
u8 ifidx;
u8 rsvd[6];
union {
struct lio_vf_rep_mtu {
u32 mtu;
u32 rsvd;
} rep_mtu;
struct lio_vf_rep_state {
u8 state;
u8 rsvd[7];
} rep_state;
};
};
struct lio_vf_rep_resp {
u64 rh;
u8 status;
u8 rsvd[7];
};
#endif
......@@ -23,6 +23,7 @@
#define _OCTEON_DEVICE_H_
#include <linux/interrupt.h>
#include <net/devlink.h>
/** PCI VendorId Device Id */
#define OCTEON_CN68XX_PCIID 0x91177d
......@@ -391,6 +392,15 @@ struct octeon_ioq_vector {
u32 ioq_num;
};
struct lio_vf_rep_list {
int num_vfs;
struct net_device *ndev[CN23XX_MAX_VFS_PER_PF];
};
struct lio_devlink_priv {
struct octeon_device *oct;
};
/** The Octeon device.
* Each Octeon device has this structure to represent all its
* components.
......@@ -568,6 +578,10 @@ struct octeon_device {
atomic_t *adapter_fw_state; /* per-adapter, lio_fw_state */
bool ptp_enable;
struct lio_vf_rep_list vf_rep_list;
struct devlink *devlink;
enum devlink_eswitch_mode eswitch_mode;
};
#define OCT_DRV_ONLINE 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment