bus.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2015 Quantenna Communications
  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 QTNFMAC_BUS_H
  17. #define QTNFMAC_BUS_H
  18. #include <linux/netdevice.h>
  19. #include <linux/workqueue.h>
  20. #define QTNF_MAX_MAC 3
  21. enum qtnf_fw_state {
  22. QTNF_FW_STATE_RESET,
  23. QTNF_FW_STATE_FW_DNLD_DONE,
  24. QTNF_FW_STATE_BOOT_DONE,
  25. QTNF_FW_STATE_ACTIVE,
  26. QTNF_FW_STATE_DEAD,
  27. };
  28. struct qtnf_bus;
  29. struct qtnf_bus_ops {
  30. /* mgmt methods */
  31. int (*preinit)(struct qtnf_bus *);
  32. void (*stop)(struct qtnf_bus *);
  33. /* control path methods */
  34. int (*control_tx)(struct qtnf_bus *, struct sk_buff *);
  35. /* data xfer methods */
  36. int (*data_tx)(struct qtnf_bus *, struct sk_buff *);
  37. void (*data_tx_timeout)(struct qtnf_bus *, struct net_device *);
  38. void (*data_rx_start)(struct qtnf_bus *);
  39. void (*data_rx_stop)(struct qtnf_bus *);
  40. };
  41. struct qtnf_bus {
  42. struct device *dev;
  43. enum qtnf_fw_state fw_state;
  44. u32 chip;
  45. u32 chiprev;
  46. const struct qtnf_bus_ops *bus_ops;
  47. struct qtnf_wmac *mac[QTNF_MAX_MAC];
  48. struct qtnf_qlink_transport trans;
  49. struct qtnf_hw_info hw_info;
  50. char fwname[32];
  51. struct napi_struct mux_napi;
  52. struct net_device mux_dev;
  53. struct completion request_firmware_complete;
  54. struct workqueue_struct *workqueue;
  55. struct work_struct event_work;
  56. struct mutex bus_lock; /* lock during command/event processing */
  57. struct dentry *dbg_dir;
  58. /* bus private data */
  59. char bus_priv[0] __aligned(sizeof(void *));
  60. };
  61. static inline void *get_bus_priv(struct qtnf_bus *bus)
  62. {
  63. if (WARN(!bus, "qtnfmac: invalid bus pointer"))
  64. return NULL;
  65. return &bus->bus_priv;
  66. }
  67. /* callback wrappers */
  68. static inline int qtnf_bus_preinit(struct qtnf_bus *bus)
  69. {
  70. if (!bus->bus_ops->preinit)
  71. return 0;
  72. return bus->bus_ops->preinit(bus);
  73. }
  74. static inline void qtnf_bus_stop(struct qtnf_bus *bus)
  75. {
  76. if (!bus->bus_ops->stop)
  77. return;
  78. bus->bus_ops->stop(bus);
  79. }
  80. static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb)
  81. {
  82. return bus->bus_ops->data_tx(bus, skb);
  83. }
  84. static inline void
  85. qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev)
  86. {
  87. return bus->bus_ops->data_tx_timeout(bus, ndev);
  88. }
  89. static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
  90. {
  91. return bus->bus_ops->control_tx(bus, skb);
  92. }
  93. static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus)
  94. {
  95. return bus->bus_ops->data_rx_start(bus);
  96. }
  97. static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus)
  98. {
  99. return bus->bus_ops->data_rx_stop(bus);
  100. }
  101. static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus)
  102. {
  103. mutex_lock(&bus->bus_lock);
  104. }
  105. static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus)
  106. {
  107. mutex_unlock(&bus->bus_lock);
  108. }
  109. /* interface functions from common layer */
  110. int qtnf_core_attach(struct qtnf_bus *bus);
  111. void qtnf_core_detach(struct qtnf_bus *bus);
  112. void qtnf_txflowblock(struct device *dev, bool state);
  113. void qtnf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
  114. #endif /* QTNFMAC_BUS_H */