bus.h 7.7 KB

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