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