18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify
58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158c2ecf20Sopenharmony_ci * SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef _VNIC_DEV_H_
198c2ecf20Sopenharmony_ci#define _VNIC_DEV_H_
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "vnic_resource.h"
228c2ecf20Sopenharmony_ci#include "vnic_devcmd.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef VNIC_PADDR_TARGET
258c2ecf20Sopenharmony_ci#define VNIC_PADDR_TARGET	0x0000000000000000ULL
268c2ecf20Sopenharmony_ci#endif
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#ifndef readq
298c2ecf20Sopenharmony_cistatic inline u64 readq(void __iomem *reg)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	return ((u64)readl(reg + 0x4UL) << 32) | (u64)readl(reg);
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic inline void writeq(u64 val, void __iomem *reg)
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	writel(lower_32_bits(val), reg);
378c2ecf20Sopenharmony_ci	writel(upper_32_bits(val), reg + 0x4UL);
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci#endif
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cienum vnic_dev_intr_mode {
428c2ecf20Sopenharmony_ci	VNIC_DEV_INTR_MODE_UNKNOWN,
438c2ecf20Sopenharmony_ci	VNIC_DEV_INTR_MODE_INTX,
448c2ecf20Sopenharmony_ci	VNIC_DEV_INTR_MODE_MSI,
458c2ecf20Sopenharmony_ci	VNIC_DEV_INTR_MODE_MSIX,
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistruct vnic_dev_bar {
498c2ecf20Sopenharmony_ci	void __iomem *vaddr;
508c2ecf20Sopenharmony_ci	dma_addr_t bus_addr;
518c2ecf20Sopenharmony_ci	unsigned long len;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct vnic_dev_ring {
558c2ecf20Sopenharmony_ci	void *descs;
568c2ecf20Sopenharmony_ci	size_t size;
578c2ecf20Sopenharmony_ci	dma_addr_t base_addr;
588c2ecf20Sopenharmony_ci	size_t base_align;
598c2ecf20Sopenharmony_ci	void *descs_unaligned;
608c2ecf20Sopenharmony_ci	size_t size_unaligned;
618c2ecf20Sopenharmony_ci	dma_addr_t base_addr_unaligned;
628c2ecf20Sopenharmony_ci	unsigned int desc_size;
638c2ecf20Sopenharmony_ci	unsigned int desc_count;
648c2ecf20Sopenharmony_ci	unsigned int desc_avail;
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistruct vnic_dev;
688c2ecf20Sopenharmony_cistruct vnic_stats;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_civoid *svnic_dev_priv(struct vnic_dev *vdev);
718c2ecf20Sopenharmony_ciunsigned int svnic_dev_get_res_count(struct vnic_dev *vdev,
728c2ecf20Sopenharmony_ci				    enum vnic_res_type type);
738c2ecf20Sopenharmony_civoid __iomem *svnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
748c2ecf20Sopenharmony_ci			       unsigned int index);
758c2ecf20Sopenharmony_ciunsigned int svnic_dev_desc_ring_size(struct vnic_dev_ring *ring,
768c2ecf20Sopenharmony_ci				     unsigned int desc_count,
778c2ecf20Sopenharmony_ci				     unsigned int desc_size);
788c2ecf20Sopenharmony_civoid svnic_dev_clear_desc_ring(struct vnic_dev_ring *ring);
798c2ecf20Sopenharmony_ciint svnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring,
808c2ecf20Sopenharmony_ci			     unsigned int desc_count, unsigned int desc_size);
818c2ecf20Sopenharmony_civoid svnic_dev_free_desc_ring(struct vnic_dev *vdev,
828c2ecf20Sopenharmony_ci			     struct vnic_dev_ring *ring);
838c2ecf20Sopenharmony_ciint svnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
848c2ecf20Sopenharmony_ci		 u64 *a0, u64 *a1, int wait);
858c2ecf20Sopenharmony_ciint svnic_dev_fw_info(struct vnic_dev *vdev,
868c2ecf20Sopenharmony_ci		     struct vnic_devcmd_fw_info **fw_info);
878c2ecf20Sopenharmony_ciint svnic_dev_spec(struct vnic_dev *vdev, unsigned int offset,
888c2ecf20Sopenharmony_ci		  unsigned int size, void *value);
898c2ecf20Sopenharmony_ciint svnic_dev_stats_clear(struct vnic_dev *vdev);
908c2ecf20Sopenharmony_ciint svnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats);
918c2ecf20Sopenharmony_ciint svnic_dev_notify_set(struct vnic_dev *vdev, u16 intr);
928c2ecf20Sopenharmony_civoid svnic_dev_notify_unset(struct vnic_dev *vdev);
938c2ecf20Sopenharmony_ciint svnic_dev_link_status(struct vnic_dev *vdev);
948c2ecf20Sopenharmony_ciu32 svnic_dev_link_down_cnt(struct vnic_dev *vdev);
958c2ecf20Sopenharmony_ciint svnic_dev_close(struct vnic_dev *vdev);
968c2ecf20Sopenharmony_ciint svnic_dev_enable_wait(struct vnic_dev *vdev);
978c2ecf20Sopenharmony_ciint svnic_dev_disable(struct vnic_dev *vdev);
988c2ecf20Sopenharmony_ciint svnic_dev_open(struct vnic_dev *vdev, int arg);
998c2ecf20Sopenharmony_ciint svnic_dev_open_done(struct vnic_dev *vdev, int *done);
1008c2ecf20Sopenharmony_ciint svnic_dev_init(struct vnic_dev *vdev, int arg);
1018c2ecf20Sopenharmony_cistruct vnic_dev *svnic_dev_alloc_discover(struct vnic_dev *vdev,
1028c2ecf20Sopenharmony_ci					 void *priv, struct pci_dev *pdev,
1038c2ecf20Sopenharmony_ci					 struct vnic_dev_bar *bar,
1048c2ecf20Sopenharmony_ci					 unsigned int num_bars);
1058c2ecf20Sopenharmony_civoid svnic_dev_set_intr_mode(struct vnic_dev *vdev,
1068c2ecf20Sopenharmony_ci			    enum vnic_dev_intr_mode intr_mode);
1078c2ecf20Sopenharmony_cienum vnic_dev_intr_mode svnic_dev_get_intr_mode(struct vnic_dev *vdev);
1088c2ecf20Sopenharmony_civoid svnic_dev_unregister(struct vnic_dev *vdev);
1098c2ecf20Sopenharmony_ciint svnic_dev_cmd_init(struct vnic_dev *vdev, int fallback);
1108c2ecf20Sopenharmony_ci#endif /* _VNIC_DEV_H_ */
111