1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * QLogic qlcnic NIC Driver
4  * Copyright (c)  2009-2013 QLogic Corporation
5  */
6 
7 #ifndef __QLCNIC_DCBX_H
8 #define __QLCNIC_DCBX_H
9 
10 #define QLCNIC_DCB_STATE	0
11 #define QLCNIC_DCB_AEN_MODE	1
12 
13 #ifdef CONFIG_QLCNIC_DCB
14 int qlcnic_register_dcb(struct qlcnic_adapter *);
15 #else
qlcnic_register_dcb(struct qlcnic_adapter * adapter)16 static inline int qlcnic_register_dcb(struct qlcnic_adapter *adapter)
17 { return 0; }
18 #endif
19 
20 struct qlcnic_dcb;
21 
22 struct qlcnic_dcb_ops {
23 	int (*query_hw_capability) (struct qlcnic_dcb *, char *);
24 	int (*get_hw_capability) (struct qlcnic_dcb *);
25 	int (*query_cee_param) (struct qlcnic_dcb *, char *, u8);
26 	void (*init_dcbnl_ops) (struct qlcnic_dcb *);
27 	void (*aen_handler) (struct qlcnic_dcb *, void *);
28 	int (*get_cee_cfg) (struct qlcnic_dcb *);
29 	void (*get_info) (struct qlcnic_dcb *);
30 	int (*attach) (struct qlcnic_dcb *);
31 	void (*free) (struct qlcnic_dcb *);
32 };
33 
34 struct qlcnic_dcb {
35 	struct qlcnic_dcb_mbx_params	*param;
36 	struct qlcnic_adapter		*adapter;
37 	struct delayed_work		aen_work;
38 	struct workqueue_struct		*wq;
39 	const struct qlcnic_dcb_ops	*ops;
40 	struct qlcnic_dcb_cfg		*cfg;
41 	unsigned long			state;
42 };
43 
qlcnic_clear_dcb_ops(struct qlcnic_dcb * dcb)44 static inline void qlcnic_clear_dcb_ops(struct qlcnic_dcb *dcb)
45 {
46 	kfree(dcb);
47 }
48 
qlcnic_dcb_get_hw_capability(struct qlcnic_dcb * dcb)49 static inline int qlcnic_dcb_get_hw_capability(struct qlcnic_dcb *dcb)
50 {
51 	if (dcb && dcb->ops->get_hw_capability)
52 		return dcb->ops->get_hw_capability(dcb);
53 
54 	return 0;
55 }
56 
qlcnic_dcb_free(struct qlcnic_dcb * dcb)57 static inline void qlcnic_dcb_free(struct qlcnic_dcb *dcb)
58 {
59 	if (dcb && dcb->ops->free)
60 		dcb->ops->free(dcb);
61 }
62 
qlcnic_dcb_attach(struct qlcnic_dcb * dcb)63 static inline int qlcnic_dcb_attach(struct qlcnic_dcb *dcb)
64 {
65 	if (dcb && dcb->ops->attach)
66 		return dcb->ops->attach(dcb);
67 
68 	return 0;
69 }
70 
71 static inline int
qlcnic_dcb_query_hw_capability(struct qlcnic_dcb * dcb,char * buf)72 qlcnic_dcb_query_hw_capability(struct qlcnic_dcb *dcb, char *buf)
73 {
74 	if (dcb && dcb->ops->query_hw_capability)
75 		return dcb->ops->query_hw_capability(dcb, buf);
76 
77 	return 0;
78 }
79 
qlcnic_dcb_get_info(struct qlcnic_dcb * dcb)80 static inline void qlcnic_dcb_get_info(struct qlcnic_dcb *dcb)
81 {
82 	if (dcb && dcb->ops->get_info)
83 		dcb->ops->get_info(dcb);
84 }
85 
86 static inline int
qlcnic_dcb_query_cee_param(struct qlcnic_dcb * dcb,char * buf,u8 type)87 qlcnic_dcb_query_cee_param(struct qlcnic_dcb *dcb, char *buf, u8 type)
88 {
89 	if (dcb && dcb->ops->query_cee_param)
90 		return dcb->ops->query_cee_param(dcb, buf, type);
91 
92 	return 0;
93 }
94 
qlcnic_dcb_get_cee_cfg(struct qlcnic_dcb * dcb)95 static inline int qlcnic_dcb_get_cee_cfg(struct qlcnic_dcb *dcb)
96 {
97 	if (dcb && dcb->ops->get_cee_cfg)
98 		return dcb->ops->get_cee_cfg(dcb);
99 
100 	return 0;
101 }
102 
qlcnic_dcb_aen_handler(struct qlcnic_dcb * dcb,void * msg)103 static inline void qlcnic_dcb_aen_handler(struct qlcnic_dcb *dcb, void *msg)
104 {
105 	if (dcb && dcb->ops->aen_handler)
106 		dcb->ops->aen_handler(dcb, msg);
107 }
108 
qlcnic_dcb_init_dcbnl_ops(struct qlcnic_dcb * dcb)109 static inline void qlcnic_dcb_init_dcbnl_ops(struct qlcnic_dcb *dcb)
110 {
111 	if (dcb && dcb->ops->init_dcbnl_ops)
112 		dcb->ops->init_dcbnl_ops(dcb);
113 }
114 
qlcnic_dcb_enable(struct qlcnic_dcb * dcb)115 static inline void qlcnic_dcb_enable(struct qlcnic_dcb *dcb)
116 {
117 	if (dcb && qlcnic_dcb_attach(dcb))
118 		qlcnic_clear_dcb_ops(dcb);
119 }
120 #endif
121