Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018-2025 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include "ngbe_type.h"
7 : : #include "ngbe_mbx.h"
8 : : #include "ngbe_vf.h"
9 : :
10 : : /* ngbe_virt_clr_reg - Set register to default (power on) state.
11 : : * @hw: pointer to hardware structure
12 : : */
13 : : static void ngbe_virt_clr_reg(struct ngbe_hw *hw)
14 : : {
15 : : u32 vfsrrctl;
16 : :
17 : : /* default values (BUF_SIZE = 2048, HDR_SIZE = 256) */
18 : : vfsrrctl = NGBE_RXCFG_HDRLEN(NGBE_RX_HDR_SIZE);
19 : : vfsrrctl |= NGBE_RXCFG_PKTLEN(NGBE_RX_BUF_SIZE);
20 : :
21 : : wr32m(hw, NGBE_RXCFG(0),
22 : : (NGBE_RXCFG_HDRLEN_MASK | NGBE_RXCFG_PKTLEN_MASK),
23 : : vfsrrctl);
24 : :
25 : :
26 : : ngbe_flush(hw);
27 : : }
28 : :
29 : : /**
30 : : * ngbe_start_hw_vf - Prepare hardware for Tx/Rx
31 : : * @hw: pointer to hardware structure
32 : : *
33 : : * Starts the hardware by filling the bus info structure and media type, clears
34 : : * all on chip counters, initializes receive address registers, multicast
35 : : * table, VLAN filter table, calls routine to set up link and flow control
36 : : * settings, and leaves transmit and receive units disabled and uninitialized
37 : : **/
38 : 0 : s32 ngbe_start_hw_vf(struct ngbe_hw *hw)
39 : : {
40 : : /* Clear adapter stopped flag */
41 : 0 : hw->adapter_stopped = false;
42 : :
43 : 0 : return 0;
44 : : }
45 : :
46 : : /**
47 : : * ngbe_init_hw_vf - virtual function hardware initialization
48 : : * @hw: pointer to hardware structure
49 : : *
50 : : * Initialize the hardware by resetting the hardware and then starting
51 : : * the hardware
52 : : **/
53 : 0 : s32 ngbe_init_hw_vf(struct ngbe_hw *hw)
54 : : {
55 : 0 : s32 status = hw->mac.start_hw(hw);
56 : :
57 : 0 : hw->mac.get_mac_addr(hw, hw->mac.addr);
58 : :
59 : 0 : return status;
60 : : }
61 : :
62 : : /**
63 : : * ngbe_reset_hw_vf - Performs hardware reset
64 : : * @hw: pointer to hardware structure
65 : : *
66 : : * Resets the hardware by resetting the transmit and receive units, masks and
67 : : * clears all interrupts.
68 : : **/
69 : 0 : s32 ngbe_reset_hw_vf(struct ngbe_hw *hw)
70 : : {
71 : : struct ngbe_mbx_info *mbx = &hw->mbx;
72 : : u32 timeout = NGBE_VF_INIT_TIMEOUT;
73 : : s32 ret_val = NGBE_ERR_INVALID_MAC_ADDR;
74 : : u32 msgbuf[NGBE_VF_PERMADDR_MSG_LEN];
75 : : u8 *addr = (u8 *)(&msgbuf[1]);
76 : :
77 : : /* Call adapter stop to disable tx/rx and clear interrupts */
78 : 0 : hw->mac.stop_hw(hw);
79 : :
80 : : /* reset the api version */
81 : 0 : hw->api_version = ngbe_mbox_api_10;
82 : :
83 : : /* backup msix vectors */
84 : 0 : mbx->timeout = NGBE_VF_MBX_INIT_TIMEOUT;
85 : 0 : msgbuf[0] = NGBE_VF_BACKUP;
86 : 0 : mbx->write_posted(hw, msgbuf, 1, 0);
87 : : msec_delay(10);
88 : :
89 : 0 : DEBUGOUT("Issuing a function level reset to MAC");
90 : : wr32(hw, NGBE_VFRST, NGBE_VFRST_SET);
91 : : ngbe_flush(hw);
92 : : msec_delay(50);
93 : :
94 : 0 : hw->offset_loaded = 1;
95 : :
96 : : /* we cannot reset while the RSTI / RSTD bits are asserted */
97 [ # # # # ]: 0 : while (!mbx->check_for_rst(hw, 0) && timeout) {
98 : 0 : timeout--;
99 : 0 : usec_delay(5);
100 : : }
101 : :
102 [ # # ]: 0 : if (!timeout)
103 : : return NGBE_ERR_RESET_FAILED;
104 : :
105 : : /* Reset VF registers to initial values */
106 : : ngbe_virt_clr_reg(hw);
107 : :
108 : : /* mailbox timeout can now become active */
109 : 0 : mbx->timeout = NGBE_VF_MBX_INIT_TIMEOUT;
110 : :
111 : 0 : msgbuf[0] = NGBE_VF_RESET;
112 : 0 : mbx->write_posted(hw, msgbuf, 1, 0);
113 : :
114 : : msec_delay(10);
115 : :
116 : : /*
117 : : * set our "perm_addr" based on info provided by PF
118 : : * also set up the mc_filter_type which is piggy backed
119 : : * on the mac address in word 3
120 : : */
121 : 0 : ret_val = mbx->read_posted(hw, msgbuf,
122 : : NGBE_VF_PERMADDR_MSG_LEN, 0);
123 [ # # ]: 0 : if (ret_val)
124 : : return ret_val;
125 : :
126 [ # # ]: 0 : if (msgbuf[0] != (NGBE_VF_RESET | NGBE_VT_MSGTYPE_ACK) &&
127 : : msgbuf[0] != (NGBE_VF_RESET | NGBE_VT_MSGTYPE_NACK))
128 : : return NGBE_ERR_INVALID_MAC_ADDR;
129 : :
130 [ # # ]: 0 : if (msgbuf[0] == (NGBE_VF_RESET | NGBE_VT_MSGTYPE_ACK))
131 : 0 : memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
132 : :
133 : 0 : hw->mac.mc_filter_type = msgbuf[NGBE_VF_MC_TYPE_WORD];
134 : :
135 : 0 : return ret_val;
136 : : }
137 : :
138 : : /**
139 : : * ngbe_stop_hw_vf - Generic stop Tx/Rx units
140 : : * @hw: pointer to hardware structure
141 : : *
142 : : * Sets the adapter_stopped flag within ngbe_hw struct. Clears interrupts,
143 : : * disables transmit and receive units. The adapter_stopped flag is used by
144 : : * the shared code and drivers to determine if the adapter is in a stopped
145 : : * state and should not touch the hardware.
146 : : **/
147 : 0 : s32 ngbe_stop_hw_vf(struct ngbe_hw *hw)
148 : : {
149 : : u16 i;
150 : :
151 : : /*
152 : : * Set the adapter_stopped flag so other driver functions stop touching
153 : : * the hardware
154 : : */
155 : 0 : hw->adapter_stopped = true;
156 : :
157 : : /* Clear interrupt mask to stop from interrupts being generated */
158 : : wr32(hw, NGBE_VFIMC, NGBE_VFIMC_MASK);
159 : :
160 : : /* Clear any pending interrupts, flush previous writes */
161 : : wr32(hw, NGBE_VFICR, NGBE_VFICR_MASK);
162 : :
163 : : /* Disable the transmit unit. Each queue must be disabled. */
164 [ # # ]: 0 : for (i = 0; i < hw->mac.max_tx_queues; i++)
165 : 0 : wr32(hw, NGBE_TXCFG(i), NGBE_TXCFG_FLUSH);
166 : :
167 : : /* Disable the receive unit by stopping each queue */
168 [ # # ]: 0 : for (i = 0; i < hw->mac.max_rx_queues; i++)
169 : 0 : wr32m(hw, NGBE_RXCFG(i), NGBE_RXCFG_ENA, 0);
170 : :
171 : : /* Clear packet split and pool config */
172 : : wr32(hw, NGBE_VFPLCFG, 0);
173 : 0 : hw->rx_loaded = 1;
174 : :
175 : : /* flush all queues disables */
176 : : ngbe_flush(hw);
177 : : msec_delay(2);
178 : :
179 : 0 : return 0;
180 : : }
181 : :
182 : : /**
183 : : * ngbe_mta_vector - Determines bit-vector in multicast table to set
184 : : * @hw: pointer to hardware structure
185 : : * @mc_addr: the multicast address
186 : : **/
187 : 0 : STATIC s32 ngbe_mta_vector(struct ngbe_hw *hw, u8 *mc_addr)
188 : : {
189 : : u32 vector = 0;
190 : :
191 [ # # # # : 0 : switch (hw->mac.mc_filter_type) {
# ]
192 : 0 : case 0: /* use bits [47:36] of the address */
193 : 0 : vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
194 : 0 : break;
195 : 0 : case 1: /* use bits [46:35] of the address */
196 : 0 : vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
197 : 0 : break;
198 : 0 : case 2: /* use bits [45:34] of the address */
199 : 0 : vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
200 : 0 : break;
201 : 0 : case 3: /* use bits [43:32] of the address */
202 : 0 : vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
203 : 0 : break;
204 : 0 : default: /* Invalid mc_filter_type */
205 : 0 : DEBUGOUT("MC filter type param set incorrectly");
206 : 0 : ASSERT(0);
207 : : break;
208 : : }
209 : :
210 : : /* vector can only be 12-bits or boundary will be exceeded */
211 : 0 : vector &= 0xFFF;
212 : 0 : return vector;
213 : : }
214 : :
215 : : STATIC s32 ngbevf_write_msg_read_ack(struct ngbe_hw *hw, u32 *msg,
216 : : u32 *retmsg, u16 size)
217 : : {
218 : : struct ngbe_mbx_info *mbx = &hw->mbx;
219 : 0 : s32 retval = mbx->write_posted(hw, msg, size, 0);
220 : :
221 [ # # # # : 0 : if (retval)
# # # # #
# # # #
# ]
222 : : return retval;
223 : :
224 : 0 : return mbx->read_posted(hw, retmsg, size, 0);
225 : : }
226 : :
227 : : /**
228 : : * ngbe_set_rar_vf - set device MAC address
229 : : * @hw: pointer to hardware structure
230 : : * @index: Receive address register to write
231 : : * @addr: Address to put into receive address register
232 : : * @vmdq: VMDq "set" or "pool" index
233 : : * @enable_addr: set flag that address is active
234 : : **/
235 : 0 : s32 ngbe_set_rar_vf(struct ngbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
236 : : u32 enable_addr)
237 : : {
238 : : u32 msgbuf[3];
239 : : u8 *msg_addr = (u8 *)(&msgbuf[1]);
240 : : s32 ret_val;
241 : :
242 : : UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
243 : :
244 : : memset(msgbuf, 0, 12);
245 : 0 : msgbuf[0] = NGBE_VF_SET_MAC_ADDR;
246 : : memcpy(msg_addr, addr, 6);
247 : : ret_val = ngbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
248 : :
249 : 0 : msgbuf[0] &= ~NGBE_VT_MSGTYPE_CTS;
250 : :
251 : : /* if nacked the address was rejected, use "perm_addr" */
252 [ # # # # ]: 0 : if (!ret_val &&
253 : : (msgbuf[0] == (NGBE_VF_SET_MAC_ADDR | NGBE_VT_MSGTYPE_NACK))) {
254 : 0 : ngbe_get_mac_addr_vf(hw, hw->mac.addr);
255 : 0 : return NGBE_ERR_MBX;
256 : : }
257 : :
258 : : return ret_val;
259 : : }
260 : :
261 : : /**
262 : : * ngbe_update_mc_addr_list_vf - Update Multicast addresses
263 : : * @hw: pointer to the HW structure
264 : : * @mc_addr_list: array of multicast addresses to program
265 : : * @mc_addr_count: number of multicast addresses to program
266 : : * @next: caller supplied function to return next address in list
267 : : * @clear: unused
268 : : *
269 : : * Updates the Multicast Table Array.
270 : : **/
271 : 0 : s32 ngbe_update_mc_addr_list_vf(struct ngbe_hw *hw, u8 *mc_addr_list,
272 : : u32 mc_addr_count, ngbe_mc_addr_itr next,
273 : : bool clear)
274 : : {
275 : : struct ngbe_mbx_info *mbx = &hw->mbx;
276 : : u32 msgbuf[NGBE_P2VMBX_SIZE];
277 : : u16 *vector_list = (u16 *)&msgbuf[1];
278 : : u32 vector;
279 : : u32 cnt, i;
280 : : u32 vmdq;
281 : :
282 : : UNREFERENCED_PARAMETER(clear);
283 : :
284 : : /* Each entry in the list uses 1 16 bit word. We have 30
285 : : * 16 bit words available in our HW msg buffer (minus 1 for the
286 : : * msg type). That's 30 hash values if we pack 'em right. If
287 : : * there are more than 30 MC addresses to add then punt the
288 : : * extras for now and then add code to handle more than 30 later.
289 : : * It would be unusual for a server to request that many multi-cast
290 : : * addresses except for in large enterprise network environments.
291 : : */
292 : :
293 : 0 : DEBUGOUT("MC Addr Count = %d", mc_addr_count);
294 : :
295 : 0 : cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
296 : : msgbuf[0] = NGBE_VF_SET_MULTICAST;
297 : 0 : msgbuf[0] |= cnt << NGBE_VT_MSGINFO_SHIFT;
298 : :
299 [ # # ]: 0 : for (i = 0; i < cnt; i++) {
300 : 0 : vector = ngbe_mta_vector(hw, next(hw, &mc_addr_list, &vmdq));
301 : 0 : DEBUGOUT("Hash value = 0x%03X", vector);
302 : 0 : vector_list[i] = (u16)vector;
303 : : }
304 : :
305 : 0 : return mbx->write_posted(hw, msgbuf, NGBE_P2VMBX_SIZE, 0);
306 : : }
307 : :
308 : : /**
309 : : * ngbevf_update_xcast_mode - Update Multicast mode
310 : : * @hw: pointer to the HW structure
311 : : * @xcast_mode: new multicast mode
312 : : *
313 : : * Updates the Multicast Mode of VF.
314 : : **/
315 : 0 : s32 ngbevf_update_xcast_mode(struct ngbe_hw *hw, int xcast_mode)
316 : : {
317 : : u32 msgbuf[2];
318 : : s32 err;
319 : :
320 [ # # # ]: 0 : switch (hw->api_version) {
321 : 0 : case ngbe_mbox_api_12:
322 : : /* New modes were introduced in 1.3 version */
323 [ # # ]: 0 : if (xcast_mode > NGBEVF_XCAST_MODE_ALLMULTI)
324 : : return NGBE_ERR_FEATURE_NOT_SUPPORTED;
325 : : /* Fall through */
326 : : case ngbe_mbox_api_13:
327 : : break;
328 : : default:
329 : : return NGBE_ERR_FEATURE_NOT_SUPPORTED;
330 : : }
331 : :
332 : 0 : msgbuf[0] = NGBE_VF_UPDATE_XCAST_MODE;
333 : 0 : msgbuf[1] = xcast_mode;
334 : :
335 : : err = ngbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
336 [ # # ]: 0 : if (err)
337 : : return err;
338 : :
339 : 0 : msgbuf[0] &= ~NGBE_VT_MSGTYPE_CTS;
340 [ # # ]: 0 : if (msgbuf[0] == (NGBE_VF_UPDATE_XCAST_MODE | NGBE_VT_MSGTYPE_NACK))
341 : 0 : return NGBE_ERR_FEATURE_NOT_SUPPORTED;
342 : : return 0;
343 : : }
344 : :
345 : : /**
346 : : * ngbe_set_vfta_vf - Set/Unset vlan filter table address
347 : : * @hw: pointer to the HW structure
348 : : * @vlan: 12 bit VLAN ID
349 : : * @vind: unused by VF drivers
350 : : * @vlan_on: if true then set bit, else clear bit
351 : : * @vlvf_bypass: boolean flag indicating updating default pool is okay
352 : : *
353 : : * Turn on/off specified VLAN in the VLAN filter table.
354 : : **/
355 : 0 : s32 ngbe_set_vfta_vf(struct ngbe_hw *hw, u32 vlan, u32 vind,
356 : : bool vlan_on, bool vlvf_bypass)
357 : : {
358 : : u32 msgbuf[2];
359 : : s32 ret_val;
360 : :
361 : : UNREFERENCED_PARAMETER(vind, vlvf_bypass);
362 : :
363 : : msgbuf[0] = NGBE_VF_SET_VLAN;
364 : 0 : msgbuf[1] = vlan;
365 : : /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
366 : 0 : msgbuf[0] |= vlan_on << NGBE_VT_MSGINFO_SHIFT;
367 : :
368 : : ret_val = ngbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
369 [ # # # # ]: 0 : if (!ret_val && (msgbuf[0] & NGBE_VT_MSGTYPE_ACK))
370 : : return 0;
371 : :
372 : 0 : return ret_val | (msgbuf[0] & NGBE_VT_MSGTYPE_NACK);
373 : : }
374 : :
375 : : /**
376 : : * ngbe_get_mac_addr_vf - Read device MAC address
377 : : * @hw: pointer to the HW structure
378 : : * @mac_addr: the MAC address
379 : : **/
380 : 0 : s32 ngbe_get_mac_addr_vf(struct ngbe_hw *hw, u8 *mac_addr)
381 : : {
382 : : int i;
383 : :
384 [ # # ]: 0 : for (i = 0; i < ETH_ADDR_LEN; i++)
385 : 0 : mac_addr[i] = hw->mac.perm_addr[i];
386 : :
387 : 0 : return 0;
388 : : }
389 : :
390 [ # # ]: 0 : s32 ngbevf_set_uc_addr_vf(struct ngbe_hw *hw, u32 index, u8 *addr)
391 : : {
392 : : u32 msgbuf[3], msgbuf_chk;
393 : : u8 *msg_addr = (u8 *)(&msgbuf[1]);
394 : : s32 ret_val;
395 : :
396 : : memset(msgbuf, 0, sizeof(msgbuf));
397 : : /*
398 : : * If index is one then this is the start of a new list and needs
399 : : * indication to the PF so it can do it's own list management.
400 : : * If it is zero then that tells the PF to just clear all of
401 : : * this VF's macvlans and there is no new list.
402 : : */
403 : 0 : msgbuf[0] |= index << NGBE_VT_MSGINFO_SHIFT;
404 : 0 : msgbuf[0] |= NGBE_VF_SET_MACVLAN;
405 : : msgbuf_chk = msgbuf[0];
406 [ # # ]: 0 : if (addr)
407 : : memcpy(msg_addr, addr, 6);
408 : :
409 : : ret_val = ngbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
410 [ # # ]: 0 : if (!ret_val) {
411 : 0 : msgbuf[0] &= ~NGBE_VT_MSGTYPE_CTS;
412 : :
413 [ # # ]: 0 : if (msgbuf[0] == (msgbuf_chk | NGBE_VT_MSGTYPE_NACK))
414 : 0 : return NGBE_ERR_OUT_OF_MEM;
415 : : }
416 : :
417 : : return ret_val;
418 : : }
419 : :
420 : : /**
421 : : * ngbe_check_mac_link_vf - Get link/speed status
422 : : * @hw: pointer to hardware structure
423 : : * @speed: pointer to link speed
424 : : * @link_up: true is link is up, false otherwise
425 : : * @autoneg_wait_to_complete: true when waiting for completion is needed
426 : : *
427 : : * Reads the links register to determine if link is up and the current speed
428 : : **/
429 : 0 : s32 ngbe_check_mac_link_vf(struct ngbe_hw *hw, u32 *speed,
430 : : bool *link_up, bool wait_to_complete)
431 : : {
432 : : /**
433 : : * for a quick link status checking, wait_to_compelet == 0,
434 : : * skip PF link status checking
435 : : */
436 : : bool no_pflink_check = 0;
437 : : struct ngbe_mbx_info *mbx = &hw->mbx;
438 : : struct ngbe_mac_info *mac = &hw->mac;
439 : : s32 ret_val = 0;
440 : : u32 links_reg;
441 : 0 : u32 in_msg = 0;
442 : :
443 : : UNREFERENCED_PARAMETER(wait_to_complete);
444 : :
445 : : /* If we were hit with a reset drop the link */
446 [ # # # # ]: 0 : if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
447 : 0 : mac->get_link_status = true;
448 : :
449 [ # # ]: 0 : if (!mac->get_link_status)
450 : 0 : goto out;
451 : :
452 : : /* if link status is down no point in checking to see if pf is up */
453 : : links_reg = rd32(hw, NGBE_VFSTATUS);
454 [ # # ]: 0 : if (!(links_reg & NGBE_VFSTATUS_BW_MASK))
455 : 0 : goto out;
456 : :
457 : : /* for SFP+ modules and DA cables it can take up to 500usecs
458 : : * before the link status is correct
459 : : */
460 [ # # ]: 0 : if (mac->type == ngbe_mac_em_vf) {
461 [ # # ]: 0 : if (po32m(hw, NGBE_VFSTATUS, NGBE_VFSTATUS_BW_MASK,
462 : : 0, NULL, 5, 100))
463 : 0 : goto out;
464 : : }
465 : :
466 [ # # ]: 0 : if (links_reg & NGBE_VFSTATUS_BW_1G)
467 : 0 : *speed = NGBE_LINK_SPEED_1GB_FULL;
468 [ # # ]: 0 : else if (links_reg & NGBE_VFSTATUS_BW_100M)
469 : 0 : *speed = NGBE_LINK_SPEED_100M_FULL;
470 [ # # ]: 0 : else if (links_reg & NGBE_VFSTATUS_BW_10M)
471 : 0 : *speed = NGBE_LINK_SPEED_10M_FULL;
472 : : else
473 : 0 : *speed = NGBE_LINK_SPEED_UNKNOWN;
474 : :
475 : : if (no_pflink_check) {
476 : : if (*speed == NGBE_LINK_SPEED_UNKNOWN)
477 : : mac->get_link_status = true;
478 : : else
479 : : mac->get_link_status = false;
480 : :
481 : : goto out;
482 : : }
483 : :
484 : : /* if the read failed it could just be a mailbox collision, best wait
485 : : * until we are called again and don't report an error
486 : : */
487 [ # # ]: 0 : if (mbx->read(hw, &in_msg, 1, 0))
488 : 0 : goto out;
489 : :
490 [ # # ]: 0 : if (!(in_msg & NGBE_VT_MSGTYPE_CTS)) {
491 : : /* msg is not CTS and is NACK we must have lost CTS status */
492 [ # # ]: 0 : if (in_msg & NGBE_VT_MSGTYPE_NACK)
493 : : ret_val = -1;
494 : 0 : goto out;
495 : : }
496 : :
497 : : /* the pf is talking, if we timed out in the past we reinit */
498 [ # # ]: 0 : if (!mbx->timeout) {
499 : : ret_val = -1;
500 : 0 : goto out;
501 : : }
502 : :
503 : : /* if we passed all the tests above then the link is up and we no
504 : : * longer need to check for link
505 : : */
506 : 0 : mac->get_link_status = false;
507 : :
508 : 0 : out:
509 : 0 : *link_up = !mac->get_link_status;
510 : 0 : return ret_val;
511 : : }
512 : :
513 : : /**
514 : : * ngbevf_rlpml_set_vf - Set the maximum receive packet length
515 : : * @hw: pointer to the HW structure
516 : : * @max_size: value to assign to max frame size
517 : : **/
518 : 0 : s32 ngbevf_rlpml_set_vf(struct ngbe_hw *hw, u16 max_size)
519 : : {
520 : : u32 msgbuf[2];
521 : : s32 retval;
522 : :
523 : 0 : msgbuf[0] = NGBE_VF_SET_LPE;
524 : 0 : msgbuf[1] = max_size;
525 : :
526 : : retval = ngbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
527 [ # # ]: 0 : if (retval)
528 : : return retval;
529 [ # # ]: 0 : if ((msgbuf[0] & NGBE_VF_SET_LPE) &&
530 [ # # ]: 0 : (msgbuf[0] & NGBE_VT_MSGTYPE_NACK))
531 : 0 : return NGBE_ERR_MBX;
532 : :
533 : : return 0;
534 : : }
535 : :
536 : : /**
537 : : * ngbevf_negotiate_api_version - Negotiate supported API version
538 : : * @hw: pointer to the HW structure
539 : : * @api: integer containing requested API version
540 : : **/
541 : 0 : int ngbevf_negotiate_api_version(struct ngbe_hw *hw, int api)
542 : : {
543 : : int err;
544 : : u32 msg[3];
545 : :
546 : : /* Negotiate the mailbox API version */
547 : 0 : msg[0] = NGBE_VF_API_NEGOTIATE;
548 : 0 : msg[1] = api;
549 : 0 : msg[2] = 0;
550 : :
551 : : err = ngbevf_write_msg_read_ack(hw, msg, msg, 3);
552 [ # # ]: 0 : if (!err) {
553 : 0 : msg[0] &= ~NGBE_VT_MSGTYPE_CTS;
554 : :
555 : : /* Store value and return 0 on success */
556 [ # # ]: 0 : if (msg[0] == (NGBE_VF_API_NEGOTIATE | NGBE_VT_MSGTYPE_ACK)) {
557 : 0 : hw->api_version = api;
558 : 0 : return 0;
559 : : }
560 : :
561 : : err = NGBE_ERR_INVALID_ARGUMENT;
562 : : }
563 : :
564 : : return err;
565 : : }
566 : :
567 : 0 : int ngbevf_get_queues(struct ngbe_hw *hw, unsigned int *num_tcs,
568 : : unsigned int *default_tc)
569 : : {
570 : : int err, i;
571 : : u32 msg[5];
572 : :
573 : : /* do nothing if API doesn't support ngbevf_get_queues */
574 [ # # ]: 0 : switch (hw->api_version) {
575 : : case ngbe_mbox_api_11:
576 : : case ngbe_mbox_api_12:
577 : : case ngbe_mbox_api_13:
578 : : break;
579 : : default:
580 : : return 0;
581 : : }
582 : :
583 : : /* Fetch queue configuration from the PF */
584 : 0 : msg[0] = NGBE_VF_GET_QUEUES;
585 [ # # ]: 0 : for (i = 1; i < 5; i++)
586 : 0 : msg[i] = 0;
587 : :
588 : : err = ngbevf_write_msg_read_ack(hw, msg, msg, 5);
589 [ # # ]: 0 : if (!err) {
590 : 0 : msg[0] &= ~NGBE_VT_MSGTYPE_CTS;
591 : :
592 : : /*
593 : : * if we didn't get an ACK there must have been
594 : : * some sort of mailbox error so we should treat it
595 : : * as such
596 : : */
597 [ # # ]: 0 : if (msg[0] != (NGBE_VF_GET_QUEUES | NGBE_VT_MSGTYPE_ACK))
598 : : return NGBE_ERR_MBX;
599 : :
600 : : /* record and validate values from message */
601 : 0 : hw->mac.max_tx_queues = msg[NGBE_VF_TX_QUEUES];
602 [ # # ]: 0 : if (hw->mac.max_tx_queues == 0 ||
603 : : hw->mac.max_tx_queues > NGBE_VF_MAX_TX_QUEUES)
604 : 0 : hw->mac.max_tx_queues = NGBE_VF_MAX_TX_QUEUES;
605 : :
606 : 0 : hw->mac.max_rx_queues = msg[NGBE_VF_RX_QUEUES];
607 [ # # ]: 0 : if (hw->mac.max_rx_queues == 0 ||
608 : : hw->mac.max_rx_queues > NGBE_VF_MAX_RX_QUEUES)
609 : 0 : hw->mac.max_rx_queues = NGBE_VF_MAX_RX_QUEUES;
610 : :
611 : 0 : *num_tcs = msg[NGBE_VF_TRANS_VLAN];
612 : : /* in case of unknown state assume we cannot tag frames */
613 [ # # ]: 0 : if (*num_tcs > hw->mac.max_rx_queues)
614 : 0 : *num_tcs = 1;
615 : :
616 : 0 : *default_tc = msg[NGBE_VF_DEF_QUEUE];
617 : : /* default to queue 0 on out-of-bounds queue number */
618 [ # # ]: 0 : if (*default_tc >= hw->mac.max_tx_queues)
619 : 0 : *default_tc = 0;
620 : : }
621 : :
622 : : return err;
623 : : }
624 : :
625 : : /**
626 : : * ngbe_init_ops_vf - Initialize the pointers for vf
627 : : * @hw: pointer to hardware structure
628 : : *
629 : : * This will assign function pointers, adapter-specific functions can
630 : : * override the assignment of generic function pointers by assigning
631 : : * their own adapter-specific function pointers.
632 : : * Does not touch the hardware.
633 : : **/
634 : 0 : s32 ngbe_init_ops_vf(struct ngbe_hw *hw)
635 : : {
636 : : struct ngbe_mac_info *mac = &hw->mac;
637 : : struct ngbe_mbx_info *mbx = &hw->mbx;
638 : :
639 : : /* MAC */
640 : 0 : mac->init_hw = ngbe_init_hw_vf;
641 : 0 : mac->reset_hw = ngbe_reset_hw_vf;
642 : 0 : mac->start_hw = ngbe_start_hw_vf;
643 : 0 : mac->stop_hw = ngbe_stop_hw_vf;
644 : 0 : mac->get_mac_addr = ngbe_get_mac_addr_vf;
645 : 0 : mac->negotiate_api_version = ngbevf_negotiate_api_version;
646 : :
647 : : /* Link */
648 : 0 : mac->check_link = ngbe_check_mac_link_vf;
649 : :
650 : : /* RAR, Multicast, VLAN */
651 : 0 : mac->set_rar = ngbe_set_rar_vf;
652 : 0 : mac->set_uc_addr = ngbevf_set_uc_addr_vf;
653 : 0 : mac->update_mc_addr_list = ngbe_update_mc_addr_list_vf;
654 : 0 : mac->update_xcast_mode = ngbevf_update_xcast_mode;
655 : 0 : mac->set_vfta = ngbe_set_vfta_vf;
656 : 0 : mac->set_rlpml = ngbevf_rlpml_set_vf;
657 : :
658 : 0 : mac->max_tx_queues = 1;
659 : 0 : mac->max_rx_queues = 1;
660 : :
661 : 0 : mbx->init_params = ngbe_init_mbx_params_vf;
662 : 0 : mbx->read = ngbe_read_mbx_vf;
663 : 0 : mbx->write = ngbe_write_mbx_vf;
664 : 0 : mbx->read_posted = ngbe_read_posted_mbx;
665 : 0 : mbx->write_posted = ngbe_write_posted_mbx;
666 : 0 : mbx->check_for_msg = ngbe_check_for_msg_vf;
667 : 0 : mbx->check_for_ack = ngbe_check_for_ack_vf;
668 : 0 : mbx->check_for_rst = ngbe_check_for_rst_vf;
669 : :
670 : 0 : return 0;
671 : : }
|