1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */
7 #include <linux/interrupt.h>
9 #include <linux/ptp_clock_kernel.h>
10 #include <linux/types.h>
11 #include <linux/workqueue.h>
13 #include "fbnic_csr.h"
15 #include "fbnic_hw_stats.h"
16 #include "fbnic_mac.h"
17 #include "fbnic_rpc.h"
21 struct net_device
*netdev
;
22 struct dentry
*dbg_fbd
;
25 u32 __iomem
*uc_addr0
;
26 u32 __iomem
*uc_addr4
;
27 const struct fbnic_mac
*mac
;
28 unsigned int fw_msix_vector
;
29 unsigned int pcs_msix_vector
;
30 unsigned short num_irqs
;
32 struct delayed_work service_task
;
34 struct fbnic_fw_mbx mbx
[FBNIC_IPC_MBX_INDICES
];
35 struct fbnic_fw_cap fw_cap
;
36 struct fbnic_fw_completion
*cmpl_data
;
37 /* Lock protecting Tx Mailbox queue to prevent possible races */
38 spinlock_t fw_tx_lock
;
40 unsigned long last_heartbeat_request
;
41 unsigned long last_heartbeat_response
;
42 u8 fw_heartbeat_enabled
;
48 /* Local copy of the devices TCAM */
49 struct fbnic_act_tcam act_tcam
[FBNIC_RPC_TCAM_ACT_NUM_ENTRIES
];
50 struct fbnic_mac_addr mac_addr
[FBNIC_RPC_TCAM_MACDA_NUM_ENTRIES
];
54 /* Number of TCQs/RCQs available on hardware */
57 /* Lock protecting writes to @time_high, @time_offset of fbnic_netdev,
58 * and the HW time CSR machinery.
61 /* Externally accessible PTP clock, may be NULL */
62 struct ptp_clock
*ptp
;
63 struct ptp_clock_info ptp_info
;
64 /* Last @time_high refresh time in jiffies (to catch stalls) */
65 unsigned long last_read
;
67 /* Local copy of hardware statistics */
68 struct fbnic_hw_stats hw_stats
;
71 /* Reserve entry 0 in the MSI-X "others" array until we have filled all
72 * 32 of the possible interrupt slots. By doing this we can avoid any
73 * potential conflicts should we need to enable one of the debug interrupt
79 FBNIC_NON_NAPI_VECTORS
82 static inline bool fbnic_present(struct fbnic_dev
*fbd
)
84 return !!READ_ONCE(fbd
->uc_addr0
);
87 static inline void fbnic_wr32(struct fbnic_dev
*fbd
, u32 reg
, u32 val
)
89 u32 __iomem
*csr
= READ_ONCE(fbd
->uc_addr0
);
92 writel(val
, csr
+ reg
);
95 u32
fbnic_rd32(struct fbnic_dev
*fbd
, u32 reg
);
97 static inline void fbnic_wrfl(struct fbnic_dev
*fbd
)
99 fbnic_rd32(fbd
, FBNIC_MASTER_SPARE_0
);
103 fbnic_rmw32(struct fbnic_dev
*fbd
, u32 reg
, u32 mask
, u32 val
)
107 v
= fbnic_rd32(fbd
, reg
);
110 fbnic_wr32(fbd
, reg
, v
);
113 #define wr32(_f, _r, _v) fbnic_wr32(_f, _r, _v)
114 #define rd32(_f, _r) fbnic_rd32(_f, _r)
115 #define wrfl(_f) fbnic_wrfl(_f)
117 bool fbnic_fw_present(struct fbnic_dev
*fbd
);
118 u32
fbnic_fw_rd32(struct fbnic_dev
*fbd
, u32 reg
);
119 void fbnic_fw_wr32(struct fbnic_dev
*fbd
, u32 reg
, u32 val
);
121 #define fw_rd32(_f, _r) fbnic_fw_rd32(_f, _r)
122 #define fw_wr32(_f, _r, _v) fbnic_fw_wr32(_f, _r, _v)
123 #define fw_wrfl(_f) fbnic_fw_rd32(_f, FBNIC_FW_ZERO_REG)
125 static inline bool fbnic_bmc_present(struct fbnic_dev
*fbd
)
127 return fbd
->fw_cap
.bmc_present
;
130 static inline bool fbnic_init_failure(struct fbnic_dev
*fbd
)
135 extern char fbnic_driver_name
[];
137 void fbnic_devlink_free(struct fbnic_dev
*fbd
);
138 struct fbnic_dev
*fbnic_devlink_alloc(struct pci_dev
*pdev
);
139 void fbnic_devlink_register(struct fbnic_dev
*fbd
);
140 void fbnic_devlink_unregister(struct fbnic_dev
*fbd
);
142 int fbnic_fw_enable_mbx(struct fbnic_dev
*fbd
);
143 void fbnic_fw_disable_mbx(struct fbnic_dev
*fbd
);
145 void fbnic_hwmon_register(struct fbnic_dev
*fbd
);
146 void fbnic_hwmon_unregister(struct fbnic_dev
*fbd
);
148 int fbnic_pcs_irq_enable(struct fbnic_dev
*fbd
);
149 void fbnic_pcs_irq_disable(struct fbnic_dev
*fbd
);
151 int fbnic_request_irq(struct fbnic_dev
*dev
, int nr
, irq_handler_t handler
,
152 unsigned long flags
, const char *name
, void *data
);
153 void fbnic_free_irq(struct fbnic_dev
*dev
, int nr
, void *data
);
154 void fbnic_free_irqs(struct fbnic_dev
*fbd
);
155 int fbnic_alloc_irqs(struct fbnic_dev
*fbd
);
157 void fbnic_get_fw_ver_commit_str(struct fbnic_dev
*fbd
, char *fw_version
,
158 const size_t str_sz
);
160 void fbnic_dbg_fbd_init(struct fbnic_dev
*fbd
);
161 void fbnic_dbg_fbd_exit(struct fbnic_dev
*fbd
);
162 void fbnic_dbg_init(void);
163 void fbnic_dbg_exit(void);
165 void fbnic_csr_get_regs(struct fbnic_dev
*fbd
, u32
*data
, u32
*regs_version
);
166 int fbnic_csr_regs_len(struct fbnic_dev
*fbd
);
173 unsigned int max_num_queues
;
174 unsigned int bar_mask
;
177 #endif /* _FBNIC_H_ */