0001
0002
0003
0004 #ifndef QTNFMAC_BUS_H
0005 #define QTNFMAC_BUS_H
0006
0007 #include <linux/netdevice.h>
0008 #include <linux/workqueue.h>
0009
0010 #include "trans.h"
0011 #include "core.h"
0012
0013 #define QTNF_MAX_MAC 3
0014
0015 #define HBM_FRAME_META_MAGIC_PATTERN_S 0xAB
0016 #define HBM_FRAME_META_MAGIC_PATTERN_E 0xBA
0017
0018 struct qtnf_frame_meta_info {
0019 u8 magic_s;
0020 u8 ifidx;
0021 u8 macid;
0022 u8 magic_e;
0023 } __packed;
0024
0025 enum qtnf_fw_state {
0026 QTNF_FW_STATE_DETACHED,
0027 QTNF_FW_STATE_BOOT_DONE,
0028 QTNF_FW_STATE_ACTIVE,
0029 QTNF_FW_STATE_RUNNING,
0030 QTNF_FW_STATE_DEAD,
0031 };
0032
0033 struct qtnf_bus;
0034
0035 struct qtnf_bus_ops {
0036
0037 int (*preinit)(struct qtnf_bus *);
0038 void (*stop)(struct qtnf_bus *);
0039
0040
0041 int (*control_tx)(struct qtnf_bus *, struct sk_buff *);
0042
0043
0044 int (*data_tx)(struct qtnf_bus *bus, struct sk_buff *skb,
0045 unsigned int macid, unsigned int vifid);
0046 void (*data_tx_timeout)(struct qtnf_bus *, struct net_device *);
0047 void (*data_tx_use_meta_set)(struct qtnf_bus *bus, bool use_meta);
0048 void (*data_rx_start)(struct qtnf_bus *);
0049 void (*data_rx_stop)(struct qtnf_bus *);
0050 };
0051
0052 struct qtnf_bus {
0053 struct device *dev;
0054 enum qtnf_fw_state fw_state;
0055 u32 chip;
0056 u32 chiprev;
0057 struct qtnf_bus_ops *bus_ops;
0058 struct qtnf_wmac *mac[QTNF_MAX_MAC];
0059 struct qtnf_qlink_transport trans;
0060 struct qtnf_hw_info hw_info;
0061 struct napi_struct mux_napi;
0062 struct net_device mux_dev;
0063 struct workqueue_struct *workqueue;
0064 struct workqueue_struct *hprio_workqueue;
0065 struct work_struct fw_work;
0066 struct work_struct event_work;
0067 struct mutex bus_lock;
0068 struct dentry *dbg_dir;
0069 struct notifier_block netdev_nb;
0070 u8 hw_id[ETH_ALEN];
0071
0072 char bus_priv[] __aligned(sizeof(void *));
0073 };
0074
0075 static inline bool qtnf_fw_is_up(struct qtnf_bus *bus)
0076 {
0077 enum qtnf_fw_state state = bus->fw_state;
0078
0079 return ((state == QTNF_FW_STATE_ACTIVE) ||
0080 (state == QTNF_FW_STATE_RUNNING));
0081 }
0082
0083 static inline bool qtnf_fw_is_attached(struct qtnf_bus *bus)
0084 {
0085 enum qtnf_fw_state state = bus->fw_state;
0086
0087 return ((state == QTNF_FW_STATE_ACTIVE) ||
0088 (state == QTNF_FW_STATE_RUNNING) ||
0089 (state == QTNF_FW_STATE_DEAD));
0090 }
0091
0092 static inline void *get_bus_priv(struct qtnf_bus *bus)
0093 {
0094 if (WARN(!bus, "qtnfmac: invalid bus pointer"))
0095 return NULL;
0096
0097 return &bus->bus_priv;
0098 }
0099
0100
0101
0102 static inline int qtnf_bus_preinit(struct qtnf_bus *bus)
0103 {
0104 if (!bus->bus_ops->preinit)
0105 return 0;
0106 return bus->bus_ops->preinit(bus);
0107 }
0108
0109 static inline void qtnf_bus_stop(struct qtnf_bus *bus)
0110 {
0111 if (!bus->bus_ops->stop)
0112 return;
0113 bus->bus_ops->stop(bus);
0114 }
0115
0116 static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb,
0117 unsigned int macid, unsigned int vifid)
0118 {
0119 return bus->bus_ops->data_tx(bus, skb, macid, vifid);
0120 }
0121
0122 static inline void
0123 qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev)
0124 {
0125 return bus->bus_ops->data_tx_timeout(bus, ndev);
0126 }
0127
0128 static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
0129 {
0130 return bus->bus_ops->control_tx(bus, skb);
0131 }
0132
0133 static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus)
0134 {
0135 return bus->bus_ops->data_rx_start(bus);
0136 }
0137
0138 static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus)
0139 {
0140 return bus->bus_ops->data_rx_stop(bus);
0141 }
0142
0143 static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus)
0144 {
0145 mutex_lock(&bus->bus_lock);
0146 }
0147
0148 static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus)
0149 {
0150 mutex_unlock(&bus->bus_lock);
0151 }
0152
0153
0154
0155 int qtnf_core_attach(struct qtnf_bus *bus);
0156 void qtnf_core_detach(struct qtnf_bus *bus);
0157
0158 #endif