1 /* Intel(R) Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2016 Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 * fm10k_stop_hw_vf - Stop Tx/Rx units
25 * @hw: pointer to hardware structure
28 static s32 fm10k_stop_hw_vf(struct fm10k_hw *hw)
30 u8 *perm_addr = hw->mac.perm_addr;
31 u32 bal = 0, bah = 0, tdlen;
35 /* we need to disable the queues before taking further steps */
36 err = fm10k_stop_hw_generic(hw);
37 if (err && err != FM10K_ERR_REQUESTS_PENDING)
40 /* If permanent address is set then we need to restore it */
41 if (is_valid_ether_addr(perm_addr)) {
42 bal = (((u32)perm_addr[3]) << 24) |
43 (((u32)perm_addr[4]) << 16) |
44 (((u32)perm_addr[5]) << 8);
45 bah = (((u32)0xFF) << 24) |
46 (((u32)perm_addr[0]) << 16) |
47 (((u32)perm_addr[1]) << 8) |
51 /* restore default itr_scale for next VF initialization */
52 tdlen = hw->mac.itr_scale << FM10K_TDLEN_ITR_SCALE_SHIFT;
54 /* The queues have already been disabled so we just need to
55 * update their base address registers
57 for (i = 0; i < hw->mac.max_queues; i++) {
58 fm10k_write_reg(hw, FM10K_TDBAL(i), bal);
59 fm10k_write_reg(hw, FM10K_TDBAH(i), bah);
60 fm10k_write_reg(hw, FM10K_RDBAL(i), bal);
61 fm10k_write_reg(hw, FM10K_RDBAH(i), bah);
62 /* Restore ITR scale in software-defined mechanism in TDLEN
63 * for next VF initialization. See definition of
64 * FM10K_TDLEN_ITR_SCALE_SHIFT for more details on the use of
67 fm10k_write_reg(hw, FM10K_TDLEN(i), tdlen);
74 * fm10k_reset_hw_vf - VF hardware reset
75 * @hw: pointer to hardware structure
77 * This function should return the hardware to a state similar to the
78 * one it is in after just being initialized.
80 static s32 fm10k_reset_hw_vf(struct fm10k_hw *hw)
84 /* shut down queues we own and reset DMA configuration */
85 err = fm10k_stop_hw_vf(hw);
86 if (err == FM10K_ERR_REQUESTS_PENDING)
87 hw->mac.reset_while_pending++;
91 /* Inititate VF reset */
92 fm10k_write_reg(hw, FM10K_VFCTRL, FM10K_VFCTRL_RST);
94 /* Flush write and allow 100us for reset to complete */
95 fm10k_write_flush(hw);
96 udelay(FM10K_RESET_TIMEOUT);
98 /* Clear reset bit and verify it was cleared */
99 fm10k_write_reg(hw, FM10K_VFCTRL, 0);
100 if (fm10k_read_reg(hw, FM10K_VFCTRL) & FM10K_VFCTRL_RST)
101 return FM10K_ERR_RESET_FAILED;
107 * fm10k_init_hw_vf - VF hardware initialization
108 * @hw: pointer to hardware structure
111 static s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
113 u32 tqdloc, tqdloc0 = ~fm10k_read_reg(hw, FM10K_TQDLOC(0));
117 /* verify we have at least 1 queue */
118 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(0)) ||
119 !~fm10k_read_reg(hw, FM10K_RXQCTL(0))) {
120 err = FM10K_ERR_NO_RESOURCES;
121 goto reset_max_queues;
124 /* determine how many queues we have */
125 for (i = 1; tqdloc0 && (i < FM10K_MAX_QUEUES_POOL); i++) {
126 /* verify the Descriptor cache offsets are increasing */
127 tqdloc = ~fm10k_read_reg(hw, FM10K_TQDLOC(i));
128 if (!tqdloc || (tqdloc == tqdloc0))
131 /* check to verify the PF doesn't own any of our queues */
132 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(i)) ||
133 !~fm10k_read_reg(hw, FM10K_RXQCTL(i)))
137 /* shut down queues we own and reset DMA configuration */
138 err = fm10k_disable_queues_generic(hw, i);
140 goto reset_max_queues;
142 /* record maximum queue count */
143 hw->mac.max_queues = i;
145 /* fetch default VLAN and ITR scale */
146 hw->mac.default_vid = (fm10k_read_reg(hw, FM10K_TXQCTL(0)) &
147 FM10K_TXQCTL_VID_MASK) >> FM10K_TXQCTL_VID_SHIFT;
148 /* Read the ITR scale from TDLEN. See the definition of
149 * FM10K_TDLEN_ITR_SCALE_SHIFT for more information about how TDLEN is
152 hw->mac.itr_scale = (fm10k_read_reg(hw, FM10K_TDLEN(0)) &
153 FM10K_TDLEN_ITR_SCALE_MASK) >>
154 FM10K_TDLEN_ITR_SCALE_SHIFT;
159 hw->mac.max_queues = 0;
164 /* This structure defines the attibutes to be parsed below */
165 const struct fm10k_tlv_attr fm10k_mac_vlan_msg_attr[] = {
166 FM10K_TLV_ATTR_U32(FM10K_MAC_VLAN_MSG_VLAN),
167 FM10K_TLV_ATTR_BOOL(FM10K_MAC_VLAN_MSG_SET),
168 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MAC),
169 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_DEFAULT_MAC),
170 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MULTICAST),
175 * fm10k_update_vlan_vf - Update status of VLAN ID in VLAN filter table
176 * @hw: pointer to hardware structure
177 * @vid: VLAN ID to add to table
178 * @vsi: Reserved, should always be 0
179 * @set: Indicates if this is a set or clear operation
181 * This function adds or removes the corresponding VLAN ID from the VLAN
182 * filter table for this VF.
184 static s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
186 struct fm10k_mbx_info *mbx = &hw->mbx;
189 /* verify the index is not set */
191 return FM10K_ERR_PARAM;
193 /* clever trick to verify reserved bits in both vid and length */
194 if ((vid << 16 | vid) >> 28)
195 return FM10K_ERR_PARAM;
197 /* encode set bit into the VLAN ID */
199 vid |= FM10K_VLAN_CLEAR;
201 /* generate VLAN request */
202 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
203 fm10k_tlv_attr_put_u32(msg, FM10K_MAC_VLAN_MSG_VLAN, vid);
205 /* load onto outgoing mailbox */
206 return mbx->ops.enqueue_tx(hw, mbx, msg);
210 * fm10k_msg_mac_vlan_vf - Read device MAC address from mailbox message
211 * @hw: pointer to the HW structure
212 * @results: Attributes for message
213 * @mbx: unused mailbox data
215 * This function should determine the MAC address for the VF
217 s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
218 struct fm10k_mbx_info *mbx)
220 u8 perm_addr[ETH_ALEN];
224 /* record MAC address requested */
225 err = fm10k_tlv_attr_get_mac_vlan(
226 results[FM10K_MAC_VLAN_MSG_DEFAULT_MAC],
231 ether_addr_copy(hw->mac.perm_addr, perm_addr);
232 hw->mac.default_vid = vid & (FM10K_VLAN_TABLE_VID_MAX - 1);
233 hw->mac.vlan_override = !!(vid & FM10K_VLAN_OVERRIDE);
239 * fm10k_read_mac_addr_vf - Read device MAC address
240 * @hw: pointer to the HW structure
242 * This function should determine the MAC address for the VF
244 static s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
246 u8 perm_addr[ETH_ALEN];
249 base_addr = fm10k_read_reg(hw, FM10K_TDBAL(0));
251 /* last byte should be 0 */
253 return FM10K_ERR_INVALID_MAC_ADDR;
255 perm_addr[3] = (u8)(base_addr >> 24);
256 perm_addr[4] = (u8)(base_addr >> 16);
257 perm_addr[5] = (u8)(base_addr >> 8);
259 base_addr = fm10k_read_reg(hw, FM10K_TDBAH(0));
261 /* first byte should be all 1's */
262 if ((~base_addr) >> 24)
263 return FM10K_ERR_INVALID_MAC_ADDR;
265 perm_addr[0] = (u8)(base_addr >> 16);
266 perm_addr[1] = (u8)(base_addr >> 8);
267 perm_addr[2] = (u8)(base_addr);
269 ether_addr_copy(hw->mac.perm_addr, perm_addr);
270 ether_addr_copy(hw->mac.addr, perm_addr);
276 * fm10k_update_uc_addr_vf - Update device unicast addresses
277 * @hw: pointer to the HW structure
279 * @mac: MAC address to add/remove from table
280 * @vid: VLAN ID to add/remove from table
281 * @add: Indicates if this is an add or remove operation
282 * @flags: flags field to indicate add and secure - unused
284 * This function is used to add or remove unicast MAC addresses for
287 static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
288 const u8 *mac, u16 vid, bool add, u8 flags)
290 struct fm10k_mbx_info *mbx = &hw->mbx;
293 /* verify VLAN ID is valid */
294 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
295 return FM10K_ERR_PARAM;
297 /* verify MAC address is valid */
298 if (!is_valid_ether_addr(mac))
299 return FM10K_ERR_PARAM;
301 /* verify we are not locked down on the MAC address */
302 if (is_valid_ether_addr(hw->mac.perm_addr) &&
303 !ether_addr_equal(hw->mac.perm_addr, mac))
304 return FM10K_ERR_PARAM;
306 /* add bit to notify us if this is a set or clear operation */
308 vid |= FM10K_VLAN_CLEAR;
310 /* generate VLAN request */
311 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
312 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MAC, mac, vid);
314 /* load onto outgoing mailbox */
315 return mbx->ops.enqueue_tx(hw, mbx, msg);
319 * fm10k_update_mc_addr_vf - Update device multicast addresses
320 * @hw: pointer to the HW structure
322 * @mac: MAC address to add/remove from table
323 * @vid: VLAN ID to add/remove from table
324 * @add: Indicates if this is an add or remove operation
326 * This function is used to add or remove multicast MAC addresses for
329 static s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw, u16 glort,
330 const u8 *mac, u16 vid, bool add)
332 struct fm10k_mbx_info *mbx = &hw->mbx;
335 /* verify VLAN ID is valid */
336 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
337 return FM10K_ERR_PARAM;
339 /* verify multicast address is valid */
340 if (!is_multicast_ether_addr(mac))
341 return FM10K_ERR_PARAM;
343 /* add bit to notify us if this is a set or clear operation */
345 vid |= FM10K_VLAN_CLEAR;
347 /* generate VLAN request */
348 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
349 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MULTICAST,
352 /* load onto outgoing mailbox */
353 return mbx->ops.enqueue_tx(hw, mbx, msg);
357 * fm10k_update_int_moderator_vf - Request update of interrupt moderator list
358 * @hw: pointer to hardware structure
360 * This function will issue a request to the PF to rescan our MSI-X table
361 * and to update the interrupt moderator linked list.
363 static void fm10k_update_int_moderator_vf(struct fm10k_hw *hw)
365 struct fm10k_mbx_info *mbx = &hw->mbx;
368 /* generate MSI-X request */
369 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MSIX);
371 /* load onto outgoing mailbox */
372 mbx->ops.enqueue_tx(hw, mbx, msg);
375 /* This structure defines the attibutes to be parsed below */
376 const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
377 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_DISABLE),
378 FM10K_TLV_ATTR_U8(FM10K_LPORT_STATE_MSG_XCAST_MODE),
379 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_READY),
384 * fm10k_msg_lport_state_vf - Message handler for lport_state message from PF
385 * @hw: Pointer to hardware structure
386 * @results: pointer array containing parsed data
387 * @mbx: Pointer to mailbox information structure
389 * This handler is meant to capture the indication from the PF that we
390 * are ready to bring up the interface.
392 s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
393 struct fm10k_mbx_info *mbx)
395 hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
396 FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
402 * fm10k_update_lport_state_vf - Update device state in lower device
403 * @hw: pointer to the HW structure
405 * @count: number of logical ports to enable - unused (always 1)
406 * @enable: boolean value indicating if this is an enable or disable request
408 * Notify the lower device of a state change. If the lower device is
409 * enabled we can add filters, if it is disabled all filters for this
410 * logical port are flushed.
412 static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
413 u16 count, bool enable)
415 struct fm10k_mbx_info *mbx = &hw->mbx;
418 /* reset glort mask 0 as we have to wait to be enabled */
419 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
421 /* generate port state request */
422 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
424 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_DISABLE);
426 /* load onto outgoing mailbox */
427 return mbx->ops.enqueue_tx(hw, mbx, msg);
431 * fm10k_update_xcast_mode_vf - Request update of multicast mode
432 * @hw: pointer to hardware structure
434 * @mode: integer value indicating mode being requested
436 * This function will attempt to request a higher mode for the port
437 * so that it can enable either multicast, multicast promiscuous, or
438 * promiscuous mode of operation.
440 static s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw, u16 glort, u8 mode)
442 struct fm10k_mbx_info *mbx = &hw->mbx;
445 if (mode > FM10K_XCAST_MODE_NONE)
446 return FM10K_ERR_PARAM;
448 /* generate message requesting to change xcast mode */
449 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
450 fm10k_tlv_attr_put_u8(msg, FM10K_LPORT_STATE_MSG_XCAST_MODE, mode);
452 /* load onto outgoing mailbox */
453 return mbx->ops.enqueue_tx(hw, mbx, msg);
457 * fm10k_update_hw_stats_vf - Updates hardware related statistics of VF
458 * @hw: pointer to hardware structure
459 * @stats: pointer to statistics structure
461 * This function collects and aggregates per queue hardware statistics.
463 static void fm10k_update_hw_stats_vf(struct fm10k_hw *hw,
464 struct fm10k_hw_stats *stats)
466 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
470 * fm10k_rebind_hw_stats_vf - Resets base for hardware statistics of VF
471 * @hw: pointer to hardware structure
472 * @stats: pointer to the stats structure to update
474 * This function resets the base for queue hardware statistics.
476 static void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
477 struct fm10k_hw_stats *stats)
479 /* Unbind Queue Statistics */
480 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
482 /* Reinitialize bases for all stats */
483 fm10k_update_hw_stats_vf(hw, stats);
487 * fm10k_configure_dglort_map_vf - Configures GLORT entry and queues
488 * @hw: pointer to hardware structure
489 * @dglort: pointer to dglort configuration structure
491 * Reads the configuration structure contained in dglort_cfg and uses
492 * that information to then populate a DGLORTMAP/DEC entry and the queues
493 * to which it has been assigned.
495 static s32 fm10k_configure_dglort_map_vf(struct fm10k_hw *hw,
496 struct fm10k_dglort_cfg *dglort)
498 /* verify the dglort pointer */
500 return FM10K_ERR_PARAM;
502 /* stub for now until we determine correct message for this */
507 static const struct fm10k_msg_data fm10k_msg_data_vf[] = {
508 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
509 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
510 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
511 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
514 static const struct fm10k_mac_ops mac_ops_vf = {
515 .get_bus_info = fm10k_get_bus_info_generic,
516 .reset_hw = fm10k_reset_hw_vf,
517 .init_hw = fm10k_init_hw_vf,
518 .start_hw = fm10k_start_hw_generic,
519 .stop_hw = fm10k_stop_hw_vf,
520 .update_vlan = fm10k_update_vlan_vf,
521 .read_mac_addr = fm10k_read_mac_addr_vf,
522 .update_uc_addr = fm10k_update_uc_addr_vf,
523 .update_mc_addr = fm10k_update_mc_addr_vf,
524 .update_xcast_mode = fm10k_update_xcast_mode_vf,
525 .update_int_moderator = fm10k_update_int_moderator_vf,
526 .update_lport_state = fm10k_update_lport_state_vf,
527 .update_hw_stats = fm10k_update_hw_stats_vf,
528 .rebind_hw_stats = fm10k_rebind_hw_stats_vf,
529 .configure_dglort_map = fm10k_configure_dglort_map_vf,
530 .get_host_state = fm10k_get_host_state_generic,
533 static s32 fm10k_get_invariants_vf(struct fm10k_hw *hw)
535 fm10k_get_invariants_generic(hw);
537 return fm10k_pfvf_mbx_init(hw, &hw->mbx, fm10k_msg_data_vf, 0);
540 const struct fm10k_info fm10k_vf_info = {
542 .get_invariants = fm10k_get_invariants_vf,
543 .mac_ops = &mac_ops_vf,