2 * Copyright (C) 2016 Cavium, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License
6 * as published by the Free Software Foundation.
11 static void cptvf_send_msg_to_pf(struct cpt_vf
*cptvf
, struct cpt_mbox
*mbx
)
13 /* Writing mbox(1) causes interrupt */
14 cpt_write_csr64(cptvf
->reg_base
, CPTX_VFX_PF_MBOXX(0, 0, 0),
16 cpt_write_csr64(cptvf
->reg_base
, CPTX_VFX_PF_MBOXX(0, 0, 1),
20 /* ACKs PF's mailbox message
22 void cptvf_mbox_send_ack(struct cpt_vf
*cptvf
, struct cpt_mbox
*mbx
)
24 mbx
->msg
= CPT_MBOX_MSG_TYPE_ACK
;
25 cptvf_send_msg_to_pf(cptvf
, mbx
);
28 /* NACKs PF's mailbox message that VF is not able to
31 void cptvf_mbox_send_nack(struct cpt_vf
*cptvf
, struct cpt_mbox
*mbx
)
33 mbx
->msg
= CPT_MBOX_MSG_TYPE_NACK
;
34 cptvf_send_msg_to_pf(cptvf
, mbx
);
37 /* Interrupt handler to handle mailbox messages from VFs */
38 void cptvf_handle_mbox_intr(struct cpt_vf
*cptvf
)
40 struct cpt_mbox mbx
= {};
43 * MBOX[0] contains msg
44 * MBOX[1] contains data
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",
53 cptvf
->pf_acked
= true;
54 cptvf
->vfid
= mbx
.data
;
55 dev_dbg(&cptvf
->pdev
->dev
, "Received VFID %d\n", cptvf
->vfid
);
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"),
65 case CPT_MBOX_MSG_TYPE_ACK
:
66 cptvf
->pf_acked
= true;
68 case CPT_MBOX_MSG_TYPE_NACK
:
69 cptvf
->pf_nacked
= true;
72 dev_err(&cptvf
->pdev
->dev
, "Invalid msg from PF, msg 0x%llx\n",
78 static int cptvf_send_msg_to_pf_timeout(struct cpt_vf
*cptvf
,
81 int timeout
= CPT_MBOX_MSG_TIMEOUT
;
84 cptvf
->pf_acked
= false;
85 cptvf
->pf_nacked
= false;
86 cptvf_send_msg_to_pf(cptvf
, mbx
);
87 /* Wait for previous message to be acked, timeout 2sec */
88 while (!cptvf
->pf_acked
) {
96 dev_err(&cptvf
->pdev
->dev
, "PF didn't ack to mbox msg %llx from VF%u\n",
97 (mbx
->msg
& 0xFF), cptvf
->vfid
);
106 * Checks if VF is able to comminicate with PF
107 * and also gets the CPT number this VF is associated to.
109 int cptvf_check_pf_ready(struct cpt_vf
*cptvf
)
111 struct pci_dev
*pdev
= cptvf
->pdev
;
112 struct cpt_mbox mbx
= {};
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");
124 * Communicate VQs size to PF to program CPT(0)_PF_Q(0-15)_CTL of the VF.
127 int cptvf_send_vq_size_msg(struct cpt_vf
*cptvf
)
129 struct pci_dev
*pdev
= cptvf
->pdev
;
130 struct cpt_mbox mbx
= {};
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");
143 * Communicate VF group required to PF and get the VQ binded to that group
145 int cptvf_send_vf_to_grp_msg(struct cpt_vf
*cptvf
)
147 struct pci_dev
*pdev
= cptvf
->pdev
;
148 struct cpt_mbox mbx
= {};
150 mbx
.msg
= CPT_MSG_QBIND_GRP
;
151 /* Convey group of the VF */
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");
162 * Communicate VF group required to PF and get the VQ binded to that group
164 int cptvf_send_vf_priority_msg(struct cpt_vf
*cptvf
)
166 struct pci_dev
*pdev
= cptvf
->pdev
;
167 struct cpt_mbox mbx
= {};
169 mbx
.msg
= CPT_MSG_VQ_PRIORITY
;
170 /* Convey group of the VF */
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");
180 * Communicate to PF that VF is UP and running
182 int cptvf_send_vf_up(struct cpt_vf
*cptvf
)
184 struct pci_dev
*pdev
= cptvf
->pdev
;
185 struct cpt_mbox mbx
= {};
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");
197 * Communicate to PF that VF is DOWN and running
199 int cptvf_send_vf_down(struct cpt_vf
*cptvf
)
201 struct pci_dev
*pdev
= cptvf
->pdev
;
202 struct cpt_mbox mbx
= {};
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");