xref: /openbmc/linux/drivers/scsi/snic/vnic_dev.h (revision fbb6b31a)
1 /*
2  * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
3  *
4  * This program is free software; you may redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15  * SOFTWARE.
16  */
17 
18 #ifndef _VNIC_DEV_H_
19 #define _VNIC_DEV_H_
20 
21 #include "vnic_resource.h"
22 #include "vnic_devcmd.h"
23 
24 #ifndef VNIC_PADDR_TARGET
25 #define VNIC_PADDR_TARGET	0x0000000000000000ULL
26 #endif
27 
28 #ifndef readq
29 static inline u64 readq(void __iomem *reg)
30 {
31 	return ((u64)readl(reg + 0x4UL) << 32) | (u64)readl(reg);
32 }
33 
34 static inline void writeq(u64 val, void __iomem *reg)
35 {
36 	writel(lower_32_bits(val), reg);
37 	writel(upper_32_bits(val), reg + 0x4UL);
38 }
39 #endif
40 
41 enum vnic_dev_intr_mode {
42 	VNIC_DEV_INTR_MODE_UNKNOWN,
43 	VNIC_DEV_INTR_MODE_INTX,
44 	VNIC_DEV_INTR_MODE_MSI,
45 	VNIC_DEV_INTR_MODE_MSIX,
46 };
47 
48 struct vnic_dev_bar {
49 	void __iomem *vaddr;
50 	dma_addr_t bus_addr;
51 	unsigned long len;
52 };
53 
54 struct vnic_dev_ring {
55 	void *descs;
56 	size_t size;
57 	dma_addr_t base_addr;
58 	size_t base_align;
59 	void *descs_unaligned;
60 	size_t size_unaligned;
61 	dma_addr_t base_addr_unaligned;
62 	unsigned int desc_size;
63 	unsigned int desc_count;
64 	unsigned int desc_avail;
65 };
66 
67 struct vnic_dev;
68 struct vnic_stats;
69 
70 void *svnic_dev_priv(struct vnic_dev *vdev);
71 unsigned int svnic_dev_get_res_count(struct vnic_dev *vdev,
72 				    enum vnic_res_type type);
73 void __iomem *svnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
74 			       unsigned int index);
75 unsigned int svnic_dev_desc_ring_size(struct vnic_dev_ring *ring,
76 				     unsigned int desc_count,
77 				     unsigned int desc_size);
78 void svnic_dev_clear_desc_ring(struct vnic_dev_ring *ring);
79 int svnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring,
80 			     unsigned int desc_count, unsigned int desc_size);
81 void svnic_dev_free_desc_ring(struct vnic_dev *vdev,
82 			     struct vnic_dev_ring *ring);
83 int svnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
84 		 u64 *a0, u64 *a1, int wait);
85 int svnic_dev_fw_info(struct vnic_dev *vdev,
86 		     struct vnic_devcmd_fw_info **fw_info);
87 int svnic_dev_spec(struct vnic_dev *vdev, unsigned int offset,
88 		  unsigned int size, void *value);
89 int svnic_dev_stats_clear(struct vnic_dev *vdev);
90 int svnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats);
91 int svnic_dev_notify_set(struct vnic_dev *vdev, u16 intr);
92 void svnic_dev_notify_unset(struct vnic_dev *vdev);
93 int svnic_dev_link_status(struct vnic_dev *vdev);
94 u32 svnic_dev_link_down_cnt(struct vnic_dev *vdev);
95 int svnic_dev_close(struct vnic_dev *vdev);
96 int svnic_dev_enable_wait(struct vnic_dev *vdev);
97 int svnic_dev_disable(struct vnic_dev *vdev);
98 int svnic_dev_open(struct vnic_dev *vdev, int arg);
99 int svnic_dev_open_done(struct vnic_dev *vdev, int *done);
100 int svnic_dev_init(struct vnic_dev *vdev, int arg);
101 struct vnic_dev *svnic_dev_alloc_discover(struct vnic_dev *vdev,
102 					 void *priv, struct pci_dev *pdev,
103 					 struct vnic_dev_bar *bar,
104 					 unsigned int num_bars);
105 void svnic_dev_set_intr_mode(struct vnic_dev *vdev,
106 			    enum vnic_dev_intr_mode intr_mode);
107 enum vnic_dev_intr_mode svnic_dev_get_intr_mode(struct vnic_dev *vdev);
108 void svnic_dev_unregister(struct vnic_dev *vdev);
109 int svnic_dev_cmd_init(struct vnic_dev *vdev, int fallback);
110 #endif /* _VNIC_DEV_H_ */
111