1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
10 #include "qed_sriov.h"
13 static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
15 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
18 /* This lock is released when we receive PF's response
19 * in qed_send_msg2pf().
20 * So, qed_vf_pf_prep() and qed_send_msg2pf()
21 * must come in sequence.
23 mutex_lock(&(p_iov->mutex));
27 "preparing to send 0x%04x tlv over vf pf channel\n",
30 /* Reset Requst offset */
31 p_iov->offset = (u8 *)p_iov->vf2pf_request;
33 /* Clear mailbox - both request and reply */
34 memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
35 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
37 /* Init type and length */
38 p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
40 /* Init first tlv header */
41 ((struct vfpf_first_tlv *)p_tlv)->reply_address =
42 (u64)p_iov->pf2vf_reply_phys;
47 static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
49 union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
50 struct ustorm_trigger_vf_zone trigger;
51 struct ustorm_vf_zone *zone_data;
52 int rc = 0, time = 100;
54 zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
56 /* output tlvs list */
57 qed_dp_tlv_list(p_hwfn, p_req);
59 /* need to add the END TLV to the message size */
60 resp_size += sizeof(struct channel_list_end_tlv);
62 /* Send TLVs over HW channel */
63 memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
64 trigger.vf_pf_msg_valid = 1;
68 "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
69 GET_FIELD(p_hwfn->hw_info.concrete_fid,
70 PXP_CONCRETE_FID_PFID),
71 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
72 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
73 &zone_data->non_trigger.vf_pf_msg_addr,
74 *((u32 *)&trigger), &zone_data->trigger);
77 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
78 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
81 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
82 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
84 /* The message data must be written first, to prevent trigger before
89 REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
91 /* When PF would be done with the response, it would write back to the
92 * `done' address. Poll until then.
94 while ((!*done) && time) {
100 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
101 "VF <-- PF Timeout [Type %d]\n",
102 p_req->first_tlv.tl.type);
106 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
107 "PF response: %d [Type %d]\n",
108 *done, p_req->first_tlv.tl.type);
112 mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
117 #define VF_ACQUIRE_THRESH 3
118 #define VF_ACQUIRE_MAC_FILTERS 1
120 static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
122 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
123 struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
124 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
125 u8 rx_count = 1, tx_count = 1, num_sbs = 1;
126 u8 num_mac = VF_ACQUIRE_MAC_FILTERS;
127 bool resources_acquired = false;
128 struct vfpf_acquire_tlv *req;
129 int rc = 0, attempts = 0;
131 /* clear mailbox and prep first tlv */
132 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
134 /* starting filling the request */
135 req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
137 req->resc_request.num_rxqs = rx_count;
138 req->resc_request.num_txqs = tx_count;
139 req->resc_request.num_sbs = num_sbs;
140 req->resc_request.num_mac_filters = num_mac;
141 req->resc_request.num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
143 req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
144 req->vfdev_info.fw_major = FW_MAJOR_VERSION;
145 req->vfdev_info.fw_minor = FW_MINOR_VERSION;
146 req->vfdev_info.fw_revision = FW_REVISION_VERSION;
147 req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
149 /* Fill capability field with any non-deprecated config we support */
150 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
152 /* pf 2 vf bulletin board address */
153 req->bulletin_addr = p_iov->bulletin.phys;
154 req->bulletin_size = p_iov->bulletin.size;
156 /* add list termination tlv */
157 qed_add_tlv(p_hwfn, &p_iov->offset,
158 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
160 while (!resources_acquired) {
162 QED_MSG_IOV, "attempting to acquire resources\n");
164 /* send acquire request */
165 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
169 /* copy acquire response from buffer to p_hwfn */
170 memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
174 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
175 /* PF agrees to allocate our resources */
176 if (!(resp->pfdev_info.capabilities &
177 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
179 "PF is using old incompatible driver; Either downgrade driver or request provider to update hypervisor version\n");
182 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
183 resources_acquired = true;
184 } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
185 attempts < VF_ACQUIRE_THRESH) {
188 "PF unwilling to fullfill resource request. Try PF recommended amount\n");
190 /* humble our request */
191 req->resc_request.num_txqs = resp->resc.num_txqs;
192 req->resc_request.num_rxqs = resp->resc.num_rxqs;
193 req->resc_request.num_sbs = resp->resc.num_sbs;
194 req->resc_request.num_mac_filters =
195 resp->resc.num_mac_filters;
196 req->resc_request.num_vlan_filters =
197 resp->resc.num_vlan_filters;
199 /* Clear response buffer */
200 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
203 "PF returned error %d to VF acquisition request\n",
209 /* Update bulletin board size with response from PF */
210 p_iov->bulletin.size = resp->bulletin_size;
213 p_hwfn->cdev->type = resp->pfdev_info.dev_type;
214 p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
216 p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
218 /* Learn of the possibility of CMT */
219 if (IS_LEAD_HWFN(p_hwfn)) {
220 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
221 DP_NOTICE(p_hwfn, "100g VF\n");
222 p_hwfn->cdev->num_hwfns = 2;
229 int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
231 struct qed_vf_iov *p_iov;
234 /* Set number of hwfns - might be overriden once leading hwfn learns
235 * actual configuration from PF.
237 if (IS_LEAD_HWFN(p_hwfn))
238 p_hwfn->cdev->num_hwfns = 1;
240 /* Set the doorbell bar. Assumption: regview is set */
241 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
242 PXP_VF_BAR0_START_DQ;
244 reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
245 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
247 reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
248 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
250 /* Allocate vf sriov info */
251 p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
253 DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sriov'\n");
257 /* Allocate vf2pf msg */
258 p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
259 sizeof(union vfpf_tlvs),
260 &p_iov->vf2pf_request_phys,
262 if (!p_iov->vf2pf_request) {
264 "Failed to allocate `vf2pf_request' DMA memory\n");
268 p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
269 sizeof(union pfvf_tlvs),
270 &p_iov->pf2vf_reply_phys,
272 if (!p_iov->pf2vf_reply) {
274 "Failed to allocate `pf2vf_reply' DMA memory\n");
275 goto free_vf2pf_request;
280 "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
281 p_iov->vf2pf_request,
282 (u64) p_iov->vf2pf_request_phys,
283 p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
285 /* Allocate Bulletin board */
286 p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
287 p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
288 p_iov->bulletin.size,
289 &p_iov->bulletin.phys,
291 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
292 "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
293 p_iov->bulletin.p_virt,
294 (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
296 mutex_init(&p_iov->mutex);
298 p_hwfn->vf_iov_info = p_iov;
300 p_hwfn->hw_info.personality = QED_PCI_ETH;
302 return qed_vf_pf_acquire(p_hwfn);
305 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
306 sizeof(union vfpf_tlvs),
307 p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
314 u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
316 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
319 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
323 return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
326 void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
328 *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
331 void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
334 p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
337 void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
339 struct qed_vf_iov *p_vf;
341 p_vf = p_hwfn->vf_iov_info;
342 *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
345 void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
346 u16 *fw_major, u16 *fw_minor,
347 u16 *fw_rev, u16 *fw_eng)
349 struct pf_vf_pfdev_info *info;
351 info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
353 *fw_major = info->fw_major;
354 *fw_minor = info->fw_minor;
355 *fw_rev = info->fw_rev;
356 *fw_eng = info->fw_eng;