bus.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /* Copyright (c) 2015 Quantenna Communications. All rights reserved. */
  3. #ifndef QTNFMAC_BUS_H
  4. #define QTNFMAC_BUS_H
  5. #include <linux/netdevice.h>
  6. #include <linux/workqueue.h>
  7. #include "trans.h"
  8. #include "core.h"
  9. #define QTNF_MAX_MAC 3
  10. #define HBM_FRAME_META_MAGIC_PATTERN_S 0xAB
  11. #define HBM_FRAME_META_MAGIC_PATTERN_E 0xBA
  12. struct qtnf_frame_meta_info {
  13. u8 magic_s;
  14. u8 ifidx;
  15. u8 macid;
  16. u8 magic_e;
  17. } __packed;
  18. enum qtnf_fw_state {
  19. QTNF_FW_STATE_DETACHED,
  20. QTNF_FW_STATE_BOOT_DONE,
  21. QTNF_FW_STATE_ACTIVE,
  22. QTNF_FW_STATE_RUNNING,
  23. QTNF_FW_STATE_DEAD,
  24. };
  25. struct qtnf_bus;
  26. struct qtnf_bus_ops {
  27. /* mgmt methods */
  28. int (*preinit)(struct qtnf_bus *);
  29. void (*stop)(struct qtnf_bus *);
  30. /* control path methods */
  31. int (*control_tx)(struct qtnf_bus *, struct sk_buff *);
  32. /* data xfer methods */
  33. int (*data_tx)(struct qtnf_bus *bus, struct sk_buff *skb,
  34. unsigned int macid, unsigned int vifid);
  35. void (*data_tx_timeout)(struct qtnf_bus *, struct net_device *);
  36. void (*data_tx_use_meta_set)(struct qtnf_bus *bus, bool use_meta);
  37. void (*data_rx_start)(struct qtnf_bus *);
  38. void (*data_rx_stop)(struct qtnf_bus *);
  39. };
  40. struct qtnf_bus {
  41. struct device *dev;
  42. enum qtnf_fw_state fw_state;
  43. u32 chip;
  44. u32 chiprev;
  45. struct qtnf_bus_ops *bus_ops;
  46. struct qtnf_wmac *mac[QTNF_MAX_MAC];
  47. struct qtnf_qlink_transport trans;
  48. struct qtnf_hw_info hw_info;
  49. struct napi_struct mux_napi;
  50. struct net_device mux_dev;
  51. struct workqueue_struct *workqueue;
  52. struct workqueue_struct *hprio_workqueue;
  53. struct work_struct fw_work;
  54. struct work_struct event_work;
  55. struct mutex bus_lock; /* lock during command/event processing */
  56. struct dentry *dbg_dir;
  57. struct notifier_block netdev_nb;
  58. u8 hw_id[ETH_ALEN];
  59. /* bus private data */
  60. char bus_priv[] __aligned(sizeof(void *));
  61. };
  62. static inline bool qtnf_fw_is_up(struct qtnf_bus *bus)
  63. {
  64. enum qtnf_fw_state state = bus->fw_state;
  65. return ((state == QTNF_FW_STATE_ACTIVE) ||
  66. (state == QTNF_FW_STATE_RUNNING));
  67. }
  68. static inline bool qtnf_fw_is_attached(struct qtnf_bus *bus)
  69. {
  70. enum qtnf_fw_state state = bus->fw_state;
  71. return ((state == QTNF_FW_STATE_ACTIVE) ||
  72. (state == QTNF_FW_STATE_RUNNING) ||
  73. (state == QTNF_FW_STATE_DEAD));
  74. }
  75. static inline void *get_bus_priv(struct qtnf_bus *bus)
  76. {
  77. if (WARN(!bus, "qtnfmac: invalid bus pointer"))
  78. return NULL;
  79. return &bus->bus_priv;
  80. }
  81. /* callback wrappers */
  82. static inline int qtnf_bus_preinit(struct qtnf_bus *bus)
  83. {
  84. if (!bus->bus_ops->preinit)
  85. return 0;
  86. return bus->bus_ops->preinit(bus);
  87. }
  88. static inline void qtnf_bus_stop(struct qtnf_bus *bus)
  89. {
  90. if (!bus->bus_ops->stop)
  91. return;
  92. bus->bus_ops->stop(bus);
  93. }
  94. static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb,
  95. unsigned int macid, unsigned int vifid)
  96. {
  97. return bus->bus_ops->data_tx(bus, skb, macid, vifid);
  98. }
  99. static inline void
  100. qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev)
  101. {
  102. return bus->bus_ops->data_tx_timeout(bus, ndev);
  103. }
  104. static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
  105. {
  106. return bus->bus_ops->control_tx(bus, skb);
  107. }
  108. static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus)
  109. {
  110. return bus->bus_ops->data_rx_start(bus);
  111. }
  112. static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus)
  113. {
  114. return bus->bus_ops->data_rx_stop(bus);
  115. }
  116. static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus)
  117. {
  118. mutex_lock(&bus->bus_lock);
  119. }
  120. static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus)
  121. {
  122. mutex_unlock(&bus->bus_lock);
  123. }
  124. /* interface functions from common layer */
  125. int qtnf_core_attach(struct qtnf_bus *bus);
  126. void qtnf_core_detach(struct qtnf_bus *bus);
  127. #endif /* QTNFMAC_BUS_H */