diff options
author | Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de> | 2014-02-17 05:34:15 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-02-17 16:42:39 -0500 |
commit | f2fdd67c6bc89de0100410efb37de69b1c98ac03 (patch) | |
tree | 08f9ec4803fd76adaf85dae04aea3a8a77188d5a /drivers/net/ieee802154/at86rf230.c | |
parent | 4244db1b0b7bc9ab7b67d8c1c38de6cf15bc87a8 (diff) |
ieee802154: enable smart transmitter features of RF212
This patch does multiple things:
* add .set_csma_params and .set_frame_retries for the RF212 radio.
This should work fine with RF230, but since I have no RF230 radios to
test with, RF230 does not implement these right now
* enable TX_ARET for frame retransmission limits greater than -1
Since RF230 has no operations to change CSMA parameters or frame retry
limits, RF230 will not be able to enter TX_ARET with this patch.
Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ieee802154/at86rf230.c')
-rw-r--r-- | drivers/net/ieee802154/at86rf230.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 345b2eeb5a14..34bf011584fb 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c | |||
@@ -52,6 +52,7 @@ struct at86rf230_local { | |||
52 | spinlock_t lock; | 52 | spinlock_t lock; |
53 | bool irq_busy; | 53 | bool irq_busy; |
54 | bool is_tx; | 54 | bool is_tx; |
55 | bool tx_aret; | ||
55 | 56 | ||
56 | int rssi_base_val; | 57 | int rssi_base_val; |
57 | }; | 58 | }; |
@@ -549,7 +550,9 @@ at86rf230_state(struct ieee802154_dev *dev, int state) | |||
549 | } while (val == STATE_TRANSITION_IN_PROGRESS); | 550 | } while (val == STATE_TRANSITION_IN_PROGRESS); |
550 | 551 | ||
551 | 552 | ||
552 | if (val == desired_status) | 553 | if (val == desired_status || |
554 | (desired_status == STATE_RX_ON && val == STATE_BUSY_RX) || | ||
555 | (desired_status == STATE_RX_AACK_ON && val == STATE_BUSY_RX_AACK)) | ||
553 | return 0; | 556 | return 0; |
554 | 557 | ||
555 | pr_err("unexpected state change: %d, asked for %d\n", val, state); | 558 | pr_err("unexpected state change: %d, asked for %d\n", val, state); |
@@ -570,6 +573,10 @@ at86rf230_start(struct ieee802154_dev *dev) | |||
570 | if (rc) | 573 | if (rc) |
571 | return rc; | 574 | return rc; |
572 | 575 | ||
576 | rc = at86rf230_state(dev, STATE_FORCE_TX_ON); | ||
577 | if (rc) | ||
578 | return rc; | ||
579 | |||
573 | return at86rf230_state(dev, STATE_RX_AACK_ON); | 580 | return at86rf230_state(dev, STATE_RX_AACK_ON); |
574 | } | 581 | } |
575 | 582 | ||
@@ -669,6 +676,12 @@ at86rf230_xmit(struct ieee802154_dev *dev, struct sk_buff *skb) | |||
669 | if (rc) | 676 | if (rc) |
670 | goto err_rx; | 677 | goto err_rx; |
671 | 678 | ||
679 | if (lp->tx_aret) { | ||
680 | rc = at86rf230_write_subreg(lp, SR_TRX_CMD, STATE_TX_ARET_ON); | ||
681 | if (rc) | ||
682 | goto err_rx; | ||
683 | } | ||
684 | |||
672 | rc = at86rf230_write_subreg(lp, SR_TRX_CMD, STATE_BUSY_TX); | 685 | rc = at86rf230_write_subreg(lp, SR_TRX_CMD, STATE_BUSY_TX); |
673 | if (rc) | 686 | if (rc) |
674 | goto err_rx; | 687 | goto err_rx; |
@@ -823,6 +836,44 @@ at86rf212_set_cca_ed_level(struct ieee802154_dev *dev, s32 level) | |||
823 | return at86rf230_write_subreg(lp, SR_CCA_ED_THRES, desens_steps); | 836 | return at86rf230_write_subreg(lp, SR_CCA_ED_THRES, desens_steps); |
824 | } | 837 | } |
825 | 838 | ||
839 | static int | ||
840 | at86rf212_set_csma_params(struct ieee802154_dev *dev, u8 min_be, u8 max_be, | ||
841 | u8 retries) | ||
842 | { | ||
843 | struct at86rf230_local *lp = dev->priv; | ||
844 | int rc; | ||
845 | |||
846 | if (min_be > max_be || max_be > 8 || retries > 5) | ||
847 | return -EINVAL; | ||
848 | |||
849 | rc = at86rf230_write_subreg(lp, SR_MIN_BE, min_be); | ||
850 | if (rc) | ||
851 | return rc; | ||
852 | |||
853 | rc = at86rf230_write_subreg(lp, SR_MAX_BE, max_be); | ||
854 | if (rc) | ||
855 | return rc; | ||
856 | |||
857 | return at86rf230_write_subreg(lp, SR_MAX_CSMA_RETRIES, max_be); | ||
858 | } | ||
859 | |||
860 | static int | ||
861 | at86rf212_set_frame_retries(struct ieee802154_dev *dev, s8 retries) | ||
862 | { | ||
863 | struct at86rf230_local *lp = dev->priv; | ||
864 | int rc = 0; | ||
865 | |||
866 | if (retries < -1 || retries > 15) | ||
867 | return -EINVAL; | ||
868 | |||
869 | lp->tx_aret = retries >= 0; | ||
870 | |||
871 | if (retries >= 0) | ||
872 | rc = at86rf230_write_subreg(lp, SR_MAX_FRAME_RETRIES, retries); | ||
873 | |||
874 | return rc; | ||
875 | } | ||
876 | |||
826 | static struct ieee802154_ops at86rf230_ops = { | 877 | static struct ieee802154_ops at86rf230_ops = { |
827 | .owner = THIS_MODULE, | 878 | .owner = THIS_MODULE, |
828 | .xmit = at86rf230_xmit, | 879 | .xmit = at86rf230_xmit, |
@@ -845,6 +896,8 @@ static struct ieee802154_ops at86rf212_ops = { | |||
845 | .set_lbt = at86rf212_set_lbt, | 896 | .set_lbt = at86rf212_set_lbt, |
846 | .set_cca_mode = at86rf212_set_cca_mode, | 897 | .set_cca_mode = at86rf212_set_cca_mode, |
847 | .set_cca_ed_level = at86rf212_set_cca_ed_level, | 898 | .set_cca_ed_level = at86rf212_set_cca_ed_level, |
899 | .set_csma_params = at86rf212_set_csma_params, | ||
900 | .set_frame_retries = at86rf212_set_frame_retries, | ||
848 | }; | 901 | }; |
849 | 902 | ||
850 | static void at86rf230_irqwork(struct work_struct *work) | 903 | static void at86rf230_irqwork(struct work_struct *work) |
@@ -921,6 +974,7 @@ static int at86rf230_hw_init(struct at86rf230_local *lp) | |||
921 | struct at86rf230_platform_data *pdata = lp->spi->dev.platform_data; | 974 | struct at86rf230_platform_data *pdata = lp->spi->dev.platform_data; |
922 | int rc, irq_pol; | 975 | int rc, irq_pol; |
923 | u8 status; | 976 | u8 status; |
977 | u8 csma_seed[2]; | ||
924 | 978 | ||
925 | rc = at86rf230_read_subreg(lp, SR_TRX_STATUS, &status); | 979 | rc = at86rf230_read_subreg(lp, SR_TRX_STATUS, &status); |
926 | if (rc) | 980 | if (rc) |
@@ -944,6 +998,14 @@ static int at86rf230_hw_init(struct at86rf230_local *lp) | |||
944 | if (rc) | 998 | if (rc) |
945 | return rc; | 999 | return rc; |
946 | 1000 | ||
1001 | get_random_bytes(csma_seed, ARRAY_SIZE(csma_seed)); | ||
1002 | rc = at86rf230_write_subreg(lp, SR_CSMA_SEED_0, csma_seed[0]); | ||
1003 | if (rc) | ||
1004 | return rc; | ||
1005 | rc = at86rf230_write_subreg(lp, SR_CSMA_SEED_1, csma_seed[1]); | ||
1006 | if (rc) | ||
1007 | return rc; | ||
1008 | |||
947 | /* CLKM changes are applied immediately */ | 1009 | /* CLKM changes are applied immediately */ |
948 | rc = at86rf230_write_subreg(lp, SR_CLKM_SHA_SEL, 0x00); | 1010 | rc = at86rf230_write_subreg(lp, SR_CLKM_SHA_SEL, 0x00); |
949 | if (rc) | 1011 | if (rc) |