1 /*******************************************************************************
3 Copyright (c) 2013 - 2015, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ***************************************************************************/
38 * fm10k_reset_hw_pf - PF hardware reset
39 * @hw: pointer to hardware structure
41 * This function should return the hardware to a state similar to the
42 * one it is in after being powered on.
44 STATIC s32 fm10k_reset_hw_pf(struct fm10k_hw *hw)
50 DEBUGFUNC("fm10k_reset_hw_pf");
52 /* Disable interrupts */
53 FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(ALL));
55 /* Lock ITR2 reg 0 into itself and disable interrupt moderation */
56 FM10K_WRITE_REG(hw, FM10K_ITR2(0), 0);
57 FM10K_WRITE_REG(hw, FM10K_INT_CTRL, 0);
59 /* We assume here Tx and Rx queue 0 are owned by the PF */
61 /* Shut off VF access to their queues forcing them to queue 0 */
62 for (i = 0; i < FM10K_TQMAP_TABLE_SIZE; i++) {
63 FM10K_WRITE_REG(hw, FM10K_TQMAP(i), 0);
64 FM10K_WRITE_REG(hw, FM10K_RQMAP(i), 0);
67 /* shut down all rings */
68 err = fm10k_disable_queues_generic(hw, FM10K_MAX_QUEUES);
69 if (err == FM10K_ERR_REQUESTS_PENDING) {
70 hw->mac.reset_while_pending++;
76 /* Verify that DMA is no longer active */
77 reg = FM10K_READ_REG(hw, FM10K_DMA_CTRL);
78 if (reg & (FM10K_DMA_CTRL_TX_ACTIVE | FM10K_DMA_CTRL_RX_ACTIVE))
79 return FM10K_ERR_DMA_PENDING;
82 /* Inititate data path reset */
83 reg = FM10K_DMA_CTRL_DATAPATH_RESET;
84 FM10K_WRITE_REG(hw, FM10K_DMA_CTRL, reg);
86 /* Flush write and allow 100us for reset to complete */
87 FM10K_WRITE_FLUSH(hw);
88 usec_delay(FM10K_RESET_TIMEOUT);
90 /* Verify we made it out of reset */
91 reg = FM10K_READ_REG(hw, FM10K_IP);
92 if (!(reg & FM10K_IP_NOTINRESET))
93 return FM10K_ERR_RESET_FAILED;
99 * fm10k_is_ari_hierarchy_pf - Indicate ARI hierarchy support
100 * @hw: pointer to hardware structure
102 * Looks at the ARI hierarchy bit to determine whether ARI is supported or not.
104 STATIC bool fm10k_is_ari_hierarchy_pf(struct fm10k_hw *hw)
106 u16 sriov_ctrl = FM10K_READ_PCI_WORD(hw, FM10K_PCIE_SRIOV_CTRL);
108 DEBUGFUNC("fm10k_is_ari_hierarchy_pf");
110 return !!(sriov_ctrl & FM10K_PCIE_SRIOV_CTRL_VFARI);
114 * fm10k_init_hw_pf - PF hardware initialization
115 * @hw: pointer to hardware structure
118 STATIC s32 fm10k_init_hw_pf(struct fm10k_hw *hw)
120 u32 dma_ctrl, txqctl;
123 DEBUGFUNC("fm10k_init_hw_pf");
125 /* Establish default VSI as valid */
126 FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(fm10k_dglort_default), 0);
127 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(fm10k_dglort_default),
128 FM10K_DGLORTMAP_ANY);
130 /* Invalidate all other GLORT entries */
131 for (i = 1; i < FM10K_DGLORT_COUNT; i++)
132 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(i), FM10K_DGLORTMAP_NONE);
134 /* reset ITR2(0) to point to itself */
135 FM10K_WRITE_REG(hw, FM10K_ITR2(0), 0);
137 /* reset VF ITR2(0) to point to 0 avoid PF registers */
138 FM10K_WRITE_REG(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), 0);
140 /* loop through all PF ITR2 registers pointing them to the previous */
141 for (i = 1; i < FM10K_ITR_REG_COUNT_PF; i++)
142 FM10K_WRITE_REG(hw, FM10K_ITR2(i), i - 1);
144 /* Enable interrupt moderator if not already enabled */
145 FM10K_WRITE_REG(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR);
147 /* compute the default txqctl configuration */
148 txqctl = FM10K_TXQCTL_PF | FM10K_TXQCTL_UNLIMITED_BW |
149 (hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT);
151 for (i = 0; i < FM10K_MAX_QUEUES; i++) {
152 /* configure rings for 256 Queue / 32 Descriptor cache mode */
153 FM10K_WRITE_REG(hw, FM10K_TQDLOC(i),
154 (i * FM10K_TQDLOC_BASE_32_DESC) |
155 FM10K_TQDLOC_SIZE_32_DESC);
156 FM10K_WRITE_REG(hw, FM10K_TXQCTL(i), txqctl);
158 /* configure rings to provide TPH processing hints */
159 FM10K_WRITE_REG(hw, FM10K_TPH_TXCTRL(i),
160 FM10K_TPH_TXCTRL_DESC_TPHEN |
161 FM10K_TPH_TXCTRL_DESC_RROEN |
162 FM10K_TPH_TXCTRL_DESC_WROEN |
163 FM10K_TPH_TXCTRL_DATA_RROEN);
164 FM10K_WRITE_REG(hw, FM10K_TPH_RXCTRL(i),
165 FM10K_TPH_RXCTRL_DESC_TPHEN |
166 FM10K_TPH_RXCTRL_DESC_RROEN |
167 FM10K_TPH_RXCTRL_DATA_WROEN |
168 FM10K_TPH_RXCTRL_HDR_WROEN);
171 /* set max hold interval to align with 1.024 usec in all modes and
174 switch (hw->bus.speed) {
175 case fm10k_bus_speed_2500:
176 dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN1;
177 hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN1;
179 case fm10k_bus_speed_5000:
180 dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN2;
181 hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN2;
183 case fm10k_bus_speed_8000:
184 dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN3;
185 hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN3;
189 /* just in case, assume Gen3 ITR scale */
190 hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN3;
194 /* Configure TSO flags */
195 FM10K_WRITE_REG(hw, FM10K_DTXTCPFLGL, FM10K_TSO_FLAGS_LOW);
196 FM10K_WRITE_REG(hw, FM10K_DTXTCPFLGH, FM10K_TSO_FLAGS_HI);
199 * Set Rx Descriptor size to 32
200 * Set Minimum MSS to 64
201 * Set Maximum number of Rx queues to 256 / 32 Descriptor
203 dma_ctrl |= FM10K_DMA_CTRL_TX_ENABLE | FM10K_DMA_CTRL_RX_ENABLE |
204 FM10K_DMA_CTRL_RX_DESC_SIZE | FM10K_DMA_CTRL_MINMSS_64 |
205 FM10K_DMA_CTRL_32_DESC;
207 FM10K_WRITE_REG(hw, FM10K_DMA_CTRL, dma_ctrl);
209 /* record maximum queue count, we limit ourselves to 128 */
210 hw->mac.max_queues = FM10K_MAX_QUEUES_PF;
212 /* We support either 64 VFs or 7 VFs depending on if we have ARI */
213 hw->iov.total_vfs = fm10k_is_ari_hierarchy_pf(hw) ? 64 : 7;
215 return FM10K_SUCCESS;
218 #ifndef NO_IS_SLOT_APPROPRIATE_CHECK
220 * fm10k_is_slot_appropriate_pf - Indicate appropriate slot for this SKU
221 * @hw: pointer to hardware structure
223 * Looks at the PCIe bus info to confirm whether or not this slot can support
224 * the necessary bandwidth for this device.
226 STATIC bool fm10k_is_slot_appropriate_pf(struct fm10k_hw *hw)
228 DEBUGFUNC("fm10k_is_slot_appropriate_pf");
230 return (hw->bus.speed == hw->bus_caps.speed) &&
231 (hw->bus.width == hw->bus_caps.width);
236 * fm10k_update_vlan_pf - Update status of VLAN ID in VLAN filter table
237 * @hw: pointer to hardware structure
238 * @vid: VLAN ID to add to table
239 * @vsi: Index indicating VF ID or PF ID in table
240 * @set: Indicates if this is a set or clear operation
242 * This function adds or removes the corresponding VLAN ID from the VLAN
243 * filter table for the corresponding function. In addition to the
244 * standard set/clear that supports one bit a multi-bit write is
245 * supported to set 64 bits at a time.
247 STATIC s32 fm10k_update_vlan_pf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
249 u32 vlan_table, reg, mask, bit, len;
251 /* verify the VSI index is valid */
252 if (vsi > FM10K_VLAN_TABLE_VSI_MAX)
253 return FM10K_ERR_PARAM;
255 /* VLAN multi-bit write:
256 * The multi-bit write has several parts to it.
258 * 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
259 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
260 * | RSVD0 | Length |C|RSVD0| VLAN ID |
261 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
263 * VLAN ID: Vlan Starting value
264 * RSVD0: Reserved section, must be 0
265 * C: Flag field, 0 is set, 1 is clear (Used in VF VLAN message)
266 * Length: Number of times to repeat the bit being set
269 vid = (vid << 17) >> 17;
271 /* verify the reserved 0 fields are 0 */
272 if (len >= FM10K_VLAN_TABLE_VID_MAX || vid >= FM10K_VLAN_TABLE_VID_MAX)
273 return FM10K_ERR_PARAM;
275 /* Loop through the table updating all required VLANs */
276 for (reg = FM10K_VLAN_TABLE(vsi, vid / 32), bit = vid % 32;
277 len < FM10K_VLAN_TABLE_VID_MAX;
278 len -= 32 - bit, reg++, bit = 0) {
279 /* record the initial state of the register */
280 vlan_table = FM10K_READ_REG(hw, reg);
282 /* truncate mask if we are at the start or end of the run */
283 mask = (~(u32)0 >> ((len < 31) ? 31 - len : 0)) << bit;
285 /* make necessary modifications to the register */
286 mask &= set ? ~vlan_table : vlan_table;
288 FM10K_WRITE_REG(hw, reg, vlan_table ^ mask);
291 return FM10K_SUCCESS;
295 * fm10k_read_mac_addr_pf - Read device MAC address
296 * @hw: pointer to the HW structure
298 * Reads the device MAC address from the SM_AREA and stores the value.
300 STATIC s32 fm10k_read_mac_addr_pf(struct fm10k_hw *hw)
302 u8 perm_addr[ETH_ALEN];
305 DEBUGFUNC("fm10k_read_mac_addr_pf");
307 serial_num = FM10K_READ_REG(hw, FM10K_SM_AREA(1));
309 /* last byte should be all 1's */
310 if ((~serial_num) << 24)
311 return FM10K_ERR_INVALID_MAC_ADDR;
313 perm_addr[0] = (u8)(serial_num >> 24);
314 perm_addr[1] = (u8)(serial_num >> 16);
315 perm_addr[2] = (u8)(serial_num >> 8);
317 serial_num = FM10K_READ_REG(hw, FM10K_SM_AREA(0));
319 /* first byte should be all 1's */
320 if ((~serial_num) >> 24)
321 return FM10K_ERR_INVALID_MAC_ADDR;
323 perm_addr[3] = (u8)(serial_num >> 16);
324 perm_addr[4] = (u8)(serial_num >> 8);
325 perm_addr[5] = (u8)(serial_num);
327 memcpy(hw->mac.perm_addr, perm_addr, ETH_ALEN);
328 memcpy(hw->mac.addr, perm_addr, ETH_ALEN);
330 return FM10K_SUCCESS;
334 * fm10k_glort_valid_pf - Validate that the provided glort is valid
335 * @hw: pointer to the HW structure
336 * @glort: base glort to be validated
338 * This function will return an error if the provided glort is invalid
340 bool fm10k_glort_valid_pf(struct fm10k_hw *hw, u16 glort)
342 glort &= hw->mac.dglort_map >> FM10K_DGLORTMAP_MASK_SHIFT;
344 return glort == (hw->mac.dglort_map & FM10K_DGLORTMAP_NONE);
348 * fm10k_update_xc_addr_pf - Update device addresses
349 * @hw: pointer to the HW structure
350 * @glort: base resource tag for this request
351 * @mac: MAC address to add/remove from table
352 * @vid: VLAN ID to add/remove from table
353 * @add: Indicates if this is an add or remove operation
354 * @flags: flags field to indicate add and secure
356 * This function generates a message to the Switch API requesting
357 * that the given logical port add/remove the given L2 MAC/VLAN address.
359 STATIC s32 fm10k_update_xc_addr_pf(struct fm10k_hw *hw, u16 glort,
360 const u8 *mac, u16 vid, bool add, u8 flags)
362 struct fm10k_mbx_info *mbx = &hw->mbx;
363 struct fm10k_mac_update mac_update;
366 DEBUGFUNC("fm10k_update_xc_addr_pf");
368 /* clear set bit from VLAN ID */
369 vid &= ~FM10K_VLAN_CLEAR;
371 /* if glort or VLAN are not valid return error */
372 if (!fm10k_glort_valid_pf(hw, glort) || vid >= FM10K_VLAN_TABLE_VID_MAX)
373 return FM10K_ERR_PARAM;
376 mac_update.mac_lower = FM10K_CPU_TO_LE32(((u32)mac[2] << 24) |
377 ((u32)mac[3] << 16) |
380 mac_update.mac_upper = FM10K_CPU_TO_LE16(((u16)mac[0] << 8) |
382 mac_update.vlan = FM10K_CPU_TO_LE16(vid);
383 mac_update.glort = FM10K_CPU_TO_LE16(glort);
384 mac_update.action = add ? 0 : 1;
385 mac_update.flags = flags;
387 /* populate mac_update fields */
388 fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_UPDATE_MAC_FWD_RULE);
389 fm10k_tlv_attr_put_le_struct(msg, FM10K_PF_ATTR_ID_MAC_UPDATE,
390 &mac_update, sizeof(mac_update));
392 /* load onto outgoing mailbox */
393 return mbx->ops.enqueue_tx(hw, mbx, msg);
397 * fm10k_update_uc_addr_pf - Update device unicast addresses
398 * @hw: pointer to the HW structure
399 * @glort: base resource tag for this request
400 * @mac: MAC address to add/remove from table
401 * @vid: VLAN ID to add/remove from table
402 * @add: Indicates if this is an add or remove operation
403 * @flags: flags field to indicate add and secure
405 * This function is used to add or remove unicast addresses for
408 STATIC s32 fm10k_update_uc_addr_pf(struct fm10k_hw *hw, u16 glort,
409 const u8 *mac, u16 vid, bool add, u8 flags)
411 DEBUGFUNC("fm10k_update_uc_addr_pf");
413 /* verify MAC address is valid */
414 if (!FM10K_IS_VALID_ETHER_ADDR(mac))
415 return FM10K_ERR_PARAM;
417 return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, flags);
421 * fm10k_update_mc_addr_pf - Update device multicast addresses
422 * @hw: pointer to the HW structure
423 * @glort: base resource tag for this request
424 * @mac: MAC address to add/remove from table
425 * @vid: VLAN ID to add/remove from table
426 * @add: Indicates if this is an add or remove operation
428 * This function is used to add or remove multicast MAC addresses for
431 STATIC s32 fm10k_update_mc_addr_pf(struct fm10k_hw *hw, u16 glort,
432 const u8 *mac, u16 vid, bool add)
434 DEBUGFUNC("fm10k_update_mc_addr_pf");
436 /* verify multicast address is valid */
437 if (!FM10K_IS_MULTICAST_ETHER_ADDR(mac))
438 return FM10K_ERR_PARAM;
440 return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, 0);
444 * fm10k_update_xcast_mode_pf - Request update of multicast mode
445 * @hw: pointer to hardware structure
446 * @glort: base resource tag for this request
447 * @mode: integer value indicating mode being requested
449 * This function will attempt to request a higher mode for the port
450 * so that it can enable either multicast, multicast promiscuous, or
451 * promiscuous mode of operation.
453 STATIC s32 fm10k_update_xcast_mode_pf(struct fm10k_hw *hw, u16 glort, u8 mode)
455 struct fm10k_mbx_info *mbx = &hw->mbx;
456 u32 msg[3], xcast_mode;
458 DEBUGFUNC("fm10k_update_xcast_mode_pf");
460 if (mode > FM10K_XCAST_MODE_NONE)
461 return FM10K_ERR_PARAM;
463 /* if glort is not valid return error */
464 if (!fm10k_glort_valid_pf(hw, glort))
465 return FM10K_ERR_PARAM;
467 /* write xcast mode as a single u32 value,
468 * lower 16 bits: glort
469 * upper 16 bits: mode
471 xcast_mode = ((u32)mode << 16) | glort;
473 /* generate message requesting to change xcast mode */
474 fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_XCAST_MODES);
475 fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_XCAST_MODE, xcast_mode);
477 /* load onto outgoing mailbox */
478 return mbx->ops.enqueue_tx(hw, mbx, msg);
482 * fm10k_update_int_moderator_pf - Update interrupt moderator linked list
483 * @hw: pointer to hardware structure
485 * This function walks through the MSI-X vector table to determine the
486 * number of active interrupts and based on that information updates the
487 * interrupt moderator linked list.
489 STATIC void fm10k_update_int_moderator_pf(struct fm10k_hw *hw)
493 /* Disable interrupt moderator */
494 FM10K_WRITE_REG(hw, FM10K_INT_CTRL, 0);
496 /* loop through PF from last to first looking enabled vectors */
497 for (i = FM10K_ITR_REG_COUNT_PF - 1; i; i--) {
498 if (!FM10K_READ_REG(hw, FM10K_MSIX_VECTOR_MASK(i)))
502 /* always reset VFITR2[0] to point to last enabled PF vector */
503 FM10K_WRITE_REG(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), i);
505 /* reset ITR2[0] to point to last enabled PF vector */
506 if (!hw->iov.num_vfs)
507 FM10K_WRITE_REG(hw, FM10K_ITR2(0), i);
509 /* Enable interrupt moderator */
510 FM10K_WRITE_REG(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR);
514 * fm10k_update_lport_state_pf - Notify the switch of a change in port state
515 * @hw: pointer to the HW structure
516 * @glort: base resource tag for this request
517 * @count: number of logical ports being updated
518 * @enable: boolean value indicating enable or disable
520 * This function is used to add/remove a logical port from the switch.
522 STATIC s32 fm10k_update_lport_state_pf(struct fm10k_hw *hw, u16 glort,
523 u16 count, bool enable)
525 struct fm10k_mbx_info *mbx = &hw->mbx;
526 u32 msg[3], lport_msg;
528 DEBUGFUNC("fm10k_lport_state_pf");
530 /* do nothing if we are being asked to create or destroy 0 ports */
532 return FM10K_SUCCESS;
534 /* if glort is not valid return error */
535 if (!fm10k_glort_valid_pf(hw, glort))
536 return FM10K_ERR_PARAM;
538 /* reset multicast mode if deleting lport */
540 fm10k_update_xcast_mode_pf(hw, glort, FM10K_XCAST_MODE_NONE);
542 /* construct the lport message from the 2 pieces of data we have */
543 lport_msg = ((u32)count << 16) | glort;
545 /* generate lport create/delete message */
546 fm10k_tlv_msg_init(msg, enable ? FM10K_PF_MSG_ID_LPORT_CREATE :
547 FM10K_PF_MSG_ID_LPORT_DELETE);
548 fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_PORT, lport_msg);
550 /* load onto outgoing mailbox */
551 return mbx->ops.enqueue_tx(hw, mbx, msg);
555 * fm10k_configure_dglort_map_pf - Configures GLORT entry and queues
556 * @hw: pointer to hardware structure
557 * @dglort: pointer to dglort configuration structure
559 * Reads the configuration structure contained in dglort_cfg and uses
560 * that information to then populate a DGLORTMAP/DEC entry and the queues
561 * to which it has been assigned.
563 STATIC s32 fm10k_configure_dglort_map_pf(struct fm10k_hw *hw,
564 struct fm10k_dglort_cfg *dglort)
566 u16 glort, queue_count, vsi_count, pc_count;
567 u16 vsi, queue, pc, q_idx;
568 u32 txqctl, dglortdec, dglortmap;
570 /* verify the dglort pointer */
572 return FM10K_ERR_PARAM;
574 /* verify the dglort values */
575 if ((dglort->idx > 7) || (dglort->rss_l > 7) || (dglort->pc_l > 3) ||
576 (dglort->vsi_l > 6) || (dglort->vsi_b > 64) ||
577 (dglort->queue_l > 8) || (dglort->queue_b >= 256))
578 return FM10K_ERR_PARAM;
580 /* determine count of VSIs and queues */
581 queue_count = BIT(dglort->rss_l + dglort->pc_l);
582 vsi_count = BIT(dglort->vsi_l + dglort->queue_l);
583 glort = dglort->glort;
584 q_idx = dglort->queue_b;
586 /* configure SGLORT for queues */
587 for (vsi = 0; vsi < vsi_count; vsi++, glort++) {
588 for (queue = 0; queue < queue_count; queue++, q_idx++) {
589 if (q_idx >= FM10K_MAX_QUEUES)
592 FM10K_WRITE_REG(hw, FM10K_TX_SGLORT(q_idx), glort);
593 FM10K_WRITE_REG(hw, FM10K_RX_SGLORT(q_idx), glort);
597 /* determine count of PCs and queues */
598 queue_count = BIT(dglort->queue_l + dglort->rss_l + dglort->vsi_l);
599 pc_count = BIT(dglort->pc_l);
601 /* configure PC for Tx queues */
602 for (pc = 0; pc < pc_count; pc++) {
603 q_idx = pc + dglort->queue_b;
604 for (queue = 0; queue < queue_count; queue++) {
605 if (q_idx >= FM10K_MAX_QUEUES)
608 txqctl = FM10K_READ_REG(hw, FM10K_TXQCTL(q_idx));
609 txqctl &= ~FM10K_TXQCTL_PC_MASK;
610 txqctl |= pc << FM10K_TXQCTL_PC_SHIFT;
611 FM10K_WRITE_REG(hw, FM10K_TXQCTL(q_idx), txqctl);
617 /* configure DGLORTDEC */
618 dglortdec = ((u32)(dglort->rss_l) << FM10K_DGLORTDEC_RSSLENGTH_SHIFT) |
619 ((u32)(dglort->queue_b) << FM10K_DGLORTDEC_QBASE_SHIFT) |
620 ((u32)(dglort->pc_l) << FM10K_DGLORTDEC_PCLENGTH_SHIFT) |
621 ((u32)(dglort->vsi_b) << FM10K_DGLORTDEC_VSIBASE_SHIFT) |
622 ((u32)(dglort->vsi_l) << FM10K_DGLORTDEC_VSILENGTH_SHIFT) |
623 ((u32)(dglort->queue_l));
624 if (dglort->inner_rss)
625 dglortdec |= FM10K_DGLORTDEC_INNERRSS_ENABLE;
627 /* configure DGLORTMAP */
628 dglortmap = (dglort->idx == fm10k_dglort_default) ?
629 FM10K_DGLORTMAP_ANY : FM10K_DGLORTMAP_ZERO;
630 dglortmap <<= dglort->vsi_l + dglort->queue_l + dglort->shared_l;
631 dglortmap |= dglort->glort;
633 /* write values to hardware */
634 FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(dglort->idx), dglortdec);
635 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(dglort->idx), dglortmap);
637 return FM10K_SUCCESS;
640 u16 fm10k_queues_per_pool(struct fm10k_hw *hw)
642 u16 num_pools = hw->iov.num_pools;
644 return (num_pools > 32) ? 2 : (num_pools > 16) ? 4 : (num_pools > 8) ?
645 8 : FM10K_MAX_QUEUES_POOL;
648 u16 fm10k_vf_queue_index(struct fm10k_hw *hw, u16 vf_idx)
650 u16 num_vfs = hw->iov.num_vfs;
651 u16 vf_q_idx = FM10K_MAX_QUEUES;
653 vf_q_idx -= fm10k_queues_per_pool(hw) * (num_vfs - vf_idx);
658 STATIC u16 fm10k_vectors_per_pool(struct fm10k_hw *hw)
660 u16 num_pools = hw->iov.num_pools;
662 return (num_pools > 32) ? 8 : (num_pools > 16) ? 16 :
663 FM10K_MAX_VECTORS_POOL;
666 STATIC u16 fm10k_vf_vector_index(struct fm10k_hw *hw, u16 vf_idx)
668 u16 vf_v_idx = FM10K_MAX_VECTORS_PF;
670 vf_v_idx += fm10k_vectors_per_pool(hw) * vf_idx;
676 * fm10k_iov_assign_resources_pf - Assign pool resources for virtualization
677 * @hw: pointer to the HW structure
678 * @num_vfs: number of VFs to be allocated
679 * @num_pools: number of virtualization pools to be allocated
681 * Allocates queues and traffic classes to virtualization entities to prepare
682 * the PF for SR-IOV and VMDq
684 STATIC s32 fm10k_iov_assign_resources_pf(struct fm10k_hw *hw, u16 num_vfs,
687 u16 qmap_stride, qpp, vpp, vf_q_idx, vf_q_idx0, qmap_idx;
688 u32 vid = hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT;
691 /* hardware only supports up to 64 pools */
693 return FM10K_ERR_PARAM;
695 /* the number of VFs cannot exceed the number of pools */
696 if ((num_vfs > num_pools) || (num_vfs > hw->iov.total_vfs))
697 return FM10K_ERR_PARAM;
699 /* record number of virtualization entities */
700 hw->iov.num_vfs = num_vfs;
701 hw->iov.num_pools = num_pools;
703 /* determine qmap offsets and counts */
704 qmap_stride = (num_vfs > 8) ? 32 : 256;
705 qpp = fm10k_queues_per_pool(hw);
706 vpp = fm10k_vectors_per_pool(hw);
708 /* calculate starting index for queues */
709 vf_q_idx = fm10k_vf_queue_index(hw, 0);
712 /* establish TCs with -1 credits and no quanta to prevent transmit */
713 for (i = 0; i < num_vfs; i++) {
714 FM10K_WRITE_REG(hw, FM10K_TC_MAXCREDIT(i), 0);
715 FM10K_WRITE_REG(hw, FM10K_TC_RATE(i), 0);
716 FM10K_WRITE_REG(hw, FM10K_TC_CREDIT(i),
717 FM10K_TC_CREDIT_CREDIT_MASK);
720 /* zero out all mbmem registers */
721 for (i = FM10K_VFMBMEM_LEN * num_vfs; i--;)
722 FM10K_WRITE_REG(hw, FM10K_MBMEM(i), 0);
724 /* clear event notification of VF FLR */
725 FM10K_WRITE_REG(hw, FM10K_PFVFLREC(0), ~0);
726 FM10K_WRITE_REG(hw, FM10K_PFVFLREC(1), ~0);
728 /* loop through unallocated rings assigning them back to PF */
729 for (i = FM10K_MAX_QUEUES_PF; i < vf_q_idx; i++) {
730 FM10K_WRITE_REG(hw, FM10K_TXDCTL(i), 0);
731 FM10K_WRITE_REG(hw, FM10K_TXQCTL(i), FM10K_TXQCTL_PF |
732 FM10K_TXQCTL_UNLIMITED_BW | vid);
733 FM10K_WRITE_REG(hw, FM10K_RXQCTL(i), FM10K_RXQCTL_PF);
736 /* PF should have already updated VFITR2[0] */
738 /* update all ITR registers to flow to VFITR2[0] */
739 for (i = FM10K_ITR_REG_COUNT_PF + 1; i < FM10K_ITR_REG_COUNT; i++) {
740 if (!(i & (vpp - 1)))
741 FM10K_WRITE_REG(hw, FM10K_ITR2(i), i - vpp);
743 FM10K_WRITE_REG(hw, FM10K_ITR2(i), i - 1);
746 /* update PF ITR2[0] to reference the last vector */
747 FM10K_WRITE_REG(hw, FM10K_ITR2(0),
748 fm10k_vf_vector_index(hw, num_vfs - 1));
750 /* loop through rings populating rings and TCs */
751 for (i = 0; i < num_vfs; i++) {
752 /* record index for VF queue 0 for use in end of loop */
753 vf_q_idx0 = vf_q_idx;
755 for (j = 0; j < qpp; j++, qmap_idx++, vf_q_idx++) {
756 /* assign VF and locked TC to queues */
757 FM10K_WRITE_REG(hw, FM10K_TXDCTL(vf_q_idx), 0);
758 FM10K_WRITE_REG(hw, FM10K_TXQCTL(vf_q_idx),
759 (i << FM10K_TXQCTL_TC_SHIFT) | i |
760 FM10K_TXQCTL_VF | vid);
761 FM10K_WRITE_REG(hw, FM10K_RXDCTL(vf_q_idx),
762 FM10K_RXDCTL_WRITE_BACK_MIN_DELAY |
763 FM10K_RXDCTL_DROP_ON_EMPTY);
764 FM10K_WRITE_REG(hw, FM10K_RXQCTL(vf_q_idx),
765 (i << FM10K_RXQCTL_VF_SHIFT) |
768 /* map queue pair to VF */
769 FM10K_WRITE_REG(hw, FM10K_TQMAP(qmap_idx), vf_q_idx);
770 FM10K_WRITE_REG(hw, FM10K_RQMAP(qmap_idx), vf_q_idx);
773 /* repeat the first ring for all of the remaining VF rings */
774 for (; j < qmap_stride; j++, qmap_idx++) {
775 FM10K_WRITE_REG(hw, FM10K_TQMAP(qmap_idx), vf_q_idx0);
776 FM10K_WRITE_REG(hw, FM10K_RQMAP(qmap_idx), vf_q_idx0);
780 /* loop through remaining indexes assigning all to queue 0 */
781 while (qmap_idx < FM10K_TQMAP_TABLE_SIZE) {
782 FM10K_WRITE_REG(hw, FM10K_TQMAP(qmap_idx), 0);
783 FM10K_WRITE_REG(hw, FM10K_RQMAP(qmap_idx), 0);
787 return FM10K_SUCCESS;
791 * fm10k_iov_configure_tc_pf - Configure the shaping group for VF
792 * @hw: pointer to the HW structure
793 * @vf_idx: index of VF receiving GLORT
794 * @rate: Rate indicated in Mb/s
796 * Configured the TC for a given VF to allow only up to a given number
797 * of Mb/s of outgoing Tx throughput.
799 STATIC s32 fm10k_iov_configure_tc_pf(struct fm10k_hw *hw, u16 vf_idx, int rate)
801 /* configure defaults */
802 u32 interval = FM10K_TC_RATE_INTERVAL_4US_GEN3;
803 u32 tc_rate = FM10K_TC_RATE_QUANTA_MASK;
805 /* verify vf is in range */
806 if (vf_idx >= hw->iov.num_vfs)
807 return FM10K_ERR_PARAM;
809 /* set interval to align with 4.096 usec in all modes */
810 switch (hw->bus.speed) {
811 case fm10k_bus_speed_2500:
812 interval = FM10K_TC_RATE_INTERVAL_4US_GEN1;
814 case fm10k_bus_speed_5000:
815 interval = FM10K_TC_RATE_INTERVAL_4US_GEN2;
822 if (rate > FM10K_VF_TC_MAX || rate < FM10K_VF_TC_MIN)
823 return FM10K_ERR_PARAM;
825 /* The quanta is measured in Bytes per 4.096 or 8.192 usec
826 * The rate is provided in Mbits per second
827 * To tralslate from rate to quanta we need to multiply the
828 * rate by 8.192 usec and divide by 8 bits/byte. To avoid
829 * dealing with floating point we can round the values up
830 * to the nearest whole number ratio which gives us 128 / 125.
832 tc_rate = (rate * 128) / 125;
834 /* try to keep the rate limiting accurate by increasing
835 * the number of credits and interval for rates less than 4Gb/s
843 /* update rate limiter with new values */
844 FM10K_WRITE_REG(hw, FM10K_TC_RATE(vf_idx), tc_rate | interval);
845 FM10K_WRITE_REG(hw, FM10K_TC_MAXCREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K);
846 FM10K_WRITE_REG(hw, FM10K_TC_CREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K);
848 return FM10K_SUCCESS;
852 * fm10k_iov_assign_int_moderator_pf - Add VF interrupts to moderator list
853 * @hw: pointer to the HW structure
854 * @vf_idx: index of VF receiving GLORT
856 * Update the interrupt moderator linked list to include any MSI-X
857 * interrupts which the VF has enabled in the MSI-X vector table.
859 STATIC s32 fm10k_iov_assign_int_moderator_pf(struct fm10k_hw *hw, u16 vf_idx)
861 u16 vf_v_idx, vf_v_limit, i;
863 /* verify vf is in range */
864 if (vf_idx >= hw->iov.num_vfs)
865 return FM10K_ERR_PARAM;
867 /* determine vector offset and count */
868 vf_v_idx = fm10k_vf_vector_index(hw, vf_idx);
869 vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw);
871 /* search for first vector that is not masked */
872 for (i = vf_v_limit - 1; i > vf_v_idx; i--) {
873 if (!FM10K_READ_REG(hw, FM10K_MSIX_VECTOR_MASK(i)))
877 /* reset linked list so it now includes our active vectors */
878 if (vf_idx == (hw->iov.num_vfs - 1))
879 FM10K_WRITE_REG(hw, FM10K_ITR2(0), i);
881 FM10K_WRITE_REG(hw, FM10K_ITR2(vf_v_limit), i);
883 return FM10K_SUCCESS;
887 * fm10k_iov_assign_default_mac_vlan_pf - Assign a MAC and VLAN to VF
888 * @hw: pointer to the HW structure
889 * @vf_info: pointer to VF information structure
891 * Assign a MAC address and default VLAN to a VF and notify it of the update
893 STATIC s32 fm10k_iov_assign_default_mac_vlan_pf(struct fm10k_hw *hw,
894 struct fm10k_vf_info *vf_info)
896 u16 qmap_stride, queues_per_pool, vf_q_idx, timeout, qmap_idx, i;
897 u32 msg[4], txdctl, txqctl, tdbal = 0, tdbah = 0;
898 s32 err = FM10K_SUCCESS;
901 /* verify vf is in range */
902 if (!vf_info || vf_info->vf_idx >= hw->iov.num_vfs)
903 return FM10K_ERR_PARAM;
905 /* determine qmap offsets and counts */
906 qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256;
907 queues_per_pool = fm10k_queues_per_pool(hw);
909 /* calculate starting index for queues */
910 vf_idx = vf_info->vf_idx;
911 vf_q_idx = fm10k_vf_queue_index(hw, vf_idx);
912 qmap_idx = qmap_stride * vf_idx;
914 /* Determine correct default VLAN ID. The FM10K_VLAN_OVERRIDE bit is
915 * used here to indicate to the VF that it will not have privilege to
916 * write VLAN_TABLE. All policy is enforced on the PF but this allows
917 * the VF to correctly report errors to userspace rqeuests.
920 vf_vid = vf_info->pf_vid | FM10K_VLAN_OVERRIDE;
922 vf_vid = vf_info->sw_vid;
924 /* generate MAC_ADDR request */
925 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
926 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_DEFAULT_MAC,
927 vf_info->mac, vf_vid);
929 /* load onto outgoing mailbox, ignore any errors on enqueue */
930 if (vf_info->mbx.ops.enqueue_tx)
931 vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
933 /* verify ring has disabled before modifying base address registers */
934 txdctl = FM10K_READ_REG(hw, FM10K_TXDCTL(vf_q_idx));
935 for (timeout = 0; txdctl & FM10K_TXDCTL_ENABLE; timeout++) {
936 /* limit ourselves to a 1ms timeout */
938 err = FM10K_ERR_DMA_PENDING;
943 txdctl = FM10K_READ_REG(hw, FM10K_TXDCTL(vf_q_idx));
946 /* Update base address registers to contain MAC address */
947 if (FM10K_IS_VALID_ETHER_ADDR(vf_info->mac)) {
948 tdbal = (((u32)vf_info->mac[3]) << 24) |
949 (((u32)vf_info->mac[4]) << 16) |
950 (((u32)vf_info->mac[5]) << 8);
952 tdbah = (((u32)0xFF) << 24) |
953 (((u32)vf_info->mac[0]) << 16) |
954 (((u32)vf_info->mac[1]) << 8) |
955 ((u32)vf_info->mac[2]);
958 /* Record the base address into queue 0 */
959 FM10K_WRITE_REG(hw, FM10K_TDBAL(vf_q_idx), tdbal);
960 FM10K_WRITE_REG(hw, FM10K_TDBAH(vf_q_idx), tdbah);
962 /* Provide the VF the ITR scale, using software-defined fields in TDLEN
963 * to pass the information during VF initialization. See definition of
964 * FM10K_TDLEN_ITR_SCALE_SHIFT for more details.
966 FM10K_WRITE_REG(hw, FM10K_TDLEN(vf_q_idx), hw->mac.itr_scale <<
967 FM10K_TDLEN_ITR_SCALE_SHIFT);
970 /* configure Queue control register */
971 txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) &
972 FM10K_TXQCTL_VID_MASK;
973 txqctl |= (vf_idx << FM10K_TXQCTL_TC_SHIFT) |
974 FM10K_TXQCTL_VF | vf_idx;
977 for (i = 0; i < queues_per_pool; i++)
978 FM10K_WRITE_REG(hw, FM10K_TXQCTL(vf_q_idx + i), txqctl);
980 /* restore the queue back to VF ownership */
981 FM10K_WRITE_REG(hw, FM10K_TQMAP(qmap_idx), vf_q_idx);
986 * fm10k_iov_reset_resources_pf - Reassign queues and interrupts to a VF
987 * @hw: pointer to the HW structure
988 * @vf_info: pointer to VF information structure
990 * Reassign the interrupts and queues to a VF following an FLR
992 STATIC s32 fm10k_iov_reset_resources_pf(struct fm10k_hw *hw,
993 struct fm10k_vf_info *vf_info)
995 u16 qmap_stride, queues_per_pool, vf_q_idx, qmap_idx;
996 u32 tdbal = 0, tdbah = 0, txqctl, rxqctl;
997 u16 vf_v_idx, vf_v_limit, vf_vid;
998 u8 vf_idx = vf_info->vf_idx;
1001 /* verify vf is in range */
1002 if (vf_idx >= hw->iov.num_vfs)
1003 return FM10K_ERR_PARAM;
1005 /* clear event notification of VF FLR */
1006 FM10K_WRITE_REG(hw, FM10K_PFVFLREC(vf_idx / 32), BIT(vf_idx % 32));
1008 /* force timeout and then disconnect the mailbox */
1009 vf_info->mbx.timeout = 0;
1010 if (vf_info->mbx.ops.disconnect)
1011 vf_info->mbx.ops.disconnect(hw, &vf_info->mbx);
1013 /* determine vector offset and count */
1014 vf_v_idx = fm10k_vf_vector_index(hw, vf_idx);
1015 vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw);
1017 /* determine qmap offsets and counts */
1018 qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256;
1019 queues_per_pool = fm10k_queues_per_pool(hw);
1020 qmap_idx = qmap_stride * vf_idx;
1022 /* make all the queues inaccessible to the VF */
1023 for (i = qmap_idx; i < (qmap_idx + qmap_stride); i++) {
1024 FM10K_WRITE_REG(hw, FM10K_TQMAP(i), 0);
1025 FM10K_WRITE_REG(hw, FM10K_RQMAP(i), 0);
1028 /* calculate starting index for queues */
1029 vf_q_idx = fm10k_vf_queue_index(hw, vf_idx);
1031 /* determine correct default VLAN ID */
1032 if (vf_info->pf_vid)
1033 vf_vid = vf_info->pf_vid;
1035 vf_vid = vf_info->sw_vid;
1037 /* configure Queue control register */
1038 txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) |
1039 (vf_idx << FM10K_TXQCTL_TC_SHIFT) |
1040 FM10K_TXQCTL_VF | vf_idx;
1041 rxqctl = (vf_idx << FM10K_RXQCTL_VF_SHIFT) | FM10K_RXQCTL_VF;
1043 /* stop further DMA and reset queue ownership back to VF */
1044 for (i = vf_q_idx; i < (queues_per_pool + vf_q_idx); i++) {
1045 FM10K_WRITE_REG(hw, FM10K_TXDCTL(i), 0);
1046 FM10K_WRITE_REG(hw, FM10K_TXQCTL(i), txqctl);
1047 FM10K_WRITE_REG(hw, FM10K_RXDCTL(i),
1048 FM10K_RXDCTL_WRITE_BACK_MIN_DELAY |
1049 FM10K_RXDCTL_DROP_ON_EMPTY);
1050 FM10K_WRITE_REG(hw, FM10K_RXQCTL(i), rxqctl);
1053 /* reset TC with -1 credits and no quanta to prevent transmit */
1054 FM10K_WRITE_REG(hw, FM10K_TC_MAXCREDIT(vf_idx), 0);
1055 FM10K_WRITE_REG(hw, FM10K_TC_RATE(vf_idx), 0);
1056 FM10K_WRITE_REG(hw, FM10K_TC_CREDIT(vf_idx),
1057 FM10K_TC_CREDIT_CREDIT_MASK);
1059 /* update our first entry in the table based on previous VF */
1061 hw->mac.ops.update_int_moderator(hw);
1063 hw->iov.ops.assign_int_moderator(hw, vf_idx - 1);
1065 /* reset linked list so it now includes our active vectors */
1066 if (vf_idx == (hw->iov.num_vfs - 1))
1067 FM10K_WRITE_REG(hw, FM10K_ITR2(0), vf_v_idx);
1069 FM10K_WRITE_REG(hw, FM10K_ITR2(vf_v_limit), vf_v_idx);
1071 /* link remaining vectors so that next points to previous */
1072 for (vf_v_idx++; vf_v_idx < vf_v_limit; vf_v_idx++)
1073 FM10K_WRITE_REG(hw, FM10K_ITR2(vf_v_idx), vf_v_idx - 1);
1075 /* zero out MBMEM, VLAN_TABLE, RETA, RSSRK, and MRQC registers */
1076 for (i = FM10K_VFMBMEM_LEN; i--;)
1077 FM10K_WRITE_REG(hw, FM10K_MBMEM_VF(vf_idx, i), 0);
1078 for (i = FM10K_VLAN_TABLE_SIZE; i--;)
1079 FM10K_WRITE_REG(hw, FM10K_VLAN_TABLE(vf_info->vsi, i), 0);
1080 for (i = FM10K_RETA_SIZE; i--;)
1081 FM10K_WRITE_REG(hw, FM10K_RETA(vf_info->vsi, i), 0);
1082 for (i = FM10K_RSSRK_SIZE; i--;)
1083 FM10K_WRITE_REG(hw, FM10K_RSSRK(vf_info->vsi, i), 0);
1084 FM10K_WRITE_REG(hw, FM10K_MRQC(vf_info->vsi), 0);
1086 /* Update base address registers to contain MAC address */
1087 if (FM10K_IS_VALID_ETHER_ADDR(vf_info->mac)) {
1088 tdbal = (((u32)vf_info->mac[3]) << 24) |
1089 (((u32)vf_info->mac[4]) << 16) |
1090 (((u32)vf_info->mac[5]) << 8);
1091 tdbah = (((u32)0xFF) << 24) |
1092 (((u32)vf_info->mac[0]) << 16) |
1093 (((u32)vf_info->mac[1]) << 8) |
1094 ((u32)vf_info->mac[2]);
1097 /* map queue pairs back to VF from last to first */
1098 for (i = queues_per_pool; i--;) {
1099 FM10K_WRITE_REG(hw, FM10K_TDBAL(vf_q_idx + i), tdbal);
1100 FM10K_WRITE_REG(hw, FM10K_TDBAH(vf_q_idx + i), tdbah);
1101 /* See definition of FM10K_TDLEN_ITR_SCALE_SHIFT for an
1102 * explanation of how TDLEN is used.
1104 FM10K_WRITE_REG(hw, FM10K_TDLEN(vf_q_idx + i),
1105 hw->mac.itr_scale <<
1106 FM10K_TDLEN_ITR_SCALE_SHIFT);
1107 FM10K_WRITE_REG(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx + i);
1108 FM10K_WRITE_REG(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx + i);
1111 /* repeat the first ring for all the remaining VF rings */
1112 for (i = queues_per_pool; i < qmap_stride; i++) {
1113 FM10K_WRITE_REG(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx);
1114 FM10K_WRITE_REG(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx);
1117 return FM10K_SUCCESS;
1121 * fm10k_iov_set_lport_pf - Assign and enable a logical port for a given VF
1122 * @hw: pointer to hardware structure
1123 * @vf_info: pointer to VF information structure
1124 * @lport_idx: Logical port offset from the hardware glort
1125 * @flags: Set of capability flags to extend port beyond basic functionality
1127 * This function allows enabling a VF port by assigning it a GLORT and
1128 * setting the flags so that it can enable an Rx mode.
1130 STATIC s32 fm10k_iov_set_lport_pf(struct fm10k_hw *hw,
1131 struct fm10k_vf_info *vf_info,
1132 u16 lport_idx, u8 flags)
1134 u16 glort = (hw->mac.dglort_map + lport_idx) & FM10K_DGLORTMAP_NONE;
1136 DEBUGFUNC("fm10k_iov_set_lport_state_pf");
1138 /* if glort is not valid return error */
1139 if (!fm10k_glort_valid_pf(hw, glort))
1140 return FM10K_ERR_PARAM;
1142 vf_info->vf_flags = flags | FM10K_VF_FLAG_NONE_CAPABLE;
1143 vf_info->glort = glort;
1145 return FM10K_SUCCESS;
1149 * fm10k_iov_reset_lport_pf - Disable a logical port for a given VF
1150 * @hw: pointer to hardware structure
1151 * @vf_info: pointer to VF information structure
1153 * This function disables a VF port by stripping it of a GLORT and
1154 * setting the flags so that it cannot enable any Rx mode.
1156 STATIC void fm10k_iov_reset_lport_pf(struct fm10k_hw *hw,
1157 struct fm10k_vf_info *vf_info)
1161 DEBUGFUNC("fm10k_iov_reset_lport_state_pf");
1163 /* need to disable the port if it is already enabled */
1164 if (FM10K_VF_FLAG_ENABLED(vf_info)) {
1165 /* notify switch that this port has been disabled */
1166 fm10k_update_lport_state_pf(hw, vf_info->glort, 1, false);
1168 /* generate port state response to notify VF it is not ready */
1169 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
1170 vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
1173 /* clear flags and glort if it exists */
1174 vf_info->vf_flags = 0;
1179 * fm10k_iov_update_stats_pf - Updates hardware related statistics for VFs
1180 * @hw: pointer to hardware structure
1181 * @q: stats for all queues of a VF
1182 * @vf_idx: index of VF
1184 * This function collects queue stats for VFs.
1186 STATIC void fm10k_iov_update_stats_pf(struct fm10k_hw *hw,
1187 struct fm10k_hw_stats_q *q,
1192 /* get stats for all of the queues */
1193 qpp = fm10k_queues_per_pool(hw);
1194 idx = fm10k_vf_queue_index(hw, vf_idx);
1195 fm10k_update_hw_stats_q(hw, q, idx, qpp);
1199 * fm10k_iov_msg_msix_pf - Message handler for MSI-X request from VF
1200 * @hw: Pointer to hardware structure
1201 * @results: Pointer array to message, results[0] is pointer to message
1202 * @mbx: Pointer to mailbox information structure
1204 * This function is a default handler for MSI-X requests from the VF. The
1205 * assumption is that in this case it is acceptable to just directly
1206 * hand off the message from the VF to the underlying shared code.
1208 s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 **results,
1209 struct fm10k_mbx_info *mbx)
1211 struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1212 u8 vf_idx = vf_info->vf_idx;
1214 UNREFERENCED_1PARAMETER(results);
1215 DEBUGFUNC("fm10k_iov_msg_msix_pf");
1217 return hw->iov.ops.assign_int_moderator(hw, vf_idx);
1221 * fm10k_iov_select_vid - Select correct default VLAN ID
1222 * @hw: Pointer to hardware structure
1223 * @vid: VLAN ID to correct
1225 * Will report an error if the VLAN ID is out of range. For VID = 0, it will
1226 * return either the pf_vid or sw_vid depending on which one is set.
1228 STATIC s32 fm10k_iov_select_vid(struct fm10k_vf_info *vf_info, u16 vid)
1231 return vf_info->pf_vid ? vf_info->pf_vid : vf_info->sw_vid;
1232 else if (vf_info->pf_vid && vid != vf_info->pf_vid)
1233 return FM10K_ERR_PARAM;
1239 * fm10k_iov_msg_mac_vlan_pf - Message handler for MAC/VLAN request from VF
1240 * @hw: Pointer to hardware structure
1241 * @results: Pointer array to message, results[0] is pointer to message
1242 * @mbx: Pointer to mailbox information structure
1244 * This function is a default handler for MAC/VLAN requests from the VF.
1245 * The assumption is that in this case it is acceptable to just directly
1246 * hand off the message from the VF to the underlying shared code.
1248 s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
1249 struct fm10k_mbx_info *mbx)
1251 struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1254 int err = FM10K_SUCCESS;
1259 DEBUGFUNC("fm10k_iov_msg_mac_vlan_pf");
1261 /* we shouldn't be updating rules on a disabled interface */
1262 if (!FM10K_VF_FLAG_ENABLED(vf_info))
1263 err = FM10K_ERR_PARAM;
1265 if (!err && !!results[FM10K_MAC_VLAN_MSG_VLAN]) {
1266 result = results[FM10K_MAC_VLAN_MSG_VLAN];
1268 /* record VLAN id requested */
1269 err = fm10k_tlv_attr_get_u32(result, &vid);
1273 set = !(vid & FM10K_VLAN_CLEAR);
1274 vid &= ~FM10K_VLAN_CLEAR;
1276 /* if the length field has been set, this is a multi-bit
1277 * update request. For multi-bit requests, simply disallow
1278 * them when the pf_vid has been set. In this case, the PF
1279 * should have already cleared the VLAN_TABLE, and if we
1280 * allowed them, it could allow a rogue VF to receive traffic
1281 * on a VLAN it was not assigned. In the single-bit case, we
1282 * need to modify requests for VLAN 0 to use the default PF or
1283 * SW vid when assigned.
1287 /* prevent multi-bit requests when PF has
1288 * administratively set the VLAN for this VF
1290 if (vf_info->pf_vid)
1291 return FM10K_ERR_PARAM;
1293 err = fm10k_iov_select_vid(vf_info, (u16)vid);
1300 /* update VSI info for VF in regards to VLAN table */
1301 err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi, set);
1304 if (!err && !!results[FM10K_MAC_VLAN_MSG_MAC]) {
1305 result = results[FM10K_MAC_VLAN_MSG_MAC];
1307 /* record unicast MAC address requested */
1308 err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
1312 /* block attempts to set MAC for a locked device */
1313 if (FM10K_IS_VALID_ETHER_ADDR(vf_info->mac) &&
1314 memcmp(mac, vf_info->mac, ETH_ALEN))
1315 return FM10K_ERR_PARAM;
1317 set = !(vlan & FM10K_VLAN_CLEAR);
1318 vlan &= ~FM10K_VLAN_CLEAR;
1320 err = fm10k_iov_select_vid(vf_info, vlan);
1326 /* notify switch of request for new unicast address */
1327 err = hw->mac.ops.update_uc_addr(hw, vf_info->glort,
1331 if (!err && !!results[FM10K_MAC_VLAN_MSG_MULTICAST]) {
1332 result = results[FM10K_MAC_VLAN_MSG_MULTICAST];
1334 /* record multicast MAC address requested */
1335 err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
1339 /* verify that the VF is allowed to request multicast */
1340 if (!(vf_info->vf_flags & FM10K_VF_FLAG_MULTI_ENABLED))
1341 return FM10K_ERR_PARAM;
1343 set = !(vlan & FM10K_VLAN_CLEAR);
1344 vlan &= ~FM10K_VLAN_CLEAR;
1346 err = fm10k_iov_select_vid(vf_info, vlan);
1352 /* notify switch of request for new multicast address */
1353 err = hw->mac.ops.update_mc_addr(hw, vf_info->glort,
1361 * fm10k_iov_supported_xcast_mode_pf - Determine best match for xcast mode
1362 * @vf_info: VF info structure containing capability flags
1363 * @mode: Requested xcast mode
1365 * This function outputs the mode that most closely matches the requested
1366 * mode. If not modes match it will request we disable the port
1368 STATIC u8 fm10k_iov_supported_xcast_mode_pf(struct fm10k_vf_info *vf_info,
1371 u8 vf_flags = vf_info->vf_flags;
1373 /* match up mode to capabilities as best as possible */
1375 case FM10K_XCAST_MODE_PROMISC:
1376 if (vf_flags & FM10K_VF_FLAG_PROMISC_CAPABLE)
1377 return FM10K_XCAST_MODE_PROMISC;
1379 case FM10K_XCAST_MODE_ALLMULTI:
1380 if (vf_flags & FM10K_VF_FLAG_ALLMULTI_CAPABLE)
1381 return FM10K_XCAST_MODE_ALLMULTI;
1383 case FM10K_XCAST_MODE_MULTI:
1384 if (vf_flags & FM10K_VF_FLAG_MULTI_CAPABLE)
1385 return FM10K_XCAST_MODE_MULTI;
1387 case FM10K_XCAST_MODE_NONE:
1388 if (vf_flags & FM10K_VF_FLAG_NONE_CAPABLE)
1389 return FM10K_XCAST_MODE_NONE;
1395 /* disable interface as it should not be able to request any */
1396 return FM10K_XCAST_MODE_DISABLE;
1400 * fm10k_iov_msg_lport_state_pf - Message handler for port state requests
1401 * @hw: Pointer to hardware structure
1402 * @results: Pointer array to message, results[0] is pointer to message
1403 * @mbx: Pointer to mailbox information structure
1405 * This function is a default handler for port state requests. The port
1406 * state requests for now are basic and consist of enabling or disabling
1409 s32 fm10k_iov_msg_lport_state_pf(struct fm10k_hw *hw, u32 **results,
1410 struct fm10k_mbx_info *mbx)
1412 struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1414 s32 err = FM10K_SUCCESS;
1418 DEBUGFUNC("fm10k_iov_msg_lport_state_pf");
1420 /* verify VF is allowed to enable even minimal mode */
1421 if (!(vf_info->vf_flags & FM10K_VF_FLAG_NONE_CAPABLE))
1422 return FM10K_ERR_PARAM;
1424 if (!!results[FM10K_LPORT_STATE_MSG_XCAST_MODE]) {
1425 result = results[FM10K_LPORT_STATE_MSG_XCAST_MODE];
1427 /* XCAST mode update requested */
1428 err = fm10k_tlv_attr_get_u8(result, &mode);
1430 return FM10K_ERR_PARAM;
1432 /* prep for possible demotion depending on capabilities */
1433 mode = fm10k_iov_supported_xcast_mode_pf(vf_info, mode);
1435 /* if mode is not currently enabled, enable it */
1436 if (!(FM10K_VF_FLAG_ENABLED(vf_info) & BIT(mode)))
1437 fm10k_update_xcast_mode_pf(hw, vf_info->glort, mode);
1439 /* swap mode back to a bit flag */
1440 mode = FM10K_VF_FLAG_SET_MODE(mode);
1441 } else if (!results[FM10K_LPORT_STATE_MSG_DISABLE]) {
1442 /* need to disable the port if it is already enabled */
1443 if (FM10K_VF_FLAG_ENABLED(vf_info))
1444 err = fm10k_update_lport_state_pf(hw, vf_info->glort,
1447 /* we need to clear VF_FLAG_ENABLED flags in order to ensure
1448 * that we actually re-enable the LPORT state below. Note that
1449 * this has no impact if the VF is already disabled, as the
1450 * flags are already cleared.
1453 vf_info->vf_flags = FM10K_VF_FLAG_CAPABLE(vf_info);
1455 /* when enabling the port we should reset the rate limiters */
1456 hw->iov.ops.configure_tc(hw, vf_info->vf_idx, vf_info->rate);
1458 /* set mode for minimal functionality */
1459 mode = FM10K_VF_FLAG_SET_MODE_NONE;
1461 /* generate port state response to notify VF it is ready */
1462 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
1463 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_READY);
1464 mbx->ops.enqueue_tx(hw, mbx, msg);
1467 /* if enable state toggled note the update */
1468 if (!err && (!FM10K_VF_FLAG_ENABLED(vf_info) != !mode))
1469 err = fm10k_update_lport_state_pf(hw, vf_info->glort, 1,
1472 /* if state change succeeded, then update our stored state */
1473 mode |= FM10K_VF_FLAG_CAPABLE(vf_info);
1475 vf_info->vf_flags = mode;
1480 #ifndef NO_DEFAULT_SRIOV_MSG_HANDLERS
1481 const struct fm10k_msg_data fm10k_iov_msg_data_pf[] = {
1482 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
1483 FM10K_VF_MSG_MSIX_HANDLER(fm10k_iov_msg_msix_pf),
1484 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_iov_msg_mac_vlan_pf),
1485 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_iov_msg_lport_state_pf),
1486 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
1491 * fm10k_update_stats_hw_pf - Updates hardware related statistics of PF
1492 * @hw: pointer to hardware structure
1493 * @stats: pointer to the stats structure to update
1495 * This function collects and aggregates global and per queue hardware
1498 STATIC void fm10k_update_hw_stats_pf(struct fm10k_hw *hw,
1499 struct fm10k_hw_stats *stats)
1501 u32 timeout, ur, ca, um, xec, vlan_drop, loopback_drop, nodesc_drop;
1504 DEBUGFUNC("fm10k_update_hw_stats_pf");
1506 /* Use Tx queue 0 as a canary to detect a reset */
1507 id = FM10K_READ_REG(hw, FM10K_TXQCTL(0));
1509 /* Read Global Statistics */
1511 timeout = fm10k_read_hw_stats_32b(hw, FM10K_STATS_TIMEOUT,
1513 ur = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UR, &stats->ur);
1514 ca = fm10k_read_hw_stats_32b(hw, FM10K_STATS_CA, &stats->ca);
1515 um = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UM, &stats->um);
1516 xec = fm10k_read_hw_stats_32b(hw, FM10K_STATS_XEC, &stats->xec);
1517 vlan_drop = fm10k_read_hw_stats_32b(hw, FM10K_STATS_VLAN_DROP,
1520 fm10k_read_hw_stats_32b(hw,
1521 FM10K_STATS_LOOPBACK_DROP,
1522 &stats->loopback_drop);
1523 nodesc_drop = fm10k_read_hw_stats_32b(hw,
1524 FM10K_STATS_NODESC_DROP,
1525 &stats->nodesc_drop);
1527 /* if value has not changed then we have consistent data */
1529 id = FM10K_READ_REG(hw, FM10K_TXQCTL(0));
1530 } while ((id ^ id_prev) & FM10K_TXQCTL_ID_MASK);
1532 /* drop non-ID bits and set VALID ID bit */
1533 id &= FM10K_TXQCTL_ID_MASK;
1534 id |= FM10K_STAT_VALID;
1536 /* Update Global Statistics */
1537 if (stats->stats_idx == id) {
1538 stats->timeout.count += timeout;
1539 stats->ur.count += ur;
1540 stats->ca.count += ca;
1541 stats->um.count += um;
1542 stats->xec.count += xec;
1543 stats->vlan_drop.count += vlan_drop;
1544 stats->loopback_drop.count += loopback_drop;
1545 stats->nodesc_drop.count += nodesc_drop;
1548 /* Update bases and record current PF id */
1549 fm10k_update_hw_base_32b(&stats->timeout, timeout);
1550 fm10k_update_hw_base_32b(&stats->ur, ur);
1551 fm10k_update_hw_base_32b(&stats->ca, ca);
1552 fm10k_update_hw_base_32b(&stats->um, um);
1553 fm10k_update_hw_base_32b(&stats->xec, xec);
1554 fm10k_update_hw_base_32b(&stats->vlan_drop, vlan_drop);
1555 fm10k_update_hw_base_32b(&stats->loopback_drop, loopback_drop);
1556 fm10k_update_hw_base_32b(&stats->nodesc_drop, nodesc_drop);
1557 stats->stats_idx = id;
1559 /* Update Queue Statistics */
1560 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
1564 * fm10k_rebind_hw_stats_pf - Resets base for hardware statistics of PF
1565 * @hw: pointer to hardware structure
1566 * @stats: pointer to the stats structure to update
1568 * This function resets the base for global and per queue hardware
1571 STATIC void fm10k_rebind_hw_stats_pf(struct fm10k_hw *hw,
1572 struct fm10k_hw_stats *stats)
1574 DEBUGFUNC("fm10k_rebind_hw_stats_pf");
1576 /* Unbind Global Statistics */
1577 fm10k_unbind_hw_stats_32b(&stats->timeout);
1578 fm10k_unbind_hw_stats_32b(&stats->ur);
1579 fm10k_unbind_hw_stats_32b(&stats->ca);
1580 fm10k_unbind_hw_stats_32b(&stats->um);
1581 fm10k_unbind_hw_stats_32b(&stats->xec);
1582 fm10k_unbind_hw_stats_32b(&stats->vlan_drop);
1583 fm10k_unbind_hw_stats_32b(&stats->loopback_drop);
1584 fm10k_unbind_hw_stats_32b(&stats->nodesc_drop);
1586 /* Unbind Queue Statistics */
1587 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
1589 /* Reinitialize bases for all stats */
1590 fm10k_update_hw_stats_pf(hw, stats);
1594 * fm10k_set_dma_mask_pf - Configures PhyAddrSpace to limit DMA to system
1595 * @hw: pointer to hardware structure
1596 * @dma_mask: 64 bit DMA mask required for platform
1598 * This function sets the PHYADDR.PhyAddrSpace bits for the endpoint in order
1599 * to limit the access to memory beyond what is physically in the system.
1601 STATIC void fm10k_set_dma_mask_pf(struct fm10k_hw *hw, u64 dma_mask)
1603 /* we need to write the upper 32 bits of DMA mask to PhyAddrSpace */
1604 u32 phyaddr = (u32)(dma_mask >> 32);
1606 DEBUGFUNC("fm10k_set_dma_mask_pf");
1608 FM10K_WRITE_REG(hw, FM10K_PHYADDR, phyaddr);
1612 * fm10k_get_fault_pf - Record a fault in one of the interface units
1613 * @hw: pointer to hardware structure
1614 * @type: pointer to fault type register offset
1615 * @fault: pointer to memory location to record the fault
1617 * Record the fault register contents to the fault data structure and
1618 * clear the entry from the register.
1620 * Returns ERR_PARAM if invalid register is specified or no error is present.
1622 STATIC s32 fm10k_get_fault_pf(struct fm10k_hw *hw, int type,
1623 struct fm10k_fault *fault)
1627 DEBUGFUNC("fm10k_get_fault_pf");
1629 /* verify the fault register is in range and is aligned */
1631 case FM10K_PCA_FAULT:
1632 case FM10K_THI_FAULT:
1633 case FM10K_FUM_FAULT:
1636 return FM10K_ERR_PARAM;
1639 /* only service faults that are valid */
1640 func = FM10K_READ_REG(hw, type + FM10K_FAULT_FUNC);
1641 if (!(func & FM10K_FAULT_FUNC_VALID))
1642 return FM10K_ERR_PARAM;
1644 /* read remaining fields */
1645 fault->address = FM10K_READ_REG(hw, type + FM10K_FAULT_ADDR_HI);
1646 fault->address <<= 32;
1647 fault->address = FM10K_READ_REG(hw, type + FM10K_FAULT_ADDR_LO);
1648 fault->specinfo = FM10K_READ_REG(hw, type + FM10K_FAULT_SPECINFO);
1650 /* clear valid bit to allow for next error */
1651 FM10K_WRITE_REG(hw, type + FM10K_FAULT_FUNC, FM10K_FAULT_FUNC_VALID);
1653 /* Record which function triggered the error */
1654 if (func & FM10K_FAULT_FUNC_PF)
1657 fault->func = 1 + ((func & FM10K_FAULT_FUNC_VF_MASK) >>
1658 FM10K_FAULT_FUNC_VF_SHIFT);
1660 /* record fault type */
1661 fault->type = func & FM10K_FAULT_FUNC_TYPE_MASK;
1663 return FM10K_SUCCESS;
1667 * fm10k_request_lport_map_pf - Request LPORT map from the switch API
1668 * @hw: pointer to hardware structure
1671 STATIC s32 fm10k_request_lport_map_pf(struct fm10k_hw *hw)
1673 struct fm10k_mbx_info *mbx = &hw->mbx;
1676 DEBUGFUNC("fm10k_request_lport_pf");
1678 /* issue request asking for LPORT map */
1679 fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_LPORT_MAP);
1681 /* load onto outgoing mailbox */
1682 return mbx->ops.enqueue_tx(hw, mbx, msg);
1686 * fm10k_get_host_state_pf - Returns the state of the switch and mailbox
1687 * @hw: pointer to hardware structure
1688 * @switch_ready: pointer to boolean value that will record switch state
1690 * This function will check the DMA_CTRL2 register and mailbox in order
1691 * to determine if the switch is ready for the PF to begin requesting
1692 * addresses and mapping traffic to the local interface.
1694 STATIC s32 fm10k_get_host_state_pf(struct fm10k_hw *hw, bool *switch_ready)
1698 DEBUGFUNC("fm10k_get_host_state_pf");
1700 /* verify the switch is ready for interaction */
1701 dma_ctrl2 = FM10K_READ_REG(hw, FM10K_DMA_CTRL2);
1702 if (!(dma_ctrl2 & FM10K_DMA_CTRL2_SWITCH_READY))
1703 return FM10K_SUCCESS;
1705 /* retrieve generic host state info */
1706 return fm10k_get_host_state_generic(hw, switch_ready);
1709 /* This structure defines the attibutes to be parsed below */
1710 const struct fm10k_tlv_attr fm10k_lport_map_msg_attr[] = {
1711 FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_ERR,
1712 sizeof(struct fm10k_swapi_error)),
1713 FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_LPORT_MAP),
1718 * fm10k_msg_lport_map_pf - Message handler for lport_map message from SM
1719 * @hw: Pointer to hardware structure
1720 * @results: pointer array containing parsed data
1721 * @mbx: Pointer to mailbox information structure
1723 * This handler configures the lport mapping based on the reply from the
1726 s32 fm10k_msg_lport_map_pf(struct fm10k_hw *hw, u32 **results,
1727 struct fm10k_mbx_info *mbx)
1733 UNREFERENCED_1PARAMETER(mbx);
1734 DEBUGFUNC("fm10k_msg_lport_map_pf");
1736 err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_LPORT_MAP],
1741 /* extract values out of the header */
1742 glort = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_GLORT);
1743 mask = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_MASK);
1745 /* verify mask is set and none of the masked bits in glort are set */
1746 if (!mask || (glort & ~mask))
1747 return FM10K_ERR_PARAM;
1749 /* verify the mask is contiguous, and that it is 1's followed by 0's */
1750 if (((~(mask - 1) & mask) + mask) & FM10K_DGLORTMAP_NONE)
1751 return FM10K_ERR_PARAM;
1753 /* record the glort, mask, and port count */
1754 hw->mac.dglort_map = dglort_map;
1756 return FM10K_SUCCESS;
1759 const struct fm10k_tlv_attr fm10k_update_pvid_msg_attr[] = {
1760 FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_UPDATE_PVID),
1765 * fm10k_msg_update_pvid_pf - Message handler for port VLAN message from SM
1766 * @hw: Pointer to hardware structure
1767 * @results: pointer array containing parsed data
1768 * @mbx: Pointer to mailbox information structure
1770 * This handler configures the default VLAN for the PF
1772 static s32 fm10k_msg_update_pvid_pf(struct fm10k_hw *hw, u32 **results,
1773 struct fm10k_mbx_info *mbx)
1779 UNREFERENCED_1PARAMETER(mbx);
1780 DEBUGFUNC("fm10k_msg_update_pvid_pf");
1782 err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_UPDATE_PVID],
1787 /* extract values from the pvid update */
1788 glort = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_GLORT);
1789 pvid = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_PVID);
1791 /* if glort is not valid return error */
1792 if (!fm10k_glort_valid_pf(hw, glort))
1793 return FM10K_ERR_PARAM;
1795 /* verify VLAN ID is valid */
1796 if (pvid >= FM10K_VLAN_TABLE_VID_MAX)
1797 return FM10K_ERR_PARAM;
1799 /* record the port VLAN ID value */
1800 hw->mac.default_vid = pvid;
1802 return FM10K_SUCCESS;
1806 * fm10k_record_global_table_data - Move global table data to swapi table info
1807 * @from: pointer to source table data structure
1808 * @to: pointer to destination table info structure
1810 * This function is will copy table_data to the table_info contained in
1813 static void fm10k_record_global_table_data(struct fm10k_global_table_data *from,
1814 struct fm10k_swapi_table_info *to)
1816 /* convert from le32 struct to CPU byte ordered values */
1817 to->used = FM10K_LE32_TO_CPU(from->used);
1818 to->avail = FM10K_LE32_TO_CPU(from->avail);
1821 const struct fm10k_tlv_attr fm10k_err_msg_attr[] = {
1822 FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_ERR,
1823 sizeof(struct fm10k_swapi_error)),
1828 * fm10k_msg_err_pf - Message handler for error reply
1829 * @hw: Pointer to hardware structure
1830 * @results: pointer array containing parsed data
1831 * @mbx: Pointer to mailbox information structure
1833 * This handler will capture the data for any error replies to previous
1834 * messages that the PF has sent.
1836 s32 fm10k_msg_err_pf(struct fm10k_hw *hw, u32 **results,
1837 struct fm10k_mbx_info *mbx)
1839 struct fm10k_swapi_error err_msg;
1842 UNREFERENCED_1PARAMETER(mbx);
1843 DEBUGFUNC("fm10k_msg_err_pf");
1845 /* extract structure from message */
1846 err = fm10k_tlv_attr_get_le_struct(results[FM10K_PF_ATTR_ID_ERR],
1847 &err_msg, sizeof(err_msg));
1851 /* record table status */
1852 fm10k_record_global_table_data(&err_msg.mac, &hw->swapi.mac);
1853 fm10k_record_global_table_data(&err_msg.nexthop, &hw->swapi.nexthop);
1854 fm10k_record_global_table_data(&err_msg.ffu, &hw->swapi.ffu);
1856 /* record SW API status value */
1857 hw->swapi.status = FM10K_LE32_TO_CPU(err_msg.status);
1859 return FM10K_SUCCESS;
1862 /* currently there is no shared 1588 timestamp handler */
1864 const struct fm10k_tlv_attr fm10k_1588_timestamp_msg_attr[] = {
1865 FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_1588_TIMESTAMP,
1866 sizeof(struct fm10k_swapi_1588_timestamp)),
1870 const struct fm10k_tlv_attr fm10k_1588_clock_owner_attr[] = {
1871 FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_1588_CLOCK_OWNER,
1872 sizeof(struct fm10k_swapi_1588_clock_owner)),
1876 const struct fm10k_tlv_attr fm10k_master_clk_offset_attr[] = {
1877 FM10K_TLV_ATTR_U64(FM10K_PF_ATTR_ID_MASTER_CLK_OFFSET),
1882 * fm10k_iov_notify_offset_pf - Notify VF of change in PTP offset
1883 * @hw: pointer to hardware structure
1884 * @vf_info: pointer to the vf info structure
1885 * @offset: 64bit unsigned offset from hardware SYSTIME
1887 * This function sends a message to a given VF to notify it of PTP offset
1890 STATIC void fm10k_iov_notify_offset_pf(struct fm10k_hw *hw,
1891 struct fm10k_vf_info *vf_info,
1896 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_1588);
1897 fm10k_tlv_attr_put_u64(msg, FM10K_1588_MSG_CLK_OFFSET, offset);
1899 if (vf_info->mbx.ops.enqueue_tx)
1900 vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
1904 * fm10k_msg_1588_clock_owner_pf - Message handler for clock ownership from SM
1905 * @hw: pointer to hardware structure
1906 * @results: pointer to array containing parsed data,
1907 * @mbx: Pointer to mailbox information structure
1909 * This handler configures the FM10K_HW_FLAG_CLOCK_OWNER field for the PF
1911 s32 fm10k_msg_1588_clock_owner_pf(struct fm10k_hw *hw, u32 **results,
1912 struct fm10k_mbx_info *mbx)
1914 struct fm10k_swapi_1588_clock_owner msg;
1918 UNREFERENCED_1PARAMETER(mbx);
1919 DEBUGFUNC("fm10k_msg_1588_clock_owner");
1921 err = fm10k_tlv_attr_get_le_struct(
1922 results[FM10K_PF_ATTR_ID_1588_CLOCK_OWNER],
1927 /* We own the clock iff the glort matches us and the enabled field is
1928 * true. Otherwise, the clock must belong to some other port.
1930 glort = le16_to_cpu(msg.glort);
1931 if (fm10k_glort_valid_pf(hw, glort) && msg.enabled)
1932 hw->flags |= FM10K_HW_FLAG_CLOCK_OWNER;
1934 hw->flags &= ~FM10K_HW_FLAG_CLOCK_OWNER;
1936 return FM10K_SUCCESS;
1940 * fm10k_adjust_systime_pf - Adjust systime frequency
1941 * @hw: pointer to hardware structure
1942 * @ppb: adjustment rate in parts per billion
1944 * This function will adjust the SYSTIME_CFG register contained in BAR 4
1945 * if this function is supported for BAR 4 access. The adjustment amount
1946 * is based on the parts per billion value provided and adjusted to a
1947 * value based on parts per 2^48 clock cycles.
1949 * If adjustment is not supported or the requested value is too large
1950 * we will return an error.
1952 STATIC s32 fm10k_adjust_systime_pf(struct fm10k_hw *hw, s32 ppb)
1956 DEBUGFUNC("fm10k_adjust_systime_pf");
1958 /* ensure that we control the clock */
1959 if (!(hw->flags & FM10K_HW_FLAG_CLOCK_OWNER))
1960 return FM10K_ERR_DEVICE_NOT_SUPPORTED;
1962 /* if sw_addr is not set we don't have switch register access */
1964 return ppb ? FM10K_ERR_PARAM : FM10K_SUCCESS;
1966 /* we must convert the value from parts per billion to parts per
1967 * 2^48 cycles. In addition I have opted to only use the 30 most
1968 * significant bits of the adjustment value as the 8 least
1969 * significant bits are located in another register and represent
1970 * a value significantly less than a part per billion, the result
1971 * of dropping the 8 least significant bits is that the adjustment
1972 * value is effectively multiplied by 2^8 when we write it.
1974 * As a result of all this the math for this breaks down as follows:
1975 * ppb / 10^9 == adjust * 2^8 / 2^48
1976 * If we solve this for adjust, and simplify it comes out as:
1977 * ppb * 2^31 / 5^9 == adjust
1979 systime_adjust = (ppb < 0) ? -ppb : ppb;
1980 systime_adjust <<= 31;
1981 do_div(systime_adjust, 1953125);
1983 /* verify the requested adjustment value is in range */
1984 if (systime_adjust > FM10K_SW_SYSTIME_ADJUST_MASK)
1985 return FM10K_ERR_PARAM;
1988 systime_adjust |= FM10K_SW_SYSTIME_ADJUST_DIR_POSITIVE;
1990 FM10K_WRITE_SW_REG(hw, FM10K_SW_SYSTIME_ADJUST, (u32)systime_adjust);
1992 return FM10K_SUCCESS;
1996 * fm10k_notify_offset_pf - Notify switch of change in PTP offset
1997 * @hw: pointer to hardware structure
1998 * @offset: 64bit unsigned offset of SYSTIME
2000 * This function sends a message to the switch to indicate a change in the
2001 * offset of the hardware SYSTIME registers. The switch manager is
2002 * responsible for transmitting this message to other hosts.
2004 STATIC s32 fm10k_notify_offset_pf(struct fm10k_hw *hw, u64 offset)
2006 struct fm10k_mbx_info *mbx = &hw->mbx;
2009 DEBUGFUNC("fm10k_notify_offset_pf");
2011 /* ensure that we control the clock */
2012 if (!(hw->flags & FM10K_HW_FLAG_CLOCK_OWNER))
2013 return FM10K_ERR_DEVICE_NOT_SUPPORTED;
2015 fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_MASTER_CLK_OFFSET);
2016 fm10k_tlv_attr_put_u64(msg, FM10K_PF_ATTR_ID_MASTER_CLK_OFFSET, offset);
2018 /* load onto outgoing mailbox */
2019 return mbx->ops.enqueue_tx(hw, mbx, msg);
2023 * fm10k_read_systime_pf - Reads value of systime registers
2024 * @hw: pointer to the hardware structure
2026 * Function reads the content of 2 registers, combined to represent a 64 bit
2027 * value measured in nanosecods. In order to guarantee the value is accurate
2028 * we check the 32 most significant bits both before and after reading the
2029 * 32 least significant bits to verify they didn't change as we were reading
2032 static u64 fm10k_read_systime_pf(struct fm10k_hw *hw)
2034 u32 systime_l, systime_h, systime_tmp;
2036 systime_h = fm10k_read_reg(hw, FM10K_SYSTIME + 1);
2039 systime_tmp = systime_h;
2040 systime_l = fm10k_read_reg(hw, FM10K_SYSTIME);
2041 systime_h = fm10k_read_reg(hw, FM10K_SYSTIME + 1);
2042 } while (systime_tmp != systime_h);
2044 return ((u64)systime_h << 32) | systime_l;
2047 static const struct fm10k_msg_data fm10k_msg_data_pf[] = {
2048 FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, fm10k_msg_err_pf),
2049 FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, fm10k_msg_err_pf),
2050 FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_msg_lport_map_pf),
2051 FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf),
2052 FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf),
2053 FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_msg_update_pvid_pf),
2054 FM10K_PF_MSG_1588_CLOCK_OWNER_HANDLER(fm10k_msg_1588_clock_owner_pf),
2055 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
2059 * fm10k_init_ops_pf - Inits func ptrs and MAC type
2060 * @hw: pointer to hardware structure
2062 * Initialize the function pointers and assign the MAC type for PF.
2063 * Does not touch the hardware.
2065 s32 fm10k_init_ops_pf(struct fm10k_hw *hw)
2067 struct fm10k_mac_info *mac = &hw->mac;
2068 struct fm10k_iov_info *iov = &hw->iov;
2070 DEBUGFUNC("fm10k_init_ops_pf");
2072 fm10k_init_ops_generic(hw);
2074 mac->ops.reset_hw = &fm10k_reset_hw_pf;
2075 mac->ops.init_hw = &fm10k_init_hw_pf;
2076 mac->ops.start_hw = &fm10k_start_hw_generic;
2077 mac->ops.stop_hw = &fm10k_stop_hw_generic;
2078 #ifndef NO_IS_SLOT_APPROPRIATE_CHECK
2079 mac->ops.is_slot_appropriate = &fm10k_is_slot_appropriate_pf;
2081 mac->ops.update_vlan = &fm10k_update_vlan_pf;
2082 mac->ops.read_mac_addr = &fm10k_read_mac_addr_pf;
2083 mac->ops.update_uc_addr = &fm10k_update_uc_addr_pf;
2084 mac->ops.update_mc_addr = &fm10k_update_mc_addr_pf;
2085 mac->ops.update_xcast_mode = &fm10k_update_xcast_mode_pf;
2086 mac->ops.update_int_moderator = &fm10k_update_int_moderator_pf;
2087 mac->ops.update_lport_state = &fm10k_update_lport_state_pf;
2088 mac->ops.update_hw_stats = &fm10k_update_hw_stats_pf;
2089 mac->ops.rebind_hw_stats = &fm10k_rebind_hw_stats_pf;
2090 mac->ops.configure_dglort_map = &fm10k_configure_dglort_map_pf;
2091 mac->ops.set_dma_mask = &fm10k_set_dma_mask_pf;
2092 mac->ops.get_fault = &fm10k_get_fault_pf;
2093 mac->ops.get_host_state = &fm10k_get_host_state_pf;
2094 mac->ops.request_lport_map = &fm10k_request_lport_map_pf;
2095 mac->ops.adjust_systime = &fm10k_adjust_systime_pf;
2096 mac->ops.notify_offset = &fm10k_notify_offset_pf;
2097 mac->ops.read_systime = &fm10k_read_systime_pf;
2099 mac->max_msix_vectors = fm10k_get_pcie_msix_count_generic(hw);
2101 iov->ops.assign_resources = &fm10k_iov_assign_resources_pf;
2102 iov->ops.configure_tc = &fm10k_iov_configure_tc_pf;
2103 iov->ops.assign_int_moderator = &fm10k_iov_assign_int_moderator_pf;
2104 iov->ops.assign_default_mac_vlan = fm10k_iov_assign_default_mac_vlan_pf;
2105 iov->ops.reset_resources = &fm10k_iov_reset_resources_pf;
2106 iov->ops.set_lport = &fm10k_iov_set_lport_pf;
2107 iov->ops.reset_lport = &fm10k_iov_reset_lport_pf;
2108 iov->ops.update_stats = &fm10k_iov_update_stats_pf;
2109 iov->ops.notify_offset = &fm10k_iov_notify_offset_pf;
2111 return fm10k_sm_mbx_init(hw, &hw->mbx, fm10k_msg_data_pf);