1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2015 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;
35 /* we need to disable the queues before taking further steps */
36 err = fm10k_stop_hw_generic(hw);
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 /* The queues have already been disabled so we just need to
52 * update their base address registers
54 for (i = 0; i < hw->mac.max_queues; i++) {
55 fm10k_write_reg(hw, FM10K_TDBAL(i), bal);
56 fm10k_write_reg(hw, FM10K_TDBAH(i), bah);
57 fm10k_write_reg(hw, FM10K_RDBAL(i), bal);
58 fm10k_write_reg(hw, FM10K_RDBAH(i), bah);
65 * fm10k_reset_hw_vf - VF hardware reset
66 * @hw: pointer to hardware structure
68 * This function should return the hardware to a state similar to the
69 * one it is in after just being initialized.
71 static s32 fm10k_reset_hw_vf(struct fm10k_hw *hw)
75 /* shut down queues we own and reset DMA configuration */
76 err = fm10k_stop_hw_vf(hw);
80 /* Inititate VF reset */
81 fm10k_write_reg(hw, FM10K_VFCTRL, FM10K_VFCTRL_RST);
83 /* Flush write and allow 100us for reset to complete */
84 fm10k_write_flush(hw);
85 udelay(FM10K_RESET_TIMEOUT);
87 /* Clear reset bit and verify it was cleared */
88 fm10k_write_reg(hw, FM10K_VFCTRL, 0);
89 if (fm10k_read_reg(hw, FM10K_VFCTRL) & FM10K_VFCTRL_RST)
90 err = FM10K_ERR_RESET_FAILED;
96 * fm10k_init_hw_vf - VF hardware initialization
97 * @hw: pointer to hardware structure
100 static s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
102 u32 tqdloc, tqdloc0 = ~fm10k_read_reg(hw, FM10K_TQDLOC(0));
106 /* verify we have at least 1 queue */
107 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(0)) ||
108 !~fm10k_read_reg(hw, FM10K_RXQCTL(0))) {
109 err = FM10K_ERR_NO_RESOURCES;
110 goto reset_max_queues;
113 /* determine how many queues we have */
114 for (i = 1; tqdloc0 && (i < FM10K_MAX_QUEUES_POOL); i++) {
115 /* verify the Descriptor cache offsets are increasing */
116 tqdloc = ~fm10k_read_reg(hw, FM10K_TQDLOC(i));
117 if (!tqdloc || (tqdloc == tqdloc0))
120 /* check to verify the PF doesn't own any of our queues */
121 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(i)) ||
122 !~fm10k_read_reg(hw, FM10K_RXQCTL(i)))
126 /* shut down queues we own and reset DMA configuration */
127 err = fm10k_disable_queues_generic(hw, i);
129 goto reset_max_queues;
131 /* record maximum queue count */
132 hw->mac.max_queues = i;
134 /* fetch default VLAN */
135 hw->mac.default_vid = (fm10k_read_reg(hw, FM10K_TXQCTL(0)) &
136 FM10K_TXQCTL_VID_MASK) >> FM10K_TXQCTL_VID_SHIFT;
141 hw->mac.max_queues = 0;
146 /* This structure defines the attibutes to be parsed below */
147 const struct fm10k_tlv_attr fm10k_mac_vlan_msg_attr[] = {
148 FM10K_TLV_ATTR_U32(FM10K_MAC_VLAN_MSG_VLAN),
149 FM10K_TLV_ATTR_BOOL(FM10K_MAC_VLAN_MSG_SET),
150 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MAC),
151 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_DEFAULT_MAC),
152 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MULTICAST),
157 * fm10k_update_vlan_vf - Update status of VLAN ID in VLAN filter table
158 * @hw: pointer to hardware structure
159 * @vid: VLAN ID to add to table
160 * @vsi: Reserved, should always be 0
161 * @set: Indicates if this is a set or clear operation
163 * This function adds or removes the corresponding VLAN ID from the VLAN
164 * filter table for this VF.
166 static s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
168 struct fm10k_mbx_info *mbx = &hw->mbx;
171 /* verify the index is not set */
173 return FM10K_ERR_PARAM;
175 /* verify upper 4 bits of vid and length are 0 */
176 if ((vid << 16 | vid) >> 28)
177 return FM10K_ERR_PARAM;
179 /* encode set bit into the VLAN ID */
181 vid |= FM10K_VLAN_CLEAR;
183 /* generate VLAN request */
184 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
185 fm10k_tlv_attr_put_u32(msg, FM10K_MAC_VLAN_MSG_VLAN, vid);
187 /* load onto outgoing mailbox */
188 return mbx->ops.enqueue_tx(hw, mbx, msg);
192 * fm10k_msg_mac_vlan_vf - Read device MAC address from mailbox message
193 * @hw: pointer to the HW structure
194 * @results: Attributes for message
195 * @mbx: unused mailbox data
197 * This function should determine the MAC address for the VF
199 s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
200 struct fm10k_mbx_info *mbx)
202 u8 perm_addr[ETH_ALEN];
206 /* record MAC address requested */
207 err = fm10k_tlv_attr_get_mac_vlan(
208 results[FM10K_MAC_VLAN_MSG_DEFAULT_MAC],
213 ether_addr_copy(hw->mac.perm_addr, perm_addr);
214 hw->mac.default_vid = vid & (FM10K_VLAN_TABLE_VID_MAX - 1);
215 hw->mac.vlan_override = !!(vid & FM10K_VLAN_CLEAR);
221 * fm10k_read_mac_addr_vf - Read device MAC address
222 * @hw: pointer to the HW structure
224 * This function should determine the MAC address for the VF
226 static s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
228 u8 perm_addr[ETH_ALEN];
231 base_addr = fm10k_read_reg(hw, FM10K_TDBAL(0));
233 /* last byte should be 0 */
235 return FM10K_ERR_INVALID_MAC_ADDR;
237 perm_addr[3] = (u8)(base_addr >> 24);
238 perm_addr[4] = (u8)(base_addr >> 16);
239 perm_addr[5] = (u8)(base_addr >> 8);
241 base_addr = fm10k_read_reg(hw, FM10K_TDBAH(0));
243 /* first byte should be all 1's */
244 if ((~base_addr) >> 24)
245 return FM10K_ERR_INVALID_MAC_ADDR;
247 perm_addr[0] = (u8)(base_addr >> 16);
248 perm_addr[1] = (u8)(base_addr >> 8);
249 perm_addr[2] = (u8)(base_addr);
251 ether_addr_copy(hw->mac.perm_addr, perm_addr);
252 ether_addr_copy(hw->mac.addr, perm_addr);
258 * fm10k_update_uc_addr_vf - Update device unicast addresses
259 * @hw: pointer to the HW structure
261 * @mac: MAC address to add/remove from table
262 * @vid: VLAN ID to add/remove from table
263 * @add: Indicates if this is an add or remove operation
264 * @flags: flags field to indicate add and secure - unused
266 * This function is used to add or remove unicast MAC addresses for
269 static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
270 const u8 *mac, u16 vid, bool add, u8 flags)
272 struct fm10k_mbx_info *mbx = &hw->mbx;
275 /* verify VLAN ID is valid */
276 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
277 return FM10K_ERR_PARAM;
279 /* verify MAC address is valid */
280 if (!is_valid_ether_addr(mac))
281 return FM10K_ERR_PARAM;
283 /* verify we are not locked down on the MAC address */
284 if (is_valid_ether_addr(hw->mac.perm_addr) &&
285 memcmp(hw->mac.perm_addr, mac, ETH_ALEN))
286 return FM10K_ERR_PARAM;
288 /* add bit to notify us if this is a set or clear operation */
290 vid |= FM10K_VLAN_CLEAR;
292 /* generate VLAN request */
293 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
294 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MAC, mac, vid);
296 /* load onto outgoing mailbox */
297 return mbx->ops.enqueue_tx(hw, mbx, msg);
301 * fm10k_update_mc_addr_vf - Update device multicast addresses
302 * @hw: pointer to the HW structure
304 * @mac: MAC address to add/remove from table
305 * @vid: VLAN ID to add/remove from table
306 * @add: Indicates if this is an add or remove operation
308 * This function is used to add or remove multicast MAC addresses for
311 static s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw, u16 glort,
312 const u8 *mac, u16 vid, bool add)
314 struct fm10k_mbx_info *mbx = &hw->mbx;
317 /* verify VLAN ID is valid */
318 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
319 return FM10K_ERR_PARAM;
321 /* verify multicast address is valid */
322 if (!is_multicast_ether_addr(mac))
323 return FM10K_ERR_PARAM;
325 /* add bit to notify us if this is a set or clear operation */
327 vid |= FM10K_VLAN_CLEAR;
329 /* generate VLAN request */
330 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
331 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MULTICAST,
334 /* load onto outgoing mailbox */
335 return mbx->ops.enqueue_tx(hw, mbx, msg);
339 * fm10k_update_int_moderator_vf - Request update of interrupt moderator list
340 * @hw: pointer to hardware structure
342 * This function will issue a request to the PF to rescan our MSI-X table
343 * and to update the interrupt moderator linked list.
345 static void fm10k_update_int_moderator_vf(struct fm10k_hw *hw)
347 struct fm10k_mbx_info *mbx = &hw->mbx;
350 /* generate MSI-X request */
351 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MSIX);
353 /* load onto outgoing mailbox */
354 mbx->ops.enqueue_tx(hw, mbx, msg);
357 /* This structure defines the attibutes to be parsed below */
358 const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
359 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_DISABLE),
360 FM10K_TLV_ATTR_U8(FM10K_LPORT_STATE_MSG_XCAST_MODE),
361 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_READY),
366 * fm10k_msg_lport_state_vf - Message handler for lport_state message from PF
367 * @hw: Pointer to hardware structure
368 * @results: pointer array containing parsed data
369 * @mbx: Pointer to mailbox information structure
371 * This handler is meant to capture the indication from the PF that we
372 * are ready to bring up the interface.
374 s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
375 struct fm10k_mbx_info *mbx)
377 hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
378 FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
384 * fm10k_update_lport_state_vf - Update device state in lower device
385 * @hw: pointer to the HW structure
387 * @count: number of logical ports to enable - unused (always 1)
388 * @enable: boolean value indicating if this is an enable or disable request
390 * Notify the lower device of a state change. If the lower device is
391 * enabled we can add filters, if it is disabled all filters for this
392 * logical port are flushed.
394 static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
395 u16 count, bool enable)
397 struct fm10k_mbx_info *mbx = &hw->mbx;
400 /* reset glort mask 0 as we have to wait to be enabled */
401 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
403 /* generate port state request */
404 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
406 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_DISABLE);
408 /* load onto outgoing mailbox */
409 return mbx->ops.enqueue_tx(hw, mbx, msg);
413 * fm10k_update_xcast_mode_vf - Request update of multicast mode
414 * @hw: pointer to hardware structure
416 * @mode: integer value indicating mode being requested
418 * This function will attempt to request a higher mode for the port
419 * so that it can enable either multicast, multicast promiscuous, or
420 * promiscuous mode of operation.
422 static s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw, u16 glort, u8 mode)
424 struct fm10k_mbx_info *mbx = &hw->mbx;
427 if (mode > FM10K_XCAST_MODE_NONE)
428 return FM10K_ERR_PARAM;
429 /* generate message requesting to change xcast mode */
430 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
431 fm10k_tlv_attr_put_u8(msg, FM10K_LPORT_STATE_MSG_XCAST_MODE, mode);
433 /* load onto outgoing mailbox */
434 return mbx->ops.enqueue_tx(hw, mbx, msg);
437 const struct fm10k_tlv_attr fm10k_1588_msg_attr[] = {
438 FM10K_TLV_ATTR_U64(FM10K_1588_MSG_TIMESTAMP),
442 /* currently there is no shared 1588 timestamp handler */
445 * fm10k_update_hw_stats_vf - Updates hardware related statistics of VF
446 * @hw: pointer to hardware structure
447 * @stats: pointer to statistics structure
449 * This function collects and aggregates per queue hardware statistics.
451 static void fm10k_update_hw_stats_vf(struct fm10k_hw *hw,
452 struct fm10k_hw_stats *stats)
454 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
458 * fm10k_rebind_hw_stats_vf - Resets base for hardware statistics of VF
459 * @hw: pointer to hardware structure
460 * @stats: pointer to the stats structure to update
462 * This function resets the base for queue hardware statistics.
464 static void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
465 struct fm10k_hw_stats *stats)
467 /* Unbind Queue Statistics */
468 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
470 /* Reinitialize bases for all stats */
471 fm10k_update_hw_stats_vf(hw, stats);
475 * fm10k_configure_dglort_map_vf - Configures GLORT entry and queues
476 * @hw: pointer to hardware structure
477 * @dglort: pointer to dglort configuration structure
479 * Reads the configuration structure contained in dglort_cfg and uses
480 * that information to then populate a DGLORTMAP/DEC entry and the queues
481 * to which it has been assigned.
483 static s32 fm10k_configure_dglort_map_vf(struct fm10k_hw *hw,
484 struct fm10k_dglort_cfg *dglort)
486 /* verify the dglort pointer */
488 return FM10K_ERR_PARAM;
490 /* stub for now until we determine correct message for this */
496 * fm10k_adjust_systime_vf - Adjust systime frequency
497 * @hw: pointer to hardware structure
498 * @ppb: adjustment rate in parts per billion
500 * This function takes an adjustment rate in parts per billion and will
501 * verify that this value is 0 as the VF cannot support adjusting the
504 * If the ppb value is non-zero the return is ERR_PARAM else success
506 static s32 fm10k_adjust_systime_vf(struct fm10k_hw *hw, s32 ppb)
508 /* The VF cannot adjust the clock frequency, however it should
509 * already have a syntonic clock with whichever host interface is
510 * running as the master for the host interface clock domain so
511 * there should be not frequency adjustment necessary.
513 return ppb ? FM10K_ERR_PARAM : 0;
517 * fm10k_read_systime_vf - Reads value of systime registers
518 * @hw: pointer to the hardware structure
520 * Function reads the content of 2 registers, combined to represent a 64 bit
521 * value measured in nanoseconds. In order to guarantee the value is accurate
522 * we check the 32 most significant bits both before and after reading the
523 * 32 least significant bits to verify they didn't change as we were reading
526 static u64 fm10k_read_systime_vf(struct fm10k_hw *hw)
528 u32 systime_l, systime_h, systime_tmp;
530 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
533 systime_tmp = systime_h;
534 systime_l = fm10k_read_reg(hw, FM10K_VFSYSTIME);
535 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
536 } while (systime_tmp != systime_h);
538 return ((u64)systime_h << 32) | systime_l;
541 static const struct fm10k_msg_data fm10k_msg_data_vf[] = {
542 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
543 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
544 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
545 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
548 static struct fm10k_mac_ops mac_ops_vf = {
549 .get_bus_info = &fm10k_get_bus_info_generic,
550 .reset_hw = &fm10k_reset_hw_vf,
551 .init_hw = &fm10k_init_hw_vf,
552 .start_hw = &fm10k_start_hw_generic,
553 .stop_hw = &fm10k_stop_hw_vf,
554 .update_vlan = &fm10k_update_vlan_vf,
555 .read_mac_addr = &fm10k_read_mac_addr_vf,
556 .update_uc_addr = &fm10k_update_uc_addr_vf,
557 .update_mc_addr = &fm10k_update_mc_addr_vf,
558 .update_xcast_mode = &fm10k_update_xcast_mode_vf,
559 .update_int_moderator = &fm10k_update_int_moderator_vf,
560 .update_lport_state = &fm10k_update_lport_state_vf,
561 .update_hw_stats = &fm10k_update_hw_stats_vf,
562 .rebind_hw_stats = &fm10k_rebind_hw_stats_vf,
563 .configure_dglort_map = &fm10k_configure_dglort_map_vf,
564 .get_host_state = &fm10k_get_host_state_generic,
565 .adjust_systime = &fm10k_adjust_systime_vf,
566 .read_systime = &fm10k_read_systime_vf,
569 static s32 fm10k_get_invariants_vf(struct fm10k_hw *hw)
571 fm10k_get_invariants_generic(hw);
573 return fm10k_pfvf_mbx_init(hw, &hw->mbx, fm10k_msg_data_vf, 0);
576 struct fm10k_info fm10k_vf_info = {
578 .get_invariants = &fm10k_get_invariants_vf,
579 .mac_ops = &mac_ops_vf,