bus.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. * @get_fwname: obtain firmware name.
  65. *
  66. * This structure provides an abstract interface towards the
  67. * bus specific driver. For control messages to common driver
  68. * will assure there is only one active transaction. Unless
  69. * indicated otherwise these callbacks are mandatory.
  70. */
  71. struct brcmf_bus_ops {
  72. int (*preinit)(struct device *dev);
  73. void (*stop)(struct device *dev);
  74. int (*txdata)(struct device *dev, struct sk_buff *skb);
  75. int (*txctl)(struct device *dev, unsigned char *msg, uint len);
  76. int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
  77. struct pktq * (*gettxq)(struct device *dev);
  78. void (*wowl_config)(struct device *dev, bool enabled);
  79. size_t (*get_ramsize)(struct device *dev);
  80. int (*get_memdump)(struct device *dev, void *data, size_t len);
  81. int (*get_fwname)(struct device *dev, const char *ext,
  82. unsigned char *fw_name);
  83. void (*debugfs_create)(struct device *dev);
  84. };
  85. /**
  86. * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
  87. *
  88. * @commonrings: commonrings which are always there.
  89. * @flowrings: commonrings which are dynamically created and destroyed for data.
  90. * @rx_dataoffset: if set then all rx data has this this offset.
  91. * @max_rxbufpost: maximum number of buffers to post for rx.
  92. * @max_flowrings: maximum number of tx flow rings supported.
  93. * @max_submissionrings: maximum number of submission rings(h2d) supported.
  94. * @max_completionrings: maximum number of completion rings(d2h) supported.
  95. */
  96. struct brcmf_bus_msgbuf {
  97. struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
  98. struct brcmf_commonring **flowrings;
  99. u32 rx_dataoffset;
  100. u32 max_rxbufpost;
  101. u16 max_flowrings;
  102. u16 max_submissionrings;
  103. u16 max_completionrings;
  104. };
  105. /**
  106. * struct brcmf_bus_stats - bus statistic counters.
  107. *
  108. * @pktcowed: packets cowed for extra headroom/unorphan.
  109. * @pktcow_failed: packets dropped due to failed cow-ing.
  110. */
  111. struct brcmf_bus_stats {
  112. atomic_t pktcowed;
  113. atomic_t pktcow_failed;
  114. };
  115. /**
  116. * struct brcmf_bus - interface structure between common and bus layer
  117. *
  118. * @bus_priv: pointer to private bus device.
  119. * @proto_type: protocol type, bcdc or msgbuf
  120. * @dev: device pointer of bus device.
  121. * @drvr: public driver information.
  122. * @state: operational state of the bus interface.
  123. * @stats: statistics shared between common and bus layer.
  124. * @maxctl: maximum size for rxctl request message.
  125. * @chip: device identifier of the dongle chip.
  126. * @always_use_fws_queue: bus wants use queue also when fwsignal is inactive.
  127. * @wowl_supported: is wowl supported by bus driver.
  128. * @chiprev: revision of the dongle chip.
  129. * @msgbuf: msgbuf protocol parameters provided by bus layer.
  130. */
  131. struct brcmf_bus {
  132. union {
  133. struct brcmf_sdio_dev *sdio;
  134. struct brcmf_usbdev *usb;
  135. struct brcmf_pciedev *pcie;
  136. } bus_priv;
  137. enum brcmf_bus_protocol_type proto_type;
  138. struct device *dev;
  139. struct brcmf_pub *drvr;
  140. enum brcmf_bus_state state;
  141. struct brcmf_bus_stats stats;
  142. uint maxctl;
  143. u32 chip;
  144. u32 chiprev;
  145. bool always_use_fws_queue;
  146. bool wowl_supported;
  147. const struct brcmf_bus_ops *ops;
  148. struct brcmf_bus_msgbuf *msgbuf;
  149. };
  150. /*
  151. * callback wrappers
  152. */
  153. static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
  154. {
  155. if (!bus->ops->preinit)
  156. return 0;
  157. return bus->ops->preinit(bus->dev);
  158. }
  159. static inline void brcmf_bus_stop(struct brcmf_bus *bus)
  160. {
  161. bus->ops->stop(bus->dev);
  162. }
  163. static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
  164. {
  165. return bus->ops->txdata(bus->dev, skb);
  166. }
  167. static inline
  168. int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  169. {
  170. return bus->ops->txctl(bus->dev, msg, len);
  171. }
  172. static inline
  173. int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  174. {
  175. return bus->ops->rxctl(bus->dev, msg, len);
  176. }
  177. static inline
  178. struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
  179. {
  180. if (!bus->ops->gettxq)
  181. return ERR_PTR(-ENOENT);
  182. return bus->ops->gettxq(bus->dev);
  183. }
  184. static inline
  185. void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
  186. {
  187. if (bus->ops->wowl_config)
  188. bus->ops->wowl_config(bus->dev, enabled);
  189. }
  190. static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus)
  191. {
  192. if (!bus->ops->get_ramsize)
  193. return 0;
  194. return bus->ops->get_ramsize(bus->dev);
  195. }
  196. static inline
  197. int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len)
  198. {
  199. if (!bus->ops->get_memdump)
  200. return -EOPNOTSUPP;
  201. return bus->ops->get_memdump(bus->dev, data, len);
  202. }
  203. static inline
  204. int brcmf_bus_get_fwname(struct brcmf_bus *bus, const char *ext,
  205. unsigned char *fw_name)
  206. {
  207. return bus->ops->get_fwname(bus->dev, ext, fw_name);
  208. }
  209. static inline
  210. void brcmf_bus_debugfs_create(struct brcmf_bus *bus)
  211. {
  212. if (!bus->ops->debugfs_create)
  213. return;
  214. return bus->ops->debugfs_create(bus->dev);
  215. }
  216. /*
  217. * interface functions from common layer
  218. */
  219. /* Receive frame for delivery to OS. Callee disposes of rxp. */
  220. void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event);
  221. /* Receive async event packet from firmware. Callee disposes of rxp. */
  222. void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
  223. /* Indication from bus module regarding presence/insertion of dongle. */
  224. int brcmf_attach(struct device *dev, struct brcmf_mp_device *settings);
  225. /* Indication from bus module regarding removal/absence of dongle */
  226. void brcmf_detach(struct device *dev);
  227. /* Indication from bus module that dongle should be reset */
  228. void brcmf_dev_reset(struct device *dev);
  229. /* Request from bus module to initiate a coredump */
  230. void brcmf_dev_coredump(struct device *dev);
  231. /* Configure the "global" bus state used by upper layers */
  232. void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);
  233. s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
  234. void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
  235. #ifdef CONFIG_BRCMFMAC_SDIO
  236. void brcmf_sdio_exit(void);
  237. void brcmf_sdio_register(void);
  238. #endif
  239. #ifdef CONFIG_BRCMFMAC_USB
  240. void brcmf_usb_exit(void);
  241. void brcmf_usb_register(void);
  242. #endif
  243. #endif /* BRCMFMAC_BUS_H */