diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2009-12-09 01:14:38 -0500 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2009-12-09 01:14:38 -0500 |
commit | bcd6acd51f3d4d1ada201e9bc5c40a31d6d80c71 (patch) | |
tree | 2f6dffd2d3e4dd67355a224de7e7a960335a92fd /drivers/ieee802154 | |
parent | 11c34c7deaeeebcee342cbc35e1bb2a6711b2431 (diff) | |
parent | 3ff6a468b45b5dfeb0e903e56f4eb27d34b2437c (diff) |
Merge commit 'origin/master' into next
Conflicts:
include/linux/kvm.h
Diffstat (limited to 'drivers/ieee802154')
-rw-r--r-- | drivers/ieee802154/fakehard.c | 64 |
1 files changed, 48 insertions, 16 deletions
diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c index 96a2959ce877..d9d0e13efe47 100644 --- a/drivers/ieee802154/fakehard.c +++ b/drivers/ieee802154/fakehard.c | |||
@@ -32,9 +32,29 @@ | |||
32 | #include <net/nl802154.h> | 32 | #include <net/nl802154.h> |
33 | #include <net/wpan-phy.h> | 33 | #include <net/wpan-phy.h> |
34 | 34 | ||
35 | struct wpan_phy *net_to_phy(struct net_device *dev) | 35 | struct fakehard_priv { |
36 | struct wpan_phy *phy; | ||
37 | }; | ||
38 | |||
39 | static struct wpan_phy *fake_to_phy(const struct net_device *dev) | ||
40 | { | ||
41 | struct fakehard_priv *priv = netdev_priv(dev); | ||
42 | return priv->phy; | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * fake_get_phy - Return a phy corresponding to this device. | ||
47 | * @dev: The network device for which to return the wan-phy object | ||
48 | * | ||
49 | * This function returns a wpan-phy object corresponding to the passed | ||
50 | * network device. Reference counter for wpan-phy object is incremented, | ||
51 | * so when the wpan-phy isn't necessary, you should drop the reference | ||
52 | * via @wpan_phy_put() call. | ||
53 | */ | ||
54 | static struct wpan_phy *fake_get_phy(const struct net_device *dev) | ||
36 | { | 55 | { |
37 | return container_of(dev->dev.parent, struct wpan_phy, dev); | 56 | struct wpan_phy *phy = fake_to_phy(dev); |
57 | return to_phy(get_device(&phy->dev)); | ||
38 | } | 58 | } |
39 | 59 | ||
40 | /** | 60 | /** |
@@ -43,7 +63,7 @@ struct wpan_phy *net_to_phy(struct net_device *dev) | |||
43 | * | 63 | * |
44 | * Return the ID of the PAN from the PIB. | 64 | * Return the ID of the PAN from the PIB. |
45 | */ | 65 | */ |
46 | static u16 fake_get_pan_id(struct net_device *dev) | 66 | static u16 fake_get_pan_id(const struct net_device *dev) |
47 | { | 67 | { |
48 | BUG_ON(dev->type != ARPHRD_IEEE802154); | 68 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
49 | 69 | ||
@@ -58,7 +78,7 @@ static u16 fake_get_pan_id(struct net_device *dev) | |||
58 | * device. If the device has not yet had a short address assigned | 78 | * device. If the device has not yet had a short address assigned |
59 | * then this should return 0xFFFF to indicate a lack of association. | 79 | * then this should return 0xFFFF to indicate a lack of association. |
60 | */ | 80 | */ |
61 | static u16 fake_get_short_addr(struct net_device *dev) | 81 | static u16 fake_get_short_addr(const struct net_device *dev) |
62 | { | 82 | { |
63 | BUG_ON(dev->type != ARPHRD_IEEE802154); | 83 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
64 | 84 | ||
@@ -78,7 +98,7 @@ static u16 fake_get_short_addr(struct net_device *dev) | |||
78 | * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 | 98 | * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 |
79 | * document. | 99 | * document. |
80 | */ | 100 | */ |
81 | static u8 fake_get_dsn(struct net_device *dev) | 101 | static u8 fake_get_dsn(const struct net_device *dev) |
82 | { | 102 | { |
83 | BUG_ON(dev->type != ARPHRD_IEEE802154); | 103 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
84 | 104 | ||
@@ -98,7 +118,7 @@ static u8 fake_get_dsn(struct net_device *dev) | |||
98 | * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 | 118 | * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 |
99 | * document. | 119 | * document. |
100 | */ | 120 | */ |
101 | static u8 fake_get_bsn(struct net_device *dev) | 121 | static u8 fake_get_bsn(const struct net_device *dev) |
102 | { | 122 | { |
103 | BUG_ON(dev->type != ARPHRD_IEEE802154); | 123 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
104 | 124 | ||
@@ -121,7 +141,7 @@ static u8 fake_get_bsn(struct net_device *dev) | |||
121 | static int fake_assoc_req(struct net_device *dev, | 141 | static int fake_assoc_req(struct net_device *dev, |
122 | struct ieee802154_addr *addr, u8 channel, u8 page, u8 cap) | 142 | struct ieee802154_addr *addr, u8 channel, u8 page, u8 cap) |
123 | { | 143 | { |
124 | struct wpan_phy *phy = net_to_phy(dev); | 144 | struct wpan_phy *phy = fake_to_phy(dev); |
125 | 145 | ||
126 | mutex_lock(&phy->pib_lock); | 146 | mutex_lock(&phy->pib_lock); |
127 | phy->current_channel = channel; | 147 | phy->current_channel = channel; |
@@ -196,7 +216,7 @@ static int fake_start_req(struct net_device *dev, struct ieee802154_addr *addr, | |||
196 | u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx, | 216 | u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx, |
197 | u8 coord_realign) | 217 | u8 coord_realign) |
198 | { | 218 | { |
199 | struct wpan_phy *phy = net_to_phy(dev); | 219 | struct wpan_phy *phy = fake_to_phy(dev); |
200 | 220 | ||
201 | mutex_lock(&phy->pib_lock); | 221 | mutex_lock(&phy->pib_lock); |
202 | phy->current_channel = channel; | 222 | phy->current_channel = channel; |
@@ -239,6 +259,8 @@ static struct ieee802154_mlme_ops fake_mlme = { | |||
239 | .start_req = fake_start_req, | 259 | .start_req = fake_start_req, |
240 | .scan_req = fake_scan_req, | 260 | .scan_req = fake_scan_req, |
241 | 261 | ||
262 | .get_phy = fake_get_phy, | ||
263 | |||
242 | .get_pan_id = fake_get_pan_id, | 264 | .get_pan_id = fake_get_pan_id, |
243 | .get_short_addr = fake_get_short_addr, | 265 | .get_short_addr = fake_get_short_addr, |
244 | .get_dsn = fake_get_dsn, | 266 | .get_dsn = fake_get_dsn, |
@@ -260,15 +282,12 @@ static int ieee802154_fake_close(struct net_device *dev) | |||
260 | static netdev_tx_t ieee802154_fake_xmit(struct sk_buff *skb, | 282 | static netdev_tx_t ieee802154_fake_xmit(struct sk_buff *skb, |
261 | struct net_device *dev) | 283 | struct net_device *dev) |
262 | { | 284 | { |
263 | skb->iif = dev->ifindex; | ||
264 | skb->dev = dev; | ||
265 | dev->stats.tx_packets++; | 285 | dev->stats.tx_packets++; |
266 | dev->stats.tx_bytes += skb->len; | 286 | dev->stats.tx_bytes += skb->len; |
267 | 287 | ||
268 | dev->trans_start = jiffies; | ||
269 | |||
270 | /* FIXME: do hardware work here ... */ | 288 | /* FIXME: do hardware work here ... */ |
271 | 289 | ||
290 | dev_kfree_skb(skb); | ||
272 | return NETDEV_TX_OK; | 291 | return NETDEV_TX_OK; |
273 | } | 292 | } |
274 | 293 | ||
@@ -313,7 +332,7 @@ static const struct net_device_ops fake_ops = { | |||
313 | 332 | ||
314 | static void ieee802154_fake_destruct(struct net_device *dev) | 333 | static void ieee802154_fake_destruct(struct net_device *dev) |
315 | { | 334 | { |
316 | struct wpan_phy *phy = net_to_phy(dev); | 335 | struct wpan_phy *phy = fake_to_phy(dev); |
317 | 336 | ||
318 | wpan_phy_unregister(phy); | 337 | wpan_phy_unregister(phy); |
319 | free_netdev(dev); | 338 | free_netdev(dev); |
@@ -338,13 +357,14 @@ static void ieee802154_fake_setup(struct net_device *dev) | |||
338 | static int __devinit ieee802154fake_probe(struct platform_device *pdev) | 357 | static int __devinit ieee802154fake_probe(struct platform_device *pdev) |
339 | { | 358 | { |
340 | struct net_device *dev; | 359 | struct net_device *dev; |
360 | struct fakehard_priv *priv; | ||
341 | struct wpan_phy *phy = wpan_phy_alloc(0); | 361 | struct wpan_phy *phy = wpan_phy_alloc(0); |
342 | int err; | 362 | int err; |
343 | 363 | ||
344 | if (!phy) | 364 | if (!phy) |
345 | return -ENOMEM; | 365 | return -ENOMEM; |
346 | 366 | ||
347 | dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup); | 367 | dev = alloc_netdev(sizeof(struct fakehard_priv), "hardwpan%d", ieee802154_fake_setup); |
348 | if (!dev) { | 368 | if (!dev) { |
349 | wpan_phy_free(phy); | 369 | wpan_phy_free(phy); |
350 | return -ENOMEM; | 370 | return -ENOMEM; |
@@ -356,12 +376,23 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev) | |||
356 | dev->addr_len); | 376 | dev->addr_len); |
357 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); | 377 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
358 | 378 | ||
359 | phy->channels_supported = (1 << 27) - 1; | 379 | /* |
380 | * For now we'd like to emulate 2.4 GHz-only device, | ||
381 | * both O-QPSK and CSS | ||
382 | */ | ||
383 | /* 2.4 GHz O-QPSK 802.15.4-2003 */ | ||
384 | phy->channels_supported[0] |= 0x7FFF800; | ||
385 | /* 2.4 GHz CSS 802.15.4a-2007 */ | ||
386 | phy->channels_supported[3] |= 0x3fff; | ||
387 | |||
360 | phy->transmit_power = 0xbf; | 388 | phy->transmit_power = 0xbf; |
361 | 389 | ||
362 | dev->netdev_ops = &fake_ops; | 390 | dev->netdev_ops = &fake_ops; |
363 | dev->ml_priv = &fake_mlme; | 391 | dev->ml_priv = &fake_mlme; |
364 | 392 | ||
393 | priv = netdev_priv(dev); | ||
394 | priv->phy = phy; | ||
395 | |||
365 | /* | 396 | /* |
366 | * If the name is a format string the caller wants us to do a | 397 | * If the name is a format string the caller wants us to do a |
367 | * name allocation. | 398 | * name allocation. |
@@ -372,11 +403,12 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev) | |||
372 | goto out; | 403 | goto out; |
373 | } | 404 | } |
374 | 405 | ||
406 | wpan_phy_set_dev(phy, &pdev->dev); | ||
375 | SET_NETDEV_DEV(dev, &phy->dev); | 407 | SET_NETDEV_DEV(dev, &phy->dev); |
376 | 408 | ||
377 | platform_set_drvdata(pdev, dev); | 409 | platform_set_drvdata(pdev, dev); |
378 | 410 | ||
379 | err = wpan_phy_register(&pdev->dev, phy); | 411 | err = wpan_phy_register(phy); |
380 | if (err) | 412 | if (err) |
381 | goto out; | 413 | goto out; |
382 | 414 | ||