1 /* QLogic qed NIC Driver 2 * Copyright (c) 2015-2017 QLogic Corporation 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * - Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * 18 * - Redistributions in binary form must reproduce the above 19 * copyright notice, this list of conditions and the following 20 * disclaimer in the documentation and /or other materials 21 * provided with the distribution. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * SOFTWARE. 31 */ 32 33 #include <linux/crc32.h> 34 #include <linux/etherdevice.h> 35 #include "qed.h" 36 #include "qed_sriov.h" 37 #include "qed_vf.h" 38 39 static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length) 40 { 41 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 42 void *p_tlv; 43 44 /* This lock is released when we receive PF's response 45 * in qed_send_msg2pf(). 46 * So, qed_vf_pf_prep() and qed_send_msg2pf() 47 * must come in sequence. 48 */ 49 mutex_lock(&(p_iov->mutex)); 50 51 DP_VERBOSE(p_hwfn, 52 QED_MSG_IOV, 53 "preparing to send 0x%04x tlv over vf pf channel\n", 54 type); 55 56 /* Reset Requst offset */ 57 p_iov->offset = (u8 *)p_iov->vf2pf_request; 58 59 /* Clear mailbox - both request and reply */ 60 memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs)); 61 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs)); 62 63 /* Init type and length */ 64 p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length); 65 66 /* Init first tlv header */ 67 ((struct vfpf_first_tlv *)p_tlv)->reply_address = 68 (u64)p_iov->pf2vf_reply_phys; 69 70 return p_tlv; 71 } 72 73 static void qed_vf_pf_req_end(struct qed_hwfn *p_hwfn, int req_status) 74 { 75 union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply; 76 77 DP_VERBOSE(p_hwfn, QED_MSG_IOV, 78 "VF request status = 0x%x, PF reply status = 0x%x\n", 79 req_status, resp->default_resp.hdr.status); 80 81 mutex_unlock(&(p_hwfn->vf_iov_info->mutex)); 82 } 83 84 static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size) 85 { 86 union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request; 87 struct ustorm_trigger_vf_zone trigger; 88 struct ustorm_vf_zone *zone_data; 89 int rc = 0, time = 100; 90 91 zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B; 92 93 /* output tlvs list */ 94 qed_dp_tlv_list(p_hwfn, p_req); 95 96 /* need to add the END TLV to the message size */ 97 resp_size += sizeof(struct channel_list_end_tlv); 98 99 /* Send TLVs over HW channel */ 100 memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone)); 101 trigger.vf_pf_msg_valid = 1; 102 103 DP_VERBOSE(p_hwfn, 104 QED_MSG_IOV, 105 "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n", 106 GET_FIELD(p_hwfn->hw_info.concrete_fid, 107 PXP_CONCRETE_FID_PFID), 108 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys), 109 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys), 110 &zone_data->non_trigger.vf_pf_msg_addr, 111 *((u32 *)&trigger), &zone_data->trigger); 112 113 REG_WR(p_hwfn, 114 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo, 115 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys)); 116 117 REG_WR(p_hwfn, 118 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi, 119 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys)); 120 121 /* The message data must be written first, to prevent trigger before 122 * data is written. 123 */ 124 wmb(); 125 126 REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger)); 127 128 /* When PF would be done with the response, it would write back to the 129 * `done' address. Poll until then. 130 */ 131 while ((!*done) && time) { 132 msleep(25); 133 time--; 134 } 135 136 if (!*done) { 137 DP_NOTICE(p_hwfn, 138 "VF <-- PF Timeout [Type %d]\n", 139 p_req->first_tlv.tl.type); 140 rc = -EBUSY; 141 } else { 142 if ((*done != PFVF_STATUS_SUCCESS) && 143 (*done != PFVF_STATUS_NO_RESOURCE)) 144 DP_NOTICE(p_hwfn, 145 "PF response: %d [Type %d]\n", 146 *done, p_req->first_tlv.tl.type); 147 else 148 DP_VERBOSE(p_hwfn, QED_MSG_IOV, 149 "PF response: %d [Type %d]\n", 150 *done, p_req->first_tlv.tl.type); 151 } 152 153 return rc; 154 } 155 156 static void qed_vf_pf_add_qid(struct qed_hwfn *p_hwfn, 157 struct qed_queue_cid *p_cid) 158 { 159 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 160 struct vfpf_qid_tlv *p_qid_tlv; 161 162 /* Only add QIDs for the queue if it was negotiated with PF */ 163 if (!(p_iov->acquire_resp.pfdev_info.capabilities & 164 PFVF_ACQUIRE_CAP_QUEUE_QIDS)) 165 return; 166 167 p_qid_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, 168 CHANNEL_TLV_QID, sizeof(*p_qid_tlv)); 169 p_qid_tlv->qid = p_cid->qid_usage_idx; 170 } 171 172 #define VF_ACQUIRE_THRESH 3 173 static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn, 174 struct vf_pf_resc_request *p_req, 175 struct pf_vf_resc *p_resp) 176 { 177 DP_VERBOSE(p_hwfn, 178 QED_MSG_IOV, 179 "PF unwilling to fullill resource request: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]. Try PF recommended amount\n", 180 p_req->num_rxqs, 181 p_resp->num_rxqs, 182 p_req->num_rxqs, 183 p_resp->num_txqs, 184 p_req->num_sbs, 185 p_resp->num_sbs, 186 p_req->num_mac_filters, 187 p_resp->num_mac_filters, 188 p_req->num_vlan_filters, 189 p_resp->num_vlan_filters, 190 p_req->num_mc_filters, 191 p_resp->num_mc_filters, p_req->num_cids, p_resp->num_cids); 192 193 /* humble our request */ 194 p_req->num_txqs = p_resp->num_txqs; 195 p_req->num_rxqs = p_resp->num_rxqs; 196 p_req->num_sbs = p_resp->num_sbs; 197 p_req->num_mac_filters = p_resp->num_mac_filters; 198 p_req->num_vlan_filters = p_resp->num_vlan_filters; 199 p_req->num_mc_filters = p_resp->num_mc_filters; 200 p_req->num_cids = p_resp->num_cids; 201 } 202 203 static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn) 204 { 205 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 206 struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp; 207 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info; 208 struct vf_pf_resc_request *p_resc; 209 bool resources_acquired = false; 210 struct vfpf_acquire_tlv *req; 211 int rc = 0, attempts = 0; 212 213 /* clear mailbox and prep first tlv */ 214 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req)); 215 p_resc = &req->resc_request; 216 217 /* starting filling the request */ 218 req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid; 219 220 p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF; 221 p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF; 222 p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF; 223 p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS; 224 p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS; 225 p_resc->num_cids = QED_ETH_VF_DEFAULT_NUM_CIDS; 226 227 req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX; 228 req->vfdev_info.fw_major = FW_MAJOR_VERSION; 229 req->vfdev_info.fw_minor = FW_MINOR_VERSION; 230 req->vfdev_info.fw_revision = FW_REVISION_VERSION; 231 req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION; 232 req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR; 233 req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR; 234 235 /* Fill capability field with any non-deprecated config we support */ 236 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G; 237 238 /* pf 2 vf bulletin board address */ 239 req->bulletin_addr = p_iov->bulletin.phys; 240 req->bulletin_size = p_iov->bulletin.size; 241 242 /* add list termination tlv */ 243 qed_add_tlv(p_hwfn, &p_iov->offset, 244 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 245 246 while (!resources_acquired) { 247 DP_VERBOSE(p_hwfn, 248 QED_MSG_IOV, "attempting to acquire resources\n"); 249 250 /* Clear response buffer, as this might be a re-send */ 251 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs)); 252 253 /* send acquire request */ 254 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 255 if (rc) 256 goto exit; 257 258 /* copy acquire response from buffer to p_hwfn */ 259 memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp)); 260 261 attempts++; 262 263 if (resp->hdr.status == PFVF_STATUS_SUCCESS) { 264 /* PF agrees to allocate our resources */ 265 if (!(resp->pfdev_info.capabilities & 266 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) { 267 /* It's possible legacy PF mistakenly accepted; 268 * but we don't care - simply mark it as 269 * legacy and continue. 270 */ 271 req->vfdev_info.capabilities |= 272 VFPF_ACQUIRE_CAP_PRE_FP_HSI; 273 } 274 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n"); 275 resources_acquired = true; 276 } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE && 277 attempts < VF_ACQUIRE_THRESH) { 278 qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc, 279 &resp->resc); 280 } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) { 281 if (pfdev_info->major_fp_hsi && 282 (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) { 283 DP_NOTICE(p_hwfn, 284 "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n", 285 pfdev_info->major_fp_hsi, 286 pfdev_info->minor_fp_hsi, 287 ETH_HSI_VER_MAJOR, 288 ETH_HSI_VER_MINOR, 289 pfdev_info->major_fp_hsi); 290 rc = -EINVAL; 291 goto exit; 292 } 293 294 if (!pfdev_info->major_fp_hsi) { 295 if (req->vfdev_info.capabilities & 296 VFPF_ACQUIRE_CAP_PRE_FP_HSI) { 297 DP_NOTICE(p_hwfn, 298 "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n"); 299 rc = -EINVAL; 300 goto exit; 301 } else { 302 DP_INFO(p_hwfn, 303 "PF is old - try re-acquire to see if it supports FW-version override\n"); 304 req->vfdev_info.capabilities |= 305 VFPF_ACQUIRE_CAP_PRE_FP_HSI; 306 continue; 307 } 308 } 309 310 /* If PF/VF are using same Major, PF must have had 311 * it's reasons. Simply fail. 312 */ 313 DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n"); 314 rc = -EINVAL; 315 goto exit; 316 } else { 317 DP_ERR(p_hwfn, 318 "PF returned error %d to VF acquisition request\n", 319 resp->hdr.status); 320 rc = -EAGAIN; 321 goto exit; 322 } 323 } 324 325 /* Mark the PF as legacy, if needed */ 326 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI) 327 p_iov->b_pre_fp_hsi = true; 328 329 /* In case PF doesn't support multi-queue Tx, update the number of 330 * CIDs to reflect the number of queues [older PFs didn't fill that 331 * field]. 332 */ 333 if (!(resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_QUEUE_QIDS)) 334 resp->resc.num_cids = resp->resc.num_rxqs + resp->resc.num_txqs; 335 336 /* Update bulletin board size with response from PF */ 337 p_iov->bulletin.size = resp->bulletin_size; 338 339 /* get HW info */ 340 p_hwfn->cdev->type = resp->pfdev_info.dev_type; 341 p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev; 342 343 p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff; 344 345 /* Learn of the possibility of CMT */ 346 if (IS_LEAD_HWFN(p_hwfn)) { 347 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) { 348 DP_NOTICE(p_hwfn, "100g VF\n"); 349 p_hwfn->cdev->num_hwfns = 2; 350 } 351 } 352 353 if (!p_iov->b_pre_fp_hsi && 354 ETH_HSI_VER_MINOR && 355 (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) { 356 DP_INFO(p_hwfn, 357 "PF is using older fastpath HSI; %02x.%02x is configured\n", 358 ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi); 359 } 360 361 exit: 362 qed_vf_pf_req_end(p_hwfn, rc); 363 364 return rc; 365 } 366 367 int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn) 368 { 369 struct qed_vf_iov *p_iov; 370 u32 reg; 371 372 /* Set number of hwfns - might be overriden once leading hwfn learns 373 * actual configuration from PF. 374 */ 375 if (IS_LEAD_HWFN(p_hwfn)) 376 p_hwfn->cdev->num_hwfns = 1; 377 378 /* Set the doorbell bar. Assumption: regview is set */ 379 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview + 380 PXP_VF_BAR0_START_DQ; 381 382 reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS; 383 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg); 384 385 reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS; 386 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg); 387 388 /* Allocate vf sriov info */ 389 p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL); 390 if (!p_iov) 391 return -ENOMEM; 392 393 /* Allocate vf2pf msg */ 394 p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, 395 sizeof(union vfpf_tlvs), 396 &p_iov->vf2pf_request_phys, 397 GFP_KERNEL); 398 if (!p_iov->vf2pf_request) 399 goto free_p_iov; 400 401 p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, 402 sizeof(union pfvf_tlvs), 403 &p_iov->pf2vf_reply_phys, 404 GFP_KERNEL); 405 if (!p_iov->pf2vf_reply) 406 goto free_vf2pf_request; 407 408 DP_VERBOSE(p_hwfn, 409 QED_MSG_IOV, 410 "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n", 411 p_iov->vf2pf_request, 412 (u64) p_iov->vf2pf_request_phys, 413 p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys); 414 415 /* Allocate Bulletin board */ 416 p_iov->bulletin.size = sizeof(struct qed_bulletin_content); 417 p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, 418 p_iov->bulletin.size, 419 &p_iov->bulletin.phys, 420 GFP_KERNEL); 421 DP_VERBOSE(p_hwfn, QED_MSG_IOV, 422 "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n", 423 p_iov->bulletin.p_virt, 424 (u64)p_iov->bulletin.phys, p_iov->bulletin.size); 425 426 mutex_init(&p_iov->mutex); 427 428 p_hwfn->vf_iov_info = p_iov; 429 430 p_hwfn->hw_info.personality = QED_PCI_ETH; 431 432 return qed_vf_pf_acquire(p_hwfn); 433 434 free_vf2pf_request: 435 dma_free_coherent(&p_hwfn->cdev->pdev->dev, 436 sizeof(union vfpf_tlvs), 437 p_iov->vf2pf_request, p_iov->vf2pf_request_phys); 438 free_p_iov: 439 kfree(p_iov); 440 441 return -ENOMEM; 442 } 443 #define TSTORM_QZONE_START PXP_VF_BAR0_START_SDM_ZONE_A 444 #define MSTORM_QZONE_START(dev) (TSTORM_QZONE_START + \ 445 (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev))) 446 447 static void 448 __qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req, 449 struct qed_tunn_update_type *p_src, 450 enum qed_tunn_clss mask, u8 *p_cls) 451 { 452 if (p_src->b_update_mode) { 453 p_req->tun_mode_update_mask |= BIT(mask); 454 455 if (p_src->b_mode_enabled) 456 p_req->tunn_mode |= BIT(mask); 457 } 458 459 *p_cls = p_src->tun_cls; 460 } 461 462 static void 463 qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req, 464 struct qed_tunn_update_type *p_src, 465 enum qed_tunn_clss mask, 466 u8 *p_cls, struct qed_tunn_update_udp_port *p_port, 467 u8 *p_update_port, u16 *p_udp_port) 468 { 469 if (p_port->b_update_port) { 470 *p_update_port = 1; 471 *p_udp_port = p_port->port; 472 } 473 474 __qed_vf_prep_tunn_req_tlv(p_req, p_src, mask, p_cls); 475 } 476 477 void qed_vf_set_vf_start_tunn_update_param(struct qed_tunnel_info *p_tun) 478 { 479 if (p_tun->vxlan.b_mode_enabled) 480 p_tun->vxlan.b_update_mode = true; 481 if (p_tun->l2_geneve.b_mode_enabled) 482 p_tun->l2_geneve.b_update_mode = true; 483 if (p_tun->ip_geneve.b_mode_enabled) 484 p_tun->ip_geneve.b_update_mode = true; 485 if (p_tun->l2_gre.b_mode_enabled) 486 p_tun->l2_gre.b_update_mode = true; 487 if (p_tun->ip_gre.b_mode_enabled) 488 p_tun->ip_gre.b_update_mode = true; 489 490 p_tun->b_update_rx_cls = true; 491 p_tun->b_update_tx_cls = true; 492 } 493 494 static void 495 __qed_vf_update_tunn_param(struct qed_tunn_update_type *p_tun, 496 u16 feature_mask, u8 tunn_mode, 497 u8 tunn_cls, enum qed_tunn_mode val) 498 { 499 if (feature_mask & BIT(val)) { 500 p_tun->b_mode_enabled = tunn_mode; 501 p_tun->tun_cls = tunn_cls; 502 } else { 503 p_tun->b_mode_enabled = false; 504 } 505 } 506 507 static void qed_vf_update_tunn_param(struct qed_hwfn *p_hwfn, 508 struct qed_tunnel_info *p_tun, 509 struct pfvf_update_tunn_param_tlv *p_resp) 510 { 511 /* Update mode and classes provided by PF */ 512 u16 feat_mask = p_resp->tunn_feature_mask; 513 514 __qed_vf_update_tunn_param(&p_tun->vxlan, feat_mask, 515 p_resp->vxlan_mode, p_resp->vxlan_clss, 516 QED_MODE_VXLAN_TUNN); 517 __qed_vf_update_tunn_param(&p_tun->l2_geneve, feat_mask, 518 p_resp->l2geneve_mode, 519 p_resp->l2geneve_clss, 520 QED_MODE_L2GENEVE_TUNN); 521 __qed_vf_update_tunn_param(&p_tun->ip_geneve, feat_mask, 522 p_resp->ipgeneve_mode, 523 p_resp->ipgeneve_clss, 524 QED_MODE_IPGENEVE_TUNN); 525 __qed_vf_update_tunn_param(&p_tun->l2_gre, feat_mask, 526 p_resp->l2gre_mode, p_resp->l2gre_clss, 527 QED_MODE_L2GRE_TUNN); 528 __qed_vf_update_tunn_param(&p_tun->ip_gre, feat_mask, 529 p_resp->ipgre_mode, p_resp->ipgre_clss, 530 QED_MODE_IPGRE_TUNN); 531 p_tun->geneve_port.port = p_resp->geneve_udp_port; 532 p_tun->vxlan_port.port = p_resp->vxlan_udp_port; 533 534 DP_VERBOSE(p_hwfn, QED_MSG_IOV, 535 "tunn mode: vxlan=0x%x, l2geneve=0x%x, ipgeneve=0x%x, l2gre=0x%x, ipgre=0x%x", 536 p_tun->vxlan.b_mode_enabled, p_tun->l2_geneve.b_mode_enabled, 537 p_tun->ip_geneve.b_mode_enabled, 538 p_tun->l2_gre.b_mode_enabled, p_tun->ip_gre.b_mode_enabled); 539 } 540 541 int qed_vf_pf_tunnel_param_update(struct qed_hwfn *p_hwfn, 542 struct qed_tunnel_info *p_src) 543 { 544 struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel; 545 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 546 struct pfvf_update_tunn_param_tlv *p_resp; 547 struct vfpf_update_tunn_param_tlv *p_req; 548 int rc; 549 550 p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_TUNN_PARAM, 551 sizeof(*p_req)); 552 553 if (p_src->b_update_rx_cls && p_src->b_update_tx_cls) 554 p_req->update_tun_cls = 1; 555 556 qed_vf_prep_tunn_req_tlv(p_req, &p_src->vxlan, QED_MODE_VXLAN_TUNN, 557 &p_req->vxlan_clss, &p_src->vxlan_port, 558 &p_req->update_vxlan_port, 559 &p_req->vxlan_port); 560 qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_geneve, 561 QED_MODE_L2GENEVE_TUNN, 562 &p_req->l2geneve_clss, &p_src->geneve_port, 563 &p_req->update_geneve_port, 564 &p_req->geneve_port); 565 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_geneve, 566 QED_MODE_IPGENEVE_TUNN, 567 &p_req->ipgeneve_clss); 568 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_gre, 569 QED_MODE_L2GRE_TUNN, &p_req->l2gre_clss); 570 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_gre, 571 QED_MODE_IPGRE_TUNN, &p_req->ipgre_clss); 572 573 /* add list termination tlv */ 574 qed_add_tlv(p_hwfn, &p_iov->offset, 575 CHANNEL_TLV_LIST_END, 576 sizeof(struct channel_list_end_tlv)); 577 578 p_resp = &p_iov->pf2vf_reply->tunn_param_resp; 579 rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp)); 580 581 if (rc) 582 goto exit; 583 584 if (p_resp->hdr.status != PFVF_STATUS_SUCCESS) { 585 DP_VERBOSE(p_hwfn, QED_MSG_IOV, 586 "Failed to update tunnel parameters\n"); 587 rc = -EINVAL; 588 } 589 590 qed_vf_update_tunn_param(p_hwfn, p_tun, p_resp); 591 exit: 592 qed_vf_pf_req_end(p_hwfn, rc); 593 return rc; 594 } 595 596 int 597 qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn, 598 struct qed_queue_cid *p_cid, 599 u16 bd_max_bytes, 600 dma_addr_t bd_chain_phys_addr, 601 dma_addr_t cqe_pbl_addr, 602 u16 cqe_pbl_size, void __iomem **pp_prod) 603 { 604 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 605 struct pfvf_start_queue_resp_tlv *resp; 606 struct vfpf_start_rxq_tlv *req; 607 u8 rx_qid = p_cid->rel.queue_id; 608 int rc; 609 610 /* clear mailbox and prep first tlv */ 611 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req)); 612 613 req->rx_qid = rx_qid; 614 req->cqe_pbl_addr = cqe_pbl_addr; 615 req->cqe_pbl_size = cqe_pbl_size; 616 req->rxq_addr = bd_chain_phys_addr; 617 req->hw_sb = p_cid->sb_igu_id; 618 req->sb_index = p_cid->sb_idx; 619 req->bd_max_bytes = bd_max_bytes; 620 req->stat_id = -1; 621 622 /* If PF is legacy, we'll need to calculate producers ourselves 623 * as well as clean them. 624 */ 625 if (p_iov->b_pre_fp_hsi) { 626 u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid]; 627 u32 init_prod_val = 0; 628 629 *pp_prod = (u8 __iomem *) 630 p_hwfn->regview + 631 MSTORM_QZONE_START(p_hwfn->cdev) + 632 hw_qid * MSTORM_QZONE_SIZE; 633 634 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */ 635 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32), 636 (u32 *)(&init_prod_val)); 637 } 638 639 qed_vf_pf_add_qid(p_hwfn, p_cid); 640 641 /* add list termination tlv */ 642 qed_add_tlv(p_hwfn, &p_iov->offset, 643 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 644 645 resp = &p_iov->pf2vf_reply->queue_start; 646 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 647 if (rc) 648 goto exit; 649 650 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 651 rc = -EINVAL; 652 goto exit; 653 } 654 655 /* Learn the address of the producer from the response */ 656 if (!p_iov->b_pre_fp_hsi) { 657 u32 init_prod_val = 0; 658 659 *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset; 660 DP_VERBOSE(p_hwfn, QED_MSG_IOV, 661 "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n", 662 rx_qid, *pp_prod, resp->offset); 663 664 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */ 665 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32), 666 (u32 *)&init_prod_val); 667 } 668 exit: 669 qed_vf_pf_req_end(p_hwfn, rc); 670 671 return rc; 672 } 673 674 int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn, 675 struct qed_queue_cid *p_cid, bool cqe_completion) 676 { 677 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 678 struct vfpf_stop_rxqs_tlv *req; 679 struct pfvf_def_resp_tlv *resp; 680 int rc; 681 682 /* clear mailbox and prep first tlv */ 683 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req)); 684 685 req->rx_qid = p_cid->rel.queue_id; 686 req->num_rxqs = 1; 687 req->cqe_completion = cqe_completion; 688 689 qed_vf_pf_add_qid(p_hwfn, p_cid); 690 691 /* add list termination tlv */ 692 qed_add_tlv(p_hwfn, &p_iov->offset, 693 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 694 695 resp = &p_iov->pf2vf_reply->default_resp; 696 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 697 if (rc) 698 goto exit; 699 700 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 701 rc = -EINVAL; 702 goto exit; 703 } 704 705 exit: 706 qed_vf_pf_req_end(p_hwfn, rc); 707 708 return rc; 709 } 710 711 int 712 qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn, 713 struct qed_queue_cid *p_cid, 714 dma_addr_t pbl_addr, 715 u16 pbl_size, void __iomem **pp_doorbell) 716 { 717 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 718 struct pfvf_start_queue_resp_tlv *resp; 719 struct vfpf_start_txq_tlv *req; 720 u16 qid = p_cid->rel.queue_id; 721 int rc; 722 723 /* clear mailbox and prep first tlv */ 724 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req)); 725 726 req->tx_qid = qid; 727 728 /* Tx */ 729 req->pbl_addr = pbl_addr; 730 req->pbl_size = pbl_size; 731 req->hw_sb = p_cid->sb_igu_id; 732 req->sb_index = p_cid->sb_idx; 733 734 qed_vf_pf_add_qid(p_hwfn, p_cid); 735 736 /* add list termination tlv */ 737 qed_add_tlv(p_hwfn, &p_iov->offset, 738 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 739 740 resp = &p_iov->pf2vf_reply->queue_start; 741 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 742 if (rc) 743 goto exit; 744 745 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 746 rc = -EINVAL; 747 goto exit; 748 } 749 750 /* Modern PFs provide the actual offsets, while legacy 751 * provided only the queue id. 752 */ 753 if (!p_iov->b_pre_fp_hsi) { 754 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + resp->offset; 755 } else { 756 u8 cid = p_iov->acquire_resp.resc.cid[qid]; 757 758 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + 759 qed_db_addr_vf(cid, 760 DQ_DEMS_LEGACY); 761 } 762 763 DP_VERBOSE(p_hwfn, QED_MSG_IOV, 764 "Txq[0x%02x]: doorbell at %p [offset 0x%08x]\n", 765 qid, *pp_doorbell, resp->offset); 766 exit: 767 qed_vf_pf_req_end(p_hwfn, rc); 768 769 return rc; 770 } 771 772 int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid) 773 { 774 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 775 struct vfpf_stop_txqs_tlv *req; 776 struct pfvf_def_resp_tlv *resp; 777 int rc; 778 779 /* clear mailbox and prep first tlv */ 780 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req)); 781 782 req->tx_qid = p_cid->rel.queue_id; 783 req->num_txqs = 1; 784 785 qed_vf_pf_add_qid(p_hwfn, p_cid); 786 787 /* add list termination tlv */ 788 qed_add_tlv(p_hwfn, &p_iov->offset, 789 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 790 791 resp = &p_iov->pf2vf_reply->default_resp; 792 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 793 if (rc) 794 goto exit; 795 796 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 797 rc = -EINVAL; 798 goto exit; 799 } 800 801 exit: 802 qed_vf_pf_req_end(p_hwfn, rc); 803 804 return rc; 805 } 806 807 int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn, 808 u8 vport_id, 809 u16 mtu, 810 u8 inner_vlan_removal, 811 enum qed_tpa_mode tpa_mode, 812 u8 max_buffers_per_cqe, u8 only_untagged) 813 { 814 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 815 struct vfpf_vport_start_tlv *req; 816 struct pfvf_def_resp_tlv *resp; 817 int rc, i; 818 819 /* clear mailbox and prep first tlv */ 820 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req)); 821 822 req->mtu = mtu; 823 req->vport_id = vport_id; 824 req->inner_vlan_removal = inner_vlan_removal; 825 req->tpa_mode = tpa_mode; 826 req->max_buffers_per_cqe = max_buffers_per_cqe; 827 req->only_untagged = only_untagged; 828 829 /* status blocks */ 830 for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++) { 831 struct qed_sb_info *p_sb = p_hwfn->vf_iov_info->sbs_info[i]; 832 833 if (p_sb) 834 req->sb_addr[i] = p_sb->sb_phys; 835 } 836 837 /* add list termination tlv */ 838 qed_add_tlv(p_hwfn, &p_iov->offset, 839 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 840 841 resp = &p_iov->pf2vf_reply->default_resp; 842 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 843 if (rc) 844 goto exit; 845 846 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 847 rc = -EINVAL; 848 goto exit; 849 } 850 851 exit: 852 qed_vf_pf_req_end(p_hwfn, rc); 853 854 return rc; 855 } 856 857 int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn) 858 { 859 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 860 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp; 861 int rc; 862 863 /* clear mailbox and prep first tlv */ 864 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN, 865 sizeof(struct vfpf_first_tlv)); 866 867 /* add list termination tlv */ 868 qed_add_tlv(p_hwfn, &p_iov->offset, 869 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 870 871 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 872 if (rc) 873 goto exit; 874 875 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 876 rc = -EINVAL; 877 goto exit; 878 } 879 880 exit: 881 qed_vf_pf_req_end(p_hwfn, rc); 882 883 return rc; 884 } 885 886 static bool 887 qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn, 888 struct qed_sp_vport_update_params *p_data, 889 u16 tlv) 890 { 891 switch (tlv) { 892 case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE: 893 return !!(p_data->update_vport_active_rx_flg || 894 p_data->update_vport_active_tx_flg); 895 case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH: 896 return !!p_data->update_tx_switching_flg; 897 case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP: 898 return !!p_data->update_inner_vlan_removal_flg; 899 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN: 900 return !!p_data->update_accept_any_vlan_flg; 901 case CHANNEL_TLV_VPORT_UPDATE_MCAST: 902 return !!p_data->update_approx_mcast_flg; 903 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM: 904 return !!(p_data->accept_flags.update_rx_mode_config || 905 p_data->accept_flags.update_tx_mode_config); 906 case CHANNEL_TLV_VPORT_UPDATE_RSS: 907 return !!p_data->rss_params; 908 case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA: 909 return !!p_data->sge_tpa_params; 910 default: 911 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n", 912 tlv); 913 return false; 914 } 915 } 916 917 static void 918 qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn, 919 struct qed_sp_vport_update_params *p_data) 920 { 921 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 922 struct pfvf_def_resp_tlv *p_resp; 923 u16 tlv; 924 925 for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE; 926 tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) { 927 if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv)) 928 continue; 929 930 p_resp = (struct pfvf_def_resp_tlv *) 931 qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply, 932 tlv); 933 if (p_resp && p_resp->hdr.status) 934 DP_VERBOSE(p_hwfn, QED_MSG_IOV, 935 "TLV[%d] Configuration %s\n", 936 tlv, 937 (p_resp && p_resp->hdr.status) ? "succeeded" 938 : "failed"); 939 } 940 } 941 942 int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn, 943 struct qed_sp_vport_update_params *p_params) 944 { 945 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 946 struct vfpf_vport_update_tlv *req; 947 struct pfvf_def_resp_tlv *resp; 948 u8 update_rx, update_tx; 949 u32 resp_size = 0; 950 u16 size, tlv; 951 int rc; 952 953 resp = &p_iov->pf2vf_reply->default_resp; 954 resp_size = sizeof(*resp); 955 956 update_rx = p_params->update_vport_active_rx_flg; 957 update_tx = p_params->update_vport_active_tx_flg; 958 959 /* clear mailbox and prep header tlv */ 960 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req)); 961 962 /* Prepare extended tlvs */ 963 if (update_rx || update_tx) { 964 struct vfpf_vport_update_activate_tlv *p_act_tlv; 965 966 size = sizeof(struct vfpf_vport_update_activate_tlv); 967 p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, 968 CHANNEL_TLV_VPORT_UPDATE_ACTIVATE, 969 size); 970 resp_size += sizeof(struct pfvf_def_resp_tlv); 971 972 if (update_rx) { 973 p_act_tlv->update_rx = update_rx; 974 p_act_tlv->active_rx = p_params->vport_active_rx_flg; 975 } 976 977 if (update_tx) { 978 p_act_tlv->update_tx = update_tx; 979 p_act_tlv->active_tx = p_params->vport_active_tx_flg; 980 } 981 } 982 983 if (p_params->update_tx_switching_flg) { 984 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv; 985 986 size = sizeof(struct vfpf_vport_update_tx_switch_tlv); 987 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH; 988 p_tx_switch_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, 989 tlv, size); 990 resp_size += sizeof(struct pfvf_def_resp_tlv); 991 992 p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg; 993 } 994 995 if (p_params->update_approx_mcast_flg) { 996 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv; 997 998 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv); 999 p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, 1000 CHANNEL_TLV_VPORT_UPDATE_MCAST, size); 1001 resp_size += sizeof(struct pfvf_def_resp_tlv); 1002 1003 memcpy(p_mcast_tlv->bins, p_params->bins, 1004 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS); 1005 } 1006 1007 update_rx = p_params->accept_flags.update_rx_mode_config; 1008 update_tx = p_params->accept_flags.update_tx_mode_config; 1009 1010 if (update_rx || update_tx) { 1011 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv; 1012 1013 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM; 1014 size = sizeof(struct vfpf_vport_update_accept_param_tlv); 1015 p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size); 1016 resp_size += sizeof(struct pfvf_def_resp_tlv); 1017 1018 if (update_rx) { 1019 p_accept_tlv->update_rx_mode = update_rx; 1020 p_accept_tlv->rx_accept_filter = 1021 p_params->accept_flags.rx_accept_filter; 1022 } 1023 1024 if (update_tx) { 1025 p_accept_tlv->update_tx_mode = update_tx; 1026 p_accept_tlv->tx_accept_filter = 1027 p_params->accept_flags.tx_accept_filter; 1028 } 1029 } 1030 1031 if (p_params->rss_params) { 1032 struct qed_rss_params *rss_params = p_params->rss_params; 1033 struct vfpf_vport_update_rss_tlv *p_rss_tlv; 1034 int i, table_size; 1035 1036 size = sizeof(struct vfpf_vport_update_rss_tlv); 1037 p_rss_tlv = qed_add_tlv(p_hwfn, 1038 &p_iov->offset, 1039 CHANNEL_TLV_VPORT_UPDATE_RSS, size); 1040 resp_size += sizeof(struct pfvf_def_resp_tlv); 1041 1042 if (rss_params->update_rss_config) 1043 p_rss_tlv->update_rss_flags |= 1044 VFPF_UPDATE_RSS_CONFIG_FLAG; 1045 if (rss_params->update_rss_capabilities) 1046 p_rss_tlv->update_rss_flags |= 1047 VFPF_UPDATE_RSS_CAPS_FLAG; 1048 if (rss_params->update_rss_ind_table) 1049 p_rss_tlv->update_rss_flags |= 1050 VFPF_UPDATE_RSS_IND_TABLE_FLAG; 1051 if (rss_params->update_rss_key) 1052 p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG; 1053 1054 p_rss_tlv->rss_enable = rss_params->rss_enable; 1055 p_rss_tlv->rss_caps = rss_params->rss_caps; 1056 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log; 1057 1058 table_size = min_t(int, T_ETH_INDIRECTION_TABLE_SIZE, 1059 1 << p_rss_tlv->rss_table_size_log); 1060 for (i = 0; i < table_size; i++) { 1061 struct qed_queue_cid *p_queue; 1062 1063 p_queue = rss_params->rss_ind_table[i]; 1064 p_rss_tlv->rss_ind_table[i] = p_queue->rel.queue_id; 1065 } 1066 memcpy(p_rss_tlv->rss_key, rss_params->rss_key, 1067 sizeof(rss_params->rss_key)); 1068 } 1069 1070 if (p_params->update_accept_any_vlan_flg) { 1071 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv; 1072 1073 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv); 1074 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN; 1075 p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size); 1076 1077 resp_size += sizeof(struct pfvf_def_resp_tlv); 1078 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan; 1079 p_any_vlan_tlv->update_accept_any_vlan_flg = 1080 p_params->update_accept_any_vlan_flg; 1081 } 1082 1083 /* add list termination tlv */ 1084 qed_add_tlv(p_hwfn, &p_iov->offset, 1085 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 1086 1087 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size); 1088 if (rc) 1089 goto exit; 1090 1091 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 1092 rc = -EINVAL; 1093 goto exit; 1094 } 1095 1096 qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params); 1097 1098 exit: 1099 qed_vf_pf_req_end(p_hwfn, rc); 1100 1101 return rc; 1102 } 1103 1104 int qed_vf_pf_reset(struct qed_hwfn *p_hwfn) 1105 { 1106 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 1107 struct pfvf_def_resp_tlv *resp; 1108 struct vfpf_first_tlv *req; 1109 int rc; 1110 1111 /* clear mailbox and prep first tlv */ 1112 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req)); 1113 1114 /* add list termination tlv */ 1115 qed_add_tlv(p_hwfn, &p_iov->offset, 1116 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 1117 1118 resp = &p_iov->pf2vf_reply->default_resp; 1119 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 1120 if (rc) 1121 goto exit; 1122 1123 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 1124 rc = -EAGAIN; 1125 goto exit; 1126 } 1127 1128 p_hwfn->b_int_enabled = 0; 1129 1130 exit: 1131 qed_vf_pf_req_end(p_hwfn, rc); 1132 1133 return rc; 1134 } 1135 1136 int qed_vf_pf_release(struct qed_hwfn *p_hwfn) 1137 { 1138 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 1139 struct pfvf_def_resp_tlv *resp; 1140 struct vfpf_first_tlv *req; 1141 u32 size; 1142 int rc; 1143 1144 /* clear mailbox and prep first tlv */ 1145 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req)); 1146 1147 /* add list termination tlv */ 1148 qed_add_tlv(p_hwfn, &p_iov->offset, 1149 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 1150 1151 resp = &p_iov->pf2vf_reply->default_resp; 1152 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 1153 1154 if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS) 1155 rc = -EAGAIN; 1156 1157 qed_vf_pf_req_end(p_hwfn, rc); 1158 1159 p_hwfn->b_int_enabled = 0; 1160 1161 if (p_iov->vf2pf_request) 1162 dma_free_coherent(&p_hwfn->cdev->pdev->dev, 1163 sizeof(union vfpf_tlvs), 1164 p_iov->vf2pf_request, 1165 p_iov->vf2pf_request_phys); 1166 if (p_iov->pf2vf_reply) 1167 dma_free_coherent(&p_hwfn->cdev->pdev->dev, 1168 sizeof(union pfvf_tlvs), 1169 p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys); 1170 1171 if (p_iov->bulletin.p_virt) { 1172 size = sizeof(struct qed_bulletin_content); 1173 dma_free_coherent(&p_hwfn->cdev->pdev->dev, 1174 size, 1175 p_iov->bulletin.p_virt, p_iov->bulletin.phys); 1176 } 1177 1178 kfree(p_hwfn->vf_iov_info); 1179 p_hwfn->vf_iov_info = NULL; 1180 1181 return rc; 1182 } 1183 1184 void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn, 1185 struct qed_filter_mcast *p_filter_cmd) 1186 { 1187 struct qed_sp_vport_update_params sp_params; 1188 int i; 1189 1190 memset(&sp_params, 0, sizeof(sp_params)); 1191 sp_params.update_approx_mcast_flg = 1; 1192 1193 if (p_filter_cmd->opcode == QED_FILTER_ADD) { 1194 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) { 1195 u32 bit; 1196 1197 bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]); 1198 __set_bit(bit, sp_params.bins); 1199 } 1200 } 1201 1202 qed_vf_pf_vport_update(p_hwfn, &sp_params); 1203 } 1204 1205 int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn, 1206 struct qed_filter_ucast *p_ucast) 1207 { 1208 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 1209 struct vfpf_ucast_filter_tlv *req; 1210 struct pfvf_def_resp_tlv *resp; 1211 int rc; 1212 1213 /* clear mailbox and prep first tlv */ 1214 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req)); 1215 req->opcode = (u8) p_ucast->opcode; 1216 req->type = (u8) p_ucast->type; 1217 memcpy(req->mac, p_ucast->mac, ETH_ALEN); 1218 req->vlan = p_ucast->vlan; 1219 1220 /* add list termination tlv */ 1221 qed_add_tlv(p_hwfn, &p_iov->offset, 1222 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 1223 1224 resp = &p_iov->pf2vf_reply->default_resp; 1225 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 1226 if (rc) 1227 goto exit; 1228 1229 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 1230 rc = -EAGAIN; 1231 goto exit; 1232 } 1233 1234 exit: 1235 qed_vf_pf_req_end(p_hwfn, rc); 1236 1237 return rc; 1238 } 1239 1240 int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn) 1241 { 1242 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 1243 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp; 1244 int rc; 1245 1246 /* clear mailbox and prep first tlv */ 1247 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP, 1248 sizeof(struct vfpf_first_tlv)); 1249 1250 /* add list termination tlv */ 1251 qed_add_tlv(p_hwfn, &p_iov->offset, 1252 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); 1253 1254 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); 1255 if (rc) 1256 goto exit; 1257 1258 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 1259 rc = -EINVAL; 1260 goto exit; 1261 } 1262 1263 exit: 1264 qed_vf_pf_req_end(p_hwfn, rc); 1265 1266 return rc; 1267 } 1268 1269 u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id) 1270 { 1271 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 1272 1273 if (!p_iov) { 1274 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n"); 1275 return 0; 1276 } 1277 1278 return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id; 1279 } 1280 1281 void qed_vf_set_sb_info(struct qed_hwfn *p_hwfn, 1282 u16 sb_id, struct qed_sb_info *p_sb) 1283 { 1284 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 1285 1286 if (!p_iov) { 1287 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n"); 1288 return; 1289 } 1290 1291 if (sb_id >= PFVF_MAX_SBS_PER_VF) { 1292 DP_NOTICE(p_hwfn, "Can't configure SB %04x\n", sb_id); 1293 return; 1294 } 1295 1296 p_iov->sbs_info[sb_id] = p_sb; 1297 } 1298 1299 int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change) 1300 { 1301 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; 1302 struct qed_bulletin_content shadow; 1303 u32 crc, crc_size; 1304 1305 crc_size = sizeof(p_iov->bulletin.p_virt->crc); 1306 *p_change = 0; 1307 1308 /* Need to guarantee PF is not in the middle of writing it */ 1309 memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size); 1310 1311 /* If version did not update, no need to do anything */ 1312 if (shadow.version == p_iov->bulletin_shadow.version) 1313 return 0; 1314 1315 /* Verify the bulletin we see is valid */ 1316 crc = crc32(0, (u8 *)&shadow + crc_size, 1317 p_iov->bulletin.size - crc_size); 1318 if (crc != shadow.crc) 1319 return -EAGAIN; 1320 1321 /* Set the shadow bulletin and process it */ 1322 memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size); 1323 1324 DP_VERBOSE(p_hwfn, QED_MSG_IOV, 1325 "Read a bulletin update %08x\n", shadow.version); 1326 1327 *p_change = 1; 1328 1329 return 0; 1330 } 1331 1332 void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn, 1333 struct qed_mcp_link_params *p_params, 1334 struct qed_bulletin_content *p_bulletin) 1335 { 1336 memset(p_params, 0, sizeof(*p_params)); 1337 1338 p_params->speed.autoneg = p_bulletin->req_autoneg; 1339 p_params->speed.advertised_speeds = p_bulletin->req_adv_speed; 1340 p_params->speed.forced_speed = p_bulletin->req_forced_speed; 1341 p_params->pause.autoneg = p_bulletin->req_autoneg_pause; 1342 p_params->pause.forced_rx = p_bulletin->req_forced_rx; 1343 p_params->pause.forced_tx = p_bulletin->req_forced_tx; 1344 p_params->loopback_mode = p_bulletin->req_loopback; 1345 } 1346 1347 void qed_vf_get_link_params(struct qed_hwfn *p_hwfn, 1348 struct qed_mcp_link_params *params) 1349 { 1350 __qed_vf_get_link_params(p_hwfn, params, 1351 &(p_hwfn->vf_iov_info->bulletin_shadow)); 1352 } 1353 1354 void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn, 1355 struct qed_mcp_link_state *p_link, 1356 struct qed_bulletin_content *p_bulletin) 1357 { 1358 memset(p_link, 0, sizeof(*p_link)); 1359 1360 p_link->link_up = p_bulletin->link_up; 1361 p_link->speed = p_bulletin->speed; 1362 p_link->full_duplex = p_bulletin->full_duplex; 1363 p_link->an = p_bulletin->autoneg; 1364 p_link->an_complete = p_bulletin->autoneg_complete; 1365 p_link->parallel_detection = p_bulletin->parallel_detection; 1366 p_link->pfc_enabled = p_bulletin->pfc_enabled; 1367 p_link->partner_adv_speed = p_bulletin->partner_adv_speed; 1368 p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en; 1369 p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en; 1370 p_link->partner_adv_pause = p_bulletin->partner_adv_pause; 1371 p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault; 1372 } 1373 1374 void qed_vf_get_link_state(struct qed_hwfn *p_hwfn, 1375 struct qed_mcp_link_state *link) 1376 { 1377 __qed_vf_get_link_state(p_hwfn, link, 1378 &(p_hwfn->vf_iov_info->bulletin_shadow)); 1379 } 1380 1381 void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn, 1382 struct qed_mcp_link_capabilities *p_link_caps, 1383 struct qed_bulletin_content *p_bulletin) 1384 { 1385 memset(p_link_caps, 0, sizeof(*p_link_caps)); 1386 p_link_caps->speed_capabilities = p_bulletin->capability_speed; 1387 } 1388 1389 void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn, 1390 struct qed_mcp_link_capabilities *p_link_caps) 1391 { 1392 __qed_vf_get_link_caps(p_hwfn, p_link_caps, 1393 &(p_hwfn->vf_iov_info->bulletin_shadow)); 1394 } 1395 1396 void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs) 1397 { 1398 *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs; 1399 } 1400 1401 void qed_vf_get_num_txqs(struct qed_hwfn *p_hwfn, u8 *num_txqs) 1402 { 1403 *num_txqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_txqs; 1404 } 1405 1406 void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac) 1407 { 1408 memcpy(port_mac, 1409 p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN); 1410 } 1411 1412 void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters) 1413 { 1414 struct qed_vf_iov *p_vf; 1415 1416 p_vf = p_hwfn->vf_iov_info; 1417 *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters; 1418 } 1419 1420 void qed_vf_get_num_mac_filters(struct qed_hwfn *p_hwfn, u8 *num_mac_filters) 1421 { 1422 struct qed_vf_iov *p_vf = p_hwfn->vf_iov_info; 1423 1424 *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters; 1425 } 1426 1427 bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac) 1428 { 1429 struct qed_bulletin_content *bulletin; 1430 1431 bulletin = &p_hwfn->vf_iov_info->bulletin_shadow; 1432 if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED))) 1433 return true; 1434 1435 /* Forbid VF from changing a MAC enforced by PF */ 1436 if (ether_addr_equal(bulletin->mac, mac)) 1437 return false; 1438 1439 return false; 1440 } 1441 1442 static bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn, 1443 u8 *dst_mac, u8 *p_is_forced) 1444 { 1445 struct qed_bulletin_content *bulletin; 1446 1447 bulletin = &hwfn->vf_iov_info->bulletin_shadow; 1448 1449 if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) { 1450 if (p_is_forced) 1451 *p_is_forced = 1; 1452 } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) { 1453 if (p_is_forced) 1454 *p_is_forced = 0; 1455 } else { 1456 return false; 1457 } 1458 1459 ether_addr_copy(dst_mac, bulletin->mac); 1460 1461 return true; 1462 } 1463 1464 static void 1465 qed_vf_bulletin_get_udp_ports(struct qed_hwfn *p_hwfn, 1466 u16 *p_vxlan_port, u16 *p_geneve_port) 1467 { 1468 struct qed_bulletin_content *p_bulletin; 1469 1470 p_bulletin = &p_hwfn->vf_iov_info->bulletin_shadow; 1471 1472 *p_vxlan_port = p_bulletin->vxlan_udp_port; 1473 *p_geneve_port = p_bulletin->geneve_udp_port; 1474 } 1475 1476 void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn, 1477 u16 *fw_major, u16 *fw_minor, 1478 u16 *fw_rev, u16 *fw_eng) 1479 { 1480 struct pf_vf_pfdev_info *info; 1481 1482 info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info; 1483 1484 *fw_major = info->fw_major; 1485 *fw_minor = info->fw_minor; 1486 *fw_rev = info->fw_rev; 1487 *fw_eng = info->fw_eng; 1488 } 1489 1490 static void qed_handle_bulletin_change(struct qed_hwfn *hwfn) 1491 { 1492 struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth; 1493 u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced; 1494 void *cookie = hwfn->cdev->ops_cookie; 1495 u16 vxlan_port, geneve_port; 1496 1497 qed_vf_bulletin_get_udp_ports(hwfn, &vxlan_port, &geneve_port); 1498 is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac, 1499 &is_mac_forced); 1500 if (is_mac_exist && cookie) 1501 ops->force_mac(cookie, mac, !!is_mac_forced); 1502 1503 ops->ports_update(cookie, vxlan_port, geneve_port); 1504 1505 /* Always update link configuration according to bulletin */ 1506 qed_link_update(hwfn); 1507 } 1508 1509 void qed_iov_vf_task(struct work_struct *work) 1510 { 1511 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn, 1512 iov_task.work); 1513 u8 change = 0; 1514 1515 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags)) 1516 return; 1517 1518 /* Handle bulletin board changes */ 1519 qed_vf_read_bulletin(hwfn, &change); 1520 if (test_and_clear_bit(QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG, 1521 &hwfn->iov_task_flags)) 1522 change = 1; 1523 if (change) 1524 qed_handle_bulletin_change(hwfn); 1525 1526 /* As VF is polling bulletin board, need to constantly re-schedule */ 1527 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ); 1528 } 1529