bus.h 7.4 KB

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