1
2
3
4
5
6
7
8
9#include "cptvf.h"
10
11static void cptvf_send_msg_to_pf(struct cpt_vf *cptvf, struct cpt_mbox *mbx)
12{
13
14 cpt_write_csr64(cptvf->reg_base, CPTX_VFX_PF_MBOXX(0, 0, 0),
15 mbx->msg);
16 cpt_write_csr64(cptvf->reg_base, CPTX_VFX_PF_MBOXX(0, 0, 1),
17 mbx->data);
18}
19
20
21
22void cptvf_mbox_send_ack(struct cpt_vf *cptvf, struct cpt_mbox *mbx)
23{
24 mbx->msg = CPT_MBOX_MSG_TYPE_ACK;
25 cptvf_send_msg_to_pf(cptvf, mbx);
26}
27
28
29
30
31void cptvf_mbox_send_nack(struct cpt_vf *cptvf, struct cpt_mbox *mbx)
32{
33 mbx->msg = CPT_MBOX_MSG_TYPE_NACK;
34 cptvf_send_msg_to_pf(cptvf, mbx);
35}
36
37
38void cptvf_handle_mbox_intr(struct cpt_vf *cptvf)
39{
40 struct cpt_mbox mbx = {};
41
42
43
44
45
46 mbx.msg = cpt_read_csr64(cptvf->reg_base, CPTX_VFX_PF_MBOXX(0, 0, 0));
47 mbx.data = cpt_read_csr64(cptvf->reg_base, CPTX_VFX_PF_MBOXX(0, 0, 1));
48 dev_dbg(&cptvf->pdev->dev, "%s: Mailbox msg 0x%llx from PF\n",
49 __func__, mbx.msg);
50 switch (mbx.msg) {
51 case CPT_MSG_READY:
52 {
53 cptvf->pf_acked = true;
54 cptvf->vfid = mbx.data;
55 dev_dbg(&cptvf->pdev->dev, "Received VFID %d\n", cptvf->vfid);
56 break;
57 }
58 case CPT_MSG_QBIND_GRP:
59 cptvf->pf_acked = true;
60 cptvf->vftype = mbx.data;
61 dev_dbg(&cptvf->pdev->dev, "VF %d type %s group %d\n",
62 cptvf->vfid, ((mbx.data == SE_TYPES) ? "SE" : "AE"),
63 cptvf->vfgrp);
64 break;
65 case CPT_MBOX_MSG_TYPE_ACK:
66 cptvf->pf_acked = true;
67 break;
68 case CPT_MBOX_MSG_TYPE_NACK:
69 cptvf->pf_nacked = true;
70 break;
71 default:
72 dev_err(&cptvf->pdev->dev, "Invalid msg from PF, msg 0x%llx\n",
73 mbx.msg);
74 break;
75 }
76}
77
78static int cptvf_send_msg_to_pf_timeout(struct cpt_vf *cptvf,
79 struct cpt_mbox *mbx)
80{
81 int timeout = CPT_MBOX_MSG_TIMEOUT;
82 int sleep = 10;
83
84 cptvf->pf_acked = false;
85 cptvf->pf_nacked = false;
86 cptvf_send_msg_to_pf(cptvf, mbx);
87
88 while (!cptvf->pf_acked) {
89 if (cptvf->pf_nacked)
90 return -EINVAL;
91 msleep(sleep);
92 if (cptvf->pf_acked)
93 break;
94 timeout -= sleep;
95 if (!timeout) {
96 dev_err(&cptvf->pdev->dev, "PF didn't ack to mbox msg %llx from VF%u\n",
97 (mbx->msg & 0xFF), cptvf->vfid);
98 return -EBUSY;
99 }
100 }
101
102 return 0;
103}
104
105
106
107
108
109int cptvf_check_pf_ready(struct cpt_vf *cptvf)
110{
111 struct pci_dev *pdev = cptvf->pdev;
112 struct cpt_mbox mbx = {};
113
114 mbx.msg = CPT_MSG_READY;
115 if (cptvf_send_msg_to_pf_timeout(cptvf, &mbx)) {
116 dev_err(&pdev->dev, "PF didn't respond to READY msg\n");
117 return -EBUSY;
118 }
119
120 return 0;
121}
122
123
124
125
126
127int cptvf_send_vq_size_msg(struct cpt_vf *cptvf)
128{
129 struct pci_dev *pdev = cptvf->pdev;
130 struct cpt_mbox mbx = {};
131
132 mbx.msg = CPT_MSG_QLEN;
133 mbx.data = cptvf->qsize;
134 if (cptvf_send_msg_to_pf_timeout(cptvf, &mbx)) {
135 dev_err(&pdev->dev, "PF didn't respond to vq_size msg\n");
136 return -EBUSY;
137 }
138
139 return 0;
140}
141
142
143
144
145int cptvf_send_vf_to_grp_msg(struct cpt_vf *cptvf)
146{
147 struct pci_dev *pdev = cptvf->pdev;
148 struct cpt_mbox mbx = {};
149
150 mbx.msg = CPT_MSG_QBIND_GRP;
151
152 mbx.data = cptvf->vfgrp;
153 if (cptvf_send_msg_to_pf_timeout(cptvf, &mbx)) {
154 dev_err(&pdev->dev, "PF didn't respond to vf_type msg\n");
155 return -EBUSY;
156 }
157
158 return 0;
159}
160
161
162
163
164int cptvf_send_vf_priority_msg(struct cpt_vf *cptvf)
165{
166 struct pci_dev *pdev = cptvf->pdev;
167 struct cpt_mbox mbx = {};
168
169 mbx.msg = CPT_MSG_VQ_PRIORITY;
170
171 mbx.data = cptvf->priority;
172 if (cptvf_send_msg_to_pf_timeout(cptvf, &mbx)) {
173 dev_err(&pdev->dev, "PF didn't respond to vf_type msg\n");
174 return -EBUSY;
175 }
176 return 0;
177}
178
179
180
181
182int cptvf_send_vf_up(struct cpt_vf *cptvf)
183{
184 struct pci_dev *pdev = cptvf->pdev;
185 struct cpt_mbox mbx = {};
186
187 mbx.msg = CPT_MSG_VF_UP;
188 if (cptvf_send_msg_to_pf_timeout(cptvf, &mbx)) {
189 dev_err(&pdev->dev, "PF didn't respond to UP msg\n");
190 return -EBUSY;
191 }
192
193 return 0;
194}
195
196
197
198
199int cptvf_send_vf_down(struct cpt_vf *cptvf)
200{
201 struct pci_dev *pdev = cptvf->pdev;
202 struct cpt_mbox mbx = {};
203
204 mbx.msg = CPT_MSG_VF_DOWN;
205 if (cptvf_send_msg_to_pf_timeout(cptvf, &mbx)) {
206 dev_err(&pdev->dev, "PF didn't respond to DOWN msg\n");
207 return -EBUSY;
208 }
209
210 return 0;
211}
212