|
| 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_act_tcam act_tcam[FBNIC_RPC_TCAM_ACT_NUM_ENTRIES]; |
| 45 | + struct fbnic_mac_addr mac_addr[FBNIC_RPC_TCAM_MACDA_NUM_ENTRIES]; |
| 46 | + u8 mac_addr_boundary; |
| 47 | + |
| 48 | + /* Number of TCQs/RCQs available on hardware */ |
| 49 | + u16 max_num_queues; |
| 50 | +}; |
| 51 | + |
| 52 | +/* Reserve entry 0 in the MSI-X "others" array until we have filled all |
| 53 | + * 32 of the possible interrupt slots. By doing this we can avoid any |
| 54 | + * potential conflicts should we need to enable one of the debug interrupt |
| 55 | + * causes later. |
| 56 | + */ |
| 57 | +enum { |
| 58 | + FBNIC_FW_MSIX_ENTRY, |
| 59 | + FBNIC_PCS_MSIX_ENTRY, |
| 60 | + FBNIC_NON_NAPI_VECTORS |
| 61 | +}; |
| 62 | + |
| 63 | +static inline bool fbnic_present(struct fbnic_dev *fbd) |
| 64 | +{ |
| 65 | + return !!READ_ONCE(fbd->uc_addr0); |
| 66 | +} |
| 67 | + |
| 68 | +static inline void fbnic_wr32(struct fbnic_dev *fbd, u32 reg, u32 val) |
| 69 | +{ |
| 70 | + u32 __iomem *csr = READ_ONCE(fbd->uc_addr0); |
| 71 | + |
| 72 | + if (csr) |
| 73 | + writel(val, csr + reg); |
| 74 | +} |
| 75 | + |
| 76 | +u32 fbnic_rd32(struct fbnic_dev *fbd, u32 reg); |
| 77 | + |
| 78 | +static inline void fbnic_wrfl(struct fbnic_dev *fbd) |
| 79 | +{ |
| 80 | + fbnic_rd32(fbd, FBNIC_MASTER_SPARE_0); |
| 81 | +} |
| 82 | + |
| 83 | +static inline void |
| 84 | +fbnic_rmw32(struct fbnic_dev *fbd, u32 reg, u32 mask, u32 val) |
| 85 | +{ |
| 86 | + u32 v; |
| 87 | + |
| 88 | + v = fbnic_rd32(fbd, reg); |
| 89 | + v &= ~mask; |
| 90 | + v |= val; |
| 91 | + fbnic_wr32(fbd, reg, v); |
| 92 | +} |
| 93 | + |
| 94 | +#define wr32(_f, _r, _v) fbnic_wr32(_f, _r, _v) |
| 95 | +#define rd32(_f, _r) fbnic_rd32(_f, _r) |
| 96 | +#define wrfl(_f) fbnic_wrfl(_f) |
| 97 | + |
| 98 | +bool fbnic_fw_present(struct fbnic_dev *fbd); |
| 99 | +u32 fbnic_fw_rd32(struct fbnic_dev *fbd, u32 reg); |
| 100 | +void fbnic_fw_wr32(struct fbnic_dev *fbd, u32 reg, u32 val); |
| 101 | + |
| 102 | +#define fw_rd32(_f, _r) fbnic_fw_rd32(_f, _r) |
| 103 | +#define fw_wr32(_f, _r, _v) fbnic_fw_wr32(_f, _r, _v) |
| 104 | +#define fw_wrfl(_f) fbnic_fw_rd32(_f, FBNIC_FW_ZERO_REG) |
| 105 | + |
| 106 | +static inline bool fbnic_bmc_present(struct fbnic_dev *fbd) |
| 107 | +{ |
| 108 | + return fbd->fw_cap.bmc_present; |
| 109 | +} |
| 110 | + |
| 111 | +static inline bool fbnic_init_failure(struct fbnic_dev *fbd) |
| 112 | +{ |
| 113 | + return !fbd->netdev; |
| 114 | +} |
| 115 | + |
| 116 | +extern char fbnic_driver_name[]; |
| 117 | + |
| 118 | +void fbnic_devlink_free(struct fbnic_dev *fbd); |
| 119 | +struct fbnic_dev *fbnic_devlink_alloc(struct pci_dev *pdev); |
| 120 | +void fbnic_devlink_register(struct fbnic_dev *fbd); |
| 121 | +void fbnic_devlink_unregister(struct fbnic_dev *fbd); |
| 122 | + |
| 123 | +int fbnic_fw_enable_mbx(struct fbnic_dev *fbd); |
| 124 | +void fbnic_fw_disable_mbx(struct fbnic_dev *fbd); |
| 125 | + |
| 126 | +int fbnic_pcs_irq_enable(struct fbnic_dev *fbd); |
| 127 | +void fbnic_pcs_irq_disable(struct fbnic_dev *fbd); |
| 128 | + |
| 129 | +int fbnic_request_irq(struct fbnic_dev *dev, int nr, irq_handler_t handler, |
| 130 | + unsigned long flags, const char *name, void *data); |
| 131 | +void fbnic_free_irq(struct fbnic_dev *dev, int nr, void *data); |
| 132 | +void fbnic_free_irqs(struct fbnic_dev *fbd); |
| 133 | +int fbnic_alloc_irqs(struct fbnic_dev *fbd); |
| 134 | + |
| 135 | +enum fbnic_boards { |
| 136 | + fbnic_board_asic |
| 137 | +}; |
| 138 | + |
| 139 | +struct fbnic_info { |
| 140 | + unsigned int max_num_queues; |
| 141 | + unsigned int bar_mask; |
| 142 | +}; |
| 143 | + |
| 144 | +#endif /* _FBNIC_H_ */ |
0 commit comments