qca_7k_common.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
  2. /*
  3. * Copyright (c) 2011, 2012, Atheros Communications Inc.
  4. * Copyright (c) 2014, I2SE GmbH
  5. */
  6. /* Atheros Ethernet framing. Every Ethernet frame is surrounded by an atheros
  7. * frame while transmitted over a serial channel.
  8. */
  9. #ifndef _QCA_FRAMING_H
  10. #define _QCA_FRAMING_H
  11. #include <linux/if_ether.h>
  12. #include <linux/if_vlan.h>
  13. #include <linux/types.h>
  14. /* Frame is currently being received */
  15. #define QCAFRM_GATHER 0
  16. /* No header byte while expecting it */
  17. #define QCAFRM_NOHEAD (QCAFRM_ERR_BASE - 1)
  18. /* No tailer byte while expecting it */
  19. #define QCAFRM_NOTAIL (QCAFRM_ERR_BASE - 2)
  20. /* Frame length is invalid */
  21. #define QCAFRM_INVLEN (QCAFRM_ERR_BASE - 3)
  22. /* Frame length is invalid */
  23. #define QCAFRM_INVFRAME (QCAFRM_ERR_BASE - 4)
  24. /* Min/Max Ethernet MTU: 46/1500 */
  25. #define QCAFRM_MIN_MTU (ETH_ZLEN - ETH_HLEN)
  26. #define QCAFRM_MAX_MTU ETH_DATA_LEN
  27. /* Min/Max frame lengths */
  28. #define QCAFRM_MIN_LEN (QCAFRM_MIN_MTU + ETH_HLEN)
  29. #define QCAFRM_MAX_LEN (QCAFRM_MAX_MTU + VLAN_ETH_HLEN)
  30. /* QCA7K header len */
  31. #define QCAFRM_HEADER_LEN 8
  32. /* QCA7K footer len */
  33. #define QCAFRM_FOOTER_LEN 2
  34. /* QCA7K Framing. */
  35. #define QCAFRM_ERR_BASE -1000
  36. enum qcafrm_state {
  37. /* HW length is only available on SPI */
  38. QCAFRM_HW_LEN0 = 0x8000,
  39. QCAFRM_HW_LEN1 = QCAFRM_HW_LEN0 - 1,
  40. QCAFRM_HW_LEN2 = QCAFRM_HW_LEN1 - 1,
  41. QCAFRM_HW_LEN3 = QCAFRM_HW_LEN2 - 1,
  42. /* Waiting first 0xAA of header */
  43. QCAFRM_WAIT_AA1 = QCAFRM_HW_LEN3 - 1,
  44. /* Waiting second 0xAA of header */
  45. QCAFRM_WAIT_AA2 = QCAFRM_WAIT_AA1 - 1,
  46. /* Waiting third 0xAA of header */
  47. QCAFRM_WAIT_AA3 = QCAFRM_WAIT_AA2 - 1,
  48. /* Waiting fourth 0xAA of header */
  49. QCAFRM_WAIT_AA4 = QCAFRM_WAIT_AA3 - 1,
  50. /* Waiting Byte 0-1 of length (litte endian) */
  51. QCAFRM_WAIT_LEN_BYTE0 = QCAFRM_WAIT_AA4 - 1,
  52. QCAFRM_WAIT_LEN_BYTE1 = QCAFRM_WAIT_AA4 - 2,
  53. /* Reserved bytes */
  54. QCAFRM_WAIT_RSVD_BYTE1 = QCAFRM_WAIT_AA4 - 3,
  55. QCAFRM_WAIT_RSVD_BYTE2 = QCAFRM_WAIT_AA4 - 4,
  56. /* The frame length is used as the state until
  57. * the end of the Ethernet frame
  58. * Waiting for first 0x55 of footer
  59. */
  60. QCAFRM_WAIT_551 = 1,
  61. /* Waiting for second 0x55 of footer */
  62. QCAFRM_WAIT_552 = QCAFRM_WAIT_551 - 1
  63. };
  64. /* Structure to maintain the frame decoding during reception. */
  65. struct qcafrm_handle {
  66. /* Current decoding state */
  67. enum qcafrm_state state;
  68. /* Initial state depends on connection type */
  69. enum qcafrm_state init;
  70. /* Offset in buffer (borrowed for length too) */
  71. u16 offset;
  72. };
  73. u16 qcafrm_create_header(u8 *buf, u16 len);
  74. u16 qcafrm_create_footer(u8 *buf);
  75. static inline void qcafrm_fsm_init_spi(struct qcafrm_handle *handle)
  76. {
  77. handle->init = QCAFRM_HW_LEN0;
  78. handle->state = handle->init;
  79. }
  80. static inline void qcafrm_fsm_init_uart(struct qcafrm_handle *handle)
  81. {
  82. handle->init = QCAFRM_WAIT_AA1;
  83. handle->state = handle->init;
  84. }
  85. s32 qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 recv_byte);
  86. #endif /* _QCA_FRAMING_H */