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