From patchwork Thu Aug 20 16:13:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 31743 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 88E50B7079 for ; Fri, 21 Aug 2009 02:14:48 +1000 (EST) Received: by ozlabs.org (Postfix) id 7DAC4DDD01; Fri, 21 Aug 2009 02:14:48 +1000 (EST) 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 1E64ADDD1B for ; Fri, 21 Aug 2009 02:14:48 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754858AbZHTQOR (ORCPT ); Thu, 20 Aug 2009 12:14:17 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754755AbZHTQOO (ORCPT ); Thu, 20 Aug 2009 12:14:14 -0400 Received: from mail-ew0-f207.google.com ([209.85.219.207]:45981 "EHLO mail-ew0-f207.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754809AbZHTQOM (ORCPT ); Thu, 20 Aug 2009 12:14:12 -0400 Received: by mail-ew0-f207.google.com with SMTP id 3so5577ewy.18 for ; Thu, 20 Aug 2009 09:14:13 -0700 (PDT) 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=8eqfmQhn4a8rpnfub9vYn2x823AGHjUia7yEMu2dXjY=; b=uFwpMqbNdgE+Hpkbj0w61LxzLRrihCPtI2J2dcTwsaP9T9uXxb5tWtc94dryjbShia wSlJMUSeDVjYl2v6NXRv31I13q+4w1PI6NAEaMlC5ZO8ZewoJTZxJbY8+h27JsrdZreg i+9BKeImWPYtCzgz0jwjS0KttxS72nYQq0VBs= 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=IDNFaDe6+0CjE3yhnHdneWT1TW4wCVanoc1QiOyJ3H6PIDwomdUkKnmsP+T56y/haR LjqaE20N7d8liHgQRfzQNP46gE1l6sz5MNZelwg6JtNzzUYSJjruoWjVIML/UjhdXLwt avwGd6snfU7CbfRTOoovlLZb2Ykf4R1Af24r8= Received: by 10.210.43.10 with SMTP id q10mr214747ebq.97.1250784853839; Thu, 20 Aug 2009 09:14:13 -0700 (PDT) Received: from localhost.localdomain (iap-pxy-mow1.siemens.ru [212.248.25.26]) by mx.google.com with ESMTPS id 7sm65984eyg.25.2009.08.20.09.14.10 (version=SSLv3 cipher=RC4-MD5); Thu, 20 Aug 2009 09:14:11 -0700 (PDT) From: Dmitry Eremin-Solenikov To: "David S. Miller" Cc: netdev@vger.kernel.org, linux-zigbee-devel@lists.sourceforge.net, Sergey Lapin Subject: [PATCH 3/5] fakehard: add binding to wpan-phy device Date: Thu, 20 Aug 2009 20:13:05 +0400 Message-Id: <1250784787-30590-4-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1250784787-30590-3-git-send-email-dbaryshkov@gmail.com> References: <1250784787-30590-1-git-send-email-dbaryshkov@gmail.com> <1250784787-30590-2-git-send-email-dbaryshkov@gmail.com> <1250784787-30590-3-git-send-email-dbaryshkov@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Make fakehard create and maintain wpan-phy node, thus representing it's phy in the sysfs. Signed-off-by: Dmitry Eremin-Solenikov --- drivers/ieee802154/fakehard.c | 52 ++++++++++++++++++++++++++++++++++++---- 1 files changed, 46 insertions(+), 6 deletions(-) diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c index 262536f..22a93bc 100644 --- a/drivers/ieee802154/fakehard.c +++ b/drivers/ieee802154/fakehard.c @@ -30,6 +30,12 @@ #include #include #include +#include + +struct wpan_phy *net_to_phy(struct net_device *dev) +{ + return container_of(dev->dev.parent, struct wpan_phy, dev); +} /** * fake_get_pan_id - Retrieve the PAN ID of the device. @@ -115,6 +121,12 @@ static u8 fake_get_bsn(struct net_device *dev) static int fake_assoc_req(struct net_device *dev, struct ieee802154_addr *addr, u8 channel, u8 cap) { + struct wpan_phy *phy = net_to_phy(dev); + + mutex_lock(&phy->pib_lock); + phy->current_channel = channel; + mutex_unlock(&phy->pib_lock); + /* We simply emulate it here */ return ieee802154_nl_assoc_confirm(dev, fake_get_short_addr(dev), IEEE802154_SUCCESS); @@ -183,6 +195,12 @@ 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); + + mutex_lock(&phy->pib_lock); + phy->current_channel = channel; + mutex_unlock(&phy->pib_lock); + /* We don't emulate beacons here at all, so START should fail */ ieee802154_nl_start_confirm(dev, IEEE802154_INVALID_PARAMETER); return 0; @@ -290,6 +308,14 @@ static const struct net_device_ops fake_ops = { .ndo_set_mac_address = ieee802154_fake_mac_addr, }; +static void ieee802154_fake_destruct(struct net_device *dev) +{ + struct wpan_phy *phy = net_to_phy(dev); + + wpan_phy_unregister(phy); + free_netdev(dev); + wpan_phy_free(phy); +} static void ieee802154_fake_setup(struct net_device *dev) { @@ -302,22 +328,34 @@ static void ieee802154_fake_setup(struct net_device *dev) dev->type = ARPHRD_IEEE802154; dev->flags = IFF_NOARP | IFF_BROADCAST; dev->watchdog_timeo = 0; + dev->destructor = ieee802154_fake_destruct; } static int __devinit ieee802154fake_probe(struct platform_device *pdev) { - struct net_device *dev = - alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup); + struct net_device *dev; + struct wpan_phy *phy = wpan_phy_alloc(0); int err; - if (!dev) + if (!phy) + return -ENOMEM; + + dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup); + if (!dev) { + wpan_phy_free(phy); return -ENOMEM; + } + + phy->dev.platform_data = dev; memcpy(dev->dev_addr, "\xba\xbe\xca\xfe\xde\xad\xbe\xef", dev->addr_len); memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); + phy->channels_supported = (1 << 27) - 1; + phy->transmit_power = 0xbf; + dev->netdev_ops = &fake_ops; dev->ml_priv = &fake_mlme; @@ -331,15 +369,18 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev) goto out; } - SET_NETDEV_DEV(dev, &pdev->dev); + SET_NETDEV_DEV(dev, &phy->dev); platform_set_drvdata(pdev, dev); + err = wpan_phy_register(&pdev->dev, phy); + if (err) + goto out; + err = register_netdev(dev); if (err < 0) goto out; - dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n"); return 0; @@ -352,7 +393,6 @@ static int __devexit ieee802154fake_remove(struct platform_device *pdev) { struct net_device *dev = platform_get_drvdata(pdev); unregister_netdev(dev); - free_netdev(dev); return 0; }