From patchwork Thu Feb 9 09:28:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 726010 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vJtKc4WPNz9s7H for ; Thu, 9 Feb 2017 20:37:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b="A1WTdVZo"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752626AbdBIJhu (ORCPT ); Thu, 9 Feb 2017 04:37:50 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33300 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752225AbdBIJhs (ORCPT ); Thu, 9 Feb 2017 04:37:48 -0500 Received: by mail-wm0-f65.google.com with SMTP id v77so1946980wmv.0 for ; Thu, 09 Feb 2017 01:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ayitIlhRLO+XY/w2X140pypJTCq3kIuDXJsGNwE5UAU=; b=A1WTdVZoSKxyFKZWE/FTvtvdi64GkNjEc/3rN7ayPoVCswhsJseHutBuf2opfCtvpw 8bwKT4z5KA0uOJyhs99d6o5AtZBR23PpnoSYE/5VgPnCQHMRTY3e1Ucs1mShpBP+Juem UeuFgivFNoypITnmGn5xrGpruRPk+Eg6pFIMi563lW2GPN9r9pME5CEkYkQFkF4OPx05 E4O6SK9yckrPIiGFfxv3m84ouwzJ1nt/jVUHP2aclZyJD5tqFOmWLmBdCbAHqA+jHPXP ydrjMlvAs+QJ1zrSh/E63NwNdVvnNQaS/r8d9yhBmCN8sjXrH03owYbWBj0coEcE9ReO qQvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ayitIlhRLO+XY/w2X140pypJTCq3kIuDXJsGNwE5UAU=; b=LIs/FPWS8jYTb30v9jC6kFxPmu1R7b4lxxXsf9t7S2Qf59rY/vzAfRMxGWQUdEv6k/ Xp+aqwJ5JS8smHZFBBvTbqqcMQJDygwQuvaTdo5mSjaTfVMui7uTYX3wHFWXInLFIHtk e+gF7g5f+xp+0gjwIz36BdT5fPDC10UIc11XM0aHp7+UmZJzdHKVEQQF7iwor0my7DxP WmaZCMpNaHBb2bEOLhaJaPWmmVLzPMsBpmsadiX3RJ7wyGjUBC6PEvx6A1itSHt9Tfaa o7DO0CKg4R222C9diMrz+E2d5A43aGhnUpH0LC5gPTLECM67wIsMxbTPTYR54q44vWrK tJ4Q== X-Gm-Message-State: AMke39n1wnwqZG3gIGRI8XCYFJ+/pdsqhv4y93JczmfRPAO6NshtSRT+SWLoetCeTbO9ng== X-Received: by 10.28.74.69 with SMTP id x66mr1899459wma.124.1486632534148; Thu, 09 Feb 2017 01:28:54 -0800 (PST) Received: from localhost (ip-78-45-162-92.net.upcbroadband.cz. [78.45.162.92]) by smtp.gmail.com with ESMTPSA id l37sm17474010wrc.41.2017.02.09.01.28.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Feb 2017 01:28:53 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, idosch@mellanox.com, eladr@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next 7/7] mlxsw: spectrum_router: Add support for route replace Date: Thu, 9 Feb 2017 10:28:44 +0100 Message-Id: <1486632524-5588-8-git-send-email-jiri@resnulli.us> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486632524-5588-1-git-send-email-jiri@resnulli.us> References: <1486632524-5588-1-git-send-email-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel Upon the reception of an ENTRY_REPLACE notification, resolve the FIB node corresponding to the prefix and length and insert the new route before the first matching entry. Since the notification also signals the deletion of the replaced route, delete it from the driver's cache. Signed-off-by: Ido Schimmel Signed-off-by: Jiri Pirko --- .../net/ethernet/mellanox/mlxsw/spectrum_router.c | 44 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index d98f039..d7ac22d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -2128,7 +2128,7 @@ static int mlxsw_sp_fib4_node_list_append(struct mlxsw_sp_fib_entry *fib_entry, static int mlxsw_sp_fib4_node_list_insert(struct mlxsw_sp_fib_node *fib_node, struct mlxsw_sp_fib_entry *new_entry, - bool append) + bool replace, bool append) { struct mlxsw_sp_fib_entry *fib_entry; @@ -2136,7 +2136,12 @@ mlxsw_sp_fib4_node_list_insert(struct mlxsw_sp_fib_node *fib_node, if (append) return mlxsw_sp_fib4_node_list_append(fib_entry, new_entry); + if (replace && WARN_ON(!fib_entry)) + return -EINVAL; + /* Insert new entry before replaced one, so that we can later + * remove the second. + */ if (fib_entry) { list_add_tail(&new_entry->list, &fib_entry->list); } else { @@ -2207,12 +2212,13 @@ mlxsw_sp_fib4_node_entry_del(struct mlxsw_sp *mlxsw_sp, static int mlxsw_sp_fib4_node_entry_link(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fib_entry *fib_entry, - bool append) + bool replace, bool append) { struct mlxsw_sp_fib_node *fib_node = fib_entry->fib_node; int err; - err = mlxsw_sp_fib4_node_list_insert(fib_node, fib_entry, append); + err = mlxsw_sp_fib4_node_list_insert(fib_node, fib_entry, replace, + append); if (err) return err; @@ -2240,10 +2246,28 @@ mlxsw_sp_fib4_node_entry_unlink(struct mlxsw_sp *mlxsw_sp, mlxsw_sp_fib4_node_list_remove(fib_entry); } +static void mlxsw_sp_fib4_entry_replace(struct mlxsw_sp *mlxsw_sp, + struct mlxsw_sp_fib_entry *fib_entry, + bool replace) +{ + struct mlxsw_sp_fib_node *fib_node = fib_entry->fib_node; + struct mlxsw_sp_fib_entry *replaced; + + if (!replace) + return; + + /* We inserted the new entry before replaced one */ + replaced = list_next_entry(fib_entry, list); + + mlxsw_sp_fib4_node_entry_unlink(mlxsw_sp, replaced); + mlxsw_sp_fib4_entry_destroy(mlxsw_sp, replaced); + mlxsw_sp_fib4_node_put(mlxsw_sp, fib_node); +} + static int mlxsw_sp_router_fib4_add(struct mlxsw_sp *mlxsw_sp, const struct fib_entry_notifier_info *fen_info, - bool append) + bool replace, bool append) { struct mlxsw_sp_fib_entry *fib_entry; struct mlxsw_sp_fib_node *fib_node; @@ -2265,12 +2289,15 @@ mlxsw_sp_router_fib4_add(struct mlxsw_sp *mlxsw_sp, goto err_fib4_entry_create; } - err = mlxsw_sp_fib4_node_entry_link(mlxsw_sp, fib_entry, append); + err = mlxsw_sp_fib4_node_entry_link(mlxsw_sp, fib_entry, replace, + append); if (err) { dev_warn(mlxsw_sp->bus_info->dev, "Failed to link FIB entry to node\n"); goto err_fib4_node_entry_link; } + mlxsw_sp_fib4_entry_replace(mlxsw_sp, fib_entry, replace); + return 0; err_fib4_node_entry_link: @@ -2479,17 +2506,19 @@ static void mlxsw_sp_router_fib_event_work(struct work_struct *work) struct mlxsw_sp_fib_event_work *fib_work = container_of(work, struct mlxsw_sp_fib_event_work, work); struct mlxsw_sp *mlxsw_sp = fib_work->mlxsw_sp; - bool append; + bool replace, append; int err; /* Protect internal structures from changes */ rtnl_lock(); switch (fib_work->event) { + case FIB_EVENT_ENTRY_REPLACE: /* fall through */ case FIB_EVENT_ENTRY_APPEND: /* fall through */ case FIB_EVENT_ENTRY_ADD: + replace = fib_work->event == FIB_EVENT_ENTRY_REPLACE; append = fib_work->event == FIB_EVENT_ENTRY_APPEND; err = mlxsw_sp_router_fib4_add(mlxsw_sp, &fib_work->fen_info, - append); + replace, append); if (err) mlxsw_sp_router_fib4_abort(mlxsw_sp); fib_info_put(fib_work->fen_info.fi); @@ -2533,6 +2562,7 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb, fib_work->event = event; switch (event) { + case FIB_EVENT_ENTRY_REPLACE: /* fall through */ case FIB_EVENT_ENTRY_APPEND: /* fall through */ case FIB_EVENT_ENTRY_ADD: /* fall through */ case FIB_EVENT_ENTRY_DEL: