1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 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
25 * fm10k_reset_hw_pf - PF hardware reset
26 * @hw: pointer to hardware structure
28 * This function should return the hardware to a state similar to the
29 * one it is in after being powered on.
31 static s32
fm10k_reset_hw_pf(struct fm10k_hw
*hw
)
37 /* Disable interrupts */
38 fm10k_write_reg(hw
, FM10K_EIMR
, FM10K_EIMR_DISABLE(ALL
));
40 /* Lock ITR2 reg 0 into itself and disable interrupt moderation */
41 fm10k_write_reg(hw
, FM10K_ITR2(0), 0);
42 fm10k_write_reg(hw
, FM10K_INT_CTRL
, 0);
44 /* We assume here Tx and Rx queue 0 are owned by the PF */
46 /* Shut off VF access to their queues forcing them to queue 0 */
47 for (i
= 0; i
< FM10K_TQMAP_TABLE_SIZE
; i
++) {
48 fm10k_write_reg(hw
, FM10K_TQMAP(i
), 0);
49 fm10k_write_reg(hw
, FM10K_RQMAP(i
), 0);
52 /* shut down all rings */
53 err
= fm10k_disable_queues_generic(hw
, FM10K_MAX_QUEUES
);
57 /* Verify that DMA is no longer active */
58 reg
= fm10k_read_reg(hw
, FM10K_DMA_CTRL
);
59 if (reg
& (FM10K_DMA_CTRL_TX_ACTIVE
| FM10K_DMA_CTRL_RX_ACTIVE
))
60 return FM10K_ERR_DMA_PENDING
;
62 /* Inititate data path reset */
63 reg
|= FM10K_DMA_CTRL_DATAPATH_RESET
;
64 fm10k_write_reg(hw
, FM10K_DMA_CTRL
, reg
);
66 /* Flush write and allow 100us for reset to complete */
67 fm10k_write_flush(hw
);
68 udelay(FM10K_RESET_TIMEOUT
);
70 /* Verify we made it out of reset */
71 reg
= fm10k_read_reg(hw
, FM10K_IP
);
72 if (!(reg
& FM10K_IP_NOTINRESET
))
73 err
= FM10K_ERR_RESET_FAILED
;
79 * fm10k_is_ari_hierarchy_pf - Indicate ARI hierarchy support
80 * @hw: pointer to hardware structure
82 * Looks at the ARI hierarchy bit to determine whether ARI is supported or not.
84 static bool fm10k_is_ari_hierarchy_pf(struct fm10k_hw
*hw
)
86 u16 sriov_ctrl
= fm10k_read_pci_cfg_word(hw
, FM10K_PCIE_SRIOV_CTRL
);
88 return !!(sriov_ctrl
& FM10K_PCIE_SRIOV_CTRL_VFARI
);
92 * fm10k_init_hw_pf - PF hardware initialization
93 * @hw: pointer to hardware structure
96 static s32
fm10k_init_hw_pf(struct fm10k_hw
*hw
)
101 /* Establish default VSI as valid */
102 fm10k_write_reg(hw
, FM10K_DGLORTDEC(fm10k_dglort_default
), 0);
103 fm10k_write_reg(hw
, FM10K_DGLORTMAP(fm10k_dglort_default
),
104 FM10K_DGLORTMAP_ANY
);
106 /* Invalidate all other GLORT entries */
107 for (i
= 1; i
< FM10K_DGLORT_COUNT
; i
++)
108 fm10k_write_reg(hw
, FM10K_DGLORTMAP(i
), FM10K_DGLORTMAP_NONE
);
110 /* reset ITR2(0) to point to itself */
111 fm10k_write_reg(hw
, FM10K_ITR2(0), 0);
113 /* reset VF ITR2(0) to point to 0 avoid PF registers */
114 fm10k_write_reg(hw
, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF
), 0);
116 /* loop through all PF ITR2 registers pointing them to the previous */
117 for (i
= 1; i
< FM10K_ITR_REG_COUNT_PF
; i
++)
118 fm10k_write_reg(hw
, FM10K_ITR2(i
), i
- 1);
120 /* Enable interrupt moderator if not already enabled */
121 fm10k_write_reg(hw
, FM10K_INT_CTRL
, FM10K_INT_CTRL_ENABLEMODERATOR
);
123 /* compute the default txqctl configuration */
124 txqctl
= FM10K_TXQCTL_PF
| FM10K_TXQCTL_UNLIMITED_BW
|
125 (hw
->mac
.default_vid
<< FM10K_TXQCTL_VID_SHIFT
);
127 for (i
= 0; i
< FM10K_MAX_QUEUES
; i
++) {
128 /* configure rings for 256 Queue / 32 Descriptor cache mode */
129 fm10k_write_reg(hw
, FM10K_TQDLOC(i
),
130 (i
* FM10K_TQDLOC_BASE_32_DESC
) |
131 FM10K_TQDLOC_SIZE_32_DESC
);
132 fm10k_write_reg(hw
, FM10K_TXQCTL(i
), txqctl
);
134 /* configure rings to provide TPH processing hints */
135 fm10k_write_reg(hw
, FM10K_TPH_TXCTRL(i
),
136 FM10K_TPH_TXCTRL_DESC_TPHEN
|
137 FM10K_TPH_TXCTRL_DESC_RROEN
|
138 FM10K_TPH_TXCTRL_DESC_WROEN
|
139 FM10K_TPH_TXCTRL_DATA_RROEN
);
140 fm10k_write_reg(hw
, FM10K_TPH_RXCTRL(i
),
141 FM10K_TPH_RXCTRL_DESC_TPHEN
|
142 FM10K_TPH_RXCTRL_DESC_RROEN
|
143 FM10K_TPH_RXCTRL_DATA_WROEN
|
144 FM10K_TPH_RXCTRL_HDR_WROEN
);
147 /* set max hold interval to align with 1.024 usec in all modes */
148 switch (hw
->bus
.speed
) {
149 case fm10k_bus_speed_2500
:
150 dma_ctrl
= FM10K_DMA_CTRL_MAX_HOLD_1US_GEN1
;
152 case fm10k_bus_speed_5000
:
153 dma_ctrl
= FM10K_DMA_CTRL_MAX_HOLD_1US_GEN2
;
155 case fm10k_bus_speed_8000
:
156 dma_ctrl
= FM10K_DMA_CTRL_MAX_HOLD_1US_GEN3
;
163 /* Configure TSO flags */
164 fm10k_write_reg(hw
, FM10K_DTXTCPFLGL
, FM10K_TSO_FLAGS_LOW
);
165 fm10k_write_reg(hw
, FM10K_DTXTCPFLGH
, FM10K_TSO_FLAGS_HI
);
168 * Set Rx Descriptor size to 32
169 * Set Minimum MSS to 64
170 * Set Maximum number of Rx queues to 256 / 32 Descriptor
172 dma_ctrl
|= FM10K_DMA_CTRL_TX_ENABLE
| FM10K_DMA_CTRL_RX_ENABLE
|
173 FM10K_DMA_CTRL_RX_DESC_SIZE
| FM10K_DMA_CTRL_MINMSS_64
|
174 FM10K_DMA_CTRL_32_DESC
;
176 fm10k_write_reg(hw
, FM10K_DMA_CTRL
, dma_ctrl
);
178 /* record maximum queue count, we limit ourselves to 128 */
179 hw
->mac
.max_queues
= FM10K_MAX_QUEUES_PF
;
181 /* We support either 64 VFs or 7 VFs depending on if we have ARI */
182 hw
->iov
.total_vfs
= fm10k_is_ari_hierarchy_pf(hw
) ? 64 : 7;
188 * fm10k_is_slot_appropriate_pf - Indicate appropriate slot for this SKU
189 * @hw: pointer to hardware structure
191 * Looks at the PCIe bus info to confirm whether or not this slot can support
192 * the necessary bandwidth for this device.
194 static bool fm10k_is_slot_appropriate_pf(struct fm10k_hw
*hw
)
196 return (hw
->bus
.speed
== hw
->bus_caps
.speed
) &&
197 (hw
->bus
.width
== hw
->bus_caps
.width
);
201 * fm10k_update_vlan_pf - Update status of VLAN ID in VLAN filter table
202 * @hw: pointer to hardware structure
203 * @vid: VLAN ID to add to table
204 * @vsi: Index indicating VF ID or PF ID in table
205 * @set: Indicates if this is a set or clear operation
207 * This function adds or removes the corresponding VLAN ID from the VLAN
208 * filter table for the corresponding function. In addition to the
209 * standard set/clear that supports one bit a multi-bit write is
210 * supported to set 64 bits at a time.
212 static s32
fm10k_update_vlan_pf(struct fm10k_hw
*hw
, u32 vid
, u8 vsi
, bool set
)
214 u32 vlan_table
, reg
, mask
, bit
, len
;
216 /* verify the VSI index is valid */
217 if (vsi
> FM10K_VLAN_TABLE_VSI_MAX
)
218 return FM10K_ERR_PARAM
;
220 /* VLAN multi-bit write:
221 * The multi-bit write has several parts to it.
223 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
224 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
225 * | RSVD0 | Length |C|RSVD0| VLAN ID |
226 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
228 * VLAN ID: Vlan Starting value
229 * RSVD0: Reserved section, must be 0
230 * C: Flag field, 0 is set, 1 is clear (Used in VF VLAN message)
231 * Length: Number of times to repeat the bit being set
234 vid
= (vid
<< 17) >> 17;
236 /* verify the reserved 0 fields are 0 */
237 if (len
>= FM10K_VLAN_TABLE_VID_MAX
|| vid
>= FM10K_VLAN_TABLE_VID_MAX
)
238 return FM10K_ERR_PARAM
;
240 /* Loop through the table updating all required VLANs */
241 for (reg
= FM10K_VLAN_TABLE(vsi
, vid
/ 32), bit
= vid
% 32;
242 len
< FM10K_VLAN_TABLE_VID_MAX
;
243 len
-= 32 - bit
, reg
++, bit
= 0) {
244 /* record the initial state of the register */
245 vlan_table
= fm10k_read_reg(hw
, reg
);
247 /* truncate mask if we are at the start or end of the run */
248 mask
= (~(u32
)0 >> ((len
< 31) ? 31 - len
: 0)) << bit
;
250 /* make necessary modifications to the register */
251 mask
&= set
? ~vlan_table
: vlan_table
;
253 fm10k_write_reg(hw
, reg
, vlan_table
^ mask
);
260 * fm10k_read_mac_addr_pf - Read device MAC address
261 * @hw: pointer to the HW structure
263 * Reads the device MAC address from the SM_AREA and stores the value.
265 static s32
fm10k_read_mac_addr_pf(struct fm10k_hw
*hw
)
267 u8 perm_addr
[ETH_ALEN
];
271 serial_num
= fm10k_read_reg(hw
, FM10K_SM_AREA(1));
273 /* last byte should be all 1's */
274 if ((~serial_num
) << 24)
275 return FM10K_ERR_INVALID_MAC_ADDR
;
277 perm_addr
[0] = (u8
)(serial_num
>> 24);
278 perm_addr
[1] = (u8
)(serial_num
>> 16);
279 perm_addr
[2] = (u8
)(serial_num
>> 8);
281 serial_num
= fm10k_read_reg(hw
, FM10K_SM_AREA(0));
283 /* first byte should be all 1's */
284 if ((~serial_num
) >> 24)
285 return FM10K_ERR_INVALID_MAC_ADDR
;
287 perm_addr
[3] = (u8
)(serial_num
>> 16);
288 perm_addr
[4] = (u8
)(serial_num
>> 8);
289 perm_addr
[5] = (u8
)(serial_num
);
291 for (i
= 0; i
< ETH_ALEN
; i
++) {
292 hw
->mac
.perm_addr
[i
] = perm_addr
[i
];
293 hw
->mac
.addr
[i
] = perm_addr
[i
];
300 * fm10k_glort_valid_pf - Validate that the provided glort is valid
301 * @hw: pointer to the HW structure
302 * @glort: base glort to be validated
304 * This function will return an error if the provided glort is invalid
306 bool fm10k_glort_valid_pf(struct fm10k_hw
*hw
, u16 glort
)
308 glort
&= hw
->mac
.dglort_map
>> FM10K_DGLORTMAP_MASK_SHIFT
;
310 return glort
== (hw
->mac
.dglort_map
& FM10K_DGLORTMAP_NONE
);
314 * fm10k_update_xc_addr_pf - Update device addresses
315 * @hw: pointer to the HW structure
316 * @glort: base resource tag for this request
317 * @mac: MAC address to add/remove from table
318 * @vid: VLAN ID to add/remove from table
319 * @add: Indicates if this is an add or remove operation
320 * @flags: flags field to indicate add and secure
322 * This function generates a message to the Switch API requesting
323 * that the given logical port add/remove the given L2 MAC/VLAN address.
325 static s32
fm10k_update_xc_addr_pf(struct fm10k_hw
*hw
, u16 glort
,
326 const u8
*mac
, u16 vid
, bool add
, u8 flags
)
328 struct fm10k_mbx_info
*mbx
= &hw
->mbx
;
329 struct fm10k_mac_update mac_update
;
332 /* clear set bit from VLAN ID */
333 vid
&= ~FM10K_VLAN_CLEAR
;
335 /* if glort or vlan are not valid return error */
336 if (!fm10k_glort_valid_pf(hw
, glort
) || vid
>= FM10K_VLAN_TABLE_VID_MAX
)
337 return FM10K_ERR_PARAM
;
340 mac_update
.mac_lower
= cpu_to_le32(((u32
)mac
[2] << 24) |
341 ((u32
)mac
[3] << 16) |
344 mac_update
.mac_upper
= cpu_to_le16(((u32
)mac
[0] << 8) |
346 mac_update
.vlan
= cpu_to_le16(vid
);
347 mac_update
.glort
= cpu_to_le16(glort
);
348 mac_update
.action
= add
? 0 : 1;
349 mac_update
.flags
= flags
;
351 /* populate mac_update fields */
352 fm10k_tlv_msg_init(msg
, FM10K_PF_MSG_ID_UPDATE_MAC_FWD_RULE
);
353 fm10k_tlv_attr_put_le_struct(msg
, FM10K_PF_ATTR_ID_MAC_UPDATE
,
354 &mac_update
, sizeof(mac_update
));
356 /* load onto outgoing mailbox */
357 return mbx
->ops
.enqueue_tx(hw
, mbx
, msg
);
361 * fm10k_update_uc_addr_pf - Update device unicast addresses
362 * @hw: pointer to the HW structure
363 * @glort: base resource tag for this request
364 * @mac: MAC address to add/remove from table
365 * @vid: VLAN ID to add/remove from table
366 * @add: Indicates if this is an add or remove operation
367 * @flags: flags field to indicate add and secure
369 * This function is used to add or remove unicast addresses for
372 static s32
fm10k_update_uc_addr_pf(struct fm10k_hw
*hw
, u16 glort
,
373 const u8
*mac
, u16 vid
, bool add
, u8 flags
)
375 /* verify MAC address is valid */
376 if (!is_valid_ether_addr(mac
))
377 return FM10K_ERR_PARAM
;
379 return fm10k_update_xc_addr_pf(hw
, glort
, mac
, vid
, add
, flags
);
383 * fm10k_update_mc_addr_pf - Update device multicast addresses
384 * @hw: pointer to the HW structure
385 * @glort: base resource tag for this request
386 * @mac: MAC address to add/remove from table
387 * @vid: VLAN ID to add/remove from table
388 * @add: Indicates if this is an add or remove operation
390 * This function is used to add or remove multicast MAC addresses for
393 static s32
fm10k_update_mc_addr_pf(struct fm10k_hw
*hw
, u16 glort
,
394 const u8
*mac
, u16 vid
, bool add
)
396 /* verify multicast address is valid */
397 if (!is_multicast_ether_addr(mac
))
398 return FM10K_ERR_PARAM
;
400 return fm10k_update_xc_addr_pf(hw
, glort
, mac
, vid
, add
, 0);
404 * fm10k_update_xcast_mode_pf - Request update of multicast mode
405 * @hw: pointer to hardware structure
406 * @glort: base resource tag for this request
407 * @mode: integer value indicating mode being requested
409 * This function will attempt to request a higher mode for the port
410 * so that it can enable either multicast, multicast promiscuous, or
411 * promiscuous mode of operation.
413 static s32
fm10k_update_xcast_mode_pf(struct fm10k_hw
*hw
, u16 glort
, u8 mode
)
415 struct fm10k_mbx_info
*mbx
= &hw
->mbx
;
416 u32 msg
[3], xcast_mode
;
418 if (mode
> FM10K_XCAST_MODE_NONE
)
419 return FM10K_ERR_PARAM
;
420 /* if glort is not valid return error */
421 if (!fm10k_glort_valid_pf(hw
, glort
))
422 return FM10K_ERR_PARAM
;
424 /* write xcast mode as a single u32 value,
425 * lower 16 bits: glort
426 * upper 16 bits: mode
428 xcast_mode
= ((u32
)mode
<< 16) | glort
;
430 /* generate message requesting to change xcast mode */
431 fm10k_tlv_msg_init(msg
, FM10K_PF_MSG_ID_XCAST_MODES
);
432 fm10k_tlv_attr_put_u32(msg
, FM10K_PF_ATTR_ID_XCAST_MODE
, xcast_mode
);
434 /* load onto outgoing mailbox */
435 return mbx
->ops
.enqueue_tx(hw
, mbx
, msg
);
439 * fm10k_update_int_moderator_pf - Update interrupt moderator linked list
440 * @hw: pointer to hardware structure
442 * This function walks through the MSI-X vector table to determine the
443 * number of active interrupts and based on that information updates the
444 * interrupt moderator linked list.
446 static void fm10k_update_int_moderator_pf(struct fm10k_hw
*hw
)
450 /* Disable interrupt moderator */
451 fm10k_write_reg(hw
, FM10K_INT_CTRL
, 0);
453 /* loop through PF from last to first looking enabled vectors */
454 for (i
= FM10K_ITR_REG_COUNT_PF
- 1; i
; i
--) {
455 if (!fm10k_read_reg(hw
, FM10K_MSIX_VECTOR_MASK(i
)))
459 /* always reset VFITR2[0] to point to last enabled PF vector */
460 fm10k_write_reg(hw
, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF
), i
);
462 /* reset ITR2[0] to point to last enabled PF vector */
463 if (!hw
->iov
.num_vfs
)
464 fm10k_write_reg(hw
, FM10K_ITR2(0), i
);
466 /* Enable interrupt moderator */
467 fm10k_write_reg(hw
, FM10K_INT_CTRL
, FM10K_INT_CTRL_ENABLEMODERATOR
);
471 * fm10k_update_lport_state_pf - Notify the switch of a change in port state
472 * @hw: pointer to the HW structure
473 * @glort: base resource tag for this request
474 * @count: number of logical ports being updated
475 * @enable: boolean value indicating enable or disable
477 * This function is used to add/remove a logical port from the switch.
479 static s32
fm10k_update_lport_state_pf(struct fm10k_hw
*hw
, u16 glort
,
480 u16 count
, bool enable
)
482 struct fm10k_mbx_info
*mbx
= &hw
->mbx
;
483 u32 msg
[3], lport_msg
;
485 /* do nothing if we are being asked to create or destroy 0 ports */
489 /* if glort is not valid return error */
490 if (!fm10k_glort_valid_pf(hw
, glort
))
491 return FM10K_ERR_PARAM
;
493 /* construct the lport message from the 2 pieces of data we have */
494 lport_msg
= ((u32
)count
<< 16) | glort
;
496 /* generate lport create/delete message */
497 fm10k_tlv_msg_init(msg
, enable
? FM10K_PF_MSG_ID_LPORT_CREATE
:
498 FM10K_PF_MSG_ID_LPORT_DELETE
);
499 fm10k_tlv_attr_put_u32(msg
, FM10K_PF_ATTR_ID_PORT
, lport_msg
);
501 /* load onto outgoing mailbox */
502 return mbx
->ops
.enqueue_tx(hw
, mbx
, msg
);
506 * fm10k_configure_dglort_map_pf - Configures GLORT entry and queues
507 * @hw: pointer to hardware structure
508 * @dglort: pointer to dglort configuration structure
510 * Reads the configuration structure contained in dglort_cfg and uses
511 * that information to then populate a DGLORTMAP/DEC entry and the queues
512 * to which it has been assigned.
514 static s32
fm10k_configure_dglort_map_pf(struct fm10k_hw
*hw
,
515 struct fm10k_dglort_cfg
*dglort
)
517 u16 glort
, queue_count
, vsi_count
, pc_count
;
518 u16 vsi
, queue
, pc
, q_idx
;
519 u32 txqctl
, dglortdec
, dglortmap
;
521 /* verify the dglort pointer */
523 return FM10K_ERR_PARAM
;
525 /* verify the dglort values */
526 if ((dglort
->idx
> 7) || (dglort
->rss_l
> 7) || (dglort
->pc_l
> 3) ||
527 (dglort
->vsi_l
> 6) || (dglort
->vsi_b
> 64) ||
528 (dglort
->queue_l
> 8) || (dglort
->queue_b
>= 256))
529 return FM10K_ERR_PARAM
;
531 /* determine count of VSIs and queues */
532 queue_count
= 1 << (dglort
->rss_l
+ dglort
->pc_l
);
533 vsi_count
= 1 << (dglort
->vsi_l
+ dglort
->queue_l
);
534 glort
= dglort
->glort
;
535 q_idx
= dglort
->queue_b
;
537 /* configure SGLORT for queues */
538 for (vsi
= 0; vsi
< vsi_count
; vsi
++, glort
++) {
539 for (queue
= 0; queue
< queue_count
; queue
++, q_idx
++) {
540 if (q_idx
>= FM10K_MAX_QUEUES
)
543 fm10k_write_reg(hw
, FM10K_TX_SGLORT(q_idx
), glort
);
544 fm10k_write_reg(hw
, FM10K_RX_SGLORT(q_idx
), glort
);
548 /* determine count of PCs and queues */
549 queue_count
= 1 << (dglort
->queue_l
+ dglort
->rss_l
+ dglort
->vsi_l
);
550 pc_count
= 1 << dglort
->pc_l
;
552 /* configure PC for Tx queues */
553 for (pc
= 0; pc
< pc_count
; pc
++) {
554 q_idx
= pc
+ dglort
->queue_b
;
555 for (queue
= 0; queue
< queue_count
; queue
++) {
556 if (q_idx
>= FM10K_MAX_QUEUES
)
559 txqctl
= fm10k_read_reg(hw
, FM10K_TXQCTL(q_idx
));
560 txqctl
&= ~FM10K_TXQCTL_PC_MASK
;
561 txqctl
|= pc
<< FM10K_TXQCTL_PC_SHIFT
;
562 fm10k_write_reg(hw
, FM10K_TXQCTL(q_idx
), txqctl
);
568 /* configure DGLORTDEC */
569 dglortdec
= ((u32
)(dglort
->rss_l
) << FM10K_DGLORTDEC_RSSLENGTH_SHIFT
) |
570 ((u32
)(dglort
->queue_b
) << FM10K_DGLORTDEC_QBASE_SHIFT
) |
571 ((u32
)(dglort
->pc_l
) << FM10K_DGLORTDEC_PCLENGTH_SHIFT
) |
572 ((u32
)(dglort
->vsi_b
) << FM10K_DGLORTDEC_VSIBASE_SHIFT
) |
573 ((u32
)(dglort
->vsi_l
) << FM10K_DGLORTDEC_VSILENGTH_SHIFT
) |
574 ((u32
)(dglort
->queue_l
));
575 if (dglort
->inner_rss
)
576 dglortdec
|= FM10K_DGLORTDEC_INNERRSS_ENABLE
;
578 /* configure DGLORTMAP */
579 dglortmap
= (dglort
->idx
== fm10k_dglort_default
) ?
580 FM10K_DGLORTMAP_ANY
: FM10K_DGLORTMAP_ZERO
;
581 dglortmap
<<= dglort
->vsi_l
+ dglort
->queue_l
+ dglort
->shared_l
;
582 dglortmap
|= dglort
->glort
;
584 /* write values to hardware */
585 fm10k_write_reg(hw
, FM10K_DGLORTDEC(dglort
->idx
), dglortdec
);
586 fm10k_write_reg(hw
, FM10K_DGLORTMAP(dglort
->idx
), dglortmap
);
591 u16
fm10k_queues_per_pool(struct fm10k_hw
*hw
)
593 u16 num_pools
= hw
->iov
.num_pools
;
595 return (num_pools
> 32) ? 2 : (num_pools
> 16) ? 4 : (num_pools
> 8) ?
596 8 : FM10K_MAX_QUEUES_POOL
;
599 u16
fm10k_vf_queue_index(struct fm10k_hw
*hw
, u16 vf_idx
)
601 u16 num_vfs
= hw
->iov
.num_vfs
;
602 u16 vf_q_idx
= FM10K_MAX_QUEUES
;
604 vf_q_idx
-= fm10k_queues_per_pool(hw
) * (num_vfs
- vf_idx
);
609 static u16
fm10k_vectors_per_pool(struct fm10k_hw
*hw
)
611 u16 num_pools
= hw
->iov
.num_pools
;
613 return (num_pools
> 32) ? 8 : (num_pools
> 16) ? 16 :
614 FM10K_MAX_VECTORS_POOL
;
617 static u16
fm10k_vf_vector_index(struct fm10k_hw
*hw
, u16 vf_idx
)
619 u16 vf_v_idx
= FM10K_MAX_VECTORS_PF
;
621 vf_v_idx
+= fm10k_vectors_per_pool(hw
) * vf_idx
;
627 * fm10k_iov_assign_resources_pf - Assign pool resources for virtualization
628 * @hw: pointer to the HW structure
629 * @num_vfs: number of VFs to be allocated
630 * @num_pools: number of virtualization pools to be allocated
632 * Allocates queues and traffic classes to virtualization entities to prepare
633 * the PF for SR-IOV and VMDq
635 static s32
fm10k_iov_assign_resources_pf(struct fm10k_hw
*hw
, u16 num_vfs
,
638 u16 qmap_stride
, qpp
, vpp
, vf_q_idx
, vf_q_idx0
, qmap_idx
;
639 u32 vid
= hw
->mac
.default_vid
<< FM10K_TXQCTL_VID_SHIFT
;
642 /* hardware only supports up to 64 pools */
644 return FM10K_ERR_PARAM
;
646 /* the number of VFs cannot exceed the number of pools */
647 if ((num_vfs
> num_pools
) || (num_vfs
> hw
->iov
.total_vfs
))
648 return FM10K_ERR_PARAM
;
650 /* record number of virtualization entities */
651 hw
->iov
.num_vfs
= num_vfs
;
652 hw
->iov
.num_pools
= num_pools
;
654 /* determine qmap offsets and counts */
655 qmap_stride
= (num_vfs
> 8) ? 32 : 256;
656 qpp
= fm10k_queues_per_pool(hw
);
657 vpp
= fm10k_vectors_per_pool(hw
);
659 /* calculate starting index for queues */
660 vf_q_idx
= fm10k_vf_queue_index(hw
, 0);
663 /* establish TCs with -1 credits and no quanta to prevent transmit */
664 for (i
= 0; i
< num_vfs
; i
++) {
665 fm10k_write_reg(hw
, FM10K_TC_MAXCREDIT(i
), 0);
666 fm10k_write_reg(hw
, FM10K_TC_RATE(i
), 0);
667 fm10k_write_reg(hw
, FM10K_TC_CREDIT(i
),
668 FM10K_TC_CREDIT_CREDIT_MASK
);
671 /* zero out all mbmem registers */
672 for (i
= FM10K_VFMBMEM_LEN
* num_vfs
; i
--;)
673 fm10k_write_reg(hw
, FM10K_MBMEM(i
), 0);
675 /* clear event notification of VF FLR */
676 fm10k_write_reg(hw
, FM10K_PFVFLREC(0), ~0);
677 fm10k_write_reg(hw
, FM10K_PFVFLREC(1), ~0);
679 /* loop through unallocated rings assigning them back to PF */
680 for (i
= FM10K_MAX_QUEUES_PF
; i
< vf_q_idx
; i
++) {
681 fm10k_write_reg(hw
, FM10K_TXDCTL(i
), 0);
682 fm10k_write_reg(hw
, FM10K_TXQCTL(i
), FM10K_TXQCTL_PF
|
683 FM10K_TXQCTL_UNLIMITED_BW
| vid
);
684 fm10k_write_reg(hw
, FM10K_RXQCTL(i
), FM10K_RXQCTL_PF
);
687 /* PF should have already updated VFITR2[0] */
689 /* update all ITR registers to flow to VFITR2[0] */
690 for (i
= FM10K_ITR_REG_COUNT_PF
+ 1; i
< FM10K_ITR_REG_COUNT
; i
++) {
691 if (!(i
& (vpp
- 1)))
692 fm10k_write_reg(hw
, FM10K_ITR2(i
), i
- vpp
);
694 fm10k_write_reg(hw
, FM10K_ITR2(i
), i
- 1);
697 /* update PF ITR2[0] to reference the last vector */
698 fm10k_write_reg(hw
, FM10K_ITR2(0),
699 fm10k_vf_vector_index(hw
, num_vfs
- 1));
701 /* loop through rings populating rings and TCs */
702 for (i
= 0; i
< num_vfs
; i
++) {
703 /* record index for VF queue 0 for use in end of loop */
704 vf_q_idx0
= vf_q_idx
;
706 for (j
= 0; j
< qpp
; j
++, qmap_idx
++, vf_q_idx
++) {
707 /* assign VF and locked TC to queues */
708 fm10k_write_reg(hw
, FM10K_TXDCTL(vf_q_idx
), 0);
709 fm10k_write_reg(hw
, FM10K_TXQCTL(vf_q_idx
),
710 (i
<< FM10K_TXQCTL_TC_SHIFT
) | i
|
711 FM10K_TXQCTL_VF
| vid
);
712 fm10k_write_reg(hw
, FM10K_RXDCTL(vf_q_idx
),
713 FM10K_RXDCTL_WRITE_BACK_MIN_DELAY
|
714 FM10K_RXDCTL_DROP_ON_EMPTY
);
715 fm10k_write_reg(hw
, FM10K_RXQCTL(vf_q_idx
),
717 (i
<< FM10K_RXQCTL_VF_SHIFT
));
719 /* map queue pair to VF */
720 fm10k_write_reg(hw
, FM10K_TQMAP(qmap_idx
), vf_q_idx
);
721 fm10k_write_reg(hw
, FM10K_RQMAP(qmap_idx
), vf_q_idx
);
724 /* repeat the first ring for all of the remaining VF rings */
725 for (; j
< qmap_stride
; j
++, qmap_idx
++) {
726 fm10k_write_reg(hw
, FM10K_TQMAP(qmap_idx
), vf_q_idx0
);
727 fm10k_write_reg(hw
, FM10K_RQMAP(qmap_idx
), vf_q_idx0
);
731 /* loop through remaining indexes assigning all to queue 0 */
732 while (qmap_idx
< FM10K_TQMAP_TABLE_SIZE
) {
733 fm10k_write_reg(hw
, FM10K_TQMAP(qmap_idx
), 0);
734 fm10k_write_reg(hw
, FM10K_RQMAP(qmap_idx
), 0);
742 * fm10k_iov_configure_tc_pf - Configure the shaping group for VF
743 * @hw: pointer to the HW structure
744 * @vf_idx: index of VF receiving GLORT
745 * @rate: Rate indicated in Mb/s
747 * Configured the TC for a given VF to allow only up to a given number
748 * of Mb/s of outgoing Tx throughput.
750 static s32
fm10k_iov_configure_tc_pf(struct fm10k_hw
*hw
, u16 vf_idx
, int rate
)
752 /* configure defaults */
753 u32 interval
= FM10K_TC_RATE_INTERVAL_4US_GEN3
;
754 u32 tc_rate
= FM10K_TC_RATE_QUANTA_MASK
;
756 /* verify vf is in range */
757 if (vf_idx
>= hw
->iov
.num_vfs
)
758 return FM10K_ERR_PARAM
;
760 /* set interval to align with 4.096 usec in all modes */
761 switch (hw
->bus
.speed
) {
762 case fm10k_bus_speed_2500
:
763 interval
= FM10K_TC_RATE_INTERVAL_4US_GEN1
;
765 case fm10k_bus_speed_5000
:
766 interval
= FM10K_TC_RATE_INTERVAL_4US_GEN2
;
773 if (rate
> FM10K_VF_TC_MAX
|| rate
< FM10K_VF_TC_MIN
)
774 return FM10K_ERR_PARAM
;
776 /* The quanta is measured in Bytes per 4.096 or 8.192 usec
777 * The rate is provided in Mbits per second
778 * To tralslate from rate to quanta we need to multiply the
779 * rate by 8.192 usec and divide by 8 bits/byte. To avoid
780 * dealing with floating point we can round the values up
781 * to the nearest whole number ratio which gives us 128 / 125.
783 tc_rate
= (rate
* 128) / 125;
785 /* try to keep the rate limiting accurate by increasing
786 * the number of credits and interval for rates less than 4Gb/s
794 /* update rate limiter with new values */
795 fm10k_write_reg(hw
, FM10K_TC_RATE(vf_idx
), tc_rate
| interval
);
796 fm10k_write_reg(hw
, FM10K_TC_MAXCREDIT(vf_idx
), FM10K_TC_MAXCREDIT_64K
);
797 fm10k_write_reg(hw
, FM10K_TC_CREDIT(vf_idx
), FM10K_TC_MAXCREDIT_64K
);
803 * fm10k_iov_assign_int_moderator_pf - Add VF interrupts to moderator list
804 * @hw: pointer to the HW structure
805 * @vf_idx: index of VF receiving GLORT
807 * Update the interrupt moderator linked list to include any MSI-X
808 * interrupts which the VF has enabled in the MSI-X vector table.
810 static s32
fm10k_iov_assign_int_moderator_pf(struct fm10k_hw
*hw
, u16 vf_idx
)
812 u16 vf_v_idx
, vf_v_limit
, i
;
814 /* verify vf is in range */
815 if (vf_idx
>= hw
->iov
.num_vfs
)
816 return FM10K_ERR_PARAM
;
818 /* determine vector offset and count */
819 vf_v_idx
= fm10k_vf_vector_index(hw
, vf_idx
);
820 vf_v_limit
= vf_v_idx
+ fm10k_vectors_per_pool(hw
);
822 /* search for first vector that is not masked */
823 for (i
= vf_v_limit
- 1; i
> vf_v_idx
; i
--) {
824 if (!fm10k_read_reg(hw
, FM10K_MSIX_VECTOR_MASK(i
)))
828 /* reset linked list so it now includes our active vectors */
829 if (vf_idx
== (hw
->iov
.num_vfs
- 1))
830 fm10k_write_reg(hw
, FM10K_ITR2(0), i
);
832 fm10k_write_reg(hw
, FM10K_ITR2(vf_v_limit
), i
);
838 * fm10k_iov_assign_default_mac_vlan_pf - Assign a MAC and VLAN to VF
839 * @hw: pointer to the HW structure
840 * @vf_info: pointer to VF information structure
842 * Assign a MAC address and default VLAN to a VF and notify it of the update
844 static s32
fm10k_iov_assign_default_mac_vlan_pf(struct fm10k_hw
*hw
,
845 struct fm10k_vf_info
*vf_info
)
847 u16 qmap_stride
, queues_per_pool
, vf_q_idx
, timeout
, qmap_idx
, i
;
848 u32 msg
[4], txdctl
, txqctl
, tdbal
= 0, tdbah
= 0;
852 /* verify vf is in range */
853 if (!vf_info
|| vf_info
->vf_idx
>= hw
->iov
.num_vfs
)
854 return FM10K_ERR_PARAM
;
856 /* determine qmap offsets and counts */
857 qmap_stride
= (hw
->iov
.num_vfs
> 8) ? 32 : 256;
858 queues_per_pool
= fm10k_queues_per_pool(hw
);
860 /* calculate starting index for queues */
861 vf_idx
= vf_info
->vf_idx
;
862 vf_q_idx
= fm10k_vf_queue_index(hw
, vf_idx
);
863 qmap_idx
= qmap_stride
* vf_idx
;
865 /* MAP Tx queue back to 0 temporarily, and disable it */
866 fm10k_write_reg(hw
, FM10K_TQMAP(qmap_idx
), 0);
867 fm10k_write_reg(hw
, FM10K_TXDCTL(vf_q_idx
), 0);
869 /* determine correct default VLAN ID */
871 vf_vid
= vf_info
->pf_vid
| FM10K_VLAN_CLEAR
;
873 vf_vid
= vf_info
->sw_vid
;
875 /* generate MAC_ADDR request */
876 fm10k_tlv_msg_init(msg
, FM10K_VF_MSG_ID_MAC_VLAN
);
877 fm10k_tlv_attr_put_mac_vlan(msg
, FM10K_MAC_VLAN_MSG_DEFAULT_MAC
,
878 vf_info
->mac
, vf_vid
);
880 /* load onto outgoing mailbox, ignore any errors on enqueue */
881 if (vf_info
->mbx
.ops
.enqueue_tx
)
882 vf_info
->mbx
.ops
.enqueue_tx(hw
, &vf_info
->mbx
, msg
);
884 /* verify ring has disabled before modifying base address registers */
885 txdctl
= fm10k_read_reg(hw
, FM10K_TXDCTL(vf_q_idx
));
886 for (timeout
= 0; txdctl
& FM10K_TXDCTL_ENABLE
; timeout
++) {
887 /* limit ourselves to a 1ms timeout */
889 err
= FM10K_ERR_DMA_PENDING
;
893 usleep_range(100, 200);
894 txdctl
= fm10k_read_reg(hw
, FM10K_TXDCTL(vf_q_idx
));
897 /* Update base address registers to contain MAC address */
898 if (is_valid_ether_addr(vf_info
->mac
)) {
899 tdbal
= (((u32
)vf_info
->mac
[3]) << 24) |
900 (((u32
)vf_info
->mac
[4]) << 16) |
901 (((u32
)vf_info
->mac
[5]) << 8);
903 tdbah
= (((u32
)0xFF) << 24) |
904 (((u32
)vf_info
->mac
[0]) << 16) |
905 (((u32
)vf_info
->mac
[1]) << 8) |
906 ((u32
)vf_info
->mac
[2]);
909 /* Record the base address into queue 0 */
910 fm10k_write_reg(hw
, FM10K_TDBAL(vf_q_idx
), tdbal
);
911 fm10k_write_reg(hw
, FM10K_TDBAH(vf_q_idx
), tdbah
);
914 /* configure Queue control register */
915 txqctl
= ((u32
)vf_vid
<< FM10K_TXQCTL_VID_SHIFT
) &
916 FM10K_TXQCTL_VID_MASK
;
917 txqctl
|= (vf_idx
<< FM10K_TXQCTL_TC_SHIFT
) |
918 FM10K_TXQCTL_VF
| vf_idx
;
921 for (i
= 0; i
< queues_per_pool
; i
++)
922 fm10k_write_reg(hw
, FM10K_TXQCTL(vf_q_idx
+ i
), txqctl
);
924 /* restore the queue back to VF ownership */
925 fm10k_write_reg(hw
, FM10K_TQMAP(qmap_idx
), vf_q_idx
);
930 * fm10k_iov_reset_resources_pf - Reassign queues and interrupts to a VF
931 * @hw: pointer to the HW structure
932 * @vf_info: pointer to VF information structure
934 * Reassign the interrupts and queues to a VF following an FLR
936 static s32
fm10k_iov_reset_resources_pf(struct fm10k_hw
*hw
,
937 struct fm10k_vf_info
*vf_info
)
939 u16 qmap_stride
, queues_per_pool
, vf_q_idx
, qmap_idx
;
940 u32 tdbal
= 0, tdbah
= 0, txqctl
, rxqctl
;
941 u16 vf_v_idx
, vf_v_limit
, vf_vid
;
942 u8 vf_idx
= vf_info
->vf_idx
;
945 /* verify vf is in range */
946 if (vf_idx
>= hw
->iov
.num_vfs
)
947 return FM10K_ERR_PARAM
;
949 /* clear event notification of VF FLR */
950 fm10k_write_reg(hw
, FM10K_PFVFLREC(vf_idx
/ 32), 1 << (vf_idx
% 32));
952 /* force timeout and then disconnect the mailbox */
953 vf_info
->mbx
.timeout
= 0;
954 if (vf_info
->mbx
.ops
.disconnect
)
955 vf_info
->mbx
.ops
.disconnect(hw
, &vf_info
->mbx
);
957 /* determine vector offset and count */
958 vf_v_idx
= fm10k_vf_vector_index(hw
, vf_idx
);
959 vf_v_limit
= vf_v_idx
+ fm10k_vectors_per_pool(hw
);
961 /* determine qmap offsets and counts */
962 qmap_stride
= (hw
->iov
.num_vfs
> 8) ? 32 : 256;
963 queues_per_pool
= fm10k_queues_per_pool(hw
);
964 qmap_idx
= qmap_stride
* vf_idx
;
966 /* make all the queues inaccessible to the VF */
967 for (i
= qmap_idx
; i
< (qmap_idx
+ qmap_stride
); i
++) {
968 fm10k_write_reg(hw
, FM10K_TQMAP(i
), 0);
969 fm10k_write_reg(hw
, FM10K_RQMAP(i
), 0);
972 /* calculate starting index for queues */
973 vf_q_idx
= fm10k_vf_queue_index(hw
, vf_idx
);
975 /* determine correct default VLAN ID */
977 vf_vid
= vf_info
->pf_vid
;
979 vf_vid
= vf_info
->sw_vid
;
981 /* configure Queue control register */
982 txqctl
= ((u32
)vf_vid
<< FM10K_TXQCTL_VID_SHIFT
) |
983 (vf_idx
<< FM10K_TXQCTL_TC_SHIFT
) |
984 FM10K_TXQCTL_VF
| vf_idx
;
985 rxqctl
= FM10K_RXQCTL_VF
| (vf_idx
<< FM10K_RXQCTL_VF_SHIFT
);
987 /* stop further DMA and reset queue ownership back to VF */
988 for (i
= vf_q_idx
; i
< (queues_per_pool
+ vf_q_idx
); i
++) {
989 fm10k_write_reg(hw
, FM10K_TXDCTL(i
), 0);
990 fm10k_write_reg(hw
, FM10K_TXQCTL(i
), txqctl
);
991 fm10k_write_reg(hw
, FM10K_RXDCTL(i
),
992 FM10K_RXDCTL_WRITE_BACK_MIN_DELAY
|
993 FM10K_RXDCTL_DROP_ON_EMPTY
);
994 fm10k_write_reg(hw
, FM10K_RXQCTL(i
), rxqctl
);
997 /* reset TC with -1 credits and no quanta to prevent transmit */
998 fm10k_write_reg(hw
, FM10K_TC_MAXCREDIT(vf_idx
), 0);
999 fm10k_write_reg(hw
, FM10K_TC_RATE(vf_idx
), 0);
1000 fm10k_write_reg(hw
, FM10K_TC_CREDIT(vf_idx
),
1001 FM10K_TC_CREDIT_CREDIT_MASK
);
1003 /* update our first entry in the table based on previous VF */
1005 hw
->mac
.ops
.update_int_moderator(hw
);
1007 hw
->iov
.ops
.assign_int_moderator(hw
, vf_idx
- 1);
1009 /* reset linked list so it now includes our active vectors */
1010 if (vf_idx
== (hw
->iov
.num_vfs
- 1))
1011 fm10k_write_reg(hw
, FM10K_ITR2(0), vf_v_idx
);
1013 fm10k_write_reg(hw
, FM10K_ITR2(vf_v_limit
), vf_v_idx
);
1015 /* link remaining vectors so that next points to previous */
1016 for (vf_v_idx
++; vf_v_idx
< vf_v_limit
; vf_v_idx
++)
1017 fm10k_write_reg(hw
, FM10K_ITR2(vf_v_idx
), vf_v_idx
- 1);
1019 /* zero out MBMEM, VLAN_TABLE, RETA, RSSRK, and MRQC registers */
1020 for (i
= FM10K_VFMBMEM_LEN
; i
--;)
1021 fm10k_write_reg(hw
, FM10K_MBMEM_VF(vf_idx
, i
), 0);
1022 for (i
= FM10K_VLAN_TABLE_SIZE
; i
--;)
1023 fm10k_write_reg(hw
, FM10K_VLAN_TABLE(vf_info
->vsi
, i
), 0);
1024 for (i
= FM10K_RETA_SIZE
; i
--;)
1025 fm10k_write_reg(hw
, FM10K_RETA(vf_info
->vsi
, i
), 0);
1026 for (i
= FM10K_RSSRK_SIZE
; i
--;)
1027 fm10k_write_reg(hw
, FM10K_RSSRK(vf_info
->vsi
, i
), 0);
1028 fm10k_write_reg(hw
, FM10K_MRQC(vf_info
->vsi
), 0);
1030 /* Update base address registers to contain MAC address */
1031 if (is_valid_ether_addr(vf_info
->mac
)) {
1032 tdbal
= (((u32
)vf_info
->mac
[3]) << 24) |
1033 (((u32
)vf_info
->mac
[4]) << 16) |
1034 (((u32
)vf_info
->mac
[5]) << 8);
1035 tdbah
= (((u32
)0xFF) << 24) |
1036 (((u32
)vf_info
->mac
[0]) << 16) |
1037 (((u32
)vf_info
->mac
[1]) << 8) |
1038 ((u32
)vf_info
->mac
[2]);
1041 /* map queue pairs back to VF from last to first */
1042 for (i
= queues_per_pool
; i
--;) {
1043 fm10k_write_reg(hw
, FM10K_TDBAL(vf_q_idx
+ i
), tdbal
);
1044 fm10k_write_reg(hw
, FM10K_TDBAH(vf_q_idx
+ i
), tdbah
);
1045 fm10k_write_reg(hw
, FM10K_TQMAP(qmap_idx
+ i
), vf_q_idx
+ i
);
1046 fm10k_write_reg(hw
, FM10K_RQMAP(qmap_idx
+ i
), vf_q_idx
+ i
);
1049 /* repeat the first ring for all the remaining VF rings */
1050 for (i
= queues_per_pool
; i
< qmap_stride
; i
++) {
1051 fm10k_write_reg(hw
, FM10K_TQMAP(qmap_idx
+ i
), vf_q_idx
);
1052 fm10k_write_reg(hw
, FM10K_RQMAP(qmap_idx
+ i
), vf_q_idx
);
1059 * fm10k_iov_set_lport_pf - Assign and enable a logical port for a given VF
1060 * @hw: pointer to hardware structure
1061 * @vf_info: pointer to VF information structure
1062 * @lport_idx: Logical port offset from the hardware glort
1063 * @flags: Set of capability flags to extend port beyond basic functionality
1065 * This function allows enabling a VF port by assigning it a GLORT and
1066 * setting the flags so that it can enable an Rx mode.
1068 static s32
fm10k_iov_set_lport_pf(struct fm10k_hw
*hw
,
1069 struct fm10k_vf_info
*vf_info
,
1070 u16 lport_idx
, u8 flags
)
1072 u16 glort
= (hw
->mac
.dglort_map
+ lport_idx
) & FM10K_DGLORTMAP_NONE
;
1074 /* if glort is not valid return error */
1075 if (!fm10k_glort_valid_pf(hw
, glort
))
1076 return FM10K_ERR_PARAM
;
1078 vf_info
->vf_flags
= flags
| FM10K_VF_FLAG_NONE_CAPABLE
;
1079 vf_info
->glort
= glort
;
1085 * fm10k_iov_reset_lport_pf - Disable a logical port for a given VF
1086 * @hw: pointer to hardware structure
1087 * @vf_info: pointer to VF information structure
1089 * This function disables a VF port by stripping it of a GLORT and
1090 * setting the flags so that it cannot enable any Rx mode.
1092 static void fm10k_iov_reset_lport_pf(struct fm10k_hw
*hw
,
1093 struct fm10k_vf_info
*vf_info
)
1097 /* need to disable the port if it is already enabled */
1098 if (FM10K_VF_FLAG_ENABLED(vf_info
)) {
1099 /* notify switch that this port has been disabled */
1100 fm10k_update_lport_state_pf(hw
, vf_info
->glort
, 1, false);
1102 /* generate port state response to notify VF it is not ready */
1103 fm10k_tlv_msg_init(msg
, FM10K_VF_MSG_ID_LPORT_STATE
);
1104 vf_info
->mbx
.ops
.enqueue_tx(hw
, &vf_info
->mbx
, msg
);
1107 /* clear flags and glort if it exists */
1108 vf_info
->vf_flags
= 0;
1113 * fm10k_iov_update_stats_pf - Updates hardware related statistics for VFs
1114 * @hw: pointer to hardware structure
1115 * @q: stats for all queues of a VF
1116 * @vf_idx: index of VF
1118 * This function collects queue stats for VFs.
1120 static void fm10k_iov_update_stats_pf(struct fm10k_hw
*hw
,
1121 struct fm10k_hw_stats_q
*q
,
1126 /* get stats for all of the queues */
1127 qpp
= fm10k_queues_per_pool(hw
);
1128 idx
= fm10k_vf_queue_index(hw
, vf_idx
);
1129 fm10k_update_hw_stats_q(hw
, q
, idx
, qpp
);
1132 static s32
fm10k_iov_report_timestamp_pf(struct fm10k_hw
*hw
,
1133 struct fm10k_vf_info
*vf_info
,
1138 /* generate port state response to notify VF it is not ready */
1139 fm10k_tlv_msg_init(msg
, FM10K_VF_MSG_ID_1588
);
1140 fm10k_tlv_attr_put_u64(msg
, FM10K_1588_MSG_TIMESTAMP
, timestamp
);
1142 return vf_info
->mbx
.ops
.enqueue_tx(hw
, &vf_info
->mbx
, msg
);
1146 * fm10k_iov_msg_msix_pf - Message handler for MSI-X request from VF
1147 * @hw: Pointer to hardware structure
1148 * @results: Pointer array to message, results[0] is pointer to message
1149 * @mbx: Pointer to mailbox information structure
1151 * This function is a default handler for MSI-X requests from the VF. The
1152 * assumption is that in this case it is acceptable to just directly
1153 * hand off the message from the VF to the underlying shared code.
1155 s32
fm10k_iov_msg_msix_pf(struct fm10k_hw
*hw
, u32
**results
,
1156 struct fm10k_mbx_info
*mbx
)
1158 struct fm10k_vf_info
*vf_info
= (struct fm10k_vf_info
*)mbx
;
1159 u8 vf_idx
= vf_info
->vf_idx
;
1161 return hw
->iov
.ops
.assign_int_moderator(hw
, vf_idx
);
1165 * fm10k_iov_msg_mac_vlan_pf - Message handler for MAC/VLAN request from VF
1166 * @hw: Pointer to hardware structure
1167 * @results: Pointer array to message, results[0] is pointer to message
1168 * @mbx: Pointer to mailbox information structure
1170 * This function is a default handler for MAC/VLAN requests from the VF.
1171 * The assumption is that in this case it is acceptable to just directly
1172 * hand off the message from the VF to the underlying shared code.
1174 s32
fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw
*hw
, u32
**results
,
1175 struct fm10k_mbx_info
*mbx
)
1177 struct fm10k_vf_info
*vf_info
= (struct fm10k_vf_info
*)mbx
;
1184 /* we shouldn't be updating rules on a disabled interface */
1185 if (!FM10K_VF_FLAG_ENABLED(vf_info
))
1186 err
= FM10K_ERR_PARAM
;
1188 if (!err
&& !!results
[FM10K_MAC_VLAN_MSG_VLAN
]) {
1189 result
= results
[FM10K_MAC_VLAN_MSG_VLAN
];
1191 /* record VLAN id requested */
1192 err
= fm10k_tlv_attr_get_u32(result
, &vid
);
1196 /* if VLAN ID is 0, set the default VLAN ID instead of 0 */
1197 if (!vid
|| (vid
== FM10K_VLAN_CLEAR
)) {
1198 if (vf_info
->pf_vid
)
1199 vid
|= vf_info
->pf_vid
;
1201 vid
|= vf_info
->sw_vid
;
1202 } else if (vid
!= vf_info
->pf_vid
) {
1203 return FM10K_ERR_PARAM
;
1206 /* update VSI info for VF in regards to VLAN table */
1207 err
= hw
->mac
.ops
.update_vlan(hw
, vid
, vf_info
->vsi
,
1208 !(vid
& FM10K_VLAN_CLEAR
));
1211 if (!err
&& !!results
[FM10K_MAC_VLAN_MSG_MAC
]) {
1212 result
= results
[FM10K_MAC_VLAN_MSG_MAC
];
1214 /* record unicast MAC address requested */
1215 err
= fm10k_tlv_attr_get_mac_vlan(result
, mac
, &vlan
);
1219 /* block attempts to set MAC for a locked device */
1220 if (is_valid_ether_addr(vf_info
->mac
) &&
1221 memcmp(mac
, vf_info
->mac
, ETH_ALEN
))
1222 return FM10K_ERR_PARAM
;
1224 /* if VLAN ID is 0, set the default VLAN ID instead of 0 */
1225 if (!vlan
|| (vlan
== FM10K_VLAN_CLEAR
)) {
1226 if (vf_info
->pf_vid
)
1227 vlan
|= vf_info
->pf_vid
;
1229 vlan
|= vf_info
->sw_vid
;
1230 } else if (vf_info
->pf_vid
) {
1231 return FM10K_ERR_PARAM
;
1234 /* notify switch of request for new unicast address */
1235 err
= hw
->mac
.ops
.update_uc_addr(hw
, vf_info
->glort
, mac
, vlan
,
1236 !(vlan
& FM10K_VLAN_CLEAR
), 0);
1239 if (!err
&& !!results
[FM10K_MAC_VLAN_MSG_MULTICAST
]) {
1240 result
= results
[FM10K_MAC_VLAN_MSG_MULTICAST
];
1242 /* record multicast MAC address requested */
1243 err
= fm10k_tlv_attr_get_mac_vlan(result
, mac
, &vlan
);
1247 /* verify that the VF is allowed to request multicast */
1248 if (!(vf_info
->vf_flags
& FM10K_VF_FLAG_MULTI_ENABLED
))
1249 return FM10K_ERR_PARAM
;
1251 /* if VLAN ID is 0, set the default VLAN ID instead of 0 */
1252 if (!vlan
|| (vlan
== FM10K_VLAN_CLEAR
)) {
1253 if (vf_info
->pf_vid
)
1254 vlan
|= vf_info
->pf_vid
;
1256 vlan
|= vf_info
->sw_vid
;
1257 } else if (vf_info
->pf_vid
) {
1258 return FM10K_ERR_PARAM
;
1261 /* notify switch of request for new multicast address */
1262 err
= hw
->mac
.ops
.update_mc_addr(hw
, vf_info
->glort
, mac
, vlan
,
1263 !(vlan
& FM10K_VLAN_CLEAR
));
1270 * fm10k_iov_supported_xcast_mode_pf - Determine best match for xcast mode
1271 * @vf_info: VF info structure containing capability flags
1272 * @mode: Requested xcast mode
1274 * This function outputs the mode that most closely matches the requested
1275 * mode. If not modes match it will request we disable the port
1277 static u8
fm10k_iov_supported_xcast_mode_pf(struct fm10k_vf_info
*vf_info
,
1280 u8 vf_flags
= vf_info
->vf_flags
;
1282 /* match up mode to capabilities as best as possible */
1284 case FM10K_XCAST_MODE_PROMISC
:
1285 if (vf_flags
& FM10K_VF_FLAG_PROMISC_CAPABLE
)
1286 return FM10K_XCAST_MODE_PROMISC
;
1288 case FM10K_XCAST_MODE_ALLMULTI
:
1289 if (vf_flags
& FM10K_VF_FLAG_ALLMULTI_CAPABLE
)
1290 return FM10K_XCAST_MODE_ALLMULTI
;
1292 case FM10K_XCAST_MODE_MULTI
:
1293 if (vf_flags
& FM10K_VF_FLAG_MULTI_CAPABLE
)
1294 return FM10K_XCAST_MODE_MULTI
;
1296 case FM10K_XCAST_MODE_NONE
:
1297 if (vf_flags
& FM10K_VF_FLAG_NONE_CAPABLE
)
1298 return FM10K_XCAST_MODE_NONE
;
1304 /* disable interface as it should not be able to request any */
1305 return FM10K_XCAST_MODE_DISABLE
;
1309 * fm10k_iov_msg_lport_state_pf - Message handler for port state requests
1310 * @hw: Pointer to hardware structure
1311 * @results: Pointer array to message, results[0] is pointer to message
1312 * @mbx: Pointer to mailbox information structure
1314 * This function is a default handler for port state requests. The port
1315 * state requests for now are basic and consist of enabling or disabling
1318 s32
fm10k_iov_msg_lport_state_pf(struct fm10k_hw
*hw
, u32
**results
,
1319 struct fm10k_mbx_info
*mbx
)
1321 struct fm10k_vf_info
*vf_info
= (struct fm10k_vf_info
*)mbx
;
1327 /* verify VF is allowed to enable even minimal mode */
1328 if (!(vf_info
->vf_flags
& FM10K_VF_FLAG_NONE_CAPABLE
))
1329 return FM10K_ERR_PARAM
;
1331 if (!!results
[FM10K_LPORT_STATE_MSG_XCAST_MODE
]) {
1332 result
= results
[FM10K_LPORT_STATE_MSG_XCAST_MODE
];
1334 /* XCAST mode update requested */
1335 err
= fm10k_tlv_attr_get_u8(result
, &mode
);
1337 return FM10K_ERR_PARAM
;
1339 /* prep for possible demotion depending on capabilities */
1340 mode
= fm10k_iov_supported_xcast_mode_pf(vf_info
, mode
);
1342 /* if mode is not currently enabled, enable it */
1343 if (!(FM10K_VF_FLAG_ENABLED(vf_info
) & (1 << mode
)))
1344 fm10k_update_xcast_mode_pf(hw
, vf_info
->glort
, mode
);
1346 /* swap mode back to a bit flag */
1347 mode
= FM10K_VF_FLAG_SET_MODE(mode
);
1348 } else if (!results
[FM10K_LPORT_STATE_MSG_DISABLE
]) {
1349 /* need to disable the port if it is already enabled */
1350 if (FM10K_VF_FLAG_ENABLED(vf_info
))
1351 err
= fm10k_update_lport_state_pf(hw
, vf_info
->glort
,
1354 /* we need to clear VF_FLAG_ENABLED flags in order to ensure
1355 * that we actually re-enable the LPORT state below. Note that
1356 * this has no impact if the VF is already disabled, as the
1357 * flags are already cleared.
1360 vf_info
->vf_flags
= FM10K_VF_FLAG_CAPABLE(vf_info
);
1362 /* when enabling the port we should reset the rate limiters */
1363 hw
->iov
.ops
.configure_tc(hw
, vf_info
->vf_idx
, vf_info
->rate
);
1365 /* set mode for minimal functionality */
1366 mode
= FM10K_VF_FLAG_SET_MODE_NONE
;
1368 /* generate port state response to notify VF it is ready */
1369 fm10k_tlv_msg_init(msg
, FM10K_VF_MSG_ID_LPORT_STATE
);
1370 fm10k_tlv_attr_put_bool(msg
, FM10K_LPORT_STATE_MSG_READY
);
1371 mbx
->ops
.enqueue_tx(hw
, mbx
, msg
);
1374 /* if enable state toggled note the update */
1375 if (!err
&& (!FM10K_VF_FLAG_ENABLED(vf_info
) != !mode
))
1376 err
= fm10k_update_lport_state_pf(hw
, vf_info
->glort
, 1,
1379 /* if state change succeeded, then update our stored state */
1380 mode
|= FM10K_VF_FLAG_CAPABLE(vf_info
);
1382 vf_info
->vf_flags
= mode
;
1387 const struct fm10k_msg_data fm10k_iov_msg_data_pf
[] = {
1388 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test
),
1389 FM10K_VF_MSG_MSIX_HANDLER(fm10k_iov_msg_msix_pf
),
1390 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_iov_msg_mac_vlan_pf
),
1391 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_iov_msg_lport_state_pf
),
1392 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error
),
1396 * fm10k_update_stats_hw_pf - Updates hardware related statistics of PF
1397 * @hw: pointer to hardware structure
1398 * @stats: pointer to the stats structure to update
1400 * This function collects and aggregates global and per queue hardware
1403 static void fm10k_update_hw_stats_pf(struct fm10k_hw
*hw
,
1404 struct fm10k_hw_stats
*stats
)
1406 u32 timeout
, ur
, ca
, um
, xec
, vlan_drop
, loopback_drop
, nodesc_drop
;
1409 /* Use Tx queue 0 as a canary to detect a reset */
1410 id
= fm10k_read_reg(hw
, FM10K_TXQCTL(0));
1412 /* Read Global Statistics */
1414 timeout
= fm10k_read_hw_stats_32b(hw
, FM10K_STATS_TIMEOUT
,
1416 ur
= fm10k_read_hw_stats_32b(hw
, FM10K_STATS_UR
, &stats
->ur
);
1417 ca
= fm10k_read_hw_stats_32b(hw
, FM10K_STATS_CA
, &stats
->ca
);
1418 um
= fm10k_read_hw_stats_32b(hw
, FM10K_STATS_UM
, &stats
->um
);
1419 xec
= fm10k_read_hw_stats_32b(hw
, FM10K_STATS_XEC
, &stats
->xec
);
1420 vlan_drop
= fm10k_read_hw_stats_32b(hw
, FM10K_STATS_VLAN_DROP
,
1422 loopback_drop
= fm10k_read_hw_stats_32b(hw
,
1423 FM10K_STATS_LOOPBACK_DROP
,
1424 &stats
->loopback_drop
);
1425 nodesc_drop
= fm10k_read_hw_stats_32b(hw
,
1426 FM10K_STATS_NODESC_DROP
,
1427 &stats
->nodesc_drop
);
1429 /* if value has not changed then we have consistent data */
1431 id
= fm10k_read_reg(hw
, FM10K_TXQCTL(0));
1432 } while ((id
^ id_prev
) & FM10K_TXQCTL_ID_MASK
);
1434 /* drop non-ID bits and set VALID ID bit */
1435 id
&= FM10K_TXQCTL_ID_MASK
;
1436 id
|= FM10K_STAT_VALID
;
1438 /* Update Global Statistics */
1439 if (stats
->stats_idx
== id
) {
1440 stats
->timeout
.count
+= timeout
;
1441 stats
->ur
.count
+= ur
;
1442 stats
->ca
.count
+= ca
;
1443 stats
->um
.count
+= um
;
1444 stats
->xec
.count
+= xec
;
1445 stats
->vlan_drop
.count
+= vlan_drop
;
1446 stats
->loopback_drop
.count
+= loopback_drop
;
1447 stats
->nodesc_drop
.count
+= nodesc_drop
;
1450 /* Update bases and record current PF id */
1451 fm10k_update_hw_base_32b(&stats
->timeout
, timeout
);
1452 fm10k_update_hw_base_32b(&stats
->ur
, ur
);
1453 fm10k_update_hw_base_32b(&stats
->ca
, ca
);
1454 fm10k_update_hw_base_32b(&stats
->um
, um
);
1455 fm10k_update_hw_base_32b(&stats
->xec
, xec
);
1456 fm10k_update_hw_base_32b(&stats
->vlan_drop
, vlan_drop
);
1457 fm10k_update_hw_base_32b(&stats
->loopback_drop
, loopback_drop
);
1458 fm10k_update_hw_base_32b(&stats
->nodesc_drop
, nodesc_drop
);
1459 stats
->stats_idx
= id
;
1461 /* Update Queue Statistics */
1462 fm10k_update_hw_stats_q(hw
, stats
->q
, 0, hw
->mac
.max_queues
);
1466 * fm10k_rebind_hw_stats_pf - Resets base for hardware statistics of PF
1467 * @hw: pointer to hardware structure
1468 * @stats: pointer to the stats structure to update
1470 * This function resets the base for global and per queue hardware
1473 static void fm10k_rebind_hw_stats_pf(struct fm10k_hw
*hw
,
1474 struct fm10k_hw_stats
*stats
)
1476 /* Unbind Global Statistics */
1477 fm10k_unbind_hw_stats_32b(&stats
->timeout
);
1478 fm10k_unbind_hw_stats_32b(&stats
->ur
);
1479 fm10k_unbind_hw_stats_32b(&stats
->ca
);
1480 fm10k_unbind_hw_stats_32b(&stats
->um
);
1481 fm10k_unbind_hw_stats_32b(&stats
->xec
);
1482 fm10k_unbind_hw_stats_32b(&stats
->vlan_drop
);
1483 fm10k_unbind_hw_stats_32b(&stats
->loopback_drop
);
1484 fm10k_unbind_hw_stats_32b(&stats
->nodesc_drop
);
1486 /* Unbind Queue Statistics */
1487 fm10k_unbind_hw_stats_q(stats
->q
, 0, hw
->mac
.max_queues
);
1489 /* Reinitialize bases for all stats */
1490 fm10k_update_hw_stats_pf(hw
, stats
);
1494 * fm10k_set_dma_mask_pf - Configures PhyAddrSpace to limit DMA to system
1495 * @hw: pointer to hardware structure
1496 * @dma_mask: 64 bit DMA mask required for platform
1498 * This function sets the PHYADDR.PhyAddrSpace bits for the endpoint in order
1499 * to limit the access to memory beyond what is physically in the system.
1501 static void fm10k_set_dma_mask_pf(struct fm10k_hw
*hw
, u64 dma_mask
)
1503 /* we need to write the upper 32 bits of DMA mask to PhyAddrSpace */
1504 u32 phyaddr
= (u32
)(dma_mask
>> 32);
1506 fm10k_write_reg(hw
, FM10K_PHYADDR
, phyaddr
);
1510 * fm10k_get_fault_pf - Record a fault in one of the interface units
1511 * @hw: pointer to hardware structure
1512 * @type: pointer to fault type register offset
1513 * @fault: pointer to memory location to record the fault
1515 * Record the fault register contents to the fault data structure and
1516 * clear the entry from the register.
1518 * Returns ERR_PARAM if invalid register is specified or no error is present.
1520 static s32
fm10k_get_fault_pf(struct fm10k_hw
*hw
, int type
,
1521 struct fm10k_fault
*fault
)
1525 /* verify the fault register is in range and is aligned */
1527 case FM10K_PCA_FAULT
:
1528 case FM10K_THI_FAULT
:
1529 case FM10K_FUM_FAULT
:
1532 return FM10K_ERR_PARAM
;
1535 /* only service faults that are valid */
1536 func
= fm10k_read_reg(hw
, type
+ FM10K_FAULT_FUNC
);
1537 if (!(func
& FM10K_FAULT_FUNC_VALID
))
1538 return FM10K_ERR_PARAM
;
1540 /* read remaining fields */
1541 fault
->address
= fm10k_read_reg(hw
, type
+ FM10K_FAULT_ADDR_HI
);
1542 fault
->address
<<= 32;
1543 fault
->address
= fm10k_read_reg(hw
, type
+ FM10K_FAULT_ADDR_LO
);
1544 fault
->specinfo
= fm10k_read_reg(hw
, type
+ FM10K_FAULT_SPECINFO
);
1546 /* clear valid bit to allow for next error */
1547 fm10k_write_reg(hw
, type
+ FM10K_FAULT_FUNC
, FM10K_FAULT_FUNC_VALID
);
1549 /* Record which function triggered the error */
1550 if (func
& FM10K_FAULT_FUNC_PF
)
1553 fault
->func
= 1 + ((func
& FM10K_FAULT_FUNC_VF_MASK
) >>
1554 FM10K_FAULT_FUNC_VF_SHIFT
);
1556 /* record fault type */
1557 fault
->type
= func
& FM10K_FAULT_FUNC_TYPE_MASK
;
1563 * fm10k_request_lport_map_pf - Request LPORT map from the switch API
1564 * @hw: pointer to hardware structure
1567 static s32
fm10k_request_lport_map_pf(struct fm10k_hw
*hw
)
1569 struct fm10k_mbx_info
*mbx
= &hw
->mbx
;
1572 /* issue request asking for LPORT map */
1573 fm10k_tlv_msg_init(msg
, FM10K_PF_MSG_ID_LPORT_MAP
);
1575 /* load onto outgoing mailbox */
1576 return mbx
->ops
.enqueue_tx(hw
, mbx
, msg
);
1580 * fm10k_get_host_state_pf - Returns the state of the switch and mailbox
1581 * @hw: pointer to hardware structure
1582 * @switch_ready: pointer to boolean value that will record switch state
1584 * This funciton will check the DMA_CTRL2 register and mailbox in order
1585 * to determine if the switch is ready for the PF to begin requesting
1586 * addresses and mapping traffic to the local interface.
1588 static s32
fm10k_get_host_state_pf(struct fm10k_hw
*hw
, bool *switch_ready
)
1593 /* verify the switch is ready for interaction */
1594 dma_ctrl2
= fm10k_read_reg(hw
, FM10K_DMA_CTRL2
);
1595 if (!(dma_ctrl2
& FM10K_DMA_CTRL2_SWITCH_READY
))
1598 /* retrieve generic host state info */
1599 ret_val
= fm10k_get_host_state_generic(hw
, switch_ready
);
1603 /* interface cannot receive traffic without logical ports */
1604 if (hw
->mac
.dglort_map
== FM10K_DGLORTMAP_NONE
)
1605 ret_val
= fm10k_request_lport_map_pf(hw
);
1611 /* This structure defines the attibutes to be parsed below */
1612 const struct fm10k_tlv_attr fm10k_lport_map_msg_attr
[] = {
1613 FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_LPORT_MAP
),
1618 * fm10k_msg_lport_map_pf - Message handler for lport_map message from SM
1619 * @hw: Pointer to hardware structure
1620 * @results: pointer array containing parsed data
1621 * @mbx: Pointer to mailbox information structure
1623 * This handler configures the lport mapping based on the reply from the
1626 s32
fm10k_msg_lport_map_pf(struct fm10k_hw
*hw
, u32
**results
,
1627 struct fm10k_mbx_info
*mbx
)
1633 err
= fm10k_tlv_attr_get_u32(results
[FM10K_PF_ATTR_ID_LPORT_MAP
],
1638 /* extract values out of the header */
1639 glort
= FM10K_MSG_HDR_FIELD_GET(dglort_map
, LPORT_MAP_GLORT
);
1640 mask
= FM10K_MSG_HDR_FIELD_GET(dglort_map
, LPORT_MAP_MASK
);
1642 /* verify mask is set and none of the masked bits in glort are set */
1643 if (!mask
|| (glort
& ~mask
))
1644 return FM10K_ERR_PARAM
;
1646 /* verify the mask is contiguous, and that it is 1's followed by 0's */
1647 if (((~(mask
- 1) & mask
) + mask
) & FM10K_DGLORTMAP_NONE
)
1648 return FM10K_ERR_PARAM
;
1650 /* record the glort, mask, and port count */
1651 hw
->mac
.dglort_map
= dglort_map
;
1656 const struct fm10k_tlv_attr fm10k_update_pvid_msg_attr
[] = {
1657 FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_UPDATE_PVID
),
1662 * fm10k_msg_update_pvid_pf - Message handler for port VLAN message from SM
1663 * @hw: Pointer to hardware structure
1664 * @results: pointer array containing parsed data
1665 * @mbx: Pointer to mailbox information structure
1667 * This handler configures the default VLAN for the PF
1669 s32
fm10k_msg_update_pvid_pf(struct fm10k_hw
*hw
, u32
**results
,
1670 struct fm10k_mbx_info
*mbx
)
1676 err
= fm10k_tlv_attr_get_u32(results
[FM10K_PF_ATTR_ID_UPDATE_PVID
],
1681 /* extract values from the pvid update */
1682 glort
= FM10K_MSG_HDR_FIELD_GET(pvid_update
, UPDATE_PVID_GLORT
);
1683 pvid
= FM10K_MSG_HDR_FIELD_GET(pvid_update
, UPDATE_PVID_PVID
);
1685 /* if glort is not valid return error */
1686 if (!fm10k_glort_valid_pf(hw
, glort
))
1687 return FM10K_ERR_PARAM
;
1689 /* verify VID is valid */
1690 if (pvid
>= FM10K_VLAN_TABLE_VID_MAX
)
1691 return FM10K_ERR_PARAM
;
1693 /* record the port VLAN ID value */
1694 hw
->mac
.default_vid
= pvid
;
1700 * fm10k_record_global_table_data - Move global table data to swapi table info
1701 * @from: pointer to source table data structure
1702 * @to: pointer to destination table info structure
1704 * This function is will copy table_data to the table_info contained in
1707 static void fm10k_record_global_table_data(struct fm10k_global_table_data
*from
,
1708 struct fm10k_swapi_table_info
*to
)
1710 /* convert from le32 struct to CPU byte ordered values */
1711 to
->used
= le32_to_cpu(from
->used
);
1712 to
->avail
= le32_to_cpu(from
->avail
);
1715 const struct fm10k_tlv_attr fm10k_err_msg_attr
[] = {
1716 FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_ERR
,
1717 sizeof(struct fm10k_swapi_error
)),
1722 * fm10k_msg_err_pf - Message handler for error reply
1723 * @hw: Pointer to hardware structure
1724 * @results: pointer array containing parsed data
1725 * @mbx: Pointer to mailbox information structure
1727 * This handler will capture the data for any error replies to previous
1728 * messages that the PF has sent.
1730 s32
fm10k_msg_err_pf(struct fm10k_hw
*hw
, u32
**results
,
1731 struct fm10k_mbx_info
*mbx
)
1733 struct fm10k_swapi_error err_msg
;
1736 /* extract structure from message */
1737 err
= fm10k_tlv_attr_get_le_struct(results
[FM10K_PF_ATTR_ID_ERR
],
1738 &err_msg
, sizeof(err_msg
));
1742 /* record table status */
1743 fm10k_record_global_table_data(&err_msg
.mac
, &hw
->swapi
.mac
);
1744 fm10k_record_global_table_data(&err_msg
.nexthop
, &hw
->swapi
.nexthop
);
1745 fm10k_record_global_table_data(&err_msg
.ffu
, &hw
->swapi
.ffu
);
1747 /* record SW API status value */
1748 hw
->swapi
.status
= le32_to_cpu(err_msg
.status
);
1753 const struct fm10k_tlv_attr fm10k_1588_timestamp_msg_attr
[] = {
1754 FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_1588_TIMESTAMP
,
1755 sizeof(struct fm10k_swapi_1588_timestamp
)),
1759 /* currently there is no shared 1588 timestamp handler */
1762 * fm10k_adjust_systime_pf - Adjust systime frequency
1763 * @hw: pointer to hardware structure
1764 * @ppb: adjustment rate in parts per billion
1766 * This function will adjust the SYSTIME_CFG register contained in BAR 4
1767 * if this function is supported for BAR 4 access. The adjustment amount
1768 * is based on the parts per billion value provided and adjusted to a
1769 * value based on parts per 2^48 clock cycles.
1771 * If adjustment is not supported or the requested value is too large
1772 * we will return an error.
1774 static s32
fm10k_adjust_systime_pf(struct fm10k_hw
*hw
, s32 ppb
)
1778 /* if sw_addr is not set we don't have switch register access */
1780 return ppb
? FM10K_ERR_PARAM
: 0;
1782 /* we must convert the value from parts per billion to parts per
1783 * 2^48 cycles. In addition I have opted to only use the 30 most
1784 * significant bits of the adjustment value as the 8 least
1785 * significant bits are located in another register and represent
1786 * a value significantly less than a part per billion, the result
1787 * of dropping the 8 least significant bits is that the adjustment
1788 * value is effectively multiplied by 2^8 when we write it.
1790 * As a result of all this the math for this breaks down as follows:
1791 * ppb / 10^9 == adjust * 2^8 / 2^48
1792 * If we solve this for adjust, and simplify it comes out as:
1793 * ppb * 2^31 / 5^9 == adjust
1795 systime_adjust
= (ppb
< 0) ? -ppb
: ppb
;
1796 systime_adjust
<<= 31;
1797 do_div(systime_adjust
, 1953125);
1799 /* verify the requested adjustment value is in range */
1800 if (systime_adjust
> FM10K_SW_SYSTIME_ADJUST_MASK
)
1801 return FM10K_ERR_PARAM
;
1804 systime_adjust
|= FM10K_SW_SYSTIME_ADJUST_DIR_POSITIVE
;
1806 fm10k_write_sw_reg(hw
, FM10K_SW_SYSTIME_ADJUST
, (u32
)systime_adjust
);
1812 * fm10k_read_systime_pf - Reads value of systime registers
1813 * @hw: pointer to the hardware structure
1815 * Function reads the content of 2 registers, combined to represent a 64 bit
1816 * value measured in nanosecods. In order to guarantee the value is accurate
1817 * we check the 32 most significant bits both before and after reading the
1818 * 32 least significant bits to verify they didn't change as we were reading
1821 static u64
fm10k_read_systime_pf(struct fm10k_hw
*hw
)
1823 u32 systime_l
, systime_h
, systime_tmp
;
1825 systime_h
= fm10k_read_reg(hw
, FM10K_SYSTIME
+ 1);
1828 systime_tmp
= systime_h
;
1829 systime_l
= fm10k_read_reg(hw
, FM10K_SYSTIME
);
1830 systime_h
= fm10k_read_reg(hw
, FM10K_SYSTIME
+ 1);
1831 } while (systime_tmp
!= systime_h
);
1833 return ((u64
)systime_h
<< 32) | systime_l
;
1836 static const struct fm10k_msg_data fm10k_msg_data_pf
[] = {
1837 FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES
, fm10k_msg_err_pf
),
1838 FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE
, fm10k_msg_err_pf
),
1839 FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_msg_lport_map_pf
),
1840 FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE
, fm10k_msg_err_pf
),
1841 FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE
, fm10k_msg_err_pf
),
1842 FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_msg_update_pvid_pf
),
1843 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error
),
1846 static struct fm10k_mac_ops mac_ops_pf
= {
1847 .get_bus_info
= &fm10k_get_bus_info_generic
,
1848 .reset_hw
= &fm10k_reset_hw_pf
,
1849 .init_hw
= &fm10k_init_hw_pf
,
1850 .start_hw
= &fm10k_start_hw_generic
,
1851 .stop_hw
= &fm10k_stop_hw_generic
,
1852 .is_slot_appropriate
= &fm10k_is_slot_appropriate_pf
,
1853 .update_vlan
= &fm10k_update_vlan_pf
,
1854 .read_mac_addr
= &fm10k_read_mac_addr_pf
,
1855 .update_uc_addr
= &fm10k_update_uc_addr_pf
,
1856 .update_mc_addr
= &fm10k_update_mc_addr_pf
,
1857 .update_xcast_mode
= &fm10k_update_xcast_mode_pf
,
1858 .update_int_moderator
= &fm10k_update_int_moderator_pf
,
1859 .update_lport_state
= &fm10k_update_lport_state_pf
,
1860 .update_hw_stats
= &fm10k_update_hw_stats_pf
,
1861 .rebind_hw_stats
= &fm10k_rebind_hw_stats_pf
,
1862 .configure_dglort_map
= &fm10k_configure_dglort_map_pf
,
1863 .set_dma_mask
= &fm10k_set_dma_mask_pf
,
1864 .get_fault
= &fm10k_get_fault_pf
,
1865 .get_host_state
= &fm10k_get_host_state_pf
,
1866 .adjust_systime
= &fm10k_adjust_systime_pf
,
1867 .read_systime
= &fm10k_read_systime_pf
,
1870 static struct fm10k_iov_ops iov_ops_pf
= {
1871 .assign_resources
= &fm10k_iov_assign_resources_pf
,
1872 .configure_tc
= &fm10k_iov_configure_tc_pf
,
1873 .assign_int_moderator
= &fm10k_iov_assign_int_moderator_pf
,
1874 .assign_default_mac_vlan
= fm10k_iov_assign_default_mac_vlan_pf
,
1875 .reset_resources
= &fm10k_iov_reset_resources_pf
,
1876 .set_lport
= &fm10k_iov_set_lport_pf
,
1877 .reset_lport
= &fm10k_iov_reset_lport_pf
,
1878 .update_stats
= &fm10k_iov_update_stats_pf
,
1879 .report_timestamp
= &fm10k_iov_report_timestamp_pf
,
1882 static s32
fm10k_get_invariants_pf(struct fm10k_hw
*hw
)
1884 fm10k_get_invariants_generic(hw
);
1886 return fm10k_sm_mbx_init(hw
, &hw
->mbx
, fm10k_msg_data_pf
);
1889 struct fm10k_info fm10k_pf_info
= {
1890 .mac
= fm10k_mac_pf
,
1891 .get_invariants
= &fm10k_get_invariants_pf
,
1892 .mac_ops
= &mac_ops_pf
,
1893 .iov_ops
= &iov_ops_pf
,