From patchwork Thu Feb 11 19:05:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 8284561 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 249479F38B for ; Thu, 11 Feb 2016 19:05:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1590A20222 for ; Thu, 11 Feb 2016 19:05:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA17220121 for ; Thu, 11 Feb 2016 19:05:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750993AbcBKTFo (ORCPT ); Thu, 11 Feb 2016 14:05:44 -0500 Received: from mail-bn1bon0079.outbound.protection.outlook.com ([157.56.111.79]:18451 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750974AbcBKTFm (ORCPT ); Thu, 11 Feb 2016 14:05:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sandiskcorp.onmicrosoft.com; s=selector1-sandisk-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=l41NFLURXiyzNGCw5D/aMgDpdfVjvuifQO88EXPsAOs=; b=PFq5xdGmSoNFjSVhevr7Hn/fdjeQJr7AYbKufRXkKd4HWj/S7WuaU8i0s8otViqhlAeOT4u6F6bSTy8N0ZAETlUsC9T5uRUJPxTgJ/gjvvLOjxAq9xyMnv1IjVdzhTmmnOrKDxNcl2z5koBXCPBTjOJp4ck9SaQrprhGMSToVJI= Received: from BN1PR02CA0038.namprd02.prod.outlook.com (10.141.56.38) by BN1PR0201MB0820.namprd02.prod.outlook.com (10.160.170.152) with Microsoft SMTP Server (TLS) id 15.1.403.16; Thu, 11 Feb 2016 19:05:40 +0000 Received: from BN1BFFO11FD017.protection.gbl (2a01:111:f400:7c10::1:158) by BN1PR02CA0038.outlook.office365.com (2a01:111:e400:2a::38) with Microsoft SMTP Server (TLS) id 15.1.403.16 via Frontend Transport; Thu, 11 Feb 2016 19:05:40 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.174) smtp.mailfrom=sandisk.com; intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.174 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.174; helo=milsmgep12.sandisk.com; Received: from milsmgep12.sandisk.com (63.163.107.174) by BN1BFFO11FD017.mail.protection.outlook.com (10.58.144.80) with Microsoft SMTP Server id 15.1.415.6 via Frontend Transport; Thu, 11 Feb 2016 19:05:39 +0000 Received: from MILHUBIP04.sdcorp.global.sandisk.com ( [172.22.12.162]) by (Symantec Messaging Gateway) with SMTP id AA.2E.03682.38BDCB65; Thu, 11 Feb 2016 11:05:39 -0800 (PST) Received: from milsmgip12.sandisk.com (10.177.8.100) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.248.2; Thu, 11 Feb 2016 11:05:38 -0800 X-AuditID: ac160a69-d23ff70000000e62-98-56bcdb837924 Received: from [10.60.52.49] ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id D4.83.03361.28BDCB65; Thu, 11 Feb 2016 11:05:38 -0800 (PST) Subject: [PATCH v4 08/21] IB/srpt: Simplify channel state management To: Doug Ledford References: <56BCDAAD.7030906@sandisk.com> CC: Christoph Hellwig , Sagi Grimberg , "Alex Estrin" , "linux-rdma@vger.kernel.org" From: Bart Van Assche Message-ID: <56BCDB82.9070804@sandisk.com> Date: Thu, 11 Feb 2016 11:05:38 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <56BCDAAD.7030906@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGLMWRmVeSWpSXmKPExsWyRoxnkW7z7T1hBrvOi1hcePqdyeLl+Q+s FitXH2WyeHaol8XiRtsDNgdWj8V7XjJ57L7ZwObxbPphJo/3+66yeXzeJBfAGsVlk5Kak1mW WqRvl8CVcf/HItaCbumK5ROPMTUwLhbrYuTkkBAwkXg2dxNzFyMXh5DAJkaJtRs2s0I4Oxgl untes8FUHbz7mAUiMYdR4sUDkCpODmEBF4nnq+4wg9giAmoSm14tYgexhQS0JJ7394NNYhZY xSix6ep1sASbgJHEt/czgSZxcPACFX08EgcSZhFQlTg+7zUTiC0qECFxuLMLrJxXQFDi5Mwn YOWcAtoSM69EgJjMApoS63fpg1QwC8hLbH87B+wBCYGDrBJzVk1hgThBXeLkkvlMExiFZyGZ NAuhfRaS9gWMzKsYxXIzc4pz01MLDI30ihPzUjKLs/WS83M3MYJjgytzB+OKSeaHGAU4GJV4 eA1u7QkTYk0sK67MPcQowcGsJMJ7fxNQiDclsbIqtSg/vqg0J7X4EKM0B4uSOK91i1qYkEB6 YklqdmpqQWoRTJaJg1OqgVHr7tUdmyakeXp+z7tZw1KeUXHi3WKG4otdF59c2Tx3d6ah66Rp sjqu9eub/N6JBp2Lcv4nY+Mg9orFWDnnT+HHxLIP/7xqJT299Ztcb27y2F3BV9ijO3vf9+qi +MMhS37d/H/p8E9brYVMId80hFjuBWd77mq+ZTJv/WHL1TzvpnLnPa3KZFZiKc5INNRiLipO BABTG3CJiQIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLJMWRmVeSWpSXmKPExsXCtZEjRbfp9p4wg227TCwuPP3OZPHy/AdW i5WrjzJZPDvUy2Jxo+0BmwOrx+I9L5k8dt9sYPN4Nv0wk8f7fVfZPD5vkgtgj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Nx1+HivIDoyuBv X-Forefront-Antispam-Report: CIP:63.163.107.174; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(3190300001)(199003)(189002)(2950100001)(80316001)(54356999)(5008740100001)(92566002)(50986999)(33656002)(87266999)(19580405001)(19580395003)(4001350100001)(5001960100002)(76176999)(189998001)(11100500001)(59896002)(77096005)(65816999)(83506001)(87936001)(106466001)(230700001)(2906002)(50466002)(36756003)(586003)(1096002)(65806001)(4326007)(1220700001)(229853001)(65956001)(86362001)(47776003)(23676002)(64126003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0201MB0820; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0201MB0820; 2:3PC3sOTqyK+wTNhKKgXjljgDrYhxrU3ZEhCVNtHLDNDnLsmxsNcAcBwO8PqYj3vzZG3nqY6y6Oh3laqJbSNONlkdo67UuLrntMDHKuQfpFbP5CMsP5Kr1DEVwXNQAyyZYy19N/cioo/PIsX76yU0Ow==; 3:NRhZajkdMx3XVjWnaWeloROgcTX6u9mUjd726cxC42BVX2kR9mY0BVgEuGZsqfklDmOTWaMn9kqOUsWT6CDUI8ex3wtSQ8IOYzDtLti1iyX6/gitdByarKzF9sb4i2TjBJ7h/dvmWz2brwcL+XksCtBAParS1IBHOCNb2Z3kgiHzVUeMCX/JHwkJvIIbboDHOoDbTqKiraTmQ9IKSqQGMJ7vBAIzZcyePVex+r5O0A6RWA9+CYbPHZS75yIHgkdj6pPnn+ob7IH6VIJ2rUHlzw==; 25:9PIEcuTMRTIZ0d5D4AO43ZEReOD2apOypbQHm4Xhy+JR+ZebKVAn/zIuyh5Vxifd0YSUEh8QZ/tOPg7R5/hnQDYA8aTvzmRwhAElmEXSuCgc0enybCLXw0dwJMvJOVB/XWS8unmArXObhaiEV9ZE83BjTStnbKDM77saASR2Qqd1MlAyc9z6bc8Z3ZbV4Gln+EVae+pydu/+UjerT9KybOh+TmP+rdheKZSSdmewUvsOMk621PAQ+utFPpYiVqvrDMM6SPNtKjZaatFOAvsPaCGch4Ah0QU6o1GxU8959LFm+mXzlLujMnNN7ASHBP6R X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501001); SRVR:BN1PR0201MB0820; X-MS-Office365-Filtering-Correlation-Id: bb2557ee-1f85-415c-74e3-08d333165518 X-Microsoft-Exchange-Diagnostics: 1; BN1PR0201MB0820; 20:n263S3pPLqmDZ1p2nSga90vvtfoIMXNQkCvcFTCnYxF0ZR7r23cB6/Pm6ZqHITN+aLKlTzyrUsIRumhdPVASUxuM2ZRqjm87xza8qXJk2MvqJAcDm4tWvhzuk9kUAg+DOd2KbzIv967TNHp79D8wARXUgf/Dwte+s7NmdJDlbtAraueKttyCoQ+YtHLQhZ72LT1JOJCXcODXfgAvR/MVJa3KDO+clx17cQqbhRK/u7Ma3UDGQtz6lFCsPnyiW+N+YhaRRgUKPvSWGUx+2Kg0n3scM+5pGj4hmzWhqYUoxzQjGvB97Mg+woFlmWhLQWGbtJPO6m7r0R8PJTuH9smS6xmTJ5SGSYlfhfITA7IOPOoYefFoVZaZQLnHMIn+aUUVfazCrtXA+Y+keEXwpjClEkzLEuNL+oYzs7KfNqhpXoKfsjO2RXmFeDvxnDEdqw+h1Uco0O+4mTU/HmasDvgnSnfIT2ZIholTIxKALA4CERYzUhsIydXUHZ0nFuT74KfD X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13015025)(5005006)(13017025)(8121501046)(13023025)(13018025)(13024025)(3002001)(10201501046); SRVR:BN1PR0201MB0820; BCL:0; PCL:0; RULEID:; SRVR:BN1PR0201MB0820; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0201MB0820; 4:DVzxCxMDIuHac3RF8EkERvslouDfMaVtgOA/gh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GMlFycjJ1MldqRzlDWXNR?= =?utf-8?B?TnpHK2VlUUgwWTF2aTA2cTQrTS9za3FTc3hyMml5dERBN3J2QXBFdmlTcmdF?= =?utf-8?B?eEJIRTVlTHZLQVJJNXMvaWtaVm1Qa2U4dURYZ3Iwditxb0xSNCtTWWsvS2dK?= =?utf-8?B?Y0w4WlFBPT0=?= X-Microsoft-Exchange-Diagnostics: 1; BN1PR0201MB0820; 5:0kcJS7g5+BUEoEyVZe/Vq5tp10p5uuC6jbttm5Y0absI9X6Mm9QSjKuA/uMsSx+iShIQGrNj6DYZzeWK+mbo13s697aFvrvsqftCNZskSObKKy8eq/Z7+V361LYjZfR1F73wR/cuWfzjYzaCT1oLMw==; 24:l/Jmsi7CtPExI4ilNEi+2pBNWctFwRPkAztt67RK/L2IoE4wG5onIXXj6AFFXOGDNii8tmF32aEmczi/4/dUjvbD+L88ZMsVWfENxl6eQPk=; 20:nh312l4XerORky+unFSwqF2GYF6EeEbHtFniUtXfWUbvAWKZHa2FFMHAAAjeCK9z9Wf3167Orw71+b/CChQZfciP6RDKgUdqNDgzGV9s50vPFvuUSWb7eEW5BMx1NtCk9vtsVPlDKUxLojBcz4Lmg0G2rEPnn29NAlja46fT2gCIw/lVJc4x1kvKurcXY1+v/Cfn5SMFmHvC3a5ephnXa54CsyezBBU+gOqBjqEsJr/JcXJdpaHQhzY0lXLsFjxl SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2016 19:05:39.3875 (UTC) X-MS-Exchange-CrossTenant-Id: fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d; Ip=[63.163.107.174]; Helo=[milsmgep12.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR0201MB0820 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The only allowed channel state changes are those that change the channel state into a state with a higher numerical value. This allows to merge the functions srpt_set_ch_state() and srpt_test_and_set_ch_state() into a single function. Signed-off-by: Bart Van Assche Reviewed-by: Christoph Hellwig Reviewed-by: Sagi Grimberg Cc: Alex Estrin --- drivers/infiniband/ulp/srpt/ib_srpt.c | 44 +++++++++++------------------------ 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index 716f429..863fdd1 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -96,37 +96,25 @@ static int srpt_queue_status(struct se_cmd *cmd); static void srpt_recv_done(struct ib_cq *cq, struct ib_wc *wc); static void srpt_send_done(struct ib_cq *cq, struct ib_wc *wc); -static enum rdma_ch_state -srpt_set_ch_state(struct srpt_rdma_ch *ch, enum rdma_ch_state new_state) -{ - unsigned long flags; - enum rdma_ch_state prev; - - spin_lock_irqsave(&ch->spinlock, flags); - prev = ch->state; - ch->state = new_state; - spin_unlock_irqrestore(&ch->spinlock, flags); - return prev; -} - -/** - * srpt_test_and_set_ch_state() - Test and set the channel state. - * - * Returns true if and only if the channel state has been set to the new state. +/* + * The only allowed channel state changes are those that change the channel + * state into a state with a higher numerical value. Hence the new > prev test. */ -static bool -srpt_test_and_set_ch_state(struct srpt_rdma_ch *ch, enum rdma_ch_state old, - enum rdma_ch_state new) +static bool srpt_set_ch_state(struct srpt_rdma_ch *ch, enum rdma_ch_state new) { unsigned long flags; enum rdma_ch_state prev; + bool changed = false; spin_lock_irqsave(&ch->spinlock, flags); prev = ch->state; - if (prev == old) + if (new > prev) { ch->state = new; + changed = true; + } spin_unlock_irqrestore(&ch->spinlock, flags); - return prev == old; + + return changed; } /** @@ -199,8 +187,7 @@ static void srpt_qp_event(struct ib_event *event, struct srpt_rdma_ch *ch) ib_cm_notify(ch->cm_id, event->event); break; case IB_EVENT_QP_LAST_WQE_REACHED: - if (srpt_test_and_set_ch_state(ch, CH_DRAINING, - CH_RELEASING)) + if (srpt_set_ch_state(ch, CH_RELEASING)) srpt_release_channel(ch); else pr_debug("%s: state %d - ignored LAST_WQE.\n", @@ -1947,12 +1934,7 @@ static void srpt_drain_channel(struct ib_cm_id *cm_id) spin_lock_irq(&sdev->spinlock); list_for_each_entry(ch, &sdev->rch_list, list) { if (ch->cm_id == cm_id) { - do_reset = srpt_test_and_set_ch_state(ch, - CH_CONNECTING, CH_DRAINING) || - srpt_test_and_set_ch_state(ch, - CH_LIVE, CH_DRAINING) || - srpt_test_and_set_ch_state(ch, - CH_DISCONNECTING, CH_DRAINING); + do_reset = srpt_set_ch_state(ch, CH_DRAINING); break; } } @@ -2353,7 +2335,7 @@ static void srpt_cm_rtu_recv(struct ib_cm_id *cm_id) ch = srpt_find_channel(cm_id->context, cm_id); BUG_ON(!ch); - if (srpt_test_and_set_ch_state(ch, CH_CONNECTING, CH_LIVE)) { + if (srpt_set_ch_state(ch, CH_LIVE)) { struct srpt_recv_ioctx *ioctx, *ioctx_tmp; ret = srpt_ch_qp_rts(ch, ch->qp);