Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ieee802154: rework cca setting

The current cca setting handle is a driver specific call. We need to
introduce some 802.15.4 specific layer and mapping 802.15.4 cca modes to
driver specific ones inside the 802.15.4 driver. This patch will add
such 802.15.4 layer and mapping the cca settings to driver specific ones.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

authored by

Alexander Aring and committed by
Marcel Holtmann
7fe9a388 b40d6376

+51 -14
+28 -2
drivers/net/ieee802154/at86rf230.c
··· 1146 1146 } 1147 1147 1148 1148 static int 1149 - at86rf230_set_cca_mode(struct ieee802154_hw *hw, u8 mode) 1149 + at86rf230_set_cca_mode(struct ieee802154_hw *hw, 1150 + const struct wpan_phy_cca *cca) 1150 1151 { 1151 1152 struct at86rf230_local *lp = hw->priv; 1153 + u8 val; 1152 1154 1153 - return at86rf230_write_subreg(lp, SR_CCA_MODE, mode); 1155 + /* mapping 802.15.4 to driver spec */ 1156 + switch (cca->mode) { 1157 + case NL802154_CCA_ENERGY: 1158 + val = 1; 1159 + break; 1160 + case NL802154_CCA_CARRIER: 1161 + val = 2; 1162 + break; 1163 + case NL802154_CCA_ENERGY_CARRIER: 1164 + switch (cca->opt) { 1165 + case NL802154_CCA_OPT_ENERGY_CARRIER_AND: 1166 + val = 3; 1167 + break; 1168 + case NL802154_CCA_OPT_ENERGY_CARRIER_OR: 1169 + val = 0; 1170 + break; 1171 + default: 1172 + return -EINVAL; 1173 + } 1174 + break; 1175 + default: 1176 + return -EINVAL; 1177 + } 1178 + 1179 + return at86rf230_write_subreg(lp, SR_CCA_MODE, val); 1154 1180 } 1155 1181 1156 1182 static int
+6 -1
include/net/cfg802154.h
··· 56 56 struct wpan_dev *wpan_dev, bool mode); 57 57 }; 58 58 59 + struct wpan_phy_cca { 60 + enum nl802154_cca_modes mode; 61 + enum nl802154_cca_opts opt; 62 + }; 63 + 59 64 struct wpan_phy { 60 65 struct mutex pib_lock; 61 66 ··· 81 76 u8 current_page; 82 77 u32 channels_supported[IEEE802154_MAX_PAGE + 1]; 83 78 s8 transmit_power; 84 - u8 cca_mode; 79 + struct wpan_phy_cca cca; 85 80 86 81 __le64 perm_extended_addr; 87 82
+3 -1
include/net/ieee802154_netdev.h
··· 28 28 #include <linux/skbuff.h> 29 29 #include <linux/ieee802154.h> 30 30 31 + #include <net/cfg802154.h> 32 + 31 33 struct ieee802154_sechdr { 32 34 #if defined(__LITTLE_ENDIAN_BITFIELD) 33 35 u8 level:3, ··· 339 337 s8 frame_retries; 340 338 341 339 bool lbt; 342 - u8 cca_mode; 340 + struct wpan_phy_cca cca; 343 341 s32 cca_ed_level; 344 342 }; 345 343
+4 -1
include/net/mac802154.h
··· 20 20 #include <linux/ieee802154.h> 21 21 #include <linux/skbuff.h> 22 22 23 + #include <net/cfg802154.h> 24 + 23 25 /* General MAC frame format: 24 26 * 2 bytes: Frame Control 25 27 * 1 byte: Sequence Number ··· 214 212 unsigned long changed); 215 213 int (*set_txpower)(struct ieee802154_hw *hw, int db); 216 214 int (*set_lbt)(struct ieee802154_hw *hw, bool on); 217 - int (*set_cca_mode)(struct ieee802154_hw *hw, u8 mode); 215 + int (*set_cca_mode)(struct ieee802154_hw *hw, 216 + const struct wpan_phy_cca *cca); 218 217 int (*set_cca_ed_level)(struct ieee802154_hw *hw, 219 218 s32 level); 220 219 int (*set_csma_params)(struct ieee802154_hw *hw,
+2 -2
net/ieee802154/nl-mac.c
··· 121 121 params.transmit_power) || 122 122 nla_put_u8(msg, IEEE802154_ATTR_LBT_ENABLED, params.lbt) || 123 123 nla_put_u8(msg, IEEE802154_ATTR_CCA_MODE, 124 - params.cca_mode) || 124 + params.cca.mode) || 125 125 nla_put_s32(msg, IEEE802154_ATTR_CCA_ED_LEVEL, 126 126 params.cca_ed_level) || 127 127 nla_put_u8(msg, IEEE802154_ATTR_CSMA_RETRIES, ··· 516 516 params.lbt = nla_get_u8(info->attrs[IEEE802154_ATTR_LBT_ENABLED]); 517 517 518 518 if (info->attrs[IEEE802154_ATTR_CCA_MODE]) 519 - params.cca_mode = nla_get_u8(info->attrs[IEEE802154_ATTR_CCA_MODE]); 519 + params.cca.mode = nla_get_u8(info->attrs[IEEE802154_ATTR_CCA_MODE]); 520 520 521 521 if (info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]) 522 522 params.cca_ed_level = nla_get_s32(info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]);
+1 -1
net/ieee802154/nl802154.c
··· 291 291 292 292 /* cca mode */ 293 293 if (nla_put_u8(msg, NL802154_ATTR_CCA_MODE, 294 - rdev->wpan_phy.cca_mode)) 294 + rdev->wpan_phy.cca.mode)) 295 295 goto nla_put_failure; 296 296 297 297 if (nla_put_s8(msg, NL802154_ATTR_TX_POWER,
+1 -1
net/ieee802154/sysfs.c
··· 68 68 MASTER_SHOW(current_channel, "%d"); 69 69 MASTER_SHOW(current_page, "%d"); 70 70 MASTER_SHOW(transmit_power, "%d +- 1 dB"); 71 - MASTER_SHOW(cca_mode, "%d"); 71 + MASTER_SHOW_COMPLEX(cca_mode, "%d", phy->cca.mode); 72 72 73 73 static ssize_t channels_supported_show(struct device *dev, 74 74 struct device_attribute *attr,
+3 -2
net/mac802154/driver-ops.h
··· 70 70 return local->ops->set_txpower(&local->hw, dbm); 71 71 } 72 72 73 - static inline int drv_set_cca_mode(struct ieee802154_local *local, u8 cca_mode) 73 + static inline int drv_set_cca_mode(struct ieee802154_local *local, 74 + const struct wpan_phy_cca *cca) 74 75 { 75 76 might_sleep(); 76 77 ··· 80 79 return -EOPNOTSUPP; 81 80 } 82 81 83 - return local->ops->set_cca_mode(&local->hw, cca_mode); 82 + return local->ops->set_cca_mode(&local->hw, cca); 84 83 } 85 84 86 85 static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
+3 -3
net/mac802154/mac_cmd.c
··· 81 81 82 82 /* PHY */ 83 83 wpan_dev->wpan_phy->transmit_power = params->transmit_power; 84 - wpan_dev->wpan_phy->cca_mode = params->cca_mode; 84 + wpan_dev->wpan_phy->cca = params->cca; 85 85 wpan_dev->wpan_phy->cca_ed_level = params->cca_ed_level; 86 86 87 87 /* MAC */ ··· 98 98 } 99 99 100 100 if (local->hw.flags & IEEE802154_HW_CCA_MODE) { 101 - ret = drv_set_cca_mode(local, params->cca_mode); 101 + ret = drv_set_cca_mode(local, &params->cca); 102 102 if (ret < 0) 103 103 return ret; 104 104 } ··· 122 122 123 123 /* PHY */ 124 124 params->transmit_power = wpan_dev->wpan_phy->transmit_power; 125 - params->cca_mode = wpan_dev->wpan_phy->cca_mode; 125 + params->cca = wpan_dev->wpan_phy->cca; 126 126 params->cca_ed_level = wpan_dev->wpan_phy->cca_ed_level; 127 127 128 128 /* MAC */