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 struct hwrm_async_event_cmpl;
20 struct bnxt;
21 
22 struct bnxt_msix_entry {
23 	u32	vector;
24 	u32	ring_idx;
25 	u32	db_offset;
26 };
27 
28 struct bnxt_ulp_ops {
29 	/* async_notifier() cannot sleep (in BH context) */
30 	void (*ulp_async_notifier)(void *, struct hwrm_async_event_cmpl *);
31 	void (*ulp_stop)(void *);
32 	void (*ulp_start)(void *);
33 	void (*ulp_sriov_config)(void *, int);
34 	void (*ulp_shutdown)(void *);
35 	void (*ulp_irq_stop)(void *);
36 	void (*ulp_irq_restart)(void *, struct bnxt_msix_entry *);
37 };
38 
39 struct bnxt_fw_msg {
40 	void	*msg;
41 	int	msg_len;
42 	void	*resp;
43 	int	resp_max_len;
44 	int	timeout;
45 };
46 
47 struct bnxt_ulp {
48 	void		*handle;
49 	struct bnxt_ulp_ops __rcu *ulp_ops;
50 	unsigned long	*async_events_bmap;
51 	u16		max_async_event_id;
52 	u16		msix_requested;
53 	u16		msix_base;
54 	atomic_t	ref_count;
55 };
56 
57 struct bnxt_en_dev {
58 	struct net_device *net;
59 	struct pci_dev *pdev;
60 	u32 flags;
61 	#define BNXT_EN_FLAG_ROCEV1_CAP		0x1
62 	#define BNXT_EN_FLAG_ROCEV2_CAP		0x2
63 	#define BNXT_EN_FLAG_ROCE_CAP		(BNXT_EN_FLAG_ROCEV1_CAP | \
64 						 BNXT_EN_FLAG_ROCEV2_CAP)
65 	#define BNXT_EN_FLAG_MSIX_REQUESTED	0x4
66 	#define BNXT_EN_FLAG_ULP_STOPPED	0x8
67 	const struct bnxt_en_ops	*en_ops;
68 	struct bnxt_ulp			ulp_tbl[BNXT_MAX_ULP];
69 	int				l2_db_size;	/* Doorbell BAR size in
70 							 * bytes mapped by L2
71 							 * driver.
72 							 */
73 	int				l2_db_size_nc;	/* Doorbell BAR size in
74 							 * bytes mapped as non-
75 							 * cacheable.
76 							 */
77 };
78 
79 struct bnxt_en_ops {
80 	int (*bnxt_register_device)(struct bnxt_en_dev *, int,
81 				    struct bnxt_ulp_ops *, void *);
82 	int (*bnxt_unregister_device)(struct bnxt_en_dev *, int);
83 	int (*bnxt_request_msix)(struct bnxt_en_dev *, int,
84 				 struct bnxt_msix_entry *, int);
85 	int (*bnxt_free_msix)(struct bnxt_en_dev *, int);
86 	int (*bnxt_send_fw_msg)(struct bnxt_en_dev *, int,
87 				struct bnxt_fw_msg *);
88 	int (*bnxt_register_fw_async_events)(struct bnxt_en_dev *, int,
89 					     unsigned long *, u16);
90 };
91 
92 static inline bool bnxt_ulp_registered(struct bnxt_en_dev *edev, int ulp_id)
93 {
94 	if (edev && rcu_access_pointer(edev->ulp_tbl[ulp_id].ulp_ops))
95 		return true;
96 	return false;
97 }
98 
99 int bnxt_get_ulp_msix_num(struct bnxt *bp);
100 int bnxt_get_ulp_msix_base(struct bnxt *bp);
101 int bnxt_get_ulp_stat_ctxs(struct bnxt *bp);
102 void bnxt_ulp_stop(struct bnxt *bp);
103 void bnxt_ulp_start(struct bnxt *bp, int err);
104 void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs);
105 void bnxt_ulp_shutdown(struct bnxt *bp);
106 void bnxt_ulp_irq_stop(struct bnxt *bp);
107 void bnxt_ulp_irq_restart(struct bnxt *bp, int err);
108 void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl);
109 struct bnxt_en_dev *bnxt_ulp_probe(struct net_device *dev);
110 
111 #endif
112