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_rlpml = txgbevf_rlpml_set_vf;
38 mac->max_tx_queues = 1;
39 mac->max_rx_queues = 1;
41 mbx->init_params = txgbe_init_mbx_params_vf;
42 mbx->read = txgbe_read_mbx_vf;
43 mbx->write = txgbe_write_mbx_vf;
44 mbx->read_posted = txgbe_read_posted_mbx;
45 mbx->write_posted = txgbe_write_posted_mbx;
46 mbx->check_for_msg = txgbe_check_for_msg_vf;
47 mbx->check_for_ack = txgbe_check_for_ack_vf;
48 mbx->check_for_rst = txgbe_check_for_rst_vf;
53 /* txgbe_virt_clr_reg - Set register to default (power on) state.
54 * @hw: pointer to hardware structure
56 static void txgbe_virt_clr_reg(struct txgbe_hw *hw)
61 /* default values (BUF_SIZE = 2048, HDR_SIZE = 256) */
62 vfsrrctl = TXGBE_RXCFG_HDRLEN(TXGBE_RX_HDR_SIZE);
63 vfsrrctl |= TXGBE_RXCFG_PKTLEN(TXGBE_RX_BUF_SIZE);
65 for (i = 0; i < 8; i++) {
66 wr32m(hw, TXGBE_RXCFG(i),
67 (TXGBE_RXCFG_HDRLEN_MASK | TXGBE_RXCFG_PKTLEN_MASK),
75 * txgbe_start_hw_vf - Prepare hardware for Tx/Rx
76 * @hw: pointer to hardware structure
78 * Starts the hardware by filling the bus info structure and media type, clears
79 * all on chip counters, initializes receive address registers, multicast
80 * table, VLAN filter table, calls routine to set up link and flow control
81 * settings, and leaves transmit and receive units disabled and uninitialized
83 s32 txgbe_start_hw_vf(struct txgbe_hw *hw)
85 /* Clear adapter stopped flag */
86 hw->adapter_stopped = false;
92 * txgbe_reset_hw_vf - Performs hardware reset
93 * @hw: pointer to hardware structure
95 * Resets the hardware by resetting the transmit and receive units, masks and
96 * clears all interrupts.
98 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw)
100 struct txgbe_mbx_info *mbx = &hw->mbx;
101 u32 timeout = TXGBE_VF_INIT_TIMEOUT;
102 s32 ret_val = TXGBE_ERR_INVALID_MAC_ADDR;
103 u32 msgbuf[TXGBE_VF_PERMADDR_MSG_LEN];
104 u8 *addr = (u8 *)(&msgbuf[1]);
106 DEBUGFUNC("txgbevf_reset_hw_vf");
108 /* Call adapter stop to disable tx/rx and clear interrupts */
111 /* reset the api version */
112 hw->api_version = txgbe_mbox_api_10;
114 /* backup msix vectors */
115 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
116 msgbuf[0] = TXGBE_VF_BACKUP;
117 mbx->write_posted(hw, msgbuf, 1, 0);
120 DEBUGOUT("Issuing a function level reset to MAC\n");
121 wr32(hw, TXGBE_VFRST, TXGBE_VFRST_SET);
125 hw->offset_loaded = 1;
127 /* we cannot reset while the RSTI / RSTD bits are asserted */
128 while (!mbx->check_for_rst(hw, 0) && timeout) {
130 /* if it doesn't work, try in 1 ms */
135 return TXGBE_ERR_RESET_FAILED;
137 /* Reset VF registers to initial values */
138 txgbe_virt_clr_reg(hw);
140 /* mailbox timeout can now become active */
141 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
143 msgbuf[0] = TXGBE_VF_RESET;
144 mbx->write_posted(hw, msgbuf, 1, 0);
149 * set our "perm_addr" based on info provided by PF
150 * also set up the mc_filter_type which is piggy backed
151 * on the mac address in word 3
153 ret_val = mbx->read_posted(hw, msgbuf,
154 TXGBE_VF_PERMADDR_MSG_LEN, 0);
158 if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
159 msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
160 return TXGBE_ERR_INVALID_MAC_ADDR;
162 if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
163 memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
165 hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
171 * txgbe_stop_hw_vf - Generic stop Tx/Rx units
172 * @hw: pointer to hardware structure
174 * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
175 * disables transmit and receive units. The adapter_stopped flag is used by
176 * the shared code and drivers to determine if the adapter is in a stopped
177 * state and should not touch the hardware.
179 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
184 * Set the adapter_stopped flag so other driver functions stop touching
187 hw->adapter_stopped = true;
189 /* Clear interrupt mask to stop from interrupts being generated */
190 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
192 /* Clear any pending interrupts, flush previous writes */
193 wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
195 /* Disable the transmit unit. Each queue must be disabled. */
196 for (i = 0; i < hw->mac.max_tx_queues; i++)
197 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
199 /* Disable the receive unit by stopping each queue */
200 for (i = 0; i < hw->mac.max_rx_queues; i++)
201 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
203 /* Clear packet split and pool config */
204 wr32(hw, TXGBE_VFPLCFG, 0);
207 /* flush all queues disables */
214 STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
215 u32 *retmsg, u16 size)
217 struct txgbe_mbx_info *mbx = &hw->mbx;
218 s32 retval = mbx->write_posted(hw, msg, size, 0);
223 return mbx->read_posted(hw, retmsg, size, 0);
227 * txgbe_set_rar_vf - set device MAC address
228 * @hw: pointer to hardware structure
229 * @index: Receive address register to write
230 * @addr: Address to put into receive address register
231 * @vmdq: VMDq "set" or "pool" index
232 * @enable_addr: set flag that address is active
234 s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
238 u8 *msg_addr = (u8 *)(&msgbuf[1]);
240 UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
242 memset(msgbuf, 0, 12);
243 msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
244 memcpy(msg_addr, addr, 6);
245 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
247 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
249 /* if nacked the address was rejected, use "perm_addr" */
251 (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
252 txgbe_get_mac_addr_vf(hw, hw->mac.addr);
253 return TXGBE_ERR_MBX;
260 * txgbe_get_mac_addr_vf - Read device MAC address
261 * @hw: pointer to the HW structure
262 * @mac_addr: the MAC address
264 s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
268 for (i = 0; i < ETH_ADDR_LEN; i++)
269 mac_addr[i] = hw->mac.perm_addr[i];
274 s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
276 u32 msgbuf[3], msgbuf_chk;
277 u8 *msg_addr = (u8 *)(&msgbuf[1]);
280 memset(msgbuf, 0, sizeof(msgbuf));
282 * If index is one then this is the start of a new list and needs
283 * indication to the PF so it can do it's own list management.
284 * If it is zero then that tells the PF to just clear all of
285 * this VF's macvlans and there is no new list.
287 msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
288 msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
289 msgbuf_chk = msgbuf[0];
291 memcpy(msg_addr, addr, 6);
293 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
295 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
297 if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
298 return TXGBE_ERR_OUT_OF_MEM;
305 * txgbe_check_mac_link_vf - Get link/speed status
306 * @hw: pointer to hardware structure
307 * @speed: pointer to link speed
308 * @link_up: true is link is up, false otherwise
309 * @autoneg_wait_to_complete: true when waiting for completion is needed
311 * Reads the links register to determine if link is up and the current speed
313 s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
314 bool *link_up, bool wait_to_complete)
317 * for a quick link status checking, wait_to_compelet == 0,
318 * skip PF link status checking
320 bool no_pflink_check = wait_to_complete == 0;
321 struct txgbe_mbx_info *mbx = &hw->mbx;
322 struct txgbe_mac_info *mac = &hw->mac;
327 /* If we were hit with a reset drop the link */
328 if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
329 mac->get_link_status = true;
331 if (!mac->get_link_status)
334 /* if link status is down no point in checking to see if pf is up */
335 links_reg = rd32(hw, TXGBE_VFSTATUS);
336 if (!(links_reg & TXGBE_VFSTATUS_UP))
339 /* for SFP+ modules and DA cables it can take up to 500usecs
340 * before the link status is correct
342 if (mac->type == txgbe_mac_raptor_vf && wait_to_complete) {
343 if (po32m(hw, TXGBE_VFSTATUS, TXGBE_VFSTATUS_UP,
348 switch (links_reg & TXGBE_VFSTATUS_BW_MASK) {
349 case TXGBE_VFSTATUS_BW_10G:
350 *speed = TXGBE_LINK_SPEED_10GB_FULL;
352 case TXGBE_VFSTATUS_BW_1G:
353 *speed = TXGBE_LINK_SPEED_1GB_FULL;
355 case TXGBE_VFSTATUS_BW_100M:
356 *speed = TXGBE_LINK_SPEED_100M_FULL;
359 *speed = TXGBE_LINK_SPEED_UNKNOWN;
362 if (no_pflink_check) {
363 if (*speed == TXGBE_LINK_SPEED_UNKNOWN)
364 mac->get_link_status = true;
366 mac->get_link_status = false;
371 /* if the read failed it could just be a mailbox collision, best wait
372 * until we are called again and don't report an error
374 if (mbx->read(hw, &in_msg, 1, 0))
377 if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
378 /* msg is not CTS and is NACK we must have lost CTS status */
379 if (in_msg & TXGBE_VT_MSGTYPE_NACK)
384 /* the pf is talking, if we timed out in the past we reinit */
390 /* if we passed all the tests above then the link is up and we no
391 * longer need to check for link
393 mac->get_link_status = false;
396 *link_up = !mac->get_link_status;
401 * txgbevf_rlpml_set_vf - Set the maximum receive packet length
402 * @hw: pointer to the HW structure
403 * @max_size: value to assign to max frame size
405 s32 txgbevf_rlpml_set_vf(struct txgbe_hw *hw, u16 max_size)
410 msgbuf[0] = TXGBE_VF_SET_LPE;
411 msgbuf[1] = max_size;
413 retval = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
416 if ((msgbuf[0] & TXGBE_VF_SET_LPE) &&
417 (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK))
418 return TXGBE_ERR_MBX;
424 * txgbevf_negotiate_api_version - Negotiate supported API version
425 * @hw: pointer to the HW structure
426 * @api: integer containing requested API version
428 int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
433 /* Negotiate the mailbox API version */
434 msg[0] = TXGBE_VF_API_NEGOTIATE;
438 err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
440 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
442 /* Store value and return 0 on success */
443 if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
444 hw->api_version = api;
448 err = TXGBE_ERR_INVALID_ARGUMENT;
454 int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
455 unsigned int *default_tc)
460 /* do nothing if API doesn't support txgbevf_get_queues */
461 switch (hw->api_version) {
462 case txgbe_mbox_api_11:
463 case txgbe_mbox_api_12:
464 case txgbe_mbox_api_13:
470 /* Fetch queue configuration from the PF */
471 msg[0] = TXGBE_VF_GET_QUEUES;
472 for (i = 1; i < 5; i++)
475 err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
477 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
480 * if we didn't get an ACK there must have been
481 * some sort of mailbox error so we should treat it
484 if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
485 return TXGBE_ERR_MBX;
487 /* record and validate values from message */
488 hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
489 if (hw->mac.max_tx_queues == 0 ||
490 hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
491 hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
493 hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
494 if (hw->mac.max_rx_queues == 0 ||
495 hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
496 hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
498 *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
499 /* in case of unknown state assume we cannot tag frames */
500 if (*num_tcs > hw->mac.max_rx_queues)
503 *default_tc = msg[TXGBE_VF_DEF_QUEUE];
504 /* default to queue 0 on out-of-bounds queue number */
505 if (*default_tc >= hw->mac.max_tx_queues)