xref: /linux/drivers/net/ethernet/pensando/ionic/ionic.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
3 
4 #ifndef _IONIC_H_
5 #define _IONIC_H_
6 
7 struct ionic_lif;
8 
9 #include "ionic_if.h"
10 #include "ionic_dev.h"
11 #include "ionic_devlink.h"
12 
13 #define IONIC_DRV_NAME		"ionic"
14 #define IONIC_DRV_DESCRIPTION	"Pensando Ethernet NIC Driver"
15 
16 #define PCI_VENDOR_ID_PENSANDO			0x1dd8
17 
18 #define PCI_DEVICE_ID_PENSANDO_IONIC_ETH_PF	0x1002
19 #define PCI_DEVICE_ID_PENSANDO_IONIC_ETH_VF	0x1003
20 
21 #define IONIC_ASIC_TYPE_ELBA	2
22 
23 #define DEVCMD_TIMEOUT			5
24 #define IONIC_ADMINQ_TIME_SLICE		msecs_to_jiffies(100)
25 
26 #define IONIC_PHC_UPDATE_NS	10000000000	    /* 10s in nanoseconds */
27 #define NORMAL_PPB		1000000000	    /* one billion parts per billion */
28 #define SCALED_PPM		(1000000ull << 16)  /* 2^16 million parts per 2^16 million */
29 
30 struct ionic_vf {
31 	u16	 index;
32 	u8	 macaddr[6];
33 	__le32	 maxrate;
34 	__le16	 vlanid;
35 	u8	 spoofchk;
36 	u8	 trusted;
37 	u8	 linkstate;
38 	dma_addr_t       stats_pa;
39 	struct ionic_lif_stats stats;
40 };
41 
42 struct ionic {
43 	struct pci_dev *pdev;
44 	struct device *dev;
45 	struct devlink_port dl_port;
46 	struct ionic_dev idev;
47 	struct mutex dev_cmd_lock;	/* lock for dev_cmd operations */
48 	struct dentry *dentry;
49 	struct ionic_dev_bar bars[IONIC_BARS_MAX];
50 	unsigned int num_bars;
51 	struct ionic_identity ident;
52 	struct workqueue_struct *wq;
53 	struct ionic_lif *lif;
54 	unsigned int nnqs_per_lif;
55 	unsigned int neqs_per_lif;
56 	unsigned int ntxqs_per_lif;
57 	unsigned int nrxqs_per_lif;
58 	unsigned int nintrs;
59 	DECLARE_BITMAP(intrs, IONIC_INTR_CTRL_REGS_MAX);
60 	cpumask_var_t *affinity_masks;
61 	struct delayed_work doorbell_check_dwork;
62 	struct work_struct nb_work;
63 	struct notifier_block nb;
64 	struct rw_semaphore vf_op_lock;	/* lock for VF operations */
65 	struct ionic_vf *vfs;
66 	int num_vfs;
67 	struct timer_list watchdog_timer;
68 	int watchdog_period;
69 };
70 
71 struct ionic_admin_ctx {
72 	struct completion work;
73 	union ionic_adminq_cmd cmd;
74 	union ionic_adminq_comp comp;
75 };
76 
77 int ionic_adminq_post(struct ionic_lif *lif, struct ionic_admin_ctx *ctx);
78 int ionic_adminq_wait(struct ionic_lif *lif, struct ionic_admin_ctx *ctx,
79 		      const int err, const bool do_msg);
80 int ionic_adminq_post_wait(struct ionic_lif *lif, struct ionic_admin_ctx *ctx);
81 int ionic_adminq_post_wait_nomsg(struct ionic_lif *lif, struct ionic_admin_ctx *ctx);
82 void ionic_adminq_netdev_err_print(struct ionic_lif *lif, u8 opcode,
83 				   u8 status, int err);
84 bool ionic_notifyq_service(struct ionic_cq *cq);
85 bool ionic_adminq_service(struct ionic_cq *cq);
86 
87 int ionic_dev_cmd_wait(struct ionic *ionic, unsigned long max_wait);
88 int ionic_dev_cmd_wait_nomsg(struct ionic *ionic, unsigned long max_wait);
89 void ionic_dev_cmd_dev_err_print(struct ionic *ionic, u8 opcode, u8 status,
90 				 int err);
91 int ionic_setup(struct ionic *ionic);
92 
93 int ionic_identify(struct ionic *ionic);
94 int ionic_init(struct ionic *ionic);
95 int ionic_reset(struct ionic *ionic);
96 
97 int ionic_port_identify(struct ionic *ionic);
98 int ionic_port_init(struct ionic *ionic);
99 int ionic_port_reset(struct ionic *ionic);
100 
101 bool ionic_doorbell_wa(struct ionic *ionic);
102 
103 #endif /* _IONIC_H_ */
104