dhd_bus.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef _BRCMF_BUS_H_
  17. #define _BRCMF_BUS_H_
  18. #include "dhd_dbg.h"
  19. /* The level of bus communication with the dongle */
  20. enum brcmf_bus_state {
  21. BRCMF_BUS_UNKNOWN, /* Not determined yet */
  22. BRCMF_BUS_NOMEDIUM, /* No medium access to dongle */
  23. BRCMF_BUS_DOWN, /* Not ready for frame transfers */
  24. BRCMF_BUS_LOAD, /* Download access only (CPU reset) */
  25. BRCMF_BUS_DATA /* Ready for frame transfers */
  26. };
  27. /* The level of bus communication with the dongle */
  28. enum brcmf_bus_protocol_type {
  29. BRCMF_PROTO_BCDC,
  30. BRCMF_PROTO_MSGBUF
  31. };
  32. struct brcmf_bus_dcmd {
  33. char *name;
  34. char *param;
  35. int param_len;
  36. struct list_head list;
  37. };
  38. /**
  39. * struct brcmf_bus_ops - bus callback operations.
  40. *
  41. * @preinit: execute bus/device specific dongle init commands (optional).
  42. * @init: prepare for communication with dongle.
  43. * @stop: clear pending frames, disable data flow.
  44. * @txdata: send a data frame to the dongle. When the data
  45. * has been transferred, the common driver must be
  46. * notified using brcmf_txcomplete(). The common
  47. * driver calls this function with interrupts
  48. * disabled.
  49. * @txctl: transmit a control request message to dongle.
  50. * @rxctl: receive a control response message from dongle.
  51. * @gettxq: obtain a reference of bus transmit queue (optional).
  52. *
  53. * This structure provides an abstract interface towards the
  54. * bus specific driver. For control messages to common driver
  55. * will assure there is only one active transaction. Unless
  56. * indicated otherwise these callbacks are mandatory.
  57. */
  58. struct brcmf_bus_ops {
  59. int (*preinit)(struct device *dev);
  60. void (*stop)(struct device *dev);
  61. int (*txdata)(struct device *dev, struct sk_buff *skb);
  62. int (*txctl)(struct device *dev, unsigned char *msg, uint len);
  63. int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
  64. struct pktq * (*gettxq)(struct device *dev);
  65. };
  66. /**
  67. * struct brcmf_bus - interface structure between common and bus layer
  68. *
  69. * @bus_priv: pointer to private bus device.
  70. * @proto_type: protocol type, bcdc or msgbuf
  71. * @dev: device pointer of bus device.
  72. * @drvr: public driver information.
  73. * @state: operational state of the bus interface.
  74. * @maxctl: maximum size for rxctl request message.
  75. * @tx_realloc: number of tx packets realloced for headroom.
  76. * @dstats: dongle-based statistical data.
  77. * @dcmd_list: bus/device specific dongle initialization commands.
  78. * @chip: device identifier of the dongle chip.
  79. * @chiprev: revision of the dongle chip.
  80. */
  81. struct brcmf_bus {
  82. union {
  83. struct brcmf_sdio_dev *sdio;
  84. struct brcmf_usbdev *usb;
  85. } bus_priv;
  86. enum brcmf_bus_protocol_type proto_type;
  87. struct device *dev;
  88. struct brcmf_pub *drvr;
  89. enum brcmf_bus_state state;
  90. uint maxctl;
  91. unsigned long tx_realloc;
  92. u32 chip;
  93. u32 chiprev;
  94. bool always_use_fws_queue;
  95. struct brcmf_bus_ops *ops;
  96. };
  97. /*
  98. * callback wrappers
  99. */
  100. static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
  101. {
  102. if (!bus->ops->preinit)
  103. return 0;
  104. return bus->ops->preinit(bus->dev);
  105. }
  106. static inline void brcmf_bus_stop(struct brcmf_bus *bus)
  107. {
  108. bus->ops->stop(bus->dev);
  109. }
  110. static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
  111. {
  112. return bus->ops->txdata(bus->dev, skb);
  113. }
  114. static inline
  115. int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  116. {
  117. return bus->ops->txctl(bus->dev, msg, len);
  118. }
  119. static inline
  120. int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  121. {
  122. return bus->ops->rxctl(bus->dev, msg, len);
  123. }
  124. static inline
  125. struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
  126. {
  127. if (!bus->ops->gettxq)
  128. return ERR_PTR(-ENOENT);
  129. return bus->ops->gettxq(bus->dev);
  130. }
  131. static inline bool brcmf_bus_ready(struct brcmf_bus *bus)
  132. {
  133. return bus->state == BRCMF_BUS_LOAD || bus->state == BRCMF_BUS_DATA;
  134. }
  135. static inline void brcmf_bus_change_state(struct brcmf_bus *bus,
  136. enum brcmf_bus_state new_state)
  137. {
  138. /* NOMEDIUM is permanent */
  139. if (bus->state == BRCMF_BUS_NOMEDIUM)
  140. return;
  141. brcmf_dbg(TRACE, "%d -> %d\n", bus->state, new_state);
  142. bus->state = new_state;
  143. }
  144. /*
  145. * interface functions from common layer
  146. */
  147. bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
  148. int prec);
  149. /* Receive frame for delivery to OS. Callee disposes of rxp. */
  150. void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
  151. /* Indication from bus module regarding presence/insertion of dongle. */
  152. int brcmf_attach(struct device *dev);
  153. /* Indication from bus module regarding removal/absence of dongle */
  154. void brcmf_detach(struct device *dev);
  155. /* Indication from bus module that dongle should be reset */
  156. void brcmf_dev_reset(struct device *dev);
  157. /* Indication from bus module to change flow-control state */
  158. void brcmf_txflowblock(struct device *dev, bool state);
  159. /* Notify the bus has transferred the tx packet to firmware */
  160. void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
  161. int brcmf_bus_start(struct device *dev);
  162. s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data,
  163. u32 len);
  164. void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
  165. #ifdef CONFIG_BRCMFMAC_SDIO
  166. void brcmf_sdio_exit(void);
  167. void brcmf_sdio_init(void);
  168. void brcmf_sdio_register(void);
  169. #endif
  170. #ifdef CONFIG_BRCMFMAC_USB
  171. void brcmf_usb_exit(void);
  172. void brcmf_usb_register(void);
  173. #endif
  174. #endif /* _BRCMF_BUS_H_ */