s390/qeth: Translate address events into switchdev notifiers

A qeth-l2 HiperSockets card can show switch-ish behaviour in the sense,
that it can report all MACs that are reachable via this interface. Just
like a switch device, it can notify the software bridge about changes
to its fdb. This patch exploits this device-to-bridge-notification and
extracts the relevant information from the hardware events to generate
notifications to an attached software bridge.

There are 2 sources for this information:
1) The reply message of Perform-Network-Subchannel-Operations (PNSO)
(operation code ADDR_INFO) reports all addresses that are currently
reachable (implemented in a later patch).
2) As long as device-to-bridge-notification is enabled, hardware will
generate address change notification events, whenever the content of
the hardware fdb changes (this patch).

The bridge_hostnotify feature (PNSO operation code BRIDGE_INFO) uses
the same address change notification events. We need to distinguish
between qeth_pnso_mode QETH_PNSO_BRIDGEPORT and QETH_PNSO_ADDR_INFO
and call a different handler. In both cases deadlocks must be
prevented, if the workqueue is drained under lock and QETH_PNSO_NONE,
when notification is disabled.

bridge_hostnotify generates udev events, there is no intend to do the same
for dev2br. Instead this patch will generate SWITCHDEV_FDB_ADD_TO_BRIDGE
and SWITCHDEV_FDB_DEL_TO_BRIDGE notifications, that will cause the
software bridge to add (or delete) entries to its fdb as 'extern_learn
offload'.

Documentation/networking/switchdev.txt proposes to add
"depends NET_SWITCHDEV" to driver's Kconfig. This is not done here,
so even in absence of the NET_SWITCHDEV module, the QETH_L2 module will
still be built, but then the switchdev notifiers will have no effect.

No VLAN filtering is done on the entries and VLAN information is not
passed on to the bridge fdb entries. This could be added later.
For now VLAN interfaces can be defined on the upper bridge interface.

Multicast entries are not passed on to the bridge fdb.
This could be added later. For now mcast flooding can be used in the
bridge.

The card reports all MACs that are in its FDB, but we must not pass on
MACs that are registered for this interface.

Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
Reviewed-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Alexandra Winter 2020-09-10 19:23:47 +02:00 коммит произвёл David S. Miller
Родитель fa115adff2
Коммит 10a6cfc0fc
2 изменённых файлов: 110 добавлений и 1 удалений

Просмотреть файл

@ -677,6 +677,7 @@ struct qeth_card_blkt {
enum qeth_pnso_mode { enum qeth_pnso_mode {
QETH_PNSO_NONE, QETH_PNSO_NONE,
QETH_PNSO_BRIDGEPORT, QETH_PNSO_BRIDGEPORT,
QETH_PNSO_ADDR_INFO,
}; };
#define QETH_BROADCAST_WITH_ECHO 0x01 #define QETH_BROADCAST_WITH_ECHO 0x01

Просмотреть файл

@ -21,6 +21,7 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/hashtable.h> #include <linux/hashtable.h>
#include <net/switchdev.h>
#include <asm/chsc.h> #include <asm/chsc.h>
#include <asm/css_chars.h> #include <asm/css_chars.h>
#include <asm/setup.h> #include <asm/setup.h>
@ -709,6 +710,68 @@ static int qeth_l2_pnso(struct qeth_card *card, u8 oc, int cnc,
return rc; return rc;
} }
static bool qeth_is_my_net_if_token(struct qeth_card *card,
struct net_if_token *token)
{
return ((card->info.ddev_devno == token->devnum) &&
(card->info.cssid == token->cssid) &&
(card->info.iid == token->iid) &&
(card->info.ssid == token->ssid) &&
(card->info.chpid == token->chpid) &&
(card->info.chid == token->chid));
}
/**
* qeth_l2_dev2br_fdb_notify() - update fdb of master bridge
* @card: qeth_card structure pointer
* @code: event bitmask: high order bit 0x80 set to
* 1 - removal of an object
* 0 - addition of an object
* Object type(s):
* 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC
* @token: "network token" structure identifying 'physical' location
* of the target
* @addr_lnid: structure with MAC address and VLAN ID of the target
*/
static void qeth_l2_dev2br_fdb_notify(struct qeth_card *card, u8 code,
struct net_if_token *token,
struct mac_addr_lnid *addr_lnid)
{
struct switchdev_notifier_fdb_info info;
u8 ntfy_mac[ETH_ALEN];
ether_addr_copy(ntfy_mac, addr_lnid->mac);
/* Ignore VLAN only changes */
if (!(code & IPA_ADDR_CHANGE_CODE_MACADDR))
return;
/* Ignore mcast entries */
if (is_multicast_ether_addr(ntfy_mac))
return;
/* Ignore my own addresses */
if (qeth_is_my_net_if_token(card, token))
return;
info.addr = ntfy_mac;
/* don't report VLAN IDs */
info.vid = 0;
info.added_by_user = false;
info.offloaded = true;
if (code & IPA_ADDR_CHANGE_CODE_REMOVAL) {
call_switchdev_notifiers(SWITCHDEV_FDB_DEL_TO_BRIDGE,
card->dev, &info.info, NULL);
QETH_CARD_TEXT(card, 4, "andelmac");
QETH_CARD_TEXT_(card, 4,
"mc%012lx", ether_addr_to_u64(ntfy_mac));
} else {
call_switchdev_notifiers(SWITCHDEV_FDB_ADD_TO_BRIDGE,
card->dev, &info.info, NULL);
QETH_CARD_TEXT(card, 4, "anaddmac");
QETH_CARD_TEXT_(card, 4,
"mc%012lx", ether_addr_to_u64(ntfy_mac));
}
}
static const struct net_device_ops qeth_l2_netdev_ops = { static const struct net_device_ops qeth_l2_netdev_ops = {
.ndo_open = qeth_open, .ndo_open = qeth_open,
.ndo_stop = qeth_stop, .ndo_stop = qeth_stop,
@ -1216,6 +1279,48 @@ struct qeth_addr_change_data {
struct qeth_ipacmd_addr_change ac_event; struct qeth_ipacmd_addr_change ac_event;
}; };
static void qeth_l2_dev2br_worker(struct work_struct *work)
{
struct delayed_work *dwork = to_delayed_work(work);
struct qeth_addr_change_data *data;
struct qeth_card *card;
unsigned int i;
data = container_of(dwork, struct qeth_addr_change_data, dwork);
card = data->card;
QETH_CARD_TEXT(card, 4, "dev2brew");
if (READ_ONCE(card->info.pnso_mode) == QETH_PNSO_NONE)
goto free;
/* Potential re-config in progress, try again later: */
if (!rtnl_trylock()) {
queue_delayed_work(card->event_wq, dwork,
msecs_to_jiffies(100));
return;
}
if (data->ac_event.lost_event_mask) {
QETH_DBF_MESSAGE(3,
"Address change notification overflow on device %x\n",
CARD_DEVID(card));
} else {
for (i = 0; i < data->ac_event.num_entries; i++) {
struct qeth_ipacmd_addr_change_entry *entry =
&data->ac_event.entry[i];
qeth_l2_dev2br_fdb_notify(card,
entry->change_code,
&entry->token,
&entry->addr_lnid);
}
}
rtnl_unlock();
free:
kfree(data);
}
static void qeth_addr_change_event_worker(struct work_struct *work) static void qeth_addr_change_event_worker(struct work_struct *work)
{ {
struct delayed_work *dwork = to_delayed_work(work); struct delayed_work *dwork = to_delayed_work(work);
@ -1298,7 +1403,10 @@ static void qeth_addr_change_event(struct qeth_card *card,
QETH_CARD_TEXT(card, 2, "ACNalloc"); QETH_CARD_TEXT(card, 2, "ACNalloc");
return; return;
} }
INIT_DELAYED_WORK(&data->dwork, qeth_addr_change_event_worker); if (card->info.pnso_mode == QETH_PNSO_BRIDGEPORT)
INIT_DELAYED_WORK(&data->dwork, qeth_addr_change_event_worker);
else
INIT_DELAYED_WORK(&data->dwork, qeth_l2_dev2br_worker);
data->card = card; data->card = card;
memcpy(&data->ac_event, hostevs, memcpy(&data->ac_event, hostevs,
sizeof(struct qeth_ipacmd_addr_change) + extrasize); sizeof(struct qeth_ipacmd_addr_change) + extrasize);