162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * This software is available to you under a choice of one of two
562306a36Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
662306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
762306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the
862306a36Sopenharmony_ci * BSD license below:
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
1162306a36Sopenharmony_ci *     without modification, are permitted provided that the following
1262306a36Sopenharmony_ci *     conditions are met:
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci *      - Redistributions of source code must retain the above
1562306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
1662306a36Sopenharmony_ci *        disclaimer.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
1962306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
2062306a36Sopenharmony_ci *        disclaimer in the documentation and/or other materials
2162306a36Sopenharmony_ci *        provided with the distribution.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2462306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2562306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2662306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2762306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2862306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2962306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3062306a36Sopenharmony_ci * SOFTWARE.
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#ifndef USNIC_VNIC_H_
3562306a36Sopenharmony_ci#define USNIC_VNIC_H_
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#include <linux/pci.h>
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#include "vnic_dev.h"
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/*                      =USNIC_VNIC_RES_TYPE= =VNIC_RES=   =DESC= */
4262306a36Sopenharmony_ci#define USNIC_VNIC_RES_TYPES \
4362306a36Sopenharmony_ci	DEFINE_USNIC_VNIC_RES_AT(EOL, RES_TYPE_EOL, "EOL", 0) \
4462306a36Sopenharmony_ci	DEFINE_USNIC_VNIC_RES(WQ, RES_TYPE_WQ, "WQ") \
4562306a36Sopenharmony_ci	DEFINE_USNIC_VNIC_RES(RQ, RES_TYPE_RQ, "RQ") \
4662306a36Sopenharmony_ci	DEFINE_USNIC_VNIC_RES(CQ, RES_TYPE_CQ, "CQ") \
4762306a36Sopenharmony_ci	DEFINE_USNIC_VNIC_RES(INTR, RES_TYPE_INTR_CTRL, "INT") \
4862306a36Sopenharmony_ci	DEFINE_USNIC_VNIC_RES(MAX, RES_TYPE_MAX, "MAX")\
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#define DEFINE_USNIC_VNIC_RES_AT(usnic_vnic_res_t, vnic_res_type, desc, val) \
5162306a36Sopenharmony_ci	USNIC_VNIC_RES_TYPE_##usnic_vnic_res_t = val,
5262306a36Sopenharmony_ci#define DEFINE_USNIC_VNIC_RES(usnic_vnic_res_t, vnic_res_type, desc) \
5362306a36Sopenharmony_ci	USNIC_VNIC_RES_TYPE_##usnic_vnic_res_t,
5462306a36Sopenharmony_cienum usnic_vnic_res_type {
5562306a36Sopenharmony_ci	USNIC_VNIC_RES_TYPES
5662306a36Sopenharmony_ci};
5762306a36Sopenharmony_ci#undef DEFINE_USNIC_VNIC_RES
5862306a36Sopenharmony_ci#undef DEFINE_USNIC_VNIC_RES_AT
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistruct usnic_vnic_res {
6162306a36Sopenharmony_ci	enum usnic_vnic_res_type	type;
6262306a36Sopenharmony_ci	unsigned int			vnic_idx;
6362306a36Sopenharmony_ci	struct usnic_vnic		*vnic;
6462306a36Sopenharmony_ci	void __iomem			*ctrl;
6562306a36Sopenharmony_ci	void				*owner;
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_cistruct usnic_vnic_res_chunk {
6962306a36Sopenharmony_ci	enum usnic_vnic_res_type	type;
7062306a36Sopenharmony_ci	int				cnt;
7162306a36Sopenharmony_ci	int				free_cnt;
7262306a36Sopenharmony_ci	struct usnic_vnic_res		**res;
7362306a36Sopenharmony_ci	struct usnic_vnic		*vnic;
7462306a36Sopenharmony_ci};
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_cistruct usnic_vnic_res_desc {
7762306a36Sopenharmony_ci	enum usnic_vnic_res_type	type;
7862306a36Sopenharmony_ci	uint16_t			cnt;
7962306a36Sopenharmony_ci};
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_cistruct usnic_vnic_res_spec {
8262306a36Sopenharmony_ci	struct usnic_vnic_res_desc resources[USNIC_VNIC_RES_TYPE_MAX];
8362306a36Sopenharmony_ci};
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ciconst char *usnic_vnic_res_type_to_str(enum usnic_vnic_res_type res_type);
8662306a36Sopenharmony_ciconst char *usnic_vnic_pci_name(struct usnic_vnic *vnic);
8762306a36Sopenharmony_ciint usnic_vnic_dump(struct usnic_vnic *vnic, char *buf, int buf_sz,
8862306a36Sopenharmony_ci			void *hdr_obj,
8962306a36Sopenharmony_ci			int (*printtitle)(void *, char*, int),
9062306a36Sopenharmony_ci			int (*printcols)(char *, int),
9162306a36Sopenharmony_ci			int (*printrow)(void *, char *, int));
9262306a36Sopenharmony_civoid usnic_vnic_res_spec_update(struct usnic_vnic_res_spec *spec,
9362306a36Sopenharmony_ci				enum usnic_vnic_res_type trgt_type,
9462306a36Sopenharmony_ci				u16 cnt);
9562306a36Sopenharmony_ciint usnic_vnic_res_spec_satisfied(const struct usnic_vnic_res_spec *min_spec,
9662306a36Sopenharmony_ci					struct usnic_vnic_res_spec *res_spec);
9762306a36Sopenharmony_ciint usnic_vnic_spec_dump(char *buf, int buf_sz,
9862306a36Sopenharmony_ci				struct usnic_vnic_res_spec *res_spec);
9962306a36Sopenharmony_ciint usnic_vnic_check_room(struct usnic_vnic *vnic,
10062306a36Sopenharmony_ci				struct usnic_vnic_res_spec *res_spec);
10162306a36Sopenharmony_ciint usnic_vnic_res_cnt(struct usnic_vnic *vnic,
10262306a36Sopenharmony_ci				enum usnic_vnic_res_type type);
10362306a36Sopenharmony_ciint usnic_vnic_res_free_cnt(struct usnic_vnic *vnic,
10462306a36Sopenharmony_ci				enum usnic_vnic_res_type type);
10562306a36Sopenharmony_cistruct usnic_vnic_res_chunk *
10662306a36Sopenharmony_ciusnic_vnic_get_resources(struct usnic_vnic *vnic,
10762306a36Sopenharmony_ci				enum usnic_vnic_res_type type,
10862306a36Sopenharmony_ci				int cnt,
10962306a36Sopenharmony_ci				void *owner);
11062306a36Sopenharmony_civoid usnic_vnic_put_resources(struct usnic_vnic_res_chunk *chunk);
11162306a36Sopenharmony_cistruct pci_dev *usnic_vnic_get_pdev(struct usnic_vnic *vnic);
11262306a36Sopenharmony_cistruct vnic_dev_bar *usnic_vnic_get_bar(struct usnic_vnic *vnic,
11362306a36Sopenharmony_ci				int bar_num);
11462306a36Sopenharmony_cistruct usnic_vnic *usnic_vnic_alloc(struct pci_dev *pdev);
11562306a36Sopenharmony_civoid usnic_vnic_free(struct usnic_vnic *vnic);
11662306a36Sopenharmony_ciu16 usnic_vnic_get_index(struct usnic_vnic *vnic);
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci#endif /*!USNIC_VNIC_H_*/
119