bus.h 8.0 KB

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