1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (c) 2015 Quantenna Communications. All rights reserved. */
7 #include <linux/netdevice.h>
8 #include <linux/workqueue.h>
13 #define QTNF_MAX_MAC 3
15 #define HBM_FRAME_META_MAGIC_PATTERN_S 0xAB
16 #define HBM_FRAME_META_MAGIC_PATTERN_E 0xBA
18 struct qtnf_frame_meta_info
{
26 QTNF_FW_STATE_DETACHED
,
27 QTNF_FW_STATE_BOOT_DONE
,
29 QTNF_FW_STATE_RUNNING
,
37 int (*preinit
)(struct qtnf_bus
*);
38 void (*stop
)(struct qtnf_bus
*);
40 /* control path methods */
41 int (*control_tx
)(struct qtnf_bus
*, struct sk_buff
*);
43 /* data xfer methods */
44 int (*data_tx
)(struct qtnf_bus
*bus
, struct sk_buff
*skb
,
45 unsigned int macid
, unsigned int vifid
);
46 void (*data_tx_timeout
)(struct qtnf_bus
*, struct net_device
*);
47 void (*data_tx_use_meta_set
)(struct qtnf_bus
*bus
, bool use_meta
);
48 void (*data_rx_start
)(struct qtnf_bus
*);
49 void (*data_rx_stop
)(struct qtnf_bus
*);
54 enum qtnf_fw_state fw_state
;
57 struct qtnf_bus_ops
*bus_ops
;
58 struct qtnf_wmac
*mac
[QTNF_MAX_MAC
];
59 struct qtnf_qlink_transport trans
;
60 struct qtnf_hw_info hw_info
;
61 struct napi_struct mux_napi
;
62 struct net_device mux_dev
;
63 struct workqueue_struct
*workqueue
;
64 struct workqueue_struct
*hprio_workqueue
;
65 struct work_struct fw_work
;
66 struct work_struct event_work
;
67 struct mutex bus_lock
; /* lock during command/event processing */
68 struct dentry
*dbg_dir
;
69 struct notifier_block netdev_nb
;
71 /* bus private data */
72 char bus_priv
[0] __aligned(sizeof(void *));
75 static inline bool qtnf_fw_is_up(struct qtnf_bus
*bus
)
77 enum qtnf_fw_state state
= bus
->fw_state
;
79 return ((state
== QTNF_FW_STATE_ACTIVE
) ||
80 (state
== QTNF_FW_STATE_RUNNING
));
83 static inline bool qtnf_fw_is_attached(struct qtnf_bus
*bus
)
85 enum qtnf_fw_state state
= bus
->fw_state
;
87 return ((state
== QTNF_FW_STATE_ACTIVE
) ||
88 (state
== QTNF_FW_STATE_RUNNING
) ||
89 (state
== QTNF_FW_STATE_DEAD
));
92 static inline void *get_bus_priv(struct qtnf_bus
*bus
)
94 if (WARN(!bus
, "qtnfmac: invalid bus pointer"))
97 return &bus
->bus_priv
;
100 /* callback wrappers */
102 static inline int qtnf_bus_preinit(struct qtnf_bus
*bus
)
104 if (!bus
->bus_ops
->preinit
)
106 return bus
->bus_ops
->preinit(bus
);
109 static inline void qtnf_bus_stop(struct qtnf_bus
*bus
)
111 if (!bus
->bus_ops
->stop
)
113 bus
->bus_ops
->stop(bus
);
116 static inline int qtnf_bus_data_tx(struct qtnf_bus
*bus
, struct sk_buff
*skb
,
117 unsigned int macid
, unsigned int vifid
)
119 return bus
->bus_ops
->data_tx(bus
, skb
, macid
, vifid
);
123 qtnf_bus_data_tx_timeout(struct qtnf_bus
*bus
, struct net_device
*ndev
)
125 return bus
->bus_ops
->data_tx_timeout(bus
, ndev
);
128 static inline int qtnf_bus_control_tx(struct qtnf_bus
*bus
, struct sk_buff
*skb
)
130 return bus
->bus_ops
->control_tx(bus
, skb
);
133 static inline void qtnf_bus_data_rx_start(struct qtnf_bus
*bus
)
135 return bus
->bus_ops
->data_rx_start(bus
);
138 static inline void qtnf_bus_data_rx_stop(struct qtnf_bus
*bus
)
140 return bus
->bus_ops
->data_rx_stop(bus
);
143 static __always_inline
void qtnf_bus_lock(struct qtnf_bus
*bus
)
145 mutex_lock(&bus
->bus_lock
);
148 static __always_inline
void qtnf_bus_unlock(struct qtnf_bus
*bus
)
150 mutex_unlock(&bus
->bus_lock
);
153 /* interface functions from common layer */
155 int qtnf_core_attach(struct qtnf_bus
*bus
);
156 void qtnf_core_detach(struct qtnf_bus
*bus
);
158 #endif /* QTNFMAC_BUS_H */