bus.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. * @get_ramsize: obtain size of device memory.
  61. * @get_memdump: obtain device memory dump in provided buffer.
  62. *
  63. * This structure provides an abstract interface towards the
  64. * bus specific driver. For control messages to common driver
  65. * will assure there is only one active transaction. Unless
  66. * indicated otherwise these callbacks are mandatory.
  67. */
  68. struct brcmf_bus_ops {
  69. int (*preinit)(struct device *dev);
  70. void (*stop)(struct device *dev);
  71. int (*txdata)(struct device *dev, struct sk_buff *skb);
  72. int (*txctl)(struct device *dev, unsigned char *msg, uint len);
  73. int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
  74. struct pktq * (*gettxq)(struct device *dev);
  75. void (*wowl_config)(struct device *dev, bool enabled);
  76. size_t (*get_ramsize)(struct device *dev);
  77. int (*get_memdump)(struct device *dev, void *data, size_t len);
  78. };
  79. /**
  80. * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
  81. *
  82. * @commonrings: commonrings which are always there.
  83. * @flowrings: commonrings which are dynamically created and destroyed for data.
  84. * @rx_dataoffset: if set then all rx data has this this offset.
  85. * @max_rxbufpost: maximum number of buffers to post for rx.
  86. * @nrof_flowrings: number of flowrings.
  87. */
  88. struct brcmf_bus_msgbuf {
  89. struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
  90. struct brcmf_commonring **flowrings;
  91. u32 rx_dataoffset;
  92. u32 max_rxbufpost;
  93. u32 nrof_flowrings;
  94. };
  95. /**
  96. * struct brcmf_bus - interface structure between common and bus layer
  97. *
  98. * @bus_priv: pointer to private bus device.
  99. * @proto_type: protocol type, bcdc or msgbuf
  100. * @dev: device pointer of bus device.
  101. * @drvr: public driver information.
  102. * @state: operational state of the bus interface.
  103. * @maxctl: maximum size for rxctl request message.
  104. * @tx_realloc: number of tx packets realloced for headroom.
  105. * @dstats: dongle-based statistical data.
  106. * @dcmd_list: bus/device specific dongle initialization commands.
  107. * @chip: device identifier of the dongle chip.
  108. * @wowl_supported: is wowl supported by bus driver.
  109. * @chiprev: revision of the dongle chip.
  110. */
  111. struct brcmf_bus {
  112. union {
  113. struct brcmf_sdio_dev *sdio;
  114. struct brcmf_usbdev *usb;
  115. struct brcmf_pciedev *pcie;
  116. } bus_priv;
  117. enum brcmf_bus_protocol_type proto_type;
  118. struct device *dev;
  119. struct brcmf_pub *drvr;
  120. enum brcmf_bus_state state;
  121. uint maxctl;
  122. unsigned long tx_realloc;
  123. u32 chip;
  124. u32 chiprev;
  125. bool always_use_fws_queue;
  126. bool wowl_supported;
  127. struct brcmf_bus_ops *ops;
  128. struct brcmf_bus_msgbuf *msgbuf;
  129. };
  130. /*
  131. * callback wrappers
  132. */
  133. static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
  134. {
  135. if (!bus->ops->preinit)
  136. return 0;
  137. return bus->ops->preinit(bus->dev);
  138. }
  139. static inline void brcmf_bus_stop(struct brcmf_bus *bus)
  140. {
  141. bus->ops->stop(bus->dev);
  142. }
  143. static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
  144. {
  145. return bus->ops->txdata(bus->dev, skb);
  146. }
  147. static inline
  148. int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  149. {
  150. return bus->ops->txctl(bus->dev, msg, len);
  151. }
  152. static inline
  153. int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  154. {
  155. return bus->ops->rxctl(bus->dev, msg, len);
  156. }
  157. static inline
  158. struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
  159. {
  160. if (!bus->ops->gettxq)
  161. return ERR_PTR(-ENOENT);
  162. return bus->ops->gettxq(bus->dev);
  163. }
  164. static inline
  165. void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
  166. {
  167. if (bus->ops->wowl_config)
  168. bus->ops->wowl_config(bus->dev, enabled);
  169. }
  170. static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus)
  171. {
  172. if (!bus->ops->get_ramsize)
  173. return 0;
  174. return bus->ops->get_ramsize(bus->dev);
  175. }
  176. static inline
  177. int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len)
  178. {
  179. if (!bus->ops->get_memdump)
  180. return -EOPNOTSUPP;
  181. return bus->ops->get_memdump(bus->dev, data, len);
  182. }
  183. /*
  184. * interface functions from common layer
  185. */
  186. bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
  187. int prec);
  188. /* Receive frame for delivery to OS. Callee disposes of rxp. */
  189. void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
  190. /* Indication from bus module regarding presence/insertion of dongle. */
  191. int brcmf_attach(struct device *dev);
  192. /* Indication from bus module regarding removal/absence of dongle */
  193. void brcmf_detach(struct device *dev);
  194. /* Indication from bus module that dongle should be reset */
  195. void brcmf_dev_reset(struct device *dev);
  196. /* Indication from bus module to change flow-control state */
  197. void brcmf_txflowblock(struct device *dev, bool state);
  198. /* Notify the bus has transferred the tx packet to firmware */
  199. void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
  200. /* Configure the "global" bus state used by upper layers */
  201. void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);
  202. int brcmf_bus_start(struct device *dev);
  203. s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
  204. void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
  205. #ifdef CONFIG_BRCMFMAC_SDIO
  206. void brcmf_sdio_exit(void);
  207. void brcmf_sdio_init(void);
  208. void brcmf_sdio_register(void);
  209. #endif
  210. #ifdef CONFIG_BRCMFMAC_USB
  211. void brcmf_usb_exit(void);
  212. void brcmf_usb_register(void);
  213. #endif
  214. #endif /* BRCMFMAC_BUS_H */