1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
10 * txgbe_init_ops_vf - Initialize the pointers for vf
11 * @hw: pointer to hardware structure
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.
18 s32 txgbe_init_ops_vf(struct txgbe_hw *hw)
20 struct txgbe_mac_info *mac = &hw->mac;
21 struct txgbe_mbx_info *mbx = &hw->mbx;
24 mac->reset_hw = txgbe_reset_hw_vf;
25 mac->start_hw = txgbe_start_hw_vf;
26 /* Cannot clear stats on VF */
27 mac->get_mac_addr = txgbe_get_mac_addr_vf;
28 mac->stop_hw = txgbe_stop_hw_vf;
29 mac->negotiate_api_version = txgbevf_negotiate_api_version;
30 mac->update_mc_addr_list = txgbe_update_mc_addr_list_vf;
33 mac->check_link = txgbe_check_mac_link_vf;
35 /* RAR, Multicast, VLAN */
36 mac->set_rar = txgbe_set_rar_vf;
37 mac->set_uc_addr = txgbevf_set_uc_addr_vf;
38 mac->update_xcast_mode = txgbevf_update_xcast_mode;
39 mac->set_vfta = txgbe_set_vfta_vf;
40 mac->set_rlpml = txgbevf_rlpml_set_vf;
42 mac->max_tx_queues = 1;
43 mac->max_rx_queues = 1;
45 mbx->init_params = txgbe_init_mbx_params_vf;
46 mbx->read = txgbe_read_mbx_vf;
47 mbx->write = txgbe_write_mbx_vf;
48 mbx->read_posted = txgbe_read_posted_mbx;
49 mbx->write_posted = txgbe_write_posted_mbx;
50 mbx->check_for_msg = txgbe_check_for_msg_vf;
51 mbx->check_for_ack = txgbe_check_for_ack_vf;
52 mbx->check_for_rst = txgbe_check_for_rst_vf;
57 /* txgbe_virt_clr_reg - Set register to default (power on) state.
58 * @hw: pointer to hardware structure
60 static void txgbe_virt_clr_reg(struct txgbe_hw *hw)
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);
69 for (i = 0; i < 8; i++) {
70 wr32m(hw, TXGBE_RXCFG(i),
71 (TXGBE_RXCFG_HDRLEN_MASK | TXGBE_RXCFG_PKTLEN_MASK),
79 * txgbe_start_hw_vf - Prepare hardware for Tx/Rx
80 * @hw: pointer to hardware structure
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
87 s32 txgbe_start_hw_vf(struct txgbe_hw *hw)
89 /* Clear adapter stopped flag */
90 hw->adapter_stopped = false;
96 * txgbe_reset_hw_vf - Performs hardware reset
97 * @hw: pointer to hardware structure
99 * Resets the hardware by resetting the transmit and receive units, masks and
100 * clears all interrupts.
102 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw)
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]);
110 DEBUGFUNC("txgbevf_reset_hw_vf");
112 /* Call adapter stop to disable tx/rx and clear interrupts */
115 /* reset the api version */
116 hw->api_version = txgbe_mbox_api_10;
118 /* backup msix vectors */
119 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
120 msgbuf[0] = TXGBE_VF_BACKUP;
121 mbx->write_posted(hw, msgbuf, 1, 0);
124 DEBUGOUT("Issuing a function level reset to MAC\n");
125 wr32(hw, TXGBE_VFRST, TXGBE_VFRST_SET);
129 hw->offset_loaded = 1;
131 /* we cannot reset while the RSTI / RSTD bits are asserted */
132 while (!mbx->check_for_rst(hw, 0) && timeout) {
134 /* if it doesn't work, try in 1 ms */
139 return TXGBE_ERR_RESET_FAILED;
141 /* Reset VF registers to initial values */
142 txgbe_virt_clr_reg(hw);
144 /* mailbox timeout can now become active */
145 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
147 msgbuf[0] = TXGBE_VF_RESET;
148 mbx->write_posted(hw, msgbuf, 1, 0);
153 * set our "perm_addr" based on info provided by PF
154 * also set up the mc_filter_type which is piggy backed
155 * on the mac address in word 3
157 ret_val = mbx->read_posted(hw, msgbuf,
158 TXGBE_VF_PERMADDR_MSG_LEN, 0);
162 if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
163 msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
164 return TXGBE_ERR_INVALID_MAC_ADDR;
166 if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
167 memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
169 hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
175 * txgbe_stop_hw_vf - Generic stop Tx/Rx units
176 * @hw: pointer to hardware structure
178 * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
179 * disables transmit and receive units. The adapter_stopped flag is used by
180 * the shared code and drivers to determine if the adapter is in a stopped
181 * state and should not touch the hardware.
183 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
188 * Set the adapter_stopped flag so other driver functions stop touching
191 hw->adapter_stopped = true;
193 /* Clear interrupt mask to stop from interrupts being generated */
194 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
196 /* Clear any pending interrupts, flush previous writes */
197 wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
199 /* Disable the transmit unit. Each queue must be disabled. */
200 for (i = 0; i < hw->mac.max_tx_queues; i++)
201 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
203 /* Disable the receive unit by stopping each queue */
204 for (i = 0; i < hw->mac.max_rx_queues; i++)
205 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
207 /* Clear packet split and pool config */
208 wr32(hw, TXGBE_VFPLCFG, 0);
211 /* flush all queues disables */
219 * txgbe_mta_vector - Determines bit-vector in multicast table to set
220 * @hw: pointer to hardware structure
221 * @mc_addr: the multicast address
223 STATIC s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
227 switch (hw->mac.mc_filter_type) {
228 case 0: /* use bits [47:36] of the address */
229 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
231 case 1: /* use bits [46:35] of the address */
232 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
234 case 2: /* use bits [45:34] of the address */
235 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
237 case 3: /* use bits [43:32] of the address */
238 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
240 default: /* Invalid mc_filter_type */
241 DEBUGOUT("MC filter type param set incorrectly\n");
246 /* vector can only be 12-bits or boundary will be exceeded */
251 STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
252 u32 *retmsg, u16 size)
254 struct txgbe_mbx_info *mbx = &hw->mbx;
255 s32 retval = mbx->write_posted(hw, msg, size, 0);
260 return mbx->read_posted(hw, retmsg, size, 0);
264 * txgbe_set_rar_vf - set device MAC address
265 * @hw: pointer to hardware structure
266 * @index: Receive address register to write
267 * @addr: Address to put into receive address register
268 * @vmdq: VMDq "set" or "pool" index
269 * @enable_addr: set flag that address is active
271 s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
275 u8 *msg_addr = (u8 *)(&msgbuf[1]);
277 UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
279 memset(msgbuf, 0, 12);
280 msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
281 memcpy(msg_addr, addr, 6);
282 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
284 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
286 /* if nacked the address was rejected, use "perm_addr" */
288 (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
289 txgbe_get_mac_addr_vf(hw, hw->mac.addr);
290 return TXGBE_ERR_MBX;
297 * txgbe_update_mc_addr_list_vf - Update Multicast addresses
298 * @hw: pointer to the HW structure
299 * @mc_addr_list: array of multicast addresses to program
300 * @mc_addr_count: number of multicast addresses to program
301 * @next: caller supplied function to return next address in list
304 * Updates the Multicast Table Array.
306 s32 txgbe_update_mc_addr_list_vf(struct txgbe_hw *hw, u8 *mc_addr_list,
307 u32 mc_addr_count, txgbe_mc_addr_itr next,
310 struct txgbe_mbx_info *mbx = &hw->mbx;
311 u32 msgbuf[TXGBE_P2VMBX_SIZE];
312 u16 *vector_list = (u16 *)&msgbuf[1];
317 UNREFERENCED_PARAMETER(clear);
319 DEBUGFUNC("txgbe_update_mc_addr_list_vf");
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.
330 DEBUGOUT("MC Addr Count = %d\n", mc_addr_count);
332 cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
333 msgbuf[0] = TXGBE_VF_SET_MULTICAST;
334 msgbuf[0] |= cnt << TXGBE_VT_MSGINFO_SHIFT;
336 for (i = 0; i < cnt; i++) {
337 vector = txgbe_mta_vector(hw, next(hw, &mc_addr_list, &vmdq));
338 DEBUGOUT("Hash value = 0x%03X\n", vector);
339 vector_list[i] = (u16)vector;
342 return mbx->write_posted(hw, msgbuf, TXGBE_P2VMBX_SIZE, 0);
346 * txgbevf_update_xcast_mode - Update Multicast mode
347 * @hw: pointer to the HW structure
348 * @xcast_mode: new multicast mode
350 * Updates the Multicast Mode of VF.
352 s32 txgbevf_update_xcast_mode(struct txgbe_hw *hw, int xcast_mode)
357 switch (hw->api_version) {
358 case txgbe_mbox_api_12:
359 /* New modes were introduced in 1.3 version */
360 if (xcast_mode > TXGBEVF_XCAST_MODE_ALLMULTI)
361 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
363 case txgbe_mbox_api_13:
366 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
369 msgbuf[0] = TXGBE_VF_UPDATE_XCAST_MODE;
370 msgbuf[1] = xcast_mode;
372 err = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
376 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
377 if (msgbuf[0] == (TXGBE_VF_UPDATE_XCAST_MODE | TXGBE_VT_MSGTYPE_NACK))
378 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
383 * txgbe_set_vfta_vf - Set/Unset vlan filter table address
384 * @hw: pointer to the HW structure
385 * @vlan: 12 bit VLAN ID
386 * @vind: unused by VF drivers
387 * @vlan_on: if true then set bit, else clear bit
388 * @vlvf_bypass: boolean flag indicating updating default pool is okay
390 * Turn on/off specified VLAN in the VLAN filter table.
392 s32 txgbe_set_vfta_vf(struct txgbe_hw *hw, u32 vlan, u32 vind,
393 bool vlan_on, bool vlvf_bypass)
397 UNREFERENCED_PARAMETER(vind, vlvf_bypass);
399 msgbuf[0] = TXGBE_VF_SET_VLAN;
401 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
402 msgbuf[0] |= vlan_on << TXGBE_VT_MSGINFO_SHIFT;
404 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
405 if (!ret_val && (msgbuf[0] & TXGBE_VT_MSGTYPE_ACK))
408 return ret_val | (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK);
412 * txgbe_get_mac_addr_vf - Read device MAC address
413 * @hw: pointer to the HW structure
414 * @mac_addr: the MAC address
416 s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
420 for (i = 0; i < ETH_ADDR_LEN; i++)
421 mac_addr[i] = hw->mac.perm_addr[i];
426 s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
428 u32 msgbuf[3], msgbuf_chk;
429 u8 *msg_addr = (u8 *)(&msgbuf[1]);
432 memset(msgbuf, 0, sizeof(msgbuf));
434 * If index is one then this is the start of a new list and needs
435 * indication to the PF so it can do it's own list management.
436 * If it is zero then that tells the PF to just clear all of
437 * this VF's macvlans and there is no new list.
439 msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
440 msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
441 msgbuf_chk = msgbuf[0];
443 memcpy(msg_addr, addr, 6);
445 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
447 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
449 if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
450 return TXGBE_ERR_OUT_OF_MEM;
457 * txgbe_check_mac_link_vf - Get link/speed status
458 * @hw: pointer to hardware structure
459 * @speed: pointer to link speed
460 * @link_up: true is link is up, false otherwise
461 * @autoneg_wait_to_complete: true when waiting for completion is needed
463 * Reads the links register to determine if link is up and the current speed
465 s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
466 bool *link_up, bool wait_to_complete)
469 * for a quick link status checking, wait_to_compelet == 0,
470 * skip PF link status checking
472 bool no_pflink_check = wait_to_complete == 0;
473 struct txgbe_mbx_info *mbx = &hw->mbx;
474 struct txgbe_mac_info *mac = &hw->mac;
479 /* If we were hit with a reset drop the link */
480 if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
481 mac->get_link_status = true;
483 if (!mac->get_link_status)
486 /* if link status is down no point in checking to see if pf is up */
487 links_reg = rd32(hw, TXGBE_VFSTATUS);
488 if (!(links_reg & TXGBE_VFSTATUS_UP))
491 /* for SFP+ modules and DA cables it can take up to 500usecs
492 * before the link status is correct
494 if (mac->type == txgbe_mac_raptor_vf && wait_to_complete) {
495 if (po32m(hw, TXGBE_VFSTATUS, TXGBE_VFSTATUS_UP,
500 switch (links_reg & TXGBE_VFSTATUS_BW_MASK) {
501 case TXGBE_VFSTATUS_BW_10G:
502 *speed = TXGBE_LINK_SPEED_10GB_FULL;
504 case TXGBE_VFSTATUS_BW_1G:
505 *speed = TXGBE_LINK_SPEED_1GB_FULL;
507 case TXGBE_VFSTATUS_BW_100M:
508 *speed = TXGBE_LINK_SPEED_100M_FULL;
511 *speed = TXGBE_LINK_SPEED_UNKNOWN;
514 if (no_pflink_check) {
515 if (*speed == TXGBE_LINK_SPEED_UNKNOWN)
516 mac->get_link_status = true;
518 mac->get_link_status = false;
523 /* if the read failed it could just be a mailbox collision, best wait
524 * until we are called again and don't report an error
526 if (mbx->read(hw, &in_msg, 1, 0))
529 if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
530 /* msg is not CTS and is NACK we must have lost CTS status */
531 if (in_msg & TXGBE_VT_MSGTYPE_NACK)
536 /* the pf is talking, if we timed out in the past we reinit */
542 /* if we passed all the tests above then the link is up and we no
543 * longer need to check for link
545 mac->get_link_status = false;
548 *link_up = !mac->get_link_status;
553 * txgbevf_rlpml_set_vf - Set the maximum receive packet length
554 * @hw: pointer to the HW structure
555 * @max_size: value to assign to max frame size
557 s32 txgbevf_rlpml_set_vf(struct txgbe_hw *hw, u16 max_size)
562 msgbuf[0] = TXGBE_VF_SET_LPE;
563 msgbuf[1] = max_size;
565 retval = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
568 if ((msgbuf[0] & TXGBE_VF_SET_LPE) &&
569 (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK))
570 return TXGBE_ERR_MBX;
576 * txgbevf_negotiate_api_version - Negotiate supported API version
577 * @hw: pointer to the HW structure
578 * @api: integer containing requested API version
580 int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
585 /* Negotiate the mailbox API version */
586 msg[0] = TXGBE_VF_API_NEGOTIATE;
590 err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
592 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
594 /* Store value and return 0 on success */
595 if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
596 hw->api_version = api;
600 err = TXGBE_ERR_INVALID_ARGUMENT;
606 int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
607 unsigned int *default_tc)
612 /* do nothing if API doesn't support txgbevf_get_queues */
613 switch (hw->api_version) {
614 case txgbe_mbox_api_11:
615 case txgbe_mbox_api_12:
616 case txgbe_mbox_api_13:
622 /* Fetch queue configuration from the PF */
623 msg[0] = TXGBE_VF_GET_QUEUES;
624 for (i = 1; i < 5; i++)
627 err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
629 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
632 * if we didn't get an ACK there must have been
633 * some sort of mailbox error so we should treat it
636 if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
637 return TXGBE_ERR_MBX;
639 /* record and validate values from message */
640 hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
641 if (hw->mac.max_tx_queues == 0 ||
642 hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
643 hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
645 hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
646 if (hw->mac.max_rx_queues == 0 ||
647 hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
648 hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
650 *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
651 /* in case of unknown state assume we cannot tag frames */
652 if (*num_tcs > hw->mac.max_rx_queues)
655 *default_tc = msg[TXGBE_VF_DEF_QUEUE];
656 /* default to queue 0 on out-of-bounds queue number */
657 if (*default_tc >= hw->mac.max_tx_queues)