1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
7 * fm10k_stop_hw_vf - Stop Tx/Rx units
8 * @hw: pointer to hardware structure
11 static s32 fm10k_stop_hw_vf(struct fm10k_hw *hw)
13 u8 *perm_addr = hw->mac.perm_addr;
14 u32 bal = 0, bah = 0, tdlen;
18 /* we need to disable the queues before taking further steps */
19 err = fm10k_stop_hw_generic(hw);
20 if (err && err != FM10K_ERR_REQUESTS_PENDING)
23 /* If permanent address is set then we need to restore it */
24 if (is_valid_ether_addr(perm_addr)) {
25 bal = (((u32)perm_addr[3]) << 24) |
26 (((u32)perm_addr[4]) << 16) |
27 (((u32)perm_addr[5]) << 8);
28 bah = (((u32)0xFF) << 24) |
29 (((u32)perm_addr[0]) << 16) |
30 (((u32)perm_addr[1]) << 8) |
34 /* restore default itr_scale for next VF initialization */
35 tdlen = hw->mac.itr_scale << FM10K_TDLEN_ITR_SCALE_SHIFT;
37 /* The queues have already been disabled so we just need to
38 * update their base address registers
40 for (i = 0; i < hw->mac.max_queues; i++) {
41 fm10k_write_reg(hw, FM10K_TDBAL(i), bal);
42 fm10k_write_reg(hw, FM10K_TDBAH(i), bah);
43 fm10k_write_reg(hw, FM10K_RDBAL(i), bal);
44 fm10k_write_reg(hw, FM10K_RDBAH(i), bah);
45 /* Restore ITR scale in software-defined mechanism in TDLEN
46 * for next VF initialization. See definition of
47 * FM10K_TDLEN_ITR_SCALE_SHIFT for more details on the use of
50 fm10k_write_reg(hw, FM10K_TDLEN(i), tdlen);
57 * fm10k_reset_hw_vf - VF hardware reset
58 * @hw: pointer to hardware structure
60 * This function should return the hardware to a state similar to the
61 * one it is in after just being initialized.
63 static s32 fm10k_reset_hw_vf(struct fm10k_hw *hw)
67 /* shut down queues we own and reset DMA configuration */
68 err = fm10k_stop_hw_vf(hw);
69 if (err == FM10K_ERR_REQUESTS_PENDING)
70 hw->mac.reset_while_pending++;
74 /* Inititate VF reset */
75 fm10k_write_reg(hw, FM10K_VFCTRL, FM10K_VFCTRL_RST);
77 /* Flush write and allow 100us for reset to complete */
78 fm10k_write_flush(hw);
79 udelay(FM10K_RESET_TIMEOUT);
81 /* Clear reset bit and verify it was cleared */
82 fm10k_write_reg(hw, FM10K_VFCTRL, 0);
83 if (fm10k_read_reg(hw, FM10K_VFCTRL) & FM10K_VFCTRL_RST)
84 return FM10K_ERR_RESET_FAILED;
90 * fm10k_init_hw_vf - VF hardware initialization
91 * @hw: pointer to hardware structure
94 static s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
96 u32 tqdloc, tqdloc0 = ~fm10k_read_reg(hw, FM10K_TQDLOC(0));
100 /* verify we have at least 1 queue */
101 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(0)) ||
102 !~fm10k_read_reg(hw, FM10K_RXQCTL(0))) {
103 err = FM10K_ERR_NO_RESOURCES;
104 goto reset_max_queues;
107 /* determine how many queues we have */
108 for (i = 1; tqdloc0 && (i < FM10K_MAX_QUEUES_POOL); i++) {
109 /* verify the Descriptor cache offsets are increasing */
110 tqdloc = ~fm10k_read_reg(hw, FM10K_TQDLOC(i));
111 if (!tqdloc || (tqdloc == tqdloc0))
114 /* check to verify the PF doesn't own any of our queues */
115 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(i)) ||
116 !~fm10k_read_reg(hw, FM10K_RXQCTL(i)))
120 /* shut down queues we own and reset DMA configuration */
121 err = fm10k_disable_queues_generic(hw, i);
123 goto reset_max_queues;
125 /* record maximum queue count */
126 hw->mac.max_queues = i;
128 /* fetch default VLAN and ITR scale */
129 hw->mac.default_vid = (fm10k_read_reg(hw, FM10K_TXQCTL(0)) &
130 FM10K_TXQCTL_VID_MASK) >> FM10K_TXQCTL_VID_SHIFT;
131 /* Read the ITR scale from TDLEN. See the definition of
132 * FM10K_TDLEN_ITR_SCALE_SHIFT for more information about how TDLEN is
135 hw->mac.itr_scale = (fm10k_read_reg(hw, FM10K_TDLEN(0)) &
136 FM10K_TDLEN_ITR_SCALE_MASK) >>
137 FM10K_TDLEN_ITR_SCALE_SHIFT;
142 hw->mac.max_queues = 0;
147 /* This structure defines the attibutes to be parsed below */
148 const struct fm10k_tlv_attr fm10k_mac_vlan_msg_attr[] = {
149 FM10K_TLV_ATTR_U32(FM10K_MAC_VLAN_MSG_VLAN),
150 FM10K_TLV_ATTR_BOOL(FM10K_MAC_VLAN_MSG_SET),
151 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MAC),
152 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_DEFAULT_MAC),
153 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MULTICAST),
158 * fm10k_update_vlan_vf - Update status of VLAN ID in VLAN filter table
159 * @hw: pointer to hardware structure
160 * @vid: VLAN ID to add to table
161 * @vsi: Reserved, should always be 0
162 * @set: Indicates if this is a set or clear operation
164 * This function adds or removes the corresponding VLAN ID from the VLAN
165 * filter table for this VF.
167 static s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
169 struct fm10k_mbx_info *mbx = &hw->mbx;
172 /* verify the index is not set */
174 return FM10K_ERR_PARAM;
176 /* clever trick to verify reserved bits in both vid and length */
177 if ((vid << 16 | vid) >> 28)
178 return FM10K_ERR_PARAM;
180 /* encode set bit into the VLAN ID */
182 vid |= FM10K_VLAN_CLEAR;
184 /* generate VLAN request */
185 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
186 fm10k_tlv_attr_put_u32(msg, FM10K_MAC_VLAN_MSG_VLAN, vid);
188 /* load onto outgoing mailbox */
189 return mbx->ops.enqueue_tx(hw, mbx, msg);
193 * fm10k_msg_mac_vlan_vf - Read device MAC address from mailbox message
194 * @hw: pointer to the HW structure
195 * @results: Attributes for message
196 * @mbx: unused mailbox data
198 * This function should determine the MAC address for the VF
200 s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
201 struct fm10k_mbx_info *mbx)
203 u8 perm_addr[ETH_ALEN];
207 /* record MAC address requested */
208 err = fm10k_tlv_attr_get_mac_vlan(
209 results[FM10K_MAC_VLAN_MSG_DEFAULT_MAC],
214 ether_addr_copy(hw->mac.perm_addr, perm_addr);
215 hw->mac.default_vid = vid & (FM10K_VLAN_TABLE_VID_MAX - 1);
216 hw->mac.vlan_override = !!(vid & FM10K_VLAN_OVERRIDE);
222 * fm10k_read_mac_addr_vf - Read device MAC address
223 * @hw: pointer to the HW structure
225 * This function should determine the MAC address for the VF
227 static s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
229 u8 perm_addr[ETH_ALEN];
232 base_addr = fm10k_read_reg(hw, FM10K_TDBAL(0));
234 /* last byte should be 0 */
236 return FM10K_ERR_INVALID_MAC_ADDR;
238 perm_addr[3] = (u8)(base_addr >> 24);
239 perm_addr[4] = (u8)(base_addr >> 16);
240 perm_addr[5] = (u8)(base_addr >> 8);
242 base_addr = fm10k_read_reg(hw, FM10K_TDBAH(0));
244 /* first byte should be all 1's */
245 if ((~base_addr) >> 24)
246 return FM10K_ERR_INVALID_MAC_ADDR;
248 perm_addr[0] = (u8)(base_addr >> 16);
249 perm_addr[1] = (u8)(base_addr >> 8);
250 perm_addr[2] = (u8)(base_addr);
252 ether_addr_copy(hw->mac.perm_addr, perm_addr);
253 ether_addr_copy(hw->mac.addr, perm_addr);
259 * fm10k_update_uc_addr_vf - Update device unicast addresses
260 * @hw: pointer to the HW structure
262 * @mac: MAC address to add/remove from table
263 * @vid: VLAN ID to add/remove from table
264 * @add: Indicates if this is an add or remove operation
265 * @flags: flags field to indicate add and secure - unused
267 * This function is used to add or remove unicast MAC addresses for
270 static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
271 const u8 *mac, u16 vid, bool add, u8 flags)
273 struct fm10k_mbx_info *mbx = &hw->mbx;
276 /* verify VLAN ID is valid */
277 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
278 return FM10K_ERR_PARAM;
280 /* verify MAC address is valid */
281 if (!is_valid_ether_addr(mac))
282 return FM10K_ERR_PARAM;
284 /* verify we are not locked down on the MAC address */
285 if (is_valid_ether_addr(hw->mac.perm_addr) &&
286 !ether_addr_equal(hw->mac.perm_addr, mac))
287 return FM10K_ERR_PARAM;
289 /* add bit to notify us if this is a set or clear operation */
291 vid |= FM10K_VLAN_CLEAR;
293 /* generate VLAN request */
294 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
295 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MAC, mac, vid);
297 /* load onto outgoing mailbox */
298 return mbx->ops.enqueue_tx(hw, mbx, msg);
302 * fm10k_update_mc_addr_vf - Update device multicast addresses
303 * @hw: pointer to the HW structure
305 * @mac: MAC address to add/remove from table
306 * @vid: VLAN ID to add/remove from table
307 * @add: Indicates if this is an add or remove operation
309 * This function is used to add or remove multicast MAC addresses for
312 static s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw, u16 glort,
313 const u8 *mac, u16 vid, bool add)
315 struct fm10k_mbx_info *mbx = &hw->mbx;
318 /* verify VLAN ID is valid */
319 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
320 return FM10K_ERR_PARAM;
322 /* verify multicast address is valid */
323 if (!is_multicast_ether_addr(mac))
324 return FM10K_ERR_PARAM;
326 /* add bit to notify us if this is a set or clear operation */
328 vid |= FM10K_VLAN_CLEAR;
330 /* generate VLAN request */
331 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
332 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MULTICAST,
335 /* load onto outgoing mailbox */
336 return mbx->ops.enqueue_tx(hw, mbx, msg);
340 * fm10k_update_int_moderator_vf - Request update of interrupt moderator list
341 * @hw: pointer to hardware structure
343 * This function will issue a request to the PF to rescan our MSI-X table
344 * and to update the interrupt moderator linked list.
346 static void fm10k_update_int_moderator_vf(struct fm10k_hw *hw)
348 struct fm10k_mbx_info *mbx = &hw->mbx;
351 /* generate MSI-X request */
352 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MSIX);
354 /* load onto outgoing mailbox */
355 mbx->ops.enqueue_tx(hw, mbx, msg);
358 /* This structure defines the attibutes to be parsed below */
359 const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
360 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_DISABLE),
361 FM10K_TLV_ATTR_U8(FM10K_LPORT_STATE_MSG_XCAST_MODE),
362 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_READY),
367 * fm10k_msg_lport_state_vf - Message handler for lport_state message from PF
368 * @hw: Pointer to hardware structure
369 * @results: pointer array containing parsed data
370 * @mbx: Pointer to mailbox information structure
372 * This handler is meant to capture the indication from the PF that we
373 * are ready to bring up the interface.
375 s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
376 struct fm10k_mbx_info *mbx)
378 hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
379 FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
385 * fm10k_update_lport_state_vf - Update device state in lower device
386 * @hw: pointer to the HW structure
388 * @count: number of logical ports to enable - unused (always 1)
389 * @enable: boolean value indicating if this is an enable or disable request
391 * Notify the lower device of a state change. If the lower device is
392 * enabled we can add filters, if it is disabled all filters for this
393 * logical port are flushed.
395 static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
396 u16 count, bool enable)
398 struct fm10k_mbx_info *mbx = &hw->mbx;
401 /* reset glort mask 0 as we have to wait to be enabled */
402 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
404 /* generate port state request */
405 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
407 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_DISABLE);
409 /* load onto outgoing mailbox */
410 return mbx->ops.enqueue_tx(hw, mbx, msg);
414 * fm10k_update_xcast_mode_vf - Request update of multicast mode
415 * @hw: pointer to hardware structure
417 * @mode: integer value indicating mode being requested
419 * This function will attempt to request a higher mode for the port
420 * so that it can enable either multicast, multicast promiscuous, or
421 * promiscuous mode of operation.
423 static s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw, u16 glort, u8 mode)
425 struct fm10k_mbx_info *mbx = &hw->mbx;
428 if (mode > FM10K_XCAST_MODE_NONE)
429 return FM10K_ERR_PARAM;
431 /* generate message requesting to change xcast mode */
432 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
433 fm10k_tlv_attr_put_u8(msg, FM10K_LPORT_STATE_MSG_XCAST_MODE, mode);
435 /* load onto outgoing mailbox */
436 return mbx->ops.enqueue_tx(hw, mbx, msg);
440 * fm10k_update_hw_stats_vf - Updates hardware related statistics of VF
441 * @hw: pointer to hardware structure
442 * @stats: pointer to statistics structure
444 * This function collects and aggregates per queue hardware statistics.
446 static void fm10k_update_hw_stats_vf(struct fm10k_hw *hw,
447 struct fm10k_hw_stats *stats)
449 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
453 * fm10k_rebind_hw_stats_vf - Resets base for hardware statistics of VF
454 * @hw: pointer to hardware structure
455 * @stats: pointer to the stats structure to update
457 * This function resets the base for queue hardware statistics.
459 static void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
460 struct fm10k_hw_stats *stats)
462 /* Unbind Queue Statistics */
463 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
465 /* Reinitialize bases for all stats */
466 fm10k_update_hw_stats_vf(hw, stats);
470 * fm10k_configure_dglort_map_vf - Configures GLORT entry and queues
471 * @hw: pointer to hardware structure
472 * @dglort: pointer to dglort configuration structure
474 * Reads the configuration structure contained in dglort_cfg and uses
475 * that information to then populate a DGLORTMAP/DEC entry and the queues
476 * to which it has been assigned.
478 static s32 fm10k_configure_dglort_map_vf(struct fm10k_hw *hw,
479 struct fm10k_dglort_cfg *dglort)
481 /* verify the dglort pointer */
483 return FM10K_ERR_PARAM;
485 /* stub for now until we determine correct message for this */
490 static const struct fm10k_msg_data fm10k_msg_data_vf[] = {
491 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
492 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
493 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
494 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
497 static const struct fm10k_mac_ops mac_ops_vf = {
498 .get_bus_info = fm10k_get_bus_info_generic,
499 .reset_hw = fm10k_reset_hw_vf,
500 .init_hw = fm10k_init_hw_vf,
501 .start_hw = fm10k_start_hw_generic,
502 .stop_hw = fm10k_stop_hw_vf,
503 .update_vlan = fm10k_update_vlan_vf,
504 .read_mac_addr = fm10k_read_mac_addr_vf,
505 .update_uc_addr = fm10k_update_uc_addr_vf,
506 .update_mc_addr = fm10k_update_mc_addr_vf,
507 .update_xcast_mode = fm10k_update_xcast_mode_vf,
508 .update_int_moderator = fm10k_update_int_moderator_vf,
509 .update_lport_state = fm10k_update_lport_state_vf,
510 .update_hw_stats = fm10k_update_hw_stats_vf,
511 .rebind_hw_stats = fm10k_rebind_hw_stats_vf,
512 .configure_dglort_map = fm10k_configure_dglort_map_vf,
513 .get_host_state = fm10k_get_host_state_generic,
516 static s32 fm10k_get_invariants_vf(struct fm10k_hw *hw)
518 fm10k_get_invariants_generic(hw);
520 return fm10k_pfvf_mbx_init(hw, &hw->mbx, fm10k_msg_data_vf, 0);
523 const struct fm10k_info fm10k_vf_info = {
525 .get_invariants = fm10k_get_invariants_vf,
526 .mac_ops = &mac_ops_vf,