bus.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 BRCMFMAC_BUS_H
  17. #define BRCMFMAC_BUS_H
  18. #include "debug.h"
  19. /* IDs of the 6 default common rings of msgbuf protocol */
  20. #define BRCMF_H2D_MSGRING_CONTROL_SUBMIT 0
  21. #define BRCMF_H2D_MSGRING_RXPOST_SUBMIT 1
  22. #define BRCMF_D2H_MSGRING_CONTROL_COMPLETE 2
  23. #define BRCMF_D2H_MSGRING_TX_COMPLETE 3
  24. #define BRCMF_D2H_MSGRING_RX_COMPLETE 4
  25. #define BRCMF_NROF_H2D_COMMON_MSGRINGS 2
  26. #define BRCMF_NROF_D2H_COMMON_MSGRINGS 3
  27. #define BRCMF_NROF_COMMON_MSGRINGS (BRCMF_NROF_H2D_COMMON_MSGRINGS + \
  28. BRCMF_NROF_D2H_COMMON_MSGRINGS)
  29. /* The level of bus communication with the dongle */
  30. enum brcmf_bus_state {
  31. BRCMF_BUS_DOWN, /* Not ready for frame transfers */
  32. BRCMF_BUS_UP /* Ready for frame transfers */
  33. };
  34. /* The level of bus communication with the dongle */
  35. enum brcmf_bus_protocol_type {
  36. BRCMF_PROTO_BCDC,
  37. BRCMF_PROTO_MSGBUF
  38. };
  39. struct brcmf_bus_dcmd {
  40. char *name;
  41. char *param;
  42. int param_len;
  43. struct list_head list;
  44. };
  45. /**
  46. * struct brcmf_bus_ops - bus callback operations.
  47. *
  48. * @preinit: execute bus/device specific dongle init commands (optional).
  49. * @init: prepare for communication with dongle.
  50. * @stop: clear pending frames, disable data flow.
  51. * @txdata: send a data frame to the dongle. When the data
  52. * has been transferred, the common driver must be
  53. * notified using brcmf_txcomplete(). The common
  54. * driver calls this function with interrupts
  55. * disabled.
  56. * @txctl: transmit a control request message to dongle.
  57. * @rxctl: receive a control response message from dongle.
  58. * @gettxq: obtain a reference of bus transmit queue (optional).
  59. * @wowl_config: specify if dongle is configured for wowl when going to suspend
  60. *
  61. * This structure provides an abstract interface towards the
  62. * bus specific driver. For control messages to common driver
  63. * will assure there is only one active transaction. Unless
  64. * indicated otherwise these callbacks are mandatory.
  65. */
  66. struct brcmf_bus_ops {
  67. int (*preinit)(struct device *dev);
  68. void (*stop)(struct device *dev);
  69. int (*txdata)(struct device *dev, struct sk_buff *skb);
  70. int (*txctl)(struct device *dev, unsigned char *msg, uint len);
  71. int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
  72. struct pktq * (*gettxq)(struct device *dev);
  73. void (*wowl_config)(struct device *dev, bool enabled);
  74. };
  75. /**
  76. * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
  77. *
  78. * @commonrings: commonrings which are always there.
  79. * @flowrings: commonrings which are dynamically created and destroyed for data.
  80. * @rx_dataoffset: if set then all rx data has this this offset.
  81. * @max_rxbufpost: maximum number of buffers to post for rx.
  82. * @nrof_flowrings: number of flowrings.
  83. */
  84. struct brcmf_bus_msgbuf {
  85. struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
  86. struct brcmf_commonring **flowrings;
  87. u32 rx_dataoffset;
  88. u32 max_rxbufpost;
  89. u32 nrof_flowrings;
  90. };
  91. /**
  92. * struct brcmf_bus - interface structure between common and bus layer
  93. *
  94. * @bus_priv: pointer to private bus device.
  95. * @proto_type: protocol type, bcdc or msgbuf
  96. * @dev: device pointer of bus device.
  97. * @drvr: public driver information.
  98. * @state: operational state of the bus interface.
  99. * @maxctl: maximum size for rxctl request message.
  100. * @tx_realloc: number of tx packets realloced for headroom.
  101. * @dstats: dongle-based statistical data.
  102. * @dcmd_list: bus/device specific dongle initialization commands.
  103. * @chip: device identifier of the dongle chip.
  104. * @wowl_supported: is wowl supported by bus driver.
  105. * @chiprev: revision of the dongle chip.
  106. */
  107. struct brcmf_bus {
  108. union {
  109. struct brcmf_sdio_dev *sdio;
  110. struct brcmf_usbdev *usb;
  111. struct brcmf_pciedev *pcie;
  112. } bus_priv;
  113. enum brcmf_bus_protocol_type proto_type;
  114. struct device *dev;
  115. struct brcmf_pub *drvr;
  116. enum brcmf_bus_state state;
  117. uint maxctl;
  118. unsigned long tx_realloc;
  119. u32 chip;
  120. u32 chiprev;
  121. bool always_use_fws_queue;
  122. bool wowl_supported;
  123. struct brcmf_bus_ops *ops;
  124. struct brcmf_bus_msgbuf *msgbuf;
  125. };
  126. /*
  127. * callback wrappers
  128. */
  129. static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
  130. {
  131. if (!bus->ops->preinit)
  132. return 0;
  133. return bus->ops->preinit(bus->dev);
  134. }
  135. static inline void brcmf_bus_stop(struct brcmf_bus *bus)
  136. {
  137. bus->ops->stop(bus->dev);
  138. }
  139. static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
  140. {
  141. return bus->ops->txdata(bus->dev, skb);
  142. }
  143. static inline
  144. int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  145. {
  146. return bus->ops->txctl(bus->dev, msg, len);
  147. }
  148. static inline
  149. int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  150. {
  151. return bus->ops->rxctl(bus->dev, msg, len);
  152. }
  153. static inline
  154. struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
  155. {
  156. if (!bus->ops->gettxq)
  157. return ERR_PTR(-ENOENT);
  158. return bus->ops->gettxq(bus->dev);
  159. }
  160. static inline
  161. void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
  162. {
  163. if (bus->ops->wowl_config)
  164. bus->ops->wowl_config(bus->dev, enabled);
  165. }
  166. /*
  167. * interface functions from common layer
  168. */
  169. bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
  170. int prec);
  171. /* Receive frame for delivery to OS. Callee disposes of rxp. */
  172. void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
  173. /* Indication from bus module regarding presence/insertion of dongle. */
  174. int brcmf_attach(struct device *dev);
  175. /* Indication from bus module regarding removal/absence of dongle */
  176. void brcmf_detach(struct device *dev);
  177. /* Indication from bus module that dongle should be reset */
  178. void brcmf_dev_reset(struct device *dev);
  179. /* Indication from bus module to change flow-control state */
  180. void brcmf_txflowblock(struct device *dev, bool state);
  181. /* Notify the bus has transferred the tx packet to firmware */
  182. void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
  183. /* Configure the "global" bus state used by upper layers */
  184. void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);
  185. int brcmf_bus_start(struct device *dev);
  186. s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
  187. void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
  188. #ifdef CONFIG_BRCMFMAC_SDIO
  189. void brcmf_sdio_exit(void);
  190. void brcmf_sdio_init(void);
  191. void brcmf_sdio_register(void);
  192. #endif
  193. #ifdef CONFIG_BRCMFMAC_USB
  194. void brcmf_usb_exit(void);
  195. void brcmf_usb_register(void);
  196. #endif
  197. #endif /* BRCMFMAC_BUS_H */