Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
| 2 | * Copyright (c) 2015 QLogic Corporation |
| 3 | * |
| 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 |
| 6 | * this source tree. |
| 7 | */ |
| 8 | |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 9 | #include <linux/crc32.h> |
Yuval Mintz | eff1696 | 2016-05-11 16:36:21 +0300 | [diff] [blame] | 10 | #include <linux/etherdevice.h> |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 11 | #include "qed.h" |
| 12 | #include "qed_sriov.h" |
| 13 | #include "qed_vf.h" |
| 14 | |
| 15 | static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length) |
| 16 | { |
| 17 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 18 | void *p_tlv; |
| 19 | |
| 20 | /* This lock is released when we receive PF's response |
| 21 | * in qed_send_msg2pf(). |
| 22 | * So, qed_vf_pf_prep() and qed_send_msg2pf() |
| 23 | * must come in sequence. |
| 24 | */ |
| 25 | mutex_lock(&(p_iov->mutex)); |
| 26 | |
| 27 | DP_VERBOSE(p_hwfn, |
| 28 | QED_MSG_IOV, |
| 29 | "preparing to send 0x%04x tlv over vf pf channel\n", |
| 30 | type); |
| 31 | |
| 32 | /* Reset Requst offset */ |
| 33 | p_iov->offset = (u8 *)p_iov->vf2pf_request; |
| 34 | |
| 35 | /* Clear mailbox - both request and reply */ |
| 36 | memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs)); |
| 37 | memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs)); |
| 38 | |
| 39 | /* Init type and length */ |
| 40 | p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length); |
| 41 | |
| 42 | /* Init first tlv header */ |
| 43 | ((struct vfpf_first_tlv *)p_tlv)->reply_address = |
| 44 | (u64)p_iov->pf2vf_reply_phys; |
| 45 | |
| 46 | return p_tlv; |
| 47 | } |
| 48 | |
| 49 | static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size) |
| 50 | { |
| 51 | union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request; |
| 52 | struct ustorm_trigger_vf_zone trigger; |
| 53 | struct ustorm_vf_zone *zone_data; |
| 54 | int rc = 0, time = 100; |
| 55 | |
| 56 | zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B; |
| 57 | |
| 58 | /* output tlvs list */ |
| 59 | qed_dp_tlv_list(p_hwfn, p_req); |
| 60 | |
| 61 | /* need to add the END TLV to the message size */ |
| 62 | resp_size += sizeof(struct channel_list_end_tlv); |
| 63 | |
| 64 | /* Send TLVs over HW channel */ |
| 65 | memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone)); |
| 66 | trigger.vf_pf_msg_valid = 1; |
| 67 | |
| 68 | DP_VERBOSE(p_hwfn, |
| 69 | QED_MSG_IOV, |
| 70 | "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n", |
| 71 | GET_FIELD(p_hwfn->hw_info.concrete_fid, |
| 72 | PXP_CONCRETE_FID_PFID), |
| 73 | upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys), |
| 74 | lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys), |
| 75 | &zone_data->non_trigger.vf_pf_msg_addr, |
| 76 | *((u32 *)&trigger), &zone_data->trigger); |
| 77 | |
| 78 | REG_WR(p_hwfn, |
| 79 | (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo, |
| 80 | lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys)); |
| 81 | |
| 82 | REG_WR(p_hwfn, |
| 83 | (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi, |
| 84 | upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys)); |
| 85 | |
| 86 | /* The message data must be written first, to prevent trigger before |
| 87 | * data is written. |
| 88 | */ |
| 89 | wmb(); |
| 90 | |
| 91 | REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger)); |
| 92 | |
| 93 | /* When PF would be done with the response, it would write back to the |
| 94 | * `done' address. Poll until then. |
| 95 | */ |
| 96 | while ((!*done) && time) { |
| 97 | msleep(25); |
| 98 | time--; |
| 99 | } |
| 100 | |
| 101 | if (!*done) { |
| 102 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 103 | "VF <-- PF Timeout [Type %d]\n", |
| 104 | p_req->first_tlv.tl.type); |
| 105 | rc = -EBUSY; |
| 106 | goto exit; |
| 107 | } else { |
| 108 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 109 | "PF response: %d [Type %d]\n", |
| 110 | *done, p_req->first_tlv.tl.type); |
| 111 | } |
| 112 | |
| 113 | exit: |
| 114 | mutex_unlock(&(p_hwfn->vf_iov_info->mutex)); |
| 115 | |
| 116 | return rc; |
| 117 | } |
| 118 | |
| 119 | #define VF_ACQUIRE_THRESH 3 |
Yuval Mintz | 1cf2b1a | 2016-06-05 13:11:12 +0300 | [diff] [blame] | 120 | static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn, |
| 121 | struct vf_pf_resc_request *p_req, |
| 122 | struct pf_vf_resc *p_resp) |
| 123 | { |
| 124 | DP_VERBOSE(p_hwfn, |
| 125 | QED_MSG_IOV, |
| 126 | "PF unwilling to fullill resource request: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x]. Try PF recommended amount\n", |
| 127 | p_req->num_rxqs, |
| 128 | p_resp->num_rxqs, |
| 129 | p_req->num_rxqs, |
| 130 | p_resp->num_txqs, |
| 131 | p_req->num_sbs, |
| 132 | p_resp->num_sbs, |
| 133 | p_req->num_mac_filters, |
| 134 | p_resp->num_mac_filters, |
| 135 | p_req->num_vlan_filters, |
| 136 | p_resp->num_vlan_filters, |
| 137 | p_req->num_mc_filters, p_resp->num_mc_filters); |
| 138 | |
| 139 | /* humble our request */ |
| 140 | p_req->num_txqs = p_resp->num_txqs; |
| 141 | p_req->num_rxqs = p_resp->num_rxqs; |
| 142 | p_req->num_sbs = p_resp->num_sbs; |
| 143 | p_req->num_mac_filters = p_resp->num_mac_filters; |
| 144 | p_req->num_vlan_filters = p_resp->num_vlan_filters; |
| 145 | p_req->num_mc_filters = p_resp->num_mc_filters; |
| 146 | } |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 147 | |
| 148 | static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn) |
| 149 | { |
| 150 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 151 | struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp; |
| 152 | struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info; |
Yuval Mintz | 1cf2b1a | 2016-06-05 13:11:12 +0300 | [diff] [blame] | 153 | struct vf_pf_resc_request *p_resc; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 154 | bool resources_acquired = false; |
| 155 | struct vfpf_acquire_tlv *req; |
| 156 | int rc = 0, attempts = 0; |
| 157 | |
| 158 | /* clear mailbox and prep first tlv */ |
| 159 | req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req)); |
Yuval Mintz | 1cf2b1a | 2016-06-05 13:11:12 +0300 | [diff] [blame] | 160 | p_resc = &req->resc_request; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 161 | |
| 162 | /* starting filling the request */ |
| 163 | req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 164 | |
Yuval Mintz | 1cf2b1a | 2016-06-05 13:11:12 +0300 | [diff] [blame] | 165 | p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF; |
| 166 | p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF; |
| 167 | p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF; |
| 168 | p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS; |
| 169 | p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 170 | |
| 171 | req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX; |
| 172 | req->vfdev_info.fw_major = FW_MAJOR_VERSION; |
| 173 | req->vfdev_info.fw_minor = FW_MINOR_VERSION; |
| 174 | req->vfdev_info.fw_revision = FW_REVISION_VERSION; |
| 175 | req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION; |
Yuval Mintz | 1fe614d | 2016-06-05 13:11:11 +0300 | [diff] [blame] | 176 | req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR; |
| 177 | req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 178 | |
| 179 | /* Fill capability field with any non-deprecated config we support */ |
| 180 | req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G; |
| 181 | |
| 182 | /* pf 2 vf bulletin board address */ |
| 183 | req->bulletin_addr = p_iov->bulletin.phys; |
| 184 | req->bulletin_size = p_iov->bulletin.size; |
| 185 | |
| 186 | /* add list termination tlv */ |
| 187 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 188 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 189 | |
| 190 | while (!resources_acquired) { |
| 191 | DP_VERBOSE(p_hwfn, |
| 192 | QED_MSG_IOV, "attempting to acquire resources\n"); |
| 193 | |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 194 | /* Clear response buffer, as this might be a re-send */ |
| 195 | memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs)); |
| 196 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 197 | /* send acquire request */ |
| 198 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 199 | if (rc) |
| 200 | return rc; |
| 201 | |
| 202 | /* copy acquire response from buffer to p_hwfn */ |
| 203 | memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp)); |
| 204 | |
| 205 | attempts++; |
| 206 | |
| 207 | if (resp->hdr.status == PFVF_STATUS_SUCCESS) { |
| 208 | /* PF agrees to allocate our resources */ |
| 209 | if (!(resp->pfdev_info.capabilities & |
| 210 | PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) { |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 211 | /* It's possible legacy PF mistakenly accepted; |
| 212 | * but we don't care - simply mark it as |
| 213 | * legacy and continue. |
| 214 | */ |
| 215 | req->vfdev_info.capabilities |= |
| 216 | VFPF_ACQUIRE_CAP_PRE_FP_HSI; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 217 | } |
| 218 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n"); |
| 219 | resources_acquired = true; |
| 220 | } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE && |
| 221 | attempts < VF_ACQUIRE_THRESH) { |
Yuval Mintz | 1cf2b1a | 2016-06-05 13:11:12 +0300 | [diff] [blame] | 222 | qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc, |
| 223 | &resp->resc); |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 224 | } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) { |
| 225 | if (pfdev_info->major_fp_hsi && |
| 226 | (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) { |
| 227 | DP_NOTICE(p_hwfn, |
| 228 | "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n", |
| 229 | pfdev_info->major_fp_hsi, |
| 230 | pfdev_info->minor_fp_hsi, |
| 231 | ETH_HSI_VER_MAJOR, |
| 232 | ETH_HSI_VER_MINOR, |
| 233 | pfdev_info->major_fp_hsi); |
| 234 | rc = -EINVAL; |
| 235 | goto exit; |
| 236 | } |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 237 | |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 238 | if (!pfdev_info->major_fp_hsi) { |
| 239 | if (req->vfdev_info.capabilities & |
| 240 | VFPF_ACQUIRE_CAP_PRE_FP_HSI) { |
| 241 | DP_NOTICE(p_hwfn, |
| 242 | "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n"); |
| 243 | rc = -EINVAL; |
| 244 | goto exit; |
| 245 | } else { |
| 246 | DP_INFO(p_hwfn, |
| 247 | "PF is old - try re-acquire to see if it supports FW-version override\n"); |
| 248 | req->vfdev_info.capabilities |= |
| 249 | VFPF_ACQUIRE_CAP_PRE_FP_HSI; |
| 250 | continue; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /* If PF/VF are using same Major, PF must have had |
| 255 | * it's reasons. Simply fail. |
| 256 | */ |
| 257 | DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n"); |
| 258 | rc = -EINVAL; |
| 259 | goto exit; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 260 | } else { |
| 261 | DP_ERR(p_hwfn, |
| 262 | "PF returned error %d to VF acquisition request\n", |
| 263 | resp->hdr.status); |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 264 | rc = -EAGAIN; |
| 265 | goto exit; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 269 | /* Mark the PF as legacy, if needed */ |
| 270 | if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI) |
| 271 | p_iov->b_pre_fp_hsi = true; |
| 272 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 273 | /* Update bulletin board size with response from PF */ |
| 274 | p_iov->bulletin.size = resp->bulletin_size; |
| 275 | |
| 276 | /* get HW info */ |
| 277 | p_hwfn->cdev->type = resp->pfdev_info.dev_type; |
| 278 | p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev; |
| 279 | |
| 280 | p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff; |
| 281 | |
| 282 | /* Learn of the possibility of CMT */ |
| 283 | if (IS_LEAD_HWFN(p_hwfn)) { |
| 284 | if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) { |
| 285 | DP_NOTICE(p_hwfn, "100g VF\n"); |
| 286 | p_hwfn->cdev->num_hwfns = 2; |
| 287 | } |
| 288 | } |
| 289 | |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 290 | if (!p_iov->b_pre_fp_hsi && |
| 291 | ETH_HSI_VER_MINOR && |
Yuval Mintz | 1fe614d | 2016-06-05 13:11:11 +0300 | [diff] [blame] | 292 | (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) { |
| 293 | DP_INFO(p_hwfn, |
| 294 | "PF is using older fastpath HSI; %02x.%02x is configured\n", |
| 295 | ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi); |
| 296 | } |
| 297 | |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 298 | exit: |
| 299 | return rc; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn) |
| 303 | { |
| 304 | struct qed_vf_iov *p_iov; |
| 305 | u32 reg; |
| 306 | |
| 307 | /* Set number of hwfns - might be overriden once leading hwfn learns |
| 308 | * actual configuration from PF. |
| 309 | */ |
| 310 | if (IS_LEAD_HWFN(p_hwfn)) |
| 311 | p_hwfn->cdev->num_hwfns = 1; |
| 312 | |
| 313 | /* Set the doorbell bar. Assumption: regview is set */ |
| 314 | p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview + |
| 315 | PXP_VF_BAR0_START_DQ; |
| 316 | |
| 317 | reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS; |
| 318 | p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg); |
| 319 | |
| 320 | reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS; |
| 321 | p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg); |
| 322 | |
| 323 | /* Allocate vf sriov info */ |
| 324 | p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL); |
| 325 | if (!p_iov) { |
| 326 | DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sriov'\n"); |
| 327 | return -ENOMEM; |
| 328 | } |
| 329 | |
| 330 | /* Allocate vf2pf msg */ |
| 331 | p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 332 | sizeof(union vfpf_tlvs), |
| 333 | &p_iov->vf2pf_request_phys, |
| 334 | GFP_KERNEL); |
| 335 | if (!p_iov->vf2pf_request) { |
| 336 | DP_NOTICE(p_hwfn, |
| 337 | "Failed to allocate `vf2pf_request' DMA memory\n"); |
| 338 | goto free_p_iov; |
| 339 | } |
| 340 | |
| 341 | p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 342 | sizeof(union pfvf_tlvs), |
| 343 | &p_iov->pf2vf_reply_phys, |
| 344 | GFP_KERNEL); |
| 345 | if (!p_iov->pf2vf_reply) { |
| 346 | DP_NOTICE(p_hwfn, |
| 347 | "Failed to allocate `pf2vf_reply' DMA memory\n"); |
| 348 | goto free_vf2pf_request; |
| 349 | } |
| 350 | |
| 351 | DP_VERBOSE(p_hwfn, |
| 352 | QED_MSG_IOV, |
| 353 | "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n", |
| 354 | p_iov->vf2pf_request, |
| 355 | (u64) p_iov->vf2pf_request_phys, |
| 356 | p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys); |
| 357 | |
| 358 | /* Allocate Bulletin board */ |
| 359 | p_iov->bulletin.size = sizeof(struct qed_bulletin_content); |
| 360 | p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 361 | p_iov->bulletin.size, |
| 362 | &p_iov->bulletin.phys, |
| 363 | GFP_KERNEL); |
| 364 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 365 | "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n", |
| 366 | p_iov->bulletin.p_virt, |
| 367 | (u64)p_iov->bulletin.phys, p_iov->bulletin.size); |
| 368 | |
| 369 | mutex_init(&p_iov->mutex); |
| 370 | |
| 371 | p_hwfn->vf_iov_info = p_iov; |
| 372 | |
| 373 | p_hwfn->hw_info.personality = QED_PCI_ETH; |
| 374 | |
| 375 | return qed_vf_pf_acquire(p_hwfn); |
| 376 | |
| 377 | free_vf2pf_request: |
| 378 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 379 | sizeof(union vfpf_tlvs), |
| 380 | p_iov->vf2pf_request, p_iov->vf2pf_request_phys); |
| 381 | free_p_iov: |
| 382 | kfree(p_iov); |
| 383 | |
| 384 | return -ENOMEM; |
| 385 | } |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 386 | #define TSTORM_QZONE_START PXP_VF_BAR0_START_SDM_ZONE_A |
| 387 | #define MSTORM_QZONE_START(dev) (TSTORM_QZONE_START + \ |
| 388 | (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev))) |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 389 | |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 390 | int qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn, |
| 391 | u8 rx_qid, |
| 392 | u16 sb, |
| 393 | u8 sb_index, |
| 394 | u16 bd_max_bytes, |
| 395 | dma_addr_t bd_chain_phys_addr, |
| 396 | dma_addr_t cqe_pbl_addr, |
| 397 | u16 cqe_pbl_size, void __iomem **pp_prod) |
| 398 | { |
| 399 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 400 | struct pfvf_start_queue_resp_tlv *resp; |
| 401 | struct vfpf_start_rxq_tlv *req; |
| 402 | int rc; |
| 403 | |
| 404 | /* clear mailbox and prep first tlv */ |
| 405 | req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req)); |
| 406 | |
| 407 | req->rx_qid = rx_qid; |
| 408 | req->cqe_pbl_addr = cqe_pbl_addr; |
| 409 | req->cqe_pbl_size = cqe_pbl_size; |
| 410 | req->rxq_addr = bd_chain_phys_addr; |
| 411 | req->hw_sb = sb; |
| 412 | req->sb_index = sb_index; |
| 413 | req->bd_max_bytes = bd_max_bytes; |
| 414 | req->stat_id = -1; |
| 415 | |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 416 | /* If PF is legacy, we'll need to calculate producers ourselves |
| 417 | * as well as clean them. |
| 418 | */ |
| 419 | if (pp_prod && p_iov->b_pre_fp_hsi) { |
| 420 | u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid]; |
| 421 | u32 init_prod_val = 0; |
| 422 | |
| 423 | *pp_prod = (u8 __iomem *)p_hwfn->regview + |
| 424 | MSTORM_QZONE_START(p_hwfn->cdev) + |
| 425 | hw_qid * MSTORM_QZONE_SIZE; |
| 426 | |
| 427 | /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */ |
| 428 | __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32), |
| 429 | (u32 *)(&init_prod_val)); |
| 430 | } |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 431 | /* add list termination tlv */ |
| 432 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 433 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 434 | |
| 435 | resp = &p_iov->pf2vf_reply->queue_start; |
| 436 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 437 | if (rc) |
| 438 | return rc; |
| 439 | |
| 440 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 441 | return -EINVAL; |
| 442 | |
| 443 | /* Learn the address of the producer from the response */ |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 444 | if (pp_prod && !p_iov->b_pre_fp_hsi) { |
Yuval Mintz | b21290b | 2016-07-27 14:45:21 +0300 | [diff] [blame] | 445 | u32 init_prod_val = 0; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 446 | |
| 447 | *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset; |
| 448 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 449 | "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n", |
| 450 | rx_qid, *pp_prod, resp->offset); |
| 451 | |
| 452 | /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */ |
Yuval Mintz | b21290b | 2016-07-27 14:45:21 +0300 | [diff] [blame] | 453 | __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32), |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 454 | (u32 *)&init_prod_val); |
| 455 | } |
| 456 | |
| 457 | return rc; |
| 458 | } |
| 459 | |
| 460 | int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn, u16 rx_qid, bool cqe_completion) |
| 461 | { |
| 462 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 463 | struct vfpf_stop_rxqs_tlv *req; |
| 464 | struct pfvf_def_resp_tlv *resp; |
| 465 | int rc; |
| 466 | |
| 467 | /* clear mailbox and prep first tlv */ |
| 468 | req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req)); |
| 469 | |
| 470 | req->rx_qid = rx_qid; |
| 471 | req->num_rxqs = 1; |
| 472 | req->cqe_completion = cqe_completion; |
| 473 | |
| 474 | /* add list termination tlv */ |
| 475 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 476 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 477 | |
| 478 | resp = &p_iov->pf2vf_reply->default_resp; |
| 479 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 480 | if (rc) |
| 481 | return rc; |
| 482 | |
| 483 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 484 | return -EINVAL; |
| 485 | |
| 486 | return rc; |
| 487 | } |
| 488 | |
| 489 | int qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn, |
| 490 | u16 tx_queue_id, |
| 491 | u16 sb, |
| 492 | u8 sb_index, |
| 493 | dma_addr_t pbl_addr, |
| 494 | u16 pbl_size, void __iomem **pp_doorbell) |
| 495 | { |
| 496 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
Yuval Mintz | 5040acf | 2016-06-05 13:11:14 +0300 | [diff] [blame] | 497 | struct pfvf_start_queue_resp_tlv *resp; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 498 | struct vfpf_start_txq_tlv *req; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 499 | int rc; |
| 500 | |
| 501 | /* clear mailbox and prep first tlv */ |
| 502 | req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req)); |
| 503 | |
| 504 | req->tx_qid = tx_queue_id; |
| 505 | |
| 506 | /* Tx */ |
| 507 | req->pbl_addr = pbl_addr; |
| 508 | req->pbl_size = pbl_size; |
| 509 | req->hw_sb = sb; |
| 510 | req->sb_index = sb_index; |
| 511 | |
| 512 | /* add list termination tlv */ |
| 513 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 514 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 515 | |
Yuval Mintz | 5040acf | 2016-06-05 13:11:14 +0300 | [diff] [blame] | 516 | resp = &p_iov->pf2vf_reply->queue_start; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 517 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 518 | if (rc) |
Yuval Mintz | 5040acf | 2016-06-05 13:11:14 +0300 | [diff] [blame] | 519 | goto exit; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 520 | |
Yuval Mintz | 5040acf | 2016-06-05 13:11:14 +0300 | [diff] [blame] | 521 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { |
| 522 | rc = -EINVAL; |
| 523 | goto exit; |
| 524 | } |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 525 | |
| 526 | if (pp_doorbell) { |
Yuval Mintz | d8c2c7e | 2016-08-22 13:25:11 +0300 | [diff] [blame^] | 527 | /* Modern PFs provide the actual offsets, while legacy |
| 528 | * provided only the queue id. |
| 529 | */ |
| 530 | if (!p_iov->b_pre_fp_hsi) { |
| 531 | *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + |
| 532 | resp->offset; |
| 533 | } else { |
| 534 | u8 cid = p_iov->acquire_resp.resc.cid[tx_queue_id]; |
| 535 | u32 db_addr; |
| 536 | |
| 537 | db_addr = qed_db_addr(cid, DQ_DEMS_LEGACY); |
| 538 | *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + |
| 539 | db_addr; |
| 540 | } |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 541 | |
Yuval Mintz | 5040acf | 2016-06-05 13:11:14 +0300 | [diff] [blame] | 542 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 543 | "Txq[0x%02x]: doorbell at %p [offset 0x%08x]\n", |
| 544 | tx_queue_id, *pp_doorbell, resp->offset); |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 545 | } |
Yuval Mintz | 5040acf | 2016-06-05 13:11:14 +0300 | [diff] [blame] | 546 | exit: |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 547 | |
| 548 | return rc; |
| 549 | } |
| 550 | |
| 551 | int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, u16 tx_qid) |
| 552 | { |
| 553 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 554 | struct vfpf_stop_txqs_tlv *req; |
| 555 | struct pfvf_def_resp_tlv *resp; |
| 556 | int rc; |
| 557 | |
| 558 | /* clear mailbox and prep first tlv */ |
| 559 | req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req)); |
| 560 | |
| 561 | req->tx_qid = tx_qid; |
| 562 | req->num_txqs = 1; |
| 563 | |
| 564 | /* add list termination tlv */ |
| 565 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 566 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 567 | |
| 568 | resp = &p_iov->pf2vf_reply->default_resp; |
| 569 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 570 | if (rc) |
| 571 | return rc; |
| 572 | |
| 573 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 574 | return -EINVAL; |
| 575 | |
| 576 | return rc; |
| 577 | } |
| 578 | |
| 579 | int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn, |
| 580 | u8 vport_id, |
| 581 | u16 mtu, |
| 582 | u8 inner_vlan_removal, |
| 583 | enum qed_tpa_mode tpa_mode, |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 584 | u8 max_buffers_per_cqe, u8 only_untagged) |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 585 | { |
| 586 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 587 | struct vfpf_vport_start_tlv *req; |
| 588 | struct pfvf_def_resp_tlv *resp; |
| 589 | int rc, i; |
| 590 | |
| 591 | /* clear mailbox and prep first tlv */ |
| 592 | req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req)); |
| 593 | |
| 594 | req->mtu = mtu; |
| 595 | req->vport_id = vport_id; |
| 596 | req->inner_vlan_removal = inner_vlan_removal; |
| 597 | req->tpa_mode = tpa_mode; |
| 598 | req->max_buffers_per_cqe = max_buffers_per_cqe; |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 599 | req->only_untagged = only_untagged; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 600 | |
| 601 | /* status blocks */ |
| 602 | for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++) |
| 603 | if (p_hwfn->sbs_info[i]) |
| 604 | req->sb_addr[i] = p_hwfn->sbs_info[i]->sb_phys; |
| 605 | |
| 606 | /* add list termination tlv */ |
| 607 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 608 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 609 | |
| 610 | resp = &p_iov->pf2vf_reply->default_resp; |
| 611 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 612 | if (rc) |
| 613 | return rc; |
| 614 | |
| 615 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 616 | return -EINVAL; |
| 617 | |
| 618 | return rc; |
| 619 | } |
| 620 | |
| 621 | int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn) |
| 622 | { |
| 623 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 624 | struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp; |
| 625 | int rc; |
| 626 | |
| 627 | /* clear mailbox and prep first tlv */ |
| 628 | qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN, |
| 629 | sizeof(struct vfpf_first_tlv)); |
| 630 | |
| 631 | /* add list termination tlv */ |
| 632 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 633 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 634 | |
| 635 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 636 | if (rc) |
| 637 | return rc; |
| 638 | |
| 639 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 640 | return -EINVAL; |
| 641 | |
| 642 | return rc; |
| 643 | } |
| 644 | |
| 645 | static bool |
| 646 | qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn, |
| 647 | struct qed_sp_vport_update_params *p_data, |
| 648 | u16 tlv) |
| 649 | { |
| 650 | switch (tlv) { |
| 651 | case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE: |
| 652 | return !!(p_data->update_vport_active_rx_flg || |
| 653 | p_data->update_vport_active_tx_flg); |
Yuval Mintz | 17b235c | 2016-05-11 16:36:18 +0300 | [diff] [blame] | 654 | case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH: |
| 655 | return !!p_data->update_tx_switching_flg; |
| 656 | case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP: |
| 657 | return !!p_data->update_inner_vlan_removal_flg; |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 658 | case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN: |
| 659 | return !!p_data->update_accept_any_vlan_flg; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 660 | case CHANNEL_TLV_VPORT_UPDATE_MCAST: |
| 661 | return !!p_data->update_approx_mcast_flg; |
| 662 | case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM: |
| 663 | return !!(p_data->accept_flags.update_rx_mode_config || |
| 664 | p_data->accept_flags.update_tx_mode_config); |
| 665 | case CHANNEL_TLV_VPORT_UPDATE_RSS: |
| 666 | return !!p_data->rss_params; |
Yuval Mintz | 17b235c | 2016-05-11 16:36:18 +0300 | [diff] [blame] | 667 | case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA: |
| 668 | return !!p_data->sge_tpa_params; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 669 | default: |
| 670 | DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n", |
| 671 | tlv); |
| 672 | return false; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | static void |
| 677 | qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn, |
| 678 | struct qed_sp_vport_update_params *p_data) |
| 679 | { |
| 680 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 681 | struct pfvf_def_resp_tlv *p_resp; |
| 682 | u16 tlv; |
| 683 | |
| 684 | for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE; |
| 685 | tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) { |
| 686 | if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv)) |
| 687 | continue; |
| 688 | |
| 689 | p_resp = (struct pfvf_def_resp_tlv *) |
| 690 | qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply, |
| 691 | tlv); |
| 692 | if (p_resp && p_resp->hdr.status) |
| 693 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 694 | "TLV[%d] Configuration %s\n", |
| 695 | tlv, |
| 696 | (p_resp && p_resp->hdr.status) ? "succeeded" |
| 697 | : "failed"); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn, |
| 702 | struct qed_sp_vport_update_params *p_params) |
| 703 | { |
| 704 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 705 | struct vfpf_vport_update_tlv *req; |
| 706 | struct pfvf_def_resp_tlv *resp; |
| 707 | u8 update_rx, update_tx; |
| 708 | u32 resp_size = 0; |
| 709 | u16 size, tlv; |
| 710 | int rc; |
| 711 | |
| 712 | resp = &p_iov->pf2vf_reply->default_resp; |
| 713 | resp_size = sizeof(*resp); |
| 714 | |
| 715 | update_rx = p_params->update_vport_active_rx_flg; |
| 716 | update_tx = p_params->update_vport_active_tx_flg; |
| 717 | |
| 718 | /* clear mailbox and prep header tlv */ |
| 719 | qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req)); |
| 720 | |
| 721 | /* Prepare extended tlvs */ |
| 722 | if (update_rx || update_tx) { |
| 723 | struct vfpf_vport_update_activate_tlv *p_act_tlv; |
| 724 | |
| 725 | size = sizeof(struct vfpf_vport_update_activate_tlv); |
| 726 | p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, |
| 727 | CHANNEL_TLV_VPORT_UPDATE_ACTIVATE, |
| 728 | size); |
| 729 | resp_size += sizeof(struct pfvf_def_resp_tlv); |
| 730 | |
| 731 | if (update_rx) { |
| 732 | p_act_tlv->update_rx = update_rx; |
| 733 | p_act_tlv->active_rx = p_params->vport_active_rx_flg; |
| 734 | } |
| 735 | |
| 736 | if (update_tx) { |
| 737 | p_act_tlv->update_tx = update_tx; |
| 738 | p_act_tlv->active_tx = p_params->vport_active_tx_flg; |
| 739 | } |
| 740 | } |
| 741 | |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 742 | if (p_params->update_tx_switching_flg) { |
| 743 | struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv; |
| 744 | |
| 745 | size = sizeof(struct vfpf_vport_update_tx_switch_tlv); |
| 746 | tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH; |
| 747 | p_tx_switch_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, |
| 748 | tlv, size); |
| 749 | resp_size += sizeof(struct pfvf_def_resp_tlv); |
| 750 | |
| 751 | p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg; |
| 752 | } |
| 753 | |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 754 | if (p_params->update_approx_mcast_flg) { |
| 755 | struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv; |
| 756 | |
| 757 | size = sizeof(struct vfpf_vport_update_mcast_bin_tlv); |
| 758 | p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, |
| 759 | CHANNEL_TLV_VPORT_UPDATE_MCAST, size); |
| 760 | resp_size += sizeof(struct pfvf_def_resp_tlv); |
| 761 | |
| 762 | memcpy(p_mcast_tlv->bins, p_params->bins, |
| 763 | sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS); |
| 764 | } |
| 765 | |
| 766 | update_rx = p_params->accept_flags.update_rx_mode_config; |
| 767 | update_tx = p_params->accept_flags.update_tx_mode_config; |
| 768 | |
| 769 | if (update_rx || update_tx) { |
| 770 | struct vfpf_vport_update_accept_param_tlv *p_accept_tlv; |
| 771 | |
| 772 | tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM; |
| 773 | size = sizeof(struct vfpf_vport_update_accept_param_tlv); |
| 774 | p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size); |
| 775 | resp_size += sizeof(struct pfvf_def_resp_tlv); |
| 776 | |
| 777 | if (update_rx) { |
| 778 | p_accept_tlv->update_rx_mode = update_rx; |
| 779 | p_accept_tlv->rx_accept_filter = |
| 780 | p_params->accept_flags.rx_accept_filter; |
| 781 | } |
| 782 | |
| 783 | if (update_tx) { |
| 784 | p_accept_tlv->update_tx_mode = update_tx; |
| 785 | p_accept_tlv->tx_accept_filter = |
| 786 | p_params->accept_flags.tx_accept_filter; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | if (p_params->rss_params) { |
| 791 | struct qed_rss_params *rss_params = p_params->rss_params; |
| 792 | struct vfpf_vport_update_rss_tlv *p_rss_tlv; |
| 793 | |
| 794 | size = sizeof(struct vfpf_vport_update_rss_tlv); |
| 795 | p_rss_tlv = qed_add_tlv(p_hwfn, |
| 796 | &p_iov->offset, |
| 797 | CHANNEL_TLV_VPORT_UPDATE_RSS, size); |
| 798 | resp_size += sizeof(struct pfvf_def_resp_tlv); |
| 799 | |
| 800 | if (rss_params->update_rss_config) |
| 801 | p_rss_tlv->update_rss_flags |= |
| 802 | VFPF_UPDATE_RSS_CONFIG_FLAG; |
| 803 | if (rss_params->update_rss_capabilities) |
| 804 | p_rss_tlv->update_rss_flags |= |
| 805 | VFPF_UPDATE_RSS_CAPS_FLAG; |
| 806 | if (rss_params->update_rss_ind_table) |
| 807 | p_rss_tlv->update_rss_flags |= |
| 808 | VFPF_UPDATE_RSS_IND_TABLE_FLAG; |
| 809 | if (rss_params->update_rss_key) |
| 810 | p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG; |
| 811 | |
| 812 | p_rss_tlv->rss_enable = rss_params->rss_enable; |
| 813 | p_rss_tlv->rss_caps = rss_params->rss_caps; |
| 814 | p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log; |
| 815 | memcpy(p_rss_tlv->rss_ind_table, rss_params->rss_ind_table, |
| 816 | sizeof(rss_params->rss_ind_table)); |
| 817 | memcpy(p_rss_tlv->rss_key, rss_params->rss_key, |
| 818 | sizeof(rss_params->rss_key)); |
| 819 | } |
| 820 | |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 821 | if (p_params->update_accept_any_vlan_flg) { |
| 822 | struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv; |
| 823 | |
| 824 | size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv); |
| 825 | tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN; |
| 826 | p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size); |
| 827 | |
| 828 | resp_size += sizeof(struct pfvf_def_resp_tlv); |
| 829 | p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan; |
| 830 | p_any_vlan_tlv->update_accept_any_vlan_flg = |
| 831 | p_params->update_accept_any_vlan_flg; |
| 832 | } |
| 833 | |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 834 | /* add list termination tlv */ |
| 835 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 836 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 837 | |
| 838 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size); |
| 839 | if (rc) |
| 840 | return rc; |
| 841 | |
| 842 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 843 | return -EINVAL; |
| 844 | |
| 845 | qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params); |
| 846 | |
| 847 | return rc; |
| 848 | } |
| 849 | |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 850 | int qed_vf_pf_reset(struct qed_hwfn *p_hwfn) |
| 851 | { |
| 852 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 853 | struct pfvf_def_resp_tlv *resp; |
| 854 | struct vfpf_first_tlv *req; |
| 855 | int rc; |
| 856 | |
| 857 | /* clear mailbox and prep first tlv */ |
| 858 | req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req)); |
| 859 | |
| 860 | /* add list termination tlv */ |
| 861 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 862 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 863 | |
| 864 | resp = &p_iov->pf2vf_reply->default_resp; |
| 865 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 866 | if (rc) |
| 867 | return rc; |
| 868 | |
| 869 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 870 | return -EAGAIN; |
| 871 | |
| 872 | p_hwfn->b_int_enabled = 0; |
| 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | int qed_vf_pf_release(struct qed_hwfn *p_hwfn) |
| 878 | { |
| 879 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 880 | struct pfvf_def_resp_tlv *resp; |
| 881 | struct vfpf_first_tlv *req; |
| 882 | u32 size; |
| 883 | int rc; |
| 884 | |
| 885 | /* clear mailbox and prep first tlv */ |
| 886 | req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req)); |
| 887 | |
| 888 | /* add list termination tlv */ |
| 889 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 890 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 891 | |
| 892 | resp = &p_iov->pf2vf_reply->default_resp; |
| 893 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 894 | |
| 895 | if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 896 | rc = -EAGAIN; |
| 897 | |
| 898 | p_hwfn->b_int_enabled = 0; |
| 899 | |
| 900 | if (p_iov->vf2pf_request) |
| 901 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 902 | sizeof(union vfpf_tlvs), |
| 903 | p_iov->vf2pf_request, |
| 904 | p_iov->vf2pf_request_phys); |
| 905 | if (p_iov->pf2vf_reply) |
| 906 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 907 | sizeof(union pfvf_tlvs), |
| 908 | p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys); |
| 909 | |
| 910 | if (p_iov->bulletin.p_virt) { |
| 911 | size = sizeof(struct qed_bulletin_content); |
| 912 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 913 | size, |
| 914 | p_iov->bulletin.p_virt, p_iov->bulletin.phys); |
| 915 | } |
| 916 | |
| 917 | kfree(p_hwfn->vf_iov_info); |
| 918 | p_hwfn->vf_iov_info = NULL; |
| 919 | |
| 920 | return rc; |
| 921 | } |
| 922 | |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 923 | void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn, |
| 924 | struct qed_filter_mcast *p_filter_cmd) |
| 925 | { |
| 926 | struct qed_sp_vport_update_params sp_params; |
| 927 | int i; |
| 928 | |
| 929 | memset(&sp_params, 0, sizeof(sp_params)); |
| 930 | sp_params.update_approx_mcast_flg = 1; |
| 931 | |
| 932 | if (p_filter_cmd->opcode == QED_FILTER_ADD) { |
| 933 | for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) { |
| 934 | u32 bit; |
| 935 | |
| 936 | bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]); |
| 937 | __set_bit(bit, sp_params.bins); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | qed_vf_pf_vport_update(p_hwfn, &sp_params); |
| 942 | } |
| 943 | |
| 944 | int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn, |
| 945 | struct qed_filter_ucast *p_ucast) |
| 946 | { |
| 947 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 948 | struct vfpf_ucast_filter_tlv *req; |
| 949 | struct pfvf_def_resp_tlv *resp; |
| 950 | int rc; |
| 951 | |
| 952 | /* clear mailbox and prep first tlv */ |
| 953 | req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req)); |
| 954 | req->opcode = (u8) p_ucast->opcode; |
| 955 | req->type = (u8) p_ucast->type; |
| 956 | memcpy(req->mac, p_ucast->mac, ETH_ALEN); |
| 957 | req->vlan = p_ucast->vlan; |
| 958 | |
| 959 | /* add list termination tlv */ |
| 960 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 961 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 962 | |
| 963 | resp = &p_iov->pf2vf_reply->default_resp; |
| 964 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 965 | if (rc) |
| 966 | return rc; |
| 967 | |
| 968 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 969 | return -EAGAIN; |
| 970 | |
| 971 | return 0; |
| 972 | } |
| 973 | |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 974 | int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn) |
| 975 | { |
| 976 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 977 | struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp; |
| 978 | int rc; |
| 979 | |
| 980 | /* clear mailbox and prep first tlv */ |
| 981 | qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP, |
| 982 | sizeof(struct vfpf_first_tlv)); |
| 983 | |
| 984 | /* add list termination tlv */ |
| 985 | qed_add_tlv(p_hwfn, &p_iov->offset, |
| 986 | CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv)); |
| 987 | |
| 988 | rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp)); |
| 989 | if (rc) |
| 990 | return rc; |
| 991 | |
| 992 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 993 | return -EINVAL; |
| 994 | |
| 995 | return 0; |
| 996 | } |
| 997 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 998 | u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id) |
| 999 | { |
| 1000 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 1001 | |
| 1002 | if (!p_iov) { |
| 1003 | DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n"); |
| 1004 | return 0; |
| 1005 | } |
| 1006 | |
| 1007 | return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id; |
| 1008 | } |
| 1009 | |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 1010 | int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change) |
| 1011 | { |
| 1012 | struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info; |
| 1013 | struct qed_bulletin_content shadow; |
| 1014 | u32 crc, crc_size; |
| 1015 | |
| 1016 | crc_size = sizeof(p_iov->bulletin.p_virt->crc); |
| 1017 | *p_change = 0; |
| 1018 | |
| 1019 | /* Need to guarantee PF is not in the middle of writing it */ |
| 1020 | memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size); |
| 1021 | |
| 1022 | /* If version did not update, no need to do anything */ |
| 1023 | if (shadow.version == p_iov->bulletin_shadow.version) |
| 1024 | return 0; |
| 1025 | |
| 1026 | /* Verify the bulletin we see is valid */ |
| 1027 | crc = crc32(0, (u8 *)&shadow + crc_size, |
| 1028 | p_iov->bulletin.size - crc_size); |
| 1029 | if (crc != shadow.crc) |
| 1030 | return -EAGAIN; |
| 1031 | |
| 1032 | /* Set the shadow bulletin and process it */ |
| 1033 | memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size); |
| 1034 | |
| 1035 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 1036 | "Read a bulletin update %08x\n", shadow.version); |
| 1037 | |
| 1038 | *p_change = 1; |
| 1039 | |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn, |
| 1044 | struct qed_mcp_link_params *p_params, |
| 1045 | struct qed_bulletin_content *p_bulletin) |
| 1046 | { |
| 1047 | memset(p_params, 0, sizeof(*p_params)); |
| 1048 | |
| 1049 | p_params->speed.autoneg = p_bulletin->req_autoneg; |
| 1050 | p_params->speed.advertised_speeds = p_bulletin->req_adv_speed; |
| 1051 | p_params->speed.forced_speed = p_bulletin->req_forced_speed; |
| 1052 | p_params->pause.autoneg = p_bulletin->req_autoneg_pause; |
| 1053 | p_params->pause.forced_rx = p_bulletin->req_forced_rx; |
| 1054 | p_params->pause.forced_tx = p_bulletin->req_forced_tx; |
| 1055 | p_params->loopback_mode = p_bulletin->req_loopback; |
| 1056 | } |
| 1057 | |
| 1058 | void qed_vf_get_link_params(struct qed_hwfn *p_hwfn, |
| 1059 | struct qed_mcp_link_params *params) |
| 1060 | { |
| 1061 | __qed_vf_get_link_params(p_hwfn, params, |
| 1062 | &(p_hwfn->vf_iov_info->bulletin_shadow)); |
| 1063 | } |
| 1064 | |
| 1065 | void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn, |
| 1066 | struct qed_mcp_link_state *p_link, |
| 1067 | struct qed_bulletin_content *p_bulletin) |
| 1068 | { |
| 1069 | memset(p_link, 0, sizeof(*p_link)); |
| 1070 | |
| 1071 | p_link->link_up = p_bulletin->link_up; |
| 1072 | p_link->speed = p_bulletin->speed; |
| 1073 | p_link->full_duplex = p_bulletin->full_duplex; |
| 1074 | p_link->an = p_bulletin->autoneg; |
| 1075 | p_link->an_complete = p_bulletin->autoneg_complete; |
| 1076 | p_link->parallel_detection = p_bulletin->parallel_detection; |
| 1077 | p_link->pfc_enabled = p_bulletin->pfc_enabled; |
| 1078 | p_link->partner_adv_speed = p_bulletin->partner_adv_speed; |
| 1079 | p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en; |
| 1080 | p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en; |
| 1081 | p_link->partner_adv_pause = p_bulletin->partner_adv_pause; |
| 1082 | p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault; |
| 1083 | } |
| 1084 | |
| 1085 | void qed_vf_get_link_state(struct qed_hwfn *p_hwfn, |
| 1086 | struct qed_mcp_link_state *link) |
| 1087 | { |
| 1088 | __qed_vf_get_link_state(p_hwfn, link, |
| 1089 | &(p_hwfn->vf_iov_info->bulletin_shadow)); |
| 1090 | } |
| 1091 | |
| 1092 | void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn, |
| 1093 | struct qed_mcp_link_capabilities *p_link_caps, |
| 1094 | struct qed_bulletin_content *p_bulletin) |
| 1095 | { |
| 1096 | memset(p_link_caps, 0, sizeof(*p_link_caps)); |
| 1097 | p_link_caps->speed_capabilities = p_bulletin->capability_speed; |
| 1098 | } |
| 1099 | |
| 1100 | void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn, |
| 1101 | struct qed_mcp_link_capabilities *p_link_caps) |
| 1102 | { |
| 1103 | __qed_vf_get_link_caps(p_hwfn, p_link_caps, |
| 1104 | &(p_hwfn->vf_iov_info->bulletin_shadow)); |
| 1105 | } |
| 1106 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1107 | void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs) |
| 1108 | { |
| 1109 | *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs; |
| 1110 | } |
| 1111 | |
| 1112 | void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac) |
| 1113 | { |
| 1114 | memcpy(port_mac, |
| 1115 | p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN); |
| 1116 | } |
| 1117 | |
| 1118 | void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters) |
| 1119 | { |
| 1120 | struct qed_vf_iov *p_vf; |
| 1121 | |
| 1122 | p_vf = p_hwfn->vf_iov_info; |
| 1123 | *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters; |
| 1124 | } |
| 1125 | |
Yuval Mintz | eff1696 | 2016-05-11 16:36:21 +0300 | [diff] [blame] | 1126 | bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac) |
| 1127 | { |
| 1128 | struct qed_bulletin_content *bulletin; |
| 1129 | |
| 1130 | bulletin = &p_hwfn->vf_iov_info->bulletin_shadow; |
| 1131 | if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED))) |
| 1132 | return true; |
| 1133 | |
| 1134 | /* Forbid VF from changing a MAC enforced by PF */ |
| 1135 | if (ether_addr_equal(bulletin->mac, mac)) |
| 1136 | return false; |
| 1137 | |
| 1138 | return false; |
| 1139 | } |
| 1140 | |
| 1141 | bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn, |
| 1142 | u8 *dst_mac, u8 *p_is_forced) |
| 1143 | { |
| 1144 | struct qed_bulletin_content *bulletin; |
| 1145 | |
| 1146 | bulletin = &hwfn->vf_iov_info->bulletin_shadow; |
| 1147 | |
| 1148 | if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) { |
| 1149 | if (p_is_forced) |
| 1150 | *p_is_forced = 1; |
| 1151 | } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) { |
| 1152 | if (p_is_forced) |
| 1153 | *p_is_forced = 0; |
| 1154 | } else { |
| 1155 | return false; |
| 1156 | } |
| 1157 | |
| 1158 | ether_addr_copy(dst_mac, bulletin->mac); |
| 1159 | |
| 1160 | return true; |
| 1161 | } |
| 1162 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1163 | void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn, |
| 1164 | u16 *fw_major, u16 *fw_minor, |
| 1165 | u16 *fw_rev, u16 *fw_eng) |
| 1166 | { |
| 1167 | struct pf_vf_pfdev_info *info; |
| 1168 | |
| 1169 | info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info; |
| 1170 | |
| 1171 | *fw_major = info->fw_major; |
| 1172 | *fw_minor = info->fw_minor; |
| 1173 | *fw_rev = info->fw_rev; |
| 1174 | *fw_eng = info->fw_eng; |
| 1175 | } |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 1176 | |
| 1177 | static void qed_handle_bulletin_change(struct qed_hwfn *hwfn) |
| 1178 | { |
Yuval Mintz | eff1696 | 2016-05-11 16:36:21 +0300 | [diff] [blame] | 1179 | struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth; |
| 1180 | u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced; |
| 1181 | void *cookie = hwfn->cdev->ops_cookie; |
| 1182 | |
| 1183 | is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac, |
| 1184 | &is_mac_forced); |
| 1185 | if (is_mac_exist && is_mac_forced && cookie) |
| 1186 | ops->force_mac(cookie, mac); |
| 1187 | |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 1188 | /* Always update link configuration according to bulletin */ |
| 1189 | qed_link_update(hwfn); |
| 1190 | } |
| 1191 | |
| 1192 | void qed_iov_vf_task(struct work_struct *work) |
| 1193 | { |
| 1194 | struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn, |
| 1195 | iov_task.work); |
| 1196 | u8 change = 0; |
| 1197 | |
| 1198 | if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags)) |
| 1199 | return; |
| 1200 | |
| 1201 | /* Handle bulletin board changes */ |
| 1202 | qed_vf_read_bulletin(hwfn, &change); |
| 1203 | if (change) |
| 1204 | qed_handle_bulletin_change(hwfn); |
| 1205 | |
| 1206 | /* As VF is polling bulletin board, need to constantly re-schedule */ |
| 1207 | queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ); |
| 1208 | } |