Commit 955dc68c authored by Samuel Mendoza-Jonas's avatar Samuel Mendoza-Jonas Committed by David S. Miller

net/ncsi: Add generic netlink family

Add a generic netlink family for NCSI. This supports three commands;
NCSI_CMD_PKG_INFO which returns information on packages and their
associated channels, NCSI_CMD_SET_INTERFACE which allows a specific
package or package/channel combination to be set as the preferred
choice, and NCSI_CMD_CLEAR_INTERFACE which clears any preferred setting.
Signed-off-by: default avatarSamuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent be631892
/*
* Copyright Samuel Mendoza-Jonas, IBM Corporation 2018.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#ifndef __UAPI_NCSI_NETLINK_H__
#define __UAPI_NCSI_NETLINK_H__
/**
* enum ncsi_nl_commands - supported NCSI commands
*
* @NCSI_CMD_UNSPEC: unspecified command to catch errors
* @NCSI_CMD_PKG_INFO: list package and channel attributes. Requires
* NCSI_ATTR_IFINDEX. If NCSI_ATTR_PACKAGE_ID is specified returns the
* specific package and its channels - otherwise a dump request returns
* all packages and their associated channels.
* @NCSI_CMD_SET_INTERFACE: set preferred package and channel combination.
* Requires NCSI_ATTR_IFINDEX and the preferred NCSI_ATTR_PACKAGE_ID and
* optionally the preferred NCSI_ATTR_CHANNEL_ID.
* @NCSI_CMD_CLEAR_INTERFACE: clear any preferred package/channel combination.
* Requires NCSI_ATTR_IFINDEX.
* @NCSI_CMD_MAX: highest command number
*/
enum ncsi_nl_commands {
NCSI_CMD_UNSPEC,
NCSI_CMD_PKG_INFO,
NCSI_CMD_SET_INTERFACE,
NCSI_CMD_CLEAR_INTERFACE,
__NCSI_CMD_AFTER_LAST,
NCSI_CMD_MAX = __NCSI_CMD_AFTER_LAST - 1
};
/**
* enum ncsi_nl_attrs - General NCSI netlink attributes
*
* @NCSI_ATTR_UNSPEC: unspecified attributes to catch errors
* @NCSI_ATTR_IFINDEX: ifindex of network device using NCSI
* @NCSI_ATTR_PACKAGE_LIST: nested array of NCSI_PKG_ATTR attributes
* @NCSI_ATTR_PACKAGE_ID: package ID
* @NCSI_ATTR_CHANNEL_ID: channel ID
* @NCSI_ATTR_MAX: highest attribute number
*/
enum ncsi_nl_attrs {
NCSI_ATTR_UNSPEC,
NCSI_ATTR_IFINDEX,
NCSI_ATTR_PACKAGE_LIST,
NCSI_ATTR_PACKAGE_ID,
NCSI_ATTR_CHANNEL_ID,
__NCSI_ATTR_AFTER_LAST,
NCSI_ATTR_MAX = __NCSI_ATTR_AFTER_LAST - 1
};
/**
* enum ncsi_nl_pkg_attrs - NCSI netlink package-specific attributes
*
* @NCSI_PKG_ATTR_UNSPEC: unspecified attributes to catch errors
* @NCSI_PKG_ATTR: nested array of package attributes
* @NCSI_PKG_ATTR_ID: package ID
* @NCSI_PKG_ATTR_FORCED: flag signifying a package has been set as preferred
* @NCSI_PKG_ATTR_CHANNEL_LIST: nested array of NCSI_CHANNEL_ATTR attributes
* @NCSI_PKG_ATTR_MAX: highest attribute number
*/
enum ncsi_nl_pkg_attrs {
NCSI_PKG_ATTR_UNSPEC,
NCSI_PKG_ATTR,
NCSI_PKG_ATTR_ID,
NCSI_PKG_ATTR_FORCED,
NCSI_PKG_ATTR_CHANNEL_LIST,
__NCSI_PKG_ATTR_AFTER_LAST,
NCSI_PKG_ATTR_MAX = __NCSI_PKG_ATTR_AFTER_LAST - 1
};
/**
* enum ncsi_nl_channel_attrs - NCSI netlink channel-specific attributes
*
* @NCSI_CHANNEL_ATTR_UNSPEC: unspecified attributes to catch errors
* @NCSI_CHANNEL_ATTR: nested array of channel attributes
* @NCSI_CHANNEL_ATTR_ID: channel ID
* @NCSI_CHANNEL_ATTR_VERSION_MAJOR: channel major version number
* @NCSI_CHANNEL_ATTR_VERSION_MINOR: channel minor version number
* @NCSI_CHANNEL_ATTR_VERSION_STR: channel version string
* @NCSI_CHANNEL_ATTR_LINK_STATE: channel link state flags
* @NCSI_CHANNEL_ATTR_ACTIVE: channels with this flag are in
* NCSI_CHANNEL_ACTIVE state
* @NCSI_CHANNEL_ATTR_FORCED: flag signifying a channel has been set as
* preferred
* @NCSI_CHANNEL_ATTR_VLAN_LIST: nested array of NCSI_CHANNEL_ATTR_VLAN_IDs
* @NCSI_CHANNEL_ATTR_VLAN_ID: VLAN ID being filtered on this channel
* @NCSI_CHANNEL_ATTR_MAX: highest attribute number
*/
enum ncsi_nl_channel_attrs {
NCSI_CHANNEL_ATTR_UNSPEC,
NCSI_CHANNEL_ATTR,
NCSI_CHANNEL_ATTR_ID,
NCSI_CHANNEL_ATTR_VERSION_MAJOR,
NCSI_CHANNEL_ATTR_VERSION_MINOR,
NCSI_CHANNEL_ATTR_VERSION_STR,
NCSI_CHANNEL_ATTR_LINK_STATE,
NCSI_CHANNEL_ATTR_ACTIVE,
NCSI_CHANNEL_ATTR_FORCED,
NCSI_CHANNEL_ATTR_VLAN_LIST,
NCSI_CHANNEL_ATTR_VLAN_ID,
__NCSI_CHANNEL_ATTR_AFTER_LAST,
NCSI_CHANNEL_ATTR_MAX = __NCSI_CHANNEL_ATTR_AFTER_LAST - 1
};
#endif /* __UAPI_NCSI_NETLINK_H__ */
# #
# Makefile for NCSI API # Makefile for NCSI API
# #
obj-$(CONFIG_NET_NCSI) += ncsi-cmd.o ncsi-rsp.o ncsi-aen.o ncsi-manage.o obj-$(CONFIG_NET_NCSI) += ncsi-cmd.o ncsi-rsp.o ncsi-aen.o ncsi-manage.o ncsi-netlink.o
...@@ -276,6 +276,8 @@ struct ncsi_dev_priv { ...@@ -276,6 +276,8 @@ struct ncsi_dev_priv {
unsigned int package_num; /* Number of packages */ unsigned int package_num; /* Number of packages */
struct list_head packages; /* List of packages */ struct list_head packages; /* List of packages */
struct ncsi_channel *hot_channel; /* Channel was ever active */ struct ncsi_channel *hot_channel; /* Channel was ever active */
struct ncsi_package *force_package; /* Force a specific package */
struct ncsi_channel *force_channel; /* Force a specific channel */
struct ncsi_request requests[256]; /* Request table */ struct ncsi_request requests[256]; /* Request table */
unsigned int request_id; /* Last used request ID */ unsigned int request_id; /* Last used request ID */
#define NCSI_REQ_START_IDX 1 #define NCSI_REQ_START_IDX 1
...@@ -318,6 +320,7 @@ extern spinlock_t ncsi_dev_lock; ...@@ -318,6 +320,7 @@ extern spinlock_t ncsi_dev_lock;
list_for_each_entry_rcu(nc, &np->channels, node) list_for_each_entry_rcu(nc, &np->channels, node)
/* Resources */ /* Resources */
u32 *ncsi_get_filter(struct ncsi_channel *nc, int table, int index);
int ncsi_find_filter(struct ncsi_channel *nc, int table, void *data); int ncsi_find_filter(struct ncsi_channel *nc, int table, void *data);
int ncsi_add_filter(struct ncsi_channel *nc, int table, void *data); int ncsi_add_filter(struct ncsi_channel *nc, int table, void *data);
int ncsi_remove_filter(struct ncsi_channel *nc, int table, int index); int ncsi_remove_filter(struct ncsi_channel *nc, int table, int index);
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/netlink.h>
#include <net/ncsi.h> #include <net/ncsi.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
...@@ -23,6 +22,7 @@ ...@@ -23,6 +22,7 @@
#include "internal.h" #include "internal.h"
#include "ncsi-pkt.h" #include "ncsi-pkt.h"
#include "ncsi-netlink.h"
LIST_HEAD(ncsi_dev_list); LIST_HEAD(ncsi_dev_list);
DEFINE_SPINLOCK(ncsi_dev_lock); DEFINE_SPINLOCK(ncsi_dev_lock);
...@@ -38,7 +38,7 @@ static inline int ncsi_filter_size(int table) ...@@ -38,7 +38,7 @@ static inline int ncsi_filter_size(int table)
return sizes[table]; return sizes[table];
} }
static u32 *ncsi_get_filter(struct ncsi_channel *nc, int table, int index) u32 *ncsi_get_filter(struct ncsi_channel *nc, int table, int index)
{ {
struct ncsi_channel_filter *ncf; struct ncsi_channel_filter *ncf;
int size; int size;
...@@ -965,20 +965,37 @@ static void ncsi_configure_channel(struct ncsi_dev_priv *ndp) ...@@ -965,20 +965,37 @@ static void ncsi_configure_channel(struct ncsi_dev_priv *ndp)
static int ncsi_choose_active_channel(struct ncsi_dev_priv *ndp) static int ncsi_choose_active_channel(struct ncsi_dev_priv *ndp)
{ {
struct ncsi_package *np; struct ncsi_package *np, *force_package;
struct ncsi_channel *nc, *found, *hot_nc; struct ncsi_channel *nc, *found, *hot_nc, *force_channel;
struct ncsi_channel_mode *ncm; struct ncsi_channel_mode *ncm;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&ndp->lock, flags); spin_lock_irqsave(&ndp->lock, flags);
hot_nc = ndp->hot_channel; hot_nc = ndp->hot_channel;
force_channel = ndp->force_channel;
force_package = ndp->force_package;
spin_unlock_irqrestore(&ndp->lock, flags); spin_unlock_irqrestore(&ndp->lock, flags);
/* Force a specific channel whether or not it has link if we have been
* configured to do so
*/
if (force_package && force_channel) {
found = force_channel;
ncm = &found->modes[NCSI_MODE_LINK];
if (!(ncm->data[2] & 0x1))
netdev_info(ndp->ndev.dev,
"NCSI: Channel %u forced, but it is link down\n",
found->id);
goto out;
}
/* The search is done once an inactive channel with up /* The search is done once an inactive channel with up
* link is found. * link is found.
*/ */
found = NULL; found = NULL;
NCSI_FOR_EACH_PACKAGE(ndp, np) { NCSI_FOR_EACH_PACKAGE(ndp, np) {
if (ndp->force_package && np != ndp->force_package)
continue;
NCSI_FOR_EACH_CHANNEL(np, nc) { NCSI_FOR_EACH_CHANNEL(np, nc) {
spin_lock_irqsave(&nc->lock, flags); spin_lock_irqsave(&nc->lock, flags);
...@@ -1594,6 +1611,9 @@ struct ncsi_dev *ncsi_register_dev(struct net_device *dev, ...@@ -1594,6 +1611,9 @@ struct ncsi_dev *ncsi_register_dev(struct net_device *dev,
ndp->ptype.dev = dev; ndp->ptype.dev = dev;
dev_add_pack(&ndp->ptype); dev_add_pack(&ndp->ptype);
/* Set up generic netlink interface */
ncsi_init_netlink(dev);
return nd; return nd;
} }
EXPORT_SYMBOL_GPL(ncsi_register_dev); EXPORT_SYMBOL_GPL(ncsi_register_dev);
...@@ -1673,6 +1693,8 @@ void ncsi_unregister_dev(struct ncsi_dev *nd) ...@@ -1673,6 +1693,8 @@ void ncsi_unregister_dev(struct ncsi_dev *nd)
#endif #endif
spin_unlock_irqrestore(&ncsi_dev_lock, flags); spin_unlock_irqrestore(&ncsi_dev_lock, flags);
ncsi_unregister_netlink(nd->dev);
kfree(ndp); kfree(ndp);
} }
EXPORT_SYMBOL_GPL(ncsi_unregister_dev); EXPORT_SYMBOL_GPL(ncsi_unregister_dev);
This diff is collapsed.
/*
* Copyright Samuel Mendoza-Jonas, IBM Corporation 2018.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#ifndef __NCSI_NETLINK_H__
#define __NCSI_NETLINK_H__
#include <linux/netdevice.h>
#include "internal.h"
int ncsi_init_netlink(struct net_device *dev);
int ncsi_unregister_netlink(struct net_device *dev);
#endif /* __NCSI_NETLINK_H__ */
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