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 : : /* amlite: bme */
137 [ # # ]: 0 : if (hw->mac.type == txgbe_mac_aml_vf ||
138 : : hw->mac.type == txgbe_mac_aml40_vf)
139 : : wr32(hw, TXGBE_BME_AML, 0x1);
140 : :
141 [ # # ]: 0 : if (!timeout)
142 : : return TXGBE_ERR_RESET_FAILED;
143 : :
144 : : /* Reset VF registers to initial values */
145 : 0 : txgbe_virt_clr_reg(hw);
146 : :
147 : : /* mailbox timeout can now become active */
148 : 0 : mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
149 : :
150 : 0 : msgbuf[0] = TXGBE_VF_RESET;
151 : 0 : mbx->write_posted(hw, msgbuf, 1, 0);
152 : :
153 : : msec_delay(10);
154 : :
155 : : /*
156 : : * set our "perm_addr" based on info provided by PF
157 : : * also set up the mc_filter_type which is piggy backed
158 : : * on the mac address in word 3
159 : : */
160 : 0 : ret_val = mbx->read_posted(hw, msgbuf,
161 : : TXGBE_VF_PERMADDR_MSG_LEN, 0);
162 [ # # ]: 0 : if (ret_val)
163 : : return ret_val;
164 : :
165 [ # # ]: 0 : if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
166 : : msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
167 : : return TXGBE_ERR_INVALID_MAC_ADDR;
168 : :
169 [ # # ]: 0 : if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
170 : 0 : memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
171 : :
172 : 0 : hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
173 : :
174 : 0 : return ret_val;
175 : : }
176 : :
177 : : /**
178 : : * txgbe_stop_hw_vf - Generic stop Tx/Rx units
179 : : * @hw: pointer to hardware structure
180 : : *
181 : : * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
182 : : * disables transmit and receive units. The adapter_stopped flag is used by
183 : : * the shared code and drivers to determine if the adapter is in a stopped
184 : : * state and should not touch the hardware.
185 : : **/
186 : 0 : s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
187 : : {
188 : : u16 i;
189 : :
190 : : /*
191 : : * Set the adapter_stopped flag so other driver functions stop touching
192 : : * the hardware
193 : : */
194 : 0 : hw->adapter_stopped = true;
195 : :
196 : : /* Clear interrupt mask to stop from interrupts being generated */
197 : : wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
198 : :
199 : : /* Clear any pending interrupts, flush previous writes */
200 : : wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
201 : :
202 : : /* Disable the transmit unit. Each queue must be disabled. */
203 [ # # ]: 0 : for (i = 0; i < hw->mac.max_tx_queues; i++)
204 : 0 : wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
205 : :
206 : : /* Disable the receive unit by stopping each queue */
207 [ # # ]: 0 : for (i = 0; i < hw->mac.max_rx_queues; i++)
208 : 0 : wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
209 : :
210 : : /* Clear packet split and pool config */
211 : : wr32(hw, TXGBE_VFPLCFG, 0);
212 [ # # # ]: 0 : hw->rx_loaded = 1;
213 : :
214 : : /* flush all queues disables */
215 : : txgbe_flush(hw);
216 : : msec_delay(2);
217 : :
218 : 0 : return 0;
219 : : }
220 : :
221 : : /**
222 : : * txgbe_mta_vector - Determines bit-vector in multicast table to set
223 : : * @hw: pointer to hardware structure
224 : : * @mc_addr: the multicast address
225 : : **/
226 : 0 : STATIC s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
227 : : {
228 : : u32 vector = 0;
229 : :
230 [ # # # # : 0 : switch (hw->mac.mc_filter_type) {
# ]
231 : 0 : case 0: /* use bits [47:36] of the address */
232 : 0 : vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
233 : 0 : break;
234 : 0 : case 1: /* use bits [46:35] of the address */
235 : 0 : vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
236 : 0 : break;
237 : 0 : case 2: /* use bits [45:34] of the address */
238 : 0 : vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
239 : 0 : break;
240 : 0 : case 3: /* use bits [43:32] of the address */
241 : 0 : vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
242 : 0 : break;
243 : 0 : default: /* Invalid mc_filter_type */
244 : 0 : DEBUGOUT("MC filter type param set incorrectly");
245 : 0 : ASSERT(0);
246 : : break;
247 : : }
248 : :
249 : : /* vector can only be 12-bits or boundary will be exceeded */
250 : 0 : vector &= 0xFFF;
251 : 0 : return vector;
252 : : }
253 : :
254 : : STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
255 : : u32 *retmsg, u16 size)
256 : : {
257 : : struct txgbe_mbx_info *mbx = &hw->mbx;
258 : 0 : s32 retval = mbx->write_posted(hw, msg, size, 0);
259 : :
260 [ # # # # : 0 : if (retval)
# # # # #
# # # # #
# # # # #
# ]
261 : : return retval;
262 : :
263 : 0 : return mbx->read_posted(hw, retmsg, size, 0);
264 : : }
265 : :
266 : : /**
267 : : * txgbe_set_rar_vf - set device MAC address
268 : : * @hw: pointer to hardware structure
269 : : * @index: Receive address register to write
270 : : * @addr: Address to put into receive address register
271 : : * @vmdq: VMDq "set" or "pool" index
272 : : * @enable_addr: set flag that address is active
273 : : **/
274 : 0 : s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
275 : : u32 enable_addr)
276 : : {
277 : : u32 msgbuf[3];
278 : : u8 *msg_addr = (u8 *)(&msgbuf[1]);
279 : : s32 ret_val;
280 : : UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
281 : :
282 : : memset(msgbuf, 0, 12);
283 : 0 : msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
284 : : memcpy(msg_addr, addr, 6);
285 : : ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
286 : :
287 : 0 : msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
288 : :
289 : : /* if nacked the address was rejected, use "perm_addr" */
290 [ # # # # ]: 0 : if (!ret_val &&
291 : : (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
292 : 0 : txgbe_get_mac_addr_vf(hw, hw->mac.addr);
293 : 0 : return TXGBE_ERR_MBX;
294 : : }
295 : :
296 : : return ret_val;
297 : : }
298 : :
299 : : /**
300 : : * txgbe_update_mc_addr_list_vf - Update Multicast addresses
301 : : * @hw: pointer to the HW structure
302 : : * @mc_addr_list: array of multicast addresses to program
303 : : * @mc_addr_count: number of multicast addresses to program
304 : : * @next: caller supplied function to return next address in list
305 : : * @clear: unused
306 : : *
307 : : * Updates the Multicast Table Array.
308 : : **/
309 : 0 : s32 txgbe_update_mc_addr_list_vf(struct txgbe_hw *hw, u8 *mc_addr_list,
310 : : u32 mc_addr_count, txgbe_mc_addr_itr next,
311 : : bool clear)
312 : : {
313 : : struct txgbe_mbx_info *mbx = &hw->mbx;
314 : : u32 msgbuf[TXGBE_P2VMBX_SIZE];
315 : : u16 *vector_list = (u16 *)&msgbuf[1];
316 : : u32 vector;
317 : : u32 cnt, i;
318 : : u32 vmdq;
319 : :
320 : : UNREFERENCED_PARAMETER(clear);
321 : :
322 : : /* Each entry in the list uses 1 16 bit word. We have 30
323 : : * 16 bit words available in our HW msg buffer (minus 1 for the
324 : : * msg type). That's 30 hash values if we pack 'em right. If
325 : : * there are more than 30 MC addresses to add then punt the
326 : : * extras for now and then add code to handle more than 30 later.
327 : : * It would be unusual for a server to request that many multi-cast
328 : : * addresses except for in large enterprise network environments.
329 : : */
330 : :
331 : 0 : DEBUGOUT("MC Addr Count = %d", mc_addr_count);
332 : :
333 : 0 : cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
334 : : msgbuf[0] = TXGBE_VF_SET_MULTICAST;
335 : 0 : msgbuf[0] |= cnt << TXGBE_VT_MSGINFO_SHIFT;
336 : :
337 [ # # ]: 0 : for (i = 0; i < cnt; i++) {
338 : 0 : vector = txgbe_mta_vector(hw, next(hw, &mc_addr_list, &vmdq));
339 : 0 : DEBUGOUT("Hash value = 0x%03X", vector);
340 : 0 : vector_list[i] = (u16)vector;
341 : : }
342 : :
343 : 0 : return mbx->write_posted(hw, msgbuf, TXGBE_P2VMBX_SIZE, 0);
344 : : }
345 : :
346 : : /**
347 : : * txgbevf_update_xcast_mode - Update Multicast mode
348 : : * @hw: pointer to the HW structure
349 : : * @xcast_mode: new multicast mode
350 : : *
351 : : * Updates the Multicast Mode of VF.
352 : : **/
353 : 0 : s32 txgbevf_update_xcast_mode(struct txgbe_hw *hw, int xcast_mode)
354 : : {
355 : : u32 msgbuf[2];
356 : : s32 err;
357 : :
358 [ # # # ]: 0 : switch (hw->api_version) {
359 : 0 : case txgbe_mbox_api_12:
360 : : /* New modes were introduced in 1.3 version */
361 [ # # ]: 0 : if (xcast_mode > TXGBEVF_XCAST_MODE_ALLMULTI)
362 : : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
363 : : /* Fall through */
364 : : case txgbe_mbox_api_13:
365 : : case txgbe_mbox_api_21:
366 : : case txgbe_mbox_api_23:
367 : : break;
368 : : default:
369 : : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
370 : : }
371 : :
372 : 0 : msgbuf[0] = TXGBE_VF_UPDATE_XCAST_MODE;
373 : 0 : msgbuf[1] = xcast_mode;
374 : :
375 : : err = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
376 [ # # ]: 0 : if (err)
377 : : return err;
378 : :
379 : 0 : msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
380 [ # # ]: 0 : if (msgbuf[0] == (TXGBE_VF_UPDATE_XCAST_MODE | TXGBE_VT_MSGTYPE_NACK))
381 : 0 : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
382 : : return 0;
383 : : }
384 : :
385 : : /**
386 : : * txgbe_set_vfta_vf - Set/Unset vlan filter table address
387 : : * @hw: pointer to the HW structure
388 : : * @vlan: 12 bit VLAN ID
389 : : * @vind: unused by VF drivers
390 : : * @vlan_on: if true then set bit, else clear bit
391 : : * @vlvf_bypass: boolean flag indicating updating default pool is okay
392 : : *
393 : : * Turn on/off specified VLAN in the VLAN filter table.
394 : : **/
395 : 0 : s32 txgbe_set_vfta_vf(struct txgbe_hw *hw, u32 vlan, u32 vind,
396 : : bool vlan_on, bool vlvf_bypass)
397 : : {
398 : : u32 msgbuf[2];
399 : : s32 ret_val;
400 : : UNREFERENCED_PARAMETER(vind, vlvf_bypass);
401 : :
402 : : msgbuf[0] = TXGBE_VF_SET_VLAN;
403 : 0 : msgbuf[1] = vlan;
404 : : /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
405 : 0 : msgbuf[0] |= vlan_on << TXGBE_VT_MSGINFO_SHIFT;
406 : :
407 : : ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
408 [ # # # # ]: 0 : if (!ret_val && (msgbuf[0] & TXGBE_VT_MSGTYPE_ACK))
409 : : return 0;
410 : :
411 : 0 : return ret_val | (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK);
412 : : }
413 : :
414 : : /**
415 : : * txgbe_get_mac_addr_vf - Read device MAC address
416 : : * @hw: pointer to the HW structure
417 : : * @mac_addr: the MAC address
418 : : **/
419 : 0 : s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
420 : : {
421 : : int i;
422 : :
423 [ # # ]: 0 : for (i = 0; i < ETH_ADDR_LEN; i++)
424 : 0 : mac_addr[i] = hw->mac.perm_addr[i];
425 : :
426 : 0 : return 0;
427 : : }
428 : :
429 [ # # ]: 0 : s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
430 : : {
431 : : u32 msgbuf[3], msgbuf_chk;
432 : : u8 *msg_addr = (u8 *)(&msgbuf[1]);
433 : : s32 ret_val;
434 : :
435 : : memset(msgbuf, 0, sizeof(msgbuf));
436 : : /*
437 : : * If index is one then this is the start of a new list and needs
438 : : * indication to the PF so it can do it's own list management.
439 : : * If it is zero then that tells the PF to just clear all of
440 : : * this VF's macvlans and there is no new list.
441 : : */
442 : 0 : msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
443 : 0 : msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
444 : : msgbuf_chk = msgbuf[0];
445 [ # # ]: 0 : if (addr)
446 : : memcpy(msg_addr, addr, 6);
447 : :
448 : : ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
449 [ # # ]: 0 : if (!ret_val) {
450 : 0 : msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
451 : :
452 [ # # ]: 0 : if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
453 : 0 : return TXGBE_ERR_OUT_OF_MEM;
454 : : }
455 : :
456 : : return ret_val;
457 : : }
458 : :
459 : : /**
460 : : * txgbe_check_mac_link_vf - Get link/speed status
461 : : * @hw: pointer to hardware structure
462 : : * @speed: pointer to link speed
463 : : * @link_up: true is link is up, false otherwise
464 : : * @autoneg_wait_to_complete: true when waiting for completion is needed
465 : : *
466 : : * Reads the links register to determine if link is up and the current speed
467 : : **/
468 : 0 : s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
469 : : bool *link_up, bool wait_to_complete)
470 : : {
471 : : /**
472 : : * for a quick link status checking, wait_to_compelet == 0,
473 : : * skip PF link status checking
474 : : */
475 : 0 : bool no_pflink_check = wait_to_complete == 0;
476 : : struct txgbe_mbx_info *mbx = &hw->mbx;
477 : : struct txgbe_mac_info *mac = &hw->mac;
478 : : s32 ret_val = 0;
479 : : u32 links_reg;
480 : 0 : u32 in_msg = 0;
481 : :
482 : : /* If we were hit with a reset drop the link */
483 [ # # # # ]: 0 : if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
484 : 0 : mac->get_link_status = true;
485 : :
486 [ # # ]: 0 : if (!mac->get_link_status)
487 : 0 : goto out;
488 : :
489 : : /* if link status is down no point in checking to see if pf is up */
490 : : links_reg = rd32(hw, TXGBE_VFSTATUS);
491 [ # # ]: 0 : if (!(links_reg & TXGBE_VFSTATUS_UP))
492 : 0 : goto out;
493 : :
494 : : /* for SFP+ modules and DA cables it can take up to 500usecs
495 : : * before the link status is correct
496 : : */
497 [ # # ]: 0 : if (wait_to_complete) {
498 [ # # ]: 0 : if (po32m(hw, TXGBE_VFSTATUS, TXGBE_VFSTATUS_UP,
499 : : 0, NULL, 5, 100))
500 : 0 : goto out;
501 : : }
502 : :
503 [ # # ]: 0 : if (hw->mac.type == txgbe_mac_sp_vf) {
504 [ # # ]: 0 : if (hw->device_id == TXGBE_DEV_ID_SP1000_VF ||
505 : : hw->device_id == TXGBE_DEV_ID_WX1820_VF)
506 [ # # # # ]: 0 : switch (links_reg & TXGBE_VFSTATUS_BW_MASK) {
507 : 0 : case TXGBE_VFSTATUS_BW_10G:
508 : 0 : *speed = TXGBE_LINK_SPEED_10GB_FULL;
509 : 0 : break;
510 : 0 : case TXGBE_VFSTATUS_BW_1G:
511 : 0 : *speed = TXGBE_LINK_SPEED_1GB_FULL;
512 : 0 : break;
513 : 0 : case TXGBE_VFSTATUS_BW_100M:
514 : 0 : *speed = TXGBE_LINK_SPEED_100M_FULL;
515 : 0 : break;
516 : 0 : default:
517 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN;
518 : : }
519 : : } else {
520 [ # # # # : 0 : switch (links_reg & TXGBE_VFSTATUS_BW_MASK_AML) {
# ]
521 : 0 : case TXGBE_VFSTATUS_BW_AML_10G:
522 : 0 : *speed = TXGBE_LINK_SPEED_10GB_FULL;
523 : 0 : break;
524 : 0 : case TXGBE_VFSTATUS_BW_AML_25G:
525 : 0 : *speed = TXGBE_LINK_SPEED_25GB_FULL;
526 : 0 : break;
527 : 0 : case TXGBE_VFSTATUS_BW_AML_40G:
528 : 0 : *speed = TXGBE_LINK_SPEED_40GB_FULL;
529 : 0 : break;
530 : 0 : case TXGBE_VFSTATUS_BW_AML_50G:
531 : 0 : *speed = TXGBE_LINK_SPEED_50GB_FULL;
532 : 0 : break;
533 : 0 : default:
534 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN;
535 : : }
536 : : }
537 : :
538 [ # # ]: 0 : if (no_pflink_check) {
539 [ # # ]: 0 : if (*speed == TXGBE_LINK_SPEED_UNKNOWN)
540 : 0 : mac->get_link_status = true;
541 : : else
542 : 0 : mac->get_link_status = false;
543 : :
544 : 0 : goto out;
545 : : }
546 : :
547 : : /* if the read failed it could just be a mailbox collision, best wait
548 : : * until we are called again and don't report an error
549 : : */
550 [ # # ]: 0 : if (mbx->read(hw, &in_msg, 1, 0))
551 : 0 : goto out;
552 : :
553 [ # # ]: 0 : if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
554 : : /* msg is not CTS and is NACK we must have lost CTS status */
555 [ # # ]: 0 : if (in_msg & TXGBE_VT_MSGTYPE_NACK)
556 : : ret_val = -1;
557 : 0 : goto out;
558 : : }
559 : :
560 : : /* the pf is talking, if we timed out in the past we reinit */
561 [ # # ]: 0 : if (!mbx->timeout) {
562 : : ret_val = -1;
563 : 0 : goto out;
564 : : }
565 : :
566 : : /* if we passed all the tests above then the link is up and we no
567 : : * longer need to check for link
568 : : */
569 : 0 : mac->get_link_status = false;
570 : :
571 : 0 : out:
572 : 0 : *link_up = !mac->get_link_status;
573 : 0 : return ret_val;
574 : : }
575 : :
576 : : /**
577 : : * txgbevf_rlpml_set_vf - Set the maximum receive packet length
578 : : * @hw: pointer to the HW structure
579 : : * @max_size: value to assign to max frame size
580 : : **/
581 : 0 : s32 txgbevf_rlpml_set_vf(struct txgbe_hw *hw, u16 max_size)
582 : : {
583 : : u32 msgbuf[2];
584 : : s32 retval;
585 : :
586 : 0 : msgbuf[0] = TXGBE_VF_SET_LPE;
587 : 0 : msgbuf[1] = max_size;
588 : :
589 : : retval = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
590 [ # # ]: 0 : if (retval)
591 : : return retval;
592 [ # # ]: 0 : if ((msgbuf[0] & TXGBE_VF_SET_LPE) &&
593 [ # # ]: 0 : (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK))
594 : 0 : return TXGBE_ERR_MBX;
595 : :
596 : : return 0;
597 : : }
598 : :
599 : : /**
600 : : * txgbevf_negotiate_api_version - Negotiate supported API version
601 : : * @hw: pointer to the HW structure
602 : : * @api: integer containing requested API version
603 : : **/
604 : 0 : int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
605 : : {
606 : : int err;
607 : : u32 msg[3];
608 : :
609 : : /* Negotiate the mailbox API version */
610 : 0 : msg[0] = TXGBE_VF_API_NEGOTIATE;
611 : 0 : msg[1] = api;
612 : 0 : msg[2] = 0;
613 : :
614 : : err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
615 [ # # ]: 0 : if (!err) {
616 : 0 : msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
617 : :
618 : : /* Store value and return 0 on success */
619 [ # # ]: 0 : if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
620 : 0 : hw->api_version = api;
621 : 0 : return 0;
622 : : }
623 : :
624 : : err = TXGBE_ERR_INVALID_ARGUMENT;
625 : : }
626 : :
627 : : return err;
628 : : }
629 : :
630 : 0 : int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
631 : : unsigned int *default_tc)
632 : : {
633 : : int err, i;
634 : : u32 msg[5];
635 : :
636 : : /* do nothing if API doesn't support txgbevf_get_queues */
637 [ # # ]: 0 : switch (hw->api_version) {
638 : : case txgbe_mbox_api_11:
639 : : case txgbe_mbox_api_12:
640 : : case txgbe_mbox_api_13:
641 : : case txgbe_mbox_api_21:
642 : : case txgbe_mbox_api_23:
643 : : break;
644 : : default:
645 : : return 0;
646 : : }
647 : :
648 : : /* Fetch queue configuration from the PF */
649 : 0 : msg[0] = TXGBE_VF_GET_QUEUES;
650 [ # # ]: 0 : for (i = 1; i < 5; i++)
651 : 0 : msg[i] = 0;
652 : :
653 : : err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
654 [ # # ]: 0 : if (!err) {
655 : 0 : msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
656 : :
657 : : /*
658 : : * if we didn't get an ACK there must have been
659 : : * some sort of mailbox error so we should treat it
660 : : * as such
661 : : */
662 [ # # ]: 0 : if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
663 : : return TXGBE_ERR_MBX;
664 : :
665 : : /* record and validate values from message */
666 : 0 : hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
667 [ # # ]: 0 : if (hw->mac.max_tx_queues == 0 ||
668 : : hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
669 : 0 : hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
670 : :
671 : 0 : hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
672 [ # # ]: 0 : if (hw->mac.max_rx_queues == 0 ||
673 : : hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
674 : 0 : hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
675 : :
676 : 0 : *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
677 : : /* in case of unknown state assume we cannot tag frames */
678 [ # # ]: 0 : if (*num_tcs > hw->mac.max_rx_queues)
679 : 0 : *num_tcs = 1;
680 : :
681 : 0 : *default_tc = msg[TXGBE_VF_DEF_QUEUE];
682 : : /* default to queue 0 on out-of-bounds queue number */
683 [ # # ]: 0 : if (*default_tc >= hw->mac.max_tx_queues)
684 : 0 : *default_tc = 0;
685 : : }
686 : :
687 : : return err;
688 : : }
689 : :
690 : : int
691 : 0 : txgbevf_add_5tuple_filter(struct txgbe_hw *hw, u32 *msg, u16 index)
692 : : {
693 : : int err;
694 : :
695 [ # # ]: 0 : if (hw->api_version < txgbe_mbox_api_21)
696 : : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
697 : :
698 : 0 : msg[TXGBEVF_5T_REQ] = TXGBE_VF_SET_5TUPLE;
699 : 0 : msg[TXGBEVF_5T_CMD] = index;
700 : 0 : msg[TXGBEVF_5T_CMD] |= 1 << TXGBEVF_5T_ADD_SHIFT;
701 : :
702 : : err = txgbevf_write_msg_read_ack(hw, msg, msg, TXGBEVF_5T_MAX);
703 [ # # ]: 0 : if (err)
704 : : return err;
705 : :
706 : 0 : msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
707 [ # # ]: 0 : if (msg[0] != (TXGBE_VF_SET_5TUPLE | TXGBE_VT_MSGTYPE_ACK))
708 : 0 : return TXGBE_ERR_NOSUPP;
709 : :
710 : : return 0;
711 : : }
712 : :
713 : : int
714 : 0 : txgbevf_del_5tuple_filter(struct txgbe_hw *hw, u16 index)
715 : : {
716 : 0 : u32 msg[2] = {0, 0};
717 : : int err;
718 : :
719 [ # # ]: 0 : if (hw->api_version < txgbe_mbox_api_21)
720 : : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
721 : :
722 : 0 : msg[TXGBEVF_5T_REQ] = TXGBE_VF_SET_5TUPLE;
723 : 0 : msg[TXGBEVF_5T_CMD] = index;
724 : :
725 : : err = txgbevf_write_msg_read_ack(hw, msg, msg, 2);
726 [ # # ]: 0 : if (err)
727 : : return err;
728 : :
729 : 0 : msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
730 [ # # ]: 0 : if (msg[0] != (TXGBE_VF_SET_5TUPLE | TXGBE_VT_MSGTYPE_ACK))
731 : 0 : return TXGBE_ERR_NOSUPP;
732 : :
733 : : return 0;
734 : : }
735 : :
736 : : int
737 : 0 : txgbevf_set_fdir(struct txgbe_hw *hw, u32 *msg, bool add)
738 : : {
739 : : u16 msg_len = TXGBEVF_FDIR_MAX;
740 : : int err = 0;
741 : :
742 [ # # ]: 0 : if (hw->api_version < txgbe_mbox_api_23)
743 : : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
744 : :
745 : 0 : msg[TXGBEVF_FDIR_REQ] = TXGBE_VF_SET_FDIR;
746 : :
747 [ # # ]: 0 : if (add)
748 : 0 : msg[TXGBEVF_FDIR_CMD] |= 1 << TXGBEVF_FDIR_ADD_SHIFT;
749 : : else
750 : : msg_len = 2;
751 : :
752 : 0 : err = txgbevf_write_msg_read_ack(hw, msg, msg, msg_len);
753 [ # # ]: 0 : if (err)
754 : : return err;
755 : :
756 : 0 : msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
757 [ # # ]: 0 : if (msg[0] == (TXGBE_VF_SET_FDIR | TXGBE_VT_MSGTYPE_NACK))
758 : 0 : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
759 : :
760 : : return 0;
761 : : }
|