xref: /linux/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 /* Broadcom NetXtreme-C/E network driver.
2  *
3  * Copyright (c) 2016-2018 Broadcom Limited
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation.
8  */
9 
10 #ifndef BNXT_ULP_H
11 #define BNXT_ULP_H
12 
13 #define BNXT_ROCE_ULP	0
14 #define BNXT_MAX_ULP	1
15 
16 #define BNXT_MIN_ROCE_CP_RINGS	2
17 #define BNXT_MIN_ROCE_STAT_CTXS	1
18 
19 #define BNXT_MAX_ROCE_MSIX_VF		2
20 #define BNXT_MAX_ROCE_MSIX_NPAR_PF	5
21 #define BNXT_MAX_ROCE_MSIX		64
22 
23 struct hwrm_async_event_cmpl;
24 struct bnxt;
25 
26 struct bnxt_msix_entry {
27 	u32	vector;
28 	u32	ring_idx;
29 	u32	db_offset;
30 };
31 
32 struct bnxt_ulp_ops {
33 	void (*ulp_irq_stop)(void *);
34 	void (*ulp_irq_restart)(void *, struct bnxt_msix_entry *);
35 };
36 
37 struct bnxt_fw_msg {
38 	void	*msg;
39 	int	msg_len;
40 	void	*resp;
41 	int	resp_max_len;
42 	int	timeout;
43 };
44 
45 struct bnxt_ulp {
46 	void		*handle;
47 	struct bnxt_ulp_ops __rcu *ulp_ops;
48 	unsigned long	*async_events_bmap;
49 	u16		max_async_event_id;
50 	u16		msix_requested;
51 	atomic_t	ref_count;
52 };
53 
54 struct bnxt_en_dev {
55 	struct net_device *net;
56 	struct pci_dev *pdev;
57 	struct bnxt_msix_entry			msix_entries[BNXT_MAX_ROCE_MSIX];
58 	u32 flags;
59 	#define BNXT_EN_FLAG_ROCEV1_CAP		0x1
60 	#define BNXT_EN_FLAG_ROCEV2_CAP		0x2
61 	#define BNXT_EN_FLAG_ROCE_CAP		(BNXT_EN_FLAG_ROCEV1_CAP | \
62 						 BNXT_EN_FLAG_ROCEV2_CAP)
63 	#define BNXT_EN_FLAG_MSIX_REQUESTED	0x4
64 	#define BNXT_EN_FLAG_ULP_STOPPED	0x8
65 	#define BNXT_EN_FLAG_VF			0x10
66 #define BNXT_EN_VF(edev)	((edev)->flags & BNXT_EN_FLAG_VF)
67 	#define BNXT_EN_FLAG_ROCE_VF_RES_MGMT	0x20
68 
69 	struct bnxt_ulp			*ulp_tbl;
70 	int				l2_db_size;	/* Doorbell BAR size in
71 							 * bytes mapped by L2
72 							 * driver.
73 							 */
74 	int				l2_db_size_nc;	/* Doorbell BAR size in
75 							 * bytes mapped as non-
76 							 * cacheable.
77 							 */
78 	int				l2_db_offset;	/* Doorbell offset in
79 							 * bytes within
80 							 * l2_db_size_nc.
81 							 */
82 	u16				chip_num;
83 	u16				hw_ring_stats_size;
84 	u16				pf_port_id;
85 	unsigned long			en_state;	/* Could be checked in
86 							 * RoCE driver suspend
87 							 * mode only. Will be
88 							 * updated in resume.
89 							 */
90 	void __iomem                    *bar0;
91 
92 	u16				ulp_num_msix_vec;
93 	u16				ulp_num_ctxs;
94 
95 					/* serialize ulp operations */
96 	struct mutex			en_dev_lock;
97 };
98 
99 static inline bool bnxt_ulp_registered(struct bnxt_en_dev *edev)
100 {
101 	if (edev && rcu_access_pointer(edev->ulp_tbl->ulp_ops))
102 		return true;
103 	return false;
104 }
105 
106 int bnxt_get_ulp_msix_num(struct bnxt *bp);
107 int bnxt_get_ulp_msix_num_in_use(struct bnxt *bp);
108 void bnxt_set_ulp_msix_num(struct bnxt *bp, int num);
109 int bnxt_get_ulp_stat_ctxs(struct bnxt *bp);
110 void bnxt_set_ulp_stat_ctxs(struct bnxt *bp, int num_ctxs);
111 int bnxt_get_ulp_stat_ctxs_in_use(struct bnxt *bp);
112 void bnxt_set_dflt_ulp_stat_ctxs(struct bnxt *bp);
113 void bnxt_ulp_stop(struct bnxt *bp);
114 void bnxt_ulp_start(struct bnxt *bp, int err);
115 void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs);
116 void bnxt_ulp_irq_stop(struct bnxt *bp);
117 void bnxt_ulp_irq_restart(struct bnxt *bp, int err);
118 void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl);
119 void bnxt_rdma_aux_device_uninit(struct bnxt *bp);
120 void bnxt_rdma_aux_device_del(struct bnxt *bp);
121 void bnxt_rdma_aux_device_add(struct bnxt *bp);
122 void bnxt_rdma_aux_device_init(struct bnxt *bp);
123 int bnxt_register_dev(struct bnxt_en_dev *edev, struct bnxt_ulp_ops *ulp_ops,
124 		      void *handle);
125 void bnxt_unregister_dev(struct bnxt_en_dev *edev);
126 int bnxt_send_msg(struct bnxt_en_dev *edev, struct bnxt_fw_msg *fw_msg);
127 int bnxt_register_async_events(struct bnxt_en_dev *edev,
128 			       unsigned long *events_bmap, u16 max_id);
129 #endif
130