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