1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* Copyright (c) 2015 Quantenna Communications. All rights reserved. */ 3 4 #ifndef QTNFMAC_BUS_H 5 #define QTNFMAC_BUS_H 6 7 #include <linux/netdevice.h> 8 #include <linux/workqueue.h> 9 10 #include "trans.h" 11 #include "core.h" 12 13 #define QTNF_MAX_MAC 3 14 15 enum qtnf_fw_state { 16 QTNF_FW_STATE_RESET, 17 QTNF_FW_STATE_FW_DNLD_DONE, 18 QTNF_FW_STATE_BOOT_DONE, 19 QTNF_FW_STATE_ACTIVE, 20 QTNF_FW_STATE_DETACHED, 21 QTNF_FW_STATE_EP_DEAD, 22 }; 23 24 struct qtnf_bus; 25 26 struct qtnf_bus_ops { 27 /* mgmt methods */ 28 int (*preinit)(struct qtnf_bus *); 29 void (*stop)(struct qtnf_bus *); 30 31 /* control path methods */ 32 int (*control_tx)(struct qtnf_bus *, struct sk_buff *); 33 34 /* data xfer methods */ 35 int (*data_tx)(struct qtnf_bus *, struct sk_buff *); 36 void (*data_tx_timeout)(struct qtnf_bus *, struct net_device *); 37 void (*data_rx_start)(struct qtnf_bus *); 38 void (*data_rx_stop)(struct qtnf_bus *); 39 }; 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 struct napi_struct mux_napi; 51 struct net_device mux_dev; 52 struct workqueue_struct *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 /* bus private data */ 58 char bus_priv[0] __aligned(sizeof(void *)); 59 }; 60 61 static inline void *get_bus_priv(struct qtnf_bus *bus) 62 { 63 if (WARN(!bus, "qtnfmac: invalid bus pointer")) 64 return NULL; 65 66 return &bus->bus_priv; 67 } 68 69 /* callback wrappers */ 70 71 static inline int qtnf_bus_preinit(struct qtnf_bus *bus) 72 { 73 if (!bus->bus_ops->preinit) 74 return 0; 75 return bus->bus_ops->preinit(bus); 76 } 77 78 static inline void qtnf_bus_stop(struct qtnf_bus *bus) 79 { 80 if (!bus->bus_ops->stop) 81 return; 82 bus->bus_ops->stop(bus); 83 } 84 85 static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb) 86 { 87 return bus->bus_ops->data_tx(bus, skb); 88 } 89 90 static inline void 91 qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev) 92 { 93 return bus->bus_ops->data_tx_timeout(bus, ndev); 94 } 95 96 static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb) 97 { 98 return bus->bus_ops->control_tx(bus, skb); 99 } 100 101 static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus) 102 { 103 return bus->bus_ops->data_rx_start(bus); 104 } 105 106 static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus) 107 { 108 return bus->bus_ops->data_rx_stop(bus); 109 } 110 111 static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus) 112 { 113 mutex_lock(&bus->bus_lock); 114 } 115 116 static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus) 117 { 118 mutex_unlock(&bus->bus_lock); 119 } 120 121 /* interface functions from common layer */ 122 123 int qtnf_core_attach(struct qtnf_bus *bus); 124 void qtnf_core_detach(struct qtnf_bus *bus); 125 126 #endif /* QTNFMAC_BUS_H */ 127