Skip to content

Commit 76a4c7d

Browse files
Nogah Frankeldavem330
authored andcommitted
mlxsw: reg: Add QoS Policer Configuration Register
The QPCR register is used to create and control policers. A policer can discard or change the color of packets that are trapped by a specific trap. Signed-off-by: Nogah Frankel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2b77958 commit 76a4c7d

File tree

1 file changed

+141
-0
lines changed
  • drivers/net/ethernet/mellanox/mlxsw

1 file changed

+141
-0
lines changed

drivers/net/ethernet/mellanox/mlxsw/reg.h

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,146 @@ static inline void mlxsw_reg_spvmlr_pack(char *payload, u8 local_port,
17571757
}
17581758
}
17591759

1760+
/* QPCR - QoS Policer Configuration Register
1761+
* -----------------------------------------
1762+
* The QPCR register is used to create policers - that limit
1763+
* the rate of bytes or packets via some trap group.
1764+
*/
1765+
#define MLXSW_REG_QPCR_ID 0x4004
1766+
#define MLXSW_REG_QPCR_LEN 0x28
1767+
1768+
MLXSW_REG_DEFINE(qpcr, MLXSW_REG_QPCR_ID, MLXSW_REG_QPCR_LEN);
1769+
1770+
enum mlxsw_reg_qpcr_g {
1771+
MLXSW_REG_QPCR_G_GLOBAL = 2,
1772+
MLXSW_REG_QPCR_G_STORM_CONTROL = 3,
1773+
};
1774+
1775+
/* reg_qpcr_g
1776+
* The policer type.
1777+
* Access: Index
1778+
*/
1779+
MLXSW_ITEM32(reg, qpcr, g, 0x00, 14, 2);
1780+
1781+
/* reg_qpcr_pid
1782+
* Policer ID.
1783+
* Access: Index
1784+
*/
1785+
MLXSW_ITEM32(reg, qpcr, pid, 0x00, 0, 14);
1786+
1787+
/* reg_qpcr_color_aware
1788+
* Is the policer aware of colors.
1789+
* Must be 0 (unaware) for cpu port.
1790+
* Access: RW for unbounded policer. RO for bounded policer.
1791+
*/
1792+
MLXSW_ITEM32(reg, qpcr, color_aware, 0x04, 15, 1);
1793+
1794+
/* reg_qpcr_bytes
1795+
* Is policer limit is for bytes per sec or packets per sec.
1796+
* 0 - packets
1797+
* 1 - bytes
1798+
* Access: RW for unbounded policer. RO for bounded policer.
1799+
*/
1800+
MLXSW_ITEM32(reg, qpcr, bytes, 0x04, 14, 1);
1801+
1802+
enum mlxsw_reg_qpcr_ir_units {
1803+
MLXSW_REG_QPCR_IR_UNITS_M,
1804+
MLXSW_REG_QPCR_IR_UNITS_K,
1805+
};
1806+
1807+
/* reg_qpcr_ir_units
1808+
* Policer's units for cir and eir fields (for bytes limits only)
1809+
* 1 - 10^3
1810+
* 0 - 10^6
1811+
* Access: OP
1812+
*/
1813+
MLXSW_ITEM32(reg, qpcr, ir_units, 0x04, 12, 1);
1814+
1815+
enum mlxsw_reg_qpcr_rate_type {
1816+
MLXSW_REG_QPCR_RATE_TYPE_SINGLE = 1,
1817+
MLXSW_REG_QPCR_RATE_TYPE_DOUBLE = 2,
1818+
};
1819+
1820+
/* reg_qpcr_rate_type
1821+
* Policer can have one limit (single rate) or 2 limits with specific operation
1822+
* for packets that exceed the lower rate but not the upper one.
1823+
* (For cpu port must be single rate)
1824+
* Access: RW for unbounded policer. RO for bounded policer.
1825+
*/
1826+
MLXSW_ITEM32(reg, qpcr, rate_type, 0x04, 8, 2);
1827+
1828+
/* reg_qpc_cbs
1829+
* Policer's committed burst size.
1830+
* The policer is working with time slices of 50 nano sec. By default every
1831+
* slice is granted the proportionate share of the committed rate. If we want to
1832+
* allow a slice to exceed that share (while still keeping the rate per sec) we
1833+
* can allow burst. The burst size is between the default proportionate share
1834+
* (and no lower than 8) to 32Gb. (Even though giving a number higher than the
1835+
* committed rate will result in exceeding the rate). The burst size must be a
1836+
* log of 2 and will be determined by 2^cbs.
1837+
* Access: RW
1838+
*/
1839+
MLXSW_ITEM32(reg, qpcr, cbs, 0x08, 24, 6);
1840+
1841+
/* reg_qpcr_cir
1842+
* Policer's committed rate.
1843+
* The rate used for sungle rate, the lower rate for double rate.
1844+
* For bytes limits, the rate will be this value * the unit from ir_units.
1845+
* (Resolution error is up to 1%).
1846+
* Access: RW
1847+
*/
1848+
MLXSW_ITEM32(reg, qpcr, cir, 0x0C, 0, 32);
1849+
1850+
/* reg_qpcr_eir
1851+
* Policer's exceed rate.
1852+
* The higher rate for double rate, reserved for single rate.
1853+
* Lower rate for double rate policer.
1854+
* For bytes limits, the rate will be this value * the unit from ir_units.
1855+
* (Resolution error is up to 1%).
1856+
* Access: RW
1857+
*/
1858+
MLXSW_ITEM32(reg, qpcr, eir, 0x10, 0, 32);
1859+
1860+
#define MLXSW_REG_QPCR_DOUBLE_RATE_ACTION 2
1861+
1862+
/* reg_qpcr_exceed_action.
1863+
* What to do with packets between the 2 limits for double rate.
1864+
* Access: RW for unbounded policer. RO for bounded policer.
1865+
*/
1866+
MLXSW_ITEM32(reg, qpcr, exceed_action, 0x14, 0, 4);
1867+
1868+
enum mlxsw_reg_qpcr_action {
1869+
/* Discard */
1870+
MLXSW_REG_QPCR_ACTION_DISCARD = 1,
1871+
/* Forward and set color to red.
1872+
* If the packet is intended to cpu port, it will be dropped.
1873+
*/
1874+
MLXSW_REG_QPCR_ACTION_FORWARD = 2,
1875+
};
1876+
1877+
/* reg_qpcr_violate_action
1878+
* What to do with packets that cross the cir limit (for single rate) or the eir
1879+
* limit (for double rate).
1880+
* Access: RW for unbounded policer. RO for bounded policer.
1881+
*/
1882+
MLXSW_ITEM32(reg, qpcr, violate_action, 0x18, 0, 4);
1883+
1884+
static inline void mlxsw_reg_qpcr_pack(char *payload, u16 pid,
1885+
enum mlxsw_reg_qpcr_ir_units ir_units,
1886+
bool bytes, u32 cir, u16 cbs)
1887+
{
1888+
MLXSW_REG_ZERO(qpcr, payload);
1889+
mlxsw_reg_qpcr_pid_set(payload, pid);
1890+
mlxsw_reg_qpcr_g_set(payload, MLXSW_REG_QPCR_G_GLOBAL);
1891+
mlxsw_reg_qpcr_rate_type_set(payload, MLXSW_REG_QPCR_RATE_TYPE_SINGLE);
1892+
mlxsw_reg_qpcr_violate_action_set(payload,
1893+
MLXSW_REG_QPCR_ACTION_DISCARD);
1894+
mlxsw_reg_qpcr_cir_set(payload, cir);
1895+
mlxsw_reg_qpcr_ir_units_set(payload, ir_units);
1896+
mlxsw_reg_qpcr_bytes_set(payload, bytes);
1897+
mlxsw_reg_qpcr_cbs_set(payload, cbs);
1898+
}
1899+
17601900
/* QTCT - QoS Switch Traffic Class Table
17611901
* -------------------------------------
17621902
* Configures the mapping between the packet switch priority and the
@@ -5254,6 +5394,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = {
52545394
MLXSW_REG(svpe),
52555395
MLXSW_REG(sfmr),
52565396
MLXSW_REG(spvmlr),
5397+
MLXSW_REG(qpcr),
52575398
MLXSW_REG(qtct),
52585399
MLXSW_REG(qeec),
52595400
MLXSW_REG(pmlp),

0 commit comments

Comments
 (0)