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;
37 mac->max_tx_queues = 1;
38 mac->max_rx_queues = 1;
40 mbx->init_params = txgbe_init_mbx_params_vf;
41 mbx->read = txgbe_read_mbx_vf;
42 mbx->write = txgbe_write_mbx_vf;
43 mbx->read_posted = txgbe_read_posted_mbx;
44 mbx->write_posted = txgbe_write_posted_mbx;
45 mbx->check_for_msg = txgbe_check_for_msg_vf;
46 mbx->check_for_ack = txgbe_check_for_ack_vf;
47 mbx->check_for_rst = txgbe_check_for_rst_vf;
52 /* txgbe_virt_clr_reg - Set register to default (power on) state.
53 * @hw: pointer to hardware structure
55 static void txgbe_virt_clr_reg(struct txgbe_hw *hw)
60 /* default values (BUF_SIZE = 2048, HDR_SIZE = 256) */
61 vfsrrctl = TXGBE_RXCFG_HDRLEN(TXGBE_RX_HDR_SIZE);
62 vfsrrctl |= TXGBE_RXCFG_PKTLEN(TXGBE_RX_BUF_SIZE);
64 for (i = 0; i < 8; i++) {
65 wr32m(hw, TXGBE_RXCFG(i),
66 (TXGBE_RXCFG_HDRLEN_MASK | TXGBE_RXCFG_PKTLEN_MASK),
74 * txgbe_start_hw_vf - Prepare hardware for Tx/Rx
75 * @hw: pointer to hardware structure
77 * Starts the hardware by filling the bus info structure and media type, clears
78 * all on chip counters, initializes receive address registers, multicast
79 * table, VLAN filter table, calls routine to set up link and flow control
80 * settings, and leaves transmit and receive units disabled and uninitialized
82 s32 txgbe_start_hw_vf(struct txgbe_hw *hw)
84 /* Clear adapter stopped flag */
85 hw->adapter_stopped = false;
91 * txgbe_reset_hw_vf - Performs hardware reset
92 * @hw: pointer to hardware structure
94 * Resets the hardware by resetting the transmit and receive units, masks and
95 * clears all interrupts.
97 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw)
99 struct txgbe_mbx_info *mbx = &hw->mbx;
100 u32 timeout = TXGBE_VF_INIT_TIMEOUT;
101 s32 ret_val = TXGBE_ERR_INVALID_MAC_ADDR;
102 u32 msgbuf[TXGBE_VF_PERMADDR_MSG_LEN];
103 u8 *addr = (u8 *)(&msgbuf[1]);
105 DEBUGFUNC("txgbevf_reset_hw_vf");
107 /* Call adapter stop to disable tx/rx and clear interrupts */
110 /* reset the api version */
111 hw->api_version = txgbe_mbox_api_10;
113 /* backup msix vectors */
114 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
115 msgbuf[0] = TXGBE_VF_BACKUP;
116 mbx->write_posted(hw, msgbuf, 1, 0);
119 DEBUGOUT("Issuing a function level reset to MAC\n");
120 wr32(hw, TXGBE_VFRST, TXGBE_VFRST_SET);
124 hw->offset_loaded = 1;
126 /* we cannot reset while the RSTI / RSTD bits are asserted */
127 while (!mbx->check_for_rst(hw, 0) && timeout) {
129 /* if it doesn't work, try in 1 ms */
134 return TXGBE_ERR_RESET_FAILED;
136 /* Reset VF registers to initial values */
137 txgbe_virt_clr_reg(hw);
139 /* mailbox timeout can now become active */
140 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
142 msgbuf[0] = TXGBE_VF_RESET;
143 mbx->write_posted(hw, msgbuf, 1, 0);
148 * set our "perm_addr" based on info provided by PF
149 * also set up the mc_filter_type which is piggy backed
150 * on the mac address in word 3
152 ret_val = mbx->read_posted(hw, msgbuf,
153 TXGBE_VF_PERMADDR_MSG_LEN, 0);
157 if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
158 msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
159 return TXGBE_ERR_INVALID_MAC_ADDR;
161 if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
162 memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
164 hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
170 * txgbe_stop_hw_vf - Generic stop Tx/Rx units
171 * @hw: pointer to hardware structure
173 * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
174 * disables transmit and receive units. The adapter_stopped flag is used by
175 * the shared code and drivers to determine if the adapter is in a stopped
176 * state and should not touch the hardware.
178 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
183 * Set the adapter_stopped flag so other driver functions stop touching
186 hw->adapter_stopped = true;
188 /* Clear interrupt mask to stop from interrupts being generated */
189 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
191 /* Clear any pending interrupts, flush previous writes */
192 wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
194 /* Disable the transmit unit. Each queue must be disabled. */
195 for (i = 0; i < hw->mac.max_tx_queues; i++)
196 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
198 /* Disable the receive unit by stopping each queue */
199 for (i = 0; i < hw->mac.max_rx_queues; i++)
200 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
202 /* Clear packet split and pool config */
203 wr32(hw, TXGBE_VFPLCFG, 0);
206 /* flush all queues disables */
213 STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
214 u32 *retmsg, u16 size)
216 struct txgbe_mbx_info *mbx = &hw->mbx;
217 s32 retval = mbx->write_posted(hw, msg, size, 0);
222 return mbx->read_posted(hw, retmsg, size, 0);
226 * txgbe_set_rar_vf - set device MAC address
227 * @hw: pointer to hardware structure
228 * @index: Receive address register to write
229 * @addr: Address to put into receive address register
230 * @vmdq: VMDq "set" or "pool" index
231 * @enable_addr: set flag that address is active
233 s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
237 u8 *msg_addr = (u8 *)(&msgbuf[1]);
239 UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
241 memset(msgbuf, 0, 12);
242 msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
243 memcpy(msg_addr, addr, 6);
244 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
246 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
248 /* if nacked the address was rejected, use "perm_addr" */
250 (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
251 txgbe_get_mac_addr_vf(hw, hw->mac.addr);
252 return TXGBE_ERR_MBX;
259 * txgbe_get_mac_addr_vf - Read device MAC address
260 * @hw: pointer to the HW structure
261 * @mac_addr: the MAC address
263 s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
267 for (i = 0; i < ETH_ADDR_LEN; i++)
268 mac_addr[i] = hw->mac.perm_addr[i];
273 s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
275 u32 msgbuf[3], msgbuf_chk;
276 u8 *msg_addr = (u8 *)(&msgbuf[1]);
279 memset(msgbuf, 0, sizeof(msgbuf));
281 * If index is one then this is the start of a new list and needs
282 * indication to the PF so it can do it's own list management.
283 * If it is zero then that tells the PF to just clear all of
284 * this VF's macvlans and there is no new list.
286 msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
287 msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
288 msgbuf_chk = msgbuf[0];
290 memcpy(msg_addr, addr, 6);
292 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
294 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
296 if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
297 return TXGBE_ERR_OUT_OF_MEM;
304 * txgbe_check_mac_link_vf - Get link/speed status
305 * @hw: pointer to hardware structure
306 * @speed: pointer to link speed
307 * @link_up: true is link is up, false otherwise
308 * @autoneg_wait_to_complete: true when waiting for completion is needed
310 * Reads the links register to determine if link is up and the current speed
312 s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
313 bool *link_up, bool wait_to_complete)
316 * for a quick link status checking, wait_to_compelet == 0,
317 * skip PF link status checking
319 bool no_pflink_check = wait_to_complete == 0;
320 struct txgbe_mbx_info *mbx = &hw->mbx;
321 struct txgbe_mac_info *mac = &hw->mac;
326 /* If we were hit with a reset drop the link */
327 if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
328 mac->get_link_status = true;
330 if (!mac->get_link_status)
333 /* if link status is down no point in checking to see if pf is up */
334 links_reg = rd32(hw, TXGBE_VFSTATUS);
335 if (!(links_reg & TXGBE_VFSTATUS_UP))
338 /* for SFP+ modules and DA cables it can take up to 500usecs
339 * before the link status is correct
341 if (mac->type == txgbe_mac_raptor_vf && wait_to_complete) {
342 if (po32m(hw, TXGBE_VFSTATUS, TXGBE_VFSTATUS_UP,
347 switch (links_reg & TXGBE_VFSTATUS_BW_MASK) {
348 case TXGBE_VFSTATUS_BW_10G:
349 *speed = TXGBE_LINK_SPEED_10GB_FULL;
351 case TXGBE_VFSTATUS_BW_1G:
352 *speed = TXGBE_LINK_SPEED_1GB_FULL;
354 case TXGBE_VFSTATUS_BW_100M:
355 *speed = TXGBE_LINK_SPEED_100M_FULL;
358 *speed = TXGBE_LINK_SPEED_UNKNOWN;
361 if (no_pflink_check) {
362 if (*speed == TXGBE_LINK_SPEED_UNKNOWN)
363 mac->get_link_status = true;
365 mac->get_link_status = false;
370 /* if the read failed it could just be a mailbox collision, best wait
371 * until we are called again and don't report an error
373 if (mbx->read(hw, &in_msg, 1, 0))
376 if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
377 /* msg is not CTS and is NACK we must have lost CTS status */
378 if (in_msg & TXGBE_VT_MSGTYPE_NACK)
383 /* the pf is talking, if we timed out in the past we reinit */
389 /* if we passed all the tests above then the link is up and we no
390 * longer need to check for link
392 mac->get_link_status = false;
395 *link_up = !mac->get_link_status;
400 * txgbevf_negotiate_api_version - Negotiate supported API version
401 * @hw: pointer to the HW structure
402 * @api: integer containing requested API version
404 int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
409 /* Negotiate the mailbox API version */
410 msg[0] = TXGBE_VF_API_NEGOTIATE;
414 err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
416 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
418 /* Store value and return 0 on success */
419 if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
420 hw->api_version = api;
424 err = TXGBE_ERR_INVALID_ARGUMENT;
430 int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
431 unsigned int *default_tc)
436 /* do nothing if API doesn't support txgbevf_get_queues */
437 switch (hw->api_version) {
438 case txgbe_mbox_api_11:
439 case txgbe_mbox_api_12:
440 case txgbe_mbox_api_13:
446 /* Fetch queue configuration from the PF */
447 msg[0] = TXGBE_VF_GET_QUEUES;
448 for (i = 1; i < 5; i++)
451 err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
453 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
456 * if we didn't get an ACK there must have been
457 * some sort of mailbox error so we should treat it
460 if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
461 return TXGBE_ERR_MBX;
463 /* record and validate values from message */
464 hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
465 if (hw->mac.max_tx_queues == 0 ||
466 hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
467 hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
469 hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
470 if (hw->mac.max_rx_queues == 0 ||
471 hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
472 hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
474 *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
475 /* in case of unknown state assume we cannot tag frames */
476 if (*num_tcs > hw->mac.max_rx_queues)
479 *default_tc = msg[TXGBE_VF_DEF_QUEUE];
480 /* default to queue 0 on out-of-bounds queue number */
481 if (*default_tc >= hw->mac.max_tx_queues)