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->stop_hw = txgbe_stop_hw_vf;
25 mac->negotiate_api_version = txgbevf_negotiate_api_version;
27 mac->max_tx_queues = 1;
28 mac->max_rx_queues = 1;
30 mbx->init_params = txgbe_init_mbx_params_vf;
31 mbx->read = txgbe_read_mbx_vf;
32 mbx->write = txgbe_write_mbx_vf;
33 mbx->read_posted = txgbe_read_posted_mbx;
34 mbx->write_posted = txgbe_write_posted_mbx;
35 mbx->check_for_msg = txgbe_check_for_msg_vf;
36 mbx->check_for_ack = txgbe_check_for_ack_vf;
37 mbx->check_for_rst = txgbe_check_for_rst_vf;
42 /* txgbe_virt_clr_reg - Set register to default (power on) state.
43 * @hw: pointer to hardware structure
45 static void txgbe_virt_clr_reg(struct txgbe_hw *hw)
50 /* default values (BUF_SIZE = 2048, HDR_SIZE = 256) */
51 vfsrrctl = TXGBE_RXCFG_HDRLEN(TXGBE_RX_HDR_SIZE);
52 vfsrrctl |= TXGBE_RXCFG_PKTLEN(TXGBE_RX_BUF_SIZE);
54 for (i = 0; i < 8; i++) {
55 wr32m(hw, TXGBE_RXCFG(i),
56 (TXGBE_RXCFG_HDRLEN_MASK | TXGBE_RXCFG_PKTLEN_MASK),
64 * txgbe_reset_hw_vf - Performs hardware reset
65 * @hw: pointer to hardware structure
67 * Resets the hardware by resetting the transmit and receive units, masks and
68 * clears all interrupts.
70 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw)
72 struct txgbe_mbx_info *mbx = &hw->mbx;
73 u32 timeout = TXGBE_VF_INIT_TIMEOUT;
74 s32 ret_val = TXGBE_ERR_INVALID_MAC_ADDR;
75 u32 msgbuf[TXGBE_VF_PERMADDR_MSG_LEN];
76 u8 *addr = (u8 *)(&msgbuf[1]);
78 DEBUGFUNC("txgbevf_reset_hw_vf");
80 /* Call adapter stop to disable tx/rx and clear interrupts */
83 /* reset the api version */
84 hw->api_version = txgbe_mbox_api_10;
86 /* backup msix vectors */
87 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
88 msgbuf[0] = TXGBE_VF_BACKUP;
89 mbx->write_posted(hw, msgbuf, 1, 0);
92 DEBUGOUT("Issuing a function level reset to MAC\n");
93 wr32(hw, TXGBE_VFRST, TXGBE_VFRST_SET);
97 hw->offset_loaded = 1;
99 /* we cannot reset while the RSTI / RSTD bits are asserted */
100 while (!mbx->check_for_rst(hw, 0) && timeout) {
102 /* if it doesn't work, try in 1 ms */
107 return TXGBE_ERR_RESET_FAILED;
109 /* Reset VF registers to initial values */
110 txgbe_virt_clr_reg(hw);
112 /* mailbox timeout can now become active */
113 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
115 msgbuf[0] = TXGBE_VF_RESET;
116 mbx->write_posted(hw, msgbuf, 1, 0);
121 * set our "perm_addr" based on info provided by PF
122 * also set up the mc_filter_type which is piggy backed
123 * on the mac address in word 3
125 ret_val = mbx->read_posted(hw, msgbuf,
126 TXGBE_VF_PERMADDR_MSG_LEN, 0);
130 if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
131 msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
132 return TXGBE_ERR_INVALID_MAC_ADDR;
134 if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
135 memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
137 hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
143 * txgbe_stop_hw_vf - Generic stop Tx/Rx units
144 * @hw: pointer to hardware structure
146 * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
147 * disables transmit and receive units. The adapter_stopped flag is used by
148 * the shared code and drivers to determine if the adapter is in a stopped
149 * state and should not touch the hardware.
151 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
156 * Set the adapter_stopped flag so other driver functions stop touching
159 hw->adapter_stopped = true;
161 /* Clear interrupt mask to stop from interrupts being generated */
162 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
164 /* Clear any pending interrupts, flush previous writes */
165 wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
167 /* Disable the transmit unit. Each queue must be disabled. */
168 for (i = 0; i < hw->mac.max_tx_queues; i++)
169 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
171 /* Disable the receive unit by stopping each queue */
172 for (i = 0; i < hw->mac.max_rx_queues; i++)
173 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
175 /* Clear packet split and pool config */
176 wr32(hw, TXGBE_VFPLCFG, 0);
179 /* flush all queues disables */
186 STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
187 u32 *retmsg, u16 size)
189 struct txgbe_mbx_info *mbx = &hw->mbx;
190 s32 retval = mbx->write_posted(hw, msg, size, 0);
195 return mbx->read_posted(hw, retmsg, size, 0);
199 * txgbevf_negotiate_api_version - Negotiate supported API version
200 * @hw: pointer to the HW structure
201 * @api: integer containing requested API version
203 int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
208 /* Negotiate the mailbox API version */
209 msg[0] = TXGBE_VF_API_NEGOTIATE;
213 err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
215 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
217 /* Store value and return 0 on success */
218 if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
219 hw->api_version = api;
223 err = TXGBE_ERR_INVALID_ARGUMENT;
229 int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
230 unsigned int *default_tc)
235 /* do nothing if API doesn't support txgbevf_get_queues */
236 switch (hw->api_version) {
237 case txgbe_mbox_api_11:
238 case txgbe_mbox_api_12:
239 case txgbe_mbox_api_13:
245 /* Fetch queue configuration from the PF */
246 msg[0] = TXGBE_VF_GET_QUEUES;
247 for (i = 1; i < 5; i++)
250 err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
252 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
255 * if we didn't get an ACK there must have been
256 * some sort of mailbox error so we should treat it
259 if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
260 return TXGBE_ERR_MBX;
262 /* record and validate values from message */
263 hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
264 if (hw->mac.max_tx_queues == 0 ||
265 hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
266 hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
268 hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
269 if (hw->mac.max_rx_queues == 0 ||
270 hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
271 hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
273 *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
274 /* in case of unknown state assume we cannot tag frames */
275 if (*num_tcs > hw->mac.max_rx_queues)
278 *default_tc = msg[TXGBE_VF_DEF_QUEUE];
279 /* default to queue 0 on out-of-bounds queue number */
280 if (*default_tc >= hw->mac.max_tx_queues)