bcmf_sdio.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /****************************************************************************
  2. * drivers/wireless/ieee80211/bcmf_sdio.h
  3. *
  4. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
  5. * Author: Simon Piriou <spiriou31@gmail.com>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #ifndef __DRIVERS_WIRELESS_IEEE80211_BCMF_SDIO_H
  39. #define __DRIVERS_WIRELESS_IEEE80211_BCMF_SDIO_H
  40. #include "bcmf_driver.h"
  41. #include <stdint.h>
  42. #include <stdbool.h>
  43. #include <queue.h>
  44. #include <semaphore.h>
  45. #include <nuttx/sdio.h>
  46. #include "bcmf_sdio_core.h"
  47. #define HEADER_SIZE 0x12 /* Default sdpcm + bdc header size */
  48. // TODO move to Kconfig
  49. #define BCMF_PKT_POOL_SIZE 4 /* Frame pool size */
  50. /****************************************************************************
  51. * Public Types
  52. ****************************************************************************/
  53. /* sdio chip configuration structure */
  54. struct bcmf_sdio_chip
  55. {
  56. uint32_t ram_size;
  57. uint32_t core_base[MAX_CORE_ID];
  58. uint8_t *firmware_image;
  59. unsigned int *firmware_image_size;
  60. uint8_t *nvram_image;
  61. unsigned int *nvram_image_size;
  62. };
  63. /* sdio bus structure extension */
  64. struct bcmf_sdio_dev_s
  65. {
  66. struct bcmf_bus_dev_s bus; /* Default bcmf bus structure */
  67. FAR struct sdio_dev_s *sdio_dev; /* The SDIO device bound to this instance */
  68. int minor; /* Device minor number */
  69. struct bcmf_sdio_chip *chip; /* Chip specific configuration */
  70. volatile bool ready; /* Current device status */
  71. bool sleeping; /* Current sleep status */
  72. int thread_id; /* Processing thread id */
  73. sem_t thread_signal; /* Semaphore for processing thread event */
  74. struct wdog_s *waitdog; /* Processing thread waitdog */
  75. uint32_t backplane_current_addr; /* Current function 1 backplane base addr */
  76. volatile bool irq_pending; /* True if interrupt is pending */
  77. uint32_t intstatus; /* Copy of device current interrupt status */
  78. uint8_t max_seq; /* Maximum transmit sequence allowed */
  79. uint8_t tx_seq; /* Transmit sequence number (next) */
  80. uint8_t rx_seq; /* Receive sequence number (expected) */
  81. sem_t queue_mutex; /* Lock for TX/RX/free queues */
  82. dq_queue_t free_queue; /* Queue of available frames */
  83. dq_queue_t tx_queue; /* Queue of frames to tramsmit */
  84. dq_queue_t rx_queue; /* Queue of frames used to receive */
  85. volatile int tx_queue_count; /* Count of items in TX queue */
  86. };
  87. /* Structure used to manage SDIO frames */
  88. struct bcmf_sdio_frame
  89. {
  90. struct bcmf_frame_s header;
  91. bool tx;
  92. dq_entry_t list_entry;
  93. uint8_t data[HEADER_SIZE + MAX_NET_DEV_MTU +
  94. CONFIG_NET_GUARDSIZE];
  95. };
  96. /****************************************************************************
  97. * Public Function Prototypes
  98. ****************************************************************************/
  99. int bcmf_bus_sdio_initialize(FAR struct bcmf_dev_s *priv,
  100. int minor, FAR struct sdio_dev_s *dev);
  101. /* FIXME: Low level bus data transfer function
  102. * To avoid bus error, len will be aligned to:
  103. * - upper power of 2 iflen is lesser than 64
  104. * - upper 64 bytes block if len is greater than 64
  105. */
  106. int bcmf_transfer_bytes(FAR struct bcmf_sdio_dev_s *sbus, bool write,
  107. uint8_t function, uint32_t address,
  108. uint8_t *buf, unsigned int len);
  109. int bcmf_read_reg(FAR struct bcmf_sdio_dev_s *sbus, uint8_t function,
  110. uint32_t address, uint8_t *reg);
  111. int bcmf_write_reg(FAR struct bcmf_sdio_dev_s *sbus, uint8_t function,
  112. uint32_t address, uint8_t reg);
  113. struct bcmf_sdio_frame *bcmf_sdio_allocate_frame(FAR struct bcmf_dev_s *priv,
  114. bool block, bool tx);
  115. void bcmf_sdio_free_frame(FAR struct bcmf_dev_s *priv,
  116. struct bcmf_sdio_frame *sframe);
  117. #endif /* __DRIVERS_WIRELESS_IEEE80211_BCMF_SDIO_H */