From patchwork Fri Nov 6 12:39:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 37854 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.176.167]) by ozlabs.org (Postfix) with ESMTP id 94024B6F2B for ; Fri, 6 Nov 2009 23:42:25 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759222AbZKFMlJ (ORCPT ); Fri, 6 Nov 2009 07:41:09 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752485AbZKFMlH (ORCPT ); Fri, 6 Nov 2009 07:41:07 -0500 Received: from mail-ew0-f207.google.com ([209.85.219.207]:58044 "EHLO mail-ew0-f207.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758850AbZKFMlB (ORCPT ); Fri, 6 Nov 2009 07:41:01 -0500 Received: by mail-ew0-f207.google.com with SMTP id 3so975605ewy.37 for ; Fri, 06 Nov 2009 04:41:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=9Kf3/iJ1sFEaoXD7XG20J9v/9m6Ghi4HMweELu+ac7k=; b=c6hPNXyY76lAdAmQjEckoqUzISp2JW0woi+T+MZmM+nLgDc8HO8aHenn1ghB2mD+nN CeVqnI6LT4Eg78LIhpIB4USD4bAcBx9kGtIFulNg8TS1RFytNWE/c0pJI9l++6mdEbvn 9hCwzSF10Fzbof+Qq32ME3uIEfQBycDPcJIFA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=cV23Kngj9pQwlVrr+Q5FjPxTVB/wWzqmhK2YqfmWBwYcJ5SPtkMWv5uZXxwjbaUhiO TtnwrX6Hf4I9fglLyr69kpBNvr+dV5ofaNvIGhH+CtFhzMisIoLGH0Ds48+vtzAvUp4P 7wXqAXmNpP44irKn8IhLdsA+EP5pt44tJBLhk= Received: by 10.213.23.88 with SMTP id q24mr5047652ebb.13.1257511266608; Fri, 06 Nov 2009 04:41:06 -0800 (PST) Received: from localhost.localdomain ([91.213.169.4]) by mx.google.com with ESMTPS id 28sm345811eyg.30.2009.11.06.04.41.04 (version=SSLv3 cipher=RC4-MD5); Fri, 06 Nov 2009 04:41:05 -0800 (PST) From: Dmitry Eremin-Solenikov To: "David S. Miller" Cc: netdev@vger.kernel.org, Sergey Lapin Subject: [PATCH 14/17] fakehard: mlme_ops->get_phy implementation Date: Fri, 6 Nov 2009 15:39:38 +0300 Message-Id: <1257511181-19403-15-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 1.6.5 In-Reply-To: <1257511181-19403-1-git-send-email-dbaryshkov@gmail.com> References: <1257511181-19403-1-git-send-email-dbaryshkov@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Dmitry Eremin-Solenikov --- drivers/ieee802154/fakehard.c | 38 ++++++++++++++++++++++++++++++++------ 1 files changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c index 70a9f9c..f877f13 100644 --- a/drivers/ieee802154/fakehard.c +++ b/drivers/ieee802154/fakehard.c @@ -32,9 +32,29 @@ #include #include -static struct wpan_phy *net_to_phy(struct net_device *dev) +struct fakehard_priv { + struct wpan_phy *phy; +}; + +static struct wpan_phy *fake_to_phy(const struct net_device *dev) +{ + struct fakehard_priv *priv = netdev_priv(dev); + return priv->phy; +} + +/** + * fake_get_phy - Return a phy corresponding to this device. + * @dev: The network device for which to return the wan-phy object + * + * This function returns a wpan-phy object corresponding to the passed + * network device. Reference counter for wpan-phy object is incremented, + * so when the wpan-phy isn't necessary, you should drop the reference + * via @wpan_phy_put() call. + */ +static struct wpan_phy *fake_get_phy(const struct net_device *dev) { - return container_of(dev->dev.parent, struct wpan_phy, dev); + struct wpan_phy *phy = fake_to_phy(dev); + return to_phy(get_device(&phy->dev)); } /** @@ -121,7 +141,7 @@ static u8 fake_get_bsn(const struct net_device *dev) static int fake_assoc_req(struct net_device *dev, struct ieee802154_addr *addr, u8 channel, u8 page, u8 cap) { - struct wpan_phy *phy = net_to_phy(dev); + struct wpan_phy *phy = fake_to_phy(dev); mutex_lock(&phy->pib_lock); phy->current_channel = channel; @@ -196,7 +216,7 @@ static int fake_start_req(struct net_device *dev, struct ieee802154_addr *addr, u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx, u8 coord_realign) { - struct wpan_phy *phy = net_to_phy(dev); + struct wpan_phy *phy = fake_to_phy(dev); mutex_lock(&phy->pib_lock); phy->current_channel = channel; @@ -239,6 +259,8 @@ static struct ieee802154_mlme_ops fake_mlme = { .start_req = fake_start_req, .scan_req = fake_scan_req, + .get_phy = fake_get_phy, + .get_pan_id = fake_get_pan_id, .get_short_addr = fake_get_short_addr, .get_dsn = fake_get_dsn, @@ -313,7 +335,7 @@ static const struct net_device_ops fake_ops = { static void ieee802154_fake_destruct(struct net_device *dev) { - struct wpan_phy *phy = net_to_phy(dev); + struct wpan_phy *phy = fake_to_phy(dev); wpan_phy_unregister(phy); free_netdev(dev); @@ -338,13 +360,14 @@ static void ieee802154_fake_setup(struct net_device *dev) static int __devinit ieee802154fake_probe(struct platform_device *pdev) { struct net_device *dev; + struct fakehard_priv *priv; struct wpan_phy *phy = wpan_phy_alloc(0); int err; if (!phy) return -ENOMEM; - dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup); + dev = alloc_netdev(sizeof(struct fakehard_priv), "hardwpan%d", ieee802154_fake_setup); if (!dev) { wpan_phy_free(phy); return -ENOMEM; @@ -370,6 +393,9 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev) dev->netdev_ops = &fake_ops; dev->ml_priv = &fake_mlme; + priv = netdev_priv(dev); + priv->phy = phy; + /* * If the name is a format string the caller wants us to do a * name allocation.