aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/net/bonding/bond_main.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/Makefile3
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/cmd.h43
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/core.h6
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/pci.c14
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/reg.h490
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.c6
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.h24
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c91
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c1006
-rw-r--r--drivers/net/ethernet/rocker/rocker_main.c3
-rw-r--r--drivers/net/team/team.c2
-rw-r--r--include/linux/netdevice.h10
-rw-r--r--include/net/netevent.h1
-rw-r--r--net/8021q/vlan_dev.c2
-rw-r--r--net/atm/clip.c2
-rw-r--r--net/bridge/br_device.c2
-rw-r--r--net/core/dev.c44
-rw-r--r--net/core/neighbour.c6
-rw-r--r--net/ieee802154/6lowpan/core.c2
20 files changed, 1747 insertions, 12 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 90157e20357e..480d73ac7d1b 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4137,6 +4137,8 @@ static const struct net_device_ops bond_netdev_ops = {
4137 .ndo_add_slave = bond_enslave, 4137 .ndo_add_slave = bond_enslave,
4138 .ndo_del_slave = bond_release, 4138 .ndo_del_slave = bond_release,
4139 .ndo_fix_features = bond_fix_features, 4139 .ndo_fix_features = bond_fix_features,
4140 .ndo_neigh_construct = netdev_default_l2upper_neigh_construct,
4141 .ndo_neigh_destroy = netdev_default_l2upper_neigh_destroy,
4140 .ndo_bridge_setlink = switchdev_port_bridge_setlink, 4142 .ndo_bridge_setlink = switchdev_port_bridge_setlink,
4141 .ndo_bridge_getlink = switchdev_port_bridge_getlink, 4143 .ndo_bridge_getlink = switchdev_port_bridge_getlink,
4142 .ndo_bridge_dellink = switchdev_port_bridge_dellink, 4144 .ndo_bridge_dellink = switchdev_port_bridge_dellink,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/Makefile b/drivers/net/ethernet/mellanox/mlxsw/Makefile
index ea05f8a10e8c..d20ae1838a64 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/Makefile
+++ b/drivers/net/ethernet/mellanox/mlxsw/Makefile
@@ -7,5 +7,6 @@ obj-$(CONFIG_MLXSW_SWITCHX2) += mlxsw_switchx2.o
7mlxsw_switchx2-objs := switchx2.o 7mlxsw_switchx2-objs := switchx2.o
8obj-$(CONFIG_MLXSW_SPECTRUM) += mlxsw_spectrum.o 8obj-$(CONFIG_MLXSW_SPECTRUM) += mlxsw_spectrum.o
9mlxsw_spectrum-objs := spectrum.o spectrum_buffers.o \ 9mlxsw_spectrum-objs := spectrum.o spectrum_buffers.o \
10 spectrum_switchdev.o spectrum_router.o 10 spectrum_switchdev.o spectrum_router.o \
11 spectrum_kvdl.o
11mlxsw_spectrum-$(CONFIG_MLXSW_SPECTRUM_DCB) += spectrum_dcb.o 12mlxsw_spectrum-$(CONFIG_MLXSW_SPECTRUM_DCB) += spectrum_dcb.o
diff --git a/drivers/net/ethernet/mellanox/mlxsw/cmd.h b/drivers/net/ethernet/mellanox/mlxsw/cmd.h
index cd63b8263688..f9cd6e3f7709 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/cmd.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/cmd.h
@@ -607,6 +607,24 @@ MLXSW_ITEM32(cmd_mbox, config_profile,
607 */ 607 */
608MLXSW_ITEM32(cmd_mbox, config_profile, set_ar_sec, 0x0C, 15, 1); 608MLXSW_ITEM32(cmd_mbox, config_profile, set_ar_sec, 0x0C, 15, 1);
609 609
610/* cmd_mbox_config_set_kvd_linear_size
611 * Capability bit. Setting a bit to 1 configures the profile
612 * according to the mailbox contents.
613 */
614MLXSW_ITEM32(cmd_mbox, config_profile, set_kvd_linear_size, 0x0C, 24, 1);
615
616/* cmd_mbox_config_set_kvd_hash_single_size
617 * Capability bit. Setting a bit to 1 configures the profile
618 * according to the mailbox contents.
619 */
620MLXSW_ITEM32(cmd_mbox, config_profile, set_kvd_hash_single_size, 0x0C, 25, 1);
621
622/* cmd_mbox_config_set_kvd_hash_double_size
623 * Capability bit. Setting a bit to 1 configures the profile
624 * according to the mailbox contents.
625 */
626MLXSW_ITEM32(cmd_mbox, config_profile, set_kvd_hash_double_size, 0x0C, 26, 1);
627
610/* cmd_mbox_config_profile_max_vepa_channels 628/* cmd_mbox_config_profile_max_vepa_channels
611 * Maximum number of VEPA channels per port (0 through 16) 629 * Maximum number of VEPA channels per port (0 through 16)
612 * 0 - multi-channel VEPA is disabled 630 * 0 - multi-channel VEPA is disabled
@@ -733,6 +751,31 @@ MLXSW_ITEM32(cmd_mbox, config_profile, adaptive_routing_group_cap, 0x4C, 0, 16);
733 */ 751 */
734MLXSW_ITEM32(cmd_mbox, config_profile, arn, 0x50, 31, 1); 752MLXSW_ITEM32(cmd_mbox, config_profile, arn, 0x50, 31, 1);
735 753
754/* cmd_mbox_config_kvd_linear_size
755 * KVD Linear Size
756 * Valid for Spectrum only
757 * Allowed values are 128*N where N=0 or higher
758 */
759MLXSW_ITEM32(cmd_mbox, config_profile, kvd_linear_size, 0x54, 0, 24);
760
761/* cmd_mbox_config_kvd_hash_single_size
762 * KVD Hash single-entries size
763 * Valid for Spectrum only
764 * Allowed values are 128*N where N=0 or higher
765 * Must be greater or equal to cap_min_kvd_hash_single_size
766 * Must be smaller or equal to cap_kvd_size - kvd_linear_size
767 */
768MLXSW_ITEM32(cmd_mbox, config_profile, kvd_hash_single_size, 0x58, 0, 24);
769
770/* cmd_mbox_config_kvd_hash_double_size
771 * KVD Hash double-entries size (units of single-size entries)
772 * Valid for Spectrum only
773 * Allowed values are 128*N where N=0 or higher
774 * Must be either 0 or greater or equal to cap_min_kvd_hash_double_size
775 * Must be smaller or equal to cap_kvd_size - kvd_linear_size
776 */
777MLXSW_ITEM32(cmd_mbox, config_profile, kvd_hash_double_size, 0x5C, 0, 24);
778
736/* cmd_mbox_config_profile_swid_config_mask 779/* cmd_mbox_config_profile_swid_config_mask
737 * Modify Switch Partition Configuration mask. When set, the configu- 780 * Modify Switch Partition Configuration mask. When set, the configu-
738 * ration value for the Switch Partition are taken from the mailbox. 781 * ration value for the Switch Partition are taken from the mailbox.
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h
index 436bc49df6ab..2fe385cce203 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/core.h
@@ -190,7 +190,8 @@ struct mlxsw_config_profile {
190 used_max_ib_mc:1, 190 used_max_ib_mc:1,
191 used_max_pkey:1, 191 used_max_pkey:1,
192 used_ar_sec:1, 192 used_ar_sec:1,
193 used_adaptive_routing_group_cap:1; 193 used_adaptive_routing_group_cap:1,
194 used_kvd_sizes:1;
194 u8 max_vepa_channels; 195 u8 max_vepa_channels;
195 u16 max_lag; 196 u16 max_lag;
196 u16 max_port_per_lag; 197 u16 max_port_per_lag;
@@ -211,6 +212,9 @@ struct mlxsw_config_profile {
211 u8 ar_sec; 212 u8 ar_sec;
212 u16 adaptive_routing_group_cap; 213 u16 adaptive_routing_group_cap;
213 u8 arn; 214 u8 arn;
215 u32 kvd_linear_size;
216 u32 kvd_hash_single_size;
217 u32 kvd_hash_double_size;
214 struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT]; 218 struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT];
215}; 219};
216 220
diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index 7f4173c8eda3..ddbc9f22278d 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -1255,6 +1255,20 @@ static int mlxsw_pci_config_profile(struct mlxsw_pci *mlxsw_pci, char *mbox,
1255 mlxsw_cmd_mbox_config_profile_adaptive_routing_group_cap_set( 1255 mlxsw_cmd_mbox_config_profile_adaptive_routing_group_cap_set(
1256 mbox, profile->adaptive_routing_group_cap); 1256 mbox, profile->adaptive_routing_group_cap);
1257 } 1257 }
1258 if (profile->used_kvd_sizes) {
1259 mlxsw_cmd_mbox_config_profile_set_kvd_linear_size_set(
1260 mbox, 1);
1261 mlxsw_cmd_mbox_config_profile_kvd_linear_size_set(
1262 mbox, profile->kvd_linear_size);
1263 mlxsw_cmd_mbox_config_profile_set_kvd_hash_single_size_set(
1264 mbox, 1);
1265 mlxsw_cmd_mbox_config_profile_kvd_hash_single_size_set(
1266 mbox, profile->kvd_hash_single_size);
1267 mlxsw_cmd_mbox_config_profile_set_kvd_hash_double_size_set(
1268 mbox, 1);
1269 mlxsw_cmd_mbox_config_profile_kvd_hash_double_size_set(
1270 mbox, profile->kvd_hash_double_size);
1271 }
1258 1272
1259 for (i = 0; i < MLXSW_CONFIG_PROFILE_SWID_COUNT; i++) 1273 for (i = 0; i < MLXSW_CONFIG_PROFILE_SWID_COUNT; i++)
1260 mlxsw_pci_config_profile_swid_config(mlxsw_pci, mbox, i, 1274 mlxsw_pci_config_profile_swid_config(mlxsw_pci, mbox, i,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h
index 9280d96bb291..0cc148566677 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/reg.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h
@@ -4,6 +4,7 @@
4 * Copyright (c) 2015-2016 Ido Schimmel <idosch@mellanox.com> 4 * Copyright (c) 2015-2016 Ido Schimmel <idosch@mellanox.com>
5 * Copyright (c) 2015 Elad Raz <eladr@mellanox.com> 5 * Copyright (c) 2015 Elad Raz <eladr@mellanox.com>
6 * Copyright (c) 2015-2016 Jiri Pirko <jiri@mellanox.com> 6 * Copyright (c) 2015-2016 Jiri Pirko <jiri@mellanox.com>
7 * Copyright (c) 2016 Yotam Gigi <yotamg@mellanox.com>
7 * 8 *
8 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met: 10 * modification, are permitted provided that the following conditions are met:
@@ -3454,6 +3455,137 @@ static inline void mlxsw_reg_ritr_pack(char *payload, bool enable,
3454 mlxsw_reg_ritr_if_mac_memcpy_to(payload, mac); 3455 mlxsw_reg_ritr_if_mac_memcpy_to(payload, mac);
3455} 3456}
3456 3457
3458/* RATR - Router Adjacency Table Register
3459 * --------------------------------------
3460 * The RATR register is used to configure the Router Adjacency (next-hop)
3461 * Table.
3462 */
3463#define MLXSW_REG_RATR_ID 0x8008
3464#define MLXSW_REG_RATR_LEN 0x2C
3465
3466static const struct mlxsw_reg_info mlxsw_reg_ratr = {
3467 .id = MLXSW_REG_RATR_ID,
3468 .len = MLXSW_REG_RATR_LEN,
3469};
3470
3471enum mlxsw_reg_ratr_op {
3472 /* Read */
3473 MLXSW_REG_RATR_OP_QUERY_READ = 0,
3474 /* Read and clear activity */
3475 MLXSW_REG_RATR_OP_QUERY_READ_CLEAR = 2,
3476 /* Write Adjacency entry */
3477 MLXSW_REG_RATR_OP_WRITE_WRITE_ENTRY = 1,
3478 /* Write Adjacency entry only if the activity is cleared.
3479 * The write may not succeed if the activity is set. There is not
3480 * direct feedback if the write has succeeded or not, however
3481 * the get will reveal the actual entry (SW can compare the get
3482 * response to the set command).
3483 */
3484 MLXSW_REG_RATR_OP_WRITE_WRITE_ENTRY_ON_ACTIVITY = 3,
3485};
3486
3487/* reg_ratr_op
3488 * Note that Write operation may also be used for updating
3489 * counter_set_type and counter_index. In this case all other
3490 * fields must not be updated.
3491 * Access: OP
3492 */
3493MLXSW_ITEM32(reg, ratr, op, 0x00, 28, 4);
3494
3495/* reg_ratr_v
3496 * Valid bit. Indicates if the adjacency entry is valid.
3497 * Note: the device may need some time before reusing an invalidated
3498 * entry. During this time the entry can not be reused. It is
3499 * recommended to use another entry before reusing an invalidated
3500 * entry (e.g. software can put it at the end of the list for
3501 * reusing). Trying to access an invalidated entry not yet cleared
3502 * by the device results with failure indicating "Try Again" status.
3503 * When valid is '0' then egress_router_interface,trap_action,
3504 * adjacency_parameters and counters are reserved
3505 * Access: RW
3506 */
3507MLXSW_ITEM32(reg, ratr, v, 0x00, 24, 1);
3508
3509/* reg_ratr_a
3510 * Activity. Set for new entries. Set if a packet lookup has hit on
3511 * the specific entry. To clear the a bit, use "clear activity".
3512 * Access: RO
3513 */
3514MLXSW_ITEM32(reg, ratr, a, 0x00, 16, 1);
3515
3516/* reg_ratr_adjacency_index_low
3517 * Bits 15:0 of index into the adjacency table.
3518 * For SwitchX and SwitchX-2, the adjacency table is linear and
3519 * used for adjacency entries only.
3520 * For Spectrum, the index is to the KVD linear.
3521 * Access: Index
3522 */
3523MLXSW_ITEM32(reg, ratr, adjacency_index_low, 0x04, 0, 16);
3524
3525/* reg_ratr_egress_router_interface
3526 * Range is 0 .. cap_max_router_interfaces - 1
3527 * Access: RW
3528 */
3529MLXSW_ITEM32(reg, ratr, egress_router_interface, 0x08, 0, 16);
3530
3531enum mlxsw_reg_ratr_trap_action {
3532 MLXSW_REG_RATR_TRAP_ACTION_NOP,
3533 MLXSW_REG_RATR_TRAP_ACTION_TRAP,
3534 MLXSW_REG_RATR_TRAP_ACTION_MIRROR_TO_CPU,
3535 MLXSW_REG_RATR_TRAP_ACTION_MIRROR,
3536 MLXSW_REG_RATR_TRAP_ACTION_DISCARD_ERRORS,
3537};
3538
3539/* reg_ratr_trap_action
3540 * see mlxsw_reg_ratr_trap_action
3541 * Access: RW
3542 */
3543MLXSW_ITEM32(reg, ratr, trap_action, 0x0C, 28, 4);
3544
3545enum mlxsw_reg_ratr_trap_id {
3546 MLXSW_REG_RATR_TRAP_ID_RTR_EGRESS0 = 0,
3547 MLXSW_REG_RATR_TRAP_ID_RTR_EGRESS1 = 1,
3548};
3549
3550/* reg_ratr_adjacency_index_high
3551 * Bits 23:16 of the adjacency_index.
3552 * Access: Index
3553 */
3554MLXSW_ITEM32(reg, ratr, adjacency_index_high, 0x0C, 16, 8);
3555
3556/* reg_ratr_trap_id
3557 * Trap ID to be reported to CPU.
3558 * Trap-ID is RTR_EGRESS0 or RTR_EGRESS1.
3559 * For trap_action of NOP, MIRROR and DISCARD_ERROR
3560 * Access: RW
3561 */
3562MLXSW_ITEM32(reg, ratr, trap_id, 0x0C, 0, 8);
3563
3564/* reg_ratr_eth_destination_mac
3565 * MAC address of the destination next-hop.
3566 * Access: RW
3567 */
3568MLXSW_ITEM_BUF(reg, ratr, eth_destination_mac, 0x12, 6);
3569
3570static inline void
3571mlxsw_reg_ratr_pack(char *payload,
3572 enum mlxsw_reg_ratr_op op, bool valid,
3573 u32 adjacency_index, u16 egress_rif)
3574{
3575 MLXSW_REG_ZERO(ratr, payload);
3576 mlxsw_reg_ratr_op_set(payload, op);
3577 mlxsw_reg_ratr_v_set(payload, valid);
3578 mlxsw_reg_ratr_adjacency_index_low_set(payload, adjacency_index);
3579 mlxsw_reg_ratr_adjacency_index_high_set(payload, adjacency_index >> 16);
3580 mlxsw_reg_ratr_egress_router_interface_set(payload, egress_rif);
3581}
3582
3583static inline void mlxsw_reg_ratr_eth_entry_pack(char *payload,
3584 const char *dest_mac)
3585{
3586 mlxsw_reg_ratr_eth_destination_mac_memcpy_to(payload, dest_mac);
3587}
3588
3457/* RALTA - Router Algorithmic LPM Tree Allocation Register 3589/* RALTA - Router Algorithmic LPM Tree Allocation Register
3458 * ------------------------------------------------------- 3590 * -------------------------------------------------------
3459 * RALTA is used to allocate the LPM trees of the SHSPM method. 3591 * RALTA is used to allocate the LPM trees of the SHSPM method.
@@ -3884,6 +4016,356 @@ mlxsw_reg_ralue_act_ip2me_pack(char *payload)
3884 MLXSW_REG_RALUE_ACTION_TYPE_IP2ME); 4016 MLXSW_REG_RALUE_ACTION_TYPE_IP2ME);
3885} 4017}
3886 4018
4019/* RAUHT - Router Algorithmic LPM Unicast Host Table Register
4020 * ----------------------------------------------------------
4021 * The RAUHT register is used to configure and query the Unicast Host table in
4022 * devices that implement the Algorithmic LPM.
4023 */
4024#define MLXSW_REG_RAUHT_ID 0x8014
4025#define MLXSW_REG_RAUHT_LEN 0x74
4026
4027static const struct mlxsw_reg_info mlxsw_reg_rauht = {
4028 .id = MLXSW_REG_RAUHT_ID,
4029 .len = MLXSW_REG_RAUHT_LEN,
4030};
4031
4032enum mlxsw_reg_rauht_type {
4033 MLXSW_REG_RAUHT_TYPE_IPV4,
4034 MLXSW_REG_RAUHT_TYPE_IPV6,
4035};
4036
4037/* reg_rauht_type
4038 * Access: Index
4039 */
4040MLXSW_ITEM32(reg, rauht, type, 0x00, 24, 2);
4041
4042enum mlxsw_reg_rauht_op {
4043 MLXSW_REG_RAUHT_OP_QUERY_READ = 0,
4044 /* Read operation */
4045 MLXSW_REG_RAUHT_OP_QUERY_CLEAR_ON_READ = 1,
4046 /* Clear on read operation. Used to read entry and clear
4047 * activity bit.
4048 */
4049 MLXSW_REG_RAUHT_OP_WRITE_ADD = 0,
4050 /* Add. Used to write a new entry to the table. All R/W fields are
4051 * relevant for new entry. Activity bit is set for new entries.
4052 */
4053 MLXSW_REG_RAUHT_OP_WRITE_UPDATE = 1,
4054 /* Update action. Used to update an existing route entry and
4055 * only update the following fields:
4056 * trap_action, trap_id, mac, counter_set_type, counter_index
4057 */
4058 MLXSW_REG_RAUHT_OP_WRITE_CLEAR_ACTIVITY = 2,
4059 /* Clear activity. A bit is cleared for the entry. */
4060 MLXSW_REG_RAUHT_OP_WRITE_DELETE = 3,
4061 /* Delete entry */
4062 MLXSW_REG_RAUHT_OP_WRITE_DELETE_ALL = 4,
4063 /* Delete all host entries on a RIF. In this command, dip
4064 * field is reserved.
4065 */
4066};
4067
4068/* reg_rauht_op
4069 * Access: OP
4070 */
4071MLXSW_ITEM32(reg, rauht, op, 0x00, 20, 3);
4072
4073/* reg_rauht_a
4074 * Activity. Set for new entries. Set if a packet lookup has hit on
4075 * the specific entry.
4076 * To clear the a bit, use "clear activity" op.
4077 * Enabled by activity_dis in RGCR
4078 * Access: RO
4079 */
4080MLXSW_ITEM32(reg, rauht, a, 0x00, 16, 1);
4081
4082/* reg_rauht_rif
4083 * Router Interface
4084 * Access: Index
4085 */
4086MLXSW_ITEM32(reg, rauht, rif, 0x00, 0, 16);
4087
4088/* reg_rauht_dip*
4089 * Destination address.
4090 * Access: Index
4091 */
4092MLXSW_ITEM32(reg, rauht, dip4, 0x1C, 0x0, 32);
4093
4094enum mlxsw_reg_rauht_trap_action {
4095 MLXSW_REG_RAUHT_TRAP_ACTION_NOP,
4096 MLXSW_REG_RAUHT_TRAP_ACTION_TRAP,
4097 MLXSW_REG_RAUHT_TRAP_ACTION_MIRROR_TO_CPU,
4098 MLXSW_REG_RAUHT_TRAP_ACTION_MIRROR,
4099 MLXSW_REG_RAUHT_TRAP_ACTION_DISCARD_ERRORS,
4100};
4101
4102/* reg_rauht_trap_action
4103 * Access: RW
4104 */
4105MLXSW_ITEM32(reg, rauht, trap_action, 0x60, 28, 4);
4106
4107enum mlxsw_reg_rauht_trap_id {
4108 MLXSW_REG_RAUHT_TRAP_ID_RTR_EGRESS0,
4109 MLXSW_REG_RAUHT_TRAP_ID_RTR_EGRESS1,
4110};
4111
4112/* reg_rauht_trap_id
4113 * Trap ID to be reported to CPU.
4114 * Trap-ID is RTR_EGRESS0 or RTR_EGRESS1.
4115 * For trap_action of NOP, MIRROR and DISCARD_ERROR,
4116 * trap_id is reserved.
4117 * Access: RW
4118 */
4119MLXSW_ITEM32(reg, rauht, trap_id, 0x60, 0, 9);
4120
4121/* reg_rauht_counter_set_type
4122 * Counter set type for flow counters
4123 * Access: RW
4124 */
4125MLXSW_ITEM32(reg, rauht, counter_set_type, 0x68, 24, 8);
4126
4127/* reg_rauht_counter_index
4128 * Counter index for flow counters
4129 * Access: RW
4130 */
4131MLXSW_ITEM32(reg, rauht, counter_index, 0x68, 0, 24);
4132
4133/* reg_rauht_mac
4134 * MAC address.
4135 * Access: RW
4136 */
4137MLXSW_ITEM_BUF(reg, rauht, mac, 0x6E, 6);
4138
4139static inline void mlxsw_reg_rauht_pack(char *payload,
4140 enum mlxsw_reg_rauht_op op, u16 rif,
4141 const char *mac)
4142{
4143 MLXSW_REG_ZERO(rauht, payload);
4144 mlxsw_reg_rauht_op_set(payload, op);
4145 mlxsw_reg_rauht_rif_set(payload, rif);
4146 mlxsw_reg_rauht_mac_memcpy_to(payload, mac);
4147}
4148
4149static inline void mlxsw_reg_rauht_pack4(char *payload,
4150 enum mlxsw_reg_rauht_op op, u16 rif,
4151 const char *mac, u32 dip)
4152{
4153 mlxsw_reg_rauht_pack(payload, op, rif, mac);
4154 mlxsw_reg_rauht_dip4_set(payload, dip);
4155}
4156
4157/* RALEU - Router Algorithmic LPM ECMP Update Register
4158 * ---------------------------------------------------
4159 * The register enables updating the ECMP section in the action for multiple
4160 * LPM Unicast entries in a single operation. The update is executed to
4161 * all entries of a {virtual router, protocol} tuple using the same ECMP group.
4162 */
4163#define MLXSW_REG_RALEU_ID 0x8015
4164#define MLXSW_REG_RALEU_LEN 0x28
4165
4166static const struct mlxsw_reg_info mlxsw_reg_raleu = {
4167 .id = MLXSW_REG_RALEU_ID,
4168 .len = MLXSW_REG_RALEU_LEN,
4169};
4170
4171/* reg_raleu_protocol
4172 * Protocol.
4173 * Access: Index
4174 */
4175MLXSW_ITEM32(reg, raleu, protocol, 0x00, 24, 4);
4176
4177/* reg_raleu_virtual_router
4178 * Virtual Router ID
4179 * Range is 0..cap_max_virtual_routers-1
4180 * Access: Index
4181 */
4182MLXSW_ITEM32(reg, raleu, virtual_router, 0x00, 0, 16);
4183
4184/* reg_raleu_adjacency_index
4185 * Adjacency Index used for matching on the existing entries.
4186 * Access: Index
4187 */
4188MLXSW_ITEM32(reg, raleu, adjacency_index, 0x10, 0, 24);
4189
4190/* reg_raleu_ecmp_size
4191 * ECMP Size used for matching on the existing entries.
4192 * Access: Index
4193 */
4194MLXSW_ITEM32(reg, raleu, ecmp_size, 0x14, 0, 13);
4195
4196/* reg_raleu_new_adjacency_index
4197 * New Adjacency Index.
4198 * Access: WO
4199 */
4200MLXSW_ITEM32(reg, raleu, new_adjacency_index, 0x20, 0, 24);
4201
4202/* reg_raleu_new_ecmp_size
4203 * New ECMP Size.
4204 * Access: WO
4205 */
4206MLXSW_ITEM32(reg, raleu, new_ecmp_size, 0x24, 0, 13);
4207
4208static inline void mlxsw_reg_raleu_pack(char *payload,
4209 enum mlxsw_reg_ralxx_protocol protocol,
4210 u16 virtual_router,
4211 u32 adjacency_index, u16 ecmp_size,
4212 u32 new_adjacency_index,
4213 u16 new_ecmp_size)
4214{
4215 MLXSW_REG_ZERO(raleu, payload);
4216 mlxsw_reg_raleu_protocol_set(payload, protocol);
4217 mlxsw_reg_raleu_virtual_router_set(payload, virtual_router);
4218 mlxsw_reg_raleu_adjacency_index_set(payload, adjacency_index);
4219 mlxsw_reg_raleu_ecmp_size_set(payload, ecmp_size);
4220 mlxsw_reg_raleu_new_adjacency_index_set(payload, new_adjacency_index);
4221 mlxsw_reg_raleu_new_ecmp_size_set(payload, new_ecmp_size);
4222}
4223
4224/* RAUHTD - Router Algorithmic LPM Unicast Host Table Dump Register
4225 * ----------------------------------------------------------------
4226 * The RAUHTD register allows dumping entries from the Router Unicast Host
4227 * Table. For a given session an entry is dumped no more than one time. The
4228 * first RAUHTD access after reset is a new session. A session ends when the
4229 * num_rec response is smaller than num_rec request or for IPv4 when the
4230 * num_entries is smaller than 4. The clear activity affect the current session
4231 * or the last session if a new session has not started.
4232 */
4233#define MLXSW_REG_RAUHTD_ID 0x8018
4234#define MLXSW_REG_RAUHTD_BASE_LEN 0x20
4235#define MLXSW_REG_RAUHTD_REC_LEN 0x20
4236#define MLXSW_REG_RAUHTD_REC_MAX_NUM 32
4237#define MLXSW_REG_RAUHTD_LEN (MLXSW_REG_RAUHTD_BASE_LEN + \
4238 MLXSW_REG_RAUHTD_REC_MAX_NUM * MLXSW_REG_RAUHTD_REC_LEN)
4239#define MLXSW_REG_RAUHTD_IPV4_ENT_PER_REC 4
4240
4241static const struct mlxsw_reg_info mlxsw_reg_rauhtd = {
4242 .id = MLXSW_REG_RAUHTD_ID,
4243 .len = MLXSW_REG_RAUHTD_LEN,
4244};
4245
4246#define MLXSW_REG_RAUHTD_FILTER_A BIT(0)
4247#define MLXSW_REG_RAUHTD_FILTER_RIF BIT(3)
4248
4249/* reg_rauhtd_filter_fields
4250 * if a bit is '0' then the relevant field is ignored and dump is done
4251 * regardless of the field value
4252 * Bit0 - filter by activity: entry_a
4253 * Bit3 - filter by entry rip: entry_rif
4254 * Access: Index
4255 */
4256MLXSW_ITEM32(reg, rauhtd, filter_fields, 0x00, 0, 8);
4257
4258enum mlxsw_reg_rauhtd_op {
4259 MLXSW_REG_RAUHTD_OP_DUMP,
4260 MLXSW_REG_RAUHTD_OP_DUMP_AND_CLEAR,
4261};
4262
4263/* reg_rauhtd_op
4264 * Access: OP
4265 */
4266MLXSW_ITEM32(reg, rauhtd, op, 0x04, 24, 2);
4267
4268/* reg_rauhtd_num_rec
4269 * At request: number of records requested
4270 * At response: number of records dumped
4271 * For IPv4, each record has 4 entries at request and up to 4 entries
4272 * at response
4273 * Range is 0..MLXSW_REG_RAUHTD_REC_MAX_NUM
4274 * Access: Index
4275 */
4276MLXSW_ITEM32(reg, rauhtd, num_rec, 0x04, 0, 8);
4277
4278/* reg_rauhtd_entry_a
4279 * Dump only if activity has value of entry_a
4280 * Reserved if filter_fields bit0 is '0'
4281 * Access: Index
4282 */
4283MLXSW_ITEM32(reg, rauhtd, entry_a, 0x08, 16, 1);
4284
4285enum mlxsw_reg_rauhtd_type {
4286 MLXSW_REG_RAUHTD_TYPE_IPV4,
4287 MLXSW_REG_RAUHTD_TYPE_IPV6,
4288};
4289
4290/* reg_rauhtd_type
4291 * Dump only if record type is:
4292 * 0 - IPv4
4293 * 1 - IPv6
4294 * Access: Index
4295 */
4296MLXSW_ITEM32(reg, rauhtd, type, 0x08, 0, 4);
4297
4298/* reg_rauhtd_entry_rif
4299 * Dump only if RIF has value of entry_rif
4300 * Reserved if filter_fields bit3 is '0'
4301 * Access: Index
4302 */
4303MLXSW_ITEM32(reg, rauhtd, entry_rif, 0x0C, 0, 16);
4304
4305static inline void mlxsw_reg_rauhtd_pack(char *payload,
4306 enum mlxsw_reg_rauhtd_type type)
4307{
4308 MLXSW_REG_ZERO(rauhtd, payload);
4309 mlxsw_reg_rauhtd_filter_fields_set(payload, MLXSW_REG_RAUHTD_FILTER_A);
4310 mlxsw_reg_rauhtd_op_set(payload, MLXSW_REG_RAUHTD_OP_DUMP_AND_CLEAR);
4311 mlxsw_reg_rauhtd_num_rec_set(payload, MLXSW_REG_RAUHTD_REC_MAX_NUM);
4312 mlxsw_reg_rauhtd_entry_a_set(payload, 1);
4313 mlxsw_reg_rauhtd_type_set(payload, type);
4314}
4315
4316/* reg_rauhtd_ipv4_rec_num_entries
4317 * Number of valid entries in this record:
4318 * 0 - 1 valid entry
4319 * 1 - 2 valid entries
4320 * 2 - 3 valid entries
4321 * 3 - 4 valid entries
4322 * Access: RO
4323 */
4324MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_rec_num_entries,
4325 MLXSW_REG_RAUHTD_BASE_LEN, 28, 2,
4326 MLXSW_REG_RAUHTD_REC_LEN, 0x00, false);
4327
4328/* reg_rauhtd_rec_type
4329 * Record type.
4330 * 0 - IPv4
4331 * 1 - IPv6
4332 * Access: RO
4333 */
4334MLXSW_ITEM32_INDEXED(reg, rauhtd, rec_type, MLXSW_REG_RAUHTD_BASE_LEN, 24, 2,
4335 MLXSW_REG_RAUHTD_REC_LEN, 0x00, false);
4336
4337#define MLXSW_REG_RAUHTD_IPV4_ENT_LEN 0x8
4338
4339/* reg_rauhtd_ipv4_ent_a
4340 * Activity. Set for new entries. Set if a packet lookup has hit on the
4341 * specific entry.
4342 * Access: RO
4343 */
4344MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_ent_a, MLXSW_REG_RAUHTD_BASE_LEN, 16, 1,
4345 MLXSW_REG_RAUHTD_IPV4_ENT_LEN, 0x00, false);
4346
4347/* reg_rauhtd_ipv4_ent_rif
4348 * Router interface.
4349 * Access: RO
4350 */
4351MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_ent_rif, MLXSW_REG_RAUHTD_BASE_LEN, 0,
4352 16, MLXSW_REG_RAUHTD_IPV4_ENT_LEN, 0x00, false);
4353
4354/* reg_rauhtd_ipv4_ent_dip
4355 * Destination IPv4 address.
4356 * Access: RO
4357 */
4358MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_ent_dip, MLXSW_REG_RAUHTD_BASE_LEN, 0,
4359 32, MLXSW_REG_RAUHTD_IPV4_ENT_LEN, 0x04, false);
4360
4361static inline void mlxsw_reg_rauhtd_ent_ipv4_unpack(char *payload,
4362 int ent_index, u16 *p_rif,
4363 u32 *p_dip)
4364{
4365 *p_rif = mlxsw_reg_rauhtd_ipv4_ent_rif_get(payload, ent_index);
4366 *p_dip = mlxsw_reg_rauhtd_ipv4_ent_dip_get(payload, ent_index);
4367}
4368
3887/* MFCR - Management Fan Control Register 4369/* MFCR - Management Fan Control Register
3888 * -------------------------------------- 4370 * --------------------------------------
3889 * This register controls the settings of the Fan Speed PWM mechanism. 4371 * This register controls the settings of the Fan Speed PWM mechanism.
@@ -4626,6 +5108,8 @@ static inline const char *mlxsw_reg_id_str(u16 reg_id)
4626 return "RGCR"; 5108 return "RGCR";
4627 case MLXSW_REG_RITR_ID: 5109 case MLXSW_REG_RITR_ID:
4628 return "RITR"; 5110 return "RITR";
5111 case MLXSW_REG_RATR_ID:
5112 return "RATR";
4629 case MLXSW_REG_RALTA_ID: 5113 case MLXSW_REG_RALTA_ID:
4630 return "RALTA"; 5114 return "RALTA";
4631 case MLXSW_REG_RALST_ID: 5115 case MLXSW_REG_RALST_ID:
@@ -4634,6 +5118,12 @@ static inline const char *mlxsw_reg_id_str(u16 reg_id)
4634 return "RALTB"; 5118 return "RALTB";
4635 case MLXSW_REG_RALUE_ID: 5119 case MLXSW_REG_RALUE_ID:
4636 return "RALUE"; 5120 return "RALUE";
5121 case MLXSW_REG_RAUHT_ID:
5122 return "RAUHT";
5123 case MLXSW_REG_RALEU_ID:
5124 return "RALEU";
5125 case MLXSW_REG_RAUHTD_ID:
5126 return "RAUHTD";
4637 case MLXSW_REG_MFCR_ID: 5127 case MLXSW_REG_MFCR_ID:
4638 return "MFCR"; 5128 return "MFCR";
4639 case MLXSW_REG_MFSC_ID: 5129 case MLXSW_REG_MFSC_ID:
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 7b2b741b2a23..c812513e079d 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -803,6 +803,8 @@ static const struct net_device_ops mlxsw_sp_port_netdev_ops = {
803 .ndo_get_stats64 = mlxsw_sp_port_get_stats64, 803 .ndo_get_stats64 = mlxsw_sp_port_get_stats64,
804 .ndo_vlan_rx_add_vid = mlxsw_sp_port_add_vid, 804 .ndo_vlan_rx_add_vid = mlxsw_sp_port_add_vid,
805 .ndo_vlan_rx_kill_vid = mlxsw_sp_port_kill_vid, 805 .ndo_vlan_rx_kill_vid = mlxsw_sp_port_kill_vid,
806 .ndo_neigh_construct = mlxsw_sp_router_neigh_construct,
807 .ndo_neigh_destroy = mlxsw_sp_router_neigh_destroy,
806 .ndo_fdb_add = switchdev_port_fdb_add, 808 .ndo_fdb_add = switchdev_port_fdb_add,
807 .ndo_fdb_del = switchdev_port_fdb_del, 809 .ndo_fdb_del = switchdev_port_fdb_del,
808 .ndo_fdb_dump = switchdev_port_fdb_dump, 810 .ndo_fdb_dump = switchdev_port_fdb_dump,
@@ -2354,6 +2356,10 @@ static struct mlxsw_config_profile mlxsw_sp_config_profile = {
2354 .max_ib_mc = 0, 2356 .max_ib_mc = 0,
2355 .used_max_pkey = 1, 2357 .used_max_pkey = 1,
2356 .max_pkey = 0, 2358 .max_pkey = 0,
2359 .used_kvd_sizes = 1,
2360 .kvd_linear_size = MLXSW_SP_KVD_LINEAR_SIZE,
2361 .kvd_hash_single_size = MLXSW_SP_KVD_HASH_SINGLE_SIZE,
2362 .kvd_hash_double_size = MLXSW_SP_KVD_HASH_DOUBLE_SIZE,
2357 .swid_config = { 2363 .swid_config = {
2358 { 2364 {
2359 .used_type = 1, 2365 .used_type = 1,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index 958e821ce845..ef4ac8987a2a 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -39,6 +39,7 @@
39 39
40#include <linux/types.h> 40#include <linux/types.h>
41#include <linux/netdevice.h> 41#include <linux/netdevice.h>
42#include <linux/rhashtable.h>
42#include <linux/bitops.h> 43#include <linux/bitops.h>
43#include <linux/if_vlan.h> 44#include <linux/if_vlan.h>
44#include <linux/list.h> 45#include <linux/list.h>
@@ -75,6 +76,10 @@
75#define MLXSW_SP_BYTES_TO_CELLS(b) DIV_ROUND_UP(b, MLXSW_SP_BYTES_PER_CELL) 76#define MLXSW_SP_BYTES_TO_CELLS(b) DIV_ROUND_UP(b, MLXSW_SP_BYTES_PER_CELL)
76#define MLXSW_SP_CELLS_TO_BYTES(c) (c * MLXSW_SP_BYTES_PER_CELL) 77#define MLXSW_SP_CELLS_TO_BYTES(c) (c * MLXSW_SP_BYTES_PER_CELL)
77 78
79#define MLXSW_SP_KVD_LINEAR_SIZE 65536 /* entries */
80#define MLXSW_SP_KVD_HASH_SINGLE_SIZE 163840 /* entries */
81#define MLXSW_SP_KVD_HASH_DOUBLE_SIZE 32768 /* entries */
82
78/* Maximum delay buffer needed in case of PAUSE frames, in cells. 83/* Maximum delay buffer needed in case of PAUSE frames, in cells.
79 * Assumes 100m cable and maximum MTU. 84 * Assumes 100m cable and maximum MTU.
80 */ 85 */
@@ -212,6 +217,15 @@ struct mlxsw_sp_vr {
212struct mlxsw_sp_router { 217struct mlxsw_sp_router {
213 struct mlxsw_sp_lpm_tree lpm_trees[MLXSW_SP_LPM_TREE_COUNT]; 218 struct mlxsw_sp_lpm_tree lpm_trees[MLXSW_SP_LPM_TREE_COUNT];
214 struct mlxsw_sp_vr vrs[MLXSW_SP_VIRTUAL_ROUTER_MAX]; 219 struct mlxsw_sp_vr vrs[MLXSW_SP_VIRTUAL_ROUTER_MAX];
220 struct rhashtable neigh_ht;
221 struct {
222 struct delayed_work dw;
223 unsigned long interval; /* ms */
224 } neighs_update;
225 struct delayed_work nexthop_probe_dw;
226#define MLXSW_SP_UNRESOLVED_NH_PROBE_INTERVAL 5000 /* ms */
227 struct list_head nexthop_group_list;
228 struct list_head nexthop_neighs_list;
215}; 229};
216 230
217struct mlxsw_sp { 231struct mlxsw_sp {
@@ -243,6 +257,9 @@ struct mlxsw_sp {
243 u8 port_to_module[MLXSW_PORT_MAX_PORTS]; 257 u8 port_to_module[MLXSW_PORT_MAX_PORTS];
244 struct mlxsw_sp_sb sb; 258 struct mlxsw_sp_sb sb;
245 struct mlxsw_sp_router router; 259 struct mlxsw_sp_router router;
260 struct {
261 DECLARE_BITMAP(usage, MLXSW_SP_KVD_LINEAR_SIZE);
262 } kvdl;
246}; 263};
247 264
248static inline struct mlxsw_sp_upper * 265static inline struct mlxsw_sp_upper *
@@ -524,5 +541,12 @@ int mlxsw_sp_router_fib4_add(struct mlxsw_sp_port *mlxsw_sp_port,
524 struct switchdev_trans *trans); 541 struct switchdev_trans *trans);
525int mlxsw_sp_router_fib4_del(struct mlxsw_sp_port *mlxsw_sp_port, 542int mlxsw_sp_router_fib4_del(struct mlxsw_sp_port *mlxsw_sp_port,
526 const struct switchdev_obj_ipv4_fib *fib4); 543 const struct switchdev_obj_ipv4_fib *fib4);
544int mlxsw_sp_router_neigh_construct(struct net_device *dev,
545 struct neighbour *n);
546void mlxsw_sp_router_neigh_destroy(struct net_device *dev,
547 struct neighbour *n);
548
549int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count);
550void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, int entry_index);
527 551
528#endif 552#endif
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
new file mode 100644
index 000000000000..ac321e8e5c1a
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
@@ -0,0 +1,91 @@
1/*
2 * drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
3 * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the names of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") version 2 as published by the Free
20 * Software Foundation.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <linux/kernel.h>
36#include <linux/bitops.h>
37
38#include "spectrum.h"
39
40#define MLXSW_SP_KVDL_SINGLE_BASE 0
41#define MLXSW_SP_KVDL_SINGLE_SIZE 16384
42#define MLXSW_SP_KVDL_CHUNKS_BASE \
43 (MLXSW_SP_KVDL_SINGLE_BASE + MLXSW_SP_KVDL_SINGLE_SIZE)
44#define MLXSW_SP_KVDL_CHUNKS_SIZE \
45 (MLXSW_SP_KVD_LINEAR_SIZE - MLXSW_SP_KVDL_CHUNKS_BASE)
46#define MLXSW_SP_CHUNK_MAX 32
47
48int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count)
49{
50 int entry_index;
51 int size;
52 int type_base;
53 int type_size;
54 int type_entries;
55
56 if (entry_count == 0 || entry_count > MLXSW_SP_CHUNK_MAX) {
57 return -EINVAL;
58 } else if (entry_count == 1) {
59 type_base = MLXSW_SP_KVDL_SINGLE_BASE;
60 type_size = MLXSW_SP_KVDL_SINGLE_SIZE;
61 type_entries = 1;
62 } else {
63 type_base = MLXSW_SP_KVDL_CHUNKS_BASE;
64 type_size = MLXSW_SP_KVDL_CHUNKS_SIZE;
65 type_entries = MLXSW_SP_CHUNK_MAX;
66 }
67
68 entry_index = type_base;
69 size = type_base + type_size;
70 for_each_clear_bit_from(entry_index, mlxsw_sp->kvdl.usage, size) {
71 int i;
72
73 for (i = 0; i < type_entries; i++)
74 set_bit(entry_index + i, mlxsw_sp->kvdl.usage);
75 return entry_index;
76 }
77 return -ENOBUFS;
78}
79
80void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, int entry_index)
81{
82 int type_entries;
83 int i;
84
85 if (entry_index < MLXSW_SP_KVDL_CHUNKS_BASE)
86 type_entries = 1;
87 else
88 type_entries = MLXSW_SP_CHUNK_MAX;
89 for (i = 0; i < type_entries; i++)
90 clear_bit(entry_index + i, mlxsw_sp->kvdl.usage);
91}
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 7e3992a681b3..e084ea5448ac 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -3,6 +3,7 @@
3 * Copyright (c) 2016 Mellanox Technologies. All rights reserved. 3 * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com> 4 * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
5 * Copyright (c) 2016 Ido Schimmel <idosch@mellanox.com> 5 * Copyright (c) 2016 Ido Schimmel <idosch@mellanox.com>
6 * Copyright (c) 2016 Yotam Gigi <yotamg@mellanox.com>
6 * 7 *
7 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met: 9 * modification, are permitted provided that the following conditions are met:
@@ -38,6 +39,10 @@
38#include <linux/rhashtable.h> 39#include <linux/rhashtable.h>
39#include <linux/bitops.h> 40#include <linux/bitops.h>
40#include <linux/in6.h> 41#include <linux/in6.h>
42#include <linux/notifier.h>
43#include <net/netevent.h>
44#include <net/neighbour.h>
45#include <net/arp.h>
41 46
42#include "spectrum.h" 47#include "spectrum.h"
43#include "core.h" 48#include "core.h"
@@ -112,6 +117,8 @@ enum mlxsw_sp_fib_entry_type {
112 MLXSW_SP_FIB_ENTRY_TYPE_TRAP, 117 MLXSW_SP_FIB_ENTRY_TYPE_TRAP,
113}; 118};
114 119
120struct mlxsw_sp_nexthop_group;
121
115struct mlxsw_sp_fib_entry { 122struct mlxsw_sp_fib_entry {
116 struct rhash_head ht_node; 123 struct rhash_head ht_node;
117 struct mlxsw_sp_fib_key key; 124 struct mlxsw_sp_fib_key key;
@@ -119,6 +126,8 @@ struct mlxsw_sp_fib_entry {
119 u8 added:1; 126 u8 added:1;
120 u16 rif; /* used for action local */ 127 u16 rif; /* used for action local */
121 struct mlxsw_sp_vr *vr; 128 struct mlxsw_sp_vr *vr;
129 struct list_head nexthop_group_node;
130 struct mlxsw_sp_nexthop_group *nh_group;
122}; 131};
123 132
124struct mlxsw_sp_fib { 133struct mlxsw_sp_fib {
@@ -544,6 +553,949 @@ static void mlxsw_sp_vrs_init(struct mlxsw_sp *mlxsw_sp)
544 } 553 }
545} 554}
546 555
556struct mlxsw_sp_neigh_key {
557 unsigned char addr[sizeof(struct in6_addr)];
558 struct net_device *dev;
559};
560
561struct mlxsw_sp_neigh_entry {
562 struct rhash_head ht_node;
563 struct mlxsw_sp_neigh_key key;
564 u16 rif;
565 struct neighbour *n;
566 bool offloaded;
567 struct delayed_work dw;
568 struct mlxsw_sp_port *mlxsw_sp_port;
569 unsigned char ha[ETH_ALEN];
570 struct list_head nexthop_list; /* list of nexthops using
571 * this neigh entry
572 */
573 struct list_head nexthop_neighs_list_node;
574};
575
576static const struct rhashtable_params mlxsw_sp_neigh_ht_params = {
577 .key_offset = offsetof(struct mlxsw_sp_neigh_entry, key),
578 .head_offset = offsetof(struct mlxsw_sp_neigh_entry, ht_node),
579 .key_len = sizeof(struct mlxsw_sp_neigh_key),
580};
581
582static int
583mlxsw_sp_neigh_entry_insert(struct mlxsw_sp *mlxsw_sp,
584 struct mlxsw_sp_neigh_entry *neigh_entry)
585{
586 return rhashtable_insert_fast(&mlxsw_sp->router.neigh_ht,
587 &neigh_entry->ht_node,
588 mlxsw_sp_neigh_ht_params);
589}
590
591static void
592mlxsw_sp_neigh_entry_remove(struct mlxsw_sp *mlxsw_sp,
593 struct mlxsw_sp_neigh_entry *neigh_entry)
594{
595 rhashtable_remove_fast(&mlxsw_sp->router.neigh_ht,
596 &neigh_entry->ht_node,
597 mlxsw_sp_neigh_ht_params);
598}
599
600static void mlxsw_sp_router_neigh_update_hw(struct work_struct *work);
601
602static struct mlxsw_sp_neigh_entry *
603mlxsw_sp_neigh_entry_create(const void *addr, size_t addr_len,
604 struct net_device *dev, u16 rif,
605 struct neighbour *n)
606{
607 struct mlxsw_sp_neigh_entry *neigh_entry;
608
609 neigh_entry = kzalloc(sizeof(*neigh_entry), GFP_ATOMIC);
610 if (!neigh_entry)
611 return NULL;
612 memcpy(neigh_entry->key.addr, addr, addr_len);
613 neigh_entry->key.dev = dev;
614 neigh_entry->rif = rif;
615 neigh_entry->n = n;
616 INIT_DELAYED_WORK(&neigh_entry->dw, mlxsw_sp_router_neigh_update_hw);
617 INIT_LIST_HEAD(&neigh_entry->nexthop_list);
618 return neigh_entry;
619}
620
621static void
622mlxsw_sp_neigh_entry_destroy(struct mlxsw_sp_neigh_entry *neigh_entry)
623{
624 kfree(neigh_entry);
625}
626
627static struct mlxsw_sp_neigh_entry *
628mlxsw_sp_neigh_entry_lookup(struct mlxsw_sp *mlxsw_sp, const void *addr,
629 size_t addr_len, struct net_device *dev)
630{
631 struct mlxsw_sp_neigh_key key = {{ 0 } };
632
633 memcpy(key.addr, addr, addr_len);
634 key.dev = dev;
635 return rhashtable_lookup_fast(&mlxsw_sp->router.neigh_ht,
636 &key, mlxsw_sp_neigh_ht_params);
637}
638
639int mlxsw_sp_router_neigh_construct(struct net_device *dev,
640 struct neighbour *n)
641{
642 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
643 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
644 struct mlxsw_sp_neigh_entry *neigh_entry;
645 struct mlxsw_sp_rif *r;
646 u32 dip;
647 int err;
648
649 if (n->tbl != &arp_tbl)
650 return 0;
651
652 dip = ntohl(*((__be32 *) n->primary_key));
653 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, &dip, sizeof(dip),
654 n->dev);
655 if (neigh_entry) {
656 WARN_ON(neigh_entry->n != n);
657 return 0;
658 }
659
660 r = mlxsw_sp_rif_find_by_dev(mlxsw_sp, dev);
661 if (WARN_ON(!r))
662 return -EINVAL;
663
664 neigh_entry = mlxsw_sp_neigh_entry_create(&dip, sizeof(dip), n->dev,
665 r->rif, n);
666 if (!neigh_entry)
667 return -ENOMEM;
668 err = mlxsw_sp_neigh_entry_insert(mlxsw_sp, neigh_entry);
669 if (err)
670 goto err_neigh_entry_insert;
671 return 0;
672
673err_neigh_entry_insert:
674 mlxsw_sp_neigh_entry_destroy(neigh_entry);
675 return err;
676}
677
678void mlxsw_sp_router_neigh_destroy(struct net_device *dev,
679 struct neighbour *n)
680{
681 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
682 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
683 struct mlxsw_sp_neigh_entry *neigh_entry;
684 u32 dip;
685
686 if (n->tbl != &arp_tbl)
687 return;
688
689 dip = ntohl(*((__be32 *) n->primary_key));
690 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, &dip, sizeof(dip),
691 n->dev);
692 if (!neigh_entry)
693 return;
694 mlxsw_sp_neigh_entry_remove(mlxsw_sp, neigh_entry);
695 mlxsw_sp_neigh_entry_destroy(neigh_entry);
696}
697
698static void
699mlxsw_sp_router_neighs_update_interval_init(struct mlxsw_sp *mlxsw_sp)
700{
701 unsigned long interval = NEIGH_VAR(&arp_tbl.parms, DELAY_PROBE_TIME);
702
703 mlxsw_sp->router.neighs_update.interval = jiffies_to_msecs(interval);
704}
705
706static void mlxsw_sp_router_neigh_ent_ipv4_process(struct mlxsw_sp *mlxsw_sp,
707 char *rauhtd_pl,
708 int ent_index)
709{
710 struct net_device *dev;
711 struct neighbour *n;
712 __be32 dipn;
713 u32 dip;
714 u16 rif;
715
716 mlxsw_reg_rauhtd_ent_ipv4_unpack(rauhtd_pl, ent_index, &rif, &dip);
717
718 if (!mlxsw_sp->rifs[rif]) {
719 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Incorrect RIF in neighbour entry\n");
720 return;
721 }
722
723 dipn = htonl(dip);
724 dev = mlxsw_sp->rifs[rif]->dev;
725 n = neigh_lookup(&arp_tbl, &dipn, dev);
726 if (!n) {
727 netdev_err(dev, "Failed to find matching neighbour for IP=%pI4h\n",
728 &dip);
729 return;
730 }
731
732 netdev_dbg(dev, "Updating neighbour with IP=%pI4h\n", &dip);
733 neigh_event_send(n, NULL);
734 neigh_release(n);
735}
736
737static void mlxsw_sp_router_neigh_rec_ipv4_process(struct mlxsw_sp *mlxsw_sp,
738 char *rauhtd_pl,
739 int rec_index)
740{
741 u8 num_entries;
742 int i;
743
744 num_entries = mlxsw_reg_rauhtd_ipv4_rec_num_entries_get(rauhtd_pl,
745 rec_index);
746 /* Hardware starts counting at 0, so add 1. */
747 num_entries++;
748
749 /* Each record consists of several neighbour entries. */
750 for (i = 0; i < num_entries; i++) {
751 int ent_index;
752
753 ent_index = rec_index * MLXSW_REG_RAUHTD_IPV4_ENT_PER_REC + i;
754 mlxsw_sp_router_neigh_ent_ipv4_process(mlxsw_sp, rauhtd_pl,
755 ent_index);
756 }
757
758}
759
760static void mlxsw_sp_router_neigh_rec_process(struct mlxsw_sp *mlxsw_sp,
761 char *rauhtd_pl, int rec_index)
762{
763 switch (mlxsw_reg_rauhtd_rec_type_get(rauhtd_pl, rec_index)) {
764 case MLXSW_REG_RAUHTD_TYPE_IPV4:
765 mlxsw_sp_router_neigh_rec_ipv4_process(mlxsw_sp, rauhtd_pl,
766 rec_index);
767 break;
768 case MLXSW_REG_RAUHTD_TYPE_IPV6:
769 WARN_ON_ONCE(1);
770 break;
771 }
772}
773
774static int mlxsw_sp_router_neighs_update_rauhtd(struct mlxsw_sp *mlxsw_sp)
775{
776 char *rauhtd_pl;
777 u8 num_rec;
778 int i, err;
779
780 rauhtd_pl = kmalloc(MLXSW_REG_RAUHTD_LEN, GFP_KERNEL);
781 if (!rauhtd_pl)
782 return -ENOMEM;
783
784 /* Make sure the neighbour's netdev isn't removed in the
785 * process.
786 */
787 rtnl_lock();
788 do {
789 mlxsw_reg_rauhtd_pack(rauhtd_pl, MLXSW_REG_RAUHTD_TYPE_IPV4);
790 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(rauhtd),
791 rauhtd_pl);
792 if (err) {
793 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to dump neighbour talbe\n");
794 break;
795 }
796 num_rec = mlxsw_reg_rauhtd_num_rec_get(rauhtd_pl);
797 for (i = 0; i < num_rec; i++)
798 mlxsw_sp_router_neigh_rec_process(mlxsw_sp, rauhtd_pl,
799 i);
800 } while (num_rec);
801 rtnl_unlock();
802
803 kfree(rauhtd_pl);
804 return err;
805}
806
807static void mlxsw_sp_router_neighs_update_nh(struct mlxsw_sp *mlxsw_sp)
808{
809 struct mlxsw_sp_neigh_entry *neigh_entry;
810
811 /* Take RTNL mutex here to prevent lists from changes */
812 rtnl_lock();
813 list_for_each_entry(neigh_entry, &mlxsw_sp->router.nexthop_neighs_list,
814 nexthop_neighs_list_node) {
815 /* If this neigh have nexthops, make the kernel think this neigh
816 * is active regardless of the traffic.
817 */
818 if (!list_empty(&neigh_entry->nexthop_list))
819 neigh_event_send(neigh_entry->n, NULL);
820 }
821 rtnl_unlock();
822}
823
824static void
825mlxsw_sp_router_neighs_update_work_schedule(struct mlxsw_sp *mlxsw_sp)
826{
827 unsigned long interval = mlxsw_sp->router.neighs_update.interval;
828
829 mlxsw_core_schedule_dw(&mlxsw_sp->router.neighs_update.dw,
830 msecs_to_jiffies(interval));
831}
832
833static void mlxsw_sp_router_neighs_update_work(struct work_struct *work)
834{
835 struct mlxsw_sp *mlxsw_sp = container_of(work, struct mlxsw_sp,
836 router.neighs_update.dw.work);
837 int err;
838
839 err = mlxsw_sp_router_neighs_update_rauhtd(mlxsw_sp);
840 if (err)
841 dev_err(mlxsw_sp->bus_info->dev, "Could not update kernel for neigh activity");
842
843 mlxsw_sp_router_neighs_update_nh(mlxsw_sp);
844
845 mlxsw_sp_router_neighs_update_work_schedule(mlxsw_sp);
846}
847
848static void mlxsw_sp_router_probe_unresolved_nexthops(struct work_struct *work)
849{
850 struct mlxsw_sp_neigh_entry *neigh_entry;
851 struct mlxsw_sp *mlxsw_sp = container_of(work, struct mlxsw_sp,
852 router.nexthop_probe_dw.work);
853
854 /* Iterate over nexthop neighbours, find those who are unresolved and
855 * send arp on them. This solves the chicken-egg problem when
856 * the nexthop wouldn't get offloaded until the neighbor is resolved
857 * but it wouldn't get resolved ever in case traffic is flowing in HW
858 * using different nexthop.
859 *
860 * Take RTNL mutex here to prevent lists from changes.
861 */
862 rtnl_lock();
863 list_for_each_entry(neigh_entry, &mlxsw_sp->router.nexthop_neighs_list,
864 nexthop_neighs_list_node) {
865 if (!(neigh_entry->n->nud_state & NUD_VALID) &&
866 !list_empty(&neigh_entry->nexthop_list))
867 neigh_event_send(neigh_entry->n, NULL);
868 }
869 rtnl_unlock();
870
871 mlxsw_core_schedule_dw(&mlxsw_sp->router.nexthop_probe_dw,
872 MLXSW_SP_UNRESOLVED_NH_PROBE_INTERVAL);
873}
874
875static void
876mlxsw_sp_nexthop_neigh_update(struct mlxsw_sp *mlxsw_sp,
877 struct mlxsw_sp_neigh_entry *neigh_entry,
878 bool removing);
879
880static void mlxsw_sp_router_neigh_update_hw(struct work_struct *work)
881{
882 struct mlxsw_sp_neigh_entry *neigh_entry =
883 container_of(work, struct mlxsw_sp_neigh_entry, dw.work);
884 struct neighbour *n = neigh_entry->n;
885 struct mlxsw_sp_port *mlxsw_sp_port = neigh_entry->mlxsw_sp_port;
886 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
887 char rauht_pl[MLXSW_REG_RAUHT_LEN];
888 struct net_device *dev;
889 bool entry_connected;
890 u8 nud_state;
891 bool updating;
892 bool removing;
893 bool adding;
894 u32 dip;
895 int err;
896
897 read_lock_bh(&n->lock);
898 dip = ntohl(*((__be32 *) n->primary_key));
899 memcpy(neigh_entry->ha, n->ha, sizeof(neigh_entry->ha));
900 nud_state = n->nud_state;
901 dev = n->dev;
902 read_unlock_bh(&n->lock);
903
904 entry_connected = nud_state & NUD_VALID;
905 adding = (!neigh_entry->offloaded) && entry_connected;
906 updating = neigh_entry->offloaded && entry_connected;
907 removing = neigh_entry->offloaded && !entry_connected;
908
909 if (adding || updating) {
910 mlxsw_reg_rauht_pack4(rauht_pl, MLXSW_REG_RAUHT_OP_WRITE_ADD,
911 neigh_entry->rif,
912 neigh_entry->ha, dip);
913 err = mlxsw_reg_write(mlxsw_sp->core,
914 MLXSW_REG(rauht), rauht_pl);
915 if (err) {
916 netdev_err(dev, "Could not add neigh %pI4h\n", &dip);
917 neigh_entry->offloaded = false;
918 } else {
919 neigh_entry->offloaded = true;
920 }
921 mlxsw_sp_nexthop_neigh_update(mlxsw_sp, neigh_entry, false);
922 } else if (removing) {
923 mlxsw_reg_rauht_pack4(rauht_pl, MLXSW_REG_RAUHT_OP_WRITE_DELETE,
924 neigh_entry->rif,
925 neigh_entry->ha, dip);
926 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(rauht),
927 rauht_pl);
928 if (err) {
929 netdev_err(dev, "Could not delete neigh %pI4h\n", &dip);
930 neigh_entry->offloaded = true;
931 } else {
932 neigh_entry->offloaded = false;
933 }
934 mlxsw_sp_nexthop_neigh_update(mlxsw_sp, neigh_entry, true);
935 }
936
937 neigh_release(n);
938 mlxsw_sp_port_dev_put(mlxsw_sp_port);
939}
940
941static int mlxsw_sp_router_netevent_event(struct notifier_block *unused,
942 unsigned long event, void *ptr)
943{
944 struct mlxsw_sp_neigh_entry *neigh_entry;
945 struct mlxsw_sp_port *mlxsw_sp_port;
946 struct mlxsw_sp *mlxsw_sp;
947 unsigned long interval;
948 struct net_device *dev;
949 struct neigh_parms *p;
950 struct neighbour *n;
951 u32 dip;
952
953 switch (event) {
954 case NETEVENT_DELAY_PROBE_TIME_UPDATE:
955 p = ptr;
956
957 /* We don't care about changes in the default table. */
958 if (!p->dev || p->tbl != &arp_tbl)
959 return NOTIFY_DONE;
960
961 /* We are in atomic context and can't take RTNL mutex,
962 * so use RCU variant to walk the device chain.
963 */
964 mlxsw_sp_port = mlxsw_sp_port_lower_dev_hold(p->dev);
965 if (!mlxsw_sp_port)
966 return NOTIFY_DONE;
967
968 mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
969 interval = jiffies_to_msecs(NEIGH_VAR(p, DELAY_PROBE_TIME));
970 mlxsw_sp->router.neighs_update.interval = interval;
971
972 mlxsw_sp_port_dev_put(mlxsw_sp_port);
973 break;
974 case NETEVENT_NEIGH_UPDATE:
975 n = ptr;
976 dev = n->dev;
977
978 if (n->tbl != &arp_tbl)
979 return NOTIFY_DONE;
980
981 mlxsw_sp_port = mlxsw_sp_port_lower_dev_hold(dev);
982 if (!mlxsw_sp_port)
983 return NOTIFY_DONE;
984
985 mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
986 dip = ntohl(*((__be32 *) n->primary_key));
987 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp,
988 &dip,
989 sizeof(__be32),
990 dev);
991 if (WARN_ON(!neigh_entry) || WARN_ON(neigh_entry->n != n)) {
992 mlxsw_sp_port_dev_put(mlxsw_sp_port);
993 return NOTIFY_DONE;
994 }
995 neigh_entry->mlxsw_sp_port = mlxsw_sp_port;
996
997 /* Take a reference to ensure the neighbour won't be
998 * destructed until we drop the reference in delayed
999 * work.
1000 */
1001 neigh_clone(n);
1002 if (!mlxsw_core_schedule_dw(&neigh_entry->dw, 0)) {
1003 neigh_release(n);
1004 mlxsw_sp_port_dev_put(mlxsw_sp_port);
1005 }
1006 break;
1007 }
1008
1009 return NOTIFY_DONE;
1010}
1011
1012static struct notifier_block mlxsw_sp_router_netevent_nb __read_mostly = {
1013 .notifier_call = mlxsw_sp_router_netevent_event,
1014};
1015
1016static int mlxsw_sp_neigh_init(struct mlxsw_sp *mlxsw_sp)
1017{
1018 int err;
1019
1020 err = rhashtable_init(&mlxsw_sp->router.neigh_ht,
1021 &mlxsw_sp_neigh_ht_params);
1022 if (err)
1023 return err;
1024
1025 /* Initialize the polling interval according to the default
1026 * table.
1027 */
1028 mlxsw_sp_router_neighs_update_interval_init(mlxsw_sp);
1029
1030 err = register_netevent_notifier(&mlxsw_sp_router_netevent_nb);
1031 if (err)
1032 goto err_register_netevent_notifier;
1033
1034 /* Create the delayed works for the activity_update */
1035 INIT_DELAYED_WORK(&mlxsw_sp->router.neighs_update.dw,
1036 mlxsw_sp_router_neighs_update_work);
1037 INIT_DELAYED_WORK(&mlxsw_sp->router.nexthop_probe_dw,
1038 mlxsw_sp_router_probe_unresolved_nexthops);
1039 mlxsw_core_schedule_dw(&mlxsw_sp->router.neighs_update.dw, 0);
1040 mlxsw_core_schedule_dw(&mlxsw_sp->router.nexthop_probe_dw, 0);
1041 return 0;
1042
1043err_register_netevent_notifier:
1044 rhashtable_destroy(&mlxsw_sp->router.neigh_ht);
1045 return err;
1046}
1047
1048static void mlxsw_sp_neigh_fini(struct mlxsw_sp *mlxsw_sp)
1049{
1050 cancel_delayed_work_sync(&mlxsw_sp->router.neighs_update.dw);
1051 cancel_delayed_work_sync(&mlxsw_sp->router.nexthop_probe_dw);
1052 unregister_netevent_notifier(&mlxsw_sp_router_netevent_nb);
1053 rhashtable_destroy(&mlxsw_sp->router.neigh_ht);
1054}
1055
1056struct mlxsw_sp_nexthop {
1057 struct list_head neigh_list_node; /* member of neigh entry list */
1058 struct mlxsw_sp_nexthop_group *nh_grp; /* pointer back to the group
1059 * this belongs to
1060 */
1061 u8 should_offload:1, /* set indicates this neigh is connected and
1062 * should be put to KVD linear area of this group.
1063 */
1064 offloaded:1, /* set in case the neigh is actually put into
1065 * KVD linear area of this group.
1066 */
1067 update:1; /* set indicates that MAC of this neigh should be
1068 * updated in HW
1069 */
1070 struct mlxsw_sp_neigh_entry *neigh_entry;
1071};
1072
1073struct mlxsw_sp_nexthop_group {
1074 struct list_head list; /* node in mlxsw->router.nexthop_group_list */
1075 struct list_head fib_list; /* list of fib entries that use this group */
1076 u8 adj_index_valid:1;
1077 u32 adj_index;
1078 u16 ecmp_size;
1079 u16 count;
1080 struct mlxsw_sp_nexthop nexthops[0];
1081};
1082
1083static int mlxsw_sp_adj_index_mass_update_vr(struct mlxsw_sp *mlxsw_sp,
1084 struct mlxsw_sp_vr *vr,
1085 u32 adj_index, u16 ecmp_size,
1086 u32 new_adj_index,
1087 u16 new_ecmp_size)
1088{
1089 char raleu_pl[MLXSW_REG_RALEU_LEN];
1090
1091 mlxsw_reg_raleu_pack(raleu_pl, vr->proto, vr->id,
1092 adj_index, ecmp_size,
1093 new_adj_index, new_ecmp_size);
1094 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(raleu), raleu_pl);
1095}
1096
1097static int mlxsw_sp_adj_index_mass_update(struct mlxsw_sp *mlxsw_sp,
1098 struct mlxsw_sp_nexthop_group *nh_grp,
1099 u32 old_adj_index, u16 old_ecmp_size)
1100{
1101 struct mlxsw_sp_fib_entry *fib_entry;
1102 struct mlxsw_sp_vr *vr = NULL;
1103 int err;
1104
1105 list_for_each_entry(fib_entry, &nh_grp->fib_list, nexthop_group_node) {
1106 if (vr == fib_entry->vr)
1107 continue;
1108 vr = fib_entry->vr;
1109 err = mlxsw_sp_adj_index_mass_update_vr(mlxsw_sp, vr,
1110 old_adj_index,
1111 old_ecmp_size,
1112 nh_grp->adj_index,
1113 nh_grp->ecmp_size);
1114 if (err)
1115 return err;
1116 }
1117 return 0;
1118}
1119
1120static int mlxsw_sp_nexthop_mac_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
1121 struct mlxsw_sp_nexthop *nh)
1122{
1123 struct mlxsw_sp_neigh_entry *neigh_entry = nh->neigh_entry;
1124 char ratr_pl[MLXSW_REG_RATR_LEN];
1125
1126 mlxsw_reg_ratr_pack(ratr_pl, MLXSW_REG_RATR_OP_WRITE_WRITE_ENTRY,
1127 true, adj_index, neigh_entry->rif);
1128 mlxsw_reg_ratr_eth_entry_pack(ratr_pl, neigh_entry->ha);
1129 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ratr), ratr_pl);
1130}
1131
1132static int
1133mlxsw_sp_nexthop_group_mac_update(struct mlxsw_sp *mlxsw_sp,
1134 struct mlxsw_sp_nexthop_group *nh_grp)
1135{
1136 u32 adj_index = nh_grp->adj_index; /* base */
1137 struct mlxsw_sp_nexthop *nh;
1138 int i;
1139 int err;
1140
1141 for (i = 0; i < nh_grp->count; i++) {
1142 nh = &nh_grp->nexthops[i];
1143
1144 if (!nh->should_offload) {
1145 nh->offloaded = 0;
1146 continue;
1147 }
1148
1149 if (nh->update) {
1150 err = mlxsw_sp_nexthop_mac_update(mlxsw_sp,
1151 adj_index, nh);
1152 if (err)
1153 return err;
1154 nh->update = 0;
1155 nh->offloaded = 1;
1156 }
1157 adj_index++;
1158 }
1159 return 0;
1160}
1161
1162static int mlxsw_sp_fib_entry_update(struct mlxsw_sp *mlxsw_sp,
1163 struct mlxsw_sp_fib_entry *fib_entry);
1164
1165static int
1166mlxsw_sp_nexthop_fib_entries_update(struct mlxsw_sp *mlxsw_sp,
1167 struct mlxsw_sp_nexthop_group *nh_grp)
1168{
1169 struct mlxsw_sp_fib_entry *fib_entry;
1170 int err;
1171
1172 list_for_each_entry(fib_entry, &nh_grp->fib_list, nexthop_group_node) {
1173 err = mlxsw_sp_fib_entry_update(mlxsw_sp, fib_entry);
1174 if (err)
1175 return err;
1176 }
1177 return 0;
1178}
1179
1180static void
1181mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
1182 struct mlxsw_sp_nexthop_group *nh_grp)
1183{
1184 struct mlxsw_sp_nexthop *nh;
1185 bool offload_change = false;
1186 u32 adj_index;
1187 u16 ecmp_size = 0;
1188 bool old_adj_index_valid;
1189 u32 old_adj_index;
1190 u16 old_ecmp_size;
1191 int ret;
1192 int i;
1193 int err;
1194
1195 for (i = 0; i < nh_grp->count; i++) {
1196 nh = &nh_grp->nexthops[i];
1197
1198 if (nh->should_offload ^ nh->offloaded) {
1199 offload_change = true;
1200 if (nh->should_offload)
1201 nh->update = 1;
1202 }
1203 if (nh->should_offload)
1204 ecmp_size++;
1205 }
1206 if (!offload_change) {
1207 /* Nothing was added or removed, so no need to reallocate. Just
1208 * update MAC on existing adjacency indexes.
1209 */
1210 err = mlxsw_sp_nexthop_group_mac_update(mlxsw_sp, nh_grp);
1211 if (err) {
1212 dev_warn(mlxsw_sp->bus_info->dev, "Failed to update neigh MAC in adjacency table.\n");
1213 goto set_trap;
1214 }
1215 return;
1216 }
1217 if (!ecmp_size)
1218 /* No neigh of this group is connected so we just set
1219 * the trap and let everthing flow through kernel.
1220 */
1221 goto set_trap;
1222
1223 ret = mlxsw_sp_kvdl_alloc(mlxsw_sp, ecmp_size);
1224 if (ret < 0) {
1225 /* We ran out of KVD linear space, just set the
1226 * trap and let everything flow through kernel.
1227 */
1228 dev_warn(mlxsw_sp->bus_info->dev, "Failed to allocate KVD linear area for nexthop group.\n");
1229 goto set_trap;
1230 }
1231 adj_index = ret;
1232 old_adj_index_valid = nh_grp->adj_index_valid;
1233 old_adj_index = nh_grp->adj_index;
1234 old_ecmp_size = nh_grp->ecmp_size;
1235 nh_grp->adj_index_valid = 1;
1236 nh_grp->adj_index = adj_index;
1237 nh_grp->ecmp_size = ecmp_size;
1238 err = mlxsw_sp_nexthop_group_mac_update(mlxsw_sp, nh_grp);
1239 if (err) {
1240 dev_warn(mlxsw_sp->bus_info->dev, "Failed to update neigh MAC in adjacency table.\n");
1241 goto set_trap;
1242 }
1243
1244 if (!old_adj_index_valid) {
1245 /* The trap was set for fib entries, so we have to call
1246 * fib entry update to unset it and use adjacency index.
1247 */
1248 err = mlxsw_sp_nexthop_fib_entries_update(mlxsw_sp, nh_grp);
1249 if (err) {
1250 dev_warn(mlxsw_sp->bus_info->dev, "Failed to add adjacency index to fib entries.\n");
1251 goto set_trap;
1252 }
1253 return;
1254 }
1255
1256 err = mlxsw_sp_adj_index_mass_update(mlxsw_sp, nh_grp,
1257 old_adj_index, old_ecmp_size);
1258 mlxsw_sp_kvdl_free(mlxsw_sp, old_adj_index);
1259 if (err) {
1260 dev_warn(mlxsw_sp->bus_info->dev, "Failed to mass-update adjacency index for nexthop group.\n");
1261 goto set_trap;
1262 }
1263 return;
1264
1265set_trap:
1266 old_adj_index_valid = nh_grp->adj_index_valid;
1267 nh_grp->adj_index_valid = 0;
1268 for (i = 0; i < nh_grp->count; i++) {
1269 nh = &nh_grp->nexthops[i];
1270 nh->offloaded = 0;
1271 }
1272 err = mlxsw_sp_nexthop_fib_entries_update(mlxsw_sp, nh_grp);
1273 if (err)
1274 dev_warn(mlxsw_sp->bus_info->dev, "Failed to set traps for fib entries.\n");
1275 if (old_adj_index_valid)
1276 mlxsw_sp_kvdl_free(mlxsw_sp, nh_grp->adj_index);
1277}
1278
1279static void __mlxsw_sp_nexthop_neigh_update(struct mlxsw_sp_nexthop *nh,
1280 bool removing)
1281{
1282 if (!removing && !nh->should_offload)
1283 nh->should_offload = 1;
1284 else if (removing && nh->offloaded)
1285 nh->should_offload = 0;
1286 nh->update = 1;
1287}
1288
1289static void
1290mlxsw_sp_nexthop_neigh_update(struct mlxsw_sp *mlxsw_sp,
1291 struct mlxsw_sp_neigh_entry *neigh_entry,
1292 bool removing)
1293{
1294 struct mlxsw_sp_nexthop *nh;
1295
1296 /* Take RTNL mutex here to prevent lists from changes */
1297 rtnl_lock();
1298 list_for_each_entry(nh, &neigh_entry->nexthop_list,
1299 neigh_list_node) {
1300 __mlxsw_sp_nexthop_neigh_update(nh, removing);
1301 mlxsw_sp_nexthop_group_refresh(mlxsw_sp, nh->nh_grp);
1302 }
1303 rtnl_unlock();
1304}
1305
1306static int mlxsw_sp_nexthop_init(struct mlxsw_sp *mlxsw_sp,
1307 struct mlxsw_sp_nexthop_group *nh_grp,
1308 struct mlxsw_sp_nexthop *nh,
1309 struct fib_nh *fib_nh)
1310{
1311 struct mlxsw_sp_neigh_entry *neigh_entry;
1312 u32 gwip = ntohl(fib_nh->nh_gw);
1313 struct net_device *dev = fib_nh->nh_dev;
1314 struct neighbour *n;
1315 u8 nud_state;
1316
1317 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, &gwip,
1318 sizeof(gwip), dev);
1319 if (!neigh_entry) {
1320 __be32 gwipn = htonl(gwip);
1321
1322 n = neigh_create(&arp_tbl, &gwipn, dev);
1323 if (IS_ERR(n))
1324 return PTR_ERR(n);
1325 neigh_event_send(n, NULL);
1326 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, &gwip,
1327 sizeof(gwip), dev);
1328 if (!neigh_entry) {
1329 neigh_release(n);
1330 return -EINVAL;
1331 }
1332 } else {
1333 /* Take a reference of neigh here ensuring that neigh would
1334 * not be detructed before the nexthop entry is finished.
1335 * The second branch takes the reference in neith_create()
1336 */
1337 n = neigh_entry->n;
1338 neigh_clone(n);
1339 }
1340
1341 /* If that is the first nexthop connected to that neigh, add to
1342 * nexthop_neighs_list
1343 */
1344 if (list_empty(&neigh_entry->nexthop_list))
1345 list_add_tail(&neigh_entry->nexthop_neighs_list_node,
1346 &mlxsw_sp->router.nexthop_neighs_list);
1347
1348 nh->nh_grp = nh_grp;
1349 nh->neigh_entry = neigh_entry;
1350 list_add_tail(&nh->neigh_list_node, &neigh_entry->nexthop_list);
1351 read_lock_bh(&n->lock);
1352 nud_state = n->nud_state;
1353 read_unlock_bh(&n->lock);
1354 __mlxsw_sp_nexthop_neigh_update(nh, !(nud_state & NUD_VALID));
1355
1356 return 0;
1357}
1358
1359static void mlxsw_sp_nexthop_fini(struct mlxsw_sp *mlxsw_sp,
1360 struct mlxsw_sp_nexthop *nh)
1361{
1362 struct mlxsw_sp_neigh_entry *neigh_entry = nh->neigh_entry;
1363
1364 list_del(&nh->neigh_list_node);
1365
1366 /* If that is the last nexthop connected to that neigh, remove from
1367 * nexthop_neighs_list
1368 */
1369 if (list_empty(&nh->neigh_entry->nexthop_list))
1370 list_del(&nh->neigh_entry->nexthop_neighs_list_node);
1371
1372 neigh_release(neigh_entry->n);
1373}
1374
1375static struct mlxsw_sp_nexthop_group *
1376mlxsw_sp_nexthop_group_create(struct mlxsw_sp *mlxsw_sp, struct fib_info *fi)
1377{
1378 struct mlxsw_sp_nexthop_group *nh_grp;
1379 struct mlxsw_sp_nexthop *nh;
1380 struct fib_nh *fib_nh;
1381 size_t alloc_size;
1382 int i;
1383 int err;
1384
1385 alloc_size = sizeof(*nh_grp) +
1386 fi->fib_nhs * sizeof(struct mlxsw_sp_nexthop);
1387 nh_grp = kzalloc(alloc_size, GFP_KERNEL);
1388 if (!nh_grp)
1389 return ERR_PTR(-ENOMEM);
1390 INIT_LIST_HEAD(&nh_grp->fib_list);
1391 nh_grp->count = fi->fib_nhs;
1392 for (i = 0; i < nh_grp->count; i++) {
1393 nh = &nh_grp->nexthops[i];
1394 fib_nh = &fi->fib_nh[i];
1395 err = mlxsw_sp_nexthop_init(mlxsw_sp, nh_grp, nh, fib_nh);
1396 if (err)
1397 goto err_nexthop_init;
1398 }
1399 list_add_tail(&nh_grp->list, &mlxsw_sp->router.nexthop_group_list);
1400 mlxsw_sp_nexthop_group_refresh(mlxsw_sp, nh_grp);
1401 return nh_grp;
1402
1403err_nexthop_init:
1404 for (i--; i >= 0; i--)
1405 mlxsw_sp_nexthop_fini(mlxsw_sp, nh);
1406 kfree(nh_grp);
1407 return ERR_PTR(err);
1408}
1409
1410static void
1411mlxsw_sp_nexthop_group_destroy(struct mlxsw_sp *mlxsw_sp,
1412 struct mlxsw_sp_nexthop_group *nh_grp)
1413{
1414 struct mlxsw_sp_nexthop *nh;
1415 int i;
1416
1417 list_del(&nh_grp->list);
1418 for (i = 0; i < nh_grp->count; i++) {
1419 nh = &nh_grp->nexthops[i];
1420 mlxsw_sp_nexthop_fini(mlxsw_sp, nh);
1421 }
1422 kfree(nh_grp);
1423}
1424
1425static bool mlxsw_sp_nexthop_match(struct mlxsw_sp_nexthop *nh,
1426 struct fib_info *fi)
1427{
1428 int i;
1429
1430 for (i = 0; i < fi->fib_nhs; i++) {
1431 struct fib_nh *fib_nh = &fi->fib_nh[i];
1432 u32 gwip = ntohl(fib_nh->nh_gw);
1433
1434 if (memcmp(nh->neigh_entry->key.addr,
1435 &gwip, sizeof(u32)) == 0 &&
1436 nh->neigh_entry->key.dev == fib_nh->nh_dev)
1437 return true;
1438 }
1439 return false;
1440}
1441
1442static bool mlxsw_sp_nexthop_group_match(struct mlxsw_sp_nexthop_group *nh_grp,
1443 struct fib_info *fi)
1444{
1445 int i;
1446
1447 if (nh_grp->count != fi->fib_nhs)
1448 return false;
1449 for (i = 0; i < nh_grp->count; i++) {
1450 struct mlxsw_sp_nexthop *nh = &nh_grp->nexthops[i];
1451
1452 if (!mlxsw_sp_nexthop_match(nh, fi))
1453 return false;
1454 }
1455 return true;
1456}
1457
1458static struct mlxsw_sp_nexthop_group *
1459mlxsw_sp_nexthop_group_find(struct mlxsw_sp *mlxsw_sp, struct fib_info *fi)
1460{
1461 struct mlxsw_sp_nexthop_group *nh_grp;
1462
1463 list_for_each_entry(nh_grp, &mlxsw_sp->router.nexthop_group_list,
1464 list) {
1465 if (mlxsw_sp_nexthop_group_match(nh_grp, fi))
1466 return nh_grp;
1467 }
1468 return NULL;
1469}
1470
1471static int mlxsw_sp_nexthop_group_get(struct mlxsw_sp *mlxsw_sp,
1472 struct mlxsw_sp_fib_entry *fib_entry,
1473 struct fib_info *fi)
1474{
1475 struct mlxsw_sp_nexthop_group *nh_grp;
1476
1477 nh_grp = mlxsw_sp_nexthop_group_find(mlxsw_sp, fi);
1478 if (!nh_grp) {
1479 nh_grp = mlxsw_sp_nexthop_group_create(mlxsw_sp, fi);
1480 if (IS_ERR(nh_grp))
1481 return PTR_ERR(nh_grp);
1482 }
1483 list_add_tail(&fib_entry->nexthop_group_node, &nh_grp->fib_list);
1484 fib_entry->nh_group = nh_grp;
1485 return 0;
1486}
1487
1488static void mlxsw_sp_nexthop_group_put(struct mlxsw_sp *mlxsw_sp,
1489 struct mlxsw_sp_fib_entry *fib_entry)
1490{
1491 struct mlxsw_sp_nexthop_group *nh_grp = fib_entry->nh_group;
1492
1493 list_del(&fib_entry->nexthop_group_node);
1494 if (!list_empty(&nh_grp->fib_list))
1495 return;
1496 mlxsw_sp_nexthop_group_destroy(mlxsw_sp, nh_grp);
1497}
1498
547static int __mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) 1499static int __mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
548{ 1500{
549 char rgcr_pl[MLXSW_REG_RGCR_LEN]; 1501 char rgcr_pl[MLXSW_REG_RGCR_LEN];
@@ -565,19 +1517,54 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
565{ 1517{
566 int err; 1518 int err;
567 1519
1520 INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_neighs_list);
1521 INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_group_list);
568 err = __mlxsw_sp_router_init(mlxsw_sp); 1522 err = __mlxsw_sp_router_init(mlxsw_sp);
569 if (err) 1523 if (err)
570 return err; 1524 return err;
571 mlxsw_sp_lpm_init(mlxsw_sp); 1525 mlxsw_sp_lpm_init(mlxsw_sp);
572 mlxsw_sp_vrs_init(mlxsw_sp); 1526 mlxsw_sp_vrs_init(mlxsw_sp);
573 return 0; 1527 return mlxsw_sp_neigh_init(mlxsw_sp);
574} 1528}
575 1529
576void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp) 1530void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp)
577{ 1531{
1532 mlxsw_sp_neigh_fini(mlxsw_sp);
578 __mlxsw_sp_router_fini(mlxsw_sp); 1533 __mlxsw_sp_router_fini(mlxsw_sp);
579} 1534}
580 1535
1536static int mlxsw_sp_fib_entry_op4_remote(struct mlxsw_sp *mlxsw_sp,
1537 struct mlxsw_sp_fib_entry *fib_entry,
1538 enum mlxsw_reg_ralue_op op)
1539{
1540 char ralue_pl[MLXSW_REG_RALUE_LEN];
1541 u32 *p_dip = (u32 *) fib_entry->key.addr;
1542 struct mlxsw_sp_vr *vr = fib_entry->vr;
1543 enum mlxsw_reg_ralue_trap_action trap_action;
1544 u16 trap_id = 0;
1545 u32 adjacency_index = 0;
1546 u16 ecmp_size = 0;
1547
1548 /* In case the nexthop group adjacency index is valid, use it
1549 * with provided ECMP size. Otherwise, setup trap and pass
1550 * traffic to kernel.
1551 */
1552 if (fib_entry->nh_group->adj_index_valid) {
1553 trap_action = MLXSW_REG_RALUE_TRAP_ACTION_NOP;
1554 adjacency_index = fib_entry->nh_group->adj_index;
1555 ecmp_size = fib_entry->nh_group->ecmp_size;
1556 } else {
1557 trap_action = MLXSW_REG_RALUE_TRAP_ACTION_TRAP;
1558 trap_id = MLXSW_TRAP_ID_RTR_INGRESS0;
1559 }
1560
1561 mlxsw_reg_ralue_pack4(ralue_pl, vr->proto, op, vr->id,
1562 fib_entry->key.prefix_len, *p_dip);
1563 mlxsw_reg_ralue_act_remote_pack(ralue_pl, trap_action, trap_id,
1564 adjacency_index, ecmp_size);
1565 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ralue), ralue_pl);
1566}
1567
581static int mlxsw_sp_fib_entry_op4_local(struct mlxsw_sp *mlxsw_sp, 1568static int mlxsw_sp_fib_entry_op4_local(struct mlxsw_sp *mlxsw_sp,
582 struct mlxsw_sp_fib_entry *fib_entry, 1569 struct mlxsw_sp_fib_entry *fib_entry,
583 enum mlxsw_reg_ralue_op op) 1570 enum mlxsw_reg_ralue_op op)
@@ -614,7 +1601,7 @@ static int mlxsw_sp_fib_entry_op4(struct mlxsw_sp *mlxsw_sp,
614{ 1601{
615 switch (fib_entry->type) { 1602 switch (fib_entry->type) {
616 case MLXSW_SP_FIB_ENTRY_TYPE_REMOTE: 1603 case MLXSW_SP_FIB_ENTRY_TYPE_REMOTE:
617 return -EINVAL; 1604 return mlxsw_sp_fib_entry_op4_remote(mlxsw_sp, fib_entry, op);
618 case MLXSW_SP_FIB_ENTRY_TYPE_LOCAL: 1605 case MLXSW_SP_FIB_ENTRY_TYPE_LOCAL:
619 return mlxsw_sp_fib_entry_op4_local(mlxsw_sp, fib_entry, op); 1606 return mlxsw_sp_fib_entry_op4_local(mlxsw_sp, fib_entry, op);
620 case MLXSW_SP_FIB_ENTRY_TYPE_TRAP: 1607 case MLXSW_SP_FIB_ENTRY_TYPE_TRAP:
@@ -694,7 +1681,17 @@ mlxsw_sp_router_fib4_entry_init(struct mlxsw_sp *mlxsw_sp,
694 fib_entry->rif = r->rif; 1681 fib_entry->rif = r->rif;
695 return 0; 1682 return 0;
696 } 1683 }
697 return -EINVAL; 1684 fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_REMOTE;
1685 return mlxsw_sp_nexthop_group_get(mlxsw_sp, fib_entry, fi);
1686}
1687
1688static void
1689mlxsw_sp_router_fib4_entry_fini(struct mlxsw_sp *mlxsw_sp,
1690 struct mlxsw_sp_fib_entry *fib_entry)
1691{
1692 if (fib_entry->type != MLXSW_SP_FIB_ENTRY_TYPE_REMOTE)
1693 return;
1694 mlxsw_sp_nexthop_group_put(mlxsw_sp, fib_entry);
698} 1695}
699 1696
700static int 1697static int
@@ -738,6 +1735,7 @@ mlxsw_sp_router_fib4_add_prepare(struct mlxsw_sp_port *mlxsw_sp_port,
738 return 0; 1735 return 0;
739 1736
740err_alloc_info: 1737err_alloc_info:
1738 mlxsw_sp_router_fib4_entry_fini(mlxsw_sp, fib_entry);
741err_fib4_entry_init: 1739err_fib4_entry_init:
742 mlxsw_sp_fib_entry_destroy(fib_entry); 1740 mlxsw_sp_fib_entry_destroy(fib_entry);
743err_fib_entry_create: 1741err_fib_entry_create:
@@ -772,6 +1770,7 @@ mlxsw_sp_router_fib4_add_commit(struct mlxsw_sp_port *mlxsw_sp_port,
772err_fib_entry_add: 1770err_fib_entry_add:
773 mlxsw_sp_fib_entry_remove(vr->fib, fib_entry); 1771 mlxsw_sp_fib_entry_remove(vr->fib, fib_entry);
774err_fib_entry_insert: 1772err_fib_entry_insert:
1773 mlxsw_sp_router_fib4_entry_fini(mlxsw_sp, fib_entry);
775 mlxsw_sp_fib_entry_destroy(fib_entry); 1774 mlxsw_sp_fib_entry_destroy(fib_entry);
776 mlxsw_sp_vr_put(mlxsw_sp, vr); 1775 mlxsw_sp_vr_put(mlxsw_sp, vr);
777 return err; 1776 return err;
@@ -808,6 +1807,7 @@ int mlxsw_sp_router_fib4_del(struct mlxsw_sp_port *mlxsw_sp_port,
808 } 1807 }
809 mlxsw_sp_fib_entry_del(mlxsw_sp_port->mlxsw_sp, fib_entry); 1808 mlxsw_sp_fib_entry_del(mlxsw_sp_port->mlxsw_sp, fib_entry);
810 mlxsw_sp_fib_entry_remove(vr->fib, fib_entry); 1809 mlxsw_sp_fib_entry_remove(vr->fib, fib_entry);
1810 mlxsw_sp_router_fib4_entry_fini(mlxsw_sp, fib_entry);
811 mlxsw_sp_fib_entry_destroy(fib_entry); 1811 mlxsw_sp_fib_entry_destroy(fib_entry);
812 mlxsw_sp_vr_put(mlxsw_sp, vr); 1812 mlxsw_sp_vr_put(mlxsw_sp, vr);
813 return 0; 1813 return 0;
diff --git a/drivers/net/ethernet/rocker/rocker_main.c b/drivers/net/ethernet/rocker/rocker_main.c
index 28b775e5a9ad..f0b09b05ed3f 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1996,7 +1996,8 @@ static int rocker_port_change_proto_down(struct net_device *dev,
1996 return 0; 1996 return 0;
1997} 1997}
1998 1998
1999static void rocker_port_neigh_destroy(struct neighbour *n) 1999static void rocker_port_neigh_destroy(struct net_device *dev,
2000 struct neighbour *n)
2000{ 2001{
2001 struct rocker_port *rocker_port = netdev_priv(n->dev); 2002 struct rocker_port *rocker_port = netdev_priv(n->dev);
2002 int err; 2003 int err;
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index f9eebea83516..a380649bf6b5 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -2002,6 +2002,8 @@ static const struct net_device_ops team_netdev_ops = {
2002 .ndo_add_slave = team_add_slave, 2002 .ndo_add_slave = team_add_slave,
2003 .ndo_del_slave = team_del_slave, 2003 .ndo_del_slave = team_del_slave,
2004 .ndo_fix_features = team_fix_features, 2004 .ndo_fix_features = team_fix_features,
2005 .ndo_neigh_construct = netdev_default_l2upper_neigh_construct,
2006 .ndo_neigh_destroy = netdev_default_l2upper_neigh_destroy,
2005 .ndo_change_carrier = team_change_carrier, 2007 .ndo_change_carrier = team_change_carrier,
2006 .ndo_bridge_setlink = switchdev_port_bridge_setlink, 2008 .ndo_bridge_setlink = switchdev_port_bridge_setlink,
2007 .ndo_bridge_getlink = switchdev_port_bridge_getlink, 2009 .ndo_bridge_getlink = switchdev_port_bridge_getlink,
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 0c6ee2c5099f..49736a31acaa 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1209,8 +1209,10 @@ struct net_device_ops {
1209 netdev_features_t features); 1209 netdev_features_t features);
1210 int (*ndo_set_features)(struct net_device *dev, 1210 int (*ndo_set_features)(struct net_device *dev,
1211 netdev_features_t features); 1211 netdev_features_t features);
1212 int (*ndo_neigh_construct)(struct neighbour *n); 1212 int (*ndo_neigh_construct)(struct net_device *dev,
1213 void (*ndo_neigh_destroy)(struct neighbour *n); 1213 struct neighbour *n);
1214 void (*ndo_neigh_destroy)(struct net_device *dev,
1215 struct neighbour *n);
1214 1216
1215 int (*ndo_fdb_add)(struct ndmsg *ndm, 1217 int (*ndo_fdb_add)(struct ndmsg *ndm,
1216 struct nlattr *tb[], 1218 struct nlattr *tb[],
@@ -3843,6 +3845,10 @@ void *netdev_lower_dev_get_private(struct net_device *dev,
3843 struct net_device *lower_dev); 3845 struct net_device *lower_dev);
3844void netdev_lower_state_changed(struct net_device *lower_dev, 3846void netdev_lower_state_changed(struct net_device *lower_dev,
3845 void *lower_state_info); 3847 void *lower_state_info);
3848int netdev_default_l2upper_neigh_construct(struct net_device *dev,
3849 struct neighbour *n);
3850void netdev_default_l2upper_neigh_destroy(struct net_device *dev,
3851 struct neighbour *n);
3846 3852
3847/* RSS keys are 40 or 52 bytes long */ 3853/* RSS keys are 40 or 52 bytes long */
3848#define NETDEV_RSS_KEY_LEN 52 3854#define NETDEV_RSS_KEY_LEN 52
diff --git a/include/net/netevent.h b/include/net/netevent.h
index d8bbb38584b6..f440df172b56 100644
--- a/include/net/netevent.h
+++ b/include/net/netevent.h
@@ -24,6 +24,7 @@ struct netevent_redirect {
24enum netevent_notif_type { 24enum netevent_notif_type {
25 NETEVENT_NEIGH_UPDATE = 1, /* arg is struct neighbour ptr */ 25 NETEVENT_NEIGH_UPDATE = 1, /* arg is struct neighbour ptr */
26 NETEVENT_REDIRECT, /* arg is struct netevent_redirect ptr */ 26 NETEVENT_REDIRECT, /* arg is struct netevent_redirect ptr */
27 NETEVENT_DELAY_PROBE_TIME_UPDATE, /* arg is struct neigh_parms ptr */
27}; 28};
28 29
29int register_netevent_notifier(struct notifier_block *nb); 30int register_netevent_notifier(struct notifier_block *nb);
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 86ae75b77390..c8f422c90856 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -790,6 +790,8 @@ static const struct net_device_ops vlan_netdev_ops = {
790 .ndo_netpoll_cleanup = vlan_dev_netpoll_cleanup, 790 .ndo_netpoll_cleanup = vlan_dev_netpoll_cleanup,
791#endif 791#endif
792 .ndo_fix_features = vlan_dev_fix_features, 792 .ndo_fix_features = vlan_dev_fix_features,
793 .ndo_neigh_construct = netdev_default_l2upper_neigh_construct,
794 .ndo_neigh_destroy = netdev_default_l2upper_neigh_destroy,
793 .ndo_fdb_add = switchdev_port_fdb_add, 795 .ndo_fdb_add = switchdev_port_fdb_add,
794 .ndo_fdb_del = switchdev_port_fdb_del, 796 .ndo_fdb_del = switchdev_port_fdb_del,
795 .ndo_fdb_dump = switchdev_port_fdb_dump, 797 .ndo_fdb_dump = switchdev_port_fdb_dump,
diff --git a/net/atm/clip.c b/net/atm/clip.c
index e07f551a863c..53b4ac09e7b7 100644
--- a/net/atm/clip.c
+++ b/net/atm/clip.c
@@ -286,7 +286,7 @@ static const struct neigh_ops clip_neigh_ops = {
286 .connected_output = neigh_direct_output, 286 .connected_output = neigh_direct_output,
287}; 287};
288 288
289static int clip_constructor(struct neighbour *neigh) 289static int clip_constructor(struct net_device *dev, struct neighbour *neigh)
290{ 290{
291 struct atmarp_entry *entry = neighbour_priv(neigh); 291 struct atmarp_entry *entry = neighbour_priv(neigh);
292 292
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 0c39e0f6da09..8eecd0ec22f2 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -349,6 +349,8 @@ static const struct net_device_ops br_netdev_ops = {
349 .ndo_add_slave = br_add_slave, 349 .ndo_add_slave = br_add_slave,
350 .ndo_del_slave = br_del_slave, 350 .ndo_del_slave = br_del_slave,
351 .ndo_fix_features = br_fix_features, 351 .ndo_fix_features = br_fix_features,
352 .ndo_neigh_construct = netdev_default_l2upper_neigh_construct,
353 .ndo_neigh_destroy = netdev_default_l2upper_neigh_destroy,
352 .ndo_fdb_add = br_fdb_add, 354 .ndo_fdb_add = br_fdb_add,
353 .ndo_fdb_del = br_fdb_delete, 355 .ndo_fdb_del = br_fdb_delete,
354 .ndo_fdb_dump = br_fdb_dump, 356 .ndo_fdb_dump = br_fdb_dump,
diff --git a/net/core/dev.c b/net/core/dev.c
index a4f3b0a9aeaf..b92d63bfde7a 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6087,6 +6087,50 @@ void netdev_lower_state_changed(struct net_device *lower_dev,
6087} 6087}
6088EXPORT_SYMBOL(netdev_lower_state_changed); 6088EXPORT_SYMBOL(netdev_lower_state_changed);
6089 6089
6090int netdev_default_l2upper_neigh_construct(struct net_device *dev,
6091 struct neighbour *n)
6092{
6093 struct net_device *lower_dev, *stop_dev;
6094 struct list_head *iter;
6095 int err;
6096
6097 netdev_for_each_lower_dev(dev, lower_dev, iter) {
6098 if (!lower_dev->netdev_ops->ndo_neigh_construct)
6099 continue;
6100 err = lower_dev->netdev_ops->ndo_neigh_construct(lower_dev, n);
6101 if (err) {
6102 stop_dev = lower_dev;
6103 goto rollback;
6104 }
6105 }
6106 return 0;
6107
6108rollback:
6109 netdev_for_each_lower_dev(dev, lower_dev, iter) {
6110 if (lower_dev == stop_dev)
6111 break;
6112 if (!lower_dev->netdev_ops->ndo_neigh_destroy)
6113 continue;
6114 lower_dev->netdev_ops->ndo_neigh_destroy(lower_dev, n);
6115 }
6116 return err;
6117}
6118EXPORT_SYMBOL_GPL(netdev_default_l2upper_neigh_construct);
6119
6120void netdev_default_l2upper_neigh_destroy(struct net_device *dev,
6121 struct neighbour *n)
6122{
6123 struct net_device *lower_dev;
6124 struct list_head *iter;
6125
6126 netdev_for_each_lower_dev(dev, lower_dev, iter) {
6127 if (!lower_dev->netdev_ops->ndo_neigh_destroy)
6128 continue;
6129 lower_dev->netdev_ops->ndo_neigh_destroy(lower_dev, n);
6130 }
6131}
6132EXPORT_SYMBOL_GPL(netdev_default_l2upper_neigh_destroy);
6133
6090static void dev_change_rx_flags(struct net_device *dev, int flags) 6134static void dev_change_rx_flags(struct net_device *dev, int flags)
6091{ 6135{
6092 const struct net_device_ops *ops = dev->netdev_ops; 6136 const struct net_device_ops *ops = dev->netdev_ops;
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 510cd62fcb99..5cdc62a8eb84 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -473,7 +473,7 @@ struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
473 } 473 }
474 474
475 if (dev->netdev_ops->ndo_neigh_construct) { 475 if (dev->netdev_ops->ndo_neigh_construct) {
476 error = dev->netdev_ops->ndo_neigh_construct(n); 476 error = dev->netdev_ops->ndo_neigh_construct(dev, n);
477 if (error < 0) { 477 if (error < 0) {
478 rc = ERR_PTR(error); 478 rc = ERR_PTR(error);
479 goto out_neigh_release; 479 goto out_neigh_release;
@@ -701,7 +701,7 @@ void neigh_destroy(struct neighbour *neigh)
701 neigh->arp_queue_len_bytes = 0; 701 neigh->arp_queue_len_bytes = 0;
702 702
703 if (dev->netdev_ops->ndo_neigh_destroy) 703 if (dev->netdev_ops->ndo_neigh_destroy)
704 dev->netdev_ops->ndo_neigh_destroy(neigh); 704 dev->netdev_ops->ndo_neigh_destroy(dev, neigh);
705 705
706 dev_put(dev); 706 dev_put(dev);
707 neigh_parms_put(neigh->parms); 707 neigh_parms_put(neigh->parms);
@@ -2047,6 +2047,7 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh)
2047 case NDTPA_DELAY_PROBE_TIME: 2047 case NDTPA_DELAY_PROBE_TIME:
2048 NEIGH_VAR_SET(p, DELAY_PROBE_TIME, 2048 NEIGH_VAR_SET(p, DELAY_PROBE_TIME,
2049 nla_get_msecs(tbp[i])); 2049 nla_get_msecs(tbp[i]));
2050 call_netevent_notifiers(NETEVENT_DELAY_PROBE_TIME_UPDATE, p);
2050 break; 2051 break;
2051 case NDTPA_RETRANS_TIME: 2052 case NDTPA_RETRANS_TIME:
2052 NEIGH_VAR_SET(p, RETRANS_TIME, 2053 NEIGH_VAR_SET(p, RETRANS_TIME,
@@ -2930,6 +2931,7 @@ static void neigh_proc_update(struct ctl_table *ctl, int write)
2930 return; 2931 return;
2931 2932
2932 set_bit(index, p->data_state); 2933 set_bit(index, p->data_state);
2934 call_netevent_notifiers(NETEVENT_DELAY_PROBE_TIME_UPDATE, p);
2933 if (!dev) /* NULL dev means this is default value */ 2935 if (!dev) /* NULL dev means this is default value */
2934 neigh_copy_dflt_parms(net, p, index); 2936 neigh_copy_dflt_parms(net, p, index);
2935} 2937}
diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c
index 8c004a0c8d64..935ab932e841 100644
--- a/net/ieee802154/6lowpan/core.c
+++ b/net/ieee802154/6lowpan/core.c
@@ -81,7 +81,7 @@ static int lowpan_stop(struct net_device *dev)
81 return 0; 81 return 0;
82} 82}
83 83
84static int lowpan_neigh_construct(struct neighbour *n) 84static int lowpan_neigh_construct(struct net_device *dev, struct neighbour *n)
85{ 85{
86 struct lowpan_802154_neigh *neigh = lowpan_802154_neigh(neighbour_priv(n)); 86 struct lowpan_802154_neigh *neigh = lowpan_802154_neigh(neighbour_priv(n));
87 87