* [PATCHv2 wpan-next 01/16] ieee802154: change transmit power to s32
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 02/16] ieee802154: change transmit power to mbm Alexander Aring
` (14 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch change the transmit power from s8 to s32. This prepares to store a
mbm value instead dbm inside the transmit power variable. The old
interface keep the a s8 dbm value, which should be backward compatibility
when assign s8 to s32.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 2 +-
include/net/cfg802154.h | 2 +-
include/net/mac802154.h | 2 +-
net/ieee802154/nl802154.c | 6 +++---
net/mac802154/driver-ops.h | 2 +-
5 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 67d00fb..02b6bb7 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1194,7 +1194,7 @@ at86rf230_set_hw_addr_filt(struct ieee802154_hw *hw,
}
static int
-at86rf230_set_txpower(struct ieee802154_hw *hw, s8 db)
+at86rf230_set_txpower(struct ieee802154_hw *hw, s32 db)
{
struct at86rf230_local *lp = hw->priv;
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 6ea16c8..47804cd 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -85,7 +85,7 @@ struct wpan_phy {
u8 current_channel;
u8 current_page;
u32 channels_supported[IEEE802154_MAX_PAGE + 1];
- s8 transmit_power;
+ s32 transmit_power;
struct wpan_phy_cca cca;
__le64 perm_extended_addr;
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index 7df28a4..400e4e8 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -213,7 +213,7 @@ struct ieee802154_ops {
int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
struct ieee802154_hw_addr_filt *filt,
unsigned long changed);
- int (*set_txpower)(struct ieee802154_hw *hw, s8 dbm);
+ int (*set_txpower)(struct ieee802154_hw *hw, s32 dbm);
int (*set_lbt)(struct ieee802154_hw *hw, bool on);
int (*set_cca_mode)(struct ieee802154_hw *hw,
const struct wpan_phy_cca *cca);
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index d750d97..f3185c7 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -207,7 +207,7 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
[NL802154_ATTR_PAGE] = { .type = NLA_U8, },
[NL802154_ATTR_CHANNEL] = { .type = NLA_U8, },
- [NL802154_ATTR_TX_POWER] = { .type = NLA_S8, },
+ [NL802154_ATTR_TX_POWER] = { .type = NLA_S32, },
[NL802154_ATTR_CCA_MODE] = { .type = NLA_U32, },
[NL802154_ATTR_CCA_OPT] = { .type = NLA_U32, },
@@ -301,8 +301,8 @@ static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
goto nla_put_failure;
}
- if (nla_put_s8(msg, NL802154_ATTR_TX_POWER,
- rdev->wpan_phy.transmit_power))
+ if (nla_put_s32(msg, NL802154_ATTR_TX_POWER,
+ rdev->wpan_phy.transmit_power))
goto nla_put_failure;
finish:
diff --git a/net/mac802154/driver-ops.h b/net/mac802154/driver-ops.h
index a053335..57c1bdb 100644
--- a/net/mac802154/driver-ops.h
+++ b/net/mac802154/driver-ops.h
@@ -58,7 +58,7 @@ drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel)
return local->ops->set_channel(&local->hw, page, channel);
}
-static inline int drv_set_tx_power(struct ieee802154_local *local, s8 dbm)
+static inline int drv_set_tx_power(struct ieee802154_local *local, s32 dbm)
{
might_sleep();
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 02/16] ieee802154: change transmit power to mbm
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 01/16] ieee802154: change transmit power to s32 Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 03/16] ieee802154: change cca ed level " Alexander Aring
` (13 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch change the handling of transmit power level from dbm to mbm.
This prepares to handle floating point transmit power levels values. The
old netlink 802.15.4 will convert the dbm value to mbm for handling
backward compatibility.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 3 ++-
include/net/cfg802154.h | 1 +
include/net/mac802154.h | 2 +-
net/ieee802154/nl-mac.c | 4 ++--
net/mac802154/driver-ops.h | 4 ++--
5 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 02b6bb7..3a303e4 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1194,9 +1194,10 @@ at86rf230_set_hw_addr_filt(struct ieee802154_hw *hw,
}
static int
-at86rf230_set_txpower(struct ieee802154_hw *hw, s32 db)
+at86rf230_set_txpower(struct ieee802154_hw *hw, s32 mbm)
{
struct at86rf230_local *lp = hw->priv;
+ s8 db = mbm / 100;
/* typical maximum output is 5dBm with RG_PHY_TX_PWR 0x60, lower five
* bits decrease power in 1dB steps. 0x60 represents extra PA gain of
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 47804cd..b5b3f9f 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -85,6 +85,7 @@ struct wpan_phy {
u8 current_channel;
u8 current_page;
u32 channels_supported[IEEE802154_MAX_PAGE + 1];
+ /* current transmit_power in mBm */
s32 transmit_power;
struct wpan_phy_cca cca;
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index 400e4e8..beb07ce 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -171,7 +171,7 @@ struct ieee802154_hw {
* Returns either zero, or negative errno.
*
* set_txpower:
- * Set radio transmit power in dB. Called with pib_lock held.
+ * Set radio transmit power in mBm. Called with pib_lock held.
* Returns either zero, or negative errno.
*
* set_lbt
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index 2b4955d..4ba2e13 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -117,7 +117,7 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
rtnl_unlock();
if (nla_put_s8(msg, IEEE802154_ATTR_TXPOWER,
- params.transmit_power) ||
+ params.transmit_power / 100) ||
nla_put_u8(msg, IEEE802154_ATTR_LBT_ENABLED, params.lbt) ||
nla_put_u8(msg, IEEE802154_ATTR_CCA_MODE,
params.cca.mode) ||
@@ -510,7 +510,7 @@ int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info)
ops->get_mac_params(dev, ¶ms);
if (info->attrs[IEEE802154_ATTR_TXPOWER])
- params.transmit_power = nla_get_s8(info->attrs[IEEE802154_ATTR_TXPOWER]);
+ params.transmit_power = nla_get_s8(info->attrs[IEEE802154_ATTR_TXPOWER]) * 100;
if (info->attrs[IEEE802154_ATTR_LBT_ENABLED])
params.lbt = nla_get_u8(info->attrs[IEEE802154_ATTR_LBT_ENABLED]);
diff --git a/net/mac802154/driver-ops.h b/net/mac802154/driver-ops.h
index 57c1bdb..d289ae3 100644
--- a/net/mac802154/driver-ops.h
+++ b/net/mac802154/driver-ops.h
@@ -58,7 +58,7 @@ drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel)
return local->ops->set_channel(&local->hw, page, channel);
}
-static inline int drv_set_tx_power(struct ieee802154_local *local, s32 dbm)
+static inline int drv_set_tx_power(struct ieee802154_local *local, s32 mbm)
{
might_sleep();
@@ -67,7 +67,7 @@ static inline int drv_set_tx_power(struct ieee802154_local *local, s32 dbm)
return -EOPNOTSUPP;
}
- return local->ops->set_txpower(&local->hw, dbm);
+ return local->ops->set_txpower(&local->hw, mbm);
}
static inline int drv_set_cca_mode(struct ieee802154_local *local,
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 03/16] ieee802154: change cca ed level to mbm
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 01/16] ieee802154: change transmit power to s32 Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 02/16] ieee802154: change transmit power to mbm Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 04/16] ieee802154: introduce wpan_phy_supported Alexander Aring
` (12 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch change the handling of cca energy detection level from dbm to
mbm. This prepares to handle floating point cca energy detection levels
values. The old netlink 802.15.4 will convert the dbm value to mbm for
handling backward compatibility.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 3 ++-
include/net/cfg802154.h | 1 +
include/net/mac802154.h | 5 ++---
net/ieee802154/nl-mac.c | 4 ++--
net/mac802154/driver-ops.h | 4 ++--
5 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 3a303e4..e68d45e 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1268,9 +1268,10 @@ at86rf23x_get_desens_steps(struct at86rf230_local *lp, s32 level)
}
static int
-at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 level)
+at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
{
struct at86rf230_local *lp = hw->priv;
+ s32 level = mbm / 100;
if (level < lp->data->rssi_base_val || level > 30)
return -EINVAL;
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index b5b3f9f..9ced2c9 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -91,6 +91,7 @@ struct wpan_phy {
__le64 perm_extended_addr;
+ /* current cca ed threshold in mBm */
s32 cca_ed_level;
/* PHY depended MAC PIB values */
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index beb07ce..3b76aab 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -184,7 +184,7 @@ struct ieee802154_hw {
* Returns either zero, or negative errno.
*
* set_cca_ed_level
- * Sets the CCA energy detection threshold in dBm. Called with pib_lock
+ * Sets the CCA energy detection threshold in mBm. Called with pib_lock
* held.
* Returns either zero, or negative errno.
*
@@ -217,8 +217,7 @@ struct ieee802154_ops {
int (*set_lbt)(struct ieee802154_hw *hw, bool on);
int (*set_cca_mode)(struct ieee802154_hw *hw,
const struct wpan_phy_cca *cca);
- int (*set_cca_ed_level)(struct ieee802154_hw *hw,
- s32 level);
+ int (*set_cca_ed_level)(struct ieee802154_hw *hw, s32 mbm);
int (*set_csma_params)(struct ieee802154_hw *hw,
u8 min_be, u8 max_be, u8 retries);
int (*set_frame_retries)(struct ieee802154_hw *hw,
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index 4ba2e13..cdc1cc3 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -122,7 +122,7 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
nla_put_u8(msg, IEEE802154_ATTR_CCA_MODE,
params.cca.mode) ||
nla_put_s32(msg, IEEE802154_ATTR_CCA_ED_LEVEL,
- params.cca_ed_level) ||
+ params.cca_ed_level / 100) ||
nla_put_u8(msg, IEEE802154_ATTR_CSMA_RETRIES,
params.csma_retries) ||
nla_put_u8(msg, IEEE802154_ATTR_CSMA_MIN_BE,
@@ -519,7 +519,7 @@ int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info)
params.cca.mode = nla_get_u8(info->attrs[IEEE802154_ATTR_CCA_MODE]);
if (info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL])
- params.cca_ed_level = nla_get_s32(info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]);
+ params.cca_ed_level = nla_get_s32(info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]) * 100;
if (info->attrs[IEEE802154_ATTR_CSMA_RETRIES])
params.csma_retries = nla_get_u8(info->attrs[IEEE802154_ATTR_CSMA_RETRIES]);
diff --git a/net/mac802154/driver-ops.h b/net/mac802154/driver-ops.h
index d289ae3..caecd5f 100644
--- a/net/mac802154/driver-ops.h
+++ b/net/mac802154/driver-ops.h
@@ -96,7 +96,7 @@ static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
}
static inline int
-drv_set_cca_ed_level(struct ieee802154_local *local, s32 ed_level)
+drv_set_cca_ed_level(struct ieee802154_local *local, s32 mbm)
{
might_sleep();
@@ -105,7 +105,7 @@ drv_set_cca_ed_level(struct ieee802154_local *local, s32 ed_level)
return -EOPNOTSUPP;
}
- return local->ops->set_cca_ed_level(&local->hw, ed_level);
+ return local->ops->set_cca_ed_level(&local->hw, mbm);
}
static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id)
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 04/16] ieee802154: introduce wpan_phy_supported
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (2 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 03/16] ieee802154: change cca ed level " Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 05/16] ieee802154: add several phy supported handling Alexander Aring
` (11 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring, Varka Bhadram, Alan Ott
This patch introduce the wpan_phy_supported struct for wpan_phy. There
is currently no way to check if a transceiver can handle IEEE 802.15.4
complaint values. With this struct we can check before if the
transceiver supports these values before sending to driver layer.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Suggested-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
Cc: Varka Bhadram <varkabhadram@gmail.com>
Cc: Alan Ott <alan@signal11.us>
---
drivers/net/ieee802154/at86rf230.c | 8 ++++----
drivers/net/ieee802154/cc2520.c | 2 +-
drivers/net/ieee802154/fakelb.c | 30 +++++++++++++++---------------
drivers/net/ieee802154/mrf24j40.c | 2 +-
include/net/cfg802154.h | 6 +++++-
net/ieee802154/nl-phy.c | 4 ++--
net/ieee802154/nl802154.c | 4 ++--
7 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index e68d45e..151d57f 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1579,7 +1579,7 @@ at86rf230_detect_device(struct at86rf230_local *lp)
case 3:
chip = "at86rf231";
lp->data = &at86rf231_data;
- lp->hw->phy->channels_supported[0] = 0x7FFF800;
+ lp->hw->phy->supported.channels[0] = 0x7FFF800;
lp->hw->phy->current_channel = 11;
lp->hw->phy->symbol_duration = 16;
break;
@@ -1587,15 +1587,15 @@ at86rf230_detect_device(struct at86rf230_local *lp)
chip = "at86rf212";
lp->data = &at86rf212_data;
lp->hw->flags |= IEEE802154_HW_LBT;
- lp->hw->phy->channels_supported[0] = 0x00007FF;
- lp->hw->phy->channels_supported[2] = 0x00007FF;
+ lp->hw->phy->supported.channels[0] = 0x00007FF;
+ lp->hw->phy->supported.channels[2] = 0x00007FF;
lp->hw->phy->current_channel = 5;
lp->hw->phy->symbol_duration = 25;
break;
case 11:
chip = "at86rf233";
lp->data = &at86rf233_data;
- lp->hw->phy->channels_supported[0] = 0x7FFF800;
+ lp->hw->phy->supported.channels[0] = 0x7FFF800;
lp->hw->phy->current_channel = 13;
lp->hw->phy->symbol_duration = 16;
break;
diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c
index f833b8b..84b28a0 100644
--- a/drivers/net/ieee802154/cc2520.c
+++ b/drivers/net/ieee802154/cc2520.c
@@ -653,7 +653,7 @@ static int cc2520_register(struct cc2520_private *priv)
ieee802154_random_extended_addr(&priv->hw->phy->perm_extended_addr);
/* We do support only 2.4 Ghz */
- priv->hw->phy->channels_supported[0] = 0x7FFF800;
+ priv->hw->phy->supported.channels[0] = 0x7FFF800;
priv->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
IEEE802154_HW_AFILT;
diff --git a/drivers/net/ieee802154/fakelb.c b/drivers/net/ieee802154/fakelb.c
index dc2bfb6..91bbf03 100644
--- a/drivers/net/ieee802154/fakelb.c
+++ b/drivers/net/ieee802154/fakelb.c
@@ -149,35 +149,35 @@ static int fakelb_add_one(struct device *dev, struct fakelb_priv *fake)
priv->hw = hw;
/* 868 MHz BPSK 802.15.4-2003 */
- hw->phy->channels_supported[0] |= 1;
+ hw->phy->supported.channels[0] |= 1;
/* 915 MHz BPSK 802.15.4-2003 */
- hw->phy->channels_supported[0] |= 0x7fe;
+ hw->phy->supported.channels[0] |= 0x7fe;
/* 2.4 GHz O-QPSK 802.15.4-2003 */
- hw->phy->channels_supported[0] |= 0x7FFF800;
+ hw->phy->supported.channels[0] |= 0x7FFF800;
/* 868 MHz ASK 802.15.4-2006 */
- hw->phy->channels_supported[1] |= 1;
+ hw->phy->supported.channels[1] |= 1;
/* 915 MHz ASK 802.15.4-2006 */
- hw->phy->channels_supported[1] |= 0x7fe;
+ hw->phy->supported.channels[1] |= 0x7fe;
/* 868 MHz O-QPSK 802.15.4-2006 */
- hw->phy->channels_supported[2] |= 1;
+ hw->phy->supported.channels[2] |= 1;
/* 915 MHz O-QPSK 802.15.4-2006 */
- hw->phy->channels_supported[2] |= 0x7fe;
+ hw->phy->supported.channels[2] |= 0x7fe;
/* 2.4 GHz CSS 802.15.4a-2007 */
- hw->phy->channels_supported[3] |= 0x3fff;
+ hw->phy->supported.channels[3] |= 0x3fff;
/* UWB Sub-gigahertz 802.15.4a-2007 */
- hw->phy->channels_supported[4] |= 1;
+ hw->phy->supported.channels[4] |= 1;
/* UWB Low band 802.15.4a-2007 */
- hw->phy->channels_supported[4] |= 0x1e;
+ hw->phy->supported.channels[4] |= 0x1e;
/* UWB High band 802.15.4a-2007 */
- hw->phy->channels_supported[4] |= 0xffe0;
+ hw->phy->supported.channels[4] |= 0xffe0;
/* 750 MHz O-QPSK 802.15.4c-2009 */
- hw->phy->channels_supported[5] |= 0xf;
+ hw->phy->supported.channels[5] |= 0xf;
/* 750 MHz MPSK 802.15.4c-2009 */
- hw->phy->channels_supported[5] |= 0xf0;
+ hw->phy->supported.channels[5] |= 0xf0;
/* 950 MHz BPSK 802.15.4d-2009 */
- hw->phy->channels_supported[6] |= 0x3ff;
+ hw->phy->supported.channels[6] |= 0x3ff;
/* 950 MHz GFSK 802.15.4d-2009 */
- hw->phy->channels_supported[6] |= 0x3ffc00;
+ hw->phy->supported.channels[6] |= 0x3ffc00;
INIT_LIST_HEAD(&priv->list);
priv->fake = fake;
diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c
index fba2dfd..f2a1bd1 100644
--- a/drivers/net/ieee802154/mrf24j40.c
+++ b/drivers/net/ieee802154/mrf24j40.c
@@ -750,7 +750,7 @@ static int mrf24j40_probe(struct spi_device *spi)
devrec->hw->priv = devrec;
devrec->hw->parent = &devrec->spi->dev;
- devrec->hw->phy->channels_supported[0] = CHANNEL_MASK;
+ devrec->hw->phy->supported.channels[0] = CHANNEL_MASK;
devrec->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
IEEE802154_HW_AFILT;
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 9ced2c9..1941d7a 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -61,6 +61,10 @@ struct cfg802154_ops {
struct wpan_dev *wpan_dev, bool mode);
};
+struct wpan_phy_supported {
+ u32 channels[IEEE802154_MAX_PAGE + 1];
+};
+
struct wpan_phy_cca {
enum nl802154_cca_modes mode;
enum nl802154_cca_opts opt;
@@ -84,7 +88,7 @@ struct wpan_phy {
*/
u8 current_channel;
u8 current_page;
- u32 channels_supported[IEEE802154_MAX_PAGE + 1];
+ struct wpan_phy_supported supported;
/* current transmit_power in mBm */
s32 transmit_power;
struct wpan_phy_cca cca;
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
index 346c666..cbc0d09 100644
--- a/net/ieee802154/nl-phy.c
+++ b/net/ieee802154/nl-phy.c
@@ -56,8 +56,8 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 portid,
nla_put_u8(msg, IEEE802154_ATTR_CHANNEL, phy->current_channel))
goto nla_put_failure;
for (i = 0; i < 32; i++) {
- if (phy->channels_supported[i])
- buf[pages++] = phy->channels_supported[i] | (i << 27);
+ if (phy->supported.channels[i])
+ buf[pages++] = phy->supported.channels[i] | (i << 27);
}
if (pages &&
nla_put(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST,
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index f3185c7..d271879 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -248,7 +248,7 @@ nl802154_send_wpan_phy_channels(struct cfg802154_registered_device *rdev,
for (page = 0; page <= IEEE802154_MAX_PAGE; page++) {
if (nla_put_u32(msg, NL802154_ATTR_SUPPORTED_CHANNEL,
- rdev->wpan_phy.channels_supported[page]))
+ rdev->wpan_phy.supported.channels[page]))
return -ENOBUFS;
}
nla_nest_end(msg, nl_page);
@@ -626,7 +626,7 @@ static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info)
/* check 802.15.4 constraints */
if (page > IEEE802154_MAX_PAGE || channel > IEEE802154_MAX_CHANNEL ||
- !(rdev->wpan_phy.channels_supported[page] & BIT(channel)))
+ !(rdev->wpan_phy.supported.channels[page] & BIT(channel)))
return -EINVAL;
return rdev_set_channel(rdev, page, channel);
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 05/16] ieee802154: add several phy supported handling
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (3 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 04/16] ieee802154: introduce wpan_phy_supported Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 06/16] mac802154: check for really changes Alexander Aring
` (10 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds support for phy supported handling for all other already
existing handling 802.15.4 functionality. We assume now a fully 802.15.4
complaint transceiver at phy allocation. If a transceiver can support
802.15.4 default values only, then the values should be overwirtten by
values the transceiver supports. If the transceiver doesn't set the
according hardware flags, we assume the 802.15.4 defaults now which
cannot be changed.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Suggested-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
---
include/net/cfg802154.h | 24 +++++++++++++++++++++++-
include/net/nl802154.h | 22 ++++++++++++++++++++++
net/ieee802154/nl802154.c | 22 +++++++++++++++++-----
net/mac802154/main.c | 26 ++++++++++++++++++++++++++
4 files changed, 88 insertions(+), 6 deletions(-)
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 1941d7a..e53242a 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -61,8 +61,30 @@ struct cfg802154_ops {
struct wpan_dev *wpan_dev, bool mode);
};
+static inline bool
+wpan_phy_supported_bool(bool b, enum nl802154_supported_bool_states st)
+{
+ switch (st) {
+ case NL802154_SUPPORTED_BOOL_TRUE:
+ return b;
+ case NL802154_SUPPORTED_BOOL_FALSE:
+ return !b;
+ case NL802154_SUPPORTED_BOOL_BOTH:
+ return true;
+ default:
+ WARN_ON(1);
+ }
+
+ return false;
+}
+
struct wpan_phy_supported {
- u32 channels[IEEE802154_MAX_PAGE + 1];
+ u32 channels[IEEE802154_MAX_PAGE + 1],
+ cca_modes, cca_opts;
+ enum nl802154_supported_bool_states lbt;
+ u8 min_minbe, max_minbe, min_maxbe, max_maxbe,
+ min_csma_backoffs, max_csma_backoffs;
+ s8 min_frame_retries, max_frame_retries;
};
struct wpan_phy_cca {
diff --git a/include/net/nl802154.h b/include/net/nl802154.h
index f8b5bc9..0552771 100644
--- a/include/net/nl802154.h
+++ b/include/net/nl802154.h
@@ -162,4 +162,26 @@ enum nl802154_cca_opts {
NL802154_CCA_OPT_ATTR_MAX = __NL802154_CCA_OPT_ATTR_AFTER_LAST - 1
};
+/**
+ * enum nl802154_supported_bool_states - bool states for bool capability entry
+ *
+ * @NL802154_SUPPORTED_BOOL_FALSE: indicates to set false
+ * @NL802154_SUPPORTED_BOOL_TRUE: indicates to set true
+ * @__NL802154_SUPPORTED_BOOL_INVALD: reserved
+ * @NL802154_SUPPORTED_BOOL_BOTH: indicates to set true and false
+ * @__NL802154_SUPPORTED_BOOL_AFTER_LAST: Internal
+ * @NL802154_SUPPORTED_BOOL_MAX: highest value for bool states
+ */
+enum nl802154_supported_bool_states {
+ NL802154_SUPPORTED_BOOL_FALSE,
+ NL802154_SUPPORTED_BOOL_TRUE,
+ /* to handle them in a mask */
+ __NL802154_SUPPORTED_BOOL_INVALD,
+ NL802154_SUPPORTED_BOOL_BOTH,
+
+ /* keep last */
+ __NL802154_SUPPORTED_BOOL_AFTER_LAST,
+ NL802154_SUPPORTED_BOOL_MAX = __NL802154_SUPPORTED_BOOL_AFTER_LAST - 1
+};
+
#endif /* __NL802154_H */
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index d271879..fa0c404 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -642,7 +642,9 @@ static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info)
cca.mode = nla_get_u32(info->attrs[NL802154_ATTR_CCA_MODE]);
/* checking 802.15.4 constraints */
- if (cca.mode < NL802154_CCA_ENERGY || cca.mode > NL802154_CCA_ATTR_MAX)
+ if (cca.mode < NL802154_CCA_ENERGY ||
+ cca.mode > NL802154_CCA_ATTR_MAX ||
+ !(rdev->wpan_phy.supported.cca_modes & BIT(cca.mode)))
return -EINVAL;
if (cca.mode == NL802154_CCA_ENERGY_CARRIER) {
@@ -650,7 +652,8 @@ static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info)
return -EINVAL;
cca.opt = nla_get_u32(info->attrs[NL802154_ATTR_CCA_OPT]);
- if (cca.opt > NL802154_CCA_OPT_ATTR_MAX)
+ if (cca.opt > NL802154_CCA_OPT_ATTR_MAX ||
+ !(rdev->wpan_phy.supported.cca_opts & BIT(cca.opt)))
return -EINVAL;
}
@@ -744,7 +747,11 @@ nl802154_set_backoff_exponent(struct sk_buff *skb, struct genl_info *info)
max_be = nla_get_u8(info->attrs[NL802154_ATTR_MAX_BE]);
/* check 802.15.4 constraints */
- if (max_be < 3 || max_be > 8 || min_be > max_be)
+ if (min_be < rdev->wpan_phy.supported.min_minbe ||
+ min_be > rdev->wpan_phy.supported.max_minbe ||
+ max_be < rdev->wpan_phy.supported.min_maxbe ||
+ max_be > rdev->wpan_phy.supported.max_maxbe ||
+ min_be > max_be)
return -EINVAL;
return rdev_set_backoff_exponent(rdev, wpan_dev, min_be, max_be);
@@ -769,7 +776,8 @@ nl802154_set_max_csma_backoffs(struct sk_buff *skb, struct genl_info *info)
info->attrs[NL802154_ATTR_MAX_CSMA_BACKOFFS]);
/* check 802.15.4 constraints */
- if (max_csma_backoffs > 5)
+ if (max_csma_backoffs < rdev->wpan_phy.supported.min_csma_backoffs ||
+ max_csma_backoffs > rdev->wpan_phy.supported.max_csma_backoffs)
return -EINVAL;
return rdev_set_max_csma_backoffs(rdev, wpan_dev, max_csma_backoffs);
@@ -793,7 +801,8 @@ nl802154_set_max_frame_retries(struct sk_buff *skb, struct genl_info *info)
info->attrs[NL802154_ATTR_MAX_FRAME_RETRIES]);
/* check 802.15.4 constraints */
- if (max_frame_retries < -1 || max_frame_retries > 7)
+ if (max_frame_retries < rdev->wpan_phy.supported.min_frame_retries ||
+ max_frame_retries > rdev->wpan_phy.supported.max_frame_retries)
return -EINVAL;
return rdev_set_max_frame_retries(rdev, wpan_dev, max_frame_retries);
@@ -813,6 +822,9 @@ static int nl802154_set_lbt_mode(struct sk_buff *skb, struct genl_info *info)
return -EINVAL;
mode = !!nla_get_u8(info->attrs[NL802154_ATTR_LBT_MODE]);
+ if (!wpan_phy_supported_bool(mode, rdev->wpan_phy.supported.lbt))
+ return -EINVAL;
+
return rdev_set_lbt_mode(rdev, wpan_dev, mode);
}
diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index 68b9667..8834fa7 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -107,6 +107,15 @@ ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops)
skb_queue_head_init(&local->skb_queue);
+ /* init supported flags with 802.15.4 default ranges */
+ phy->supported.max_minbe = 8;
+ phy->supported.min_maxbe = 3;
+ phy->supported.max_maxbe = 8;
+ phy->supported.min_frame_retries = -1;
+ phy->supported.max_frame_retries = 7;
+ phy->supported.max_csma_backoffs = 5;
+ phy->supported.lbt = NL802154_SUPPORTED_BOOL_FALSE;
+
return &local->hw;
}
EXPORT_SYMBOL(ieee802154_alloc_hw);
@@ -155,6 +164,23 @@ int ieee802154_register_hw(struct ieee802154_hw *hw)
ieee802154_setup_wpan_phy_pib(local->phy);
+ if (!(hw->flags & IEEE802154_HW_CSMA_PARAMS)) {
+ local->phy->supported.min_csma_backoffs = 4;
+ local->phy->supported.max_csma_backoffs = 4;
+ local->phy->supported.min_maxbe = 5;
+ local->phy->supported.max_maxbe = 5;
+ local->phy->supported.min_minbe = 3;
+ local->phy->supported.max_minbe = 3;
+ }
+
+ if (!(hw->flags & IEEE802154_HW_FRAME_RETRIES)) {
+ /* TODO should be 3, but our default value is -1 which means
+ * no ARET handling.
+ */
+ local->phy->supported.min_frame_retries = -1;
+ local->phy->supported.max_frame_retries = -1;
+ }
+
rc = wpan_phy_register(local->phy);
if (rc < 0)
goto out_wq;
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 06/16] mac802154: check for really changes
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (4 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 05/16] ieee802154: add several phy supported handling Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 07/16] mac802154: remove check if operation is supported Alexander Aring
` (9 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds check if the value is really changed inside pib/mib.
If a transceiver do support only one value for e.g. max_be then this
will also handle that the driver layer doesn't need to care about
handling to set one value only.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
include/net/cfg802154.h | 12 ++++++++++++
net/mac802154/cfg.c | 26 ++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index e53242a..de00e5c 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -92,6 +92,18 @@ struct wpan_phy_cca {
enum nl802154_cca_opts opt;
};
+static inline bool
+wpan_phy_cca_cmp(const struct wpan_phy_cca *a, const struct wpan_phy_cca *b)
+{
+ if (a->mode != b->mode)
+ return false;
+
+ if (a->mode == NL802154_CCA_ENERGY_CARRIER)
+ return a->opt == b->opt;
+
+ return true;
+}
+
struct wpan_phy {
struct mutex pib_lock;
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index c636015..45c4dc3 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -73,6 +73,10 @@ ieee802154_set_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel)
ASSERT_RTNL();
+ if (wpan_phy->current_page == page &&
+ wpan_phy->current_channel == channel)
+ return 0;
+
ret = drv_set_channel(local, page, channel);
if (!ret) {
wpan_phy->current_page = page;
@@ -91,6 +95,9 @@ ieee802154_set_cca_mode(struct wpan_phy *wpan_phy,
ASSERT_RTNL();
+ if (wpan_phy_cca_cmp(&wpan_phy->cca, cca))
+ return 0;
+
/* check if phy support this setting */
if (!(local->hw.flags & IEEE802154_HW_CCA_MODE))
return -EOPNOTSUPP;
@@ -108,6 +115,9 @@ ieee802154_set_pan_id(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
{
ASSERT_RTNL();
+ if (wpan_dev->pan_id == pan_id)
+ return 0;
+
wpan_dev->pan_id = pan_id;
return 0;
}
@@ -121,6 +131,10 @@ ieee802154_set_backoff_exponent(struct wpan_phy *wpan_phy,
ASSERT_RTNL();
+ if (wpan_dev->min_be == min_be &&
+ wpan_dev->max_be == max_be)
+ return 0;
+
if (!(local->hw.flags & IEEE802154_HW_CSMA_PARAMS))
return -EOPNOTSUPP;
@@ -135,6 +149,9 @@ ieee802154_set_short_addr(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
{
ASSERT_RTNL();
+ if (wpan_dev->short_addr == short_addr)
+ return 0;
+
wpan_dev->short_addr = short_addr;
return 0;
}
@@ -148,6 +165,9 @@ ieee802154_set_max_csma_backoffs(struct wpan_phy *wpan_phy,
ASSERT_RTNL();
+ if (wpan_dev->csma_retries == max_csma_backoffs)
+ return 0;
+
if (!(local->hw.flags & IEEE802154_HW_CSMA_PARAMS))
return -EOPNOTSUPP;
@@ -164,6 +184,9 @@ ieee802154_set_max_frame_retries(struct wpan_phy *wpan_phy,
ASSERT_RTNL();
+ if (wpan_dev->frame_retries == max_frame_retries)
+ return 0;
+
if (!(local->hw.flags & IEEE802154_HW_FRAME_RETRIES))
return -EOPNOTSUPP;
@@ -179,6 +202,9 @@ ieee802154_set_lbt_mode(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
ASSERT_RTNL();
+ if (wpan_dev->lbt == mode)
+ return 0;
+
if (!(local->hw.flags & IEEE802154_HW_LBT))
return -EOPNOTSUPP;
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 07/16] mac802154: remove check if operation is supported
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (5 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 06/16] mac802154: check for really changes Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 08/16] ieee802154: add iftypes capability Alexander Aring
` (8 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch removes the check if operation is supported by driver layer.
This is done now by capabilities flags, if these are valid then the
driver should support the operation, otherwise a WARN_ON occurs.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/mac802154/cfg.c | 24 ------------------------
1 file changed, 24 deletions(-)
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index 45c4dc3..d5290ea 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -98,10 +98,6 @@ ieee802154_set_cca_mode(struct wpan_phy *wpan_phy,
if (wpan_phy_cca_cmp(&wpan_phy->cca, cca))
return 0;
- /* check if phy support this setting */
- if (!(local->hw.flags & IEEE802154_HW_CCA_MODE))
- return -EOPNOTSUPP;
-
ret = drv_set_cca_mode(local, cca);
if (!ret)
wpan_phy->cca = *cca;
@@ -127,17 +123,12 @@ ieee802154_set_backoff_exponent(struct wpan_phy *wpan_phy,
struct wpan_dev *wpan_dev,
u8 min_be, u8 max_be)
{
- struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
-
ASSERT_RTNL();
if (wpan_dev->min_be == min_be &&
wpan_dev->max_be == max_be)
return 0;
- if (!(local->hw.flags & IEEE802154_HW_CSMA_PARAMS))
- return -EOPNOTSUPP;
-
wpan_dev->min_be = min_be;
wpan_dev->max_be = max_be;
return 0;
@@ -161,16 +152,11 @@ ieee802154_set_max_csma_backoffs(struct wpan_phy *wpan_phy,
struct wpan_dev *wpan_dev,
u8 max_csma_backoffs)
{
- struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
-
ASSERT_RTNL();
if (wpan_dev->csma_retries == max_csma_backoffs)
return 0;
- if (!(local->hw.flags & IEEE802154_HW_CSMA_PARAMS))
- return -EOPNOTSUPP;
-
wpan_dev->csma_retries = max_csma_backoffs;
return 0;
}
@@ -180,16 +166,11 @@ ieee802154_set_max_frame_retries(struct wpan_phy *wpan_phy,
struct wpan_dev *wpan_dev,
s8 max_frame_retries)
{
- struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
-
ASSERT_RTNL();
if (wpan_dev->frame_retries == max_frame_retries)
return 0;
- if (!(local->hw.flags & IEEE802154_HW_FRAME_RETRIES))
- return -EOPNOTSUPP;
-
wpan_dev->frame_retries = max_frame_retries;
return 0;
}
@@ -198,16 +179,11 @@ static int
ieee802154_set_lbt_mode(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
bool mode)
{
- struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
-
ASSERT_RTNL();
if (wpan_dev->lbt == mode)
return 0;
- if (!(local->hw.flags & IEEE802154_HW_LBT))
- return -EOPNOTSUPP;
-
wpan_dev->lbt = mode;
return 0;
}
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 08/16] ieee802154: add iftypes capability
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (6 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 07/16] mac802154: remove check if operation is supported Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 09/16] ieee802154: add support for get tx powers Alexander Aring
` (7 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds capability flags for supported interface types.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
include/net/cfg802154.h | 2 +-
net/ieee802154/nl802154.c | 3 ++-
net/mac802154/main.c | 6 ++++++
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index de00e5c..387db39 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -80,7 +80,7 @@ wpan_phy_supported_bool(bool b, enum nl802154_supported_bool_states st)
struct wpan_phy_supported {
u32 channels[IEEE802154_MAX_PAGE + 1],
- cca_modes, cca_opts;
+ cca_modes, cca_opts, iftypes;
enum nl802154_supported_bool_states lbt;
u8 min_minbe, max_minbe, min_maxbe, max_maxbe,
min_csma_backoffs, max_csma_backoffs;
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index fa0c404..00b646d 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -575,7 +575,8 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
if (info->attrs[NL802154_ATTR_IFTYPE]) {
type = nla_get_u32(info->attrs[NL802154_ATTR_IFTYPE]);
- if (type > NL802154_IFTYPE_MAX)
+ if (type > NL802154_IFTYPE_MAX ||
+ !(rdev->wpan_phy.supported.iftypes & BIT(type)))
return -EINVAL;
}
diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index 8834fa7..f3c0a46 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -116,6 +116,9 @@ ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops)
phy->supported.max_csma_backoffs = 5;
phy->supported.lbt = NL802154_SUPPORTED_BOOL_FALSE;
+ /* always supported */
+ phy->supported.iftypes = BIT(NL802154_IFTYPE_NODE);
+
return &local->hw;
}
EXPORT_SYMBOL(ieee802154_alloc_hw);
@@ -181,6 +184,9 @@ int ieee802154_register_hw(struct ieee802154_hw *hw)
local->phy->supported.max_frame_retries = -1;
}
+ if (hw->flags & IEEE802154_HW_PROMISCUOUS)
+ local->phy->supported.iftypes |= BIT(NL802154_IFTYPE_MONITOR);
+
rc = wpan_phy_register(local->phy);
if (rc < 0)
goto out_wq;
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 09/16] ieee802154: add support for get tx powers
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (7 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 08/16] ieee802154: add iftypes capability Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 12:02 ` Phoebe Buckheister
2015-05-06 11:40 ` [PATCHv2 wpan-next 10/16] ieee802154: add support for get cca ed levels Alexander Aring
` (6 subsequent siblings)
15 siblings, 1 reply; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds support for get transmit power levels. The driver needs
to implement a driver ops callback which can iterate over each transmit
power level index. This callback can return zero for successful
iteration, 1 for ending the iteration, 2 for continue the iteration
which an index increment and values below 0 zero if failed.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
include/net/cfg802154.h | 1 +
include/net/mac802154.h | 10 +++++++++-
net/ieee802154/rdev-ops.h | 11 +++++++++++
net/ieee802154/trace.h | 31 +++++++++++++++++++++++++++++++
net/mac802154/cfg.c | 11 +++++++++++
net/mac802154/driver-ops.h | 12 ++++++++++++
6 files changed, 75 insertions(+), 1 deletion(-)
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 387db39..6758e61 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -44,6 +44,7 @@ struct cfg802154_ops {
int (*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
int (*set_cca_mode)(struct wpan_phy *wpan_phy,
const struct wpan_phy_cca *cca);
+ int (*get_tx_powers)(struct wpan_phy *wpan_phy, s32 *mbm, u32 idx);
int (*set_pan_id)(struct wpan_phy *wpan_phy,
struct wpan_dev *wpan_dev, __le16 pan_id);
int (*set_short_addr)(struct wpan_phy *wpan_phy,
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index 3b76aab..be8d3de 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -174,6 +174,12 @@ struct ieee802154_hw {
* Set radio transmit power in mBm. Called with pib_lock held.
* Returns either zero, or negative errno.
*
+ * get_txpowers:
+ * Get radio transmit powers in mBm. Called when rtnl lock is held.
+ * Parameter idx descibes the index of transmit power which is supported.
+ * Returns either zero or negative errno. One should be returned for
+ * indicate to break the iteration of tx power settings.
+ *
* set_lbt
* Enables or disables listen before talk on the device. Called with
* pib_lock held.
@@ -213,7 +219,9 @@ struct ieee802154_ops {
int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
struct ieee802154_hw_addr_filt *filt,
unsigned long changed);
- int (*set_txpower)(struct ieee802154_hw *hw, s32 dbm);
+ int (*set_txpower)(struct ieee802154_hw *hw, s32 mbm);
+ int (*get_tx_powers)(struct ieee802154_hw *hw, s32 *mbm,
+ u32 idx);
int (*set_lbt)(struct ieee802154_hw *hw, bool on);
int (*set_cca_mode)(struct ieee802154_hw *hw,
const struct wpan_phy_cca *cca);
diff --git a/net/ieee802154/rdev-ops.h b/net/ieee802154/rdev-ops.h
index 7b5a9dd..8fc1afe 100644
--- a/net/ieee802154/rdev-ops.h
+++ b/net/ieee802154/rdev-ops.h
@@ -75,6 +75,17 @@ rdev_set_cca_mode(struct cfg802154_registered_device *rdev,
}
static inline int
+rdev_get_tx_powers(struct cfg802154_registered_device *rdev, s32 *mbm, u32 idx)
+{
+ int ret;
+
+ trace_802154_rdev_get_tx_powers(&rdev->wpan_phy, idx);
+ ret = rdev->ops->get_tx_powers(&rdev->wpan_phy, mbm, idx);
+ trace_802154_rdev_return_int_mbm(&rdev->wpan_phy, ret, mbm);
+ return ret;
+}
+
+static inline int
rdev_set_pan_id(struct cfg802154_registered_device *rdev,
struct wpan_dev *wpan_dev, __le16 pan_id)
{
diff --git a/net/ieee802154/trace.h b/net/ieee802154/trace.h
index 5ac25eb..3c54b5e 100644
--- a/net/ieee802154/trace.h
+++ b/net/ieee802154/trace.h
@@ -108,6 +108,37 @@ TRACE_EVENT(802154_rdev_set_cca_mode,
WPAN_CCA_PR_ARG)
);
+TRACE_EVENT(802154_rdev_get_tx_powers,
+ TP_PROTO(struct wpan_phy *wpan_phy, u32 idx),
+ TP_ARGS(wpan_phy, idx),
+ TP_STRUCT__entry(
+ WPAN_PHY_ENTRY
+ __field(u32, idx)
+ ),
+ TP_fast_assign(
+ WPAN_PHY_ASSIGN;
+ __entry->idx = idx;
+ ),
+ TP_printk(WPAN_PHY_PR_FMT ", idx: %d", WPAN_PHY_PR_ARG, __entry->idx)
+);
+
+TRACE_EVENT(802154_rdev_return_int_mbm,
+ TP_PROTO(struct wpan_phy *wpan_phy, int ret, s32 *mbm),
+ TP_ARGS(wpan_phy, ret, mbm),
+ TP_STRUCT__entry(
+ WPAN_PHY_ENTRY
+ __field(int, ret)
+ __field(s32, mbm)
+ ),
+ TP_fast_assign(
+ WPAN_PHY_ASSIGN;
+ __entry->ret = ret;
+ __entry->mbm = *mbm;
+ ),
+ TP_printk(WPAN_PHY_PR_FMT ", returned: %d, mbm: %d", WPAN_PHY_PR_ARG,
+ __entry->ret, __entry->mbm)
+);
+
DECLARE_EVENT_CLASS(802154_le16_template,
TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
__le16 le16arg),
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index d5290ea..4228069 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -106,6 +106,16 @@ ieee802154_set_cca_mode(struct wpan_phy *wpan_phy,
}
static int
+ieee802154_get_tx_powers(struct wpan_phy *wpan_phy, s32 *mbm, u32 idx)
+{
+ struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
+
+ ASSERT_RTNL();
+
+ return drv_get_tx_powers(local, mbm, idx);
+}
+
+static int
ieee802154_set_pan_id(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
__le16 pan_id)
{
@@ -195,6 +205,7 @@ const struct cfg802154_ops mac802154_config_ops = {
.del_virtual_intf = ieee802154_del_iface,
.set_channel = ieee802154_set_channel,
.set_cca_mode = ieee802154_set_cca_mode,
+ .get_tx_powers = ieee802154_get_tx_powers,
.set_pan_id = ieee802154_set_pan_id,
.set_short_addr = ieee802154_set_short_addr,
.set_backoff_exponent = ieee802154_set_backoff_exponent,
diff --git a/net/mac802154/driver-ops.h b/net/mac802154/driver-ops.h
index caecd5f..27a59dc 100644
--- a/net/mac802154/driver-ops.h
+++ b/net/mac802154/driver-ops.h
@@ -70,6 +70,18 @@ static inline int drv_set_tx_power(struct ieee802154_local *local, s32 mbm)
return local->ops->set_txpower(&local->hw, mbm);
}
+static inline int
+drv_get_tx_powers(struct ieee802154_local *local, s32 *mbm, u32 idx)
+{
+ might_sleep();
+
+ /* if not implemented indicate a empty list */
+ if (!local->ops->get_tx_powers)
+ return 1;
+
+ return local->ops->get_tx_powers(&local->hw, mbm, idx);
+}
+
static inline int drv_set_cca_mode(struct ieee802154_local *local,
const struct wpan_phy_cca *cca)
{
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCHv2 wpan-next 09/16] ieee802154: add support for get tx powers
2015-05-06 11:40 ` [PATCHv2 wpan-next 09/16] ieee802154: add support for get tx powers Alexander Aring
@ 2015-05-06 12:02 ` Phoebe Buckheister
2015-05-06 13:19 ` Alexander Aring
0 siblings, 1 reply; 19+ messages in thread
From: Phoebe Buckheister @ 2015-05-06 12:02 UTC (permalink / raw)
To: Alexander Aring; +Cc: linux-wpan, kernel
On Wed, 6 May 2015 13:40:21 +0200
Alexander Aring <alex.aring@gmail.com> wrote:
> This patch adds support for get transmit power levels. The driver
> needs to implement a driver ops callback which can iterate over each
> transmit power level index. This callback can return zero for
> successful iteration, 1 for ending the iteration, 2 for continue the
> iteration which an index increment and values below 0 zero if failed.
Now that every tx power value can be represented, why not just return a
const s32* and a number of elements in that array?
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> ---
> include/net/cfg802154.h | 1 +
> include/net/mac802154.h | 10 +++++++++-
> net/ieee802154/rdev-ops.h | 11 +++++++++++
> net/ieee802154/trace.h | 31 +++++++++++++++++++++++++++++++
> net/mac802154/cfg.c | 11 +++++++++++
> net/mac802154/driver-ops.h | 12 ++++++++++++
> 6 files changed, 75 insertions(+), 1 deletion(-)
>
> diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
> index 387db39..6758e61 100644
> --- a/include/net/cfg802154.h
> +++ b/include/net/cfg802154.h
> @@ -44,6 +44,7 @@ struct cfg802154_ops {
> int (*set_channel)(struct wpan_phy *wpan_phy, u8
> page, u8 channel); int (*set_cca_mode)(struct wpan_phy
> *wpan_phy, const struct wpan_phy_cca *cca);
> + int (*get_tx_powers)(struct wpan_phy *wpan_phy, s32
> *mbm, u32 idx); int (*set_pan_id)(struct wpan_phy *wpan_phy,
> struct wpan_dev *wpan_dev, __le16
> pan_id); int (*set_short_addr)(struct wpan_phy *wpan_phy,
> diff --git a/include/net/mac802154.h b/include/net/mac802154.h
> index 3b76aab..be8d3de 100644
> --- a/include/net/mac802154.h
> +++ b/include/net/mac802154.h
> @@ -174,6 +174,12 @@ struct ieee802154_hw {
> * Set radio transmit power in mBm. Called with pib_lock
> held.
> * Returns either zero, or negative errno.
> *
> + * get_txpowers:
> + * Get radio transmit powers in mBm. Called when rtnl lock
> is held.
> + * Parameter idx descibes the index of transmit power which
> is supported.
> + * Returns either zero or negative errno. One should be
> returned for
> + * indicate to break the iteration of tx power settings.
> + *
> * set_lbt
> * Enables or disables listen before talk on the device.
> Called with
> * pib_lock held.
> @@ -213,7 +219,9 @@ struct ieee802154_ops {
> int (*set_hw_addr_filt)(struct ieee802154_hw
> *hw, struct ieee802154_hw_addr_filt *filt,
> unsigned long changed);
> - int (*set_txpower)(struct ieee802154_hw *hw,
> s32 dbm);
> + int (*set_txpower)(struct ieee802154_hw *hw,
> s32 mbm);
> + int (*get_tx_powers)(struct ieee802154_hw
> *hw, s32 *mbm,
> + u32 idx);
> int (*set_lbt)(struct ieee802154_hw *hw, bool
> on); int (*set_cca_mode)(struct ieee802154_hw *hw,
> const struct wpan_phy_cca
> *cca); diff --git a/net/ieee802154/rdev-ops.h
> b/net/ieee802154/rdev-ops.h index 7b5a9dd..8fc1afe 100644
> --- a/net/ieee802154/rdev-ops.h
> +++ b/net/ieee802154/rdev-ops.h
> @@ -75,6 +75,17 @@ rdev_set_cca_mode(struct
> cfg802154_registered_device *rdev, }
>
> static inline int
> +rdev_get_tx_powers(struct cfg802154_registered_device *rdev, s32
> *mbm, u32 idx) +{
> + int ret;
> +
> + trace_802154_rdev_get_tx_powers(&rdev->wpan_phy, idx);
> + ret = rdev->ops->get_tx_powers(&rdev->wpan_phy, mbm, idx);
> + trace_802154_rdev_return_int_mbm(&rdev->wpan_phy, ret, mbm);
> + return ret;
> +}
> +
> +static inline int
> rdev_set_pan_id(struct cfg802154_registered_device *rdev,
> struct wpan_dev *wpan_dev, __le16 pan_id)
> {
> diff --git a/net/ieee802154/trace.h b/net/ieee802154/trace.h
> index 5ac25eb..3c54b5e 100644
> --- a/net/ieee802154/trace.h
> +++ b/net/ieee802154/trace.h
> @@ -108,6 +108,37 @@ TRACE_EVENT(802154_rdev_set_cca_mode,
> WPAN_CCA_PR_ARG)
> );
>
> +TRACE_EVENT(802154_rdev_get_tx_powers,
> + TP_PROTO(struct wpan_phy *wpan_phy, u32 idx),
> + TP_ARGS(wpan_phy, idx),
> + TP_STRUCT__entry(
> + WPAN_PHY_ENTRY
> + __field(u32, idx)
> + ),
> + TP_fast_assign(
> + WPAN_PHY_ASSIGN;
> + __entry->idx = idx;
> + ),
> + TP_printk(WPAN_PHY_PR_FMT ", idx: %d", WPAN_PHY_PR_ARG,
> __entry->idx) +);
> +
> +TRACE_EVENT(802154_rdev_return_int_mbm,
> + TP_PROTO(struct wpan_phy *wpan_phy, int ret, s32 *mbm),
> + TP_ARGS(wpan_phy, ret, mbm),
> + TP_STRUCT__entry(
> + WPAN_PHY_ENTRY
> + __field(int, ret)
> + __field(s32, mbm)
> + ),
> + TP_fast_assign(
> + WPAN_PHY_ASSIGN;
> + __entry->ret = ret;
> + __entry->mbm = *mbm;
> + ),
> + TP_printk(WPAN_PHY_PR_FMT ", returned: %d, mbm: %d",
> WPAN_PHY_PR_ARG,
> + __entry->ret, __entry->mbm)
> +);
> +
> DECLARE_EVENT_CLASS(802154_le16_template,
> TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev
> *wpan_dev, __le16 le16arg),
> diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
> index d5290ea..4228069 100644
> --- a/net/mac802154/cfg.c
> +++ b/net/mac802154/cfg.c
> @@ -106,6 +106,16 @@ ieee802154_set_cca_mode(struct wpan_phy
> *wpan_phy, }
>
> static int
> +ieee802154_get_tx_powers(struct wpan_phy *wpan_phy, s32 *mbm, u32
> idx) +{
> + struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
> +
> + ASSERT_RTNL();
> +
> + return drv_get_tx_powers(local, mbm, idx);
> +}
> +
> +static int
> ieee802154_set_pan_id(struct wpan_phy *wpan_phy, struct wpan_dev
> *wpan_dev, __le16 pan_id)
> {
> @@ -195,6 +205,7 @@ const struct cfg802154_ops mac802154_config_ops =
> { .del_virtual_intf = ieee802154_del_iface,
> .set_channel = ieee802154_set_channel,
> .set_cca_mode = ieee802154_set_cca_mode,
> + .get_tx_powers = ieee802154_get_tx_powers,
> .set_pan_id = ieee802154_set_pan_id,
> .set_short_addr = ieee802154_set_short_addr,
> .set_backoff_exponent = ieee802154_set_backoff_exponent,
> diff --git a/net/mac802154/driver-ops.h b/net/mac802154/driver-ops.h
> index caecd5f..27a59dc 100644
> --- a/net/mac802154/driver-ops.h
> +++ b/net/mac802154/driver-ops.h
> @@ -70,6 +70,18 @@ static inline int drv_set_tx_power(struct
> ieee802154_local *local, s32 mbm) return
> local->ops->set_txpower(&local->hw, mbm); }
>
> +static inline int
> +drv_get_tx_powers(struct ieee802154_local *local, s32 *mbm, u32 idx)
> +{
> + might_sleep();
> +
> + /* if not implemented indicate a empty list */
> + if (!local->ops->get_tx_powers)
> + return 1;
> +
> + return local->ops->get_tx_powers(&local->hw, mbm, idx);
> +}
> +
> static inline int drv_set_cca_mode(struct ieee802154_local *local,
> const struct wpan_phy_cca *cca)
> {
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCHv2 wpan-next 09/16] ieee802154: add support for get tx powers
2015-05-06 12:02 ` Phoebe Buckheister
@ 2015-05-06 13:19 ` Alexander Aring
0 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 13:19 UTC (permalink / raw)
To: Phoebe Buckheister; +Cc: linux-wpan, kernel
On Wed, May 06, 2015 at 02:02:04PM +0200, Phoebe Buckheister wrote:
> On Wed, 6 May 2015 13:40:21 +0200
> Alexander Aring <alex.aring@gmail.com> wrote:
>
> > This patch adds support for get transmit power levels. The driver
> > needs to implement a driver ops callback which can iterate over each
> > transmit power level index. This callback can return zero for
> > successful iteration, 1 for ending the iteration, 2 for continue the
> > iteration which an index increment and values below 0 zero if failed.
>
> Now that every tx power value can be represented, why not just return a
> const s32* and a number of elements in that array?
ok, I will try to implement it, sounds better.
I followed the first implementation like the station dump in wireless
[0]. (Some example to print a list over netlink) Now I detect that they
use "-ENOENT" for the last entry which should be better than "1".
Nevertheless I think this is only good for dynamic changeable list like
the use case for [0]. It's very unlikely that the capabilities changes
while using of the stack.
- Alex
[0] http://lxr.free-electrons.com/source/net/wireless/nl80211.c#L3876
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCHv2 wpan-next 10/16] ieee802154: add support for get cca ed levels
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (8 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 09/16] ieee802154: add support for get tx powers Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 11/16] at86rf230: set cca_modes supported flags Alexander Aring
` (5 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds support for get cca energy detection levels. The driver
needs to implement a driver ops callback which can iterate over each
transmit power level index. This callback can return zero for successful
iteration, 1 for ending the iteration, 2 for continue the iteration
which an index increment and values below 0 zero if failed.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
include/net/cfg802154.h | 2 ++
include/net/mac802154.h | 8 ++++++++
net/ieee802154/rdev-ops.h | 12 ++++++++++++
net/ieee802154/trace.h | 14 ++++++++++++++
net/mac802154/cfg.c | 11 +++++++++++
net/mac802154/driver-ops.h | 12 ++++++++++++
6 files changed, 59 insertions(+)
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 6758e61..3219ca9 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -45,6 +45,8 @@ struct cfg802154_ops {
int (*set_cca_mode)(struct wpan_phy *wpan_phy,
const struct wpan_phy_cca *cca);
int (*get_tx_powers)(struct wpan_phy *wpan_phy, s32 *mbm, u32 idx);
+ int (*get_cca_ed_levels)(struct wpan_phy *wpan_phy, s32 *mbm,
+ u32 idx);
int (*set_pan_id)(struct wpan_phy *wpan_phy,
struct wpan_dev *wpan_dev, __le16 pan_id);
int (*set_short_addr)(struct wpan_phy *wpan_phy,
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index be8d3de..2d2afa0 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -180,6 +180,12 @@ struct ieee802154_hw {
* Returns either zero or negative errno. One should be returned for
* indicate to break the iteration of tx power settings.
*
+ * get_cca_ed_levels
+ * Get cca ed levels in dBm for cca mode 3. Called when rtnl lock is
+ * held. Parameter idx descibes the index of cca ed levels which is
+ * supported. Returns either zero or negative errno. One should be
+ * returned to break the iteration of cca ed levels setting.
+ *
* set_lbt
* Enables or disables listen before talk on the device. Called with
* pib_lock held.
@@ -222,6 +228,8 @@ struct ieee802154_ops {
int (*set_txpower)(struct ieee802154_hw *hw, s32 mbm);
int (*get_tx_powers)(struct ieee802154_hw *hw, s32 *mbm,
u32 idx);
+ int (*get_cca_ed_levels)(struct ieee802154_hw *hw,
+ s32 *dbm, u32 idx);
int (*set_lbt)(struct ieee802154_hw *hw, bool on);
int (*set_cca_mode)(struct ieee802154_hw *hw,
const struct wpan_phy_cca *cca);
diff --git a/net/ieee802154/rdev-ops.h b/net/ieee802154/rdev-ops.h
index 8fc1afe..658afc6 100644
--- a/net/ieee802154/rdev-ops.h
+++ b/net/ieee802154/rdev-ops.h
@@ -75,6 +75,18 @@ rdev_set_cca_mode(struct cfg802154_registered_device *rdev,
}
static inline int
+rdev_get_cca_ed_levels(struct cfg802154_registered_device *rdev, s32 *mbm,
+ u32 idx)
+{
+ int ret;
+
+ trace_802154_rdev_get_cca_ed_levels(&rdev->wpan_phy, idx);
+ ret = rdev->ops->get_cca_ed_levels(&rdev->wpan_phy, mbm, idx);
+ trace_802154_rdev_return_int_mbm(&rdev->wpan_phy, ret, mbm);
+ return ret;
+}
+
+static inline int
rdev_get_tx_powers(struct cfg802154_registered_device *rdev, s32 *mbm, u32 idx)
{
int ret;
diff --git a/net/ieee802154/trace.h b/net/ieee802154/trace.h
index 3c54b5e..d4bcdba 100644
--- a/net/ieee802154/trace.h
+++ b/net/ieee802154/trace.h
@@ -108,6 +108,20 @@ TRACE_EVENT(802154_rdev_set_cca_mode,
WPAN_CCA_PR_ARG)
);
+TRACE_EVENT(802154_rdev_get_cca_ed_levels,
+ TP_PROTO(struct wpan_phy *wpan_phy, u32 idx),
+ TP_ARGS(wpan_phy, idx),
+ TP_STRUCT__entry(
+ WPAN_PHY_ENTRY
+ __field(u32, idx)
+ ),
+ TP_fast_assign(
+ WPAN_PHY_ASSIGN;
+ __entry->idx = idx;
+ ),
+ TP_printk(WPAN_PHY_PR_FMT ", idx: %d", WPAN_PHY_PR_ARG, __entry->idx)
+);
+
TRACE_EVENT(802154_rdev_get_tx_powers,
TP_PROTO(struct wpan_phy *wpan_phy, u32 idx),
TP_ARGS(wpan_phy, idx),
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index 4228069..b839f6d 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -106,6 +106,16 @@ ieee802154_set_cca_mode(struct wpan_phy *wpan_phy,
}
static int
+ieee802154_get_cca_ed_levels(struct wpan_phy *wpan_phy, s32 *mbm, u32 idx)
+{
+ struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
+
+ ASSERT_RTNL();
+
+ return drv_get_cca_ed_levels(local, mbm, idx);
+}
+
+static int
ieee802154_get_tx_powers(struct wpan_phy *wpan_phy, s32 *mbm, u32 idx)
{
struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
@@ -206,6 +216,7 @@ const struct cfg802154_ops mac802154_config_ops = {
.set_channel = ieee802154_set_channel,
.set_cca_mode = ieee802154_set_cca_mode,
.get_tx_powers = ieee802154_get_tx_powers,
+ .get_cca_ed_levels = ieee802154_get_cca_ed_levels,
.set_pan_id = ieee802154_set_pan_id,
.set_short_addr = ieee802154_set_short_addr,
.set_backoff_exponent = ieee802154_set_backoff_exponent,
diff --git a/net/mac802154/driver-ops.h b/net/mac802154/driver-ops.h
index 27a59dc..75e1f2a 100644
--- a/net/mac802154/driver-ops.h
+++ b/net/mac802154/driver-ops.h
@@ -120,6 +120,18 @@ drv_set_cca_ed_level(struct ieee802154_local *local, s32 mbm)
return local->ops->set_cca_ed_level(&local->hw, mbm);
}
+static inline int
+drv_get_cca_ed_levels(struct ieee802154_local *local, s32 *mbm, u32 idx)
+{
+ might_sleep();
+
+ /* if not implemented indicate a empty list */
+ if (!local->ops->get_tx_powers)
+ return 1;
+
+ return local->ops->get_cca_ed_levels(&local->hw, mbm, idx);
+}
+
static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id)
{
struct ieee802154_hw_addr_filt filt;
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 11/16] at86rf230: set cca_modes supported flags
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (9 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 10/16] ieee802154: add support for get cca ed levels Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 12/16] at86rf230: add reset states of tx power level Alexander Aring
` (4 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch sets the at86rf230 supported cca modes. In case of at86rf212
it also can support listen before transmit.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 151d57f..e2be571 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1569,6 +1569,11 @@ at86rf230_detect_device(struct at86rf230_local *lp)
IEEE802154_HW_TXPOWER | IEEE802154_HW_ARET |
IEEE802154_HW_AFILT | IEEE802154_HW_PROMISCUOUS;
+ lp->hw->phy->supported.cca_modes = BIT(NL802154_CCA_ENERGY) |
+ BIT(NL802154_CCA_CARRIER) | BIT(NL802154_CCA_ENERGY_CARRIER);
+ lp->hw->phy->supported.cca_opts = BIT(NL802154_CCA_OPT_ENERGY_CARRIER_AND) |
+ BIT(NL802154_CCA_OPT_ENERGY_CARRIER_OR);
+
lp->hw->phy->cca.mode = NL802154_CCA_ENERGY;
switch (part) {
@@ -1591,6 +1596,7 @@ at86rf230_detect_device(struct at86rf230_local *lp)
lp->hw->phy->supported.channels[2] = 0x00007FF;
lp->hw->phy->current_channel = 5;
lp->hw->phy->symbol_duration = 25;
+ lp->hw->phy->supported.lbt = NL802154_SUPPORTED_BOOL_BOTH;
break;
case 11:
chip = "at86rf233";
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 12/16] at86rf230: add reset states of tx power level
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (10 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 11/16] at86rf230: set cca_modes supported flags Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 13/16] at86rf230: rework tx power support Alexander Aring
` (3 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds the reset states for tx power levels after running reset
procedure.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index e2be571..14e743c 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1587,6 +1587,7 @@ at86rf230_detect_device(struct at86rf230_local *lp)
lp->hw->phy->supported.channels[0] = 0x7FFF800;
lp->hw->phy->current_channel = 11;
lp->hw->phy->symbol_duration = 16;
+ lp->hw->phy->transmit_power = 300;
break;
case 7:
chip = "at86rf212";
@@ -1597,6 +1598,7 @@ at86rf230_detect_device(struct at86rf230_local *lp)
lp->hw->phy->current_channel = 5;
lp->hw->phy->symbol_duration = 25;
lp->hw->phy->supported.lbt = NL802154_SUPPORTED_BOOL_BOTH;
+ lp->hw->phy->transmit_power = 500;
break;
case 11:
chip = "at86rf233";
@@ -1604,6 +1606,7 @@ at86rf230_detect_device(struct at86rf230_local *lp)
lp->hw->phy->supported.channels[0] = 0x7FFF800;
lp->hw->phy->current_channel = 13;
lp->hw->phy->symbol_duration = 16;
+ lp->hw->phy->transmit_power = 400;
break;
default:
chip = "unknown";
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 13/16] at86rf230: rework tx power support
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (11 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 12/16] at86rf230: add reset states of tx power level Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 14/16] at86rf230: rework tx cca energy detection level Alexander Aring
` (2 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds support for get transmit power levels and reworks the
set of transmit power levels which was broken before.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 94 +++++++++++++++++++++++++++++++++-----
1 file changed, 83 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 14e743c..10cb6a4 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -48,9 +48,12 @@ struct at86rf2xx_chip_data {
u16 t_frame;
u16 t_p_ack;
int rssi_base_val;
+ const s32 *tx_powers_table;
int (*set_channel)(struct at86rf230_local *, u8, u8);
int (*get_desense_steps)(struct at86rf230_local *, s32);
+ int (*set_txpower)(struct at86rf230_local *, s32);
+ int (*get_txpowers)(struct at86rf230_local *, s32 *, u32);
};
#define AT86RF2XX_MAX_BUF (127 + 3)
@@ -124,9 +127,12 @@ struct at86rf230_local {
#define SR_IRQ_2_EXT_EN 0x04, 0x40, 6
#define SR_PA_EXT_EN 0x04, 0x80, 7
#define RG_PHY_TX_PWR (0x05)
-#define SR_TX_PWR 0x05, 0x0f, 0
-#define SR_PA_LT 0x05, 0x30, 4
-#define SR_PA_BUF_LT 0x05, 0xc0, 6
+#define SR_TX_PWR_23X 0x05, 0x0f, 0
+#define SR_PA_LT_230 0x05, 0x30, 4
+#define SR_PA_BUF_LT_230 0x05, 0xc0, 6
+#define SR_TX_PWR_212 0x05, 0x1f, 0
+#define SR_GC_PA_212 0x05, 0x60, 5
+#define SR_PA_BOOST_LT_212 0x05, 0x80, 7
#define RG_PHY_RSSI (0x06)
#define SR_RSSI 0x06, 0x1f, 0
#define SR_RND_VALUE 0x06, 0x60, 5
@@ -1193,12 +1199,34 @@ at86rf230_set_hw_addr_filt(struct ieee802154_hw *hw,
return 0;
}
+#define AT86RF23X_MAX_TX_POWERS 0xF
+static const s32 at86rf233_powers[AT86RF23X_MAX_TX_POWERS + 1] = {
+ 400, 370, 340, 300, 250, 200, 100, 0, -100, -200, -300, -400, -600,
+ -800, -1200, -1700,
+};
+
+static const s32 at86rf231_powers[AT86RF23X_MAX_TX_POWERS + 1] = {
+ 300, 280, 230, 180, 130, 70, 0, -100, -200, -300, -400, -500, -700,
+ -900, -1200, -1700,
+};
+
static int
-at86rf230_set_txpower(struct ieee802154_hw *hw, s32 mbm)
+at86rf23x_set_txpower(struct at86rf230_local *lp, s32 mbm)
{
- struct at86rf230_local *lp = hw->priv;
- s8 db = mbm / 100;
+ u32 i;
+ for (i = 0; i < AT86RF23X_MAX_TX_POWERS; i++) {
+ if (lp->data->tx_powers_table[i] == mbm)
+ return at86rf230_write_subreg(lp, SR_TX_PWR_23X, i);
+ }
+
+ return -EINVAL;
+}
+
+static int
+at86rf212_set_txpower(struct at86rf230_local *lp, s32 mbm)
+{
+ s8 db = mbm / 100;
/* typical maximum output is 5dBm with RG_PHY_TX_PWR 0x60, lower five
* bits decrease power in 1dB steps. 0x60 represents extra PA gain of
* 0dB.
@@ -1208,9 +1236,44 @@ at86rf230_set_txpower(struct ieee802154_hw *hw, s32 mbm)
if (db > 5 || db < -26)
return -EINVAL;
- db = -(db - 5);
+ return at86rf230_write_subreg(lp, SR_TX_PWR_212, -(db - 5));
+}
+
+static int
+at86rf230_set_txpower(struct ieee802154_hw *hw, s32 mbm)
+{
+ struct at86rf230_local *lp = hw->priv;
+
+ return lp->data->set_txpower(lp, mbm);
+}
+
+static int
+at86rf23x_get_txpowers(struct at86rf230_local *lp, s32 *mbm, u32 idx)
+{
+ if (idx > AT86RF23X_MAX_TX_POWERS)
+ return 1;
+
+ *mbm = lp->data->tx_powers_table[idx];
+ return 0;
+}
+
+#define AT86RF212_MAX_TX_POWERS 0x1F
+static int
+at86rf212_get_txpowers(struct at86rf230_local *lp, s32 *mbm, u32 idx)
+{
+ if (idx > AT86RF212_MAX_TX_POWERS)
+ return 1;
+
+ *mbm = (5 - idx) * 100;
+ return 0;
+}
+
+static int
+at86rf230_get_txpowers(struct ieee802154_hw *hw, s32 *mbm, u32 idx)
+{
+ struct at86rf230_local *lp = hw->priv;
- return __at86rf230_write(lp, RG_PHY_TX_PWR, 0x60 | db);
+ return lp->data->get_txpowers(lp, mbm, idx);
}
static int
@@ -1349,6 +1412,7 @@ static const struct ieee802154_ops at86rf230_ops = {
.stop = at86rf230_stop,
.set_hw_addr_filt = at86rf230_set_hw_addr_filt,
.set_txpower = at86rf230_set_txpower,
+ .get_tx_powers = at86rf230_get_txpowers,
.set_lbt = at86rf230_set_lbt,
.set_cca_mode = at86rf230_set_cca_mode,
.set_cca_ed_level = at86rf230_set_cca_ed_level,
@@ -1366,8 +1430,11 @@ static struct at86rf2xx_chip_data at86rf233_data = {
.t_frame = 4096,
.t_p_ack = 545,
.rssi_base_val = -91,
+ .tx_powers_table = at86rf233_powers,
.set_channel = at86rf23x_set_channel,
- .get_desense_steps = at86rf23x_get_desens_steps
+ .get_desense_steps = at86rf23x_get_desens_steps,
+ .set_txpower = at86rf23x_set_txpower,
+ .get_txpowers = at86rf23x_get_txpowers,
};
static struct at86rf2xx_chip_data at86rf231_data = {
@@ -1379,8 +1446,11 @@ static struct at86rf2xx_chip_data at86rf231_data = {
.t_frame = 4096,
.t_p_ack = 545,
.rssi_base_val = -91,
+ .tx_powers_table = at86rf231_powers,
.set_channel = at86rf23x_set_channel,
- .get_desense_steps = at86rf23x_get_desens_steps
+ .get_desense_steps = at86rf23x_get_desens_steps,
+ .set_txpower = at86rf23x_set_txpower,
+ .get_txpowers = at86rf23x_get_txpowers,
};
static struct at86rf2xx_chip_data at86rf212_data = {
@@ -1393,7 +1463,9 @@ static struct at86rf2xx_chip_data at86rf212_data = {
.t_p_ack = 545,
.rssi_base_val = -100,
.set_channel = at86rf212_set_channel,
- .get_desense_steps = at86rf212_get_desens_steps
+ .get_desense_steps = at86rf212_get_desens_steps,
+ .set_txpower = at86rf212_set_txpower,
+ .get_txpowers = at86rf212_get_txpowers,
};
static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim)
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 14/16] at86rf230: rework tx cca energy detection level
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (12 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 13/16] at86rf230: rework tx power support Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 15/16] ieee802154: check transmit power before driver layer Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 16/16] nl802154: add support for dump phy capabilities Alexander Aring
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch reworks the cca energy detection level handling. This
contains a calculation which works on all transceiver types and
add support for dump cca energy detection levels.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 10cb6a4..165c4cd 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -51,7 +51,6 @@ struct at86rf2xx_chip_data {
const s32 *tx_powers_table;
int (*set_channel)(struct at86rf230_local *, u8, u8);
- int (*get_desense_steps)(struct at86rf230_local *, s32);
int (*set_txpower)(struct at86rf230_local *, s32);
int (*get_txpowers)(struct at86rf230_local *, s32 *, u32);
};
@@ -1319,28 +1318,32 @@ at86rf230_set_cca_mode(struct ieee802154_hw *hw,
}
static int
-at86rf212_get_desens_steps(struct at86rf230_local *lp, s32 level)
+at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
{
- return (level - lp->data->rssi_base_val) * 100 / 207;
-}
+ struct at86rf230_local *lp = hw->priv;
+ s32 level = mbm / 100;
-static int
-at86rf23x_get_desens_steps(struct at86rf230_local *lp, s32 level)
-{
- return (level - lp->data->rssi_base_val) / 2;
+ /* backwards compatible for old interface, should be removed */
+ if (level < lp->data->rssi_base_val ||
+ level > lp->data->rssi_base_val + 2 * 0xF)
+ return -EINVAL;
+
+ return at86rf230_write_subreg(lp, SR_CCA_ED_THRES,
+ (level - lp->data->rssi_base_val) / 2);
}
+#define AT86RF230_MAX_ED_LEVELS_IDX 0xF
+
static int
-at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
+at86rf230_get_cca_ed_levels(struct ieee802154_hw *hw, s32 *mbm, u32 idx)
{
struct at86rf230_local *lp = hw->priv;
- s32 level = mbm / 100;
- if (level < lp->data->rssi_base_val || level > 30)
- return -EINVAL;
+ if (idx > AT86RF230_MAX_ED_LEVELS_IDX)
+ return 1;
- return at86rf230_write_subreg(lp, SR_CCA_ED_THRES,
- lp->data->get_desense_steps(lp, level));
+ *mbm = (lp->data->rssi_base_val + 2 * idx) * 100;
+ return 0;
}
static int
@@ -1413,6 +1416,7 @@ static const struct ieee802154_ops at86rf230_ops = {
.set_hw_addr_filt = at86rf230_set_hw_addr_filt,
.set_txpower = at86rf230_set_txpower,
.get_tx_powers = at86rf230_get_txpowers,
+ .get_cca_ed_levels = at86rf230_get_cca_ed_levels,
.set_lbt = at86rf230_set_lbt,
.set_cca_mode = at86rf230_set_cca_mode,
.set_cca_ed_level = at86rf230_set_cca_ed_level,
@@ -1432,7 +1436,6 @@ static struct at86rf2xx_chip_data at86rf233_data = {
.rssi_base_val = -91,
.tx_powers_table = at86rf233_powers,
.set_channel = at86rf23x_set_channel,
- .get_desense_steps = at86rf23x_get_desens_steps,
.set_txpower = at86rf23x_set_txpower,
.get_txpowers = at86rf23x_get_txpowers,
};
@@ -1448,7 +1451,6 @@ static struct at86rf2xx_chip_data at86rf231_data = {
.rssi_base_val = -91,
.tx_powers_table = at86rf231_powers,
.set_channel = at86rf23x_set_channel,
- .get_desense_steps = at86rf23x_get_desens_steps,
.set_txpower = at86rf23x_set_txpower,
.get_txpowers = at86rf23x_get_txpowers,
};
@@ -1463,7 +1465,6 @@ static struct at86rf2xx_chip_data at86rf212_data = {
.t_p_ack = 545,
.rssi_base_val = -100,
.set_channel = at86rf212_set_channel,
- .get_desense_steps = at86rf212_get_desens_steps,
.set_txpower = at86rf212_set_txpower,
.get_txpowers = at86rf212_get_txpowers,
};
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 15/16] ieee802154: check transmit power before driver layer
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (13 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 14/16] at86rf230: rework tx cca energy detection level Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 16/16] nl802154: add support for dump phy capabilities Alexander Aring
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch moves the validation check of transmit power mbm values to
the netlink layer by using the callback to get all transmit power levels
mbm values.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 22 +++-----------------
net/mac802154/mac_cmd.c | 41 ++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 19 deletions(-)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 165c4cd..2484f16 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1225,17 +1225,7 @@ at86rf23x_set_txpower(struct at86rf230_local *lp, s32 mbm)
static int
at86rf212_set_txpower(struct at86rf230_local *lp, s32 mbm)
{
- s8 db = mbm / 100;
- /* typical maximum output is 5dBm with RG_PHY_TX_PWR 0x60, lower five
- * bits decrease power in 1dB steps. 0x60 represents extra PA gain of
- * 0dB.
- * thus, supported values for db range from -26 to 5, for 31dB of
- * reduction to 0dB of reduction.
- */
- if (db > 5 || db < -26)
- return -EINVAL;
-
- return at86rf230_write_subreg(lp, SR_TX_PWR_212, -(db - 5));
+ return at86rf230_write_subreg(lp, SR_TX_PWR_212, -((mbm / 100) - 5));
}
static int
@@ -1321,15 +1311,9 @@ static int
at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
{
struct at86rf230_local *lp = hw->priv;
- s32 level = mbm / 100;
-
- /* backwards compatible for old interface, should be removed */
- if (level < lp->data->rssi_base_val ||
- level > lp->data->rssi_base_val + 2 * 0xF)
- return -EINVAL;
+ s32 val = ((mbm / 100) - lp->data->rssi_base_val) / 2;
- return at86rf230_write_subreg(lp, SR_CCA_ED_THRES,
- (level - lp->data->rssi_base_val) / 2);
+ return at86rf230_write_subreg(lp, SR_CCA_ED_THRES, val);
}
#define AT86RF230_MAX_ED_LEVELS_IDX 0xF
diff --git a/net/mac802154/mac_cmd.c b/net/mac802154/mac_cmd.c
index bdccb4e..f09d8fb 100644
--- a/net/mac802154/mac_cmd.c
+++ b/net/mac802154/mac_cmd.c
@@ -76,6 +76,7 @@ static int mac802154_set_mac_params(struct net_device *dev,
struct ieee802154_local *local = sdata->local;
struct wpan_dev *wpan_dev = &sdata->wpan_dev;
int ret;
+ s32 idx;
ASSERT_RTNL();
@@ -92,6 +93,26 @@ static int mac802154_set_mac_params(struct net_device *dev,
wpan_dev->lbt = params->lbt;
if (local->hw.flags & IEEE802154_HW_TXPOWER) {
+ bool found = false;
+ s32 pwr;
+
+ idx = 0;
+ while (1) {
+ ret = drv_get_tx_powers(local, &pwr, idx++);
+ if (ret < 0)
+ return ret;
+ else if (ret == 1)
+ break;
+
+ if (pwr == params->transmit_power) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -EINVAL;
+
ret = drv_set_tx_power(local, params->transmit_power);
if (ret < 0)
return ret;
@@ -104,6 +125,26 @@ static int mac802154_set_mac_params(struct net_device *dev,
}
if (local->hw.flags & IEEE802154_HW_CCA_ED_LEVEL) {
+ bool found = false;
+ s32 ed;
+
+ idx = 0;
+ while (1) {
+ ret = drv_get_cca_ed_levels(local, &ed, idx++);
+ if (ret < 0)
+ return ret;
+ else if (ret == 1)
+ break;
+
+ if (ed == params->cca_ed_level) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -EINVAL;
+
ret = drv_set_cca_ed_level(local, params->cca_ed_level);
if (ret < 0)
return ret;
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCHv2 wpan-next 16/16] nl802154: add support for dump phy capabilities
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
` (14 preceding siblings ...)
2015-05-06 11:40 ` [PATCHv2 wpan-next 15/16] ieee802154: check transmit power before driver layer Alexander Aring
@ 2015-05-06 11:40 ` Alexander Aring
15 siblings, 0 replies; 19+ messages in thread
From: Alexander Aring @ 2015-05-06 11:40 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch add support to nl802154 to dump all phy capabilities which is
inside the wpan_phy_supported struct. Also we introduce a new method to
dumping supported channels. The new method will offer a easier interface
and has lesser netlink traffic.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
include/net/nl802154.h | 57 +++++++++++++++++++++
net/ieee802154/nl802154.c | 127 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 183 insertions(+), 1 deletion(-)
diff --git a/include/net/nl802154.h b/include/net/nl802154.h
index 0552771..0badebd 100644
--- a/include/net/nl802154.h
+++ b/include/net/nl802154.h
@@ -100,6 +100,8 @@ enum nl802154_attrs {
NL802154_ATTR_EXTENDED_ADDR,
+ NL802154_ATTR_WPAN_PHY_CAPS,
+
/* add attributes here, update the policy in nl802154.c */
__NL802154_ATTR_AFTER_LAST,
@@ -120,6 +122,61 @@ enum nl802154_iftype {
};
/**
+ * enum nl802154_wpan_phy_capability_attr - wpan phy capability attributes
+ *
+ * @__NL802154_CAP_ATTR_INVALID: attribute number 0 is reserved
+ * @NL802154_CAP_ATTR_CHANNELS: a nested attribute for nl802154_channel_attr
+ * @NL802154_CAP_ATTR_TX_POWERS: a nested attribute for
+ * nl802154_wpan_phy_tx_power
+ * @NL802154_CAP_ATTR_MIN_CCA_ED_LEVEL: minimum value for cca_ed_level
+ * @NL802154_CAP_ATTR_MAX_CCA_ED_LEVEL: maxmimum value for cca_ed_level
+ * @NL802154_CAP_ATTR_CCA_MODES: nl802154_cca_modes flags
+ * @NL802154_CAP_ATTR_CCA_OPTS: nl802154_cca_opts flags
+ * @NL802154_CAP_ATTR_MIN_MINBE: minimum of minbe value
+ * @NL802154_CAP_ATTR_MAX_MINBE: maximum of minbe value
+ * @NL802154_CAP_ATTR_MIN_MAXBE: minimum of maxbe value
+ * @NL802154_CAP_ATTR_MAX_MINBE: maximum of maxbe value
+ * @NL802154_CAP_ATTR_MIN_CSMA_BACKOFFS: minimum of csma backoff value
+ * @NL802154_CAP_ATTR_MAX_CSMA_BACKOFFS: maximum of csma backoffs value
+ * @NL802154_CAP_ATTR_MIN_FRAME_RETRIES: minimum of frame retries value
+ * @NL802154_CAP_ATTR_MAX_FRAME_RETRIES: maximum of frame retries value
+ * @NL802154_CAP_ATTR_IFTYPES: nl802154_iftype flags
+ * @NL802154_CAP_ATTR_LBT: nl802154_supported_bool_states flags
+ * @NL802154_CAP_ATTR_MAX: highest cap attribute currently defined
+ * @__NL802154_CAP_ATTR_AFTER_LAST: internal use
+ */
+enum nl802154_wpan_phy_capability_attr {
+ __NL802154_CAP_ATTR_INVALID,
+
+ NL802154_CAP_ATTR_IFTYPES,
+
+ NL802154_CAP_ATTR_CHANNELS,
+ NL802154_CAP_ATTR_TX_POWERS,
+
+ NL802154_CAP_ATTR_CCA_ED_LEVELS,
+ NL802154_CAP_ATTR_CCA_MODES,
+ NL802154_CAP_ATTR_CCA_OPTS,
+
+ NL802154_CAP_ATTR_MIN_MINBE,
+ NL802154_CAP_ATTR_MAX_MINBE,
+
+ NL802154_CAP_ATTR_MIN_MAXBE,
+ NL802154_CAP_ATTR_MAX_MAXBE,
+
+ NL802154_CAP_ATTR_MIN_CSMA_BACKOFFS,
+ NL802154_CAP_ATTR_MAX_CSMA_BACKOFFS,
+
+ NL802154_CAP_ATTR_MIN_FRAME_RETRIES,
+ NL802154_CAP_ATTR_MAX_FRAME_RETRIES,
+
+ NL802154_CAP_ATTR_LBT,
+
+ /* keep last */
+ __NL802154_CAP_ATTR_AFTER_LAST,
+ NL802154_CAP_ATTR_MAX = __NL802154_CAP_ATTR_AFTER_LAST - 1
+};
+
+/**
* enum nl802154_cca_modes - cca modes
*
* @__NL802154_CCA_INVALID: cca mode number 0 is reserved
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 00b646d..568b514 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -225,6 +225,8 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
[NL802154_ATTR_MAX_FRAME_RETRIES] = { .type = NLA_S8, },
[NL802154_ATTR_LBT_MODE] = { .type = NLA_U8, },
+
+ [NL802154_ATTR_WPAN_PHY_CAPS] = { .type = NLA_NESTED },
};
/* message building helper */
@@ -236,6 +238,28 @@ static inline void *nl802154hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
}
static int
+nl802154_put_flags(struct sk_buff *msg, int attr, u32 mask)
+{
+ struct nlattr *nl_flags = nla_nest_start(msg, attr);
+ int i;
+
+ if (!nl_flags)
+ return -ENOBUFS;
+
+ i = 0;
+ while (mask) {
+ if ((mask & 1) && nla_put_flag(msg, i))
+ return -ENOBUFS;
+
+ mask >>= 1;
+ i++;
+ }
+
+ nla_nest_end(msg, nl_flags);
+ return 0;
+}
+
+static int
nl802154_send_wpan_phy_channels(struct cfg802154_registered_device *rdev,
struct sk_buff *msg)
{
@@ -256,6 +280,102 @@ nl802154_send_wpan_phy_channels(struct cfg802154_registered_device *rdev,
return 0;
}
+static int
+nl802154_put_capabilities(struct sk_buff *msg,
+ struct cfg802154_registered_device *rdev)
+{
+ const struct wpan_phy_supported *caps = &rdev->wpan_phy.supported;
+ struct nlattr *nl_tx_pwrs, *nl_caps, *nl_channels;
+ int idx;
+ s32 pwr;
+ int ret;
+
+ nl_caps = nla_nest_start(msg, NL802154_ATTR_WPAN_PHY_CAPS);
+ if (!nl_caps)
+ return -ENOBUFS;
+
+ nl_channels = nla_nest_start(msg, NL802154_CAP_ATTR_CHANNELS);
+ if (!nl_channels)
+ return -ENOBUFS;
+
+ for (idx = 0; idx <= IEEE802154_MAX_PAGE; idx++) {
+ if (caps->channels[idx]) {
+ if (nl802154_put_flags(msg, idx,
+ caps->channels[idx]))
+ return -ENOBUFS;
+ }
+ }
+
+ nla_nest_end(msg, nl_channels);
+
+ /* cca_ed_levels only in mode 1 and 3 important, check if supported */
+ if (caps->cca_modes & (BIT(NL802154_CCA_ENERGY_CARRIER) |
+ BIT(NL802154_CCA_ENERGY))) {
+ struct nlattr *nl_ed_lvls;
+ s32 ed;
+
+ nl_ed_lvls = nla_nest_start(msg,
+ NL802154_CAP_ATTR_CCA_ED_LEVELS);
+ if (!nl_ed_lvls)
+ return -ENOBUFS;
+
+ idx = 0;
+ while (1) {
+ ret = rdev_get_cca_ed_levels(rdev, &ed, idx++);
+ if (ret < 0)
+ return ret;
+ else if (ret == 1)
+ break;
+
+ nla_put_s32(msg, idx, ed);
+ };
+
+ nla_nest_end(msg, nl_ed_lvls);
+ }
+
+ nl_tx_pwrs = nla_nest_start(msg, NL802154_CAP_ATTR_TX_POWERS);
+ if (!nl_tx_pwrs)
+ return -ENOBUFS;
+
+ idx = 0;
+ while (1) {
+ ret = rdev_get_tx_powers(rdev, &pwr, idx++);
+ if (ret < 0)
+ return ret;
+ else if (ret == 1)
+ break;
+
+ nla_put_s32(msg, idx, pwr);
+ };
+
+ nla_nest_end(msg, nl_tx_pwrs);
+
+ if (nl802154_put_flags(msg, NL802154_CAP_ATTR_CCA_MODES,
+ caps->cca_modes) ||
+ nl802154_put_flags(msg, NL802154_CAP_ATTR_CCA_OPTS,
+ caps->cca_opts) ||
+ nla_put_u8(msg, NL802154_CAP_ATTR_MIN_MINBE, caps->min_minbe) ||
+ nla_put_u8(msg, NL802154_CAP_ATTR_MAX_MINBE, caps->max_minbe) ||
+ nla_put_u8(msg, NL802154_CAP_ATTR_MIN_MAXBE, caps->min_maxbe) ||
+ nla_put_u8(msg, NL802154_CAP_ATTR_MAX_MAXBE, caps->max_maxbe) ||
+ nla_put_u8(msg, NL802154_CAP_ATTR_MIN_CSMA_BACKOFFS,
+ caps->min_csma_backoffs) ||
+ nla_put_u8(msg, NL802154_CAP_ATTR_MAX_CSMA_BACKOFFS,
+ caps->max_csma_backoffs) ||
+ nla_put_s8(msg, NL802154_CAP_ATTR_MIN_FRAME_RETRIES,
+ caps->min_frame_retries) ||
+ nla_put_s8(msg, NL802154_CAP_ATTR_MAX_FRAME_RETRIES,
+ caps->max_frame_retries) ||
+ nl802154_put_flags(msg, NL802154_CAP_ATTR_IFTYPES,
+ caps->iftypes) ||
+ nla_put_u32(msg, NL802154_CAP_ATTR_LBT, caps->lbt))
+ return -ENOBUFS;
+
+ nla_nest_end(msg, nl_caps);
+
+ return 0;
+}
+
static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
enum nl802154_commands cmd,
struct sk_buff *msg, u32 portid, u32 seq,
@@ -286,7 +406,9 @@ static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
rdev->wpan_phy.current_channel))
goto nla_put_failure;
- /* supported channels array */
+ /* TODO remove this behaviour, we still keep support it for a while
+ * so users can change the behaviour to the new one.
+ */
if (nl802154_send_wpan_phy_channels(rdev, msg))
goto nla_put_failure;
@@ -305,6 +427,9 @@ static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
rdev->wpan_phy.transmit_power))
goto nla_put_failure;
+ if (nl802154_put_capabilities(msg, rdev))
+ goto nla_put_failure;
+
finish:
genlmsg_end(msg, hdr);
return 0;
--
2.3.7
^ permalink raw reply related [flat|nested] 19+ messages in thread