bus.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 firmware_init_complete;
  54. struct workqueue_struct *workqueue;
  55. struct work_struct fw_work;
  56. struct work_struct event_work;
  57. struct mutex bus_lock; /* lock during command/event processing */
  58. struct dentry *dbg_dir;
  59. /* bus private data */
  60. char bus_priv[0] __aligned(sizeof(void *));
  61. };
  62. static inline void *get_bus_priv(struct qtnf_bus *bus)
  63. {
  64. if (WARN(!bus, "qtnfmac: invalid bus pointer"))
  65. return NULL;
  66. return &bus->bus_priv;
  67. }
  68. /* callback wrappers */
  69. static inline int qtnf_bus_preinit(struct qtnf_bus *bus)
  70. {
  71. if (!bus->bus_ops->preinit)
  72. return 0;
  73. return bus->bus_ops->preinit(bus);
  74. }
  75. static inline void qtnf_bus_stop(struct qtnf_bus *bus)
  76. {
  77. if (!bus->bus_ops->stop)
  78. return;
  79. bus->bus_ops->stop(bus);
  80. }
  81. static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb)
  82. {
  83. return bus->bus_ops->data_tx(bus, skb);
  84. }
  85. static inline void
  86. qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev)
  87. {
  88. return bus->bus_ops->data_tx_timeout(bus, ndev);
  89. }
  90. static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
  91. {
  92. return bus->bus_ops->control_tx(bus, skb);
  93. }
  94. static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus)
  95. {
  96. return bus->bus_ops->data_rx_start(bus);
  97. }
  98. static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus)
  99. {
  100. return bus->bus_ops->data_rx_stop(bus);
  101. }
  102. static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus)
  103. {
  104. mutex_lock(&bus->bus_lock);
  105. }
  106. static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus)
  107. {
  108. mutex_unlock(&bus->bus_lock);
  109. }
  110. /* interface functions from common layer */
  111. int qtnf_core_attach(struct qtnf_bus *bus);
  112. void qtnf_core_detach(struct qtnf_bus *bus);
  113. void qtnf_txflowblock(struct device *dev, bool state);
  114. void qtnf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
  115. #endif /* QTNFMAC_BUS_H */