Ariel Elior | be1f1ffa | 2013-01-01 05:22:24 +0000 | [diff] [blame] | 1 | /* bnx2x_vfpf.c: Broadcom Everest network driver. |
| 2 | * |
Yuval Mintz | 247fa82 | 2013-01-14 05:11:50 +0000 | [diff] [blame] | 3 | * Copyright 2009-2013 Broadcom Corporation |
Ariel Elior | be1f1ffa | 2013-01-01 05:22:24 +0000 | [diff] [blame] | 4 | * |
| 5 | * Unless you and Broadcom execute a separate written software license |
| 6 | * agreement governing use of this software, this software is licensed to you |
| 7 | * under the terms of the GNU General Public License version 2, available |
| 8 | * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL"). |
| 9 | * |
| 10 | * Notwithstanding the above, under no circumstances may you combine this |
| 11 | * software in any way with any other Broadcom software provided under a |
| 12 | * license other than the GPL, without Broadcom's express prior written |
| 13 | * consent. |
| 14 | * |
| 15 | * Maintained by: Eilon Greenstein <eilong@broadcom.com> |
| 16 | * Written by: Shmulik Ravid <shmulikr@broadcom.com> |
| 17 | * Ariel Elior <ariele@broadcom.com> |
| 18 | */ |
| 19 | |
| 20 | #include "bnx2x.h" |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 21 | #include "bnx2x_cmn.h" |
Ariel Elior | b93288d | 2013-01-01 05:22:35 +0000 | [diff] [blame] | 22 | #include <linux/crc32.h> |
Ariel Elior | be1f1ffa | 2013-01-01 05:22:24 +0000 | [diff] [blame] | 23 | |
stephen hemminger | a8f47eb | 2014-01-09 22:20:11 -0800 | [diff] [blame^] | 24 | static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx); |
| 25 | |
Ariel Elior | be1f1ffa | 2013-01-01 05:22:24 +0000 | [diff] [blame] | 26 | /* place a given tlv on the tlv buffer at a given offset */ |
stephen hemminger | a8f47eb | 2014-01-09 22:20:11 -0800 | [diff] [blame^] | 27 | static void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, |
| 28 | u16 offset, u16 type, u16 length) |
Ariel Elior | be1f1ffa | 2013-01-01 05:22:24 +0000 | [diff] [blame] | 29 | { |
| 30 | struct channel_tlv *tl = |
| 31 | (struct channel_tlv *)(tlvs_list + offset); |
| 32 | |
| 33 | tl->type = type; |
| 34 | tl->length = length; |
| 35 | } |
| 36 | |
| 37 | /* Clear the mailbox and init the header of the first tlv */ |
stephen hemminger | a8f47eb | 2014-01-09 22:20:11 -0800 | [diff] [blame^] | 38 | static void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv, |
| 39 | u16 type, u16 length) |
Ariel Elior | be1f1ffa | 2013-01-01 05:22:24 +0000 | [diff] [blame] | 40 | { |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 41 | mutex_lock(&bp->vf2pf_mutex); |
| 42 | |
Ariel Elior | be1f1ffa | 2013-01-01 05:22:24 +0000 | [diff] [blame] | 43 | DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n", |
| 44 | type); |
| 45 | |
| 46 | /* Clear mailbox */ |
| 47 | memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg)); |
| 48 | |
| 49 | /* init type and length */ |
| 50 | bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length); |
| 51 | |
| 52 | /* init first tlv header */ |
| 53 | first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req); |
| 54 | } |
| 55 | |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 56 | /* releases the mailbox */ |
stephen hemminger | a8f47eb | 2014-01-09 22:20:11 -0800 | [diff] [blame^] | 57 | static void bnx2x_vfpf_finalize(struct bnx2x *bp, |
| 58 | struct vfpf_first_tlv *first_tlv) |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 59 | { |
| 60 | DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n", |
| 61 | first_tlv->tl.type); |
| 62 | |
| 63 | mutex_unlock(&bp->vf2pf_mutex); |
| 64 | } |
| 65 | |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 66 | /* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */ |
| 67 | static void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list, |
| 68 | enum channel_tlvs req_tlv) |
| 69 | { |
| 70 | struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list; |
| 71 | |
| 72 | do { |
| 73 | if (tlv->type == req_tlv) |
| 74 | return tlv; |
| 75 | |
| 76 | if (!tlv->length) { |
| 77 | BNX2X_ERR("Found TLV with length 0\n"); |
| 78 | return NULL; |
| 79 | } |
| 80 | |
| 81 | tlvs_list += tlv->length; |
| 82 | tlv = (struct channel_tlv *)tlvs_list; |
| 83 | } while (tlv->type != CHANNEL_TLV_LIST_END); |
| 84 | |
| 85 | DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv); |
| 86 | |
| 87 | return NULL; |
| 88 | } |
| 89 | |
Ariel Elior | be1f1ffa | 2013-01-01 05:22:24 +0000 | [diff] [blame] | 90 | /* list the types and lengths of the tlvs on the buffer */ |
stephen hemminger | a8f47eb | 2014-01-09 22:20:11 -0800 | [diff] [blame^] | 91 | static void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list) |
Ariel Elior | be1f1ffa | 2013-01-01 05:22:24 +0000 | [diff] [blame] | 92 | { |
| 93 | int i = 1; |
| 94 | struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list; |
| 95 | |
| 96 | while (tlv->type != CHANNEL_TLV_LIST_END) { |
| 97 | /* output tlv */ |
| 98 | DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i, |
| 99 | tlv->type, tlv->length); |
| 100 | |
| 101 | /* advance to next tlv */ |
| 102 | tlvs_list += tlv->length; |
| 103 | |
| 104 | /* cast general tlv list pointer to channel tlv header*/ |
| 105 | tlv = (struct channel_tlv *)tlvs_list; |
| 106 | |
| 107 | i++; |
| 108 | |
| 109 | /* break condition for this loop */ |
| 110 | if (i > MAX_TLVS_IN_LIST) { |
| 111 | WARN(true, "corrupt tlvs"); |
| 112 | return; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /* output last tlv */ |
| 117 | DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i, |
| 118 | tlv->type, tlv->length); |
| 119 | } |
Ariel Elior | b56e967 | 2013-01-01 05:22:32 +0000 | [diff] [blame] | 120 | |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 121 | /* test whether we support a tlv type */ |
| 122 | bool bnx2x_tlv_supported(u16 tlvtype) |
| 123 | { |
| 124 | return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX; |
| 125 | } |
| 126 | |
| 127 | static inline int bnx2x_pfvf_status_codes(int rc) |
| 128 | { |
| 129 | switch (rc) { |
| 130 | case 0: |
| 131 | return PFVF_STATUS_SUCCESS; |
| 132 | case -ENOMEM: |
| 133 | return PFVF_STATUS_NO_RESOURCE; |
| 134 | default: |
| 135 | return PFVF_STATUS_FAILURE; |
| 136 | } |
| 137 | } |
| 138 | |
stephen hemminger | 732ac8c | 2013-02-22 08:01:10 +0000 | [diff] [blame] | 139 | static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping) |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 140 | { |
| 141 | struct cstorm_vf_zone_data __iomem *zone_data = |
| 142 | REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START); |
Ariel Elior | 78c3bcc | 2013-06-20 17:39:08 +0300 | [diff] [blame] | 143 | int tout = 100, interval = 100; /* wait for 10 seconds */ |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 144 | |
| 145 | if (*done) { |
| 146 | BNX2X_ERR("done was non zero before message to pf was sent\n"); |
| 147 | WARN_ON(true); |
| 148 | return -EINVAL; |
| 149 | } |
| 150 | |
Ariel Elior | 78c3bcc | 2013-06-20 17:39:08 +0300 | [diff] [blame] | 151 | /* if PF indicated channel is down avoid sending message. Return success |
| 152 | * so calling flow can continue |
| 153 | */ |
| 154 | bnx2x_sample_bulletin(bp); |
| 155 | if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) { |
| 156 | DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n"); |
| 157 | *done = PFVF_STATUS_SUCCESS; |
Dmitry Kravkov | ffa1cb9 | 2013-11-17 08:59:28 +0200 | [diff] [blame] | 158 | return -EINVAL; |
Ariel Elior | 78c3bcc | 2013-06-20 17:39:08 +0300 | [diff] [blame] | 159 | } |
| 160 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 161 | /* Write message address */ |
| 162 | writel(U64_LO(msg_mapping), |
| 163 | &zone_data->non_trigger.vf_pf_channel.msg_addr_lo); |
| 164 | writel(U64_HI(msg_mapping), |
| 165 | &zone_data->non_trigger.vf_pf_channel.msg_addr_hi); |
| 166 | |
| 167 | /* make sure the address is written before FW accesses it */ |
| 168 | wmb(); |
| 169 | |
| 170 | /* Trigger the PF FW */ |
| 171 | writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid); |
| 172 | |
| 173 | /* Wait for PF to complete */ |
| 174 | while ((tout >= 0) && (!*done)) { |
| 175 | msleep(interval); |
| 176 | tout -= 1; |
| 177 | |
| 178 | /* progress indicator - HV can take its own sweet time in |
| 179 | * answering VFs... |
| 180 | */ |
| 181 | DP_CONT(BNX2X_MSG_IOV, "."); |
| 182 | } |
| 183 | |
| 184 | if (!*done) { |
| 185 | BNX2X_ERR("PF response has timed out\n"); |
| 186 | return -EAGAIN; |
| 187 | } |
| 188 | DP(BNX2X_MSG_SP, "Got a response from PF\n"); |
| 189 | return 0; |
| 190 | } |
| 191 | |
stephen hemminger | 732ac8c | 2013-02-22 08:01:10 +0000 | [diff] [blame] | 192 | static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id) |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 193 | { |
| 194 | u32 me_reg; |
| 195 | int tout = 10, interval = 100; /* Wait for 1 sec */ |
| 196 | |
| 197 | do { |
| 198 | /* pxp traps vf read of doorbells and returns me reg value */ |
| 199 | me_reg = readl(bp->doorbells); |
| 200 | if (GOOD_ME_REG(me_reg)) |
| 201 | break; |
| 202 | |
| 203 | msleep(interval); |
| 204 | |
| 205 | BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?", |
| 206 | me_reg); |
| 207 | } while (tout-- > 0); |
| 208 | |
| 209 | if (!GOOD_ME_REG(me_reg)) { |
| 210 | BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg); |
| 211 | return -EINVAL; |
| 212 | } |
| 213 | |
Michal Schmidt | c047e07 | 2013-12-17 18:51:25 +0100 | [diff] [blame] | 214 | DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 215 | |
| 216 | *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT; |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count) |
| 222 | { |
| 223 | int rc = 0, attempts = 0; |
| 224 | struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire; |
| 225 | struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp; |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 226 | struct vfpf_port_phys_id_resp_tlv *phys_port_resp; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 227 | u32 vf_id; |
| 228 | bool resources_acquired = false; |
| 229 | |
| 230 | /* clear mailbox and prep first tlv */ |
| 231 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req)); |
| 232 | |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 233 | if (bnx2x_get_vf_id(bp, &vf_id)) { |
| 234 | rc = -EAGAIN; |
| 235 | goto out; |
| 236 | } |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 237 | |
| 238 | req->vfdev_info.vf_id = vf_id; |
| 239 | req->vfdev_info.vf_os = 0; |
| 240 | |
| 241 | req->resc_request.num_rxqs = rx_count; |
| 242 | req->resc_request.num_txqs = tx_count; |
| 243 | req->resc_request.num_sbs = bp->igu_sb_cnt; |
| 244 | req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS; |
| 245 | req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS; |
| 246 | |
| 247 | /* pf 2 vf bulletin board address */ |
| 248 | req->bulletin_addr = bp->pf2vf_bulletin_mapping; |
| 249 | |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 250 | /* Request physical port identifier */ |
| 251 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, |
| 252 | CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv)); |
| 253 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 254 | /* add list termination tlv */ |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 255 | bnx2x_add_tlv(bp, req, |
| 256 | req->first_tlv.tl.length + sizeof(struct channel_tlv), |
| 257 | CHANNEL_TLV_LIST_END, |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 258 | sizeof(struct channel_list_end_tlv)); |
| 259 | |
| 260 | /* output tlvs list */ |
| 261 | bnx2x_dp_tlv_list(bp, req); |
| 262 | |
| 263 | while (!resources_acquired) { |
| 264 | DP(BNX2X_MSG_SP, "attempting to acquire resources\n"); |
| 265 | |
| 266 | /* send acquire request */ |
| 267 | rc = bnx2x_send_msg2pf(bp, |
| 268 | &resp->hdr.status, |
| 269 | bp->vf2pf_mbox_mapping); |
| 270 | |
| 271 | /* PF timeout */ |
| 272 | if (rc) |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 273 | goto out; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 274 | |
| 275 | /* copy acquire response from buffer to bp */ |
| 276 | memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp)); |
| 277 | |
| 278 | attempts++; |
| 279 | |
Yuval Mintz | 16a5fd9 | 2013-06-02 00:06:18 +0000 | [diff] [blame] | 280 | /* test whether the PF accepted our request. If not, humble |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 281 | * the request and try again. |
| 282 | */ |
| 283 | if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) { |
| 284 | DP(BNX2X_MSG_SP, "resources acquired\n"); |
| 285 | resources_acquired = true; |
| 286 | } else if (bp->acquire_resp.hdr.status == |
| 287 | PFVF_STATUS_NO_RESOURCE && |
| 288 | attempts < VF_ACQUIRE_THRESH) { |
| 289 | DP(BNX2X_MSG_SP, |
| 290 | "PF unwilling to fulfill resource request. Try PF recommended amount\n"); |
| 291 | |
| 292 | /* humble our request */ |
| 293 | req->resc_request.num_txqs = |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 294 | min(req->resc_request.num_txqs, |
| 295 | bp->acquire_resp.resc.num_txqs); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 296 | req->resc_request.num_rxqs = |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 297 | min(req->resc_request.num_rxqs, |
| 298 | bp->acquire_resp.resc.num_rxqs); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 299 | req->resc_request.num_sbs = |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 300 | min(req->resc_request.num_sbs, |
| 301 | bp->acquire_resp.resc.num_sbs); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 302 | req->resc_request.num_mac_filters = |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 303 | min(req->resc_request.num_mac_filters, |
| 304 | bp->acquire_resp.resc.num_mac_filters); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 305 | req->resc_request.num_vlan_filters = |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 306 | min(req->resc_request.num_vlan_filters, |
| 307 | bp->acquire_resp.resc.num_vlan_filters); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 308 | req->resc_request.num_mc_filters = |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 309 | min(req->resc_request.num_mc_filters, |
| 310 | bp->acquire_resp.resc.num_mc_filters); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 311 | |
| 312 | /* Clear response buffer */ |
| 313 | memset(&bp->vf2pf_mbox->resp, 0, |
| 314 | sizeof(union pfvf_tlvs)); |
| 315 | } else { |
| 316 | /* PF reports error */ |
| 317 | BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n", |
| 318 | bp->acquire_resp.hdr.status); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 319 | rc = -EAGAIN; |
| 320 | goto out; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 324 | /* Retrieve physical port id (if possible) */ |
| 325 | phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *) |
| 326 | bnx2x_search_tlv_list(bp, resp, |
| 327 | CHANNEL_TLV_PHYS_PORT_ID); |
| 328 | if (phys_port_resp) { |
| 329 | memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN); |
| 330 | bp->flags |= HAS_PHYS_PORT_ID; |
| 331 | } |
| 332 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 333 | /* get HW info */ |
| 334 | bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff); |
| 335 | bp->link_params.chip_id = bp->common.chip_id; |
| 336 | bp->db_size = bp->acquire_resp.pfdev_info.db_size; |
| 337 | bp->common.int_block = INT_BLOCK_IGU; |
| 338 | bp->common.chip_port_mode = CHIP_2_PORT_MODE; |
| 339 | bp->igu_dsb_id = -1; |
| 340 | bp->mf_ov = 0; |
| 341 | bp->mf_mode = 0; |
| 342 | bp->common.flash_size = 0; |
| 343 | bp->flags |= |
| 344 | NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG; |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 345 | bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 346 | bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id; |
| 347 | strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver, |
| 348 | sizeof(bp->fw_ver)); |
| 349 | |
| 350 | if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr)) |
| 351 | memcpy(bp->dev->dev_addr, |
| 352 | bp->acquire_resp.resc.current_mac_addr, |
| 353 | ETH_ALEN); |
| 354 | |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 355 | out: |
| 356 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
| 357 | return rc; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | int bnx2x_vfpf_release(struct bnx2x *bp) |
| 361 | { |
| 362 | struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release; |
| 363 | struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 364 | u32 rc, vf_id; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 365 | |
| 366 | /* clear mailbox and prep first tlv */ |
| 367 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req)); |
| 368 | |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 369 | if (bnx2x_get_vf_id(bp, &vf_id)) { |
| 370 | rc = -EAGAIN; |
| 371 | goto out; |
| 372 | } |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 373 | |
| 374 | req->vf_id = vf_id; |
| 375 | |
| 376 | /* add list termination tlv */ |
| 377 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, |
| 378 | sizeof(struct channel_list_end_tlv)); |
| 379 | |
| 380 | /* output tlvs list */ |
| 381 | bnx2x_dp_tlv_list(bp, req); |
| 382 | |
| 383 | /* send release request */ |
| 384 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); |
| 385 | |
| 386 | if (rc) |
| 387 | /* PF timeout */ |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 388 | goto out; |
| 389 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 390 | if (resp->hdr.status == PFVF_STATUS_SUCCESS) { |
| 391 | /* PF released us */ |
| 392 | DP(BNX2X_MSG_SP, "vf released\n"); |
| 393 | } else { |
| 394 | /* PF reports error */ |
Yuval Mintz | 6bf07b8 | 2013-06-02 00:06:20 +0000 | [diff] [blame] | 395 | BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n", |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 396 | resp->hdr.status); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 397 | rc = -EAGAIN; |
| 398 | goto out; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 399 | } |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 400 | out: |
| 401 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 402 | |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 403 | return rc; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /* Tell PF about SB addresses */ |
| 407 | int bnx2x_vfpf_init(struct bnx2x *bp) |
| 408 | { |
| 409 | struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init; |
| 410 | struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; |
| 411 | int rc, i; |
| 412 | |
| 413 | /* clear mailbox and prep first tlv */ |
| 414 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req)); |
| 415 | |
| 416 | /* status blocks */ |
| 417 | for_each_eth_queue(bp, i) |
| 418 | req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i, |
| 419 | status_blk_mapping); |
| 420 | |
| 421 | /* statistics - requests only supports single queue for now */ |
| 422 | req->stats_addr = bp->fw_stats_data_mapping + |
| 423 | offsetof(struct bnx2x_fw_stats_data, queue_stats); |
| 424 | |
Ariel Elior | 60cad4e | 2013-09-04 14:09:22 +0300 | [diff] [blame] | 425 | req->stats_stride = sizeof(struct per_queue_stats); |
| 426 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 427 | /* add list termination tlv */ |
| 428 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, |
| 429 | sizeof(struct channel_list_end_tlv)); |
| 430 | |
| 431 | /* output tlvs list */ |
| 432 | bnx2x_dp_tlv_list(bp, req); |
| 433 | |
| 434 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); |
| 435 | if (rc) |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 436 | goto out; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 437 | |
| 438 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { |
| 439 | BNX2X_ERR("INIT VF failed: %d. Breaking...\n", |
| 440 | resp->hdr.status); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 441 | rc = -EAGAIN; |
| 442 | goto out; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | DP(BNX2X_MSG_SP, "INIT VF Succeeded\n"); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 446 | out: |
| 447 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
| 448 | |
| 449 | return rc; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | /* CLOSE VF - opposite to INIT_VF */ |
| 453 | void bnx2x_vfpf_close_vf(struct bnx2x *bp) |
| 454 | { |
| 455 | struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close; |
| 456 | struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; |
| 457 | int i, rc; |
| 458 | u32 vf_id; |
| 459 | |
| 460 | /* If we haven't got a valid VF id, there is no sense to |
| 461 | * continue with sending messages |
| 462 | */ |
| 463 | if (bnx2x_get_vf_id(bp, &vf_id)) |
| 464 | goto free_irq; |
| 465 | |
| 466 | /* Close the queues */ |
| 467 | for_each_queue(bp, i) |
| 468 | bnx2x_vfpf_teardown_queue(bp, i); |
| 469 | |
Dmitry Kravkov | f8f4f61 | 2013-04-24 01:45:00 +0000 | [diff] [blame] | 470 | /* remove mac */ |
| 471 | bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false); |
| 472 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 473 | /* clear mailbox and prep first tlv */ |
| 474 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req)); |
| 475 | |
| 476 | req->vf_id = vf_id; |
| 477 | |
| 478 | /* add list termination tlv */ |
| 479 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, |
| 480 | sizeof(struct channel_list_end_tlv)); |
| 481 | |
| 482 | /* output tlvs list */ |
| 483 | bnx2x_dp_tlv_list(bp, req); |
| 484 | |
| 485 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); |
| 486 | |
| 487 | if (rc) |
| 488 | BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc); |
| 489 | |
| 490 | else if (resp->hdr.status != PFVF_STATUS_SUCCESS) |
| 491 | BNX2X_ERR("Sending CLOSE failed: pf response was %d\n", |
| 492 | resp->hdr.status); |
| 493 | |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 494 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
| 495 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 496 | free_irq: |
| 497 | /* Disable HW interrupts, NAPI */ |
| 498 | bnx2x_netif_stop(bp, 0); |
| 499 | /* Delete all NAPI objects */ |
| 500 | bnx2x_del_all_napi(bp); |
| 501 | |
| 502 | /* Release IRQs */ |
| 503 | bnx2x_free_irq(bp); |
| 504 | } |
| 505 | |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 506 | static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 507 | struct bnx2x_vf_queue *q) |
| 508 | { |
| 509 | u8 cl_id = vfq_cl_id(vf, q); |
| 510 | u8 func_id = FW_VF_HANDLE(vf->abs_vfid); |
| 511 | |
| 512 | /* mac */ |
| 513 | bnx2x_init_mac_obj(bp, &q->mac_obj, |
| 514 | cl_id, q->cid, func_id, |
| 515 | bnx2x_vf_sp(bp, vf, mac_rdata), |
| 516 | bnx2x_vf_sp_map(bp, vf, mac_rdata), |
| 517 | BNX2X_FILTER_MAC_PENDING, |
| 518 | &vf->filter_state, |
| 519 | BNX2X_OBJ_TYPE_RX_TX, |
| 520 | &bp->macs_pool); |
| 521 | /* vlan */ |
| 522 | bnx2x_init_vlan_obj(bp, &q->vlan_obj, |
| 523 | cl_id, q->cid, func_id, |
| 524 | bnx2x_vf_sp(bp, vf, vlan_rdata), |
| 525 | bnx2x_vf_sp_map(bp, vf, vlan_rdata), |
| 526 | BNX2X_FILTER_VLAN_PENDING, |
| 527 | &vf->filter_state, |
| 528 | BNX2X_OBJ_TYPE_RX_TX, |
| 529 | &bp->vlans_pool); |
| 530 | |
| 531 | /* mcast */ |
| 532 | bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id, |
| 533 | q->cid, func_id, func_id, |
| 534 | bnx2x_vf_sp(bp, vf, mcast_rdata), |
| 535 | bnx2x_vf_sp_map(bp, vf, mcast_rdata), |
| 536 | BNX2X_FILTER_MCAST_PENDING, |
| 537 | &vf->filter_state, |
| 538 | BNX2X_OBJ_TYPE_RX_TX); |
| 539 | |
| 540 | /* rss */ |
| 541 | bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid, |
| 542 | func_id, func_id, |
| 543 | bnx2x_vf_sp(bp, vf, rss_rdata), |
| 544 | bnx2x_vf_sp_map(bp, vf, rss_rdata), |
| 545 | BNX2X_FILTER_RSS_CONF_PENDING, |
| 546 | &vf->filter_state, |
| 547 | BNX2X_OBJ_TYPE_RX_TX); |
| 548 | |
| 549 | vf->leading_rss = cl_id; |
| 550 | q->is_leading = true; |
| 551 | } |
| 552 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 553 | /* ask the pf to open a queue for the vf */ |
Ariel Elior | 60cad4e | 2013-09-04 14:09:22 +0300 | [diff] [blame] | 554 | int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 555 | bool is_leading) |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 556 | { |
| 557 | struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q; |
| 558 | struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; |
Ariel Elior | 60cad4e | 2013-09-04 14:09:22 +0300 | [diff] [blame] | 559 | u8 fp_idx = fp->index; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 560 | u16 tpa_agg_size = 0, flags = 0; |
| 561 | int rc; |
| 562 | |
| 563 | /* clear mailbox and prep first tlv */ |
| 564 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req)); |
| 565 | |
| 566 | /* select tpa mode to request */ |
| 567 | if (!fp->disable_tpa) { |
| 568 | flags |= VFPF_QUEUE_FLG_TPA; |
| 569 | flags |= VFPF_QUEUE_FLG_TPA_IPV6; |
| 570 | if (fp->mode == TPA_MODE_GRO) |
| 571 | flags |= VFPF_QUEUE_FLG_TPA_GRO; |
| 572 | tpa_agg_size = TPA_AGG_SIZE; |
| 573 | } |
| 574 | |
Ariel Elior | 60cad4e | 2013-09-04 14:09:22 +0300 | [diff] [blame] | 575 | if (is_leading) |
| 576 | flags |= VFPF_QUEUE_FLG_LEADING_RSS; |
| 577 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 578 | /* calculate queue flags */ |
| 579 | flags |= VFPF_QUEUE_FLG_STATS; |
| 580 | flags |= VFPF_QUEUE_FLG_CACHE_ALIGN; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 581 | flags |= VFPF_QUEUE_FLG_VLAN; |
| 582 | DP(NETIF_MSG_IFUP, "vlan removal enabled\n"); |
| 583 | |
| 584 | /* Common */ |
| 585 | req->vf_qid = fp_idx; |
| 586 | req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID; |
| 587 | |
| 588 | /* Rx */ |
| 589 | req->rxq.rcq_addr = fp->rx_comp_mapping; |
| 590 | req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE; |
| 591 | req->rxq.rxq_addr = fp->rx_desc_mapping; |
| 592 | req->rxq.sge_addr = fp->rx_sge_mapping; |
| 593 | req->rxq.vf_sb = fp_idx; |
| 594 | req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS; |
| 595 | req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0; |
| 596 | req->rxq.mtu = bp->dev->mtu; |
| 597 | req->rxq.buf_sz = fp->rx_buf_size; |
| 598 | req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE; |
| 599 | req->rxq.tpa_agg_sz = tpa_agg_size; |
| 600 | req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT; |
| 601 | req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) & |
| 602 | (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT; |
| 603 | req->rxq.flags = flags; |
| 604 | req->rxq.drop_flags = 0; |
| 605 | req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT; |
| 606 | req->rxq.stat_id = -1; /* No stats at the moment */ |
| 607 | |
| 608 | /* Tx */ |
| 609 | req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping; |
| 610 | req->txq.vf_sb = fp_idx; |
| 611 | req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0; |
| 612 | req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0; |
| 613 | req->txq.flags = flags; |
| 614 | req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW; |
| 615 | |
| 616 | /* add list termination tlv */ |
| 617 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, |
| 618 | sizeof(struct channel_list_end_tlv)); |
| 619 | |
| 620 | /* output tlvs list */ |
| 621 | bnx2x_dp_tlv_list(bp, req); |
| 622 | |
| 623 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); |
| 624 | if (rc) |
| 625 | BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n", |
| 626 | fp_idx); |
| 627 | |
| 628 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { |
| 629 | BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n", |
| 630 | fp_idx, resp->hdr.status); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 631 | rc = -EINVAL; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 632 | } |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 633 | |
| 634 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
| 635 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 636 | return rc; |
| 637 | } |
| 638 | |
stephen hemminger | a8f47eb | 2014-01-09 22:20:11 -0800 | [diff] [blame^] | 639 | static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx) |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 640 | { |
| 641 | struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op; |
| 642 | struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; |
| 643 | int rc; |
| 644 | |
| 645 | /* clear mailbox and prep first tlv */ |
| 646 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q, |
| 647 | sizeof(*req)); |
| 648 | |
| 649 | req->vf_qid = qidx; |
| 650 | |
| 651 | /* add list termination tlv */ |
| 652 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, |
| 653 | sizeof(struct channel_list_end_tlv)); |
| 654 | |
| 655 | /* output tlvs list */ |
| 656 | bnx2x_dp_tlv_list(bp, req); |
| 657 | |
| 658 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); |
| 659 | |
| 660 | if (rc) { |
| 661 | BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx, |
| 662 | rc); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 663 | goto out; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /* PF failed the transaction */ |
| 667 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { |
| 668 | BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx, |
| 669 | resp->hdr.status); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 670 | rc = -EINVAL; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 673 | out: |
| 674 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
| 675 | return rc; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /* request pf to add a mac for the vf */ |
Dmitry Kravkov | f8f4f61 | 2013-04-24 01:45:00 +0000 | [diff] [blame] | 679 | int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set) |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 680 | { |
| 681 | struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters; |
| 682 | struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; |
Dmitry Kravkov | f8f4f61 | 2013-04-24 01:45:00 +0000 | [diff] [blame] | 683 | struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content; |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 684 | int rc = 0; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 685 | |
| 686 | /* clear mailbox and prep first tlv */ |
| 687 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS, |
| 688 | sizeof(*req)); |
| 689 | |
| 690 | req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED; |
Dmitry Kravkov | f8f4f61 | 2013-04-24 01:45:00 +0000 | [diff] [blame] | 691 | req->vf_qid = vf_qid; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 692 | req->n_mac_vlan_filters = 1; |
Dmitry Kravkov | f8f4f61 | 2013-04-24 01:45:00 +0000 | [diff] [blame] | 693 | |
| 694 | req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID; |
| 695 | if (set) |
| 696 | req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 697 | |
| 698 | /* sample bulletin board for new mac */ |
| 699 | bnx2x_sample_bulletin(bp); |
| 700 | |
| 701 | /* copy mac from device to request */ |
Dmitry Kravkov | f8f4f61 | 2013-04-24 01:45:00 +0000 | [diff] [blame] | 702 | memcpy(req->filters[0].mac, addr, ETH_ALEN); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 703 | |
| 704 | /* add list termination tlv */ |
| 705 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, |
| 706 | sizeof(struct channel_list_end_tlv)); |
| 707 | |
| 708 | /* output tlvs list */ |
| 709 | bnx2x_dp_tlv_list(bp, req); |
| 710 | |
| 711 | /* send message to pf */ |
| 712 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); |
| 713 | if (rc) { |
| 714 | BNX2X_ERR("failed to send message to pf. rc was %d\n", rc); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 715 | goto out; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | /* failure may mean PF was configured with a new mac for us */ |
| 719 | while (resp->hdr.status == PFVF_STATUS_FAILURE) { |
| 720 | DP(BNX2X_MSG_IOV, |
| 721 | "vfpf SET MAC failed. Check bulletin board for new posts\n"); |
| 722 | |
Dmitry Kravkov | f8f4f61 | 2013-04-24 01:45:00 +0000 | [diff] [blame] | 723 | /* copy mac from bulletin to device */ |
| 724 | memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN); |
| 725 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 726 | /* check if bulletin board was updated */ |
| 727 | if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) { |
| 728 | /* copy mac from device to request */ |
| 729 | memcpy(req->filters[0].mac, bp->dev->dev_addr, |
| 730 | ETH_ALEN); |
| 731 | |
| 732 | /* send message to pf */ |
| 733 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, |
| 734 | bp->vf2pf_mbox_mapping); |
| 735 | } else { |
| 736 | /* no new info in bulletin */ |
| 737 | break; |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { |
| 742 | BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 743 | rc = -EINVAL; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 744 | } |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 745 | out: |
| 746 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
Ariel Elior | 60cad4e | 2013-09-04 14:09:22 +0300 | [diff] [blame] | 751 | /* request pf to config rss table for vf queues*/ |
| 752 | int bnx2x_vfpf_config_rss(struct bnx2x *bp, |
| 753 | struct bnx2x_config_rss_params *params) |
| 754 | { |
| 755 | struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; |
| 756 | struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss; |
| 757 | int rc = 0; |
| 758 | |
| 759 | /* clear mailbox and prep first tlv */ |
| 760 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS, |
| 761 | sizeof(*req)); |
| 762 | |
| 763 | /* add list termination tlv */ |
| 764 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, |
| 765 | sizeof(struct channel_list_end_tlv)); |
| 766 | |
| 767 | memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE); |
| 768 | memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key)); |
| 769 | req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE; |
| 770 | req->rss_key_size = T_ETH_RSS_KEY; |
| 771 | req->rss_result_mask = params->rss_result_mask; |
| 772 | |
| 773 | /* flags handled individually for backward/forward compatability */ |
| 774 | if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED)) |
| 775 | req->rss_flags |= VFPF_RSS_MODE_DISABLED; |
| 776 | if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR)) |
| 777 | req->rss_flags |= VFPF_RSS_MODE_REGULAR; |
| 778 | if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH)) |
| 779 | req->rss_flags |= VFPF_RSS_SET_SRCH; |
| 780 | if (params->rss_flags & (1 << BNX2X_RSS_IPV4)) |
| 781 | req->rss_flags |= VFPF_RSS_IPV4; |
| 782 | if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP)) |
| 783 | req->rss_flags |= VFPF_RSS_IPV4_TCP; |
| 784 | if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP)) |
| 785 | req->rss_flags |= VFPF_RSS_IPV4_UDP; |
| 786 | if (params->rss_flags & (1 << BNX2X_RSS_IPV6)) |
| 787 | req->rss_flags |= VFPF_RSS_IPV6; |
| 788 | if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP)) |
| 789 | req->rss_flags |= VFPF_RSS_IPV6_TCP; |
| 790 | if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP)) |
| 791 | req->rss_flags |= VFPF_RSS_IPV6_UDP; |
| 792 | |
| 793 | DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags); |
| 794 | |
| 795 | /* output tlvs list */ |
| 796 | bnx2x_dp_tlv_list(bp, req); |
| 797 | |
| 798 | /* send message to pf */ |
| 799 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); |
| 800 | if (rc) { |
| 801 | BNX2X_ERR("failed to send message to pf. rc was %d\n", rc); |
| 802 | goto out; |
| 803 | } |
| 804 | |
| 805 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { |
Yuval Mintz | 31b3523 | 2013-12-26 09:57:10 +0200 | [diff] [blame] | 806 | /* Since older drivers don't support this feature (and VF has |
| 807 | * no way of knowing other than failing this), don't propagate |
| 808 | * an error in this case. |
| 809 | */ |
| 810 | DP(BNX2X_MSG_IOV, |
| 811 | "Failed to send rss message to PF over VF-PF channel [%d]\n", |
| 812 | resp->hdr.status); |
Ariel Elior | 60cad4e | 2013-09-04 14:09:22 +0300 | [diff] [blame] | 813 | } |
| 814 | out: |
| 815 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
| 816 | |
Yuval Mintz | 31b3523 | 2013-12-26 09:57:10 +0200 | [diff] [blame] | 817 | return rc; |
Ariel Elior | 60cad4e | 2013-09-04 14:09:22 +0300 | [diff] [blame] | 818 | } |
| 819 | |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 820 | int bnx2x_vfpf_set_mcast(struct net_device *dev) |
| 821 | { |
| 822 | struct bnx2x *bp = netdev_priv(dev); |
| 823 | struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters; |
| 824 | struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; |
| 825 | int rc, i = 0; |
| 826 | struct netdev_hw_addr *ha; |
| 827 | |
| 828 | if (bp->state != BNX2X_STATE_OPEN) { |
| 829 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | |
| 833 | /* clear mailbox and prep first tlv */ |
| 834 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS, |
| 835 | sizeof(*req)); |
| 836 | |
| 837 | /* Get Rx mode requested */ |
| 838 | DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags); |
| 839 | |
| 840 | netdev_for_each_mc_addr(ha, dev) { |
| 841 | DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n", |
| 842 | bnx2x_mc_addr(ha)); |
| 843 | memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN); |
| 844 | i++; |
| 845 | } |
| 846 | |
| 847 | /* We support four PFVF_MAX_MULTICAST_PER_VF mcast |
| 848 | * addresses tops |
| 849 | */ |
| 850 | if (i >= PFVF_MAX_MULTICAST_PER_VF) { |
| 851 | DP(NETIF_MSG_IFUP, |
| 852 | "VF supports not more than %d multicast MAC addresses\n", |
| 853 | PFVF_MAX_MULTICAST_PER_VF); |
| 854 | return -EINVAL; |
| 855 | } |
| 856 | |
| 857 | req->n_multicast = i; |
| 858 | req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED; |
| 859 | req->vf_qid = 0; |
| 860 | |
| 861 | /* add list termination tlv */ |
| 862 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, |
| 863 | sizeof(struct channel_list_end_tlv)); |
| 864 | |
| 865 | /* output tlvs list */ |
| 866 | bnx2x_dp_tlv_list(bp, req); |
| 867 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); |
| 868 | if (rc) { |
| 869 | BNX2X_ERR("Sending a message failed: %d\n", rc); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 870 | goto out; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { |
| 874 | BNX2X_ERR("Set Rx mode/multicast failed: %d\n", |
| 875 | resp->hdr.status); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 876 | rc = -EINVAL; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 877 | } |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 878 | out: |
| 879 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp) |
| 885 | { |
| 886 | int mode = bp->rx_mode; |
| 887 | struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters; |
| 888 | struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; |
| 889 | int rc; |
| 890 | |
| 891 | /* clear mailbox and prep first tlv */ |
| 892 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS, |
| 893 | sizeof(*req)); |
| 894 | |
| 895 | DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode); |
| 896 | |
| 897 | switch (mode) { |
| 898 | case BNX2X_RX_MODE_NONE: /* no Rx */ |
| 899 | req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE; |
| 900 | break; |
| 901 | case BNX2X_RX_MODE_NORMAL: |
| 902 | req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST; |
| 903 | req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST; |
| 904 | req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST; |
| 905 | break; |
| 906 | case BNX2X_RX_MODE_ALLMULTI: |
| 907 | req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST; |
| 908 | req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST; |
| 909 | req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST; |
| 910 | break; |
| 911 | case BNX2X_RX_MODE_PROMISC: |
| 912 | req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST; |
| 913 | req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST; |
| 914 | req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST; |
| 915 | break; |
| 916 | default: |
| 917 | BNX2X_ERR("BAD rx mode (%d)\n", mode); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 918 | rc = -EINVAL; |
| 919 | goto out; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED; |
| 923 | req->vf_qid = 0; |
| 924 | |
| 925 | /* add list termination tlv */ |
| 926 | bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, |
| 927 | sizeof(struct channel_list_end_tlv)); |
| 928 | |
| 929 | /* output tlvs list */ |
| 930 | bnx2x_dp_tlv_list(bp, req); |
| 931 | |
| 932 | rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); |
| 933 | if (rc) |
| 934 | BNX2X_ERR("Sending a message failed: %d\n", rc); |
| 935 | |
| 936 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { |
| 937 | BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status); |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 938 | rc = -EINVAL; |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 939 | } |
Dmitry Kravkov | 1d6f3cd | 2013-03-27 01:05:17 +0000 | [diff] [blame] | 940 | out: |
| 941 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
Ariel Elior | 6411280 | 2013-01-07 00:50:23 +0000 | [diff] [blame] | 942 | |
| 943 | return rc; |
| 944 | } |
| 945 | |
Ariel Elior | b56e967 | 2013-01-01 05:22:32 +0000 | [diff] [blame] | 946 | /* General service functions */ |
| 947 | static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid) |
| 948 | { |
| 949 | u32 addr = BAR_CSTRORM_INTMEM + |
| 950 | CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid); |
| 951 | |
| 952 | REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY); |
| 953 | } |
| 954 | |
| 955 | static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid) |
| 956 | { |
| 957 | u32 addr = BAR_CSTRORM_INTMEM + |
| 958 | CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid); |
| 959 | |
| 960 | REG_WR8(bp, addr, 1); |
| 961 | } |
| 962 | |
| 963 | static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp) |
| 964 | { |
| 965 | int i; |
| 966 | |
| 967 | for_each_vf(bp, i) |
| 968 | storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid)); |
| 969 | } |
| 970 | |
Yuval Mintz | 16a5fd9 | 2013-06-02 00:06:18 +0000 | [diff] [blame] | 971 | /* enable vf_pf mailbox (aka vf-pf-channel) */ |
Ariel Elior | b56e967 | 2013-01-01 05:22:32 +0000 | [diff] [blame] | 972 | void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid) |
| 973 | { |
| 974 | bnx2x_vf_flr_clnup_epilog(bp, abs_vfid); |
| 975 | |
| 976 | /* enable the mailbox in the FW */ |
| 977 | storm_memset_vf_mbx_ack(bp, abs_vfid); |
| 978 | storm_memset_vf_mbx_valid(bp, abs_vfid); |
| 979 | |
| 980 | /* enable the VF access to the mailbox */ |
| 981 | bnx2x_vf_enable_access(bp, abs_vfid); |
| 982 | } |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 983 | |
| 984 | /* this works only on !E1h */ |
| 985 | static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf, |
| 986 | dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi, |
| 987 | u32 vf_addr_lo, u32 len32) |
| 988 | { |
| 989 | struct dmae_command dmae; |
| 990 | |
| 991 | if (CHIP_IS_E1x(bp)) { |
| 992 | BNX2X_ERR("Chip revision does not support VFs\n"); |
| 993 | return DMAE_NOT_RDY; |
| 994 | } |
| 995 | |
| 996 | if (!bp->dmae_ready) { |
| 997 | BNX2X_ERR("DMAE is not ready, can not copy\n"); |
| 998 | return DMAE_NOT_RDY; |
| 999 | } |
| 1000 | |
| 1001 | /* set opcode and fixed command fields */ |
| 1002 | bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI); |
| 1003 | |
| 1004 | if (from_vf) { |
| 1005 | dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) | |
| 1006 | (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) | |
| 1007 | (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT); |
| 1008 | |
| 1009 | dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT); |
| 1010 | |
| 1011 | dmae.src_addr_lo = vf_addr_lo; |
| 1012 | dmae.src_addr_hi = vf_addr_hi; |
| 1013 | dmae.dst_addr_lo = U64_LO(pf_addr); |
| 1014 | dmae.dst_addr_hi = U64_HI(pf_addr); |
| 1015 | } else { |
| 1016 | dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) | |
| 1017 | (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) | |
| 1018 | (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT); |
| 1019 | |
| 1020 | dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT); |
| 1021 | |
| 1022 | dmae.src_addr_lo = U64_LO(pf_addr); |
| 1023 | dmae.src_addr_hi = U64_HI(pf_addr); |
| 1024 | dmae.dst_addr_lo = vf_addr_lo; |
| 1025 | dmae.dst_addr_hi = vf_addr_hi; |
| 1026 | } |
| 1027 | dmae.len = len32; |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 1028 | |
| 1029 | /* issue the command and wait for completion */ |
Ariel Elior | 32316a4 | 2013-10-20 16:51:32 +0200 | [diff] [blame] | 1030 | return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp)); |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1033 | static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp, |
| 1034 | struct bnx2x_virtf *vf) |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1035 | { |
| 1036 | struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index); |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1037 | u16 length, type; |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1038 | |
| 1039 | /* prepare response */ |
| 1040 | type = mbx->first_tlv.tl.type; |
| 1041 | length = type == CHANNEL_TLV_ACQUIRE ? |
| 1042 | sizeof(struct pfvf_acquire_resp_tlv) : |
| 1043 | sizeof(struct pfvf_general_resp_tlv); |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1044 | bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length); |
| 1045 | bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END, |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1046 | sizeof(struct channel_list_end_tlv)); |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp, |
| 1050 | struct bnx2x_virtf *vf) |
| 1051 | { |
| 1052 | struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index); |
| 1053 | struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp; |
| 1054 | dma_addr_t pf_addr; |
| 1055 | u64 vf_addr; |
| 1056 | int rc; |
| 1057 | |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1058 | bnx2x_dp_tlv_list(bp, resp); |
| 1059 | DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n", |
| 1060 | mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset); |
| 1061 | |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1062 | resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc); |
| 1063 | |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1064 | /* send response */ |
| 1065 | vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) + |
| 1066 | mbx->first_tlv.resp_msg_offset; |
| 1067 | pf_addr = mbx->msg_mapping + |
| 1068 | offsetof(struct bnx2x_vf_mbx_msg, resp); |
| 1069 | |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1070 | /* Copy the response buffer. The first u64 is written afterwards, as |
| 1071 | * the vf is sensitive to the header being written |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1072 | */ |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1073 | vf_addr += sizeof(u64); |
| 1074 | pf_addr += sizeof(u64); |
| 1075 | rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid, |
| 1076 | U64_HI(vf_addr), |
| 1077 | U64_LO(vf_addr), |
| 1078 | (sizeof(union pfvf_tlvs) - sizeof(u64))/4); |
| 1079 | if (rc) { |
| 1080 | BNX2X_ERR("Failed to copy response body to VF %d\n", |
| 1081 | vf->abs_vfid); |
| 1082 | goto mbx_error; |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1083 | } |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1084 | vf_addr -= sizeof(u64); |
| 1085 | pf_addr -= sizeof(u64); |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1086 | |
| 1087 | /* ack the FW */ |
| 1088 | storm_memset_vf_mbx_ack(bp, vf->abs_vfid); |
| 1089 | mmiowb(); |
| 1090 | |
| 1091 | /* initiate dmae to send the response */ |
| 1092 | mbx->flags &= ~VF_MSG_INPROCESS; |
| 1093 | |
| 1094 | /* copy the response header including status-done field, |
| 1095 | * must be last dmae, must be after FW is acked |
| 1096 | */ |
| 1097 | rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid, |
| 1098 | U64_HI(vf_addr), |
| 1099 | U64_LO(vf_addr), |
| 1100 | sizeof(u64)/4); |
| 1101 | |
| 1102 | /* unlock channel mutex */ |
| 1103 | bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); |
| 1104 | |
| 1105 | if (rc) { |
| 1106 | BNX2X_ERR("Failed to copy response status to VF %d\n", |
| 1107 | vf->abs_vfid); |
Ariel Elior | f1929b0 | 2013-01-01 05:22:41 +0000 | [diff] [blame] | 1108 | goto mbx_error; |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1109 | } |
| 1110 | return; |
Ariel Elior | f1929b0 | 2013-01-01 05:22:41 +0000 | [diff] [blame] | 1111 | |
| 1112 | mbx_error: |
| 1113 | bnx2x_vf_release(bp, vf, false); /* non blocking */ |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1116 | static void bnx2x_vf_mbx_resp(struct bnx2x *bp, |
| 1117 | struct bnx2x_virtf *vf) |
| 1118 | { |
| 1119 | bnx2x_vf_mbx_resp_single_tlv(bp, vf); |
| 1120 | bnx2x_vf_mbx_resp_send_msg(bp, vf); |
| 1121 | } |
| 1122 | |
| 1123 | static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp, |
| 1124 | struct bnx2x_virtf *vf, |
| 1125 | void *buffer, |
| 1126 | u16 *offset) |
| 1127 | { |
| 1128 | struct vfpf_port_phys_id_resp_tlv *port_id; |
| 1129 | |
| 1130 | if (!(bp->flags & HAS_PHYS_PORT_ID)) |
| 1131 | return; |
| 1132 | |
| 1133 | bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID, |
| 1134 | sizeof(struct vfpf_port_phys_id_resp_tlv)); |
| 1135 | |
| 1136 | port_id = (struct vfpf_port_phys_id_resp_tlv *) |
| 1137 | (((u8 *)buffer) + *offset); |
| 1138 | memcpy(port_id->id, bp->phys_port_id, ETH_ALEN); |
| 1139 | |
| 1140 | /* Offset should continue representing the offset to the tail |
| 1141 | * of TLV data (outside this function scope) |
| 1142 | */ |
| 1143 | *offset += sizeof(struct vfpf_port_phys_id_resp_tlv); |
| 1144 | } |
| 1145 | |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1146 | static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 1147 | struct bnx2x_vf_mbx *mbx, int vfop_status) |
| 1148 | { |
| 1149 | int i; |
| 1150 | struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp; |
| 1151 | struct pf_vf_resc *resc = &resp->resc; |
| 1152 | u8 status = bnx2x_pfvf_status_codes(vfop_status); |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1153 | u16 length; |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1154 | |
| 1155 | memset(resp, 0, sizeof(*resp)); |
| 1156 | |
| 1157 | /* fill in pfdev info */ |
| 1158 | resp->pfdev_info.chip_num = bp->common.chip_id; |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 1159 | resp->pfdev_info.db_size = bp->db_size; |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1160 | resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2; |
| 1161 | resp->pfdev_info.pf_cap = (PFVF_CAP_RSS | |
| 1162 | /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA); |
| 1163 | bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver, |
| 1164 | sizeof(resp->pfdev_info.fw_ver)); |
| 1165 | |
| 1166 | if (status == PFVF_STATUS_NO_RESOURCE || |
| 1167 | status == PFVF_STATUS_SUCCESS) { |
| 1168 | /* set resources numbers, if status equals NO_RESOURCE these |
| 1169 | * are max possible numbers |
| 1170 | */ |
| 1171 | resc->num_rxqs = vf_rxq_count(vf) ? : |
| 1172 | bnx2x_vf_max_queue_cnt(bp, vf); |
| 1173 | resc->num_txqs = vf_txq_count(vf) ? : |
| 1174 | bnx2x_vf_max_queue_cnt(bp, vf); |
| 1175 | resc->num_sbs = vf_sb_count(vf); |
| 1176 | resc->num_mac_filters = vf_mac_rules_cnt(vf); |
| 1177 | resc->num_vlan_filters = vf_vlan_rules_cnt(vf); |
| 1178 | resc->num_mc_filters = 0; |
| 1179 | |
| 1180 | if (status == PFVF_STATUS_SUCCESS) { |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 1181 | /* fill in the allocated resources */ |
| 1182 | struct pf_vf_bulletin_content *bulletin = |
| 1183 | BP_VF_BULLETIN(bp, vf->index); |
| 1184 | |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1185 | for_each_vfq(vf, i) |
| 1186 | resc->hw_qid[i] = |
| 1187 | vfq_qzone_id(vf, vfq_get(vf, i)); |
| 1188 | |
| 1189 | for_each_vf_sb(vf, i) { |
| 1190 | resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i); |
| 1191 | resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i); |
| 1192 | } |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 1193 | |
| 1194 | /* if a mac has been set for this vf, supply it */ |
| 1195 | if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) { |
| 1196 | memcpy(resc->current_mac_addr, bulletin->mac, |
| 1197 | ETH_ALEN); |
| 1198 | } |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | DP(BNX2X_MSG_IOV, "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%x\n" |
| 1203 | "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n", |
| 1204 | vf->abs_vfid, |
| 1205 | resp->pfdev_info.chip_num, |
| 1206 | resp->pfdev_info.db_size, |
| 1207 | resp->pfdev_info.indices_per_sb, |
| 1208 | resp->pfdev_info.pf_cap, |
| 1209 | resc->num_rxqs, |
| 1210 | resc->num_txqs, |
| 1211 | resc->num_sbs, |
| 1212 | resc->num_mac_filters, |
| 1213 | resc->num_vlan_filters, |
| 1214 | resc->num_mc_filters, |
| 1215 | resp->pfdev_info.fw_ver); |
| 1216 | |
| 1217 | DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ "); |
| 1218 | for (i = 0; i < vf_rxq_count(vf); i++) |
| 1219 | DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]); |
| 1220 | DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ "); |
| 1221 | for (i = 0; i < vf_sb_count(vf); i++) |
| 1222 | DP_CONT(BNX2X_MSG_IOV, "%d:%d ", |
| 1223 | resc->hw_sbs[i].hw_sb_id, |
| 1224 | resc->hw_sbs[i].sb_qid); |
| 1225 | DP_CONT(BNX2X_MSG_IOV, "]\n"); |
| 1226 | |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1227 | /* prepare response */ |
| 1228 | length = sizeof(struct pfvf_acquire_resp_tlv); |
| 1229 | bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length); |
| 1230 | |
| 1231 | /* Handle possible VF requests for physical port identifiers. |
| 1232 | * 'length' should continue to indicate the offset of the first empty |
| 1233 | * place in the buffer (i.e., where next TLV should be inserted) |
| 1234 | */ |
| 1235 | if (bnx2x_search_tlv_list(bp, &mbx->msg->req, |
| 1236 | CHANNEL_TLV_PHYS_PORT_ID)) |
| 1237 | bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length); |
| 1238 | |
| 1239 | bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END, |
| 1240 | sizeof(struct channel_list_end_tlv)); |
| 1241 | |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1242 | /* send the response */ |
| 1243 | vf->op_rc = vfop_status; |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 1244 | bnx2x_vf_mbx_resp_send_msg(bp, vf); |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 1248 | struct bnx2x_vf_mbx *mbx) |
| 1249 | { |
| 1250 | int rc; |
| 1251 | struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire; |
| 1252 | |
| 1253 | /* log vfdef info */ |
| 1254 | DP(BNX2X_MSG_IOV, |
| 1255 | "VF[%d] ACQUIRE: vfdev_info- vf_id %d, vf_os %d resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d\n", |
| 1256 | vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os, |
| 1257 | acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs, |
| 1258 | acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters, |
| 1259 | acquire->resc_request.num_vlan_filters, |
| 1260 | acquire->resc_request.num_mc_filters); |
| 1261 | |
| 1262 | /* acquire the resources */ |
| 1263 | rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request); |
| 1264 | |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 1265 | /* store address of vf's bulletin board */ |
| 1266 | vf->bulletin_map = acquire->bulletin_addr; |
| 1267 | |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1268 | /* response */ |
| 1269 | bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc); |
| 1270 | } |
| 1271 | |
Ariel Elior | b93288d | 2013-01-01 05:22:35 +0000 | [diff] [blame] | 1272 | static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 1273 | struct bnx2x_vf_mbx *mbx) |
| 1274 | { |
| 1275 | struct vfpf_init_tlv *init = &mbx->msg->req.init; |
| 1276 | |
| 1277 | /* record ghost addresses from vf message */ |
| 1278 | vf->spq_map = init->spq_addr; |
| 1279 | vf->fw_stat_map = init->stats_addr; |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 1280 | vf->stats_stride = init->stats_stride; |
Ariel Elior | b93288d | 2013-01-01 05:22:35 +0000 | [diff] [blame] | 1281 | vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr); |
| 1282 | |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 1283 | /* set VF multiqueue statistics collection mode */ |
| 1284 | if (init->flags & VFPF_INIT_FLG_STATS_COALESCE) |
| 1285 | vf->cfg_flags |= VF_CFG_STATS_COALESCE; |
| 1286 | |
Ariel Elior | b93288d | 2013-01-01 05:22:35 +0000 | [diff] [blame] | 1287 | /* response */ |
| 1288 | bnx2x_vf_mbx_resp(bp, vf); |
| 1289 | } |
| 1290 | |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1291 | /* convert MBX queue-flags to standard SP queue-flags */ |
Ariel Elior | 2177653 | 2013-03-27 01:05:16 +0000 | [diff] [blame] | 1292 | static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags, |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1293 | unsigned long *sp_q_flags) |
| 1294 | { |
| 1295 | if (mbx_q_flags & VFPF_QUEUE_FLG_TPA) |
| 1296 | __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags); |
| 1297 | if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6) |
| 1298 | __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags); |
| 1299 | if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO) |
| 1300 | __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags); |
| 1301 | if (mbx_q_flags & VFPF_QUEUE_FLG_STATS) |
| 1302 | __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags); |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1303 | if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN) |
| 1304 | __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags); |
| 1305 | if (mbx_q_flags & VFPF_QUEUE_FLG_COS) |
| 1306 | __set_bit(BNX2X_Q_FLG_COS, sp_q_flags); |
| 1307 | if (mbx_q_flags & VFPF_QUEUE_FLG_HC) |
| 1308 | __set_bit(BNX2X_Q_FLG_HC, sp_q_flags); |
| 1309 | if (mbx_q_flags & VFPF_QUEUE_FLG_DHC) |
| 1310 | __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags); |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 1311 | if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS) |
| 1312 | __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags); |
Ariel Elior | 2177653 | 2013-03-27 01:05:16 +0000 | [diff] [blame] | 1313 | |
Yuval Mintz | 16a5fd9 | 2013-06-02 00:06:18 +0000 | [diff] [blame] | 1314 | /* outer vlan removal is set according to PF's multi function mode */ |
Ariel Elior | 2177653 | 2013-03-27 01:05:16 +0000 | [diff] [blame] | 1315 | if (IS_MF_SD(bp)) |
| 1316 | __set_bit(BNX2X_Q_FLG_OV, sp_q_flags); |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 1320 | struct bnx2x_vf_mbx *mbx) |
| 1321 | { |
| 1322 | struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q; |
| 1323 | struct bnx2x_vfop_cmd cmd = { |
| 1324 | .done = bnx2x_vf_mbx_resp, |
| 1325 | .block = false, |
| 1326 | }; |
| 1327 | |
| 1328 | /* verify vf_qid */ |
| 1329 | if (setup_q->vf_qid >= vf_rxq_count(vf)) { |
| 1330 | BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n", |
| 1331 | setup_q->vf_qid, vf_rxq_count(vf)); |
| 1332 | vf->op_rc = -EINVAL; |
| 1333 | goto response; |
| 1334 | } |
| 1335 | |
| 1336 | /* tx queues must be setup alongside rx queues thus if the rx queue |
| 1337 | * is not marked as valid there's nothing to do. |
| 1338 | */ |
| 1339 | if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) { |
| 1340 | struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid); |
| 1341 | unsigned long q_type = 0; |
| 1342 | |
| 1343 | struct bnx2x_queue_init_params *init_p; |
| 1344 | struct bnx2x_queue_setup_params *setup_p; |
| 1345 | |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 1346 | if (bnx2x_vfq_is_leading(q)) |
| 1347 | bnx2x_leading_vfq_init(bp, vf, q); |
| 1348 | |
Yuval Mintz | 16a5fd9 | 2013-06-02 00:06:18 +0000 | [diff] [blame] | 1349 | /* re-init the VF operation context */ |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1350 | memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor)); |
| 1351 | setup_p = &vf->op_params.qctor.prep_qsetup; |
| 1352 | init_p = &vf->op_params.qctor.qstate.params.init; |
| 1353 | |
| 1354 | /* activate immediately */ |
| 1355 | __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags); |
| 1356 | |
| 1357 | if (setup_q->param_valid & VFPF_TXQ_VALID) { |
| 1358 | struct bnx2x_txq_setup_params *txq_params = |
| 1359 | &setup_p->txq_params; |
| 1360 | |
| 1361 | __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); |
| 1362 | |
| 1363 | /* save sb resource index */ |
| 1364 | q->sb_idx = setup_q->txq.vf_sb; |
| 1365 | |
| 1366 | /* tx init */ |
| 1367 | init_p->tx.hc_rate = setup_q->txq.hc_rate; |
| 1368 | init_p->tx.sb_cq_index = setup_q->txq.sb_index; |
| 1369 | |
Ariel Elior | 2177653 | 2013-03-27 01:05:16 +0000 | [diff] [blame] | 1370 | bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags, |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1371 | &init_p->tx.flags); |
| 1372 | |
| 1373 | /* tx setup - flags */ |
Ariel Elior | 2177653 | 2013-03-27 01:05:16 +0000 | [diff] [blame] | 1374 | bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags, |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1375 | &setup_p->flags); |
| 1376 | |
| 1377 | /* tx setup - general, nothing */ |
| 1378 | |
| 1379 | /* tx setup - tx */ |
| 1380 | txq_params->dscr_map = setup_q->txq.txq_addr; |
| 1381 | txq_params->sb_cq_index = setup_q->txq.sb_index; |
| 1382 | txq_params->traffic_type = setup_q->txq.traffic_type; |
| 1383 | |
| 1384 | bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p, |
| 1385 | q->index, q->sb_idx); |
| 1386 | } |
| 1387 | |
| 1388 | if (setup_q->param_valid & VFPF_RXQ_VALID) { |
| 1389 | struct bnx2x_rxq_setup_params *rxq_params = |
| 1390 | &setup_p->rxq_params; |
| 1391 | |
| 1392 | __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); |
| 1393 | |
| 1394 | /* Note: there is no support for different SBs |
| 1395 | * for TX and RX |
| 1396 | */ |
| 1397 | q->sb_idx = setup_q->rxq.vf_sb; |
| 1398 | |
| 1399 | /* rx init */ |
| 1400 | init_p->rx.hc_rate = setup_q->rxq.hc_rate; |
| 1401 | init_p->rx.sb_cq_index = setup_q->rxq.sb_index; |
Ariel Elior | 2177653 | 2013-03-27 01:05:16 +0000 | [diff] [blame] | 1402 | bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags, |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1403 | &init_p->rx.flags); |
| 1404 | |
| 1405 | /* rx setup - flags */ |
Ariel Elior | 2177653 | 2013-03-27 01:05:16 +0000 | [diff] [blame] | 1406 | bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags, |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1407 | &setup_p->flags); |
| 1408 | |
| 1409 | /* rx setup - general */ |
| 1410 | setup_p->gen_params.mtu = setup_q->rxq.mtu; |
| 1411 | |
| 1412 | /* rx setup - rx */ |
| 1413 | rxq_params->drop_flags = setup_q->rxq.drop_flags; |
| 1414 | rxq_params->dscr_map = setup_q->rxq.rxq_addr; |
| 1415 | rxq_params->sge_map = setup_q->rxq.sge_addr; |
| 1416 | rxq_params->rcq_map = setup_q->rxq.rcq_addr; |
| 1417 | rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr; |
| 1418 | rxq_params->buf_sz = setup_q->rxq.buf_sz; |
| 1419 | rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz; |
| 1420 | rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt; |
| 1421 | rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz; |
| 1422 | rxq_params->cache_line_log = |
| 1423 | setup_q->rxq.cache_line_log; |
| 1424 | rxq_params->sb_cq_index = setup_q->rxq.sb_index; |
| 1425 | |
Yuval Mintz | 858f4deb | 2013-12-26 09:57:12 +0200 | [diff] [blame] | 1426 | /* rx setup - multicast engine */ |
| 1427 | if (bnx2x_vfq_is_leading(q)) { |
| 1428 | u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid); |
| 1429 | |
| 1430 | rxq_params->mcast_engine_id = mcast_id; |
| 1431 | __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags); |
| 1432 | } |
| 1433 | |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1434 | bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p, |
| 1435 | q->index, q->sb_idx); |
| 1436 | } |
| 1437 | /* complete the preparations */ |
| 1438 | bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type); |
| 1439 | |
| 1440 | vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index); |
| 1441 | if (vf->op_rc) |
| 1442 | goto response; |
| 1443 | return; |
| 1444 | } |
| 1445 | response: |
| 1446 | bnx2x_vf_mbx_resp(bp, vf); |
| 1447 | } |
| 1448 | |
Ariel Elior | 954ea74 | 2013-01-01 05:22:38 +0000 | [diff] [blame] | 1449 | enum bnx2x_vfop_filters_state { |
| 1450 | BNX2X_VFOP_MBX_Q_FILTERS_MACS, |
| 1451 | BNX2X_VFOP_MBX_Q_FILTERS_VLANS, |
| 1452 | BNX2X_VFOP_MBX_Q_FILTERS_RXMODE, |
| 1453 | BNX2X_VFOP_MBX_Q_FILTERS_MCAST, |
| 1454 | BNX2X_VFOP_MBX_Q_FILTERS_DONE |
| 1455 | }; |
| 1456 | |
| 1457 | static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp, |
| 1458 | struct bnx2x_virtf *vf, |
| 1459 | struct vfpf_set_q_filters_tlv *tlv, |
| 1460 | struct bnx2x_vfop_filters **pfl, |
| 1461 | u32 type_flag) |
| 1462 | { |
| 1463 | int i, j; |
| 1464 | struct bnx2x_vfop_filters *fl = NULL; |
| 1465 | size_t fsz; |
| 1466 | |
| 1467 | fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) + |
| 1468 | sizeof(struct bnx2x_vfop_filters); |
| 1469 | |
| 1470 | fl = kzalloc(fsz, GFP_KERNEL); |
| 1471 | if (!fl) |
| 1472 | return -ENOMEM; |
| 1473 | |
| 1474 | INIT_LIST_HEAD(&fl->head); |
| 1475 | |
| 1476 | for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) { |
| 1477 | struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i]; |
| 1478 | |
| 1479 | if ((msg_filter->flags & type_flag) != type_flag) |
| 1480 | continue; |
| 1481 | if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) { |
| 1482 | fl->filters[j].mac = msg_filter->mac; |
| 1483 | fl->filters[j].type = BNX2X_VFOP_FILTER_MAC; |
| 1484 | } else { |
| 1485 | fl->filters[j].vid = msg_filter->vlan_tag; |
| 1486 | fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN; |
| 1487 | } |
| 1488 | fl->filters[j].add = |
| 1489 | (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ? |
| 1490 | true : false; |
| 1491 | list_add_tail(&fl->filters[j++].link, &fl->head); |
| 1492 | } |
| 1493 | if (list_empty(&fl->head)) |
| 1494 | kfree(fl); |
| 1495 | else |
| 1496 | *pfl = fl; |
| 1497 | |
| 1498 | return 0; |
| 1499 | } |
| 1500 | |
| 1501 | static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx, |
| 1502 | struct vfpf_q_mac_vlan_filter *filter) |
| 1503 | { |
| 1504 | DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags); |
| 1505 | if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID) |
| 1506 | DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag); |
| 1507 | if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID) |
| 1508 | DP_CONT(msglvl, ", MAC=%pM", filter->mac); |
| 1509 | DP_CONT(msglvl, "\n"); |
| 1510 | } |
| 1511 | |
| 1512 | static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl, |
| 1513 | struct vfpf_set_q_filters_tlv *filters) |
| 1514 | { |
| 1515 | int i; |
| 1516 | |
| 1517 | if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) |
| 1518 | for (i = 0; i < filters->n_mac_vlan_filters; i++) |
| 1519 | bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i, |
| 1520 | &filters->filters[i]); |
| 1521 | |
| 1522 | if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) |
| 1523 | DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask); |
| 1524 | |
| 1525 | if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) |
| 1526 | for (i = 0; i < filters->n_multicast; i++) |
| 1527 | DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]); |
| 1528 | } |
| 1529 | |
| 1530 | #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID |
| 1531 | #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID |
| 1532 | |
| 1533 | static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf) |
| 1534 | { |
| 1535 | int rc; |
| 1536 | |
| 1537 | struct vfpf_set_q_filters_tlv *msg = |
| 1538 | &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters; |
| 1539 | |
| 1540 | struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf); |
| 1541 | enum bnx2x_vfop_filters_state state = vfop->state; |
| 1542 | |
| 1543 | struct bnx2x_vfop_cmd cmd = { |
| 1544 | .done = bnx2x_vfop_mbx_qfilters, |
| 1545 | .block = false, |
| 1546 | }; |
| 1547 | |
| 1548 | DP(BNX2X_MSG_IOV, "STATE: %d\n", state); |
| 1549 | |
| 1550 | if (vfop->rc < 0) |
| 1551 | goto op_err; |
| 1552 | |
| 1553 | switch (state) { |
| 1554 | case BNX2X_VFOP_MBX_Q_FILTERS_MACS: |
| 1555 | /* next state */ |
| 1556 | vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS; |
| 1557 | |
| 1558 | /* check for any vlan/mac changes */ |
| 1559 | if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) { |
| 1560 | /* build mac list */ |
| 1561 | struct bnx2x_vfop_filters *fl = NULL; |
| 1562 | |
| 1563 | vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl, |
| 1564 | VFPF_MAC_FILTER); |
| 1565 | if (vfop->rc) |
| 1566 | goto op_err; |
| 1567 | |
| 1568 | if (fl) { |
| 1569 | /* set mac list */ |
| 1570 | rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl, |
| 1571 | msg->vf_qid, |
| 1572 | false); |
| 1573 | if (rc) { |
| 1574 | vfop->rc = rc; |
| 1575 | goto op_err; |
| 1576 | } |
| 1577 | return; |
| 1578 | } |
| 1579 | } |
| 1580 | /* fall through */ |
| 1581 | |
| 1582 | case BNX2X_VFOP_MBX_Q_FILTERS_VLANS: |
| 1583 | /* next state */ |
| 1584 | vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE; |
| 1585 | |
| 1586 | /* check for any vlan/mac changes */ |
| 1587 | if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) { |
| 1588 | /* build vlan list */ |
| 1589 | struct bnx2x_vfop_filters *fl = NULL; |
| 1590 | |
| 1591 | vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl, |
| 1592 | VFPF_VLAN_FILTER); |
| 1593 | if (vfop->rc) |
| 1594 | goto op_err; |
| 1595 | |
| 1596 | if (fl) { |
| 1597 | /* set vlan list */ |
| 1598 | rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl, |
| 1599 | msg->vf_qid, |
| 1600 | false); |
| 1601 | if (rc) { |
| 1602 | vfop->rc = rc; |
| 1603 | goto op_err; |
| 1604 | } |
| 1605 | return; |
| 1606 | } |
| 1607 | } |
| 1608 | /* fall through */ |
| 1609 | |
| 1610 | case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE: |
| 1611 | /* next state */ |
| 1612 | vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST; |
| 1613 | |
| 1614 | if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) { |
| 1615 | unsigned long accept = 0; |
Yuval Mintz | e8379c7 | 2014-01-05 18:33:54 +0200 | [diff] [blame] | 1616 | struct pf_vf_bulletin_content *bulletin = |
| 1617 | BP_VF_BULLETIN(bp, vf->index); |
Ariel Elior | 954ea74 | 2013-01-01 05:22:38 +0000 | [diff] [blame] | 1618 | |
| 1619 | /* covert VF-PF if mask to bnx2x accept flags */ |
| 1620 | if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST) |
| 1621 | __set_bit(BNX2X_ACCEPT_UNICAST, &accept); |
| 1622 | |
| 1623 | if (msg->rx_mask & |
| 1624 | VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST) |
| 1625 | __set_bit(BNX2X_ACCEPT_MULTICAST, &accept); |
| 1626 | |
| 1627 | if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST) |
| 1628 | __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept); |
| 1629 | |
| 1630 | if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST) |
| 1631 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept); |
| 1632 | |
| 1633 | if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST) |
| 1634 | __set_bit(BNX2X_ACCEPT_BROADCAST, &accept); |
| 1635 | |
| 1636 | /* A packet arriving the vf's mac should be accepted |
Yuval Mintz | e8379c7 | 2014-01-05 18:33:54 +0200 | [diff] [blame] | 1637 | * with any vlan, unless a vlan has already been |
| 1638 | * configured. |
Ariel Elior | 954ea74 | 2013-01-01 05:22:38 +0000 | [diff] [blame] | 1639 | */ |
Yuval Mintz | e8379c7 | 2014-01-05 18:33:54 +0200 | [diff] [blame] | 1640 | if (!(bulletin->valid_bitmap & (1 << VLAN_VALID))) |
| 1641 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept); |
Ariel Elior | 954ea74 | 2013-01-01 05:22:38 +0000 | [diff] [blame] | 1642 | |
| 1643 | /* set rx-mode */ |
| 1644 | rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd, |
| 1645 | msg->vf_qid, accept); |
| 1646 | if (rc) { |
| 1647 | vfop->rc = rc; |
| 1648 | goto op_err; |
| 1649 | } |
| 1650 | return; |
| 1651 | } |
| 1652 | /* fall through */ |
| 1653 | |
| 1654 | case BNX2X_VFOP_MBX_Q_FILTERS_MCAST: |
| 1655 | /* next state */ |
| 1656 | vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE; |
| 1657 | |
| 1658 | if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) { |
| 1659 | /* set mcasts */ |
| 1660 | rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast, |
| 1661 | msg->n_multicast, false); |
| 1662 | if (rc) { |
| 1663 | vfop->rc = rc; |
| 1664 | goto op_err; |
| 1665 | } |
| 1666 | return; |
| 1667 | } |
| 1668 | /* fall through */ |
| 1669 | op_done: |
| 1670 | case BNX2X_VFOP_MBX_Q_FILTERS_DONE: |
| 1671 | bnx2x_vfop_end(bp, vf, vfop); |
| 1672 | return; |
| 1673 | op_err: |
| 1674 | BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n", |
| 1675 | vf->abs_vfid, msg->vf_qid, vfop->rc); |
| 1676 | goto op_done; |
| 1677 | |
| 1678 | default: |
| 1679 | bnx2x_vfop_default(state); |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp, |
| 1684 | struct bnx2x_virtf *vf, |
| 1685 | struct bnx2x_vfop_cmd *cmd) |
| 1686 | { |
| 1687 | struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf); |
| 1688 | if (vfop) { |
| 1689 | bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS, |
| 1690 | bnx2x_vfop_mbx_qfilters, cmd->done); |
| 1691 | return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters, |
| 1692 | cmd->block); |
| 1693 | } |
| 1694 | return -ENOMEM; |
| 1695 | } |
| 1696 | |
| 1697 | static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp, |
| 1698 | struct bnx2x_virtf *vf, |
| 1699 | struct bnx2x_vf_mbx *mbx) |
| 1700 | { |
| 1701 | struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters; |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 1702 | struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index); |
Ariel Elior | 954ea74 | 2013-01-01 05:22:38 +0000 | [diff] [blame] | 1703 | struct bnx2x_vfop_cmd cmd = { |
| 1704 | .done = bnx2x_vf_mbx_resp, |
| 1705 | .block = false, |
| 1706 | }; |
| 1707 | |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 1708 | /* if a mac was already set for this VF via the set vf mac ndo, we only |
| 1709 | * accept mac configurations of that mac. Why accept them at all? |
| 1710 | * because PF may have been unable to configure the mac at the time |
| 1711 | * since queue was not set up. |
| 1712 | */ |
| 1713 | if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) { |
| 1714 | /* once a mac was set by ndo can only accept a single mac... */ |
| 1715 | if (filters->n_mac_vlan_filters > 1) { |
| 1716 | BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n", |
| 1717 | vf->abs_vfid); |
| 1718 | vf->op_rc = -EPERM; |
| 1719 | goto response; |
| 1720 | } |
| 1721 | |
| 1722 | /* ...and only the mac set by the ndo */ |
| 1723 | if (filters->n_mac_vlan_filters == 1 && |
dingtianhong | 8fd90de | 2013-12-30 15:40:32 +0800 | [diff] [blame] | 1724 | !ether_addr_equal(filters->filters->mac, bulletin->mac)) { |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 1725 | BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n", |
| 1726 | vf->abs_vfid); |
| 1727 | |
| 1728 | vf->op_rc = -EPERM; |
| 1729 | goto response; |
| 1730 | } |
| 1731 | } |
Yuval Mintz | e8379c7 | 2014-01-05 18:33:54 +0200 | [diff] [blame] | 1732 | /* if vlan was set by hypervisor we don't allow guest to config vlan */ |
| 1733 | if (bulletin->valid_bitmap & 1 << VLAN_VALID) { |
| 1734 | int i; |
| 1735 | |
| 1736 | /* search for vlan filters */ |
| 1737 | for (i = 0; i < filters->n_mac_vlan_filters; i++) { |
| 1738 | if (filters->filters[i].flags & |
| 1739 | VFPF_Q_FILTER_VLAN_TAG_VALID) { |
| 1740 | BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n", |
| 1741 | vf->abs_vfid); |
| 1742 | vf->op_rc = -EPERM; |
| 1743 | goto response; |
| 1744 | } |
| 1745 | } |
| 1746 | } |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 1747 | |
Ariel Elior | 954ea74 | 2013-01-01 05:22:38 +0000 | [diff] [blame] | 1748 | /* verify vf_qid */ |
| 1749 | if (filters->vf_qid > vf_rxq_count(vf)) |
| 1750 | goto response; |
| 1751 | |
| 1752 | DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n", |
| 1753 | vf->abs_vfid, |
| 1754 | filters->vf_qid); |
| 1755 | |
| 1756 | /* print q_filter message */ |
| 1757 | bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters); |
| 1758 | |
| 1759 | vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd); |
| 1760 | if (vf->op_rc) |
| 1761 | goto response; |
| 1762 | return; |
| 1763 | |
| 1764 | response: |
| 1765 | bnx2x_vf_mbx_resp(bp, vf); |
| 1766 | } |
| 1767 | |
Ariel Elior | 463a68a | 2013-01-01 05:22:39 +0000 | [diff] [blame] | 1768 | static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 1769 | struct bnx2x_vf_mbx *mbx) |
| 1770 | { |
| 1771 | int qid = mbx->msg->req.q_op.vf_qid; |
| 1772 | struct bnx2x_vfop_cmd cmd = { |
| 1773 | .done = bnx2x_vf_mbx_resp, |
| 1774 | .block = false, |
| 1775 | }; |
| 1776 | |
| 1777 | DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n", |
| 1778 | vf->abs_vfid, qid); |
| 1779 | |
| 1780 | vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid); |
| 1781 | if (vf->op_rc) |
| 1782 | bnx2x_vf_mbx_resp(bp, vf); |
| 1783 | } |
| 1784 | |
Ariel Elior | 99e9d21 | 2013-01-01 05:22:40 +0000 | [diff] [blame] | 1785 | static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 1786 | struct bnx2x_vf_mbx *mbx) |
| 1787 | { |
| 1788 | struct bnx2x_vfop_cmd cmd = { |
| 1789 | .done = bnx2x_vf_mbx_resp, |
| 1790 | .block = false, |
| 1791 | }; |
| 1792 | |
| 1793 | DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid); |
| 1794 | |
| 1795 | vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd); |
| 1796 | if (vf->op_rc) |
| 1797 | bnx2x_vf_mbx_resp(bp, vf); |
| 1798 | } |
| 1799 | |
Ariel Elior | f1929b0 | 2013-01-01 05:22:41 +0000 | [diff] [blame] | 1800 | static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 1801 | struct bnx2x_vf_mbx *mbx) |
| 1802 | { |
| 1803 | struct bnx2x_vfop_cmd cmd = { |
| 1804 | .done = bnx2x_vf_mbx_resp, |
| 1805 | .block = false, |
| 1806 | }; |
| 1807 | |
| 1808 | DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid); |
| 1809 | |
| 1810 | vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd); |
| 1811 | if (vf->op_rc) |
| 1812 | bnx2x_vf_mbx_resp(bp, vf); |
| 1813 | } |
| 1814 | |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 1815 | static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 1816 | struct bnx2x_vf_mbx *mbx) |
| 1817 | { |
| 1818 | struct bnx2x_vfop_cmd cmd = { |
| 1819 | .done = bnx2x_vf_mbx_resp, |
| 1820 | .block = false, |
| 1821 | }; |
| 1822 | struct bnx2x_config_rss_params *vf_op_params = &vf->op_params.rss; |
| 1823 | struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss; |
| 1824 | |
| 1825 | if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE || |
| 1826 | rss_tlv->rss_key_size != T_ETH_RSS_KEY) { |
| 1827 | BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n", |
| 1828 | vf->index); |
| 1829 | vf->op_rc = -EINVAL; |
| 1830 | goto mbx_resp; |
| 1831 | } |
| 1832 | |
| 1833 | /* set vfop params according to rss tlv */ |
| 1834 | memcpy(vf_op_params->ind_table, rss_tlv->ind_table, |
| 1835 | T_ETH_INDIRECTION_TABLE_SIZE); |
| 1836 | memcpy(vf_op_params->rss_key, rss_tlv->rss_key, |
| 1837 | sizeof(rss_tlv->rss_key)); |
| 1838 | vf_op_params->rss_obj = &vf->rss_conf_obj; |
| 1839 | vf_op_params->rss_result_mask = rss_tlv->rss_result_mask; |
| 1840 | |
| 1841 | /* flags handled individually for backward/forward compatability */ |
Michal Kalderon | 5b62291 | 2014-01-05 18:33:52 +0200 | [diff] [blame] | 1842 | vf_op_params->rss_flags = 0; |
| 1843 | vf_op_params->ramrod_flags = 0; |
| 1844 | |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 1845 | if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED) |
| 1846 | __set_bit(BNX2X_RSS_MODE_DISABLED, &vf_op_params->rss_flags); |
| 1847 | if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR) |
| 1848 | __set_bit(BNX2X_RSS_MODE_REGULAR, &vf_op_params->rss_flags); |
| 1849 | if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH) |
| 1850 | __set_bit(BNX2X_RSS_SET_SRCH, &vf_op_params->rss_flags); |
| 1851 | if (rss_tlv->rss_flags & VFPF_RSS_IPV4) |
| 1852 | __set_bit(BNX2X_RSS_IPV4, &vf_op_params->rss_flags); |
| 1853 | if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) |
| 1854 | __set_bit(BNX2X_RSS_IPV4_TCP, &vf_op_params->rss_flags); |
| 1855 | if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) |
| 1856 | __set_bit(BNX2X_RSS_IPV4_UDP, &vf_op_params->rss_flags); |
| 1857 | if (rss_tlv->rss_flags & VFPF_RSS_IPV6) |
| 1858 | __set_bit(BNX2X_RSS_IPV6, &vf_op_params->rss_flags); |
| 1859 | if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) |
| 1860 | __set_bit(BNX2X_RSS_IPV6_TCP, &vf_op_params->rss_flags); |
| 1861 | if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP) |
| 1862 | __set_bit(BNX2X_RSS_IPV6_UDP, &vf_op_params->rss_flags); |
| 1863 | |
| 1864 | if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) && |
| 1865 | rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) || |
| 1866 | (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) && |
| 1867 | rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) { |
| 1868 | BNX2X_ERR("about to hit a FW assert. aborting...\n"); |
| 1869 | vf->op_rc = -EINVAL; |
| 1870 | goto mbx_resp; |
| 1871 | } |
| 1872 | |
| 1873 | vf->op_rc = bnx2x_vfop_rss_cmd(bp, vf, &cmd); |
| 1874 | |
| 1875 | mbx_resp: |
| 1876 | if (vf->op_rc) |
| 1877 | bnx2x_vf_mbx_resp(bp, vf); |
| 1878 | } |
| 1879 | |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 1880 | /* dispatch request */ |
| 1881 | static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf, |
| 1882 | struct bnx2x_vf_mbx *mbx) |
| 1883 | { |
| 1884 | int i; |
| 1885 | |
| 1886 | /* check if tlv type is known */ |
| 1887 | if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) { |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1888 | /* Lock the per vf op mutex and note the locker's identity. |
| 1889 | * The unlock will take place in mbx response. |
| 1890 | */ |
| 1891 | bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); |
| 1892 | |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 1893 | /* switch on the opcode */ |
| 1894 | switch (mbx->first_tlv.tl.type) { |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1895 | case CHANNEL_TLV_ACQUIRE: |
| 1896 | bnx2x_vf_mbx_acquire(bp, vf, mbx); |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1897 | return; |
Ariel Elior | b93288d | 2013-01-01 05:22:35 +0000 | [diff] [blame] | 1898 | case CHANNEL_TLV_INIT: |
| 1899 | bnx2x_vf_mbx_init_vf(bp, vf, mbx); |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1900 | return; |
Ariel Elior | 8db573b | 2013-01-01 05:22:37 +0000 | [diff] [blame] | 1901 | case CHANNEL_TLV_SETUP_Q: |
| 1902 | bnx2x_vf_mbx_setup_q(bp, vf, mbx); |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1903 | return; |
Ariel Elior | 954ea74 | 2013-01-01 05:22:38 +0000 | [diff] [blame] | 1904 | case CHANNEL_TLV_SET_Q_FILTERS: |
| 1905 | bnx2x_vf_mbx_set_q_filters(bp, vf, mbx); |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1906 | return; |
Ariel Elior | 463a68a | 2013-01-01 05:22:39 +0000 | [diff] [blame] | 1907 | case CHANNEL_TLV_TEARDOWN_Q: |
| 1908 | bnx2x_vf_mbx_teardown_q(bp, vf, mbx); |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1909 | return; |
Ariel Elior | 99e9d21 | 2013-01-01 05:22:40 +0000 | [diff] [blame] | 1910 | case CHANNEL_TLV_CLOSE: |
| 1911 | bnx2x_vf_mbx_close_vf(bp, vf, mbx); |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1912 | return; |
Ariel Elior | f1929b0 | 2013-01-01 05:22:41 +0000 | [diff] [blame] | 1913 | case CHANNEL_TLV_RELEASE: |
| 1914 | bnx2x_vf_mbx_release_vf(bp, vf, mbx); |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1915 | return; |
Ariel Elior | b9871bc | 2013-09-04 14:09:21 +0300 | [diff] [blame] | 1916 | case CHANNEL_TLV_UPDATE_RSS: |
| 1917 | bnx2x_vf_mbx_update_rss(bp, vf, mbx); |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1918 | return; |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 1919 | } |
Ariel Elior | 463a68a | 2013-01-01 05:22:39 +0000 | [diff] [blame] | 1920 | |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 1921 | } else { |
| 1922 | /* unknown TLV - this may belong to a VF driver from the future |
| 1923 | * - a version written after this PF driver was written, which |
| 1924 | * supports features unknown as of yet. Too bad since we don't |
| 1925 | * support them. Or this may be because someone wrote a crappy |
| 1926 | * VF driver and is sending garbage over the channel. |
| 1927 | */ |
Yuval Mintz | 6bf07b8 | 2013-06-02 00:06:20 +0000 | [diff] [blame] | 1928 | BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n", |
| 1929 | mbx->first_tlv.tl.type, mbx->first_tlv.tl.length, |
| 1930 | vf->state); |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 1931 | for (i = 0; i < 20; i++) |
| 1932 | DP_CONT(BNX2X_MSG_IOV, "%x ", |
| 1933 | mbx->msg->req.tlv_buf_size.tlv_buffer[i]); |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1934 | } |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1935 | |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1936 | /* can we respond to VF (do we have an address for it?) */ |
| 1937 | if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) { |
| 1938 | /* mbx_resp uses the op_rc of the VF */ |
| 1939 | vf->op_rc = PFVF_STATUS_NOT_SUPPORTED; |
| 1940 | |
| 1941 | /* notify the VF that we do not support this request */ |
| 1942 | bnx2x_vf_mbx_resp(bp, vf); |
| 1943 | } else { |
| 1944 | /* can't send a response since this VF is unknown to us |
| 1945 | * just ack the FW to release the mailbox and unlock |
| 1946 | * the channel. |
Ariel Elior | 8ca5e17 | 2013-01-01 05:22:34 +0000 | [diff] [blame] | 1947 | */ |
Ariel Elior | cbbf77d | 2013-09-23 10:12:55 +0300 | [diff] [blame] | 1948 | storm_memset_vf_mbx_ack(bp, vf->abs_vfid); |
| 1949 | /* Firmware ack should be written before unlocking channel */ |
| 1950 | mmiowb(); |
| 1951 | bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | /* handle new vf-pf message */ |
| 1956 | void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event) |
| 1957 | { |
| 1958 | struct bnx2x_virtf *vf; |
| 1959 | struct bnx2x_vf_mbx *mbx; |
| 1960 | u8 vf_idx; |
| 1961 | int rc; |
| 1962 | |
| 1963 | DP(BNX2X_MSG_IOV, |
| 1964 | "vf pf event received: vfid %d, address_hi %x, address lo %x", |
| 1965 | vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo); |
| 1966 | /* Sanity checks consider removing later */ |
| 1967 | |
| 1968 | /* check if the vf_id is valid */ |
| 1969 | if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf > |
| 1970 | BNX2X_NR_VIRTFN(bp)) { |
| 1971 | BNX2X_ERR("Illegal vf_id %d max allowed: %d\n", |
| 1972 | vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp)); |
| 1973 | goto mbx_done; |
| 1974 | } |
| 1975 | vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id); |
| 1976 | mbx = BP_VF_MBX(bp, vf_idx); |
| 1977 | |
| 1978 | /* verify an event is not currently being processed - |
| 1979 | * debug failsafe only |
| 1980 | */ |
| 1981 | if (mbx->flags & VF_MSG_INPROCESS) { |
| 1982 | BNX2X_ERR("Previous message is still being processed, vf_id %d\n", |
| 1983 | vfpf_event->vf_id); |
| 1984 | goto mbx_done; |
| 1985 | } |
| 1986 | vf = BP_VF(bp, vf_idx); |
| 1987 | |
| 1988 | /* save the VF message address */ |
| 1989 | mbx->vf_addr_hi = vfpf_event->msg_addr_hi; |
| 1990 | mbx->vf_addr_lo = vfpf_event->msg_addr_lo; |
| 1991 | DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n", |
| 1992 | mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset); |
| 1993 | |
| 1994 | /* dmae to get the VF request */ |
| 1995 | rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid, |
| 1996 | mbx->vf_addr_hi, mbx->vf_addr_lo, |
| 1997 | sizeof(union vfpf_tlvs)/4); |
| 1998 | if (rc) { |
| 1999 | BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid); |
| 2000 | goto mbx_error; |
| 2001 | } |
| 2002 | |
| 2003 | /* process the VF message header */ |
| 2004 | mbx->first_tlv = mbx->msg->req.first_tlv; |
| 2005 | |
Yuval Mintz | 3d7d562 | 2013-10-09 16:06:28 +0200 | [diff] [blame] | 2006 | /* Clean response buffer to refrain from falsely seeing chains */ |
| 2007 | memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs)); |
| 2008 | |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 2009 | /* dispatch the request (will prepare the response) */ |
| 2010 | bnx2x_vf_mbx_request(bp, vf, mbx); |
| 2011 | goto mbx_done; |
| 2012 | |
| 2013 | mbx_error: |
Ariel Elior | f1929b0 | 2013-01-01 05:22:41 +0000 | [diff] [blame] | 2014 | bnx2x_vf_release(bp, vf, false); /* non blocking */ |
Ariel Elior | fd1fc79 | 2013-01-01 05:22:33 +0000 | [diff] [blame] | 2015 | mbx_done: |
| 2016 | return; |
| 2017 | } |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 2018 | |
| 2019 | /* propagate local bulletin board to vf */ |
| 2020 | int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf) |
| 2021 | { |
| 2022 | struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf); |
| 2023 | dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping + |
| 2024 | vf * BULLETIN_CONTENT_SIZE; |
| 2025 | dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map); |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 2026 | int rc; |
| 2027 | |
| 2028 | /* can only update vf after init took place */ |
| 2029 | if (bnx2x_vf(bp, vf, state) != VF_ENABLED && |
| 2030 | bnx2x_vf(bp, vf, state) != VF_ACQUIRED) |
| 2031 | return 0; |
| 2032 | |
| 2033 | /* increment bulletin board version and compute crc */ |
| 2034 | bulletin->version++; |
Ariel Elior | 4c133c3 | 2013-01-23 03:21:54 +0000 | [diff] [blame] | 2035 | bulletin->length = BULLETIN_CONTENT_SIZE; |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 2036 | bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin); |
| 2037 | |
| 2038 | /* propagate bulletin board via dmae to vm memory */ |
| 2039 | rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, |
| 2040 | bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr), |
Ariel Elior | 4c133c3 | 2013-01-23 03:21:54 +0000 | [diff] [blame] | 2041 | U64_LO(vf_addr), bulletin->length / 4); |
Ariel Elior | abc5a02 | 2013-01-01 05:22:43 +0000 | [diff] [blame] | 2042 | return rc; |
| 2043 | } |