dhd_bus.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. * @init: prepare for communication with dongle.
  34. * @stop: clear pending frames, disable data flow.
  35. * @txdata: send a data frame to the dongle (callee disposes skb).
  36. * @txctl: transmit a control request message to dongle.
  37. * @rxctl: receive a control response message from dongle.
  38. * @gettxq: obtain a reference of bus transmit queue (optional).
  39. *
  40. * This structure provides an abstract interface towards the
  41. * bus specific driver. For control messages to common driver
  42. * will assure there is only one active transaction. Unless
  43. * indicated otherwise these callbacks are mandatory.
  44. */
  45. struct brcmf_bus_ops {
  46. int (*init)(struct device *dev);
  47. void (*stop)(struct device *dev);
  48. int (*txdata)(struct device *dev, struct sk_buff *skb);
  49. int (*txctl)(struct device *dev, unsigned char *msg, uint len);
  50. int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
  51. struct pktq * (*gettxq)(struct device *dev);
  52. };
  53. /**
  54. * struct brcmf_bus - interface structure between common and bus layer
  55. *
  56. * @bus_priv: pointer to private bus device.
  57. * @dev: device pointer of bus device.
  58. * @drvr: public driver information.
  59. * @state: operational state of the bus interface.
  60. * @maxctl: maximum size for rxctl request message.
  61. * @tx_realloc: number of tx packets realloced for headroom.
  62. * @dstats: dongle-based statistical data.
  63. * @align: alignment requirement for the bus.
  64. * @dcmd_list: bus/device specific dongle initialization commands.
  65. * @chip: device identifier of the dongle chip.
  66. * @chiprev: revision of the dongle chip.
  67. */
  68. struct brcmf_bus {
  69. union {
  70. struct brcmf_sdio_dev *sdio;
  71. struct brcmf_usbdev *usb;
  72. } bus_priv;
  73. struct device *dev;
  74. struct brcmf_pub *drvr;
  75. enum brcmf_bus_state state;
  76. uint maxctl;
  77. unsigned long tx_realloc;
  78. u8 align;
  79. u32 chip;
  80. u32 chiprev;
  81. struct list_head dcmd_list;
  82. struct brcmf_bus_ops *ops;
  83. };
  84. /*
  85. * callback wrappers
  86. */
  87. static inline int brcmf_bus_init(struct brcmf_bus *bus)
  88. {
  89. return bus->ops->init(bus->dev);
  90. }
  91. static inline void brcmf_bus_stop(struct brcmf_bus *bus)
  92. {
  93. bus->ops->stop(bus->dev);
  94. }
  95. static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
  96. {
  97. return bus->ops->txdata(bus->dev, skb);
  98. }
  99. static inline
  100. int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  101. {
  102. return bus->ops->txctl(bus->dev, msg, len);
  103. }
  104. static inline
  105. int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  106. {
  107. return bus->ops->rxctl(bus->dev, msg, len);
  108. }
  109. static inline
  110. struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
  111. {
  112. if (!bus->ops->gettxq)
  113. return ERR_PTR(-ENOENT);
  114. return bus->ops->gettxq(bus->dev);
  115. }
  116. /*
  117. * interface functions from common layer
  118. */
  119. extern bool brcmf_c_prec_enq(struct device *dev, struct pktq *q,
  120. struct sk_buff *pkt, int prec);
  121. /* Receive frame for delivery to OS. Callee disposes of rxp. */
  122. extern void brcmf_rx_frames(struct device *dev, struct sk_buff_head *rxlist);
  123. /* Indication from bus module regarding presence/insertion of dongle. */
  124. extern int brcmf_attach(uint bus_hdrlen, struct device *dev);
  125. /* Indication from bus module regarding removal/absence of dongle */
  126. extern void brcmf_detach(struct device *dev);
  127. /* Indication from bus module that dongle should be reset */
  128. extern void brcmf_dev_reset(struct device *dev);
  129. /* Indication from bus module to change flow-control state */
  130. extern void brcmf_txflowblock(struct device *dev, bool state);
  131. /* Notify the bus has transferred the tx packet to firmware */
  132. extern void brcmf_txcomplete(struct device *dev, struct sk_buff *txp,
  133. bool success);
  134. extern int brcmf_bus_start(struct device *dev);
  135. #ifdef CONFIG_BRCMFMAC_SDIO
  136. extern void brcmf_sdio_exit(void);
  137. extern void brcmf_sdio_init(void);
  138. #endif
  139. #ifdef CONFIG_BRCMFMAC_USB
  140. extern void brcmf_usb_exit(void);
  141. extern void brcmf_usb_init(void);
  142. #endif
  143. #endif /* _BRCMF_BUS_H_ */