ieee802154: add usual way to get extended address via device tree
Subsystems (5)
Alexander Aring
maintainercover ieee802154: add usual way to get extended address via device tree
Hi,
this patch introduce an usual way to getting extended address from device tree. I added the properties "extended-address" and "local-extended-address". The ethernet framework has "mac-address", "local-mac-address" and "address", where "address" is according the comment an obsolete property.
An example how you could add a extended address would be:
&spi1 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi1_pins>;
at86rf231@0 {
compatible = "atmel,at86rf231";
spi-max-frequency = <7500000>;
reg = <0>;
interrupts = <19 4>;
interrupt-parent = <&gpio3>;
xtal-trim = /bits/ 8 <0x03>;
extended-address = [ DE AD BE EF CA FE FA CE ];
};
};This is actually a RFC only. I want to be sure that we can use this naming convention and I need also add a cc in Patch 1/1 ("of: net: add support for extended address") to the device tree mailinglist, then wait for an acked-by and marcel can apply it on bluetooth-next and we have it mainline.
- Alex
Alexander Aring (2):
of: net: add support for extended address
at86rf230: add support for dt or pdata extended addr
drivers/net/ieee802154/at86rf230.c | 15 ++++++++++++--- drivers/of/of_net.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/of_net.h | 6 ++++++ include/linux/spi/at86rf230.h | 1 + 4 files changed, 53 insertions(+), 3 deletions(-)
Signature · 1 line
2.3.0
Alexander Aring
maintainerRFC 1/2 of: net: add support for extended address
This patch adds a general of_get_extended_address function. The idea is that 802.15.4 transceivers contains an "extended-address" property like "mac-address" property. In driver layer each driver can request such address via calling the of_get_extended_address function and set the perm_extended_addr attribute of a 802.15.4 phy. This is the default used extended address of a 802.15.4 interface.
The of_get_extended_address function returns an invalid address on error. The sense is to validate the extended afterwards by calling ieee802154_is_valid_extended_addr then the driver can choose an other source for default extended address like reading firmware or a random one.
--- drivers/of/of_net.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/of_net.h | 6 ++++++ 2 files changed, 40 insertions(+)
drivers/of/of_net.c +34 -0
@@ -6,11 +6,14 @@* Initially copied out of arch/powerpc/kernel/prom_parse.c */ #include <linux/etherdevice.h> +#include <linux/ieee802154.h> #include <linux/kernel.h> #include <linux/of_net.h> #include <linux/phy.h> #include <linux/export.h> +#include <net/mac802154.h> +/** * of_get_phy_mode - Get phy mode for given device_node * @np: Pointer to the given device_node
@@ -75,3 +78,34 @@ const void *of_get_mac_address(struct device_node *np)return NULL ; }EXPORT_SYMBOL (of_get_mac_address); + +/** +* Search the device tree for the best extended address to use. +* 'extended-address' is checked first, because that is supposed to contain +* to "most recent" extended address. If that isn't set, then +* 'local-extended-address' is checked next, because that is the default +* address. +* +* Returns a valid extended address on success, otherwise an invalid extended +* address. +*/ +__le64 of_get_extended_address (struct device_node *np) +{ +struct property *pp; +__le64 extended_addr =cpu_to_le64 (0x0000000000000000ULL ); + + pp =of_find_property (np,"extended-address" ,NULL ); +if (pp && (pp->length ==IEEE802154_EXTENDED_ADDR_LEN )) { +ieee802154_be64_to_le64 (&extended_addr, pp->value); + +if (ieee802154_is_valid_extended_addr (extended_addr)) +return extended_addr; + } + + pp =of_find_property (np,"local-extended-address" ,NULL ); +if (pp && (pp->length ==IEEE802154_EXTENDED_ADDR_LEN )) +ieee802154_be64_to_le64 (&extended_addr, pp->value); + +return extended_addr; +} +EXPORT_SYMBOL (of_get_extended_address);
include/linux/of_net.h +6 -0
@@ -11,6 +11,7 @@#include <linux/of.h> extern int of_get_phy_mode (struct device_node *np);extern const void *of_get_mac_address (struct device_node *np); +extern __le64 of_get_extended_address (struct device_node *np);#else static inline int of_get_phy_mode (struct device_node *np) {
@@ -21,6 +22,11 @@ static inline const void *of_get_mac_address(struct device_node *np) {return NULL ; } + +static inline __le64 of_get_extended_address (struct device_node *np) +{ +return cpu_to_le64 (0x0000000000000000ULL ); +}#endif #endif /* __LINUX_OF_NET_H */
Signature · 1 line
2.3.0
Alexander Aring
maintainerRFC 2/2 at86rf230: add support for dt or pdata extended addr
In reply to Alexander AringThis patch adds support for setting the extended address over devicetree or platform data.
--- drivers/net/ieee802154/at86rf230.c | 15 ++++++++++++--- include/linux/spi/at86rf230.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/net/ieee802154/at86rf230.c +12 -3
@@ -29,6 +29,7 @@#include <linux/regmap.h> #include <linux/skbuff.h> #include <linux/of_gpio.h> +#include <linux/of_net.h> #include <linux/ieee802154.h> #include <net/mac802154.h>
@@ -1434,7 +1435,7 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim)static int at86rf230_get_pdata (struct spi_device *spi,int *rstn,int *slp_tr, -u8 *xtal_trim) +u8 *xtal_trim,__le64 *extended_addr) {struct at86rf230_platform_data *pdata = spi->dev.platform_data;int ret;
@@ -1446,6 +1447,7 @@ at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr, *rstn = pdata->rstn; *slp_tr = pdata->slp_tr; *xtal_trim = pdata->xtal_trim; + *extended_addr =cpu_to_le64 (pdata->extended_addr);return 0 ; }
@@ -1455,6 +1457,7 @@ at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr,if (ret <0 && ret != -EINVAL )return ret; + *extended_addr =of_get_extended_address (spi->dev.of_node);return 0 ; }
@@ -1572,6 +1575,7 @@ static int at86rf230_probe(struct spi_device *spi)struct at86rf230_local *lp;unsigned int status;int rc, irq_type, rstn, slp_tr; +__le64 extended_addr;u8 xtal_trim =0 ;if (!spi->irq) {
@@ -1579,7 +1583,8 @@ static int at86rf230_probe(struct spi_device *spi)return -EINVAL ; } - rc =at86rf230_get_pdata (spi, &rstn, &slp_tr, &xtal_trim); + rc =at86rf230_get_pdata (spi, &rstn, &slp_tr, &xtal_trim, + &extended_addr);if (rc <0 ) {dev_err (&spi->dev,"failed to parse platform_data: %d\n" , rc);return rc;
@@ -1617,7 +1622,11 @@ static int at86rf230_probe(struct spi_device *spi) lp->spi = spi; hw->parent = &spi->dev; hw->vif_data_size =sizeof (*lp); -ieee802154_random_extended_addr (&hw->phy->perm_extended_addr); + +if (ieee802154_is_valid_extended_addr (extended_addr)) + hw->phy->perm_extended_addr = extended_addr; +else +ieee802154_random_extended_addr (&hw->phy->perm_extended_addr); lp->regmap =devm_regmap_init_spi (spi, &at86rf230_regmap_spi_config);if (IS_ERR (lp->regmap)) {
include/linux/spi/at86rf230.h +1 -0
@@ -23,6 +23,7 @@ struct at86rf230_platform_data {int slp_tr;int dig2;u8 xtal_trim; + u64 extended_addr; };#endif
Signature · 1 line
2.3.0
Alexander Aring
maintainerRe: [RFC bluetooth-next 1/2] of: net: add support for extended address
In reply to Alexander AringHi,
some notes from me which I figured out for reviewing right now.
On Sun, Mar 08, 2015 at 09:17:22AM +0100, Alexander Aring wrote:
...
Quoted 15 lines
(quoted diff) +2
-0+} +EXPORT_SYMBOL(of_get_extended_address);include/linux/of_net.h +1
-0@@ -11,6 +11,7 @@#include <linux/of.h> extern int of_get_phy_mode (struct device_node *np);extern const void *of_get_mac_address (struct device_node *np); +extern __le64 of_get_extended_address (struct device_node *np);#else static inline int of_get_phy_mode (struct device_node *np) {
include/linux/of_net.h static inline const void *of_get_mac_address(struct device_node *np) · line 31
Quoted 10 lines
include/linux/of_net.h +5
-0@@ -21,6 +22,11 @@ static inline const void *of_get_mac_address(struct device_node *np) {return NULL ; } + +static inline __le64 of_get_extended_address (struct device_node *np) +{ +return cpu_to_le64 (0x0000000000000000ULL ); +}#endif
I need to be sure that __le64 is definied here from include of <linux/of.h>. I didn't check that right now.
- Alex
Alexander Aring
maintainerRe: [RFC bluetooth-next 2/2] at86rf230: add support for dt or pdata extended addr
In reply to Alexander AringHi,
Quoted 2 lines · Alexander Aring
This patch adds support for setting the extended address over devicetree or platform data.
I should also add some notes in:
Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt
about the extended-addr definition or should I add some generic 802.15.4 specific file where I describe the common way to add an extended.
If yes where should it be placed. Something like:
Documentation/devicetree/bindings/net/ieee802154/general.txt
Or should I define it driver specific. When setting "extended-addr" via the dt property "extended-addr" then because the driver doesn't support the handling.
- Alex
Alexander Aring
maintainerRe: [RFC bluetooth-next 2/2] at86rf230: add support for dt or pdata extended addr
Quoted 3 lines
Or should I define it driver specific. When setting "extended-addr" via the dt property "extended-addr" then because the driver doesn't support the handling.
s/dt property "extended-addr"/dt property "extended-addr" doesn't work/
sorry, I hope now it's clear what I meant here.
- Alex