brintos

brintos / linux-shallow public Read only

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