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;
30 /* RAR, Multicast, VLAN */
31 mac->set_rar = txgbe_set_rar_vf;
32 mac->set_uc_addr = txgbevf_set_uc_addr_vf;
34 mac->max_tx_queues = 1;
35 mac->max_rx_queues = 1;
37 mbx->init_params = txgbe_init_mbx_params_vf;
38 mbx->read = txgbe_read_mbx_vf;
39 mbx->write = txgbe_write_mbx_vf;
40 mbx->read_posted = txgbe_read_posted_mbx;
41 mbx->write_posted = txgbe_write_posted_mbx;
42 mbx->check_for_msg = txgbe_check_for_msg_vf;
43 mbx->check_for_ack = txgbe_check_for_ack_vf;
44 mbx->check_for_rst = txgbe_check_for_rst_vf;
49 /* txgbe_virt_clr_reg - Set register to default (power on) state.
50 * @hw: pointer to hardware structure
52 static void txgbe_virt_clr_reg(struct txgbe_hw *hw)
57 /* default values (BUF_SIZE = 2048, HDR_SIZE = 256) */
58 vfsrrctl = TXGBE_RXCFG_HDRLEN(TXGBE_RX_HDR_SIZE);
59 vfsrrctl |= TXGBE_RXCFG_PKTLEN(TXGBE_RX_BUF_SIZE);
61 for (i = 0; i < 8; i++) {
62 wr32m(hw, TXGBE_RXCFG(i),
63 (TXGBE_RXCFG_HDRLEN_MASK | TXGBE_RXCFG_PKTLEN_MASK),
71 * txgbe_start_hw_vf - Prepare hardware for Tx/Rx
72 * @hw: pointer to hardware structure
74 * Starts the hardware by filling the bus info structure and media type, clears
75 * all on chip counters, initializes receive address registers, multicast
76 * table, VLAN filter table, calls routine to set up link and flow control
77 * settings, and leaves transmit and receive units disabled and uninitialized
79 s32 txgbe_start_hw_vf(struct txgbe_hw *hw)
81 /* Clear adapter stopped flag */
82 hw->adapter_stopped = false;
88 * txgbe_reset_hw_vf - Performs hardware reset
89 * @hw: pointer to hardware structure
91 * Resets the hardware by resetting the transmit and receive units, masks and
92 * clears all interrupts.
94 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw)
96 struct txgbe_mbx_info *mbx = &hw->mbx;
97 u32 timeout = TXGBE_VF_INIT_TIMEOUT;
98 s32 ret_val = TXGBE_ERR_INVALID_MAC_ADDR;
99 u32 msgbuf[TXGBE_VF_PERMADDR_MSG_LEN];
100 u8 *addr = (u8 *)(&msgbuf[1]);
102 DEBUGFUNC("txgbevf_reset_hw_vf");
104 /* Call adapter stop to disable tx/rx and clear interrupts */
107 /* reset the api version */
108 hw->api_version = txgbe_mbox_api_10;
110 /* backup msix vectors */
111 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
112 msgbuf[0] = TXGBE_VF_BACKUP;
113 mbx->write_posted(hw, msgbuf, 1, 0);
116 DEBUGOUT("Issuing a function level reset to MAC\n");
117 wr32(hw, TXGBE_VFRST, TXGBE_VFRST_SET);
121 hw->offset_loaded = 1;
123 /* we cannot reset while the RSTI / RSTD bits are asserted */
124 while (!mbx->check_for_rst(hw, 0) && timeout) {
126 /* if it doesn't work, try in 1 ms */
131 return TXGBE_ERR_RESET_FAILED;
133 /* Reset VF registers to initial values */
134 txgbe_virt_clr_reg(hw);
136 /* mailbox timeout can now become active */
137 mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
139 msgbuf[0] = TXGBE_VF_RESET;
140 mbx->write_posted(hw, msgbuf, 1, 0);
145 * set our "perm_addr" based on info provided by PF
146 * also set up the mc_filter_type which is piggy backed
147 * on the mac address in word 3
149 ret_val = mbx->read_posted(hw, msgbuf,
150 TXGBE_VF_PERMADDR_MSG_LEN, 0);
154 if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
155 msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
156 return TXGBE_ERR_INVALID_MAC_ADDR;
158 if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
159 memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
161 hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
167 * txgbe_stop_hw_vf - Generic stop Tx/Rx units
168 * @hw: pointer to hardware structure
170 * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
171 * disables transmit and receive units. The adapter_stopped flag is used by
172 * the shared code and drivers to determine if the adapter is in a stopped
173 * state and should not touch the hardware.
175 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
180 * Set the adapter_stopped flag so other driver functions stop touching
183 hw->adapter_stopped = true;
185 /* Clear interrupt mask to stop from interrupts being generated */
186 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
188 /* Clear any pending interrupts, flush previous writes */
189 wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
191 /* Disable the transmit unit. Each queue must be disabled. */
192 for (i = 0; i < hw->mac.max_tx_queues; i++)
193 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
195 /* Disable the receive unit by stopping each queue */
196 for (i = 0; i < hw->mac.max_rx_queues; i++)
197 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
199 /* Clear packet split and pool config */
200 wr32(hw, TXGBE_VFPLCFG, 0);
203 /* flush all queues disables */
210 STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
211 u32 *retmsg, u16 size)
213 struct txgbe_mbx_info *mbx = &hw->mbx;
214 s32 retval = mbx->write_posted(hw, msg, size, 0);
219 return mbx->read_posted(hw, retmsg, size, 0);
223 * txgbe_set_rar_vf - set device MAC address
224 * @hw: pointer to hardware structure
225 * @index: Receive address register to write
226 * @addr: Address to put into receive address register
227 * @vmdq: VMDq "set" or "pool" index
228 * @enable_addr: set flag that address is active
230 s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
234 u8 *msg_addr = (u8 *)(&msgbuf[1]);
236 UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
238 memset(msgbuf, 0, 12);
239 msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
240 memcpy(msg_addr, addr, 6);
241 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
243 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
245 /* if nacked the address was rejected, use "perm_addr" */
247 (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
248 txgbe_get_mac_addr_vf(hw, hw->mac.addr);
249 return TXGBE_ERR_MBX;
256 * txgbe_get_mac_addr_vf - Read device MAC address
257 * @hw: pointer to the HW structure
258 * @mac_addr: the MAC address
260 s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
264 for (i = 0; i < ETH_ADDR_LEN; i++)
265 mac_addr[i] = hw->mac.perm_addr[i];
270 s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
272 u32 msgbuf[3], msgbuf_chk;
273 u8 *msg_addr = (u8 *)(&msgbuf[1]);
276 memset(msgbuf, 0, sizeof(msgbuf));
278 * If index is one then this is the start of a new list and needs
279 * indication to the PF so it can do it's own list management.
280 * If it is zero then that tells the PF to just clear all of
281 * this VF's macvlans and there is no new list.
283 msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
284 msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
285 msgbuf_chk = msgbuf[0];
287 memcpy(msg_addr, addr, 6);
289 ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
291 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
293 if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
294 return TXGBE_ERR_OUT_OF_MEM;
301 * txgbevf_negotiate_api_version - Negotiate supported API version
302 * @hw: pointer to the HW structure
303 * @api: integer containing requested API version
305 int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
310 /* Negotiate the mailbox API version */
311 msg[0] = TXGBE_VF_API_NEGOTIATE;
315 err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
317 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
319 /* Store value and return 0 on success */
320 if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
321 hw->api_version = api;
325 err = TXGBE_ERR_INVALID_ARGUMENT;
331 int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
332 unsigned int *default_tc)
337 /* do nothing if API doesn't support txgbevf_get_queues */
338 switch (hw->api_version) {
339 case txgbe_mbox_api_11:
340 case txgbe_mbox_api_12:
341 case txgbe_mbox_api_13:
347 /* Fetch queue configuration from the PF */
348 msg[0] = TXGBE_VF_GET_QUEUES;
349 for (i = 1; i < 5; i++)
352 err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
354 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
357 * if we didn't get an ACK there must have been
358 * some sort of mailbox error so we should treat it
361 if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
362 return TXGBE_ERR_MBX;
364 /* record and validate values from message */
365 hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
366 if (hw->mac.max_tx_queues == 0 ||
367 hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
368 hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
370 hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
371 if (hw->mac.max_rx_queues == 0 ||
372 hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
373 hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
375 *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
376 /* in case of unknown state assume we cannot tag frames */
377 if (*num_tcs > hw->mac.max_rx_queues)
380 *default_tc = msg[TXGBE_VF_DEF_QUEUE];
381 /* default to queue 0 on out-of-bounds queue number */
382 if (*default_tc >= hw->mac.max_tx_queues)