dhd_bus.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 _BRCMF_BUS_H_
  17. #define _BRCMF_BUS_H_
  18. /* The level of bus communication with the dongle */
  19. enum brcmf_bus_state {
  20. BRCMF_BUS_DOWN, /* Not ready for frame transfers */
  21. BRCMF_BUS_LOAD, /* Download access only (CPU reset) */
  22. BRCMF_BUS_DATA /* Ready for frame transfers */
  23. };
  24. struct brcmf_bus_dcmd {
  25. char *name;
  26. char *param;
  27. int param_len;
  28. struct list_head list;
  29. };
  30. /**
  31. * struct brcmf_bus_ops - bus callback operations.
  32. *
  33. * @preinit: execute bus/device specific dongle init commands (optional).
  34. * @init: prepare for communication with dongle.
  35. * @stop: clear pending frames, disable data flow.
  36. * @txdata: send a data frame to the dongle. When the data
  37. * has been transferred, the common driver must be
  38. * notified using brcmf_txcomplete(). The common
  39. * driver calls this function with interrupts
  40. * disabled.
  41. * @txctl: transmit a control request message to dongle.
  42. * @rxctl: receive a control response message from dongle.
  43. * @gettxq: obtain a reference of bus transmit queue (optional).
  44. *
  45. * This structure provides an abstract interface towards the
  46. * bus specific driver. For control messages to common driver
  47. * will assure there is only one active transaction. Unless
  48. * indicated otherwise these callbacks are mandatory.
  49. */
  50. struct brcmf_bus_ops {
  51. int (*preinit)(struct device *dev);
  52. int (*init)(struct device *dev);
  53. void (*stop)(struct device *dev);
  54. int (*txdata)(struct device *dev, struct sk_buff *skb);
  55. int (*txctl)(struct device *dev, unsigned char *msg, uint len);
  56. int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
  57. struct pktq * (*gettxq)(struct device *dev);
  58. };
  59. /**
  60. * struct brcmf_bus - interface structure between common and bus layer
  61. *
  62. * @bus_priv: pointer to private bus device.
  63. * @dev: device pointer of bus device.
  64. * @drvr: public driver information.
  65. * @state: operational state of the bus interface.
  66. * @maxctl: maximum size for rxctl request message.
  67. * @tx_realloc: number of tx packets realloced for headroom.
  68. * @dstats: dongle-based statistical data.
  69. * @dcmd_list: bus/device specific dongle initialization commands.
  70. * @chip: device identifier of the dongle chip.
  71. * @chiprev: revision of the dongle chip.
  72. */
  73. struct brcmf_bus {
  74. union {
  75. struct brcmf_sdio_dev *sdio;
  76. struct brcmf_usbdev *usb;
  77. } bus_priv;
  78. struct device *dev;
  79. struct brcmf_pub *drvr;
  80. enum brcmf_bus_state state;
  81. uint maxctl;
  82. unsigned long tx_realloc;
  83. u32 chip;
  84. u32 chiprev;
  85. struct brcmf_bus_ops *ops;
  86. };
  87. /*
  88. * callback wrappers
  89. */
  90. static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
  91. {
  92. if (!bus->ops->preinit)
  93. return 0;
  94. return bus->ops->preinit(bus->dev);
  95. }
  96. static inline int brcmf_bus_init(struct brcmf_bus *bus)
  97. {
  98. return bus->ops->init(bus->dev);
  99. }
  100. static inline void brcmf_bus_stop(struct brcmf_bus *bus)
  101. {
  102. bus->ops->stop(bus->dev);
  103. }
  104. static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
  105. {
  106. return bus->ops->txdata(bus->dev, skb);
  107. }
  108. static inline
  109. int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  110. {
  111. return bus->ops->txctl(bus->dev, msg, len);
  112. }
  113. static inline
  114. int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  115. {
  116. return bus->ops->rxctl(bus->dev, msg, len);
  117. }
  118. static inline
  119. struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
  120. {
  121. if (!bus->ops->gettxq)
  122. return ERR_PTR(-ENOENT);
  123. return bus->ops->gettxq(bus->dev);
  124. }
  125. /*
  126. * interface functions from common layer
  127. */
  128. bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
  129. int prec);
  130. /* Receive frame for delivery to OS. Callee disposes of rxp. */
  131. void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
  132. /* Indication from bus module regarding presence/insertion of dongle. */
  133. int brcmf_attach(struct device *dev);
  134. /* Indication from bus module regarding removal/absence of dongle */
  135. void brcmf_detach(struct device *dev);
  136. /* Indication from bus module that dongle should be reset */
  137. void brcmf_dev_reset(struct device *dev);
  138. /* Indication from bus module to change flow-control state */
  139. void brcmf_txflowblock(struct device *dev, bool state);
  140. /* Notify the bus has transferred the tx packet to firmware */
  141. void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
  142. int brcmf_bus_start(struct device *dev);
  143. s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data,
  144. u32 len);
  145. void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
  146. #ifdef CONFIG_BRCMFMAC_SDIO
  147. void brcmf_sdio_exit(void);
  148. void brcmf_sdio_init(void);
  149. void brcmf_sdio_register(void);
  150. #endif
  151. #ifdef CONFIG_BRCMFMAC_USB
  152. void brcmf_usb_exit(void);
  153. void brcmf_usb_register(void);
  154. #endif
  155. #endif /* _BRCMF_BUS_H_ */