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 : : wr32(hw, TXGBE_BME_AML, 0x1);
139 : :
140 [ # # ]: 0 : if (!timeout)
141 : : return TXGBE_ERR_RESET_FAILED;
142 : :
143 : : /* Reset VF registers to initial values */
144 : 0 : txgbe_virt_clr_reg(hw);
145 : :
146 : : /* mailbox timeout can now become active */
147 : 0 : mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
148 : :
149 : 0 : msgbuf[0] = TXGBE_VF_RESET;
150 : 0 : mbx->write_posted(hw, msgbuf, 1, 0);
151 : :
152 : : msec_delay(10);
153 : :
154 : : /*
155 : : * set our "perm_addr" based on info provided by PF
156 : : * also set up the mc_filter_type which is piggy backed
157 : : * on the mac address in word 3
158 : : */
159 : 0 : ret_val = mbx->read_posted(hw, msgbuf,
160 : : TXGBE_VF_PERMADDR_MSG_LEN, 0);
161 [ # # ]: 0 : if (ret_val)
162 : : return ret_val;
163 : :
164 [ # # ]: 0 : if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
165 : : msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
166 : : return TXGBE_ERR_INVALID_MAC_ADDR;
167 : :
168 [ # # ]: 0 : if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
169 : 0 : memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
170 : :
171 : 0 : hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
172 : :
173 : 0 : return ret_val;
174 : : }
175 : :
176 : : /**
177 : : * txgbe_stop_hw_vf - Generic stop Tx/Rx units
178 : : * @hw: pointer to hardware structure
179 : : *
180 : : * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
181 : : * disables transmit and receive units. The adapter_stopped flag is used by
182 : : * the shared code and drivers to determine if the adapter is in a stopped
183 : : * state and should not touch the hardware.
184 : : **/
185 : 0 : s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
186 : : {
187 : : u16 i;
188 : :
189 : : /*
190 : : * Set the adapter_stopped flag so other driver functions stop touching
191 : : * the hardware
192 : : */
193 : 0 : hw->adapter_stopped = true;
194 : :
195 : : /* Clear interrupt mask to stop from interrupts being generated */
196 : : wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
197 : :
198 : : /* Clear any pending interrupts, flush previous writes */
199 : : wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
200 : :
201 : : /* Disable the transmit unit. Each queue must be disabled. */
202 [ # # ]: 0 : for (i = 0; i < hw->mac.max_tx_queues; i++)
203 : 0 : wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
204 : :
205 : : /* Disable the receive unit by stopping each queue */
206 [ # # ]: 0 : for (i = 0; i < hw->mac.max_rx_queues; i++)
207 : 0 : wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
208 : :
209 : : /* Clear packet split and pool config */
210 : : wr32(hw, TXGBE_VFPLCFG, 0);
211 [ # # # ]: 0 : hw->rx_loaded = 1;
212 : :
213 : : /* flush all queues disables */
214 : : txgbe_flush(hw);
215 : : msec_delay(2);
216 : :
217 : 0 : return 0;
218 : : }
219 : :
220 : : /**
221 : : * txgbe_mta_vector - Determines bit-vector in multicast table to set
222 : : * @hw: pointer to hardware structure
223 : : * @mc_addr: the multicast address
224 : : **/
225 : 0 : STATIC s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
226 : : {
227 : : u32 vector = 0;
228 : :
229 [ # # # # : 0 : switch (hw->mac.mc_filter_type) {
# ]
230 : 0 : case 0: /* use bits [47:36] of the address */
231 : 0 : vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
232 : 0 : break;
233 : 0 : case 1: /* use bits [46:35] of the address */
234 : 0 : vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
235 : 0 : break;
236 : 0 : case 2: /* use bits [45:34] of the address */
237 : 0 : vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
238 : 0 : break;
239 : 0 : case 3: /* use bits [43:32] of the address */
240 : 0 : vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
241 : 0 : break;
242 : 0 : default: /* Invalid mc_filter_type */
243 : 0 : DEBUGOUT("MC filter type param set incorrectly");
244 : 0 : ASSERT(0);
245 : : break;
246 : : }
247 : :
248 : : /* vector can only be 12-bits or boundary will be exceeded */
249 : 0 : vector &= 0xFFF;
250 : 0 : return vector;
251 : : }
252 : :
253 : : STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
254 : : u32 *retmsg, u16 size)
255 : : {
256 : : struct txgbe_mbx_info *mbx = &hw->mbx;
257 : 0 : s32 retval = mbx->write_posted(hw, msg, size, 0);
258 : :
259 [ # # # # : 0 : if (retval)
# # # # #
# # # # #
# # # # #
# ]
260 : : return retval;
261 : :
262 : 0 : return mbx->read_posted(hw, retmsg, size, 0);
263 : : }
264 : :
265 : : /**
266 : : * txgbe_set_rar_vf - set device MAC address
267 : : * @hw: pointer to hardware structure
268 : : * @index: Receive address register to write
269 : : * @addr: Address to put into receive address register
270 : : * @vmdq: VMDq "set" or "pool" index
271 : : * @enable_addr: set flag that address is active
272 : : **/
273 : 0 : s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
274 : : u32 enable_addr)
275 : : {
276 : : u32 msgbuf[3];
277 : : u8 *msg_addr = (u8 *)(&msgbuf[1]);
278 : : s32 ret_val;
279 : : UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
280 : :
281 : : memset(msgbuf, 0, 12);
282 : 0 : msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
283 : : memcpy(msg_addr, addr, 6);
284 : : ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
285 : :
286 : 0 : msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
287 : :
288 : : /* if nacked the address was rejected, use "perm_addr" */
289 [ # # # # ]: 0 : if (!ret_val &&
290 : : (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
291 : 0 : txgbe_get_mac_addr_vf(hw, hw->mac.addr);
292 : 0 : return TXGBE_ERR_MBX;
293 : : }
294 : :
295 : : return ret_val;
296 : : }
297 : :
298 : : /**
299 : : * txgbe_update_mc_addr_list_vf - Update Multicast addresses
300 : : * @hw: pointer to the HW structure
301 : : * @mc_addr_list: array of multicast addresses to program
302 : : * @mc_addr_count: number of multicast addresses to program
303 : : * @next: caller supplied function to return next address in list
304 : : * @clear: unused
305 : : *
306 : : * Updates the Multicast Table Array.
307 : : **/
308 : 0 : s32 txgbe_update_mc_addr_list_vf(struct txgbe_hw *hw, u8 *mc_addr_list,
309 : : u32 mc_addr_count, txgbe_mc_addr_itr next,
310 : : bool clear)
311 : : {
312 : : struct txgbe_mbx_info *mbx = &hw->mbx;
313 : : u32 msgbuf[TXGBE_P2VMBX_SIZE];
314 : : u16 *vector_list = (u16 *)&msgbuf[1];
315 : : u32 vector;
316 : : u32 cnt, i;
317 : : u32 vmdq;
318 : :
319 : : UNREFERENCED_PARAMETER(clear);
320 : :
321 : : /* Each entry in the list uses 1 16 bit word. We have 30
322 : : * 16 bit words available in our HW msg buffer (minus 1 for the
323 : : * msg type). That's 30 hash values if we pack 'em right. If
324 : : * there are more than 30 MC addresses to add then punt the
325 : : * extras for now and then add code to handle more than 30 later.
326 : : * It would be unusual for a server to request that many multi-cast
327 : : * addresses except for in large enterprise network environments.
328 : : */
329 : :
330 : 0 : DEBUGOUT("MC Addr Count = %d", mc_addr_count);
331 : :
332 : 0 : cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
333 : : msgbuf[0] = TXGBE_VF_SET_MULTICAST;
334 : 0 : msgbuf[0] |= cnt << TXGBE_VT_MSGINFO_SHIFT;
335 : :
336 [ # # ]: 0 : for (i = 0; i < cnt; i++) {
337 : 0 : vector = txgbe_mta_vector(hw, next(hw, &mc_addr_list, &vmdq));
338 : 0 : DEBUGOUT("Hash value = 0x%03X", vector);
339 : 0 : vector_list[i] = (u16)vector;
340 : : }
341 : :
342 : 0 : return mbx->write_posted(hw, msgbuf, TXGBE_P2VMBX_SIZE, 0);
343 : : }
344 : :
345 : : /**
346 : : * txgbevf_update_xcast_mode - Update Multicast mode
347 : : * @hw: pointer to the HW structure
348 : : * @xcast_mode: new multicast mode
349 : : *
350 : : * Updates the Multicast Mode of VF.
351 : : **/
352 : 0 : s32 txgbevf_update_xcast_mode(struct txgbe_hw *hw, int xcast_mode)
353 : : {
354 : : u32 msgbuf[2];
355 : : s32 err;
356 : :
357 [ # # # ]: 0 : switch (hw->api_version) {
358 : 0 : case txgbe_mbox_api_12:
359 : : /* New modes were introduced in 1.3 version */
360 [ # # ]: 0 : if (xcast_mode > TXGBEVF_XCAST_MODE_ALLMULTI)
361 : : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
362 : : /* Fall through */
363 : : case txgbe_mbox_api_13:
364 : : case txgbe_mbox_api_21:
365 : : case txgbe_mbox_api_23:
366 : : break;
367 : : default:
368 : : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
369 : : }
370 : :
371 : 0 : msgbuf[0] = TXGBE_VF_UPDATE_XCAST_MODE;
372 : 0 : msgbuf[1] = xcast_mode;
373 : :
374 : : err = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
375 [ # # ]: 0 : if (err)
376 : : return err;
377 : :
378 : 0 : msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
379 [ # # ]: 0 : if (msgbuf[0] == (TXGBE_VF_UPDATE_XCAST_MODE | TXGBE_VT_MSGTYPE_NACK))
380 : 0 : return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
381 : : return 0;
382 : : }
383 : :
384 : : /**
385 : : * txgbe_set_vfta_vf - Set/Unset vlan filter table address
386 : : * @hw: pointer to the HW structure
387 : : * @vlan: 12 bit VLAN ID
388 : : * @vind: unused by VF drivers
389 : : * @vlan_on: if true then set bit, else clear bit
390 : : * @vlvf_bypass: boolean flag indicating updating default pool is okay
391 : : *
392 : : * Turn on/off specified VLAN in the VLAN filter table.
393 : : **/
394 : 0 : s32 txgbe_set_vfta_vf(struct txgbe_hw *hw, u32 vlan, u32 vind,
395 : : bool vlan_on, bool vlvf_bypass)
396 : : {
397 : : u32 msgbuf[2];
398 : : s32 ret_val;
399 : : UNREFERENCED_PARAMETER(vind, vlvf_bypass);
400 : :
401 : : msgbuf[0] = TXGBE_VF_SET_VLAN;
402 : 0 : msgbuf[1] = vlan;
403 : : /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
404 : 0 : msgbuf[0] |= vlan_on << TXGBE_VT_MSGINFO_SHIFT;
405 : :
406 : : ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
407 [ # # # # ]: 0 : if (!ret_val && (msgbuf[0] & TXGBE_VT_MSGTYPE_ACK))
408 : : return 0;
409 : :
410 : 0 : return ret_val | (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK);
411 : : }
412 : :
413 : : /**
414 : : * txgbe_get_mac_addr_vf - Read device MAC address
415 : : * @hw: pointer to the HW structure
416 : : * @mac_addr: the MAC address
417 : : **/
418 : 0 : s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
419 : : {
420 : : int i;
421 : :
422 [ # # ]: 0 : for (i = 0; i < ETH_ADDR_LEN; i++)
423 : 0 : mac_addr[i] = hw->mac.perm_addr[i];
424 : :
425 : 0 : return 0;
426 : : }
427 : :
428 [ # # ]: 0 : s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
429 : : {
430 : : u32 msgbuf[3], msgbuf_chk;
431 : : u8 *msg_addr = (u8 *)(&msgbuf[1]);
432 : : s32 ret_val;
433 : :
434 : : memset(msgbuf, 0, sizeof(msgbuf));
435 : : /*
436 : : * If index is one then this is the start of a new list and needs
437 : : * indication to the PF so it can do it's own list management.
438 : : * If it is zero then that tells the PF to just clear all of
439 : : * this VF's macvlans and there is no new list.
440 : : */
441 : 0 : msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
442 : 0 : msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
443 : : msgbuf_chk = msgbuf[0];
444 [ # # ]: 0 : if (addr)
445 : : memcpy(msg_addr, addr, 6);
446 : :
447 : : ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
448 [ # # ]: 0 : if (!ret_val) {
449 : 0 : msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
450 : :
451 [ # # ]: 0 : if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
452 : 0 : return TXGBE_ERR_OUT_OF_MEM;
453 : : }
454 : :
455 : : return ret_val;
456 : : }
457 : :
458 : : /**
459 : : * txgbe_check_mac_link_vf - Get link/speed status
460 : : * @hw: pointer to hardware structure
461 : : * @speed: pointer to link speed
462 : : * @link_up: true is link is up, false otherwise
463 : : * @autoneg_wait_to_complete: true when waiting for completion is needed
464 : : *
465 : : * Reads the links register to determine if link is up and the current speed
466 : : **/
467 : 0 : s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
468 : : bool *link_up, bool wait_to_complete)
469 : : {
470 : : /**
471 : : * for a quick link status checking, wait_to_compelet == 0,
472 : : * skip PF link status checking
473 : : */
474 : 0 : bool no_pflink_check = wait_to_complete == 0;
475 : : struct txgbe_mbx_info *mbx = &hw->mbx;
476 : : struct txgbe_mac_info *mac = &hw->mac;
477 : : s32 ret_val = 0;
478 : : u32 links_reg;
479 : 0 : u32 in_msg = 0;
480 : :
481 : : /* If we were hit with a reset drop the link */
482 [ # # # # ]: 0 : if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
483 : 0 : mac->get_link_status = true;
484 : :
485 [ # # ]: 0 : if (!mac->get_link_status)
486 : 0 : goto out;
487 : :
488 : : /* if link status is down no point in checking to see if pf is up */
489 : : links_reg = rd32(hw, TXGBE_VFSTATUS);
490 [ # # ]: 0 : if (!(links_reg & TXGBE_VFSTATUS_UP))
491 : 0 : goto out;
492 : :
493 : : /* for SFP+ modules and DA cables it can take up to 500usecs
494 : : * before the link status is correct
495 : : */
496 [ # # ]: 0 : if ((mac->type == txgbe_mac_sp_vf ||
497 [ # # ]: 0 : mac->type == txgbe_mac_aml_vf) && 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 : : }
|