Commit | Line | Data |
---|---|---|
be1f1ffa AE |
1 | /* bnx2x_vfpf.c: Broadcom Everest network driver. |
2 | * | |
247fa82b | 3 | * Copyright 2009-2013 Broadcom Corporation |
be1f1ffa AE |
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" | |
6411280a | 21 | #include "bnx2x_cmn.h" |
b93288d5 | 22 | #include <linux/crc32.h> |
be1f1ffa | 23 | |
a8f47eb7 | 24 | static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx); |
25 | ||
be1f1ffa | 26 | /* place a given tlv on the tlv buffer at a given offset */ |
a8f47eb7 | 27 | static void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, |
28 | u16 offset, u16 type, u16 length) | |
be1f1ffa AE |
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 */ | |
a8f47eb7 | 38 | static void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv, |
39 | u16 type, u16 length) | |
be1f1ffa | 40 | { |
1d6f3cd8 DK |
41 | mutex_lock(&bp->vf2pf_mutex); |
42 | ||
be1f1ffa AE |
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 | ||
1d6f3cd8 | 56 | /* releases the mailbox */ |
a8f47eb7 | 57 | static void bnx2x_vfpf_finalize(struct bnx2x *bp, |
58 | struct vfpf_first_tlv *first_tlv) | |
1d6f3cd8 DK |
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 | ||
3d7d562c YM |
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 | ||
be1f1ffa | 90 | /* list the types and lengths of the tlvs on the buffer */ |
a8f47eb7 | 91 | static void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list) |
be1f1ffa AE |
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 | } | |
b56e9670 | 120 | |
fd1fc79d AE |
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 | ||
732ac8ca | 139 | static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping) |
6411280a AE |
140 | { |
141 | struct cstorm_vf_zone_data __iomem *zone_data = | |
142 | REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START); | |
78c3bcc5 | 143 | int tout = 100, interval = 100; /* wait for 10 seconds */ |
6411280a AE |
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 | ||
78c3bcc5 AE |
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; | |
ffa1cb96 | 158 | return -EINVAL; |
78c3bcc5 AE |
159 | } |
160 | ||
6411280a AE |
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 | ||
732ac8ca | 192 | static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id) |
6411280a AE |
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 | ||
c047e070 | 214 | DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg); |
6411280a AE |
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; | |
3d7d562c | 226 | struct vfpf_port_phys_id_resp_tlv *phys_port_resp; |
6411280a AE |
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 | ||
1d6f3cd8 DK |
233 | if (bnx2x_get_vf_id(bp, &vf_id)) { |
234 | rc = -EAGAIN; | |
235 | goto out; | |
236 | } | |
6411280a AE |
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 | ||
3d7d562c YM |
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 | ||
6411280a | 254 | /* add list termination tlv */ |
3d7d562c YM |
255 | bnx2x_add_tlv(bp, req, |
256 | req->first_tlv.tl.length + sizeof(struct channel_tlv), | |
257 | CHANNEL_TLV_LIST_END, | |
6411280a AE |
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) | |
1d6f3cd8 | 273 | goto out; |
6411280a AE |
274 | |
275 | /* copy acquire response from buffer to bp */ | |
276 | memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp)); | |
277 | ||
278 | attempts++; | |
279 | ||
16a5fd92 | 280 | /* test whether the PF accepted our request. If not, humble |
6411280a AE |
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 = | |
b9871bcf AE |
294 | min(req->resc_request.num_txqs, |
295 | bp->acquire_resp.resc.num_txqs); | |
6411280a | 296 | req->resc_request.num_rxqs = |
b9871bcf AE |
297 | min(req->resc_request.num_rxqs, |
298 | bp->acquire_resp.resc.num_rxqs); | |
6411280a | 299 | req->resc_request.num_sbs = |
b9871bcf AE |
300 | min(req->resc_request.num_sbs, |
301 | bp->acquire_resp.resc.num_sbs); | |
6411280a | 302 | req->resc_request.num_mac_filters = |
b9871bcf AE |
303 | min(req->resc_request.num_mac_filters, |
304 | bp->acquire_resp.resc.num_mac_filters); | |
6411280a | 305 | req->resc_request.num_vlan_filters = |
b9871bcf AE |
306 | min(req->resc_request.num_vlan_filters, |
307 | bp->acquire_resp.resc.num_vlan_filters); | |
6411280a | 308 | req->resc_request.num_mc_filters = |
b9871bcf AE |
309 | min(req->resc_request.num_mc_filters, |
310 | bp->acquire_resp.resc.num_mc_filters); | |
6411280a AE |
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); | |
1d6f3cd8 DK |
319 | rc = -EAGAIN; |
320 | goto out; | |
6411280a AE |
321 | } |
322 | } | |
323 | ||
3d7d562c YM |
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 | ||
6411280a AE |
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; | |
b9871bcf | 345 | bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs; |
6411280a AE |
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 | ||
1d6f3cd8 DK |
355 | out: |
356 | bnx2x_vfpf_finalize(bp, &req->first_tlv); | |
357 | return rc; | |
6411280a AE |
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; | |
1d6f3cd8 | 364 | u32 rc, vf_id; |
6411280a AE |
365 | |
366 | /* clear mailbox and prep first tlv */ | |
367 | bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req)); | |
368 | ||
1d6f3cd8 DK |
369 | if (bnx2x_get_vf_id(bp, &vf_id)) { |
370 | rc = -EAGAIN; | |
371 | goto out; | |
372 | } | |
6411280a AE |
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 */ | |
1d6f3cd8 DK |
388 | goto out; |
389 | ||
6411280a AE |
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 */ | |
6bf07b8e | 395 | BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n", |
6411280a | 396 | resp->hdr.status); |
1d6f3cd8 DK |
397 | rc = -EAGAIN; |
398 | goto out; | |
6411280a | 399 | } |
1d6f3cd8 DK |
400 | out: |
401 | bnx2x_vfpf_finalize(bp, &req->first_tlv); | |
6411280a | 402 | |
1d6f3cd8 | 403 | return rc; |
6411280a AE |
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 | ||
60cad4e6 AE |
425 | req->stats_stride = sizeof(struct per_queue_stats); |
426 | ||
6411280a AE |
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) | |
1d6f3cd8 | 436 | goto out; |
6411280a AE |
437 | |
438 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { | |
439 | BNX2X_ERR("INIT VF failed: %d. Breaking...\n", | |
440 | resp->hdr.status); | |
1d6f3cd8 DK |
441 | rc = -EAGAIN; |
442 | goto out; | |
6411280a AE |
443 | } |
444 | ||
445 | DP(BNX2X_MSG_SP, "INIT VF Succeeded\n"); | |
1d6f3cd8 DK |
446 | out: |
447 | bnx2x_vfpf_finalize(bp, &req->first_tlv); | |
448 | ||
449 | return rc; | |
6411280a AE |
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 | ||
f8f4f61a DK |
470 | /* remove mac */ |
471 | bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false); | |
472 | ||
6411280a AE |
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 | ||
1d6f3cd8 DK |
494 | bnx2x_vfpf_finalize(bp, &req->first_tlv); |
495 | ||
6411280a AE |
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 | ||
b9871bcf AE |
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 | ||
6411280a | 553 | /* ask the pf to open a queue for the vf */ |
60cad4e6 AE |
554 | int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
555 | bool is_leading) | |
6411280a AE |
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; | |
60cad4e6 | 559 | u8 fp_idx = fp->index; |
6411280a AE |
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 | ||
60cad4e6 AE |
575 | if (is_leading) |
576 | flags |= VFPF_QUEUE_FLG_LEADING_RSS; | |
577 | ||
6411280a AE |
578 | /* calculate queue flags */ |
579 | flags |= VFPF_QUEUE_FLG_STATS; | |
580 | flags |= VFPF_QUEUE_FLG_CACHE_ALIGN; | |
6411280a AE |
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); | |
1d6f3cd8 | 631 | rc = -EINVAL; |
6411280a | 632 | } |
1d6f3cd8 DK |
633 | |
634 | bnx2x_vfpf_finalize(bp, &req->first_tlv); | |
635 | ||
6411280a AE |
636 | return rc; |
637 | } | |
638 | ||
a8f47eb7 | 639 | static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx) |
6411280a AE |
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); | |
1d6f3cd8 | 663 | goto out; |
6411280a AE |
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); | |
1d6f3cd8 | 670 | rc = -EINVAL; |
6411280a AE |
671 | } |
672 | ||
1d6f3cd8 DK |
673 | out: |
674 | bnx2x_vfpf_finalize(bp, &req->first_tlv); | |
675 | return rc; | |
6411280a AE |
676 | } |
677 | ||
678 | /* request pf to add a mac for the vf */ | |
f8f4f61a | 679 | int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set) |
6411280a AE |
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; | |
f8f4f61a | 683 | struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content; |
1d6f3cd8 | 684 | int rc = 0; |
6411280a AE |
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; | |
f8f4f61a | 691 | req->vf_qid = vf_qid; |
6411280a | 692 | req->n_mac_vlan_filters = 1; |
f8f4f61a DK |
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; | |
6411280a AE |
697 | |
698 | /* sample bulletin board for new mac */ | |
699 | bnx2x_sample_bulletin(bp); | |
700 | ||
701 | /* copy mac from device to request */ | |
f8f4f61a | 702 | memcpy(req->filters[0].mac, addr, ETH_ALEN); |
6411280a AE |
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); | |
1d6f3cd8 | 715 | goto out; |
6411280a AE |
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 | ||
f8f4f61a DK |
723 | /* copy mac from bulletin to device */ |
724 | memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN); | |
725 | ||
6411280a AE |
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); | |
1d6f3cd8 | 743 | rc = -EINVAL; |
6411280a | 744 | } |
1d6f3cd8 DK |
745 | out: |
746 | bnx2x_vfpf_finalize(bp, &req->first_tlv); | |
6411280a AE |
747 | |
748 | return 0; | |
749 | } | |
750 | ||
60cad4e6 AE |
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) { | |
31b3523c YM |
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); | |
60cad4e6 AE |
813 | } |
814 | out: | |
815 | bnx2x_vfpf_finalize(bp, &req->first_tlv); | |
816 | ||
31b3523c | 817 | return rc; |
60cad4e6 AE |
818 | } |
819 | ||
6411280a AE |
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); | |
1d6f3cd8 | 870 | goto out; |
6411280a AE |
871 | } |
872 | ||
873 | if (resp->hdr.status != PFVF_STATUS_SUCCESS) { | |
874 | BNX2X_ERR("Set Rx mode/multicast failed: %d\n", | |
875 | resp->hdr.status); | |
1d6f3cd8 | 876 | rc = -EINVAL; |
6411280a | 877 | } |
1d6f3cd8 DK |
878 | out: |
879 | bnx2x_vfpf_finalize(bp, &req->first_tlv); | |
6411280a AE |
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); | |
1d6f3cd8 DK |
918 | rc = -EINVAL; |
919 | goto out; | |
6411280a AE |
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); | |
1d6f3cd8 | 938 | rc = -EINVAL; |
6411280a | 939 | } |
1d6f3cd8 DK |
940 | out: |
941 | bnx2x_vfpf_finalize(bp, &req->first_tlv); | |
6411280a AE |
942 | |
943 | return rc; | |
944 | } | |
945 | ||
b56e9670 AE |
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 | ||
16a5fd92 | 971 | /* enable vf_pf mailbox (aka vf-pf-channel) */ |
b56e9670 AE |
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 | } | |
fd1fc79d AE |
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; | |
fd1fc79d AE |
1028 | |
1029 | /* issue the command and wait for completion */ | |
32316a46 | 1030 | return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp)); |
fd1fc79d AE |
1031 | } |
1032 | ||
3d7d562c YM |
1033 | static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp, |
1034 | struct bnx2x_virtf *vf) | |
8ca5e17e AE |
1035 | { |
1036 | struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index); | |
8ca5e17e | 1037 | u16 length, type; |
8ca5e17e AE |
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); | |
3d7d562c YM |
1044 | bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length); |
1045 | bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END, | |
8ca5e17e | 1046 | sizeof(struct channel_list_end_tlv)); |
3d7d562c YM |
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 | ||
8ca5e17e AE |
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 | ||
3d7d562c YM |
1062 | resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc); |
1063 | ||
8ca5e17e AE |
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 | ||
3d7d562c YM |
1070 | /* Copy the response buffer. The first u64 is written afterwards, as |
1071 | * the vf is sensitive to the header being written | |
8ca5e17e | 1072 | */ |
3d7d562c YM |
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; | |
8ca5e17e | 1083 | } |
3d7d562c YM |
1084 | vf_addr -= sizeof(u64); |
1085 | pf_addr -= sizeof(u64); | |
8ca5e17e AE |
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); | |
f1929b01 | 1108 | goto mbx_error; |
8ca5e17e AE |
1109 | } |
1110 | return; | |
f1929b01 AE |
1111 | |
1112 | mbx_error: | |
1113 | bnx2x_vf_release(bp, vf, false); /* non blocking */ | |
8ca5e17e AE |
1114 | } |
1115 | ||
3d7d562c YM |
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 | ||
8ca5e17e AE |
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); | |
3d7d562c | 1153 | u16 length; |
8ca5e17e AE |
1154 | |
1155 | memset(resp, 0, sizeof(*resp)); | |
1156 | ||
1157 | /* fill in pfdev info */ | |
1158 | resp->pfdev_info.chip_num = bp->common.chip_id; | |
b9871bcf | 1159 | resp->pfdev_info.db_size = bp->db_size; |
8ca5e17e AE |
1160 | resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2; |
1161 | resp->pfdev_info.pf_cap = (PFVF_CAP_RSS | | |
14a94ebd MK |
1162 | PFVF_CAP_TPA | |
1163 | PFVF_CAP_TPA_UPDATE); | |
8ca5e17e AE |
1164 | bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver, |
1165 | sizeof(resp->pfdev_info.fw_ver)); | |
1166 | ||
1167 | if (status == PFVF_STATUS_NO_RESOURCE || | |
1168 | status == PFVF_STATUS_SUCCESS) { | |
1169 | /* set resources numbers, if status equals NO_RESOURCE these | |
1170 | * are max possible numbers | |
1171 | */ | |
1172 | resc->num_rxqs = vf_rxq_count(vf) ? : | |
1173 | bnx2x_vf_max_queue_cnt(bp, vf); | |
1174 | resc->num_txqs = vf_txq_count(vf) ? : | |
1175 | bnx2x_vf_max_queue_cnt(bp, vf); | |
1176 | resc->num_sbs = vf_sb_count(vf); | |
1177 | resc->num_mac_filters = vf_mac_rules_cnt(vf); | |
1178 | resc->num_vlan_filters = vf_vlan_rules_cnt(vf); | |
1179 | resc->num_mc_filters = 0; | |
1180 | ||
1181 | if (status == PFVF_STATUS_SUCCESS) { | |
abc5a021 AE |
1182 | /* fill in the allocated resources */ |
1183 | struct pf_vf_bulletin_content *bulletin = | |
1184 | BP_VF_BULLETIN(bp, vf->index); | |
1185 | ||
8ca5e17e AE |
1186 | for_each_vfq(vf, i) |
1187 | resc->hw_qid[i] = | |
1188 | vfq_qzone_id(vf, vfq_get(vf, i)); | |
1189 | ||
1190 | for_each_vf_sb(vf, i) { | |
1191 | resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i); | |
1192 | resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i); | |
1193 | } | |
abc5a021 AE |
1194 | |
1195 | /* if a mac has been set for this vf, supply it */ | |
1196 | if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) { | |
1197 | memcpy(resc->current_mac_addr, bulletin->mac, | |
1198 | ETH_ALEN); | |
1199 | } | |
8ca5e17e AE |
1200 | } |
1201 | } | |
1202 | ||
1203 | 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" | |
1204 | "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n", | |
1205 | vf->abs_vfid, | |
1206 | resp->pfdev_info.chip_num, | |
1207 | resp->pfdev_info.db_size, | |
1208 | resp->pfdev_info.indices_per_sb, | |
1209 | resp->pfdev_info.pf_cap, | |
1210 | resc->num_rxqs, | |
1211 | resc->num_txqs, | |
1212 | resc->num_sbs, | |
1213 | resc->num_mac_filters, | |
1214 | resc->num_vlan_filters, | |
1215 | resc->num_mc_filters, | |
1216 | resp->pfdev_info.fw_ver); | |
1217 | ||
1218 | DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ "); | |
1219 | for (i = 0; i < vf_rxq_count(vf); i++) | |
1220 | DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]); | |
1221 | DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ "); | |
1222 | for (i = 0; i < vf_sb_count(vf); i++) | |
1223 | DP_CONT(BNX2X_MSG_IOV, "%d:%d ", | |
1224 | resc->hw_sbs[i].hw_sb_id, | |
1225 | resc->hw_sbs[i].sb_qid); | |
1226 | DP_CONT(BNX2X_MSG_IOV, "]\n"); | |
1227 | ||
3d7d562c YM |
1228 | /* prepare response */ |
1229 | length = sizeof(struct pfvf_acquire_resp_tlv); | |
1230 | bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length); | |
1231 | ||
1232 | /* Handle possible VF requests for physical port identifiers. | |
1233 | * 'length' should continue to indicate the offset of the first empty | |
1234 | * place in the buffer (i.e., where next TLV should be inserted) | |
1235 | */ | |
1236 | if (bnx2x_search_tlv_list(bp, &mbx->msg->req, | |
1237 | CHANNEL_TLV_PHYS_PORT_ID)) | |
1238 | bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length); | |
1239 | ||
1240 | bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END, | |
1241 | sizeof(struct channel_list_end_tlv)); | |
1242 | ||
8ca5e17e AE |
1243 | /* send the response */ |
1244 | vf->op_rc = vfop_status; | |
3d7d562c | 1245 | bnx2x_vf_mbx_resp_send_msg(bp, vf); |
8ca5e17e AE |
1246 | } |
1247 | ||
1248 | static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf, | |
1249 | struct bnx2x_vf_mbx *mbx) | |
1250 | { | |
1251 | int rc; | |
1252 | struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire; | |
1253 | ||
1254 | /* log vfdef info */ | |
1255 | DP(BNX2X_MSG_IOV, | |
1256 | "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", | |
1257 | vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os, | |
1258 | acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs, | |
1259 | acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters, | |
1260 | acquire->resc_request.num_vlan_filters, | |
1261 | acquire->resc_request.num_mc_filters); | |
1262 | ||
1263 | /* acquire the resources */ | |
1264 | rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request); | |
1265 | ||
abc5a021 AE |
1266 | /* store address of vf's bulletin board */ |
1267 | vf->bulletin_map = acquire->bulletin_addr; | |
1268 | ||
8ca5e17e AE |
1269 | /* response */ |
1270 | bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc); | |
1271 | } | |
1272 | ||
b93288d5 AE |
1273 | static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, |
1274 | struct bnx2x_vf_mbx *mbx) | |
1275 | { | |
1276 | struct vfpf_init_tlv *init = &mbx->msg->req.init; | |
1277 | ||
1278 | /* record ghost addresses from vf message */ | |
1279 | vf->spq_map = init->spq_addr; | |
1280 | vf->fw_stat_map = init->stats_addr; | |
b9871bcf | 1281 | vf->stats_stride = init->stats_stride; |
b93288d5 AE |
1282 | vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr); |
1283 | ||
b9871bcf AE |
1284 | /* set VF multiqueue statistics collection mode */ |
1285 | if (init->flags & VFPF_INIT_FLG_STATS_COALESCE) | |
1286 | vf->cfg_flags |= VF_CFG_STATS_COALESCE; | |
1287 | ||
b93288d5 AE |
1288 | /* response */ |
1289 | bnx2x_vf_mbx_resp(bp, vf); | |
1290 | } | |
1291 | ||
8db573ba | 1292 | /* convert MBX queue-flags to standard SP queue-flags */ |
21776537 | 1293 | static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags, |
8db573ba AE |
1294 | unsigned long *sp_q_flags) |
1295 | { | |
1296 | if (mbx_q_flags & VFPF_QUEUE_FLG_TPA) | |
1297 | __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags); | |
1298 | if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6) | |
1299 | __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags); | |
1300 | if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO) | |
1301 | __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags); | |
1302 | if (mbx_q_flags & VFPF_QUEUE_FLG_STATS) | |
1303 | __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags); | |
8db573ba AE |
1304 | if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN) |
1305 | __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags); | |
1306 | if (mbx_q_flags & VFPF_QUEUE_FLG_COS) | |
1307 | __set_bit(BNX2X_Q_FLG_COS, sp_q_flags); | |
1308 | if (mbx_q_flags & VFPF_QUEUE_FLG_HC) | |
1309 | __set_bit(BNX2X_Q_FLG_HC, sp_q_flags); | |
1310 | if (mbx_q_flags & VFPF_QUEUE_FLG_DHC) | |
1311 | __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags); | |
b9871bcf AE |
1312 | if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS) |
1313 | __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags); | |
21776537 | 1314 | |
16a5fd92 | 1315 | /* outer vlan removal is set according to PF's multi function mode */ |
21776537 AE |
1316 | if (IS_MF_SD(bp)) |
1317 | __set_bit(BNX2X_Q_FLG_OV, sp_q_flags); | |
8db573ba AE |
1318 | } |
1319 | ||
1320 | static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf, | |
1321 | struct bnx2x_vf_mbx *mbx) | |
1322 | { | |
1323 | struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q; | |
1324 | struct bnx2x_vfop_cmd cmd = { | |
1325 | .done = bnx2x_vf_mbx_resp, | |
1326 | .block = false, | |
1327 | }; | |
1328 | ||
1329 | /* verify vf_qid */ | |
1330 | if (setup_q->vf_qid >= vf_rxq_count(vf)) { | |
1331 | BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n", | |
1332 | setup_q->vf_qid, vf_rxq_count(vf)); | |
1333 | vf->op_rc = -EINVAL; | |
1334 | goto response; | |
1335 | } | |
1336 | ||
1337 | /* tx queues must be setup alongside rx queues thus if the rx queue | |
1338 | * is not marked as valid there's nothing to do. | |
1339 | */ | |
1340 | if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) { | |
1341 | struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid); | |
1342 | unsigned long q_type = 0; | |
1343 | ||
1344 | struct bnx2x_queue_init_params *init_p; | |
1345 | struct bnx2x_queue_setup_params *setup_p; | |
1346 | ||
b9871bcf AE |
1347 | if (bnx2x_vfq_is_leading(q)) |
1348 | bnx2x_leading_vfq_init(bp, vf, q); | |
1349 | ||
16a5fd92 | 1350 | /* re-init the VF operation context */ |
8db573ba AE |
1351 | memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor)); |
1352 | setup_p = &vf->op_params.qctor.prep_qsetup; | |
1353 | init_p = &vf->op_params.qctor.qstate.params.init; | |
1354 | ||
1355 | /* activate immediately */ | |
1356 | __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags); | |
1357 | ||
1358 | if (setup_q->param_valid & VFPF_TXQ_VALID) { | |
1359 | struct bnx2x_txq_setup_params *txq_params = | |
1360 | &setup_p->txq_params; | |
1361 | ||
1362 | __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); | |
1363 | ||
1364 | /* save sb resource index */ | |
1365 | q->sb_idx = setup_q->txq.vf_sb; | |
1366 | ||
1367 | /* tx init */ | |
1368 | init_p->tx.hc_rate = setup_q->txq.hc_rate; | |
1369 | init_p->tx.sb_cq_index = setup_q->txq.sb_index; | |
1370 | ||
21776537 | 1371 | bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags, |
8db573ba AE |
1372 | &init_p->tx.flags); |
1373 | ||
1374 | /* tx setup - flags */ | |
21776537 | 1375 | bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags, |
8db573ba AE |
1376 | &setup_p->flags); |
1377 | ||
1378 | /* tx setup - general, nothing */ | |
1379 | ||
1380 | /* tx setup - tx */ | |
1381 | txq_params->dscr_map = setup_q->txq.txq_addr; | |
1382 | txq_params->sb_cq_index = setup_q->txq.sb_index; | |
1383 | txq_params->traffic_type = setup_q->txq.traffic_type; | |
1384 | ||
1385 | bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p, | |
1386 | q->index, q->sb_idx); | |
1387 | } | |
1388 | ||
1389 | if (setup_q->param_valid & VFPF_RXQ_VALID) { | |
1390 | struct bnx2x_rxq_setup_params *rxq_params = | |
1391 | &setup_p->rxq_params; | |
1392 | ||
1393 | __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); | |
1394 | ||
1395 | /* Note: there is no support for different SBs | |
1396 | * for TX and RX | |
1397 | */ | |
1398 | q->sb_idx = setup_q->rxq.vf_sb; | |
1399 | ||
1400 | /* rx init */ | |
1401 | init_p->rx.hc_rate = setup_q->rxq.hc_rate; | |
1402 | init_p->rx.sb_cq_index = setup_q->rxq.sb_index; | |
21776537 | 1403 | bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags, |
8db573ba AE |
1404 | &init_p->rx.flags); |
1405 | ||
1406 | /* rx setup - flags */ | |
21776537 | 1407 | bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags, |
8db573ba AE |
1408 | &setup_p->flags); |
1409 | ||
1410 | /* rx setup - general */ | |
1411 | setup_p->gen_params.mtu = setup_q->rxq.mtu; | |
1412 | ||
1413 | /* rx setup - rx */ | |
1414 | rxq_params->drop_flags = setup_q->rxq.drop_flags; | |
1415 | rxq_params->dscr_map = setup_q->rxq.rxq_addr; | |
1416 | rxq_params->sge_map = setup_q->rxq.sge_addr; | |
1417 | rxq_params->rcq_map = setup_q->rxq.rcq_addr; | |
1418 | rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr; | |
1419 | rxq_params->buf_sz = setup_q->rxq.buf_sz; | |
1420 | rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz; | |
1421 | rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt; | |
1422 | rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz; | |
1423 | rxq_params->cache_line_log = | |
1424 | setup_q->rxq.cache_line_log; | |
1425 | rxq_params->sb_cq_index = setup_q->rxq.sb_index; | |
1426 | ||
858f4deb YM |
1427 | /* rx setup - multicast engine */ |
1428 | if (bnx2x_vfq_is_leading(q)) { | |
1429 | u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid); | |
1430 | ||
1431 | rxq_params->mcast_engine_id = mcast_id; | |
1432 | __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags); | |
1433 | } | |
1434 | ||
8db573ba AE |
1435 | bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p, |
1436 | q->index, q->sb_idx); | |
1437 | } | |
1438 | /* complete the preparations */ | |
1439 | bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type); | |
1440 | ||
1441 | vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index); | |
1442 | if (vf->op_rc) | |
1443 | goto response; | |
1444 | return; | |
1445 | } | |
1446 | response: | |
1447 | bnx2x_vf_mbx_resp(bp, vf); | |
1448 | } | |
1449 | ||
954ea748 AE |
1450 | enum bnx2x_vfop_filters_state { |
1451 | BNX2X_VFOP_MBX_Q_FILTERS_MACS, | |
1452 | BNX2X_VFOP_MBX_Q_FILTERS_VLANS, | |
1453 | BNX2X_VFOP_MBX_Q_FILTERS_RXMODE, | |
1454 | BNX2X_VFOP_MBX_Q_FILTERS_MCAST, | |
1455 | BNX2X_VFOP_MBX_Q_FILTERS_DONE | |
1456 | }; | |
1457 | ||
1458 | static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp, | |
1459 | struct bnx2x_virtf *vf, | |
1460 | struct vfpf_set_q_filters_tlv *tlv, | |
1461 | struct bnx2x_vfop_filters **pfl, | |
1462 | u32 type_flag) | |
1463 | { | |
1464 | int i, j; | |
1465 | struct bnx2x_vfop_filters *fl = NULL; | |
1466 | size_t fsz; | |
1467 | ||
1468 | fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) + | |
1469 | sizeof(struct bnx2x_vfop_filters); | |
1470 | ||
1471 | fl = kzalloc(fsz, GFP_KERNEL); | |
1472 | if (!fl) | |
1473 | return -ENOMEM; | |
1474 | ||
1475 | INIT_LIST_HEAD(&fl->head); | |
1476 | ||
1477 | for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) { | |
1478 | struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i]; | |
1479 | ||
1480 | if ((msg_filter->flags & type_flag) != type_flag) | |
1481 | continue; | |
1482 | if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) { | |
1483 | fl->filters[j].mac = msg_filter->mac; | |
1484 | fl->filters[j].type = BNX2X_VFOP_FILTER_MAC; | |
1485 | } else { | |
1486 | fl->filters[j].vid = msg_filter->vlan_tag; | |
1487 | fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN; | |
1488 | } | |
1489 | fl->filters[j].add = | |
1490 | (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ? | |
1491 | true : false; | |
1492 | list_add_tail(&fl->filters[j++].link, &fl->head); | |
1493 | } | |
1494 | if (list_empty(&fl->head)) | |
1495 | kfree(fl); | |
1496 | else | |
1497 | *pfl = fl; | |
1498 | ||
1499 | return 0; | |
1500 | } | |
1501 | ||
1502 | static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx, | |
1503 | struct vfpf_q_mac_vlan_filter *filter) | |
1504 | { | |
1505 | DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags); | |
1506 | if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID) | |
1507 | DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag); | |
1508 | if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID) | |
1509 | DP_CONT(msglvl, ", MAC=%pM", filter->mac); | |
1510 | DP_CONT(msglvl, "\n"); | |
1511 | } | |
1512 | ||
1513 | static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl, | |
1514 | struct vfpf_set_q_filters_tlv *filters) | |
1515 | { | |
1516 | int i; | |
1517 | ||
1518 | if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) | |
1519 | for (i = 0; i < filters->n_mac_vlan_filters; i++) | |
1520 | bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i, | |
1521 | &filters->filters[i]); | |
1522 | ||
1523 | if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) | |
1524 | DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask); | |
1525 | ||
1526 | if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) | |
1527 | for (i = 0; i < filters->n_multicast; i++) | |
1528 | DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]); | |
1529 | } | |
1530 | ||
1531 | #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID | |
1532 | #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID | |
1533 | ||
1534 | static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf) | |
1535 | { | |
1536 | int rc; | |
1537 | ||
1538 | struct vfpf_set_q_filters_tlv *msg = | |
1539 | &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters; | |
1540 | ||
1541 | struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf); | |
1542 | enum bnx2x_vfop_filters_state state = vfop->state; | |
1543 | ||
1544 | struct bnx2x_vfop_cmd cmd = { | |
1545 | .done = bnx2x_vfop_mbx_qfilters, | |
1546 | .block = false, | |
1547 | }; | |
1548 | ||
1549 | DP(BNX2X_MSG_IOV, "STATE: %d\n", state); | |
1550 | ||
1551 | if (vfop->rc < 0) | |
1552 | goto op_err; | |
1553 | ||
1554 | switch (state) { | |
1555 | case BNX2X_VFOP_MBX_Q_FILTERS_MACS: | |
1556 | /* next state */ | |
1557 | vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS; | |
1558 | ||
1559 | /* check for any vlan/mac changes */ | |
1560 | if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) { | |
1561 | /* build mac list */ | |
1562 | struct bnx2x_vfop_filters *fl = NULL; | |
1563 | ||
1564 | vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl, | |
1565 | VFPF_MAC_FILTER); | |
1566 | if (vfop->rc) | |
1567 | goto op_err; | |
1568 | ||
1569 | if (fl) { | |
1570 | /* set mac list */ | |
1571 | rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl, | |
1572 | msg->vf_qid, | |
1573 | false); | |
1574 | if (rc) { | |
1575 | vfop->rc = rc; | |
1576 | goto op_err; | |
1577 | } | |
1578 | return; | |
1579 | } | |
1580 | } | |
1581 | /* fall through */ | |
1582 | ||
1583 | case BNX2X_VFOP_MBX_Q_FILTERS_VLANS: | |
1584 | /* next state */ | |
1585 | vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE; | |
1586 | ||
1587 | /* check for any vlan/mac changes */ | |
1588 | if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) { | |
1589 | /* build vlan list */ | |
1590 | struct bnx2x_vfop_filters *fl = NULL; | |
1591 | ||
1592 | vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl, | |
1593 | VFPF_VLAN_FILTER); | |
1594 | if (vfop->rc) | |
1595 | goto op_err; | |
1596 | ||
1597 | if (fl) { | |
1598 | /* set vlan list */ | |
1599 | rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl, | |
1600 | msg->vf_qid, | |
1601 | false); | |
1602 | if (rc) { | |
1603 | vfop->rc = rc; | |
1604 | goto op_err; | |
1605 | } | |
1606 | return; | |
1607 | } | |
1608 | } | |
1609 | /* fall through */ | |
1610 | ||
1611 | case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE: | |
1612 | /* next state */ | |
1613 | vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST; | |
1614 | ||
1615 | if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) { | |
1616 | unsigned long accept = 0; | |
e8379c79 YM |
1617 | struct pf_vf_bulletin_content *bulletin = |
1618 | BP_VF_BULLETIN(bp, vf->index); | |
954ea748 AE |
1619 | |
1620 | /* covert VF-PF if mask to bnx2x accept flags */ | |
1621 | if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST) | |
1622 | __set_bit(BNX2X_ACCEPT_UNICAST, &accept); | |
1623 | ||
1624 | if (msg->rx_mask & | |
1625 | VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST) | |
1626 | __set_bit(BNX2X_ACCEPT_MULTICAST, &accept); | |
1627 | ||
1628 | if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST) | |
1629 | __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept); | |
1630 | ||
1631 | if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST) | |
1632 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept); | |
1633 | ||
1634 | if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST) | |
1635 | __set_bit(BNX2X_ACCEPT_BROADCAST, &accept); | |
1636 | ||
1637 | /* A packet arriving the vf's mac should be accepted | |
e8379c79 YM |
1638 | * with any vlan, unless a vlan has already been |
1639 | * configured. | |
954ea748 | 1640 | */ |
e8379c79 YM |
1641 | if (!(bulletin->valid_bitmap & (1 << VLAN_VALID))) |
1642 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept); | |
954ea748 AE |
1643 | |
1644 | /* set rx-mode */ | |
1645 | rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd, | |
1646 | msg->vf_qid, accept); | |
1647 | if (rc) { | |
1648 | vfop->rc = rc; | |
1649 | goto op_err; | |
1650 | } | |
1651 | return; | |
1652 | } | |
1653 | /* fall through */ | |
1654 | ||
1655 | case BNX2X_VFOP_MBX_Q_FILTERS_MCAST: | |
1656 | /* next state */ | |
1657 | vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE; | |
1658 | ||
1659 | if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) { | |
1660 | /* set mcasts */ | |
1661 | rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast, | |
1662 | msg->n_multicast, false); | |
1663 | if (rc) { | |
1664 | vfop->rc = rc; | |
1665 | goto op_err; | |
1666 | } | |
1667 | return; | |
1668 | } | |
1669 | /* fall through */ | |
1670 | op_done: | |
1671 | case BNX2X_VFOP_MBX_Q_FILTERS_DONE: | |
1672 | bnx2x_vfop_end(bp, vf, vfop); | |
1673 | return; | |
1674 | op_err: | |
1675 | BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n", | |
1676 | vf->abs_vfid, msg->vf_qid, vfop->rc); | |
1677 | goto op_done; | |
1678 | ||
1679 | default: | |
1680 | bnx2x_vfop_default(state); | |
1681 | } | |
1682 | } | |
1683 | ||
1684 | static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp, | |
1685 | struct bnx2x_virtf *vf, | |
1686 | struct bnx2x_vfop_cmd *cmd) | |
1687 | { | |
1688 | struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf); | |
1689 | if (vfop) { | |
1690 | bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS, | |
1691 | bnx2x_vfop_mbx_qfilters, cmd->done); | |
1692 | return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters, | |
1693 | cmd->block); | |
1694 | } | |
1695 | return -ENOMEM; | |
1696 | } | |
1697 | ||
ba72f32c YM |
1698 | static int bnx2x_filters_validate_mac(struct bnx2x *bp, |
1699 | struct bnx2x_virtf *vf, | |
1700 | struct vfpf_set_q_filters_tlv *filters) | |
954ea748 | 1701 | { |
abc5a021 | 1702 | struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index); |
ba72f32c | 1703 | int rc = 0; |
954ea748 | 1704 | |
abc5a021 AE |
1705 | /* if a mac was already set for this VF via the set vf mac ndo, we only |
1706 | * accept mac configurations of that mac. Why accept them at all? | |
1707 | * because PF may have been unable to configure the mac at the time | |
1708 | * since queue was not set up. | |
1709 | */ | |
1710 | if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) { | |
1711 | /* once a mac was set by ndo can only accept a single mac... */ | |
1712 | if (filters->n_mac_vlan_filters > 1) { | |
1713 | BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n", | |
1714 | vf->abs_vfid); | |
1715 | vf->op_rc = -EPERM; | |
ba72f32c | 1716 | rc = -EPERM; |
abc5a021 AE |
1717 | goto response; |
1718 | } | |
1719 | ||
1720 | /* ...and only the mac set by the ndo */ | |
1721 | if (filters->n_mac_vlan_filters == 1 && | |
8fd90de8 | 1722 | !ether_addr_equal(filters->filters->mac, bulletin->mac)) { |
abc5a021 AE |
1723 | BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n", |
1724 | vf->abs_vfid); | |
1725 | ||
1726 | vf->op_rc = -EPERM; | |
ba72f32c | 1727 | rc = -EPERM; |
abc5a021 AE |
1728 | goto response; |
1729 | } | |
1730 | } | |
ba72f32c YM |
1731 | |
1732 | response: | |
1733 | return rc; | |
1734 | } | |
1735 | ||
1736 | static int bnx2x_filters_validate_vlan(struct bnx2x *bp, | |
1737 | struct bnx2x_virtf *vf, | |
1738 | struct vfpf_set_q_filters_tlv *filters) | |
1739 | { | |
1740 | struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index); | |
1741 | int rc = 0; | |
1742 | ||
e8379c79 YM |
1743 | /* if vlan was set by hypervisor we don't allow guest to config vlan */ |
1744 | if (bulletin->valid_bitmap & 1 << VLAN_VALID) { | |
1745 | int i; | |
1746 | ||
1747 | /* search for vlan filters */ | |
1748 | for (i = 0; i < filters->n_mac_vlan_filters; i++) { | |
1749 | if (filters->filters[i].flags & | |
1750 | VFPF_Q_FILTER_VLAN_TAG_VALID) { | |
1751 | BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n", | |
1752 | vf->abs_vfid); | |
1753 | vf->op_rc = -EPERM; | |
ba72f32c | 1754 | rc = -EPERM; |
e8379c79 YM |
1755 | goto response; |
1756 | } | |
1757 | } | |
1758 | } | |
abc5a021 | 1759 | |
954ea748 | 1760 | /* verify vf_qid */ |
ba72f32c YM |
1761 | if (filters->vf_qid > vf_rxq_count(vf)) { |
1762 | rc = -EPERM; | |
1763 | goto response; | |
1764 | } | |
1765 | ||
1766 | response: | |
1767 | return rc; | |
1768 | } | |
1769 | ||
1770 | static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp, | |
1771 | struct bnx2x_virtf *vf, | |
1772 | struct bnx2x_vf_mbx *mbx) | |
1773 | { | |
1774 | struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters; | |
1775 | struct bnx2x_vfop_cmd cmd = { | |
1776 | .done = bnx2x_vf_mbx_resp, | |
1777 | .block = false, | |
1778 | }; | |
1779 | ||
1780 | if (bnx2x_filters_validate_mac(bp, vf, filters)) | |
1781 | goto response; | |
1782 | ||
1783 | if (bnx2x_filters_validate_vlan(bp, vf, filters)) | |
954ea748 AE |
1784 | goto response; |
1785 | ||
1786 | DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n", | |
1787 | vf->abs_vfid, | |
1788 | filters->vf_qid); | |
1789 | ||
1790 | /* print q_filter message */ | |
1791 | bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters); | |
1792 | ||
1793 | vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd); | |
1794 | if (vf->op_rc) | |
1795 | goto response; | |
1796 | return; | |
1797 | ||
1798 | response: | |
1799 | bnx2x_vf_mbx_resp(bp, vf); | |
1800 | } | |
1801 | ||
463a68a7 AE |
1802 | static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf, |
1803 | struct bnx2x_vf_mbx *mbx) | |
1804 | { | |
1805 | int qid = mbx->msg->req.q_op.vf_qid; | |
1806 | struct bnx2x_vfop_cmd cmd = { | |
1807 | .done = bnx2x_vf_mbx_resp, | |
1808 | .block = false, | |
1809 | }; | |
1810 | ||
1811 | DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n", | |
1812 | vf->abs_vfid, qid); | |
1813 | ||
1814 | vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid); | |
1815 | if (vf->op_rc) | |
1816 | bnx2x_vf_mbx_resp(bp, vf); | |
1817 | } | |
1818 | ||
99e9d211 AE |
1819 | static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, |
1820 | struct bnx2x_vf_mbx *mbx) | |
1821 | { | |
1822 | struct bnx2x_vfop_cmd cmd = { | |
1823 | .done = bnx2x_vf_mbx_resp, | |
1824 | .block = false, | |
1825 | }; | |
1826 | ||
1827 | DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid); | |
1828 | ||
1829 | vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd); | |
1830 | if (vf->op_rc) | |
1831 | bnx2x_vf_mbx_resp(bp, vf); | |
1832 | } | |
1833 | ||
f1929b01 AE |
1834 | static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, |
1835 | struct bnx2x_vf_mbx *mbx) | |
1836 | { | |
1837 | struct bnx2x_vfop_cmd cmd = { | |
1838 | .done = bnx2x_vf_mbx_resp, | |
1839 | .block = false, | |
1840 | }; | |
1841 | ||
1842 | DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid); | |
1843 | ||
1844 | vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd); | |
1845 | if (vf->op_rc) | |
1846 | bnx2x_vf_mbx_resp(bp, vf); | |
1847 | } | |
1848 | ||
b9871bcf AE |
1849 | static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf, |
1850 | struct bnx2x_vf_mbx *mbx) | |
1851 | { | |
1852 | struct bnx2x_vfop_cmd cmd = { | |
1853 | .done = bnx2x_vf_mbx_resp, | |
1854 | .block = false, | |
1855 | }; | |
1856 | struct bnx2x_config_rss_params *vf_op_params = &vf->op_params.rss; | |
1857 | struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss; | |
1858 | ||
1859 | if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE || | |
1860 | rss_tlv->rss_key_size != T_ETH_RSS_KEY) { | |
1861 | BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n", | |
1862 | vf->index); | |
1863 | vf->op_rc = -EINVAL; | |
1864 | goto mbx_resp; | |
1865 | } | |
1866 | ||
1867 | /* set vfop params according to rss tlv */ | |
1868 | memcpy(vf_op_params->ind_table, rss_tlv->ind_table, | |
1869 | T_ETH_INDIRECTION_TABLE_SIZE); | |
1870 | memcpy(vf_op_params->rss_key, rss_tlv->rss_key, | |
1871 | sizeof(rss_tlv->rss_key)); | |
1872 | vf_op_params->rss_obj = &vf->rss_conf_obj; | |
1873 | vf_op_params->rss_result_mask = rss_tlv->rss_result_mask; | |
1874 | ||
1875 | /* flags handled individually for backward/forward compatability */ | |
5b622918 MK |
1876 | vf_op_params->rss_flags = 0; |
1877 | vf_op_params->ramrod_flags = 0; | |
1878 | ||
b9871bcf AE |
1879 | if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED) |
1880 | __set_bit(BNX2X_RSS_MODE_DISABLED, &vf_op_params->rss_flags); | |
1881 | if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR) | |
1882 | __set_bit(BNX2X_RSS_MODE_REGULAR, &vf_op_params->rss_flags); | |
1883 | if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH) | |
1884 | __set_bit(BNX2X_RSS_SET_SRCH, &vf_op_params->rss_flags); | |
1885 | if (rss_tlv->rss_flags & VFPF_RSS_IPV4) | |
1886 | __set_bit(BNX2X_RSS_IPV4, &vf_op_params->rss_flags); | |
1887 | if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) | |
1888 | __set_bit(BNX2X_RSS_IPV4_TCP, &vf_op_params->rss_flags); | |
1889 | if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) | |
1890 | __set_bit(BNX2X_RSS_IPV4_UDP, &vf_op_params->rss_flags); | |
1891 | if (rss_tlv->rss_flags & VFPF_RSS_IPV6) | |
1892 | __set_bit(BNX2X_RSS_IPV6, &vf_op_params->rss_flags); | |
1893 | if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) | |
1894 | __set_bit(BNX2X_RSS_IPV6_TCP, &vf_op_params->rss_flags); | |
1895 | if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP) | |
1896 | __set_bit(BNX2X_RSS_IPV6_UDP, &vf_op_params->rss_flags); | |
1897 | ||
1898 | if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) && | |
1899 | rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) || | |
1900 | (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) && | |
1901 | rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) { | |
1902 | BNX2X_ERR("about to hit a FW assert. aborting...\n"); | |
1903 | vf->op_rc = -EINVAL; | |
1904 | goto mbx_resp; | |
1905 | } | |
1906 | ||
1907 | vf->op_rc = bnx2x_vfop_rss_cmd(bp, vf, &cmd); | |
1908 | ||
1909 | mbx_resp: | |
1910 | if (vf->op_rc) | |
1911 | bnx2x_vf_mbx_resp(bp, vf); | |
1912 | } | |
1913 | ||
14a94ebd MK |
1914 | static int bnx2x_validate_tpa_params(struct bnx2x *bp, |
1915 | struct vfpf_tpa_tlv *tpa_tlv) | |
1916 | { | |
1917 | int rc = 0; | |
1918 | ||
1919 | if (tpa_tlv->tpa_client_info.max_sges_for_packet > | |
1920 | U_ETH_MAX_SGES_FOR_PACKET) { | |
1921 | rc = -EINVAL; | |
1922 | BNX2X_ERR("TPA update: max_sges received %d, max is %d\n", | |
1923 | tpa_tlv->tpa_client_info.max_sges_for_packet, | |
1924 | U_ETH_MAX_SGES_FOR_PACKET); | |
1925 | } | |
1926 | ||
1927 | if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) { | |
1928 | rc = -EINVAL; | |
1929 | BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n", | |
1930 | tpa_tlv->tpa_client_info.max_tpa_queues, | |
1931 | MAX_AGG_QS(bp)); | |
1932 | } | |
1933 | ||
1934 | return rc; | |
1935 | } | |
1936 | ||
1937 | static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf, | |
1938 | struct bnx2x_vf_mbx *mbx) | |
1939 | { | |
1940 | struct bnx2x_vfop_cmd cmd = { | |
1941 | .done = bnx2x_vf_mbx_resp, | |
1942 | .block = false, | |
1943 | }; | |
1944 | struct bnx2x_queue_update_tpa_params *vf_op_params = | |
1945 | &vf->op_params.qstate.params.update_tpa; | |
1946 | struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa; | |
1947 | ||
1948 | memset(vf_op_params, 0, sizeof(*vf_op_params)); | |
1949 | ||
1950 | if (bnx2x_validate_tpa_params(bp, tpa_tlv)) | |
1951 | goto mbx_resp; | |
1952 | ||
1953 | vf_op_params->complete_on_both_clients = | |
1954 | tpa_tlv->tpa_client_info.complete_on_both_clients; | |
1955 | vf_op_params->dont_verify_thr = | |
1956 | tpa_tlv->tpa_client_info.dont_verify_thr; | |
1957 | vf_op_params->max_agg_sz = | |
1958 | tpa_tlv->tpa_client_info.max_agg_size; | |
1959 | vf_op_params->max_sges_pkt = | |
1960 | tpa_tlv->tpa_client_info.max_sges_for_packet; | |
1961 | vf_op_params->max_tpa_queues = | |
1962 | tpa_tlv->tpa_client_info.max_tpa_queues; | |
1963 | vf_op_params->sge_buff_sz = | |
1964 | tpa_tlv->tpa_client_info.sge_buff_size; | |
1965 | vf_op_params->sge_pause_thr_high = | |
1966 | tpa_tlv->tpa_client_info.sge_pause_thr_high; | |
1967 | vf_op_params->sge_pause_thr_low = | |
1968 | tpa_tlv->tpa_client_info.sge_pause_thr_low; | |
1969 | vf_op_params->tpa_mode = | |
1970 | tpa_tlv->tpa_client_info.tpa_mode; | |
1971 | vf_op_params->update_ipv4 = | |
1972 | tpa_tlv->tpa_client_info.update_ipv4; | |
1973 | vf_op_params->update_ipv6 = | |
1974 | tpa_tlv->tpa_client_info.update_ipv6; | |
1975 | ||
1976 | vf->op_rc = bnx2x_vfop_tpa_cmd(bp, vf, &cmd, tpa_tlv); | |
1977 | ||
1978 | mbx_resp: | |
1979 | if (vf->op_rc) | |
1980 | bnx2x_vf_mbx_resp(bp, vf); | |
1981 | } | |
1982 | ||
fd1fc79d AE |
1983 | /* dispatch request */ |
1984 | static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf, | |
1985 | struct bnx2x_vf_mbx *mbx) | |
1986 | { | |
1987 | int i; | |
1988 | ||
1989 | /* check if tlv type is known */ | |
1990 | if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) { | |
8ca5e17e AE |
1991 | /* Lock the per vf op mutex and note the locker's identity. |
1992 | * The unlock will take place in mbx response. | |
1993 | */ | |
1994 | bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); | |
1995 | ||
fd1fc79d AE |
1996 | /* switch on the opcode */ |
1997 | switch (mbx->first_tlv.tl.type) { | |
8ca5e17e AE |
1998 | case CHANNEL_TLV_ACQUIRE: |
1999 | bnx2x_vf_mbx_acquire(bp, vf, mbx); | |
cbbf77de | 2000 | return; |
b93288d5 AE |
2001 | case CHANNEL_TLV_INIT: |
2002 | bnx2x_vf_mbx_init_vf(bp, vf, mbx); | |
cbbf77de | 2003 | return; |
8db573ba AE |
2004 | case CHANNEL_TLV_SETUP_Q: |
2005 | bnx2x_vf_mbx_setup_q(bp, vf, mbx); | |
cbbf77de | 2006 | return; |
954ea748 AE |
2007 | case CHANNEL_TLV_SET_Q_FILTERS: |
2008 | bnx2x_vf_mbx_set_q_filters(bp, vf, mbx); | |
cbbf77de | 2009 | return; |
463a68a7 AE |
2010 | case CHANNEL_TLV_TEARDOWN_Q: |
2011 | bnx2x_vf_mbx_teardown_q(bp, vf, mbx); | |
cbbf77de | 2012 | return; |
99e9d211 AE |
2013 | case CHANNEL_TLV_CLOSE: |
2014 | bnx2x_vf_mbx_close_vf(bp, vf, mbx); | |
cbbf77de | 2015 | return; |
f1929b01 AE |
2016 | case CHANNEL_TLV_RELEASE: |
2017 | bnx2x_vf_mbx_release_vf(bp, vf, mbx); | |
cbbf77de | 2018 | return; |
b9871bcf AE |
2019 | case CHANNEL_TLV_UPDATE_RSS: |
2020 | bnx2x_vf_mbx_update_rss(bp, vf, mbx); | |
cbbf77de | 2021 | return; |
14a94ebd MK |
2022 | case CHANNEL_TLV_UPDATE_TPA: |
2023 | bnx2x_vf_mbx_update_tpa(bp, vf, mbx); | |
2024 | return; | |
fd1fc79d | 2025 | } |
463a68a7 | 2026 | |
fd1fc79d AE |
2027 | } else { |
2028 | /* unknown TLV - this may belong to a VF driver from the future | |
2029 | * - a version written after this PF driver was written, which | |
2030 | * supports features unknown as of yet. Too bad since we don't | |
2031 | * support them. Or this may be because someone wrote a crappy | |
2032 | * VF driver and is sending garbage over the channel. | |
2033 | */ | |
6bf07b8e YM |
2034 | BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n", |
2035 | mbx->first_tlv.tl.type, mbx->first_tlv.tl.length, | |
2036 | vf->state); | |
fd1fc79d AE |
2037 | for (i = 0; i < 20; i++) |
2038 | DP_CONT(BNX2X_MSG_IOV, "%x ", | |
2039 | mbx->msg->req.tlv_buf_size.tlv_buffer[i]); | |
cbbf77de | 2040 | } |
8ca5e17e | 2041 | |
cbbf77de AE |
2042 | /* can we respond to VF (do we have an address for it?) */ |
2043 | if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) { | |
2044 | /* mbx_resp uses the op_rc of the VF */ | |
2045 | vf->op_rc = PFVF_STATUS_NOT_SUPPORTED; | |
8ca5e17e | 2046 | |
cbbf77de AE |
2047 | /* notify the VF that we do not support this request */ |
2048 | bnx2x_vf_mbx_resp(bp, vf); | |
2049 | } else { | |
2050 | /* can't send a response since this VF is unknown to us | |
2051 | * just ack the FW to release the mailbox and unlock | |
2052 | * the channel. | |
2053 | */ | |
2054 | storm_memset_vf_mbx_ack(bp, vf->abs_vfid); | |
2055 | /* Firmware ack should be written before unlocking channel */ | |
2056 | mmiowb(); | |
2057 | bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); | |
fd1fc79d AE |
2058 | } |
2059 | } | |
2060 | ||
2061 | /* handle new vf-pf message */ | |
2062 | void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event) | |
2063 | { | |
2064 | struct bnx2x_virtf *vf; | |
2065 | struct bnx2x_vf_mbx *mbx; | |
2066 | u8 vf_idx; | |
2067 | int rc; | |
2068 | ||
2069 | DP(BNX2X_MSG_IOV, | |
2070 | "vf pf event received: vfid %d, address_hi %x, address lo %x", | |
2071 | vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo); | |
2072 | /* Sanity checks consider removing later */ | |
2073 | ||
2074 | /* check if the vf_id is valid */ | |
2075 | if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf > | |
2076 | BNX2X_NR_VIRTFN(bp)) { | |
2077 | BNX2X_ERR("Illegal vf_id %d max allowed: %d\n", | |
2078 | vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp)); | |
2079 | goto mbx_done; | |
2080 | } | |
2081 | vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id); | |
2082 | mbx = BP_VF_MBX(bp, vf_idx); | |
2083 | ||
2084 | /* verify an event is not currently being processed - | |
2085 | * debug failsafe only | |
2086 | */ | |
2087 | if (mbx->flags & VF_MSG_INPROCESS) { | |
2088 | BNX2X_ERR("Previous message is still being processed, vf_id %d\n", | |
2089 | vfpf_event->vf_id); | |
2090 | goto mbx_done; | |
2091 | } | |
2092 | vf = BP_VF(bp, vf_idx); | |
2093 | ||
2094 | /* save the VF message address */ | |
2095 | mbx->vf_addr_hi = vfpf_event->msg_addr_hi; | |
2096 | mbx->vf_addr_lo = vfpf_event->msg_addr_lo; | |
2097 | DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n", | |
2098 | mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset); | |
2099 | ||
2100 | /* dmae to get the VF request */ | |
2101 | rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid, | |
2102 | mbx->vf_addr_hi, mbx->vf_addr_lo, | |
2103 | sizeof(union vfpf_tlvs)/4); | |
2104 | if (rc) { | |
2105 | BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid); | |
2106 | goto mbx_error; | |
2107 | } | |
2108 | ||
2109 | /* process the VF message header */ | |
2110 | mbx->first_tlv = mbx->msg->req.first_tlv; | |
2111 | ||
3d7d562c YM |
2112 | /* Clean response buffer to refrain from falsely seeing chains */ |
2113 | memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs)); | |
2114 | ||
fd1fc79d AE |
2115 | /* dispatch the request (will prepare the response) */ |
2116 | bnx2x_vf_mbx_request(bp, vf, mbx); | |
2117 | goto mbx_done; | |
2118 | ||
2119 | mbx_error: | |
f1929b01 | 2120 | bnx2x_vf_release(bp, vf, false); /* non blocking */ |
fd1fc79d AE |
2121 | mbx_done: |
2122 | return; | |
2123 | } | |
abc5a021 AE |
2124 | |
2125 | /* propagate local bulletin board to vf */ | |
2126 | int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf) | |
2127 | { | |
2128 | struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf); | |
2129 | dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping + | |
2130 | vf * BULLETIN_CONTENT_SIZE; | |
2131 | dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map); | |
abc5a021 AE |
2132 | int rc; |
2133 | ||
2134 | /* can only update vf after init took place */ | |
2135 | if (bnx2x_vf(bp, vf, state) != VF_ENABLED && | |
2136 | bnx2x_vf(bp, vf, state) != VF_ACQUIRED) | |
2137 | return 0; | |
2138 | ||
2139 | /* increment bulletin board version and compute crc */ | |
2140 | bulletin->version++; | |
4c133c39 | 2141 | bulletin->length = BULLETIN_CONTENT_SIZE; |
abc5a021 AE |
2142 | bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin); |
2143 | ||
2144 | /* propagate bulletin board via dmae to vm memory */ | |
2145 | rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, | |
2146 | bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr), | |
4c133c39 | 2147 | U64_LO(vf_addr), bulletin->length / 4); |
abc5a021 AE |
2148 | return rc; |
2149 | } |