1 /*
2  * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  *
32  */
33 
34 #ifndef USNIC_VNIC_H_
35 #define USNIC_VNIC_H_
36 
37 #include <linux/pci.h>
38 
39 #include "vnic_dev.h"
40 
41 /*                      =USNIC_VNIC_RES_TYPE= =VNIC_RES=   =DESC= */
42 #define USNIC_VNIC_RES_TYPES \
43 	DEFINE_USNIC_VNIC_RES_AT(EOL, RES_TYPE_EOL, "EOL", 0) \
44 	DEFINE_USNIC_VNIC_RES(WQ, RES_TYPE_WQ, "WQ") \
45 	DEFINE_USNIC_VNIC_RES(RQ, RES_TYPE_RQ, "RQ") \
46 	DEFINE_USNIC_VNIC_RES(CQ, RES_TYPE_CQ, "CQ") \
47 	DEFINE_USNIC_VNIC_RES(INTR, RES_TYPE_INTR_CTRL, "INT") \
48 	DEFINE_USNIC_VNIC_RES(MAX, RES_TYPE_MAX, "MAX")\
49 
50 #define DEFINE_USNIC_VNIC_RES_AT(usnic_vnic_res_t, vnic_res_type, desc, val) \
51 	USNIC_VNIC_RES_TYPE_##usnic_vnic_res_t = val,
52 #define DEFINE_USNIC_VNIC_RES(usnic_vnic_res_t, vnic_res_type, desc) \
53 	USNIC_VNIC_RES_TYPE_##usnic_vnic_res_t,
54 enum usnic_vnic_res_type {
55 	USNIC_VNIC_RES_TYPES
56 };
57 #undef DEFINE_USNIC_VNIC_RES
58 #undef DEFINE_USNIC_VNIC_RES_AT
59 
60 struct usnic_vnic_res {
61 	enum usnic_vnic_res_type	type;
62 	unsigned int			vnic_idx;
63 	struct usnic_vnic		*vnic;
64 	void __iomem			*ctrl;
65 	void				*owner;
66 };
67 
68 struct usnic_vnic_res_chunk {
69 	enum usnic_vnic_res_type	type;
70 	int				cnt;
71 	int				free_cnt;
72 	struct usnic_vnic_res		**res;
73 	struct usnic_vnic		*vnic;
74 };
75 
76 struct usnic_vnic_res_desc {
77 	enum usnic_vnic_res_type	type;
78 	uint16_t			cnt;
79 };
80 
81 struct usnic_vnic_res_spec {
82 	struct usnic_vnic_res_desc resources[USNIC_VNIC_RES_TYPE_MAX];
83 };
84 
85 const char *usnic_vnic_res_type_to_str(enum usnic_vnic_res_type res_type);
86 const char *usnic_vnic_pci_name(struct usnic_vnic *vnic);
87 int usnic_vnic_dump(struct usnic_vnic *vnic, char *buf, int buf_sz,
88 			void *hdr_obj,
89 			int (*printtitle)(void *, char*, int),
90 			int (*printcols)(char *, int),
91 			int (*printrow)(void *, char *, int));
92 void usnic_vnic_res_spec_update(struct usnic_vnic_res_spec *spec,
93 				enum usnic_vnic_res_type trgt_type,
94 				u16 cnt);
95 int usnic_vnic_res_spec_satisfied(const struct usnic_vnic_res_spec *min_spec,
96 					struct usnic_vnic_res_spec *res_spec);
97 int usnic_vnic_spec_dump(char *buf, int buf_sz,
98 				struct usnic_vnic_res_spec *res_spec);
99 int usnic_vnic_check_room(struct usnic_vnic *vnic,
100 				struct usnic_vnic_res_spec *res_spec);
101 int usnic_vnic_res_cnt(struct usnic_vnic *vnic,
102 				enum usnic_vnic_res_type type);
103 int usnic_vnic_res_free_cnt(struct usnic_vnic *vnic,
104 				enum usnic_vnic_res_type type);
105 struct usnic_vnic_res_chunk *
106 usnic_vnic_get_resources(struct usnic_vnic *vnic,
107 				enum usnic_vnic_res_type type,
108 				int cnt,
109 				void *owner);
110 void usnic_vnic_put_resources(struct usnic_vnic_res_chunk *chunk);
111 struct pci_dev *usnic_vnic_get_pdev(struct usnic_vnic *vnic);
112 struct vnic_dev_bar *usnic_vnic_get_bar(struct usnic_vnic *vnic,
113 				int bar_num);
114 struct usnic_vnic *usnic_vnic_alloc(struct pci_dev *pdev);
115 void usnic_vnic_free(struct usnic_vnic *vnic);
116 u16 usnic_vnic_get_index(struct usnic_vnic *vnic);
117 
118 #endif /*!USNIC_VNIC_H_*/
119