From patchwork Tue Sep 19 17:46:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 815759 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iSgoYKVi"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xxVhd2X3hz9rvt for ; Wed, 20 Sep 2017 03:48:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751580AbdISRr7 (ORCPT ); Tue, 19 Sep 2017 13:47:59 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33476 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbdISRrQ (ORCPT ); Tue, 19 Sep 2017 13:47:16 -0400 Received: by mail-wm0-f66.google.com with SMTP id m127so325530wmm.0 for ; Tue, 19 Sep 2017 10:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZWcvBn5C2IzoSjdOtgu0IH0e44F9wLq51uLX0Y8QLjs=; b=iSgoYKViECd0u2LxGwrtew8z6beRmYfHHxrswmCzvpI6r/8h9Q6QIsiD/m2iSad6fd 4E6O0P3kJI03MzOaOnXs+wO5o1Zh8MchOhP69peVmAsXdAcD1r7TFfsn5fV/sBODpuaN rH9u4zklPu1kN7BPXg7DF83QK3ynEENHpg8QLMjfLMZEErvhuKi7EL8IqzfRptBt/JKn DLjoBm5hjqVVaAsHInbdwpgtkpvkwmei80XGqD2NamwGk/MJdGJoclSLOaxbJqpVv/NE f9vVHFL4SpwyrZoWcNQK4hWGONZbKqxm/eszHDhV3MORbI/X85bM8sbWL3ZzilS7sYfy dLjw== 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=ZWcvBn5C2IzoSjdOtgu0IH0e44F9wLq51uLX0Y8QLjs=; b=s3JFVYSJVNLyS87T0Os8qTTBVkXQTp6N6FXEzc8dcSZ6oOsKYilVhmzk7PwUg5gdSe 6RFwlK+s8J/+0mbOeRLwzNvWI2KNP44u1dX6z6Ve4K4X015HhZVkk0vzmhfmfRZsWc+G +wICnVv2GX5+lc2lBUqPp+j/TqfMdY1+jWF+cVdOEOeoQ+2+9xgBJB/KMZ/ZLWX0Gbil 3UK4BMhz0HBtxSdVyonKESF+2y9DCts84vmQARKRR+ju1VIPUiL2Aedxy98hQCCO0zcS 5Y52Xp6upWR6HQEnW/SaWSOtUF7inNjaA51kXX2UORG+027ikpZz/kB3L2gFXVvM0jEI Al9Q== X-Gm-Message-State: AHPjjUjaY9a/VySQlcrP4e6hX1kcn8/OEqi2ASJ7sLTBRPJYW7UuiauT YTEQPsByIrx6HirAp+5E2CmDw+17 X-Google-Smtp-Source: AOwi7QC40e806AzAd2VHaIY7/edZ7jWjYtJCSK33D3V715uxyVrmGbNGRxjYOWsRo2Yh5xxodxErnw== X-Received: by 10.28.212.148 with SMTP id l142mr1562134wmg.99.1505843235040; Tue, 19 Sep 2017 10:47:15 -0700 (PDT) Received: from fainelli-desktop.broadcom.com ([192.19.255.250]) by smtp.gmail.com with ESMTPSA id q19sm11543124wrb.17.2017.09.19.10.47.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Sep 2017 10:47:14 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: davem@davemloft.net, andrew@lunn.ch, vivien.didelot@savoirfairelinux.com, Florian Fainelli Subject: [PATCH net-next v3 05/12] net: dsa: b53: Use a macro to define I/O operations Date: Tue, 19 Sep 2017 10:46:47 -0700 Message-Id: <20170919174654.2122-6-f.fainelli@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170919174654.2122-1-f.fainelli@gmail.com> References: <20170919174654.2122-1-f.fainelli@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Instead of repeating the same pattern: acquire mutex, read/write, release mutex, define a macro: b53_build_op() which takes the type (read|write), I/O size, and value (scalar or pointer). This helps with fixing bugs that could exist (e.g: missing barrier, lock etc.). Reviewed-by: Vivien Didelot Signed-off-by: Florian Fainelli --- drivers/net/dsa/b53/b53_priv.h | 133 +++++++---------------------------------- 1 file changed, 22 insertions(+), 111 deletions(-) diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h index 7528b22aeb03..5bebe97900e8 100644 --- a/drivers/net/dsa/b53/b53_priv.h +++ b/drivers/net/dsa/b53/b53_priv.h @@ -199,119 +199,30 @@ static inline void b53_switch_remove(struct b53_device *dev) dsa_unregister_switch(dev->ds); } -static inline int b53_read8(struct b53_device *dev, u8 page, u8 reg, u8 *val) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->read8(dev, page, reg, val); - mutex_unlock(&dev->reg_mutex); - - return ret; -} - -static inline int b53_read16(struct b53_device *dev, u8 page, u8 reg, u16 *val) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->read16(dev, page, reg, val); - mutex_unlock(&dev->reg_mutex); - - return ret; -} - -static inline int b53_read32(struct b53_device *dev, u8 page, u8 reg, u32 *val) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->read32(dev, page, reg, val); - mutex_unlock(&dev->reg_mutex); - - return ret; -} - -static inline int b53_read48(struct b53_device *dev, u8 page, u8 reg, u64 *val) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->read48(dev, page, reg, val); - mutex_unlock(&dev->reg_mutex); - - return ret; +#define b53_build_op(type_op_size, val_type) \ +static inline int b53_##type_op_size(struct b53_device *dev, u8 page, \ + u8 reg, val_type val) \ +{ \ + int ret; \ + \ + mutex_lock(&dev->reg_mutex); \ + ret = dev->ops->type_op_size(dev, page, reg, val); \ + mutex_unlock(&dev->reg_mutex); \ + \ + return ret; \ } -static inline int b53_read64(struct b53_device *dev, u8 page, u8 reg, u64 *val) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->read64(dev, page, reg, val); - mutex_unlock(&dev->reg_mutex); - - return ret; -} - -static inline int b53_write8(struct b53_device *dev, u8 page, u8 reg, u8 value) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->write8(dev, page, reg, value); - mutex_unlock(&dev->reg_mutex); - - return ret; -} - -static inline int b53_write16(struct b53_device *dev, u8 page, u8 reg, - u16 value) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->write16(dev, page, reg, value); - mutex_unlock(&dev->reg_mutex); - - return ret; -} - -static inline int b53_write32(struct b53_device *dev, u8 page, u8 reg, - u32 value) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->write32(dev, page, reg, value); - mutex_unlock(&dev->reg_mutex); - - return ret; -} - -static inline int b53_write48(struct b53_device *dev, u8 page, u8 reg, - u64 value) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->write48(dev, page, reg, value); - mutex_unlock(&dev->reg_mutex); - - return ret; -} - -static inline int b53_write64(struct b53_device *dev, u8 page, u8 reg, - u64 value) -{ - int ret; - - mutex_lock(&dev->reg_mutex); - ret = dev->ops->write64(dev, page, reg, value); - mutex_unlock(&dev->reg_mutex); - - return ret; -} +b53_build_op(read8, u8 *); +b53_build_op(read16, u16 *); +b53_build_op(read32, u32 *); +b53_build_op(read48, u64 *); +b53_build_op(read64, u64 *); + +b53_build_op(write8, u8); +b53_build_op(write16, u16); +b53_build_op(write32, u32); +b53_build_op(write48, u64); +b53_build_op(write64, u64); struct b53_arl_entry { u8 port;