xref: /linux/drivers/net/ethernet/meta/fbnic/fbnic.h (revision 20d2e88cc7461b03b97293d62d780a2d4b08ed8b)
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_mac.h"
15 
16 struct fbnic_dev {
17 	struct device *dev;
18 	struct net_device *netdev;
19 
20 	u32 __iomem *uc_addr0;
21 	u32 __iomem *uc_addr4;
22 	const struct fbnic_mac *mac;
23 	unsigned int fw_msix_vector;
24 	unsigned short num_irqs;
25 
26 	struct delayed_work service_task;
27 
28 	struct fbnic_fw_mbx mbx[FBNIC_IPC_MBX_INDICES];
29 	struct fbnic_fw_cap fw_cap;
30 	/* Lock protecting Tx Mailbox queue to prevent possible races */
31 	spinlock_t fw_tx_lock;
32 
33 	unsigned long last_heartbeat_request;
34 	unsigned long last_heartbeat_response;
35 	u8 fw_heartbeat_enabled;
36 
37 	u64 dsn;
38 	u32 mps;
39 	u32 readrq;
40 
41 	/* Number of TCQs/RCQs available on hardware */
42 	u16 max_num_queues;
43 };
44 
45 /* Reserve entry 0 in the MSI-X "others" array until we have filled all
46  * 32 of the possible interrupt slots. By doing this we can avoid any
47  * potential conflicts should we need to enable one of the debug interrupt
48  * causes later.
49  */
50 enum {
51 	FBNIC_FW_MSIX_ENTRY,
52 	FBNIC_NON_NAPI_VECTORS
53 };
54 
55 static inline bool fbnic_present(struct fbnic_dev *fbd)
56 {
57 	return !!READ_ONCE(fbd->uc_addr0);
58 }
59 
60 static inline void fbnic_wr32(struct fbnic_dev *fbd, u32 reg, u32 val)
61 {
62 	u32 __iomem *csr = READ_ONCE(fbd->uc_addr0);
63 
64 	if (csr)
65 		writel(val, csr + reg);
66 }
67 
68 u32 fbnic_rd32(struct fbnic_dev *fbd, u32 reg);
69 
70 static inline void fbnic_wrfl(struct fbnic_dev *fbd)
71 {
72 	fbnic_rd32(fbd, FBNIC_MASTER_SPARE_0);
73 }
74 
75 static inline void
76 fbnic_rmw32(struct fbnic_dev *fbd, u32 reg, u32 mask, u32 val)
77 {
78 	u32 v;
79 
80 	v = fbnic_rd32(fbd, reg);
81 	v &= ~mask;
82 	v |= val;
83 	fbnic_wr32(fbd, reg, v);
84 }
85 
86 #define wr32(_f, _r, _v)	fbnic_wr32(_f, _r, _v)
87 #define rd32(_f, _r)		fbnic_rd32(_f, _r)
88 #define wrfl(_f)		fbnic_wrfl(_f)
89 
90 bool fbnic_fw_present(struct fbnic_dev *fbd);
91 u32 fbnic_fw_rd32(struct fbnic_dev *fbd, u32 reg);
92 void fbnic_fw_wr32(struct fbnic_dev *fbd, u32 reg, u32 val);
93 
94 #define fw_rd32(_f, _r)		fbnic_fw_rd32(_f, _r)
95 #define fw_wr32(_f, _r, _v)	fbnic_fw_wr32(_f, _r, _v)
96 #define fw_wrfl(_f)		fbnic_fw_rd32(_f, FBNIC_FW_ZERO_REG)
97 
98 static inline bool fbnic_init_failure(struct fbnic_dev *fbd)
99 {
100 	return !fbd->netdev;
101 }
102 
103 extern char fbnic_driver_name[];
104 
105 void fbnic_devlink_free(struct fbnic_dev *fbd);
106 struct fbnic_dev *fbnic_devlink_alloc(struct pci_dev *pdev);
107 void fbnic_devlink_register(struct fbnic_dev *fbd);
108 void fbnic_devlink_unregister(struct fbnic_dev *fbd);
109 
110 int fbnic_fw_enable_mbx(struct fbnic_dev *fbd);
111 void fbnic_fw_disable_mbx(struct fbnic_dev *fbd);
112 
113 int fbnic_request_irq(struct fbnic_dev *dev, int nr, irq_handler_t handler,
114 		      unsigned long flags, const char *name, void *data);
115 void fbnic_free_irq(struct fbnic_dev *dev, int nr, void *data);
116 void fbnic_free_irqs(struct fbnic_dev *fbd);
117 int fbnic_alloc_irqs(struct fbnic_dev *fbd);
118 
119 enum fbnic_boards {
120 	fbnic_board_asic
121 };
122 
123 struct fbnic_info {
124 	unsigned int max_num_queues;
125 	unsigned int bar_mask;
126 };
127 
128 #endif /* _FBNIC_H_ */
129