bus.h 3.6 KB

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