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