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

Merge branch 'ieee802154-for-davem-2017-12-04' of git://git.kernel.org/pub/scm/linux/kernel/git/sschmidt/wpan-next

Stefan Schmidt says:

====================
pull-request: ieee802154-next 2017-12-04

Some update from ieee802154 to *net-next*

Jian-Hong Pan updated our docs to match the APIs in code.
Michael Hennerichs enhanced the adf7242 driver to work with adf7241
devices and reworked the IRQ and packet handling in the driver.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+105 -27
+1 -1
Documentation/devicetree/bindings/net/ieee802154/adf7242.txt
··· 1 1 * ADF7242 IEEE 802.15.4 * 2 2 3 3 Required properties: 4 - - compatible: should be "adi,adf7242" 4 + - compatible: should be "adi,adf7242", "adi,adf7241" 5 5 - spi-max-frequency: maximal bus speed (12.5 MHz) 6 6 - reg: the chipselect index 7 7 - interrupts: the interrupt generated by the device via pin IRQ1.
+40
Documentation/networking/ieee802154.txt
··· 97 97 - void ieee802154_unregister_hw(struct ieee802154_hw *hw): 98 98 freeing registered PHY 99 99 100 + - void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, 101 + u8 lqi): 102 + telling 802.15.4 module there is a new received frame in the skb with 103 + the RF Link Quality Indicator (LQI) from the hardware device 104 + 105 + - void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb, 106 + bool ifs_handling): 107 + telling 802.15.4 module the frame in the skb is or going to be 108 + transmitted through the hardware device 109 + 110 + The device driver must implement the following callbacks in the IEEE 802.15.4 111 + operations structure at least: 112 + struct ieee802154_ops { 113 + ... 114 + int (*start)(struct ieee802154_hw *hw); 115 + void (*stop)(struct ieee802154_hw *hw); 116 + ... 117 + int (*xmit_async)(struct ieee802154_hw *hw, struct sk_buff *skb); 118 + int (*ed)(struct ieee802154_hw *hw, u8 *level); 119 + int (*set_channel)(struct ieee802154_hw *hw, u8 page, u8 channel); 120 + ... 121 + }; 122 + 123 + - int start(struct ieee802154_hw *hw): 124 + handler that 802.15.4 module calls for the hardware device initialization. 125 + 126 + - void stop(struct ieee802154_hw *hw): 127 + handler that 802.15.4 module calls for the hardware device cleanup. 128 + 129 + - int xmit_async(struct ieee802154_hw *hw, struct sk_buff *skb): 130 + handler that 802.15.4 module calls for each frame in the skb going to be 131 + transmitted through the hardware device. 132 + 133 + - int ed(struct ieee802154_hw *hw, u8 *level): 134 + handler that 802.15.4 module calls for Energy Detection from the hardware 135 + device. 136 + 137 + - int set_channel(struct ieee802154_hw *hw, u8 page, u8 channel): 138 + set radio for listening on specific channel of the hardware device. 139 + 100 140 Moreover IEEE 802.15.4 device operations structure should be filled. 101 141 102 142 Fake drivers
+64 -26
drivers/net/ieee802154/adf7242.c
··· 1 1 /* 2 2 * Analog Devices ADF7242 Low-Power IEEE 802.15.4 Transceiver 3 3 * 4 - * Copyright 2009-2015 Analog Devices Inc. 4 + * Copyright 2009-2017 Analog Devices Inc. 5 5 * 6 6 * Licensed under the GPL-2 or later. 7 7 * ··· 344 344 return ret; 345 345 } 346 346 347 - static int adf7242_wait_ready(struct adf7242_local *lp, int line) 347 + static int adf7242_wait_rc_ready(struct adf7242_local *lp, int line) 348 348 { 349 349 return adf7242_wait_status(lp, STAT_RC_READY | STAT_SPI_READY, 350 350 STAT_RC_READY | STAT_SPI_READY, line); 351 + } 352 + 353 + static int adf7242_wait_spi_ready(struct adf7242_local *lp, int line) 354 + { 355 + return adf7242_wait_status(lp, STAT_SPI_READY, 356 + STAT_SPI_READY, line); 351 357 } 352 358 353 359 static int adf7242_write_fbuf(struct adf7242_local *lp, u8 *data, u8 len) ··· 375 369 spi_message_add_tail(&xfer_head, &msg); 376 370 spi_message_add_tail(&xfer_buf, &msg); 377 371 378 - adf7242_wait_ready(lp, __LINE__); 372 + adf7242_wait_spi_ready(lp, __LINE__); 379 373 380 374 mutex_lock(&lp->bmux); 381 375 buf[0] = CMD_SPI_PKT_WR; ··· 407 401 spi_message_add_tail(&xfer_head, &msg); 408 402 spi_message_add_tail(&xfer_buf, &msg); 409 403 410 - adf7242_wait_ready(lp, __LINE__); 404 + adf7242_wait_spi_ready(lp, __LINE__); 411 405 412 406 mutex_lock(&lp->bmux); 413 407 if (packet_read) { ··· 438 432 .rx_buf = lp->buf_read_rx, 439 433 }; 440 434 441 - adf7242_wait_ready(lp, __LINE__); 435 + adf7242_wait_spi_ready(lp, __LINE__); 442 436 443 437 mutex_lock(&lp->bmux); 444 438 lp->buf_read_tx[0] = CMD_SPI_MEM_RD(addr); ··· 468 462 { 469 463 int status; 470 464 471 - adf7242_wait_ready(lp, __LINE__); 465 + adf7242_wait_spi_ready(lp, __LINE__); 472 466 473 467 mutex_lock(&lp->bmux); 474 468 lp->buf_reg_tx[0] = CMD_SPI_MEM_WR(addr); ··· 490 484 dev_vdbg(&lp->spi->dev, "%s : CMD=0x%X\n", __func__, cmd); 491 485 492 486 if (cmd != CMD_RC_PC_RESET_NO_WAIT) 493 - adf7242_wait_ready(lp, __LINE__); 487 + adf7242_wait_rc_ready(lp, __LINE__); 494 488 495 489 mutex_lock(&lp->bmux); 496 490 lp->buf_cmd = cmd; ··· 561 555 kfree(buf); 562 556 #endif 563 557 return 0; 558 + } 559 + 560 + static void adf7242_clear_irqstat(struct adf7242_local *lp) 561 + { 562 + adf7242_write_reg(lp, REG_IRQ1_SRC1, IRQ_CCA_COMPLETE | IRQ_SFD_RX | 563 + IRQ_SFD_TX | IRQ_RX_PKT_RCVD | IRQ_TX_PKT_SENT | 564 + IRQ_FRAME_VALID | IRQ_ADDRESS_VALID | IRQ_CSMA_CA); 565 + } 566 + 567 + static int adf7242_cmd_rx(struct adf7242_local *lp) 568 + { 569 + /* Wait until the ACK is sent */ 570 + adf7242_wait_status(lp, RC_STATUS_PHY_RDY, RC_STATUS_MASK, __LINE__); 571 + adf7242_clear_irqstat(lp); 572 + 573 + return adf7242_cmd(lp, CMD_RC_RX); 564 574 } 565 575 566 576 static int adf7242_set_txpower(struct ieee802154_hw *hw, int mbm) ··· 682 660 struct adf7242_local *lp = hw->priv; 683 661 684 662 adf7242_cmd(lp, CMD_RC_PHY_RDY); 685 - adf7242_write_reg(lp, REG_IRQ1_SRC1, 0xFF); 663 + adf7242_clear_irqstat(lp); 686 664 enable_irq(lp->spi->irq); 687 665 set_bit(FLAG_START, &lp->flags); 688 666 ··· 693 671 { 694 672 struct adf7242_local *lp = hw->priv; 695 673 674 + disable_irq(lp->spi->irq); 696 675 adf7242_cmd(lp, CMD_RC_IDLE); 697 676 clear_bit(FLAG_START, &lp->flags); 698 - disable_irq(lp->spi->irq); 699 - adf7242_write_reg(lp, REG_IRQ1_SRC1, 0xFF); 677 + adf7242_clear_irqstat(lp); 700 678 } 701 679 702 680 static int adf7242_channel(struct ieee802154_hw *hw, u8 page, u8 channel) ··· 811 789 struct adf7242_local *lp = hw->priv; 812 790 int ret; 813 791 792 + /* ensure existing instances of the IRQ handler have completed */ 793 + disable_irq(lp->spi->irq); 814 794 set_bit(FLAG_XMIT, &lp->flags); 815 795 reinit_completion(&lp->tx_complete); 816 796 adf7242_cmd(lp, CMD_RC_PHY_RDY); 797 + adf7242_clear_irqstat(lp); 817 798 818 799 ret = adf7242_write_fbuf(lp, skb->data, skb->len); 819 800 if (ret) ··· 825 800 ret = adf7242_cmd(lp, CMD_RC_CSMACA); 826 801 if (ret) 827 802 goto err; 803 + enable_irq(lp->spi->irq); 828 804 829 805 ret = wait_for_completion_interruptible_timeout(&lp->tx_complete, 830 806 HZ / 10); ··· 848 822 849 823 err: 850 824 clear_bit(FLAG_XMIT, &lp->flags); 851 - adf7242_cmd(lp, CMD_RC_RX); 825 + adf7242_cmd_rx(lp); 852 826 853 827 return ret; 854 828 } ··· 872 846 873 847 skb = dev_alloc_skb(len); 874 848 if (!skb) { 875 - adf7242_cmd(lp, CMD_RC_RX); 849 + adf7242_cmd_rx(lp); 876 850 return -ENOMEM; 877 851 } 878 852 ··· 880 854 ret = adf7242_read_fbuf(lp, data, len, true); 881 855 if (ret < 0) { 882 856 kfree_skb(skb); 883 - adf7242_cmd(lp, CMD_RC_RX); 857 + adf7242_cmd_rx(lp); 884 858 return ret; 885 859 } 886 860 887 861 lqi = data[len - 2]; 888 862 lp->rssi = data[len - 1]; 889 863 890 - adf7242_cmd(lp, CMD_RC_RX); 864 + ret = adf7242_cmd_rx(lp); 891 865 892 866 skb_trim(skb, len - 2); /* Don't put RSSI/LQI or CRC into the frame */ 893 867 ··· 896 870 dev_dbg(&lp->spi->dev, "%s: ret=%d len=%d lqi=%d rssi=%d\n", 897 871 __func__, ret, (int)len, (int)lqi, lp->rssi); 898 872 899 - return 0; 873 + return ret; 900 874 } 901 875 902 876 static const struct ieee802154_ops adf7242_ops = { ··· 914 888 .set_cca_ed_level = adf7242_set_cca_ed_level, 915 889 }; 916 890 917 - static void adf7242_debug(u8 irq1) 891 + static void adf7242_debug(struct adf7242_local *lp, u8 irq1) 918 892 { 919 893 #ifdef DEBUG 920 894 u8 stat; ··· 932 906 irq1 & IRQ_FRAME_VALID ? "IRQ_FRAME_VALID\n" : "", 933 907 irq1 & IRQ_ADDRESS_VALID ? "IRQ_ADDRESS_VALID\n" : ""); 934 908 935 - dev_dbg(&lp->spi->dev, "%s STATUS = %X:\n%s\n%s%s%s%s%s\n", 909 + dev_dbg(&lp->spi->dev, "%s STATUS = %X:\n%s\n%s\n%s\n%s\n%s%s%s%s%s\n", 936 910 __func__, stat, 911 + stat & STAT_SPI_READY ? "SPI_READY" : "SPI_BUSY", 912 + stat & STAT_IRQ_STATUS ? "IRQ_PENDING" : "IRQ_CLEAR", 937 913 stat & STAT_RC_READY ? "RC_READY" : "RC_BUSY", 914 + stat & STAT_CCA_RESULT ? "CHAN_IDLE" : "CHAN_BUSY", 938 915 (stat & 0xf) == RC_STATUS_IDLE ? "RC_STATUS_IDLE" : "", 939 916 (stat & 0xf) == RC_STATUS_MEAS ? "RC_STATUS_MEAS" : "", 940 917 (stat & 0xf) == RC_STATUS_PHY_RDY ? "RC_STATUS_PHY_RDY" : "", ··· 952 923 unsigned int xmit; 953 924 u8 irq1; 954 925 955 - adf7242_wait_status(lp, RC_STATUS_PHY_RDY, RC_STATUS_MASK, __LINE__); 956 - 957 926 adf7242_read_reg(lp, REG_IRQ1_SRC1, &irq1); 958 - adf7242_write_reg(lp, REG_IRQ1_SRC1, irq1); 959 927 960 928 if (!(irq1 & (IRQ_RX_PKT_RCVD | IRQ_CSMA_CA))) 961 929 dev_err(&lp->spi->dev, "%s :ERROR IRQ1 = 0x%X\n", 962 930 __func__, irq1); 963 931 964 - adf7242_debug(irq1); 932 + adf7242_debug(lp, irq1); 965 933 966 934 xmit = test_bit(FLAG_XMIT, &lp->flags); 967 935 968 936 if (xmit && (irq1 & IRQ_CSMA_CA)) { 937 + adf7242_wait_status(lp, RC_STATUS_PHY_RDY, 938 + RC_STATUS_MASK, __LINE__); 939 + 969 940 if (ADF7242_REPORT_CSMA_CA_STAT) { 970 941 u8 astat; 971 942 ··· 986 957 lp->tx_stat = SUCCESS; 987 958 } 988 959 complete(&lp->tx_complete); 960 + adf7242_clear_irqstat(lp); 989 961 } else if (!xmit && (irq1 & IRQ_RX_PKT_RCVD) && 990 962 (irq1 & IRQ_FRAME_VALID)) { 991 963 adf7242_rx(lp); ··· 995 965 dev_dbg(&lp->spi->dev, "%s:%d : ERROR IRQ1 = 0x%X\n", 996 966 __func__, __LINE__, irq1); 997 967 adf7242_cmd(lp, CMD_RC_PHY_RDY); 998 - adf7242_write_reg(lp, REG_IRQ1_SRC1, 0xFF); 999 - adf7242_cmd(lp, CMD_RC_RX); 968 + adf7242_cmd_rx(lp); 1000 969 } else { 1001 970 /* This can only be xmit without IRQ, likely a RX packet. 1002 971 * we get an TX IRQ shortly - do nothing or let the xmit 1003 972 * timeout handle this 1004 973 */ 974 + 1005 975 dev_dbg(&lp->spi->dev, "%s:%d : ERROR IRQ1 = 0x%X, xmit %d\n", 1006 976 __func__, __LINE__, irq1, xmit); 977 + adf7242_wait_status(lp, RC_STATUS_PHY_RDY, 978 + RC_STATUS_MASK, __LINE__); 1007 979 complete(&lp->tx_complete); 980 + adf7242_clear_irqstat(lp); 1008 981 } 1009 982 1010 983 return IRQ_HANDLED; ··· 1027 994 adf7242_set_promiscuous_mode(lp->hw, lp->promiscuous); 1028 995 adf7242_set_csma_params(lp->hw, lp->min_be, lp->max_be, 1029 996 lp->max_cca_retries); 1030 - adf7242_write_reg(lp, REG_IRQ1_SRC1, 0xFF); 997 + adf7242_clear_irqstat(lp); 1031 998 1032 999 if (test_bit(FLAG_START, &lp->flags)) { 1033 1000 enable_irq(lp->spi->irq); ··· 1093 1060 adf7242_write_reg(lp, REG_IRQ1_EN0, 0); 1094 1061 adf7242_write_reg(lp, REG_IRQ1_EN1, IRQ_RX_PKT_RCVD | IRQ_CSMA_CA); 1095 1062 1096 - adf7242_write_reg(lp, REG_IRQ1_SRC1, 0xFF); 1063 + adf7242_clear_irqstat(lp); 1097 1064 adf7242_write_reg(lp, REG_IRQ1_SRC0, 0xFF); 1098 1065 1099 1066 adf7242_cmd(lp, CMD_RC_IDLE); ··· 1119 1086 irq1 & IRQ_FRAME_VALID ? "IRQ_FRAME_VALID\n" : "", 1120 1087 irq1 & IRQ_ADDRESS_VALID ? "IRQ_ADDRESS_VALID\n" : ""); 1121 1088 1122 - seq_printf(file, "STATUS = %X:\n%s\n%s%s%s%s%s\n", stat, 1089 + seq_printf(file, "STATUS = %X:\n%s\n%s\n%s\n%s\n%s%s%s%s%s\n", stat, 1090 + stat & STAT_SPI_READY ? "SPI_READY" : "SPI_BUSY", 1091 + stat & STAT_IRQ_STATUS ? "IRQ_PENDING" : "IRQ_CLEAR", 1123 1092 stat & STAT_RC_READY ? "RC_READY" : "RC_BUSY", 1093 + stat & STAT_CCA_RESULT ? "CHAN_IDLE" : "CHAN_BUSY", 1124 1094 (stat & 0xf) == RC_STATUS_IDLE ? "RC_STATUS_IDLE" : "", 1125 1095 (stat & 0xf) == RC_STATUS_MEAS ? "RC_STATUS_MEAS" : "", 1126 1096 (stat & 0xf) == RC_STATUS_PHY_RDY ? "RC_STATUS_PHY_RDY" : "", ··· 1293 1257 1294 1258 static const struct of_device_id adf7242_of_match[] = { 1295 1259 { .compatible = "adi,adf7242", }, 1260 + { .compatible = "adi,adf7241", }, 1296 1261 { }, 1297 1262 }; 1298 1263 MODULE_DEVICE_TABLE(of, adf7242_of_match); 1299 1264 1300 1265 static const struct spi_device_id adf7242_device_id[] = { 1301 1266 { .name = "adf7242", }, 1267 + { .name = "adf7241", }, 1302 1268 { }, 1303 1269 }; 1304 1270 MODULE_DEVICE_TABLE(spi, adf7242_device_id);