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->update_xcast_mode = txgbevf_update_xcast_mode;
37 mac->set_vfta = txgbe_set_vfta_vf;
38 mac->set_rlpml = txgbevf_rlpml_set_vf;
40 mac->max_tx_queues = 1;
41 mac->max_rx_queues = 1;
43 mbx->init_params = txgbe_init_mbx_params_vf;
44 mbx->read = txgbe_read_mbx_vf;
45 mbx->write = txgbe_write_mbx_vf;
46 mbx->read_posted = txgbe_read_posted_mbx;
47 mbx->write_posted = txgbe_write_posted_mbx;
48 mbx->check_for_msg = txgbe_check_for_msg_vf;
49 mbx->check_for_ack = txgbe_check_for_ack_vf;
50 mbx->check_for_rst = txgbe_check_for_rst_vf;
55 /* txgbe_virt_clr_reg - Set register to default (power on) state.
56 * @hw: pointer to hardware structure
58 static void txgbe_virt_clr_reg(struct txgbe_hw *hw)
63 /* default values (BUF_SIZE = 2048, HDR_SIZE = 256) */
64 vfsrrctl = TXGBE_RXCFG_HDRLEN(TXGBE_RX_HDR_SIZE);
65 vfsrrctl |= TXGBE_RXCFG_PKTLEN(TXGBE_RX_BUF_SIZE);
67 for (i = 0; i < 8; i++) {
68 wr32m(hw, TXGBE_RXCFG(i),
69 (TXGBE_RXCFG_HDRLEN_MASK | TXGBE_RXCFG_PKTLEN_MASK),
77 * txgbe_start_hw_vf - Prepare hardware for Tx/Rx
78 * @hw: pointer to hardware structure
80 * Starts the hardware by filling the bus info structure and media type, clears
81 * all on chip counters, initializes receive address registers, multicast
82 * table, VLAN filter table, calls routine to set up link and flow control
83 * settings, and leaves transmit and receive units disabled and uninitialized
85 s32 txgbe_start_hw_vf(struct txgbe_hw *hw)
87 /* Clear adapter stopped flag */
88 hw->adapter_stopped = false;
94 * txgbe_reset_hw_vf - Performs hardware reset
95 * @hw: pointer to hardware structure
97 * Resets the hardware by resetting the transmit and receive units, masks and
98 * clears all interrupts.
100 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw)
102 struct txgbe_mbx_info *mbx = &hw->mbx;
103 u32 timeout = TXGBE_VF_INIT_TIMEOUT;
104 s32 ret_val = TXGBE_ERR_INVALID_MAC_ADDR;
105 u32 msgbuf[TXGBE_VF_PERMADDR_MSG_LEN];
106 u8 *addr = (u8 *)(&msgbuf[1]);
108 DEBUGFUNC("txgbevf_reset_hw_vf");
110 /* Call adapter stop to disable tx/rx and clear interrupts */
113 /* reset the api version */
114 hw->api_version = txgbe_mbox_api_10;
116 /* backup msix vectors */
117 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
118 msgbuf[0] = TXGBE_VF_BACKUP;
119 mbx->write_posted(hw, msgbuf, 1, 0);
122 DEBUGOUT("Issuing a function level reset to MAC\n");
123 wr32(hw, TXGBE_VFRST, TXGBE_VFRST_SET);
127 hw->offset_loaded = 1;
129 /* we cannot reset while the RSTI / RSTD bits are asserted */
130 while (!mbx->check_for_rst(hw, 0) && timeout) {
132 /* if it doesn't work, try in 1 ms */
137 return TXGBE_ERR_RESET_FAILED;
139 /* Reset VF registers to initial values */
140 txgbe_virt_clr_reg(hw);
142 /* mailbox timeout can now become active */
143 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
145 msgbuf[0] = TXGBE_VF_RESET;
146 mbx->write_posted(hw, msgbuf, 1, 0);
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
155 ret_val = mbx->read_posted(hw, msgbuf,
156 TXGBE_VF_PERMADDR_MSG_LEN, 0);
160 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;
164 if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
165 memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
167 hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
173 * txgbe_stop_hw_vf - Generic stop Tx/Rx units
174 * @hw: pointer to hardware structure
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.
181 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
186 * Set the adapter_stopped flag so other driver functions stop touching
189 hw->adapter_stopped = true;
191 /* Clear interrupt mask to stop from interrupts being generated */
192 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
194 /* Clear any pending interrupts, flush previous writes */
195 wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
197 /* Disable the transmit unit. Each queue must be disabled. */
198 for (i = 0; i < hw->mac.max_tx_queues; i++)
199 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
201 /* Disable the receive unit by stopping each queue */
202 for (i = 0; i < hw->mac.max_rx_queues; i++)
203 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
205 /* Clear packet split and pool config */
206 wr32(hw, TXGBE_VFPLCFG, 0);
209 /* flush all queues disables */
216 STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
217 u32 *retmsg, u16 size)
219 struct txgbe_mbx_info *mbx = &hw->mbx;
220 s32 retval = mbx->write_posted(hw, msg, size, 0);
225 return mbx->read_posted(hw, retmsg, size, 0);
229 * txgbe_set_rar_vf - set device MAC address
230 * @hw: pointer to hardware structure
231 * @index: Receive address register to write
232 * @addr: Address to put into receive address register
233 * @vmdq: VMDq "set" or "pool" index
234 * @enable_addr: set flag that address is active
236 s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
240 u8 *msg_addr = (u8 *)(&msgbuf[1]);
242 UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
244 memset(msgbuf, 0, 12);
245 msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
246 memcpy(msg_addr, addr, 6);
247 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
249 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
251 /* if nacked the address was rejected, use "perm_addr" */
253 (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
254 txgbe_get_mac_addr_vf(hw, hw->mac.addr);
255 return TXGBE_ERR_MBX;
262 * txgbevf_update_xcast_mode - Update Multicast mode
263 * @hw: pointer to the HW structure
264 * @xcast_mode: new multicast mode
266 * Updates the Multicast Mode of VF.
268 s32 txgbevf_update_xcast_mode(struct txgbe_hw *hw, int xcast_mode)
273 switch (hw->api_version) {
274 case txgbe_mbox_api_12:
275 /* New modes were introduced in 1.3 version */
276 if (xcast_mode > TXGBEVF_XCAST_MODE_ALLMULTI)
277 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
279 case txgbe_mbox_api_13:
282 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
285 msgbuf[0] = TXGBE_VF_UPDATE_XCAST_MODE;
286 msgbuf[1] = xcast_mode;
288 err = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
292 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
293 if (msgbuf[0] == (TXGBE_VF_UPDATE_XCAST_MODE | TXGBE_VT_MSGTYPE_NACK))
294 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
299 * txgbe_set_vfta_vf - Set/Unset vlan filter table address
300 * @hw: pointer to the HW structure
301 * @vlan: 12 bit VLAN ID
302 * @vind: unused by VF drivers
303 * @vlan_on: if true then set bit, else clear bit
304 * @vlvf_bypass: boolean flag indicating updating default pool is okay
306 * Turn on/off specified VLAN in the VLAN filter table.
308 s32 txgbe_set_vfta_vf(struct txgbe_hw *hw, u32 vlan, u32 vind,
309 bool vlan_on, bool vlvf_bypass)
313 UNREFERENCED_PARAMETER(vind, vlvf_bypass);
315 msgbuf[0] = TXGBE_VF_SET_VLAN;
317 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
318 msgbuf[0] |= vlan_on << TXGBE_VT_MSGINFO_SHIFT;
320 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
321 if (!ret_val && (msgbuf[0] & TXGBE_VT_MSGTYPE_ACK))
324 return ret_val | (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK);
328 * txgbe_get_mac_addr_vf - Read device MAC address
329 * @hw: pointer to the HW structure
330 * @mac_addr: the MAC address
332 s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
336 for (i = 0; i < ETH_ADDR_LEN; i++)
337 mac_addr[i] = hw->mac.perm_addr[i];
342 s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
344 u32 msgbuf[3], msgbuf_chk;
345 u8 *msg_addr = (u8 *)(&msgbuf[1]);
348 memset(msgbuf, 0, sizeof(msgbuf));
350 * If index is one then this is the start of a new list and needs
351 * indication to the PF so it can do it's own list management.
352 * If it is zero then that tells the PF to just clear all of
353 * this VF's macvlans and there is no new list.
355 msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
356 msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
357 msgbuf_chk = msgbuf[0];
359 memcpy(msg_addr, addr, 6);
361 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
363 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
365 if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
366 return TXGBE_ERR_OUT_OF_MEM;
373 * txgbe_check_mac_link_vf - Get link/speed status
374 * @hw: pointer to hardware structure
375 * @speed: pointer to link speed
376 * @link_up: true is link is up, false otherwise
377 * @autoneg_wait_to_complete: true when waiting for completion is needed
379 * Reads the links register to determine if link is up and the current speed
381 s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
382 bool *link_up, bool wait_to_complete)
385 * for a quick link status checking, wait_to_compelet == 0,
386 * skip PF link status checking
388 bool no_pflink_check = wait_to_complete == 0;
389 struct txgbe_mbx_info *mbx = &hw->mbx;
390 struct txgbe_mac_info *mac = &hw->mac;
395 /* If we were hit with a reset drop the link */
396 if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
397 mac->get_link_status = true;
399 if (!mac->get_link_status)
402 /* if link status is down no point in checking to see if pf is up */
403 links_reg = rd32(hw, TXGBE_VFSTATUS);
404 if (!(links_reg & TXGBE_VFSTATUS_UP))
407 /* for SFP+ modules and DA cables it can take up to 500usecs
408 * before the link status is correct
410 if (mac->type == txgbe_mac_raptor_vf && wait_to_complete) {
411 if (po32m(hw, TXGBE_VFSTATUS, TXGBE_VFSTATUS_UP,
416 switch (links_reg & TXGBE_VFSTATUS_BW_MASK) {
417 case TXGBE_VFSTATUS_BW_10G:
418 *speed = TXGBE_LINK_SPEED_10GB_FULL;
420 case TXGBE_VFSTATUS_BW_1G:
421 *speed = TXGBE_LINK_SPEED_1GB_FULL;
423 case TXGBE_VFSTATUS_BW_100M:
424 *speed = TXGBE_LINK_SPEED_100M_FULL;
427 *speed = TXGBE_LINK_SPEED_UNKNOWN;
430 if (no_pflink_check) {
431 if (*speed == TXGBE_LINK_SPEED_UNKNOWN)
432 mac->get_link_status = true;
434 mac->get_link_status = false;
439 /* if the read failed it could just be a mailbox collision, best wait
440 * until we are called again and don't report an error
442 if (mbx->read(hw, &in_msg, 1, 0))
445 if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
446 /* msg is not CTS and is NACK we must have lost CTS status */
447 if (in_msg & TXGBE_VT_MSGTYPE_NACK)
452 /* the pf is talking, if we timed out in the past we reinit */
458 /* if we passed all the tests above then the link is up and we no
459 * longer need to check for link
461 mac->get_link_status = false;
464 *link_up = !mac->get_link_status;
469 * txgbevf_rlpml_set_vf - Set the maximum receive packet length
470 * @hw: pointer to the HW structure
471 * @max_size: value to assign to max frame size
473 s32 txgbevf_rlpml_set_vf(struct txgbe_hw *hw, u16 max_size)
478 msgbuf[0] = TXGBE_VF_SET_LPE;
479 msgbuf[1] = max_size;
481 retval = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
484 if ((msgbuf[0] & TXGBE_VF_SET_LPE) &&
485 (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK))
486 return TXGBE_ERR_MBX;
492 * txgbevf_negotiate_api_version - Negotiate supported API version
493 * @hw: pointer to the HW structure
494 * @api: integer containing requested API version
496 int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
501 /* Negotiate the mailbox API version */
502 msg[0] = TXGBE_VF_API_NEGOTIATE;
506 err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
508 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
510 /* Store value and return 0 on success */
511 if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
512 hw->api_version = api;
516 err = TXGBE_ERR_INVALID_ARGUMENT;
522 int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
523 unsigned int *default_tc)
528 /* do nothing if API doesn't support txgbevf_get_queues */
529 switch (hw->api_version) {
530 case txgbe_mbox_api_11:
531 case txgbe_mbox_api_12:
532 case txgbe_mbox_api_13:
538 /* Fetch queue configuration from the PF */
539 msg[0] = TXGBE_VF_GET_QUEUES;
540 for (i = 1; i < 5; i++)
543 err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
545 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
548 * if we didn't get an ACK there must have been
549 * some sort of mailbox error so we should treat it
552 if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
553 return TXGBE_ERR_MBX;
555 /* record and validate values from message */
556 hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
557 if (hw->mac.max_tx_queues == 0 ||
558 hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
559 hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
561 hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
562 if (hw->mac.max_rx_queues == 0 ||
563 hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
564 hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
566 *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
567 /* in case of unknown state assume we cannot tag frames */
568 if (*num_tcs > hw->mac.max_rx_queues)
571 *default_tc = msg[TXGBE_VF_DEF_QUEUE];
572 /* default to queue 0 on out-of-bounds queue number */
573 if (*default_tc >= hw->mac.max_tx_queues)