1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
9 * txgbe_init_ops_vf - Initialize the pointers for vf
10 * @hw: pointer to hardware structure
12 * This will assign function pointers, adapter-specific functions can
13 * override the assignment of generic function pointers by assigning
14 * their own adapter-specific function pointers.
15 * Does not touch the hardware.
17 s32 txgbe_init_ops_vf(struct txgbe_hw *hw)
19 struct txgbe_mac_info *mac = &hw->mac;
20 struct txgbe_mbx_info *mbx = &hw->mbx;
23 mac->reset_hw = txgbe_reset_hw_vf;
24 mac->start_hw = txgbe_start_hw_vf;
25 /* Cannot clear stats on VF */
26 mac->get_mac_addr = txgbe_get_mac_addr_vf;
27 mac->stop_hw = txgbe_stop_hw_vf;
28 mac->negotiate_api_version = txgbevf_negotiate_api_version;
31 mac->check_link = txgbe_check_mac_link_vf;
33 /* RAR, Multicast, VLAN */
34 mac->set_rar = txgbe_set_rar_vf;
35 mac->set_uc_addr = txgbevf_set_uc_addr_vf;
36 mac->set_vfta = txgbe_set_vfta_vf;
37 mac->set_rlpml = txgbevf_rlpml_set_vf;
39 mac->max_tx_queues = 1;
40 mac->max_rx_queues = 1;
42 mbx->init_params = txgbe_init_mbx_params_vf;
43 mbx->read = txgbe_read_mbx_vf;
44 mbx->write = txgbe_write_mbx_vf;
45 mbx->read_posted = txgbe_read_posted_mbx;
46 mbx->write_posted = txgbe_write_posted_mbx;
47 mbx->check_for_msg = txgbe_check_for_msg_vf;
48 mbx->check_for_ack = txgbe_check_for_ack_vf;
49 mbx->check_for_rst = txgbe_check_for_rst_vf;
54 /* txgbe_virt_clr_reg - Set register to default (power on) state.
55 * @hw: pointer to hardware structure
57 static void txgbe_virt_clr_reg(struct txgbe_hw *hw)
62 /* default values (BUF_SIZE = 2048, HDR_SIZE = 256) */
63 vfsrrctl = TXGBE_RXCFG_HDRLEN(TXGBE_RX_HDR_SIZE);
64 vfsrrctl |= TXGBE_RXCFG_PKTLEN(TXGBE_RX_BUF_SIZE);
66 for (i = 0; i < 8; i++) {
67 wr32m(hw, TXGBE_RXCFG(i),
68 (TXGBE_RXCFG_HDRLEN_MASK | TXGBE_RXCFG_PKTLEN_MASK),
76 * txgbe_start_hw_vf - Prepare hardware for Tx/Rx
77 * @hw: pointer to hardware structure
79 * Starts the hardware by filling the bus info structure and media type, clears
80 * all on chip counters, initializes receive address registers, multicast
81 * table, VLAN filter table, calls routine to set up link and flow control
82 * settings, and leaves transmit and receive units disabled and uninitialized
84 s32 txgbe_start_hw_vf(struct txgbe_hw *hw)
86 /* Clear adapter stopped flag */
87 hw->adapter_stopped = false;
93 * txgbe_reset_hw_vf - Performs hardware reset
94 * @hw: pointer to hardware structure
96 * Resets the hardware by resetting the transmit and receive units, masks and
97 * clears all interrupts.
99 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw)
101 struct txgbe_mbx_info *mbx = &hw->mbx;
102 u32 timeout = TXGBE_VF_INIT_TIMEOUT;
103 s32 ret_val = TXGBE_ERR_INVALID_MAC_ADDR;
104 u32 msgbuf[TXGBE_VF_PERMADDR_MSG_LEN];
105 u8 *addr = (u8 *)(&msgbuf[1]);
107 DEBUGFUNC("txgbevf_reset_hw_vf");
109 /* Call adapter stop to disable tx/rx and clear interrupts */
112 /* reset the api version */
113 hw->api_version = txgbe_mbox_api_10;
115 /* backup msix vectors */
116 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
117 msgbuf[0] = TXGBE_VF_BACKUP;
118 mbx->write_posted(hw, msgbuf, 1, 0);
121 DEBUGOUT("Issuing a function level reset to MAC\n");
122 wr32(hw, TXGBE_VFRST, TXGBE_VFRST_SET);
126 hw->offset_loaded = 1;
128 /* we cannot reset while the RSTI / RSTD bits are asserted */
129 while (!mbx->check_for_rst(hw, 0) && timeout) {
131 /* if it doesn't work, try in 1 ms */
136 return TXGBE_ERR_RESET_FAILED;
138 /* Reset VF registers to initial values */
139 txgbe_virt_clr_reg(hw);
141 /* mailbox timeout can now become active */
142 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
144 msgbuf[0] = TXGBE_VF_RESET;
145 mbx->write_posted(hw, msgbuf, 1, 0);
150 * set our "perm_addr" based on info provided by PF
151 * also set up the mc_filter_type which is piggy backed
152 * on the mac address in word 3
154 ret_val = mbx->read_posted(hw, msgbuf,
155 TXGBE_VF_PERMADDR_MSG_LEN, 0);
159 if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
160 msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
161 return TXGBE_ERR_INVALID_MAC_ADDR;
163 if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
164 memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
166 hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
172 * txgbe_stop_hw_vf - Generic stop Tx/Rx units
173 * @hw: pointer to hardware structure
175 * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
176 * disables transmit and receive units. The adapter_stopped flag is used by
177 * the shared code and drivers to determine if the adapter is in a stopped
178 * state and should not touch the hardware.
180 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
185 * Set the adapter_stopped flag so other driver functions stop touching
188 hw->adapter_stopped = true;
190 /* Clear interrupt mask to stop from interrupts being generated */
191 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
193 /* Clear any pending interrupts, flush previous writes */
194 wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
196 /* Disable the transmit unit. Each queue must be disabled. */
197 for (i = 0; i < hw->mac.max_tx_queues; i++)
198 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
200 /* Disable the receive unit by stopping each queue */
201 for (i = 0; i < hw->mac.max_rx_queues; i++)
202 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
204 /* Clear packet split and pool config */
205 wr32(hw, TXGBE_VFPLCFG, 0);
208 /* flush all queues disables */
215 STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
216 u32 *retmsg, u16 size)
218 struct txgbe_mbx_info *mbx = &hw->mbx;
219 s32 retval = mbx->write_posted(hw, msg, size, 0);
224 return mbx->read_posted(hw, retmsg, size, 0);
228 * txgbe_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
235 s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
239 u8 *msg_addr = (u8 *)(&msgbuf[1]);
241 UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
243 memset(msgbuf, 0, 12);
244 msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
245 memcpy(msg_addr, addr, 6);
246 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
248 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
250 /* if nacked the address was rejected, use "perm_addr" */
252 (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
253 txgbe_get_mac_addr_vf(hw, hw->mac.addr);
254 return TXGBE_ERR_MBX;
261 * txgbe_set_vfta_vf - Set/Unset vlan filter table address
262 * @hw: pointer to the HW structure
263 * @vlan: 12 bit VLAN ID
264 * @vind: unused by VF drivers
265 * @vlan_on: if true then set bit, else clear bit
266 * @vlvf_bypass: boolean flag indicating updating default pool is okay
268 * Turn on/off specified VLAN in the VLAN filter table.
270 s32 txgbe_set_vfta_vf(struct txgbe_hw *hw, u32 vlan, u32 vind,
271 bool vlan_on, bool vlvf_bypass)
275 UNREFERENCED_PARAMETER(vind, vlvf_bypass);
277 msgbuf[0] = TXGBE_VF_SET_VLAN;
279 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
280 msgbuf[0] |= vlan_on << TXGBE_VT_MSGINFO_SHIFT;
282 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
283 if (!ret_val && (msgbuf[0] & TXGBE_VT_MSGTYPE_ACK))
286 return ret_val | (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK);
290 * txgbe_get_mac_addr_vf - Read device MAC address
291 * @hw: pointer to the HW structure
292 * @mac_addr: the MAC address
294 s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
298 for (i = 0; i < ETH_ADDR_LEN; i++)
299 mac_addr[i] = hw->mac.perm_addr[i];
304 s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
306 u32 msgbuf[3], msgbuf_chk;
307 u8 *msg_addr = (u8 *)(&msgbuf[1]);
310 memset(msgbuf, 0, sizeof(msgbuf));
312 * If index is one then this is the start of a new list and needs
313 * indication to the PF so it can do it's own list management.
314 * If it is zero then that tells the PF to just clear all of
315 * this VF's macvlans and there is no new list.
317 msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
318 msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
319 msgbuf_chk = msgbuf[0];
321 memcpy(msg_addr, addr, 6);
323 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
325 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
327 if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
328 return TXGBE_ERR_OUT_OF_MEM;
335 * txgbe_check_mac_link_vf - Get link/speed status
336 * @hw: pointer to hardware structure
337 * @speed: pointer to link speed
338 * @link_up: true is link is up, false otherwise
339 * @autoneg_wait_to_complete: true when waiting for completion is needed
341 * Reads the links register to determine if link is up and the current speed
343 s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
344 bool *link_up, bool wait_to_complete)
347 * for a quick link status checking, wait_to_compelet == 0,
348 * skip PF link status checking
350 bool no_pflink_check = wait_to_complete == 0;
351 struct txgbe_mbx_info *mbx = &hw->mbx;
352 struct txgbe_mac_info *mac = &hw->mac;
357 /* If we were hit with a reset drop the link */
358 if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
359 mac->get_link_status = true;
361 if (!mac->get_link_status)
364 /* if link status is down no point in checking to see if pf is up */
365 links_reg = rd32(hw, TXGBE_VFSTATUS);
366 if (!(links_reg & TXGBE_VFSTATUS_UP))
369 /* for SFP+ modules and DA cables it can take up to 500usecs
370 * before the link status is correct
372 if (mac->type == txgbe_mac_raptor_vf && wait_to_complete) {
373 if (po32m(hw, TXGBE_VFSTATUS, TXGBE_VFSTATUS_UP,
378 switch (links_reg & TXGBE_VFSTATUS_BW_MASK) {
379 case TXGBE_VFSTATUS_BW_10G:
380 *speed = TXGBE_LINK_SPEED_10GB_FULL;
382 case TXGBE_VFSTATUS_BW_1G:
383 *speed = TXGBE_LINK_SPEED_1GB_FULL;
385 case TXGBE_VFSTATUS_BW_100M:
386 *speed = TXGBE_LINK_SPEED_100M_FULL;
389 *speed = TXGBE_LINK_SPEED_UNKNOWN;
392 if (no_pflink_check) {
393 if (*speed == TXGBE_LINK_SPEED_UNKNOWN)
394 mac->get_link_status = true;
396 mac->get_link_status = false;
401 /* if the read failed it could just be a mailbox collision, best wait
402 * until we are called again and don't report an error
404 if (mbx->read(hw, &in_msg, 1, 0))
407 if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
408 /* msg is not CTS and is NACK we must have lost CTS status */
409 if (in_msg & TXGBE_VT_MSGTYPE_NACK)
414 /* the pf is talking, if we timed out in the past we reinit */
420 /* if we passed all the tests above then the link is up and we no
421 * longer need to check for link
423 mac->get_link_status = false;
426 *link_up = !mac->get_link_status;
431 * txgbevf_rlpml_set_vf - Set the maximum receive packet length
432 * @hw: pointer to the HW structure
433 * @max_size: value to assign to max frame size
435 s32 txgbevf_rlpml_set_vf(struct txgbe_hw *hw, u16 max_size)
440 msgbuf[0] = TXGBE_VF_SET_LPE;
441 msgbuf[1] = max_size;
443 retval = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
446 if ((msgbuf[0] & TXGBE_VF_SET_LPE) &&
447 (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK))
448 return TXGBE_ERR_MBX;
454 * txgbevf_negotiate_api_version - Negotiate supported API version
455 * @hw: pointer to the HW structure
456 * @api: integer containing requested API version
458 int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
463 /* Negotiate the mailbox API version */
464 msg[0] = TXGBE_VF_API_NEGOTIATE;
468 err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
470 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
472 /* Store value and return 0 on success */
473 if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
474 hw->api_version = api;
478 err = TXGBE_ERR_INVALID_ARGUMENT;
484 int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
485 unsigned int *default_tc)
490 /* do nothing if API doesn't support txgbevf_get_queues */
491 switch (hw->api_version) {
492 case txgbe_mbox_api_11:
493 case txgbe_mbox_api_12:
494 case txgbe_mbox_api_13:
500 /* Fetch queue configuration from the PF */
501 msg[0] = TXGBE_VF_GET_QUEUES;
502 for (i = 1; i < 5; i++)
505 err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
507 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
510 * if we didn't get an ACK there must have been
511 * some sort of mailbox error so we should treat it
514 if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
515 return TXGBE_ERR_MBX;
517 /* record and validate values from message */
518 hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
519 if (hw->mac.max_tx_queues == 0 ||
520 hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
521 hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
523 hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
524 if (hw->mac.max_rx_queues == 0 ||
525 hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
526 hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
528 *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
529 /* in case of unknown state assume we cannot tag frames */
530 if (*num_tcs > hw->mac.max_rx_queues)
533 *default_tc = msg[TXGBE_VF_DEF_QUEUE];
534 /* default to queue 0 on out-of-bounds queue number */
535 if (*default_tc >= hw->mac.max_tx_queues)