@@ -489,8 +489,6 @@ static void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg)
489489 if ((label_name [len ] - '0' ) == hw -> pf_id ) {
490490 hw -> tnl .tbl [hw -> tnl .count ].type = tnls [i ].type ;
491491 hw -> tnl .tbl [hw -> tnl .count ].valid = false;
492- hw -> tnl .tbl [hw -> tnl .count ].in_use = false;
493- hw -> tnl .tbl [hw -> tnl .count ].marked = false;
494492 hw -> tnl .tbl [hw -> tnl .count ].boost_addr = val ;
495493 hw -> tnl .tbl [hw -> tnl .count ].port = 0 ;
496494 hw -> tnl .count ++ ;
@@ -505,8 +503,11 @@ static void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg)
505503 for (i = 0 ; i < hw -> tnl .count ; i ++ ) {
506504 ice_find_boost_entry (ice_seg , hw -> tnl .tbl [i ].boost_addr ,
507505 & hw -> tnl .tbl [i ].boost_entry );
508- if (hw -> tnl .tbl [i ].boost_entry )
506+ if (hw -> tnl .tbl [i ].boost_entry ) {
509507 hw -> tnl .tbl [i ].valid = true;
508+ if (hw -> tnl .tbl [i ].type < __TNL_TYPE_CNT )
509+ hw -> tnl .valid_count [hw -> tnl .tbl [i ].type ]++ ;
510+ }
510511 }
511512}
512513
@@ -1626,129 +1627,76 @@ static struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
16261627}
16271628
16281629/**
1629- * ice_tunnel_port_in_use_hlpr - helper function to determine tunnel usage
1630+ * ice_get_open_tunnel_port - retrieve an open tunnel port
16301631 * @hw: pointer to the HW structure
1631- * @port: port to search for
1632- * @index: optionally returns index
1633- *
1634- * Returns whether a port is already in use as a tunnel, and optionally its
1635- * index
1632+ * @port: returns open port
16361633 */
1637- static bool ice_tunnel_port_in_use_hlpr (struct ice_hw * hw , u16 port , u16 * index )
1634+ bool
1635+ ice_get_open_tunnel_port (struct ice_hw * hw , u16 * port )
16381636{
1637+ bool res = false;
16391638 u16 i ;
16401639
1640+ mutex_lock (& hw -> tnl_lock );
1641+
16411642 for (i = 0 ; i < hw -> tnl .count && i < ICE_TUNNEL_MAX_ENTRIES ; i ++ )
1642- if (hw -> tnl .tbl [i ].in_use && hw -> tnl .tbl [i ].port == port ) {
1643- if ( index )
1644- * index = i ;
1645- return true ;
1643+ if (hw -> tnl .tbl [i ].valid && hw -> tnl .tbl [i ].port ) {
1644+ * port = hw -> tnl . tbl [ i ]. port ;
1645+ res = true ;
1646+ break ;
16461647 }
16471648
1648- return false;
1649- }
1650-
1651- /**
1652- * ice_tunnel_port_in_use
1653- * @hw: pointer to the HW structure
1654- * @port: port to search for
1655- * @index: optionally returns index
1656- *
1657- * Returns whether a port is already in use as a tunnel, and optionally its
1658- * index
1659- */
1660- bool ice_tunnel_port_in_use (struct ice_hw * hw , u16 port , u16 * index )
1661- {
1662- bool res ;
1663-
1664- mutex_lock (& hw -> tnl_lock );
1665- res = ice_tunnel_port_in_use_hlpr (hw , port , index );
16661649 mutex_unlock (& hw -> tnl_lock );
16671650
16681651 return res ;
16691652}
16701653
16711654/**
1672- * ice_find_free_tunnel_entry
1655+ * ice_tunnel_idx_to_entry - convert linear index to the sparse one
16731656 * @hw: pointer to the HW structure
1674- * @type: tunnel type
1675- * @index: optionally returns index
1657+ * @type: type of tunnel
1658+ * @idx: linear index
16761659 *
1677- * Returns whether there is a free tunnel entry, and optionally its index
1678- */
1679- static bool
1680- ice_find_free_tunnel_entry (struct ice_hw * hw , enum ice_tunnel_type type ,
1681- u16 * index )
1682- {
1683- u16 i ;
1684-
1685- for (i = 0 ; i < hw -> tnl .count && i < ICE_TUNNEL_MAX_ENTRIES ; i ++ )
1686- if (hw -> tnl .tbl [i ].valid && !hw -> tnl .tbl [i ].in_use &&
1687- hw -> tnl .tbl [i ].type == type ) {
1688- if (index )
1689- * index = i ;
1690- return true;
1691- }
1692-
1693- return false;
1694- }
1695-
1696- /**
1697- * ice_get_open_tunnel_port - retrieve an open tunnel port
1698- * @hw: pointer to the HW structure
1699- * @port: returns open port
1660+ * Stack assumes we have 2 linear tables with indexes [0, count_valid),
1661+ * but really the port table may be sprase, and types are mixed, so convert
1662+ * the stack index into the device index.
17001663 */
1701- bool
1702- ice_get_open_tunnel_port ( struct ice_hw * hw , u16 * port )
1664+ static u16 ice_tunnel_idx_to_entry ( struct ice_hw * hw , enum ice_tunnel_type type ,
1665+ u16 idx )
17031666{
1704- bool res = false;
17051667 u16 i ;
17061668
1707- mutex_lock (& hw -> tnl_lock );
1708-
17091669 for (i = 0 ; i < hw -> tnl .count && i < ICE_TUNNEL_MAX_ENTRIES ; i ++ )
1710- if (hw -> tnl .tbl [i ].valid && hw -> tnl .tbl [i ].in_use ) {
1711- * port = hw -> tnl .tbl [i ].port ;
1712- res = true;
1713- break ;
1714- }
1715-
1716- mutex_unlock (& hw -> tnl_lock );
1670+ if (hw -> tnl .tbl [i ].valid &&
1671+ hw -> tnl .tbl [i ].type == type &&
1672+ idx -- )
1673+ return i ;
17171674
1718- return res ;
1675+ WARN_ON_ONCE (1 );
1676+ return 0 ;
17191677}
17201678
17211679/**
17221680 * ice_create_tunnel
17231681 * @hw: pointer to the HW structure
1682+ * @index: device table entry
17241683 * @type: type of tunnel
17251684 * @port: port of tunnel to create
17261685 *
17271686 * Create a tunnel by updating the parse graph in the parser. We do that by
17281687 * creating a package buffer with the tunnel info and issuing an update package
17291688 * command.
17301689 */
1731- enum ice_status
1732- ice_create_tunnel (struct ice_hw * hw , enum ice_tunnel_type type , u16 port )
1690+ static enum ice_status
1691+ ice_create_tunnel (struct ice_hw * hw , u16 index ,
1692+ enum ice_tunnel_type type , u16 port )
17331693{
17341694 struct ice_boost_tcam_section * sect_rx , * sect_tx ;
17351695 enum ice_status status = ICE_ERR_MAX_LIMIT ;
17361696 struct ice_buf_build * bld ;
1737- u16 index ;
17381697
17391698 mutex_lock (& hw -> tnl_lock );
17401699
1741- if (ice_tunnel_port_in_use_hlpr (hw , port , & index )) {
1742- hw -> tnl .tbl [index ].ref ++ ;
1743- status = 0 ;
1744- goto ice_create_tunnel_end ;
1745- }
1746-
1747- if (!ice_find_free_tunnel_entry (hw , type , & index )) {
1748- status = ICE_ERR_OUT_OF_RANGE ;
1749- goto ice_create_tunnel_end ;
1750- }
1751-
17521700 bld = ice_pkg_buf_alloc (hw );
17531701 if (!bld ) {
17541702 status = ICE_ERR_NO_MEMORY ;
@@ -1787,11 +1735,8 @@ ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
17871735 memcpy (sect_tx -> tcam , sect_rx -> tcam , sizeof (* sect_tx -> tcam ));
17881736
17891737 status = ice_update_pkg (hw , ice_pkg_buf (bld ), 1 );
1790- if (!status ) {
1738+ if (!status )
17911739 hw -> tnl .tbl [index ].port = port ;
1792- hw -> tnl .tbl [index ].in_use = true;
1793- hw -> tnl .tbl [index ].ref = 1 ;
1794- }
17951740
17961741ice_create_tunnel_err :
17971742 ice_pkg_buf_free (hw , bld );
@@ -1805,46 +1750,31 @@ ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
18051750/**
18061751 * ice_destroy_tunnel
18071752 * @hw: pointer to the HW structure
1753+ * @index: device table entry
1754+ * @type: type of tunnel
18081755 * @port: port of tunnel to destroy (ignored if the all parameter is true)
1809- * @all: flag that states to destroy all tunnels
18101756 *
18111757 * Destroys a tunnel or all tunnels by creating an update package buffer
18121758 * targeting the specific updates requested and then performing an update
18131759 * package.
18141760 */
1815- enum ice_status ice_destroy_tunnel (struct ice_hw * hw , u16 port , bool all )
1761+ static enum ice_status
1762+ ice_destroy_tunnel (struct ice_hw * hw , u16 index , enum ice_tunnel_type type ,
1763+ u16 port )
18161764{
18171765 struct ice_boost_tcam_section * sect_rx , * sect_tx ;
18181766 enum ice_status status = ICE_ERR_MAX_LIMIT ;
18191767 struct ice_buf_build * bld ;
1820- u16 count = 0 ;
1821- u16 index ;
1822- u16 size ;
1823- u16 i ;
18241768
18251769 mutex_lock (& hw -> tnl_lock );
18261770
1827- if (!all && ice_tunnel_port_in_use_hlpr (hw , port , & index ))
1828- if (hw -> tnl .tbl [index ].ref > 1 ) {
1829- hw -> tnl .tbl [index ].ref -- ;
1830- status = 0 ;
1831- goto ice_destroy_tunnel_end ;
1832- }
1833-
1834- /* determine count */
1835- for (i = 0 ; i < hw -> tnl .count && i < ICE_TUNNEL_MAX_ENTRIES ; i ++ )
1836- if (hw -> tnl .tbl [i ].valid && hw -> tnl .tbl [i ].in_use &&
1837- (all || hw -> tnl .tbl [i ].port == port ))
1838- count ++ ;
1839-
1840- if (!count ) {
1841- status = ICE_ERR_PARAM ;
1771+ if (WARN_ON (!hw -> tnl .tbl [index ].valid ||
1772+ hw -> tnl .tbl [index ].type != type ||
1773+ hw -> tnl .tbl [index ].port != port )) {
1774+ status = ICE_ERR_OUT_OF_RANGE ;
18421775 goto ice_destroy_tunnel_end ;
18431776 }
18441777
1845- /* size of section - there is at least one entry */
1846- size = struct_size (sect_rx , tcam , count );
1847-
18481778 bld = ice_pkg_buf_alloc (hw );
18491779 if (!bld ) {
18501780 status = ICE_ERR_NO_MEMORY ;
@@ -1856,40 +1786,28 @@ enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
18561786 goto ice_destroy_tunnel_err ;
18571787
18581788 sect_rx = ice_pkg_buf_alloc_section (bld , ICE_SID_RXPARSER_BOOST_TCAM ,
1859- size );
1789+ struct_size ( sect_rx , tcam , 1 ) );
18601790 if (!sect_rx )
18611791 goto ice_destroy_tunnel_err ;
18621792 sect_rx -> count = cpu_to_le16 (1 );
18631793
18641794 sect_tx = ice_pkg_buf_alloc_section (bld , ICE_SID_TXPARSER_BOOST_TCAM ,
1865- size );
1795+ struct_size ( sect_tx , tcam , 1 ) );
18661796 if (!sect_tx )
18671797 goto ice_destroy_tunnel_err ;
18681798 sect_tx -> count = cpu_to_le16 (1 );
18691799
18701800 /* copy original boost entry to update package buffer, one copy to Rx
18711801 * section, another copy to the Tx section
18721802 */
1873- for (i = 0 ; i < hw -> tnl .count && i < ICE_TUNNEL_MAX_ENTRIES ; i ++ )
1874- if (hw -> tnl .tbl [i ].valid && hw -> tnl .tbl [i ].in_use &&
1875- (all || hw -> tnl .tbl [i ].port == port )) {
1876- memcpy (sect_rx -> tcam + i , hw -> tnl .tbl [i ].boost_entry ,
1877- sizeof (* sect_rx -> tcam ));
1878- memcpy (sect_tx -> tcam + i , hw -> tnl .tbl [i ].boost_entry ,
1879- sizeof (* sect_tx -> tcam ));
1880- hw -> tnl .tbl [i ].marked = true;
1881- }
1803+ memcpy (sect_rx -> tcam , hw -> tnl .tbl [index ].boost_entry ,
1804+ sizeof (* sect_rx -> tcam ));
1805+ memcpy (sect_tx -> tcam , hw -> tnl .tbl [index ].boost_entry ,
1806+ sizeof (* sect_tx -> tcam ));
18821807
18831808 status = ice_update_pkg (hw , ice_pkg_buf (bld ), 1 );
18841809 if (!status )
1885- for (i = 0 ; i < hw -> tnl .count &&
1886- i < ICE_TUNNEL_MAX_ENTRIES ; i ++ )
1887- if (hw -> tnl .tbl [i ].marked ) {
1888- hw -> tnl .tbl [i ].ref = 0 ;
1889- hw -> tnl .tbl [i ].port = 0 ;
1890- hw -> tnl .tbl [i ].in_use = false;
1891- hw -> tnl .tbl [i ].marked = false;
1892- }
1810+ hw -> tnl .tbl [index ].port = 0 ;
18931811
18941812ice_destroy_tunnel_err :
18951813 ice_pkg_buf_free (hw , bld );
@@ -1900,6 +1818,52 @@ enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
19001818 return status ;
19011819}
19021820
1821+ int ice_udp_tunnel_set_port (struct net_device * netdev , unsigned int table ,
1822+ unsigned int idx , struct udp_tunnel_info * ti )
1823+ {
1824+ struct ice_netdev_priv * np = netdev_priv (netdev );
1825+ struct ice_vsi * vsi = np -> vsi ;
1826+ struct ice_pf * pf = vsi -> back ;
1827+ enum ice_tunnel_type tnl_type ;
1828+ enum ice_status status ;
1829+ u16 index ;
1830+
1831+ tnl_type = ti -> type == UDP_TUNNEL_TYPE_VXLAN ? TNL_VXLAN : TNL_GENEVE ;
1832+ index = ice_tunnel_idx_to_entry (& pf -> hw , idx , tnl_type );
1833+
1834+ status = ice_create_tunnel (& pf -> hw , index , tnl_type , ntohs (ti -> port ));
1835+ if (status ) {
1836+ netdev_err (netdev , "Error adding UDP tunnel - %s\n" ,
1837+ ice_stat_str (status ));
1838+ return - EIO ;
1839+ }
1840+
1841+ udp_tunnel_nic_set_port_priv (netdev , table , idx , index );
1842+ return 0 ;
1843+ }
1844+
1845+ int ice_udp_tunnel_unset_port (struct net_device * netdev , unsigned int table ,
1846+ unsigned int idx , struct udp_tunnel_info * ti )
1847+ {
1848+ struct ice_netdev_priv * np = netdev_priv (netdev );
1849+ struct ice_vsi * vsi = np -> vsi ;
1850+ struct ice_pf * pf = vsi -> back ;
1851+ enum ice_tunnel_type tnl_type ;
1852+ enum ice_status status ;
1853+
1854+ tnl_type = ti -> type == UDP_TUNNEL_TYPE_VXLAN ? TNL_VXLAN : TNL_GENEVE ;
1855+
1856+ status = ice_destroy_tunnel (& pf -> hw , ti -> hw_priv , tnl_type ,
1857+ ntohs (ti -> port ));
1858+ if (status ) {
1859+ netdev_err (netdev , "Error removing UDP tunnel - %s\n" ,
1860+ ice_stat_str (status ));
1861+ return - EIO ;
1862+ }
1863+
1864+ return 0 ;
1865+ }
1866+
19031867/* PTG Management */
19041868
19051869/**
0 commit comments