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 dngl_stats {
  25. unsigned long rx_packets; /* total packets received */
  26. unsigned long tx_packets; /* total packets transmitted */
  27. unsigned long rx_bytes; /* total bytes received */
  28. unsigned long tx_bytes; /* total bytes transmitted */
  29. unsigned long rx_errors; /* bad packets received */
  30. unsigned long tx_errors; /* packet transmit problems */
  31. unsigned long rx_dropped; /* packets dropped by dongle */
  32. unsigned long tx_dropped; /* packets dropped by dongle */
  33. unsigned long multicast; /* multicast packets received */
  34. };
  35. struct brcmf_bus_dcmd {
  36. char *name;
  37. char *param;
  38. int param_len;
  39. struct list_head list;
  40. };
  41. /**
  42. * struct brcmf_bus_ops - bus callback operations.
  43. *
  44. * @init: prepare for communication with dongle.
  45. * @stop: clear pending frames, disable data flow.
  46. * @txdata: send a data frame to the dongle (callee disposes skb).
  47. * @txctl: transmit a control request message to dongle.
  48. * @rxctl: receive a control response message from dongle.
  49. *
  50. * This structure provides an abstract interface towards the
  51. * bus specific driver. For control messages to common driver
  52. * will assure there is only one active transaction.
  53. */
  54. struct brcmf_bus_ops {
  55. int (*init)(struct device *dev);
  56. void (*stop)(struct device *dev);
  57. int (*txdata)(struct device *dev, struct sk_buff *skb);
  58. int (*txctl)(struct device *dev, unsigned char *msg, uint len);
  59. int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
  60. };
  61. /**
  62. * struct brcmf_bus - interface structure between common and bus layer
  63. *
  64. * @bus_priv: pointer to private bus device.
  65. * @dev: device pointer of bus device.
  66. * @drvr: public driver information.
  67. * @state: operational state of the bus interface.
  68. * @maxctl: maximum size for rxctl request message.
  69. * @drvr_up: indicates driver up/down status.
  70. * @tx_realloc: number of tx packets realloced for headroom.
  71. * @dstats: dongle-based statistical data.
  72. * @align: alignment requirement for the bus.
  73. * @dcmd_list: bus/device specific dongle initialization commands.
  74. */
  75. struct brcmf_bus {
  76. union {
  77. struct brcmf_sdio_dev *sdio;
  78. struct brcmf_usbdev *usb;
  79. } bus_priv;
  80. struct device *dev;
  81. struct brcmf_pub *drvr;
  82. enum brcmf_bus_state state;
  83. uint maxctl;
  84. bool drvr_up;
  85. unsigned long tx_realloc;
  86. struct dngl_stats dstats;
  87. u8 align;
  88. struct list_head dcmd_list;
  89. struct brcmf_bus_ops *ops;
  90. };
  91. /*
  92. * callback wrappers
  93. */
  94. static inline int brcmf_bus_init(struct brcmf_bus *bus)
  95. {
  96. return bus->ops->init(bus->dev);
  97. }
  98. static inline void brcmf_bus_stop(struct brcmf_bus *bus)
  99. {
  100. bus->ops->stop(bus->dev);
  101. }
  102. static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
  103. {
  104. return bus->ops->txdata(bus->dev, skb);
  105. }
  106. static inline
  107. int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  108. {
  109. return bus->ops->txctl(bus->dev, msg, len);
  110. }
  111. static inline
  112. int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
  113. {
  114. return bus->ops->rxctl(bus->dev, msg, len);
  115. }
  116. /*
  117. * interface functions from common layer
  118. */
  119. /* Remove any protocol-specific data header. */
  120. extern int brcmf_proto_hdrpull(struct device *dev, int *ifidx,
  121. struct sk_buff *rxp);
  122. extern bool brcmf_c_prec_enq(struct device *dev, struct pktq *q,
  123. struct sk_buff *pkt, int prec);
  124. /* Receive frame for delivery to OS. Callee disposes of rxp. */
  125. extern void brcmf_rx_frame(struct device *dev, u8 ifidx,
  126. struct sk_buff_head *rxlist);
  127. static inline void brcmf_rx_packet(struct device *dev, int ifidx,
  128. struct sk_buff *pkt)
  129. {
  130. struct sk_buff_head q;
  131. skb_queue_head_init(&q);
  132. skb_queue_tail(&q, pkt);
  133. brcmf_rx_frame(dev, ifidx, &q);
  134. }
  135. /* Indication from bus module regarding presence/insertion of dongle. */
  136. extern int brcmf_attach(uint bus_hdrlen, struct device *dev);
  137. /* Indication from bus module regarding removal/absence of dongle */
  138. extern void brcmf_detach(struct device *dev);
  139. /* Indication from bus module to change flow-control state */
  140. extern void brcmf_txflowblock(struct device *dev, bool state);
  141. /* Notify tx completion */
  142. extern void brcmf_txcomplete(struct device *dev, struct sk_buff *txp,
  143. bool success);
  144. extern int brcmf_bus_start(struct device *dev);
  145. #ifdef CONFIG_BRCMFMAC_SDIO
  146. extern void brcmf_sdio_exit(void);
  147. extern void brcmf_sdio_init(void);
  148. #endif
  149. #ifdef CONFIG_BRCMFMAC_USB
  150. extern void brcmf_usb_exit(void);
  151. extern void brcmf_usb_init(void);
  152. #endif
  153. #endif /* _BRCMF_BUS_H_ */