1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */
3
4 #ifndef _FBNIC_H_
5 #define _FBNIC_H_
6
7 #include <linux/interrupt.h>
8 #include <linux/io.h>
9 #include <linux/types.h>
10 #include <linux/workqueue.h>
11
12 #include "fbnic_csr.h"
13 #include "fbnic_fw.h"
14 #include "fbnic_hw_stats.h"
15 #include "fbnic_mac.h"
16 #include "fbnic_rpc.h"
17
18 struct fbnic_dev {
19 struct device *dev;
20 struct net_device *netdev;
21
22 u32 __iomem *uc_addr0;
23 u32 __iomem *uc_addr4;
24 const struct fbnic_mac *mac;
25 unsigned int fw_msix_vector;
26 unsigned int pcs_msix_vector;
27 unsigned short num_irqs;
28
29 struct delayed_work service_task;
30
31 struct fbnic_fw_mbx mbx[FBNIC_IPC_MBX_INDICES];
32 struct fbnic_fw_cap fw_cap;
33 /* Lock protecting Tx Mailbox queue to prevent possible races */
34 spinlock_t fw_tx_lock;
35
36 unsigned long last_heartbeat_request;
37 unsigned long last_heartbeat_response;
38 u8 fw_heartbeat_enabled;
39
40 u64 dsn;
41 u32 mps;
42 u32 readrq;
43
44 /* Local copy of the devices TCAM */
45 struct fbnic_act_tcam act_tcam[FBNIC_RPC_TCAM_ACT_NUM_ENTRIES];
46 struct fbnic_mac_addr mac_addr[FBNIC_RPC_TCAM_MACDA_NUM_ENTRIES];
47 u8 mac_addr_boundary;
48
49 /* Number of TCQs/RCQs available on hardware */
50 u16 max_num_queues;
51
52 /* Local copy of hardware statistics */
53 struct fbnic_hw_stats hw_stats;
54 };
55
56 /* Reserve entry 0 in the MSI-X "others" array until we have filled all
57 * 32 of the possible interrupt slots. By doing this we can avoid any
58 * potential conflicts should we need to enable one of the debug interrupt
59 * causes later.
60 */
61 enum {
62 FBNIC_FW_MSIX_ENTRY,
63 FBNIC_PCS_MSIX_ENTRY,
64 FBNIC_NON_NAPI_VECTORS
65 };
66
fbnic_present(struct fbnic_dev * fbd)67 static inline bool fbnic_present(struct fbnic_dev *fbd)
68 {
69 return !!READ_ONCE(fbd->uc_addr0);
70 }
71
fbnic_wr32(struct fbnic_dev * fbd,u32 reg,u32 val)72 static inline void fbnic_wr32(struct fbnic_dev *fbd, u32 reg, u32 val)
73 {
74 u32 __iomem *csr = READ_ONCE(fbd->uc_addr0);
75
76 if (csr)
77 writel(val, csr + reg);
78 }
79
80 u32 fbnic_rd32(struct fbnic_dev *fbd, u32 reg);
81
fbnic_wrfl(struct fbnic_dev * fbd)82 static inline void fbnic_wrfl(struct fbnic_dev *fbd)
83 {
84 fbnic_rd32(fbd, FBNIC_MASTER_SPARE_0);
85 }
86
87 static inline void
fbnic_rmw32(struct fbnic_dev * fbd,u32 reg,u32 mask,u32 val)88 fbnic_rmw32(struct fbnic_dev *fbd, u32 reg, u32 mask, u32 val)
89 {
90 u32 v;
91
92 v = fbnic_rd32(fbd, reg);
93 v &= ~mask;
94 v |= val;
95 fbnic_wr32(fbd, reg, v);
96 }
97
98 #define wr32(_f, _r, _v) fbnic_wr32(_f, _r, _v)
99 #define rd32(_f, _r) fbnic_rd32(_f, _r)
100 #define wrfl(_f) fbnic_wrfl(_f)
101
102 bool fbnic_fw_present(struct fbnic_dev *fbd);
103 u32 fbnic_fw_rd32(struct fbnic_dev *fbd, u32 reg);
104 void fbnic_fw_wr32(struct fbnic_dev *fbd, u32 reg, u32 val);
105
106 #define fw_rd32(_f, _r) fbnic_fw_rd32(_f, _r)
107 #define fw_wr32(_f, _r, _v) fbnic_fw_wr32(_f, _r, _v)
108 #define fw_wrfl(_f) fbnic_fw_rd32(_f, FBNIC_FW_ZERO_REG)
109
fbnic_bmc_present(struct fbnic_dev * fbd)110 static inline bool fbnic_bmc_present(struct fbnic_dev *fbd)
111 {
112 return fbd->fw_cap.bmc_present;
113 }
114
fbnic_init_failure(struct fbnic_dev * fbd)115 static inline bool fbnic_init_failure(struct fbnic_dev *fbd)
116 {
117 return !fbd->netdev;
118 }
119
120 extern char fbnic_driver_name[];
121
122 void fbnic_devlink_free(struct fbnic_dev *fbd);
123 struct fbnic_dev *fbnic_devlink_alloc(struct pci_dev *pdev);
124 void fbnic_devlink_register(struct fbnic_dev *fbd);
125 void fbnic_devlink_unregister(struct fbnic_dev *fbd);
126
127 int fbnic_fw_enable_mbx(struct fbnic_dev *fbd);
128 void fbnic_fw_disable_mbx(struct fbnic_dev *fbd);
129
130 int fbnic_pcs_irq_enable(struct fbnic_dev *fbd);
131 void fbnic_pcs_irq_disable(struct fbnic_dev *fbd);
132
133 int fbnic_request_irq(struct fbnic_dev *dev, int nr, irq_handler_t handler,
134 unsigned long flags, const char *name, void *data);
135 void fbnic_free_irq(struct fbnic_dev *dev, int nr, void *data);
136 void fbnic_free_irqs(struct fbnic_dev *fbd);
137 int fbnic_alloc_irqs(struct fbnic_dev *fbd);
138
139 void fbnic_get_fw_ver_commit_str(struct fbnic_dev *fbd, char *fw_version,
140 const size_t str_sz);
141
142 enum fbnic_boards {
143 fbnic_board_asic
144 };
145
146 struct fbnic_info {
147 unsigned int max_num_queues;
148 unsigned int bar_mask;
149 };
150
151 #endif /* _FBNIC_H_ */
152