Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0d163f4 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller
Browse files

nfp: add shared buffer configuration



Allow app FW to advertise its shared buffer pool information.
Use the per-PF mailbox to configure them from devlink.

Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0c693323
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ nfp-objs := \
	    nfp_net_sriov.o \
	    nfp_netvf_main.o \
	    nfp_port.o \
	    nfp_shared_buf.o \
	    nic/main.o

ifeq ($(CONFIG_NFP_APP_FLOWER),y)
+70 −0
Original line number Diff line number Diff line
@@ -51,9 +51,79 @@
 *
 * @NFP_MBOX_NO_CMD:	null command
 * Used to indicate previous command has finished.
 *
 * @NFP_MBOX_POOL_GET:	get shared buffer pool info/config
 * Input  - struct nfp_shared_buf_pool_id
 * Output - struct nfp_shared_buf_pool_info_get
 *
 * @NFP_MBOX_POOL_SET:	set shared buffer pool info/config
 * Input  - struct nfp_shared_buf_pool_info_set
 * Output - None
 */
enum nfp_mbox_cmd {
	NFP_MBOX_NO_CMD			= 0x00,

	NFP_MBOX_POOL_GET		= 0x01,
	NFP_MBOX_POOL_SET		= 0x02,
};

#define NFP_SHARED_BUF_COUNT_SYM_NAME	"_abi_nfd_pf%u_sb_cnt"
#define NFP_SHARED_BUF_TABLE_SYM_NAME	"_abi_nfd_pf%u_sb_tbl"

/**
 * struct nfp_shared_buf - NFP shared buffer description
 * @id:				numerical user-visible id of the shared buffer
 * @size:			size in bytes of the buffer
 * @ingress_pools_count:	number of ingress pools
 * @egress_pools_count:		number of egress pools
 * @ingress_tc_count:		number of ingress trafic classes
 * @egress_tc_count:		number of egress trafic classes
 * @pool_size_unit:		pool size may be in credits, each credit is
 *				@pool_size_unit bytes
 */
struct nfp_shared_buf {
	__le32 id;
	__le32 size;
	__le16 ingress_pools_count;
	__le16 egress_pools_count;
	__le16 ingress_tc_count;
	__le16 egress_tc_count;

	__le32 pool_size_unit;
};

/**
 * struct nfp_shared_buf_pool_id - shared buffer pool identification
 * @shared_buf:		shared buffer id
 * @pool:		pool index
 */
struct nfp_shared_buf_pool_id {
	__le32 shared_buf;
	__le32 pool;
};

/**
 * struct nfp_shared_buf_pool_info_get - struct devlink_sb_pool_info mirror
 * @pool_type:		one of enum devlink_sb_pool_type
 * @size:		pool size in units of SB's @pool_size_unit
 * @threshold_type:	one of enum devlink_sb_threshold_type
 */
struct nfp_shared_buf_pool_info_get {
	__le32 pool_type;
	__le32 size;
	__le32 threshold_type;
};

/**
 * struct nfp_shared_buf_pool_info_set - packed args of sb_pool_set
 * @id:			pool identification info
 * @size:		pool size in units of SB's @pool_size_unit
 * @threshold_type:	one of enum devlink_sb_threshold_type
 */
struct nfp_shared_buf_pool_info_set {
	struct nfp_shared_buf_pool_id id;
	__le32 size;
	__le32 threshold_type;
};

#endif
+22 −0
Original line number Diff line number Diff line
@@ -149,6 +149,26 @@ nfp_devlink_port_unsplit(struct devlink *devlink, unsigned int port_index)
	return ret;
}

static int
nfp_devlink_sb_pool_get(struct devlink *devlink, unsigned int sb_index,
			u16 pool_index, struct devlink_sb_pool_info *pool_info)
{
	struct nfp_pf *pf = devlink_priv(devlink);

	return nfp_shared_buf_pool_get(pf, sb_index, pool_index, pool_info);
}

static int
nfp_devlink_sb_pool_set(struct devlink *devlink, unsigned int sb_index,
			u16 pool_index,
			u32 size, enum devlink_sb_threshold_type threshold_type)
{
	struct nfp_pf *pf = devlink_priv(devlink);

	return nfp_shared_buf_pool_set(pf, sb_index, pool_index,
				       size, threshold_type);
}

static int nfp_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode)
{
	struct nfp_pf *pf = devlink_priv(devlink);
@@ -159,6 +179,8 @@ static int nfp_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode)
const struct devlink_ops nfp_devlink_ops = {
	.port_split		= nfp_devlink_port_split,
	.port_unsplit		= nfp_devlink_port_unsplit,
	.sb_pool_get		= nfp_devlink_sb_pool_get,
	.sb_pool_set		= nfp_devlink_sb_pool_set,
	.eswitch_mode_get	= nfp_devlink_eswitch_mode_get,
};

+14 −1
Original line number Diff line number Diff line
@@ -46,10 +46,10 @@
#include <linux/mutex.h>
#include <linux/pci.h>
#include <linux/workqueue.h>
#include <net/devlink.h>

struct dentry;
struct device;
struct devlink_ops;
struct pci_dev;

struct nfp_cpp;
@@ -62,6 +62,7 @@ struct nfp_nsp_identify;
struct nfp_port;
struct nfp_rtsym;
struct nfp_rtsym_table;
struct nfp_shared_buf;

/**
 * struct nfp_dumpspec - NFP FW dump specification structure
@@ -110,6 +111,8 @@ struct nfp_dumpspec {
 * @ports:		Linked list of port structures (struct nfp_port)
 * @wq:			Workqueue for running works which need to grab @lock
 * @port_refresh_work:	Work entry for taking netdevs out
 * @shared_bufs:	Array of shared buffer structures if FW has any SBs
 * @num_shared_bufs:	Number of elements in @shared_bufs
 * @lock:		Protects all fields which may change after probe
 */
struct nfp_pf {
@@ -162,6 +165,9 @@ struct nfp_pf {
	struct workqueue_struct *wq;
	struct work_struct port_refresh_work;

	struct nfp_shared_buf *shared_bufs;
	unsigned int num_shared_bufs;

	struct mutex lock;
};

@@ -200,4 +206,11 @@ s64 nfp_net_dump_calculate_size(struct nfp_pf *pf, struct nfp_dumpspec *spec,
int nfp_net_dump_populate_buffer(struct nfp_pf *pf, struct nfp_dumpspec *spec,
				 struct ethtool_dump *dump_param, void *dest);

int nfp_shared_buf_register(struct nfp_pf *pf);
void nfp_shared_buf_unregister(struct nfp_pf *pf);
int nfp_shared_buf_pool_get(struct nfp_pf *pf, unsigned int sb, u16 pool_index,
			    struct devlink_sb_pool_info *pool_info);
int nfp_shared_buf_pool_set(struct nfp_pf *pf, unsigned int sb,
			    u16 pool_index, u32 size,
			    enum devlink_sb_threshold_type threshold_type);
#endif /* NFP_MAIN_H */
+7 −0
Original line number Diff line number Diff line
@@ -728,6 +728,10 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
	if (err)
		goto err_app_clean;

	err = nfp_shared_buf_register(pf);
	if (err)
		goto err_devlink_unreg;

	mutex_lock(&pf->lock);
	pf->ddir = nfp_net_debugfs_device_add(pf->pdev);

@@ -761,6 +765,8 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
err_clean_ddir:
	nfp_net_debugfs_dir_clean(&pf->ddir);
	mutex_unlock(&pf->lock);
	nfp_shared_buf_unregister(pf);
err_devlink_unreg:
	cancel_work_sync(&pf->port_refresh_work);
	devlink_unregister(devlink);
err_app_clean:
@@ -788,6 +794,7 @@ void nfp_net_pci_remove(struct nfp_pf *pf)

	mutex_unlock(&pf->lock);

	nfp_shared_buf_unregister(pf);
	devlink_unregister(priv_to_devlink(pf));

	nfp_net_pf_free_irqs(pf);
Loading