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;
29 mac->update_mc_addr_list = txgbe_update_mc_addr_list_vf;
32 mac->check_link = txgbe_check_mac_link_vf;
34 /* RAR, Multicast, VLAN */
35 mac->set_rar = txgbe_set_rar_vf;
36 mac->set_uc_addr = txgbevf_set_uc_addr_vf;
37 mac->update_xcast_mode = txgbevf_update_xcast_mode;
38 mac->set_vfta = txgbe_set_vfta_vf;
39 mac->set_rlpml = txgbevf_rlpml_set_vf;
41 mac->max_tx_queues = 1;
42 mac->max_rx_queues = 1;
44 mbx->init_params = txgbe_init_mbx_params_vf;
45 mbx->read = txgbe_read_mbx_vf;
46 mbx->write = txgbe_write_mbx_vf;
47 mbx->read_posted = txgbe_read_posted_mbx;
48 mbx->write_posted = txgbe_write_posted_mbx;
49 mbx->check_for_msg = txgbe_check_for_msg_vf;
50 mbx->check_for_ack = txgbe_check_for_ack_vf;
51 mbx->check_for_rst = txgbe_check_for_rst_vf;
56 /* txgbe_virt_clr_reg - Set register to default (power on) state.
57 * @hw: pointer to hardware structure
59 static void txgbe_virt_clr_reg(struct txgbe_hw *hw)
64 /* default values (BUF_SIZE = 2048, HDR_SIZE = 256) */
65 vfsrrctl = TXGBE_RXCFG_HDRLEN(TXGBE_RX_HDR_SIZE);
66 vfsrrctl |= TXGBE_RXCFG_PKTLEN(TXGBE_RX_BUF_SIZE);
68 for (i = 0; i < 8; i++) {
69 wr32m(hw, TXGBE_RXCFG(i),
70 (TXGBE_RXCFG_HDRLEN_MASK | TXGBE_RXCFG_PKTLEN_MASK),
78 * txgbe_start_hw_vf - Prepare hardware for Tx/Rx
79 * @hw: pointer to hardware structure
81 * Starts the hardware by filling the bus info structure and media type, clears
82 * all on chip counters, initializes receive address registers, multicast
83 * table, VLAN filter table, calls routine to set up link and flow control
84 * settings, and leaves transmit and receive units disabled and uninitialized
86 s32 txgbe_start_hw_vf(struct txgbe_hw *hw)
88 /* Clear adapter stopped flag */
89 hw->adapter_stopped = false;
95 * txgbe_reset_hw_vf - Performs hardware reset
96 * @hw: pointer to hardware structure
98 * Resets the hardware by resetting the transmit and receive units, masks and
99 * clears all interrupts.
101 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw)
103 struct txgbe_mbx_info *mbx = &hw->mbx;
104 u32 timeout = TXGBE_VF_INIT_TIMEOUT;
105 s32 ret_val = TXGBE_ERR_INVALID_MAC_ADDR;
106 u32 msgbuf[TXGBE_VF_PERMADDR_MSG_LEN];
107 u8 *addr = (u8 *)(&msgbuf[1]);
109 DEBUGFUNC("txgbevf_reset_hw_vf");
111 /* Call adapter stop to disable tx/rx and clear interrupts */
114 /* reset the api version */
115 hw->api_version = txgbe_mbox_api_10;
117 /* backup msix vectors */
118 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
119 msgbuf[0] = TXGBE_VF_BACKUP;
120 mbx->write_posted(hw, msgbuf, 1, 0);
123 DEBUGOUT("Issuing a function level reset to MAC\n");
124 wr32(hw, TXGBE_VFRST, TXGBE_VFRST_SET);
128 hw->offset_loaded = 1;
130 /* we cannot reset while the RSTI / RSTD bits are asserted */
131 while (!mbx->check_for_rst(hw, 0) && timeout) {
133 /* if it doesn't work, try in 1 ms */
138 return TXGBE_ERR_RESET_FAILED;
140 /* Reset VF registers to initial values */
141 txgbe_virt_clr_reg(hw);
143 /* mailbox timeout can now become active */
144 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
146 msgbuf[0] = TXGBE_VF_RESET;
147 mbx->write_posted(hw, msgbuf, 1, 0);
152 * set our "perm_addr" based on info provided by PF
153 * also set up the mc_filter_type which is piggy backed
154 * on the mac address in word 3
156 ret_val = mbx->read_posted(hw, msgbuf,
157 TXGBE_VF_PERMADDR_MSG_LEN, 0);
161 if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
162 msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
163 return TXGBE_ERR_INVALID_MAC_ADDR;
165 if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
166 memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
168 hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
174 * txgbe_stop_hw_vf - Generic stop Tx/Rx units
175 * @hw: pointer to hardware structure
177 * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
178 * disables transmit and receive units. The adapter_stopped flag is used by
179 * the shared code and drivers to determine if the adapter is in a stopped
180 * state and should not touch the hardware.
182 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
187 * Set the adapter_stopped flag so other driver functions stop touching
190 hw->adapter_stopped = true;
192 /* Clear interrupt mask to stop from interrupts being generated */
193 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
195 /* Clear any pending interrupts, flush previous writes */
196 wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
198 /* Disable the transmit unit. Each queue must be disabled. */
199 for (i = 0; i < hw->mac.max_tx_queues; i++)
200 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
202 /* Disable the receive unit by stopping each queue */
203 for (i = 0; i < hw->mac.max_rx_queues; i++)
204 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
206 /* Clear packet split and pool config */
207 wr32(hw, TXGBE_VFPLCFG, 0);
210 /* flush all queues disables */
218 * txgbe_mta_vector - Determines bit-vector in multicast table to set
219 * @hw: pointer to hardware structure
220 * @mc_addr: the multicast address
222 STATIC s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
226 switch (hw->mac.mc_filter_type) {
227 case 0: /* use bits [47:36] of the address */
228 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
230 case 1: /* use bits [46:35] of the address */
231 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
233 case 2: /* use bits [45:34] of the address */
234 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
236 case 3: /* use bits [43:32] of the address */
237 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
239 default: /* Invalid mc_filter_type */
240 DEBUGOUT("MC filter type param set incorrectly\n");
245 /* vector can only be 12-bits or boundary will be exceeded */
250 STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
251 u32 *retmsg, u16 size)
253 struct txgbe_mbx_info *mbx = &hw->mbx;
254 s32 retval = mbx->write_posted(hw, msg, size, 0);
259 return mbx->read_posted(hw, retmsg, size, 0);
263 * txgbe_set_rar_vf - set device MAC address
264 * @hw: pointer to hardware structure
265 * @index: Receive address register to write
266 * @addr: Address to put into receive address register
267 * @vmdq: VMDq "set" or "pool" index
268 * @enable_addr: set flag that address is active
270 s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
274 u8 *msg_addr = (u8 *)(&msgbuf[1]);
276 UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
278 memset(msgbuf, 0, 12);
279 msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
280 memcpy(msg_addr, addr, 6);
281 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
283 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
285 /* if nacked the address was rejected, use "perm_addr" */
287 (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
288 txgbe_get_mac_addr_vf(hw, hw->mac.addr);
289 return TXGBE_ERR_MBX;
296 * txgbe_update_mc_addr_list_vf - Update Multicast addresses
297 * @hw: pointer to the HW structure
298 * @mc_addr_list: array of multicast addresses to program
299 * @mc_addr_count: number of multicast addresses to program
300 * @next: caller supplied function to return next address in list
303 * Updates the Multicast Table Array.
305 s32 txgbe_update_mc_addr_list_vf(struct txgbe_hw *hw, u8 *mc_addr_list,
306 u32 mc_addr_count, txgbe_mc_addr_itr next,
309 struct txgbe_mbx_info *mbx = &hw->mbx;
310 u32 msgbuf[TXGBE_P2VMBX_SIZE];
311 u16 *vector_list = (u16 *)&msgbuf[1];
316 UNREFERENCED_PARAMETER(clear);
318 DEBUGFUNC("txgbe_update_mc_addr_list_vf");
320 /* Each entry in the list uses 1 16 bit word. We have 30
321 * 16 bit words available in our HW msg buffer (minus 1 for the
322 * msg type). That's 30 hash values if we pack 'em right. If
323 * there are more than 30 MC addresses to add then punt the
324 * extras for now and then add code to handle more than 30 later.
325 * It would be unusual for a server to request that many multi-cast
326 * addresses except for in large enterprise network environments.
329 DEBUGOUT("MC Addr Count = %d\n", mc_addr_count);
331 cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
332 msgbuf[0] = TXGBE_VF_SET_MULTICAST;
333 msgbuf[0] |= cnt << TXGBE_VT_MSGINFO_SHIFT;
335 for (i = 0; i < cnt; i++) {
336 vector = txgbe_mta_vector(hw, next(hw, &mc_addr_list, &vmdq));
337 DEBUGOUT("Hash value = 0x%03X\n", vector);
338 vector_list[i] = (u16)vector;
341 return mbx->write_posted(hw, msgbuf, TXGBE_P2VMBX_SIZE, 0);
345 * txgbevf_update_xcast_mode - Update Multicast mode
346 * @hw: pointer to the HW structure
347 * @xcast_mode: new multicast mode
349 * Updates the Multicast Mode of VF.
351 s32 txgbevf_update_xcast_mode(struct txgbe_hw *hw, int xcast_mode)
356 switch (hw->api_version) {
357 case txgbe_mbox_api_12:
358 /* New modes were introduced in 1.3 version */
359 if (xcast_mode > TXGBEVF_XCAST_MODE_ALLMULTI)
360 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
362 case txgbe_mbox_api_13:
365 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
368 msgbuf[0] = TXGBE_VF_UPDATE_XCAST_MODE;
369 msgbuf[1] = xcast_mode;
371 err = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
375 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
376 if (msgbuf[0] == (TXGBE_VF_UPDATE_XCAST_MODE | TXGBE_VT_MSGTYPE_NACK))
377 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
382 * txgbe_set_vfta_vf - Set/Unset vlan filter table address
383 * @hw: pointer to the HW structure
384 * @vlan: 12 bit VLAN ID
385 * @vind: unused by VF drivers
386 * @vlan_on: if true then set bit, else clear bit
387 * @vlvf_bypass: boolean flag indicating updating default pool is okay
389 * Turn on/off specified VLAN in the VLAN filter table.
391 s32 txgbe_set_vfta_vf(struct txgbe_hw *hw, u32 vlan, u32 vind,
392 bool vlan_on, bool vlvf_bypass)
396 UNREFERENCED_PARAMETER(vind, vlvf_bypass);
398 msgbuf[0] = TXGBE_VF_SET_VLAN;
400 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
401 msgbuf[0] |= vlan_on << TXGBE_VT_MSGINFO_SHIFT;
403 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
404 if (!ret_val && (msgbuf[0] & TXGBE_VT_MSGTYPE_ACK))
407 return ret_val | (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK);
411 * txgbe_get_mac_addr_vf - Read device MAC address
412 * @hw: pointer to the HW structure
413 * @mac_addr: the MAC address
415 s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
419 for (i = 0; i < ETH_ADDR_LEN; i++)
420 mac_addr[i] = hw->mac.perm_addr[i];
425 s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
427 u32 msgbuf[3], msgbuf_chk;
428 u8 *msg_addr = (u8 *)(&msgbuf[1]);
431 memset(msgbuf, 0, sizeof(msgbuf));
433 * If index is one then this is the start of a new list and needs
434 * indication to the PF so it can do it's own list management.
435 * If it is zero then that tells the PF to just clear all of
436 * this VF's macvlans and there is no new list.
438 msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
439 msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
440 msgbuf_chk = msgbuf[0];
442 memcpy(msg_addr, addr, 6);
444 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
446 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
448 if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
449 return TXGBE_ERR_OUT_OF_MEM;
456 * txgbe_check_mac_link_vf - Get link/speed status
457 * @hw: pointer to hardware structure
458 * @speed: pointer to link speed
459 * @link_up: true is link is up, false otherwise
460 * @autoneg_wait_to_complete: true when waiting for completion is needed
462 * Reads the links register to determine if link is up and the current speed
464 s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
465 bool *link_up, bool wait_to_complete)
468 * for a quick link status checking, wait_to_compelet == 0,
469 * skip PF link status checking
471 bool no_pflink_check = wait_to_complete == 0;
472 struct txgbe_mbx_info *mbx = &hw->mbx;
473 struct txgbe_mac_info *mac = &hw->mac;
478 /* If we were hit with a reset drop the link */
479 if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
480 mac->get_link_status = true;
482 if (!mac->get_link_status)
485 /* if link status is down no point in checking to see if pf is up */
486 links_reg = rd32(hw, TXGBE_VFSTATUS);
487 if (!(links_reg & TXGBE_VFSTATUS_UP))
490 /* for SFP+ modules and DA cables it can take up to 500usecs
491 * before the link status is correct
493 if (mac->type == txgbe_mac_raptor_vf && wait_to_complete) {
494 if (po32m(hw, TXGBE_VFSTATUS, TXGBE_VFSTATUS_UP,
499 switch (links_reg & TXGBE_VFSTATUS_BW_MASK) {
500 case TXGBE_VFSTATUS_BW_10G:
501 *speed = TXGBE_LINK_SPEED_10GB_FULL;
503 case TXGBE_VFSTATUS_BW_1G:
504 *speed = TXGBE_LINK_SPEED_1GB_FULL;
506 case TXGBE_VFSTATUS_BW_100M:
507 *speed = TXGBE_LINK_SPEED_100M_FULL;
510 *speed = TXGBE_LINK_SPEED_UNKNOWN;
513 if (no_pflink_check) {
514 if (*speed == TXGBE_LINK_SPEED_UNKNOWN)
515 mac->get_link_status = true;
517 mac->get_link_status = false;
522 /* if the read failed it could just be a mailbox collision, best wait
523 * until we are called again and don't report an error
525 if (mbx->read(hw, &in_msg, 1, 0))
528 if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
529 /* msg is not CTS and is NACK we must have lost CTS status */
530 if (in_msg & TXGBE_VT_MSGTYPE_NACK)
535 /* the pf is talking, if we timed out in the past we reinit */
541 /* if we passed all the tests above then the link is up and we no
542 * longer need to check for link
544 mac->get_link_status = false;
547 *link_up = !mac->get_link_status;
552 * txgbevf_rlpml_set_vf - Set the maximum receive packet length
553 * @hw: pointer to the HW structure
554 * @max_size: value to assign to max frame size
556 s32 txgbevf_rlpml_set_vf(struct txgbe_hw *hw, u16 max_size)
561 msgbuf[0] = TXGBE_VF_SET_LPE;
562 msgbuf[1] = max_size;
564 retval = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
567 if ((msgbuf[0] & TXGBE_VF_SET_LPE) &&
568 (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK))
569 return TXGBE_ERR_MBX;
575 * txgbevf_negotiate_api_version - Negotiate supported API version
576 * @hw: pointer to the HW structure
577 * @api: integer containing requested API version
579 int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
584 /* Negotiate the mailbox API version */
585 msg[0] = TXGBE_VF_API_NEGOTIATE;
589 err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
591 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
593 /* Store value and return 0 on success */
594 if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
595 hw->api_version = api;
599 err = TXGBE_ERR_INVALID_ARGUMENT;
605 int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
606 unsigned int *default_tc)
611 /* do nothing if API doesn't support txgbevf_get_queues */
612 switch (hw->api_version) {
613 case txgbe_mbox_api_11:
614 case txgbe_mbox_api_12:
615 case txgbe_mbox_api_13:
621 /* Fetch queue configuration from the PF */
622 msg[0] = TXGBE_VF_GET_QUEUES;
623 for (i = 1; i < 5; i++)
626 err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
628 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
631 * if we didn't get an ACK there must have been
632 * some sort of mailbox error so we should treat it
635 if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
636 return TXGBE_ERR_MBX;
638 /* record and validate values from message */
639 hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
640 if (hw->mac.max_tx_queues == 0 ||
641 hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
642 hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
644 hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
645 if (hw->mac.max_rx_queues == 0 ||
646 hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
647 hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
649 *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
650 /* in case of unknown state assume we cannot tag frames */
651 if (*num_tcs > hw->mac.max_rx_queues)
654 *default_tc = msg[TXGBE_VF_DEF_QUEUE];
655 /* default to queue 0 on out-of-bounds queue number */
656 if (*default_tc >= hw->mac.max_tx_queues)