blob: 6cc4704190fdeafc930ae23f9b0031a9d6cf722b [file] [log] [blame]
Vivien Didelota40c1752017-05-19 17:00:44 -04001/*
2 * Handling of a single switch port
3 *
4 * Copyright (c) 2017 Savoir-faire Linux Inc.
5 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <linux/if_bridge.h>
14
15#include "dsa_priv.h"
16
17int dsa_port_set_state(struct dsa_port *dp, u8 state,
18 struct switchdev_trans *trans)
19{
20 struct dsa_switch *ds = dp->ds;
21 int port = dp->index;
22
23 if (switchdev_trans_ph_prepare(trans))
24 return ds->ops->port_stp_state_set ? 0 : -EOPNOTSUPP;
25
26 if (ds->ops->port_stp_state_set)
27 ds->ops->port_stp_state_set(ds, port, state);
28
29 if (ds->ops->port_fast_age) {
30 /* Fast age FDB entries or flush appropriate forwarding database
31 * for the given port, if we are moving it from Learning or
32 * Forwarding state, to Disabled or Blocking or Listening state.
33 */
34
35 if ((dp->stp_state == BR_STATE_LEARNING ||
36 dp->stp_state == BR_STATE_FORWARDING) &&
37 (state == BR_STATE_DISABLED ||
38 state == BR_STATE_BLOCKING ||
39 state == BR_STATE_LISTENING))
40 ds->ops->port_fast_age(ds, port);
41 }
42
43 dp->stp_state = state;
44
45 return 0;
46}
47
48void dsa_port_set_state_now(struct dsa_port *dp, u8 state)
49{
50 int err;
51
52 err = dsa_port_set_state(dp, state, NULL);
53 if (err)
54 pr_err("DSA: failed to set STP state %u (%d)\n", state, err);
55}