net: atlantic: MACSec support for AQC devices
Subsystems (5)
v2 cover net: atlantic: MACSec support for AQC devices
This RFC patchset introduces MACSec HW offloading support in Marvell(Aquantia) AQC atlantic driver.
This implementation is a joint effort of Marvell developers on top of the work started by Antoine Tenart.
RFC v2:
- Split out patch for updating the SCI upon MAC address change.
Sent as a net tree fix;
- Improved changelog for "net: macsec: add support for getting offloaded
stats" patch (patch 0008 in this series); - Don't fallback to s/w stats when offloading is enabled;
- Removed the "enable HW offloading by default" patch. Separate patch will be submitted to enable specifying the desired offload upon macsec device creation (upon ip link add);
- Accommodated comments related to "MACSec offload skeleton" patch.
v1: https://patchwork.ozlabs.org/cover/1238082/
Several patches introduce backward-incompatible changes and are subject for discussion/drop:
1) patch 0007:
multicast/broadcast when offloading is needed to handle ARP requests, because they have broadcast destination address;
With this patch we also match and encrypt/decrypt packets between macsec hw and realdev based on device's mac address.
This can potentially be used to support multiple macsec offloaded interfaces on top of one realdev.
However in some environments this could lead to problems, e.g. the 'bridge over macsec' configuration will expect the packets with unknown src MAC should come through macsec.
The patch is questionable, we've used it because our current hw setup and requirements both assume that the decryption is done based on mac address match only.
This could be changed by encrypting/decripting all the traffic (except control).
2) patch 0009:
real_dev features are now propagated to macsec device (when HW offloading is enabled), otherwise feature set might lead to HW reconfiguration during MACSec configuration.
Also, HW offloaded macsec should be able to keep LRO LSO features, since they are transparent for macsec engine (at least in our hardware).
Antoine Tenart (4):
net: introduce the MACSEC netdev feature
net: add a reference to MACsec ops in net_device
net: macsec: allow to reference a netdev from a MACsec context
net: macsec: add support for offloading to the MAC
Dmitry Bogdanov (8):
net: macsec: init secy pointer in macsec_context
net: macsec: allow multiple macsec devices with offload
net: macsec: add support for getting offloaded stats
net: atlantic: MACSec offload skeleton
net: atlantic: MACSec egress offload HW bindings
net: atlantic: MACSec egress offload implementation
net: atlantic: MACSec offload statistics HW bindings
net: atlantic: MACSec offload statistics implementation
Mark Starovoytov (4):
net: macsec: support multicast/broadcast when offloading
net: macsec: report real_dev features when HW offloading is enabled
net: atlantic: MACSec ingress offload HW bindings
net: atlantic: MACSec ingress offload implementation
drivers/net/ethernet/aquantia/Kconfig | 1 + .../net/ethernet/aquantia/atlantic/Makefile | 7 +- .../ethernet/aquantia/atlantic/aq_ethtool.c | 160 +- .../net/ethernet/aquantia/atlantic/aq_hw.h | 6 + .../ethernet/aquantia/atlantic/aq_macsec.c | 1840 +++++++++++ .../ethernet/aquantia/atlantic/aq_macsec.h | 138 + .../net/ethernet/aquantia/atlantic/aq_nic.c | 21 +- .../net/ethernet/aquantia/atlantic/aq_nic.h | 6 +- .../ethernet/aquantia/atlantic/aq_pci_func.c | 5 + .../aquantia/atlantic/hw_atl/hw_atl_utils.h | 51 +- .../atlantic/hw_atl/hw_atl_utils_fw2x.c | 69 + .../atlantic/macsec/MSS_Egress_registers.h | 78 + .../atlantic/macsec/MSS_Ingress_registers.h | 82 + .../aquantia/atlantic/macsec/macsec_api.c | 2938 +++++++++++++++++ .../aquantia/atlantic/macsec/macsec_api.h | 328 ++ .../aquantia/atlantic/macsec/macsec_struct.h | 919 ++++++ drivers/net/macsec.c | 447 ++- include/linux/netdev_features.h | 3 + include/linux/netdevice.h | 9 + include/net/macsec.h | 29 +- include/uapi/linux/if_link.h | 1 + net/ethtool/common.c | 1 + tools/include/uapi/linux/if_link.h | 1 + 23 files changed, 6962 insertions(+), 178 deletions(-) create mode 100644 drivers/net/ethernet/aquantia/atlantic/aq_macsec.c create mode 100644 drivers/net/ethernet/aquantia/atlantic/aq_macsec.h create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/MSS_Egress_registers.h create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/MSS_Ingress_registers.h create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.c create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.h create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/macsec_struct.h
Signature · 1 line
2.17.1
RFC v2 1/16 net: introduce the MACSEC netdev feature
From: Antoine Tenart <[email protected]>
This patch introduce a new netdev feature, which will be used by drivers to state they can perform MACsec transformations in hardware.
--- include/linux/netdev_features.h | 3 +++ net/ethtool/common.c | 1 + 2 files changed, 4 insertions(+)
include/linux/netdev_features.h +3 -0
@@ -83,6 +83,8 @@ enum {NETIF_F_HW_TLS_RECORD_BIT ,/* Offload TLS record */ NETIF_F_GRO_FRAGLIST_BIT ,/* Fraglist GRO */ +NETIF_F_HW_MACSEC_BIT ,/* Offload MACsec operations */ +/* * Add your fresh new feature above and remember to update * netdev_features_strings[] in net/core/ethtool.c and maybe
@@ -154,6 +156,7 @@ enum {#define NETIF_F_HW_TLS_RX __NETIF_F(HW_TLS_RX)#define NETIF_F_GRO_FRAGLIST __NETIF_F(GRO_FRAGLIST)#define NETIF_F_GSO_FRAGLIST __NETIF_F(GSO_FRAGLIST) +#define NETIF_F_HW_MACSEC __NETIF_F(HW_MACSEC)/* Finds the next feature with the highest number of the range of start till 0. */
net/ethtool/common.c +1 -0
@@ -60,6 +60,7 @@ const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = { [NETIF_F_HW_TLS_TX_BIT] = "tls-hw-tx-offload", [NETIF_F_HW_TLS_RX_BIT] = "tls-hw-rx-offload", [NETIF_F_GRO_FRAGLIST_BIT] = "rx-gro-list", + [NETIF_F_HW_MACSEC_BIT] = "macsec-hw-offload", }; const char
Signature · 1 line
2.17.1
RFC v2 2/16 net: add a reference to MACsec ops in net_device
In reply to Igor RusskikhFrom: Antoine Tenart <[email protected]>
This patch adds a reference to MACsec ops to the net_device structure, allowing net device drivers to implement offloading operations for MACsec.
--- include/linux/netdevice.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/netdevice.h +9 -0
@@ -53,6 +53,8 @@ struct netpoll_info;struct device ;struct phy_device ;struct dsa_port ; +struct macsec_context ; +struct macsec_ops ;struct sfp_bus ;/* 802.11 specific */
@@ -1819,6 +1821,8 @@ enum netdev_priv_flags {* that follow this device when it is moved * to another network namespace. * +* @macsec_ops: MACsec offloading ops +* * FIXME: cleanup struct net_device such that network protocol info * moves out. */
@@ -2113,6 +2117,11 @@ struct net_device { unsigned wol_enabled:1;struct list_head net_notifier_list; + +#if IS_ENABLED (CONFIG_MACSEC ) +/* MACsec management functions */ +const struct macsec_ops *macsec_ops; +#endif };#define to_net_dev (d) container_of(d, struct net_device, dev)
Signature · 1 line
2.17.1
RFC v2 3/16 net: macsec: allow to reference a netdev from a MACsec context
In reply to Igor RusskikhFrom: Antoine Tenart <[email protected]>
This patch allows to reference a net_device from a MACsec context. This is needed to allow implementing MACsec operations in net device drivers.
--- include/net/macsec.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/net/macsec.h +4 -1
@@ -178,7 +178,10 @@ struct macsec_secy {* struct macsec_context - MACsec context for hardware offloading */ struct macsec_context { -struct phy_device *phydev; +union { +struct net_device *netdev; +struct phy_device *phydev; + };enum macsec_offload offload;struct macsec_secy *secy;
Signature · 1 line
2.17.1
RFC v2 4/16 net: macsec: add support for offloading to the MAC
In reply to Igor RusskikhFrom: Antoine Tenart <[email protected]>
This patch adds a new MACsec offloading option, MACSEC_OFFLOAD_MAC, allowing a user to select a MAC as a provider for MACsec offloading operations.
--- drivers/net/macsec.c | 13 +++++++++++-- include/uapi/linux/if_link.h | 1 + tools/include/uapi/linux/if_link.h | 1 + 3 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/macsec.c +11 -2
@@ -325,7 +325,8 @@ static void macsec_set_shortlen(struct macsec_eth_header *h, size_t data_len)/* Checks if a MACsec interface is being offloaded to an hardware engine */ static bool macsec_is_offloaded (struct macsec_dev *macsec) { -if (macsec->offload ==MACSEC_OFFLOAD_PHY ) +if (macsec->offload ==MACSEC_OFFLOAD_MAC || + macsec->offload ==MACSEC_OFFLOAD_PHY )return true;return false;
@@ -341,6 +342,9 @@ static bool macsec_check_offload(enum macsec_offload offload,if (offload ==MACSEC_OFFLOAD_PHY )return macsec->real_dev->phydev && macsec->real_dev->phydev->macsec_ops; +else if (offload ==MACSEC_OFFLOAD_MAC ) +return macsec->real_dev->features &NETIF_F_HW_MACSEC && + macsec->real_dev->macsec_ops;return false; }
@@ -355,9 +359,14 @@ static const struct macsec_ops *__macsec_get_ops(enum macsec_offload offload,if (offload ==MACSEC_OFFLOAD_PHY ) ctx->phydev = macsec->real_dev->phydev; +else if (offload ==MACSEC_OFFLOAD_MAC ) + ctx->netdev = macsec->real_dev; } -return macsec->real_dev->phydev->macsec_ops; +if (offload ==MACSEC_OFFLOAD_PHY ) +return macsec->real_dev->phydev->macsec_ops; +else +return macsec->real_dev->macsec_ops; }/* Returns a pointer to the MACsec ops struct if any and updates the MACsec
include/uapi/linux/if_link.h +1 -0
@@ -489,6 +489,7 @@ enum macsec_validation_type {enum macsec_offload {MACSEC_OFFLOAD_OFF =0 ,MACSEC_OFFLOAD_PHY =1 , +MACSEC_OFFLOAD_MAC =2 , __MACSEC_OFFLOAD_END,MACSEC_OFFLOAD_MAX = __MACSEC_OFFLOAD_END -1 , };
tools/include/uapi/linux/if_link.h +1 -0
@@ -489,6 +489,7 @@ enum macsec_validation_type {enum macsec_offload {MACSEC_OFFLOAD_OFF =0 ,MACSEC_OFFLOAD_PHY =1 , +MACSEC_OFFLOAD_MAC =2 , __MACSEC_OFFLOAD_END,MACSEC_OFFLOAD_MAX = __MACSEC_OFFLOAD_END -1 , };
Signature · 1 line
2.17.1
RFC v2 5/16 net: macsec: init secy pointer in macsec_context
In reply to Igor RusskikhFrom: Dmitry Bogdanov <[email protected]>
This patch adds secy pointer initialization in the macsec_context. It will be used by MAC drivers in offloading operations.
--- drivers/net/macsec.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/macsec.c +15 -1
@@ -1692,6 +1692,7 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info) ctx.sa.assoc_num = assoc_num; ctx.sa.rx_sa = rx_sa; + ctx.secy = secy;memcpy (ctx.sa.key,nla_data (tb_sa[MACSEC_SA_ATTR_KEY ]),MACSEC_KEYID_LEN );
@@ -1733,6 +1734,7 @@ static int macsec_add_rxsc(struct sk_buff *skb, struct genl_info *info)struct nlattr **attrs = info->attrs;struct macsec_rx_sc *rx_sc;struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX +1 ]; +struct macsec_secy *secy;bool was_active;int ret;
@@ -1752,6 +1754,7 @@ static int macsec_add_rxsc(struct sk_buff *skb, struct genl_info *info)return PTR_ERR (dev); } + secy = &macsec_priv (dev)->secy; sci =nla_get_sci (tb_rxsc[MACSEC_RXSC_ATTR_SCI ]); rx_sc =create_rx_sc (dev, sci);
@@ -1775,6 +1778,7 @@ static int macsec_add_rxsc(struct sk_buff *skb, struct genl_info *info) } ctx.rx_sc = rx_sc; + ctx.secy = secy; ret =macsec_offload (ops->mdo_add_rxsc, &ctx);if (ret)
@@ -1900,6 +1904,7 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info) ctx.sa.assoc_num = assoc_num; ctx.sa.tx_sa = tx_sa; + ctx.secy = secy;memcpy (ctx.sa.key,nla_data (tb_sa[MACSEC_SA_ATTR_KEY ]),MACSEC_KEYID_LEN );
@@ -1969,6 +1974,7 @@ static int macsec_del_rxsa(struct sk_buff *skb, struct genl_info *info) ctx.sa.assoc_num = assoc_num; ctx.sa.rx_sa = rx_sa; + ctx.secy = secy; ret =macsec_offload (ops->mdo_del_rxsa, &ctx);if (ret)
@@ -2034,6 +2040,7 @@ static int macsec_del_rxsc(struct sk_buff *skb, struct genl_info *info) } ctx.rx_sc = rx_sc; + ctx.secy = secy; ret =macsec_offload (ops->mdo_del_rxsc, &ctx);if (ret) goto cleanup;
@@ -2092,6 +2099,7 @@ static int macsec_del_txsa(struct sk_buff *skb, struct genl_info *info) ctx.sa.assoc_num = assoc_num; ctx.sa.tx_sa = tx_sa; + ctx.secy = secy; ret =macsec_offload (ops->mdo_del_txsa, &ctx);if (ret)
@@ -2189,6 +2197,7 @@ static int macsec_upd_txsa(struct sk_buff *skb, struct genl_info *info) ctx.sa.assoc_num = assoc_num; ctx.sa.tx_sa = tx_sa; + ctx.secy = secy; ret =macsec_offload (ops->mdo_upd_txsa, &ctx);if (ret)
@@ -2269,6 +2278,7 @@ static int macsec_upd_rxsa(struct sk_buff *skb, struct genl_info *info) ctx.sa.assoc_num = assoc_num; ctx.sa.rx_sa = rx_sa; + ctx.secy = secy; ret =macsec_offload (ops->mdo_upd_rxsa, &ctx);if (ret)
@@ -2339,6 +2349,7 @@ static int macsec_upd_rxsc(struct sk_buff *skb, struct genl_info *info) } ctx.rx_sc = rx_sc; + ctx.secy = secy; ret =macsec_offload (ops->mdo_upd_rxsc, &ctx);if (ret)
@@ -3184,6 +3195,7 @@ static int macsec_dev_open(struct net_device *dev) goto clear_allmulti; } + ctx.secy = &macsec->secy; err =macsec_offload (ops->mdo_dev_open, &ctx);if (err) goto clear_allmulti;
@@ -3215,8 +3227,10 @@ static int macsec_dev_stop(struct net_device *dev)struct macsec_context ctx; ops =macsec_get_ops (macsec, &ctx); -if (ops) +if (ops) { + ctx.secy = &macsec->secy;macsec_offload (ops->mdo_dev_stop, &ctx); + } }dev_mc_unsync (real_dev, dev);
Signature · 1 line
2.17.1
RFC v2 6/16 net: macsec: allow multiple macsec devices with offload
In reply to Igor RusskikhFrom: Dmitry Bogdanov <[email protected]>
Offload engine can setup several SecY. Each macsec interface shall have its own mac address. It will filter a traffic by dest mac address.
--- drivers/net/macsec.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-)
drivers/net/macsec.c +1 -24
@@ -2389,11 +2389,10 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)enum macsec_offload offload, prev_offload;int (*func)(struct macsec_context *ctx);struct nlattr **attrs = info->attrs; -struct net_device *dev, *loop_dev; +struct net_device *dev;const struct macsec_ops *ops;struct macsec_context ctx;struct macsec_dev *macsec; -struct net *loop_net;int ret;if (!attrs[MACSEC_ATTR_IFINDEX ])
@@ -2421,28 +2420,6 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info) !macsec_check_offload(offload, macsec))return -EOPNOTSUPP ; -if (offload ==MACSEC_OFFLOAD_OFF ) - goto skip_limitation; - -/* Check the physical interface isn't offloading another interface -* first. -*/ -for_each_net (loop_net) { -for_each_netdev (loop_net, loop_dev) { -struct macsec_dev *priv; - -if (!netif_is_macsec (loop_dev)) -continue ; - - priv =macsec_priv (loop_dev); - -if (priv->real_dev == macsec->real_dev && - priv->offload !=MACSEC_OFFLOAD_OFF ) -return -EBUSY ; - } - } - -skip_limitation:/* Check if the net device is busy. */ if (netif_running (dev))return -EBUSY ;
Signature · 1 line
2.17.1
RFC v2 7/16 net: macsec: support multicast/broadcast when offloading
In reply to Igor RusskikhFrom: Mark Starovoytov <[email protected]>
The idea is simple. If the frame is an exact match for the controlled port (based on DA comparison), then we simply divert this skb to matching port.
Multicast/broadcast messages are delivered to all ports.
--- drivers/net/macsec.c | 51 +++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 13 deletions(-)
drivers/net/macsec.c +38 -13
@@ -947,22 +947,53 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb) {/* Deliver to the uncontrolled port by default */ enum rx_handler_result ret =RX_HANDLER_PASS ; +struct ethhdr *hdr =eth_hdr (skb);struct macsec_rxh_data *rxd;struct macsec_dev *macsec;rcu_read_lock (); rxd =macsec_data_rcu (skb->dev); -/* 10.6 If the management control validateFrames is not -* Strict, frames without a SecTAG are received, counted, and -* delivered to the Controlled Port -*/ list_for_each_entry_rcu (macsec, &rxd->secys, secys) {struct sk_buff *nskb;struct pcpu_secy_stats *secy_stats =this_cpu_ptr (macsec->stats); +struct net_device *ndev = macsec->secy.netdev; -if (!macsec_is_offloaded (macsec) && - macsec->secy.validate_frames ==MACSEC_VALIDATE_STRICT ) { +/* If h/w offloading is enabled, HW decodes frames and strips +* the SecTAG, so we have to deduce which port to deliver to. +*/ +if (macsec_is_offloaded (macsec) &&netif_running (ndev)) { +if (ether_addr_equal_64bits (hdr->h_dest, + ndev->dev_addr)) { +/* exact match, divert skb to this port */ + skb->dev = ndev; + skb->pkt_type =PACKET_HOST ; + ret =RX_HANDLER_ANOTHER ; + goto out; + }else if (is_multicast_ether_addr_64bits ( + hdr->h_dest)) { +/* multicast frame, deliver on this port too */ + nskb =skb_clone (skb,GFP_ATOMIC ); +if (!nskb) +break ; + + nskb->dev = ndev; +if (ether_addr_equal_64bits (hdr->h_dest, + ndev->broadcast)) + nskb->pkt_type =PACKET_BROADCAST ; +else + nskb->pkt_type =PACKET_MULTICAST ; + +netif_rx (nskb); + } +continue ; + } + +/* 10.6 If the management control validateFrames is not +* Strict, frames without a SecTAG are received, counted, and +* delivered to the Controlled Port +*/ +if (macsec->secy.validate_frames ==MACSEC_VALIDATE_STRICT ) {u64_stats_update_begin (&secy_stats->syncp); secy_stats->stats.InPktsNoTag++;u64_stats_update_end (&secy_stats->syncp);
@@ -974,19 +1005,13 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)if (!nskb)break ; - nskb->dev = macsec->secy.netdev; + nskb->dev = ndev;if (netif_rx (nskb) ==NET_RX_SUCCESS ) {u64_stats_update_begin (&secy_stats->syncp); secy_stats->stats.InPktsUntagged++;u64_stats_update_end (&secy_stats->syncp); } - -if (netif_running (macsec->secy.netdev) && -macsec_is_offloaded (macsec)) { - ret =RX_HANDLER_EXACT ; - goto out; - } } out:
Signature · 1 line
2.17.1
RFC v2 8/16 net: macsec: add support for getting offloaded stats
In reply to Igor RusskikhFrom: Dmitry Bogdanov <[email protected]>
When HW offloading is enabled, offloaded stats should be used, because s/w stats are wrong and out of sync with the HW in this case.
--- drivers/net/macsec.c | 316 +++++++++++++++++++++++++++++-------------- include/net/macsec.h | 24 ++++ 2 files changed, 235 insertions(+), 105 deletions(-)
drivers/net/macsec.c +211 -105
@@ -76,17 +76,6 @@ struct gcm_iv {__be32 pn; }; -struct macsec_dev_stats { -__u64 OutPktsUntagged; -__u64 InPktsUntagged; -__u64 OutPktsTooLong; -__u64 InPktsNoTag; -__u64 InPktsBadTag; -__u64 InPktsUnknownSCI; -__u64 InPktsNoSCI; -__u64 InPktsOverrun; -}; -#define MACSEC_VALIDATE_DEFAULT MACSEC_VALIDATE_STRICTstruct pcpu_secy_stats {
@@ -2489,207 +2478,309 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)return ret; } -static int copy_tx_sa_stats (struct sk_buff *skb, -struct macsec_tx_sa_stats __percpu *pstats) +static void get_tx_sa_stats (struct net_device *dev,int an, +struct macsec_tx_sa *tx_sa, +struct macsec_tx_sa_stats *sum) { -struct macsec_tx_sa_stats sum = {0 , }; +struct macsec_dev *macsec =macsec_priv (dev);int cpu; +/* If h/w offloading is available, propagate to the device */ +if (macsec_is_offloaded (macsec)) { +const struct macsec_ops *ops; +struct macsec_context ctx; + + ops =macsec_get_ops (macsec, &ctx); +if (ops) { + ctx.sa.assoc_num = an; + ctx.sa.tx_sa = tx_sa; + ctx.stats.tx_sa_stats = sum; + ctx.secy = &macsec_priv (dev)->secy; +macsec_offload (ops->mdo_get_tx_sa_stats, &ctx); + } +return ; + } +for_each_possible_cpu (cpu) { -const struct macsec_tx_sa_stats *stats =per_cpu_ptr (pstats, cpu); +const struct macsec_tx_sa_stats *stats = +per_cpu_ptr (tx_sa->stats, cpu); - sum.OutPktsProtected += stats->OutPktsProtected; - sum.OutPktsEncrypted += stats->OutPktsEncrypted; + sum->OutPktsProtected += stats->OutPktsProtected; + sum->OutPktsEncrypted += stats->OutPktsEncrypted; } +} -if (nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_OUT_PKTS_PROTECTED , sum.OutPktsProtected) || -nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_OUT_PKTS_ENCRYPTED , sum.OutPktsEncrypted)) +static int copy_tx_sa_stats (struct sk_buff *skb,struct macsec_tx_sa_stats *sum) +{ +if (nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_OUT_PKTS_PROTECTED , + sum->OutPktsProtected) || +nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_OUT_PKTS_ENCRYPTED , + sum->OutPktsEncrypted))return -EMSGSIZE ;return 0 ; } -static noinline_for_stack int -copy_rx_sa_stats (struct sk_buff *skb, -struct macsec_rx_sa_stats __percpu *pstats) +static void get_rx_sa_stats (struct net_device *dev, +struct macsec_rx_sc *rx_sc,int an, +struct macsec_rx_sa *rx_sa, +struct macsec_rx_sa_stats *sum) { -struct macsec_rx_sa_stats sum = {0 , }; +struct macsec_dev *macsec =macsec_priv (dev);int cpu; -for_each_possible_cpu (cpu) { -const struct macsec_rx_sa_stats *stats =per_cpu_ptr (pstats, cpu); +/* If h/w offloading is available, propagate to the device */ +if (macsec_is_offloaded (macsec)) { +const struct macsec_ops *ops; +struct macsec_context ctx; - sum.InPktsOK += stats->InPktsOK; - sum.InPktsInvalid += stats->InPktsInvalid; - sum.InPktsNotValid += stats->InPktsNotValid; - sum.InPktsNotUsingSA += stats->InPktsNotUsingSA; - sum.InPktsUnusedSA += stats->InPktsUnusedSA; + ops =macsec_get_ops (macsec, &ctx); +if (ops) { + ctx.sa.assoc_num = an; + ctx.sa.rx_sa = rx_sa; + ctx.stats.rx_sa_stats = sum; + ctx.secy = &macsec_priv (dev)->secy; + ctx.rx_sc = rx_sc; +macsec_offload (ops->mdo_get_rx_sa_stats, &ctx); + } +return ; + } + +for_each_possible_cpu (cpu) { +const struct macsec_rx_sa_stats *stats = +per_cpu_ptr (rx_sa->stats, cpu); + + sum->InPktsOK += stats->InPktsOK; + sum->InPktsInvalid += stats->InPktsInvalid; + sum->InPktsNotValid += stats->InPktsNotValid; + sum->InPktsNotUsingSA += stats->InPktsNotUsingSA; + sum->InPktsUnusedSA += stats->InPktsUnusedSA; } +} -if (nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_OK , sum.InPktsOK) || -nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_INVALID , sum.InPktsInvalid) || -nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_VALID , sum.InPktsNotValid) || -nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_USING_SA , sum.InPktsNotUsingSA) || -nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_UNUSED_SA , sum.InPktsUnusedSA)) +static int copy_rx_sa_stats (struct sk_buff *skb, +struct macsec_rx_sa_stats *sum) +{ +if (nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_OK , sum->InPktsOK) || +nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_INVALID , + sum->InPktsInvalid) || +nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_VALID , + sum->InPktsNotValid) || +nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_USING_SA , + sum->InPktsNotUsingSA) || +nla_put_u32 (skb,MACSEC_SA_STATS_ATTR_IN_PKTS_UNUSED_SA , + sum->InPktsUnusedSA))return -EMSGSIZE ;return 0 ; } -static noinline_for_stack int -copy_rx_sc_stats (struct sk_buff *skb,struct pcpu_rx_sc_stats __percpu *pstats) +static void get_rx_sc_stats (struct net_device *dev, +struct macsec_rx_sc *rx_sc, +struct macsec_rx_sc_stats *sum) { -struct macsec_rx_sc_stats sum = {0 , }; +struct macsec_dev *macsec =macsec_priv (dev);int cpu; +/* If h/w offloading is available, propagate to the device */ +if (macsec_is_offloaded (macsec)) { +const struct macsec_ops *ops; +struct macsec_context ctx; + + ops =macsec_get_ops (macsec, &ctx); +if (ops) { + ctx.stats.rx_sc_stats = sum; + ctx.secy = &macsec_priv (dev)->secy; + ctx.rx_sc = rx_sc; +macsec_offload (ops->mdo_get_rx_sc_stats, &ctx); + } +return ; + } +for_each_possible_cpu (cpu) {const struct pcpu_rx_sc_stats *stats;struct macsec_rx_sc_stats tmp;unsigned int start; - stats =per_cpu_ptr (pstats, cpu); + stats =per_cpu_ptr (rx_sc->stats, cpu);do { start =u64_stats_fetch_begin_irq (&stats->syncp);memcpy (&tmp, &stats->stats,sizeof (tmp)); }while (u64_stats_fetch_retry_irq (&stats->syncp, start)); - sum.InOctetsValidated += tmp.InOctetsValidated; - sum.InOctetsDecrypted += tmp.InOctetsDecrypted; - sum.InPktsUnchecked += tmp.InPktsUnchecked; - sum.InPktsDelayed += tmp.InPktsDelayed; - sum.InPktsOK += tmp.InPktsOK; - sum.InPktsInvalid += tmp.InPktsInvalid; - sum.InPktsLate += tmp.InPktsLate; - sum.InPktsNotValid += tmp.InPktsNotValid; - sum.InPktsNotUsingSA += tmp.InPktsNotUsingSA; - sum.InPktsUnusedSA += tmp.InPktsUnusedSA; + sum->InOctetsValidated += tmp.InOctetsValidated; + sum->InOctetsDecrypted += tmp.InOctetsDecrypted; + sum->InPktsUnchecked += tmp.InPktsUnchecked; + sum->InPktsDelayed += tmp.InPktsDelayed; + sum->InPktsOK += tmp.InPktsOK; + sum->InPktsInvalid += tmp.InPktsInvalid; + sum->InPktsLate += tmp.InPktsLate; + sum->InPktsNotValid += tmp.InPktsNotValid; + sum->InPktsNotUsingSA += tmp.InPktsNotUsingSA; + sum->InPktsUnusedSA += tmp.InPktsUnusedSA; } +} +static int copy_rx_sc_stats (struct sk_buff *skb,struct macsec_rx_sc_stats *sum) +{if (nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_OCTETS_VALIDATED , - sum.InOctetsValidated, + sum->InOctetsValidated,MACSEC_RXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_OCTETS_DECRYPTED , - sum.InOctetsDecrypted, + sum->InOctetsDecrypted,MACSEC_RXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNCHECKED , - sum.InPktsUnchecked, + sum->InPktsUnchecked,MACSEC_RXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_PKTS_DELAYED , - sum.InPktsDelayed, + sum->InPktsDelayed,MACSEC_RXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_PKTS_OK , - sum.InPktsOK, + sum->InPktsOK,MACSEC_RXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_PKTS_INVALID , - sum.InPktsInvalid, + sum->InPktsInvalid,MACSEC_RXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_PKTS_LATE , - sum.InPktsLate, + sum->InPktsLate,MACSEC_RXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_VALID , - sum.InPktsNotValid, + sum->InPktsNotValid,MACSEC_RXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_USING_SA , - sum.InPktsNotUsingSA, + sum->InPktsNotUsingSA,MACSEC_RXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNUSED_SA , - sum.InPktsUnusedSA, + sum->InPktsUnusedSA,MACSEC_RXSC_STATS_ATTR_PAD ))return -EMSGSIZE ;return 0 ; } -static noinline_for_stack int -copy_tx_sc_stats (struct sk_buff *skb,struct pcpu_tx_sc_stats __percpu *pstats) +static void get_tx_sc_stats (struct net_device *dev, +struct macsec_tx_sc_stats *sum) { -struct macsec_tx_sc_stats sum = {0 , }; +struct macsec_dev *macsec =macsec_priv (dev);int cpu; +/* If h/w offloading is available, propagate to the device */ +if (macsec_is_offloaded (macsec)) { +const struct macsec_ops *ops; +struct macsec_context ctx; + + ops =macsec_get_ops (macsec, &ctx); +if (ops) { + ctx.stats.tx_sc_stats = sum; + ctx.secy = &macsec_priv (dev)->secy; +macsec_offload (ops->mdo_get_tx_sc_stats, &ctx); + } +return ; + } +for_each_possible_cpu (cpu) {const struct pcpu_tx_sc_stats *stats;struct macsec_tx_sc_stats tmp;unsigned int start; - stats =per_cpu_ptr (pstats, cpu); + stats =per_cpu_ptr (macsec_priv (dev)->secy.tx_sc.stats, cpu);do { start =u64_stats_fetch_begin_irq (&stats->syncp);memcpy (&tmp, &stats->stats,sizeof (tmp)); }while (u64_stats_fetch_retry_irq (&stats->syncp, start)); - sum.OutPktsProtected += tmp.OutPktsProtected; - sum.OutPktsEncrypted += tmp.OutPktsEncrypted; - sum.OutOctetsProtected += tmp.OutOctetsProtected; - sum.OutOctetsEncrypted += tmp.OutOctetsEncrypted; + sum->OutPktsProtected += tmp.OutPktsProtected; + sum->OutPktsEncrypted += tmp.OutPktsEncrypted; + sum->OutOctetsProtected += tmp.OutOctetsProtected; + sum->OutOctetsEncrypted += tmp.OutOctetsEncrypted; } +} +static int copy_tx_sc_stats (struct sk_buff *skb,struct macsec_tx_sc_stats *sum) +{if (nla_put_u64_64bit (skb,MACSEC_TXSC_STATS_ATTR_OUT_PKTS_PROTECTED , - sum.OutPktsProtected, + sum->OutPktsProtected,MACSEC_TXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_TXSC_STATS_ATTR_OUT_PKTS_ENCRYPTED , - sum.OutPktsEncrypted, + sum->OutPktsEncrypted,MACSEC_TXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_PROTECTED , - sum.OutOctetsProtected, + sum->OutOctetsProtected,MACSEC_TXSC_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_ENCRYPTED , - sum.OutOctetsEncrypted, + sum->OutOctetsEncrypted,MACSEC_TXSC_STATS_ATTR_PAD ))return -EMSGSIZE ;return 0 ; } -static noinline_for_stack int -copy_secy_stats (struct sk_buff *skb,struct pcpu_secy_stats __percpu *pstats) +static void get_secy_stats (struct net_device *dev,struct macsec_dev_stats *sum) { -struct macsec_dev_stats sum = {0 , }; +struct macsec_dev *macsec =macsec_priv (dev);int cpu; +/* If h/w offloading is available, propagate to the device */ +if (macsec_is_offloaded (macsec)) { +const struct macsec_ops *ops; +struct macsec_context ctx; + + ops =macsec_get_ops (macsec, &ctx); +if (ops) { + ctx.stats.dev_stats = sum; + ctx.secy = &macsec_priv (dev)->secy; +macsec_offload (ops->mdo_get_dev_stats, &ctx); + } +return ; + } +for_each_possible_cpu (cpu) {const struct pcpu_secy_stats *stats;struct macsec_dev_stats tmp;unsigned int start; - stats =per_cpu_ptr (pstats, cpu); + stats =per_cpu_ptr (macsec_priv (dev)->stats, cpu);do { start =u64_stats_fetch_begin_irq (&stats->syncp);memcpy (&tmp, &stats->stats,sizeof (tmp)); }while (u64_stats_fetch_retry_irq (&stats->syncp, start)); - sum.OutPktsUntagged += tmp.OutPktsUntagged; - sum.InPktsUntagged += tmp.InPktsUntagged; - sum.OutPktsTooLong += tmp.OutPktsTooLong; - sum.InPktsNoTag += tmp.InPktsNoTag; - sum.InPktsBadTag += tmp.InPktsBadTag; - sum.InPktsUnknownSCI += tmp.InPktsUnknownSCI; - sum.InPktsNoSCI += tmp.InPktsNoSCI; - sum.InPktsOverrun += tmp.InPktsOverrun; + sum->OutPktsUntagged += tmp.OutPktsUntagged; + sum->InPktsUntagged += tmp.InPktsUntagged; + sum->OutPktsTooLong += tmp.OutPktsTooLong; + sum->InPktsNoTag += tmp.InPktsNoTag; + sum->InPktsBadTag += tmp.InPktsBadTag; + sum->InPktsUnknownSCI += tmp.InPktsUnknownSCI; + sum->InPktsNoSCI += tmp.InPktsNoSCI; + sum->InPktsOverrun += tmp.InPktsOverrun; } +} +static int copy_secy_stats (struct sk_buff *skb,struct macsec_dev_stats *sum) +{if (nla_put_u64_64bit (skb,MACSEC_SECY_STATS_ATTR_OUT_PKTS_UNTAGGED , - sum.OutPktsUntagged, + sum->OutPktsUntagged,MACSEC_SECY_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_SECY_STATS_ATTR_IN_PKTS_UNTAGGED , - sum.InPktsUntagged, + sum->InPktsUntagged,MACSEC_SECY_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_SECY_STATS_ATTR_OUT_PKTS_TOO_LONG , - sum.OutPktsTooLong, + sum->OutPktsTooLong,MACSEC_SECY_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_TAG , - sum.InPktsNoTag, + sum->InPktsNoTag,MACSEC_SECY_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_SECY_STATS_ATTR_IN_PKTS_BAD_TAG , - sum.InPktsBadTag, + sum->InPktsBadTag,MACSEC_SECY_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_SECY_STATS_ATTR_IN_PKTS_UNKNOWN_SCI , - sum.InPktsUnknownSCI, + sum->InPktsUnknownSCI,MACSEC_SECY_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_SCI , - sum.InPktsNoSCI, + sum->InPktsNoSCI,MACSEC_SECY_STATS_ATTR_PAD ) ||nla_put_u64_64bit (skb,MACSEC_SECY_STATS_ATTR_IN_PKTS_OVERRUN , - sum.InPktsOverrun, + sum->InPktsOverrun,MACSEC_SECY_STATS_ATTR_PAD ))return -EMSGSIZE ;
@@ -2750,7 +2841,12 @@ static noinline_for_stack int dump_secy(struct macsec_secy *secy, struct net_device *dev, struct sk_buff *skb, struct netlink_callback *cb) { + struct macsec_tx_sc_stats tx_sc_stats = {0, }; +struct macsec_tx_sa_stats tx_sa_stats = {0 , }; +struct macsec_rx_sc_stats rx_sc_stats = {0 , }; +struct macsec_rx_sa_stats rx_sa_stats = {0 , };struct macsec_dev *macsec =netdev_priv (dev); +struct macsec_dev_stats dev_stats = {0 , };struct macsec_tx_sc *tx_sc = &secy->tx_sc;struct nlattr *txsa_list, *rxsc_list;struct macsec_rx_sc *rx_sc;
@@ -2781,7 +2877,9 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev, attr =nla_nest_start_noflag (skb,MACSEC_ATTR_TXSC_STATS );if (!attr) goto nla_put_failure; -if (copy_tx_sc_stats (skb, tx_sc->stats)) { + +get_tx_sc_stats (dev, &tx_sc_stats); +if (copy_tx_sc_stats (skb, &tx_sc_stats)) {nla_nest_cancel (skb, attr); goto nla_put_failure; }
@@ -2790,7 +2888,8 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev, attr =nla_nest_start_noflag (skb,MACSEC_ATTR_SECY_STATS );if (!attr) goto nla_put_failure; -if (copy_secy_stats (skb,macsec_priv (dev)->stats)) { +get_secy_stats (dev, &dev_stats); +if (copy_secy_stats (skb, &dev_stats)) {nla_nest_cancel (skb, attr); goto nla_put_failure; }
@@ -2812,22 +2911,15 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev, goto nla_put_failure; } -if (nla_put_u8 (skb,MACSEC_SA_ATTR_AN , i) || -nla_put_u32 (skb,MACSEC_SA_ATTR_PN , tx_sa->next_pn) || -nla_put (skb,MACSEC_SA_ATTR_KEYID ,MACSEC_KEYID_LEN , tx_sa->key.id) || -nla_put_u8 (skb,MACSEC_SA_ATTR_ACTIVE , tx_sa->active)) { -nla_nest_cancel (skb, txsa_nest); -nla_nest_cancel (skb, txsa_list); - goto nla_put_failure; - } - attr =nla_nest_start_noflag (skb,MACSEC_SA_ATTR_STATS );if (!attr) {nla_nest_cancel (skb, txsa_nest);nla_nest_cancel (skb, txsa_list); goto nla_put_failure; } -if (copy_tx_sa_stats (skb, tx_sa->stats)) { +memset (&tx_sa_stats,0 ,sizeof (tx_sa_stats)); +get_tx_sa_stats (dev, i, tx_sa, &tx_sa_stats); +if (copy_tx_sa_stats (skb, &tx_sa_stats)) {nla_nest_cancel (skb, attr);nla_nest_cancel (skb, txsa_nest);nla_nest_cancel (skb, txsa_list);
@@ -2835,6 +2927,16 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev, }nla_nest_end (skb, attr); +if (nla_put_u8 (skb,MACSEC_SA_ATTR_AN , i) || +nla_put_u32 (skb,MACSEC_SA_ATTR_PN , tx_sa->next_pn) || +nla_put (skb,MACSEC_SA_ATTR_KEYID ,MACSEC_KEYID_LEN , + tx_sa->key.id) || +nla_put_u8 (skb,MACSEC_SA_ATTR_ACTIVE , tx_sa->active)) { +nla_nest_cancel (skb, txsa_nest); +nla_nest_cancel (skb, txsa_list); + goto nla_put_failure; + } +nla_nest_end (skb, txsa_nest); }nla_nest_end (skb, txsa_list);
@@ -2868,7 +2970,9 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,nla_nest_cancel (skb, rxsc_list); goto nla_put_failure; } -if (copy_rx_sc_stats (skb, rx_sc->stats)) { +memset (&rx_sc_stats,0 ,sizeof (rx_sc_stats)); +get_rx_sc_stats (dev, rx_sc, &rx_sc_stats); +if (copy_rx_sc_stats (skb, &rx_sc_stats)) {nla_nest_cancel (skb, attr);nla_nest_cancel (skb, rxsc_nest);nla_nest_cancel (skb, rxsc_list);
@@ -2907,7 +3011,9 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,nla_nest_cancel (skb, rxsc_list); goto nla_put_failure; } -if (copy_rx_sa_stats (skb, rx_sa->stats)) { +memset (&rx_sa_stats,0 ,sizeof (rx_sa_stats)); +get_rx_sa_stats (dev, rx_sc, i, rx_sa, &rx_sa_stats); +if (copy_rx_sa_stats (skb, &rx_sa_stats)) {nla_nest_cancel (skb, attr);nla_nest_cancel (skb, rxsa_list);nla_nest_cancel (skb, rxsc_nest);
include/net/macsec.h +24 -0
@@ -58,6 +58,17 @@ struct macsec_tx_sc_stats {__u64 OutOctetsEncrypted; }; +struct macsec_dev_stats { +__u64 OutPktsUntagged; +__u64 InPktsUntagged; +__u64 OutPktsTooLong; +__u64 InPktsNoTag; +__u64 InPktsBadTag; +__u64 InPktsUnknownSCI; +__u64 InPktsNoSCI; +__u64 InPktsOverrun; +}; +/** * struct macsec_rx_sa - receive secure association * @active:
@@ -194,6 +205,13 @@ struct macsec_context {struct macsec_tx_sa *tx_sa; }; } sa; +union { +struct macsec_tx_sc_stats *tx_sc_stats; +struct macsec_tx_sa_stats *tx_sa_stats; +struct macsec_rx_sc_stats *rx_sc_stats; +struct macsec_rx_sa_stats *rx_sa_stats; +struct macsec_dev_stats *dev_stats; + } stats; u8 prepare:1; };
@@ -220,6 +238,12 @@ struct macsec_ops {int (*mdo_add_txsa)(struct macsec_context *ctx);int (*mdo_upd_txsa)(struct macsec_context *ctx);int (*mdo_del_txsa)(struct macsec_context *ctx); +/* Statistics */ +int (*mdo_get_dev_stats)(struct macsec_context *ctx); +int (*mdo_get_tx_sc_stats)(struct macsec_context *ctx); +int (*mdo_get_tx_sa_stats)(struct macsec_context *ctx); +int (*mdo_get_rx_sc_stats)(struct macsec_context *ctx); +int (*mdo_get_rx_sa_stats)(struct macsec_context *ctx); };void macsec_pn_wrapped (struct macsec_secy *secy,struct macsec_tx_sa *tx_sa);
Signature · 1 line
2.17.1
RFC v2 9/16 net: macsec: report real_dev features when HW offloading is enabled
In reply to Igor RusskikhFrom: Mark Starovoytov <[email protected]>
This patch makes real_dev_feature propagation by MACSec offloaded device.
Issue description:real_dev features are disabled upon macsec creation.
Root cause:
Features limitation (specific to SW MACSec limitation) is being applied to HW offloaded case as well.
This causes 'set_features' request on the real_dev with reduced feature set due to chain propagation.
Proposed solution:
Report real_dev features when HW offloading is enabled.
NB! MACSec offloaded device does not propagate VLAN offload features at the moment. This can potentially be added later on as a separate patch.
Note: this patch requires HW offloading to be enabled by default in order to function properly.
--- drivers/net/macsec.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/net/macsec.c +22 -4
@@ -2469,6 +2469,10 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info) goto rollback;rtnl_unlock (); +/* Force features update, since they are different for SW MACSec and +* HW offloading cases. +*/ +netdev_update_features (dev);return 0 ; rollback:
@@ -3214,9 +3218,16 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,return ret; } -#define MACSEC_FEATURES \ +#define SW_MACSEC_FEATURES \ (NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST) +/* If h/w offloading is enabled, use real device features save for +* VLAN_FEATURES - they require additional ops +* HW_MACSEC - no reason to report it +*/ +#define REAL_DEV_FEATURES (dev) \ + ((dev)->features & ~(NETIF_F_VLAN_FEATURES | NETIF_F_HW_MACSEC)) +static int macsec_dev_init (struct net_device *dev) {struct macsec_dev *macsec =macsec_priv (dev);
@@ -3233,8 +3244,12 @@ static int macsec_dev_init(struct net_device *dev)return err; } - dev->features = real_dev->features &MACSEC_FEATURES ; - dev->features |=NETIF_F_LLTX |NETIF_F_GSO_SOFTWARE ; +if (macsec_is_offloaded (macsec)) { + dev->features =REAL_DEV_FEATURES (real_dev); + }else { + dev->features = real_dev->features &SW_MACSEC_FEATURES ; + dev->features |=NETIF_F_LLTX |NETIF_F_GSO_SOFTWARE ; + } dev->needed_headroom = real_dev->needed_headroom +MACSEC_NEEDED_HEADROOM ;
@@ -3263,7 +3278,10 @@ static netdev_features_t macsec_fix_features(struct net_device *dev,struct macsec_dev *macsec =macsec_priv (dev);struct net_device *real_dev = macsec->real_dev; - features &= (real_dev->features &MACSEC_FEATURES ) | +if (macsec_is_offloaded (macsec)) +return REAL_DEV_FEATURES (real_dev); + + features &= (real_dev->features &SW_MACSEC_FEATURES ) |NETIF_F_GSO_SOFTWARE |NETIF_F_SOFT_FEATURES ; features |=NETIF_F_LLTX ;
Signature · 1 line
2.17.1
RFC v2 10/16 net: atlantic: MACSec offload skeleton
In reply to Igor RusskikhFrom: Dmitry Bogdanov <[email protected]>
This patch adds basic functionality for MACSec offloading for Atlantic NICs.
MACSec offloading functionality is enabled if network card has appropriate FW that has MACSec offloading enabled in config.
Actual functionality (ingress, egress, etc) will be added in follow-up patches.
--- drivers/net/ethernet/aquantia/Kconfig | 1 + .../net/ethernet/aquantia/atlantic/Makefile | 4 + .../net/ethernet/aquantia/atlantic/aq_hw.h | 6 + .../ethernet/aquantia/atlantic/aq_macsec.c | 179 ++++++++++++++++++ .../ethernet/aquantia/atlantic/aq_macsec.h | 56 ++++++ .../net/ethernet/aquantia/atlantic/aq_nic.c | 16 ++ .../net/ethernet/aquantia/atlantic/aq_nic.h | 4 + .../ethernet/aquantia/atlantic/aq_pci_func.c | 5 + .../aquantia/atlantic/hw_atl/hw_atl_utils.h | 51 ++++- .../atlantic/hw_atl/hw_atl_utils_fw2x.c | 69 +++++++ 10 files changed, 383 insertions(+), 8 deletions(-) create mode 100644 drivers/net/ethernet/aquantia/atlantic/aq_macsec.c create mode 100644 drivers/net/ethernet/aquantia/atlantic/aq_macsec.h
drivers/net/ethernet/aquantia/Kconfig +1 -0
@@ -20,6 +20,7 @@ config AQTION tristate "aQuantia AQtion(tm) Support" depends on PCI depends on X86_64 || ARM64 || COMPILE_TEST + depends on MACSEC || MACSEC=n ---help--- This enables the support for the aQuantia AQtion(tm) Ethernet card.
drivers/net/ethernet/aquantia/atlantic/Makefile +4 -0
@@ -8,6 +8,8 @@ obj-$(CONFIG_AQTION) += atlantic.o +ccflags-y += -I$(src) + atlantic-objs := aq_main.o \ aq_nic.o \ aq_pci_func.o \
@@ -24,4 +26,6 @@ atlantic-objs := aq_main.o \ hw_atl/hw_atl_utils_fw2x.o \ hw_atl/hw_atl_llh.o +atlantic-$(CONFIG_MACSEC) += aq_macsec.o + atlantic-$(CONFIG_PTP_1588_CLOCK) += aq_ptp.o
drivers/net/ethernet/aquantia/atlantic/aq_hw.h +6 -0
@@ -343,6 +343,12 @@ struct aq_fw_ops {int (*get_eee_rate)(struct aq_hw_s *self,u32 *rate,u32 *supported_rates); + +u32 (*get_link_capabilities)(struct aq_hw_s *self); + +int (*send_macsec_req)(struct aq_hw_s *self, +struct macsec_msg_fw_request *msg, + struct macsec_msg_fw_response *resp); };#endif /* AQ_HW_H */
drivers/net/ethernet/aquantia/atlantic/aq_macsec.c new file +179 -0
179 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/aq_macsec.h new file +56 -0
56 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +16 -0
@@ -11,6 +11,7 @@#include "aq_vec.h" #include "aq_hw.h" #include "aq_pci_func.h" +#include "aq_macsec.h" #include "aq_main.h" #include "aq_phy.h" #include "aq_ptp.h"
@@ -176,6 +177,9 @@ static int aq_nic_update_link_status(struct aq_nic_s *self)aq_utils_obj_clear (&self->flags,AQ_NIC_LINK_DOWN );netif_carrier_on (self->ndev); +#if IS_ENABLED (CONFIG_MACSEC ) +aq_macsec_enable (self); +#endif netif_tx_wake_all_queues (self->ndev); }if (netif_carrier_ok (self->ndev) && !self->link_status.mbps) {
@@ -217,6 +221,10 @@ static void aq_nic_service_task(struct work_struct *work)if (err)return ; +#if IS_ENABLED (CONFIG_MACSEC ) +aq_macsec_work (self); +#endif +mutex_lock (&self->fwreq_mutex);if (self->aq_fw_ops->update_stats) self->aq_fw_ops->update_stats (self->aq_hw);
@@ -262,6 +270,10 @@ int aq_nic_ndev_register(struct aq_nic_s *self)if (err) goto err_exit; +#if IS_ENABLED (CONFIG_MACSEC ) +aq_macsec_init (self); +#endif +mutex_lock (&self->fwreq_mutex); err = self->aq_fw_ops->get_mac_permanent (self->aq_hw, self->ndev->dev_addr);
@@ -296,6 +308,10 @@ int aq_nic_ndev_register(struct aq_nic_s *self) goto err_exit; err_exit: +#if IS_ENABLED (CONFIG_MACSEC ) +if (err) +aq_macsec_free (self); +#endif return err; }
drivers/net/ethernet/aquantia/atlantic/aq_nic.h +4 -0
@@ -17,6 +17,7 @@ struct aq_ring_s;struct aq_hw_ops ;struct aq_fw_s ;struct aq_vec_s ; +struct aq_macsec_cfg ;struct aq_ptp_s ;enum aq_rx_filter_type ;
@@ -129,6 +130,9 @@ struct aq_nic_s {u32 irqvecs;/* mutex to serialize FW interface access operations */ struct mutex fwreq_mutex; +#if IS_ENABLED (CONFIG_MACSEC ) +struct aq_macsec_cfg *macsec_cfg; +#endif /* PTP support */ struct aq_ptp_s *aq_ptp;struct aq_hw_rx_fltrs_s aq_hw_rx_fltrs;
drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c +5 -0
@@ -18,6 +18,7 @@#include "hw_atl/hw_atl_b0.h" #include "aq_filters.h" #include "aq_drvinfo.h" +#include "aq_macsec.h" static const struct pci_device_id aq_pci_tbl[] = { {PCI_VDEVICE (AQUANTIA ,AQ_DEVICE_ID_0001 ), },
@@ -324,6 +325,10 @@ static void aq_pci_remove(struct pci_dev *pdev)aq_clear_rxnfc_all_rules (self);if (self->ndev->reg_state ==NETREG_REGISTERED )unregister_netdev (self->ndev); + +#if IS_ENABLED (CONFIG_MACSEC ) +aq_macsec_free (self); +#endif aq_nic_free_vectors (self);aq_pci_free_irq_vectors (self);iounmap (self->aq_hw->mmio);
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.h +43 -8
83 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c +69 -0
96 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC v2 11/16 net: atlantic: MACSec egress offload HW bindings
In reply to Igor RusskikhFrom: Dmitry Bogdanov <[email protected]>
This patch adds the Atlantic HW-specific bindings for MACSec egress, e.g. register addresses / structs, helper function, etc, which will be used by actual callback implementations.
--- .../net/ethernet/aquantia/atlantic/Makefile | 3 +- .../atlantic/macsec/MSS_Egress_registers.h | 78 ++ .../aquantia/atlantic/macsec/macsec_api.c | 1154 +++++++++++++++++ .../aquantia/atlantic/macsec/macsec_api.h | 133 ++ .../aquantia/atlantic/macsec/macsec_struct.h | 322 +++++ 5 files changed, 1689 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/MSS_Egress_registers.h create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.c create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.h create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/macsec_struct.h
drivers/net/ethernet/aquantia/atlantic/Makefile +2 -1
@@ -24,7 +24,8 @@ atlantic-objs := aq_main.o \ hw_atl/hw_atl_b0.o \ hw_atl/hw_atl_utils.o \ hw_atl/hw_atl_utils_fw2x.o \ - hw_atl/hw_atl_llh.o + hw_atl/hw_atl_llh.o \ + macsec/macsec_api.o atlantic-$(CONFIG_MACSEC) += aq_macsec.o
drivers/net/ethernet/aquantia/atlantic/macsec/MSS_Egress_registers.h new file +78 -0
78 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.c new file +1154 -0
1,154 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.h new file +133 -0
133 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/macsec/macsec_struct.h new file +322 -0
322 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC v2 12/16 net: atlantic: MACSec egress offload implementation
In reply to Igor RusskikhFrom: Dmitry Bogdanov <[email protected]>
This patch adds support for MACSec egress HW offloading on Atlantic network cards.
--- .../ethernet/aquantia/atlantic/aq_macsec.c | 681 +++++++++++++++++- .../ethernet/aquantia/atlantic/aq_macsec.h | 4 + 2 files changed, 677 insertions(+), 8 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_macsec.c +673 -8
@@ -12,44 +12,524 @@#include "aq_nic.h" #include <linux/rtnetlink.h> +#include "macsec/macsec_api.h" +#define AQ_MACSEC_KEY_LEN_128_BIT 16 +#define AQ_MACSEC_KEY_LEN_192_BIT 24 +#define AQ_MACSEC_KEY_LEN_256_BIT 32 + +enum aq_clear_type { +/* update HW configuration */ +AQ_CLEAR_HW =BIT (0 ), +/* update SW configuration (busy bits, pointers) */ +AQ_CLEAR_SW =BIT (1 ), +/* update both HW and SW configuration */ +AQ_CLEAR_ALL =AQ_CLEAR_HW |AQ_CLEAR_SW , +}; + +static int aq_clear_txsc (struct aq_nic_s *nic,const int txsc_idx, +enum aq_clear_type clear_type); +static int aq_clear_txsa (struct aq_nic_s *nic,struct aq_macsec_txsc *aq_txsc, +const int sa_num,enum aq_clear_type clear_type); +static int aq_clear_secy (struct aq_nic_s *nic,const struct macsec_secy *secy, +enum aq_clear_type clear_type); +static int aq_apply_macsec_cfg (struct aq_nic_s *nic); +static int aq_apply_secy_cfg (struct aq_nic_s *nic, +const struct macsec_secy *secy); + +static void aq_ether_addr_to_mac (u32 mac[2 ],unsigned char *emac) +{ +u32 tmp[2 ] = {0 }; + +memcpy (((u8 *)tmp) +2 , emac,ETH_ALEN ); + + mac[0 ] =swab32 (tmp[1 ]); + mac[1 ] =swab32 (tmp[0 ]); +} + +/* There's a 1:1 mapping between SecY and TX SC */ +static int aq_get_txsc_idx_from_secy (struct aq_macsec_cfg *macsec_cfg, +const struct macsec_secy *secy) +{ +int i; + +if (unlikely (!secy)) +return -1 ; + +for (i =0 ; i <AQ_MACSEC_MAX_SC ; i++) { +if (macsec_cfg->aq_txsc[i].sw_secy == secy) +return i; + } +return -1 ; +} + +static int aq_get_txsc_idx_from_sc_idx (const enum aq_macsec_sc_sa sc_sa, +const unsigned int sc_idx) +{ +switch (sc_sa) { +case aq_macsec_sa_sc_4sa_8sc: +return sc_idx >>2 ; +case aq_macsec_sa_sc_2sa_16sc: +return sc_idx >>1 ; +case aq_macsec_sa_sc_1sa_32sc: +return sc_idx; +default : +WARN_ONCE (1 ,"Invalid sc_sa" ); + } +return -1 ; +} + +/* Rotate keys u32[8] */ +static void aq_rotate_keys (u32 (*key)[8 ],const int key_len) +{ +u32 tmp[8 ] = {0 }; + +memcpy (&tmp, key,sizeof (tmp)); +memset (*key,0 ,sizeof (*key)); + +if (key_len ==AQ_MACSEC_KEY_LEN_128_BIT ) { + (*key)[0 ] =swab32 (tmp[3 ]); + (*key)[1 ] =swab32 (tmp[2 ]); + (*key)[2 ] =swab32 (tmp[1 ]); + (*key)[3 ] =swab32 (tmp[0 ]); + }else if (key_len ==AQ_MACSEC_KEY_LEN_192_BIT ) { + (*key)[0 ] =swab32 (tmp[5 ]); + (*key)[1 ] =swab32 (tmp[4 ]); + (*key)[2 ] =swab32 (tmp[3 ]); + (*key)[3 ] =swab32 (tmp[2 ]); + (*key)[4 ] =swab32 (tmp[1 ]); + (*key)[5 ] =swab32 (tmp[0 ]); + }else if (key_len ==AQ_MACSEC_KEY_LEN_256_BIT ) { + (*key)[0 ] =swab32 (tmp[7 ]); + (*key)[1 ] =swab32 (tmp[6 ]); + (*key)[2 ] =swab32 (tmp[5 ]); + (*key)[3 ] =swab32 (tmp[4 ]); + (*key)[4 ] =swab32 (tmp[3 ]); + (*key)[5 ] =swab32 (tmp[2 ]); + (*key)[6 ] =swab32 (tmp[1 ]); + (*key)[7 ] =swab32 (tmp[0 ]); + }else { +pr_warn ("Rotate_keys: invalid key_len\n" ); + } +} +static int aq_mdo_dev_open (struct macsec_context *ctx) { -return 0 ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +int ret =0 ; + +if (ctx->prepare) +return 0 ; + +if (netif_carrier_ok (nic->ndev)) + ret =aq_apply_secy_cfg (nic, ctx->secy); + +return ret; }static int aq_mdo_dev_stop (struct macsec_context *ctx) { +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +int i; + +if (ctx->prepare) +return 0 ; + +for (i =0 ; i <AQ_MACSEC_MAX_SC ; i++) { +if (nic->macsec_cfg->txsc_idx_busy &BIT (i)) +aq_clear_secy (nic, nic->macsec_cfg->aq_txsc[i].sw_secy, +AQ_CLEAR_HW ); + } +return 0 ; } +static int aq_set_txsc (struct aq_nic_s *nic,const int txsc_idx) +{ +struct aq_macsec_txsc *aq_txsc = &nic->macsec_cfg->aq_txsc[txsc_idx]; +struct aq_mss_egress_class_record tx_class_rec = {0 }; +const struct macsec_secy *secy = aq_txsc->sw_secy; +struct aq_mss_egress_sc_record sc_rec = {0 }; +unsigned int sc_idx = aq_txsc->hw_sc_idx; +struct aq_hw_s *hw = nic->aq_hw; +__be64 nsci; +int ret =0 ; + +aq_ether_addr_to_mac (tx_class_rec.mac_sa, secy->netdev->dev_addr); + +netdev_dbg (nic->ndev, +"set secy: sci %#llx, sc_idx=%d, protect=%d, curr_an=%d\n" , + secy->sci, sc_idx, secy->protect_frames, + secy->tx_sc.encoding_sa); + + nsci =cpu_to_be64 ((__force u64 )secy->sci); +memcpy (tx_class_rec.sci, &nsci,sizeof (nsci)); + tx_class_rec.sci_mask =0 ; + + tx_class_rec.sa_mask =0x3f ; + + tx_class_rec.action =0 ;/* forward to SA/SC table */ + tx_class_rec.valid =1 ; + + tx_class_rec.sc_idx = sc_idx; + + tx_class_rec.sc_sa = nic->macsec_cfg->sc_sa; + + ret =aq_mss_set_egress_class_record (hw, &tx_class_rec, txsc_idx); +if (ret) +return ret; + + sc_rec.protect = secy->protect_frames; +if (secy->tx_sc.encrypt) + sc_rec.tci |=BIT (1 ); +if (secy->tx_sc.scb) + sc_rec.tci |=BIT (2 ); +if (secy->tx_sc.send_sci) + sc_rec.tci |=BIT (3 ); +if (secy->tx_sc.end_station) + sc_rec.tci |=BIT (4 ); +/* The C bit is clear if and only if the Secure Data is +* exactly the same as the User Data and the ICV is 16 octets long. +*/ +if (!(secy->icv_len ==16 && !secy->tx_sc.encrypt)) + sc_rec.tci |=BIT (0 ); + + sc_rec.an_roll =0 ; + +switch (secy->key_len) { +case AQ_MACSEC_KEY_LEN_128_BIT : + sc_rec.sak_len =0 ; +break ; +case AQ_MACSEC_KEY_LEN_192_BIT : + sc_rec.sak_len =1 ; +break ; +case AQ_MACSEC_KEY_LEN_256_BIT : + sc_rec.sak_len =2 ; +break ; +default : +WARN_ONCE (1 ,"Invalid sc_sa" ); +return -EINVAL ; + } + + sc_rec.curr_an = secy->tx_sc.encoding_sa; + sc_rec.valid =1 ; + sc_rec.fresh =1 ; + +return aq_mss_set_egress_sc_record (hw, &sc_rec, sc_idx); +} + +static u32 aq_sc_idx_max (const enum aq_macsec_sc_sa sc_sa) +{ +u32 result =0 ; + +switch (sc_sa) { +case aq_macsec_sa_sc_4sa_8sc: + result =8 ; +break ; +case aq_macsec_sa_sc_2sa_16sc: + result =16 ; +break ; +case aq_macsec_sa_sc_1sa_32sc: + result =32 ; +break ; +default : +break ; + }; + +return result; +} + +static u32 aq_to_hw_sc_idx (const u32 sc_idx,const enum aq_macsec_sc_sa sc_sa) +{ +switch (sc_sa) { +case aq_macsec_sa_sc_4sa_8sc: +return sc_idx <<2 ; +case aq_macsec_sa_sc_2sa_16sc: +return sc_idx <<1 ; +case aq_macsec_sa_sc_1sa_32sc: +return sc_idx; +default : +/* Should never happen */ +break ; + }; + +WARN_ON (true); +return sc_idx; +} + +static enum aq_macsec_sc_sa sc_sa_from_num_an (const int num_an) +{ +enum aq_macsec_sc_sa sc_sa = aq_macsec_sa_sc_not_used; + +switch (num_an) { +case 4 : + sc_sa = aq_macsec_sa_sc_4sa_8sc; +break ; +case 2 : + sc_sa = aq_macsec_sa_sc_2sa_16sc; +break ; +case 1 : + sc_sa = aq_macsec_sa_sc_1sa_32sc; +break ; +default : +break ; + } + +return sc_sa; +} +static int aq_mdo_add_secy (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +struct aq_macsec_cfg *cfg = nic->macsec_cfg; +const struct macsec_secy *secy = ctx->secy; +enum aq_macsec_sc_sa sc_sa; +u32 txsc_idx; +int ret =0 ; + + sc_sa =sc_sa_from_num_an (MACSEC_NUM_AN ); +if (sc_sa == aq_macsec_sa_sc_not_used) +return -EINVAL ; + +if (hweight32 (cfg->txsc_idx_busy) >=aq_sc_idx_max (sc_sa)) +return -ENOSPC ; + + txsc_idx =ffz (cfg->txsc_idx_busy); +if (txsc_idx ==AQ_MACSEC_MAX_SC ) +return -ENOSPC ; + +if (ctx->prepare) +return 0 ; + + cfg->sc_sa = sc_sa; + cfg->aq_txsc[txsc_idx].hw_sc_idx =aq_to_hw_sc_idx (txsc_idx, sc_sa); + cfg->aq_txsc[txsc_idx].sw_secy = secy; +netdev_dbg (nic->ndev,"add secy: txsc_idx=%d, sc_idx=%d\n" , txsc_idx, + cfg->aq_txsc[txsc_idx].hw_sc_idx); + +if (netif_carrier_ok (nic->ndev) &&netif_running (secy->netdev)) + ret =aq_set_txsc (nic, txsc_idx); + +set_bit (txsc_idx, &cfg->txsc_idx_busy); + +return 0 ; }static int aq_mdo_upd_secy (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +const struct macsec_secy *secy = ctx->secy; +int txsc_idx; +int ret =0 ; + + txsc_idx =aq_get_txsc_idx_from_secy (nic->macsec_cfg, secy); +if (txsc_idx <0 ) +return -ENOENT ; + +if (ctx->prepare) +return 0 ; + +if (netif_carrier_ok (nic->ndev) &&netif_running (secy->netdev)) + ret =aq_set_txsc (nic, txsc_idx); + +return ret; +} + +static int aq_clear_txsc (struct aq_nic_s *nic,const int txsc_idx, +enum aq_clear_type clear_type) +{ +struct aq_macsec_txsc *tx_sc = &nic->macsec_cfg->aq_txsc[txsc_idx]; +struct aq_mss_egress_class_record tx_class_rec = {0 }; +struct aq_mss_egress_sc_record sc_rec = {0 }; +struct aq_hw_s *hw = nic->aq_hw; +int ret =0 ; +int sa_num; + + for_each_set_bit (sa_num, &tx_sc->tx_sa_idx_busy, AQ_MACSEC_MAX_SA) { + ret =aq_clear_txsa (nic, tx_sc, sa_num, clear_type); +if (ret) +return ret; + } + +if (clear_type &AQ_CLEAR_HW ) { + ret =aq_mss_set_egress_class_record (hw, &tx_class_rec, + txsc_idx); +if (ret) +return ret; + + sc_rec.fresh =1 ; + ret =aq_mss_set_egress_sc_record (hw, &sc_rec, + tx_sc->hw_sc_idx); +if (ret) +return ret; + } + +if (clear_type &AQ_CLEAR_SW ) { +clear_bit (txsc_idx, &nic->macsec_cfg->txsc_idx_busy); + nic->macsec_cfg->aq_txsc[txsc_idx].sw_secy =NULL ; + } + +return ret; }static int aq_mdo_del_secy (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +int ret =0 ; + +if (ctx->prepare) +return 0 ; + +if (!nic->macsec_cfg) +return 0 ; + + ret =aq_clear_secy (nic, ctx->secy,AQ_CLEAR_ALL ); + +return ret; +} + +static int aq_update_txsa (struct aq_nic_s *nic,const unsigned int sc_idx, +const struct macsec_secy *secy, +const struct macsec_tx_sa *tx_sa, +const unsigned char *key,const unsigned char an) +{ +struct aq_mss_egress_sakey_record key_rec; +const unsigned int sa_idx = sc_idx | an; +struct aq_mss_egress_sa_record sa_rec; +struct aq_hw_s *hw = nic->aq_hw; +int ret =0 ; + +netdev_dbg (nic->ndev,"set tx_sa %d: active=%d, next_pn=%d\n" , an, + tx_sa->active, tx_sa->next_pn); + +memset (&sa_rec,0 ,sizeof (sa_rec)); + sa_rec.valid = tx_sa->active; + sa_rec.fresh =1 ; + sa_rec.next_pn = tx_sa->next_pn; + + ret =aq_mss_set_egress_sa_record (hw, &sa_rec, sa_idx); +if (ret) { +netdev_err (nic->ndev, +"aq_mss_set_egress_sa_record failed with %d\n" , ret); +return ret; + } + +if (!key) +return ret; + +memset (&key_rec,0 ,sizeof (key_rec)); +memcpy (&key_rec.key, key, secy->key_len); + +aq_rotate_keys (&key_rec.key, secy->key_len); + + ret =aq_mss_set_egress_sakey_record (hw, &key_rec, sa_idx); +if (ret) +netdev_err (nic->ndev, +"aq_mss_set_egress_sakey_record failed with %d\n" , + ret); + +return ret; }static int aq_mdo_add_txsa (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +struct aq_macsec_cfg *cfg = nic->macsec_cfg; +const struct macsec_secy *secy = ctx->secy; +struct aq_macsec_txsc *aq_txsc; +int txsc_idx; +int ret =0 ; + + txsc_idx =aq_get_txsc_idx_from_secy (cfg, secy); +if (txsc_idx <0 ) +return -EINVAL ; + +if (ctx->prepare) +return 0 ; + + aq_txsc = &cfg->aq_txsc[txsc_idx]; +set_bit (ctx->sa.assoc_num, &aq_txsc->tx_sa_idx_busy); + +memcpy (aq_txsc->tx_sa_key[ctx->sa.assoc_num], ctx->sa.key, + secy->key_len); + +if (netif_carrier_ok (nic->ndev) &&netif_running (secy->netdev)) + ret =aq_update_txsa (nic, aq_txsc->hw_sc_idx, secy, + ctx->sa.tx_sa, ctx->sa.key, + ctx->sa.assoc_num); + +return ret; }static int aq_mdo_upd_txsa (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +struct aq_macsec_cfg *cfg = nic->macsec_cfg; +const struct macsec_secy *secy = ctx->secy; +struct aq_macsec_txsc *aq_txsc; +int txsc_idx; +int ret =0 ; + + txsc_idx =aq_get_txsc_idx_from_secy (cfg, secy); +if (txsc_idx <0 ) +return -EINVAL ; + +if (ctx->prepare) +return 0 ; + + aq_txsc = &cfg->aq_txsc[txsc_idx]; +if (netif_carrier_ok (nic->ndev) &&netif_running (secy->netdev)) + ret =aq_update_txsa (nic, aq_txsc->hw_sc_idx, secy, + ctx->sa.tx_sa,NULL , ctx->sa.assoc_num); + +return ret; +} + +static int aq_clear_txsa (struct aq_nic_s *nic,struct aq_macsec_txsc *aq_txsc, +const int sa_num,enum aq_clear_type clear_type) +{ +const int sa_idx = aq_txsc->hw_sc_idx | sa_num; +struct aq_hw_s *hw = nic->aq_hw; +int ret =0 ; + +if (clear_type &AQ_CLEAR_SW ) +clear_bit (sa_num, &aq_txsc->tx_sa_idx_busy); + +if ((clear_type &AQ_CLEAR_HW ) &&netif_carrier_ok (nic->ndev)) { +struct aq_mss_egress_sakey_record key_rec; +struct aq_mss_egress_sa_record sa_rec; + +memset (&sa_rec,0 ,sizeof (sa_rec)); + sa_rec.fresh =1 ; + + ret =aq_mss_set_egress_sa_record (hw, &sa_rec, sa_idx); +if (ret) +return ret; + +memset (&key_rec,0 ,sizeof (key_rec)); +return aq_mss_set_egress_sakey_record (hw, &key_rec, sa_idx); + } + +return 0 ; }static int aq_mdo_del_txsa (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +struct aq_macsec_cfg *cfg = nic->macsec_cfg; +int txsc_idx; +int ret =0 ; + + txsc_idx =aq_get_txsc_idx_from_secy (cfg, ctx->secy); +if (txsc_idx <0 ) +return -EINVAL ; + +if (ctx->prepare) +return 0 ; + + ret =aq_clear_txsa (nic, &cfg->aq_txsc[txsc_idx], ctx->sa.assoc_num, +AQ_CLEAR_ALL ); + +return ret; }static int aq_mdo_add_rxsc (struct macsec_context *ctx)
@@ -82,8 +562,170 @@ static int aq_mdo_del_rxsa(struct macsec_context *ctx)return -EOPNOTSUPP ; } +static int apply_txsc_cfg (struct aq_nic_s *nic,const int txsc_idx) +{ +struct aq_macsec_txsc *aq_txsc = &nic->macsec_cfg->aq_txsc[txsc_idx]; +const struct macsec_secy *secy = aq_txsc->sw_secy; +struct macsec_tx_sa *tx_sa; +int ret =0 ; +int i; + +if (!netif_running (secy->netdev)) +return ret; + + ret =aq_set_txsc (nic, txsc_idx); +if (ret) +return ret; + +for (i =0 ; i <MACSEC_NUM_AN ; i++) { + tx_sa =rcu_dereference_bh (secy->tx_sc.sa[i]); +if (tx_sa) { + ret =aq_update_txsa (nic, aq_txsc->hw_sc_idx, secy, + tx_sa, aq_txsc->tx_sa_key[i], i); +if (ret) +return ret; + } + } + +return ret; +} + +static int aq_clear_secy (struct aq_nic_s *nic,const struct macsec_secy *secy, +enum aq_clear_type clear_type) +{ +int txsc_idx; +int ret =0 ; + + txsc_idx =aq_get_txsc_idx_from_secy (nic->macsec_cfg, secy); +if (txsc_idx >=0 ) { + ret =aq_clear_txsc (nic, txsc_idx, clear_type); +if (ret) +return ret; + } + +return ret; +} + +static int aq_apply_secy_cfg (struct aq_nic_s *nic, +const struct macsec_secy *secy) +{ +int txsc_idx; +int ret =0 ; + + txsc_idx =aq_get_txsc_idx_from_secy (nic->macsec_cfg, secy); +if (txsc_idx >=0 ) +apply_txsc_cfg (nic, txsc_idx); + +return ret; +} + +static int aq_apply_macsec_cfg (struct aq_nic_s *nic) +{ +int ret =0 ; +int i; + +for (i =0 ; i <AQ_MACSEC_MAX_SC ; i++) { +if (nic->macsec_cfg->txsc_idx_busy &BIT (i)) { + ret =apply_txsc_cfg (nic, i); +if (ret) +return ret; + } + } + +return ret; +} + +static int aq_sa_from_sa_idx (const enum aq_macsec_sc_sa sc_sa,const int sa_idx) +{ +switch (sc_sa) { +case aq_macsec_sa_sc_4sa_8sc: +return sa_idx &3 ; +case aq_macsec_sa_sc_2sa_16sc: +return sa_idx &1 ; +case aq_macsec_sa_sc_1sa_32sc: +return 0 ; +default : +WARN_ONCE (1 ,"Invalid sc_sa" ); + } +return -EINVAL ; +} + +static int aq_sc_idx_from_sa_idx (const enum aq_macsec_sc_sa sc_sa, +const int sa_idx) +{ +switch (sc_sa) { +case aq_macsec_sa_sc_4sa_8sc: +return sa_idx & ~3 ; +case aq_macsec_sa_sc_2sa_16sc: +return sa_idx & ~1 ; +case aq_macsec_sa_sc_1sa_32sc: +return sa_idx; +default : +WARN_ONCE (1 ,"Invalid sc_sa" ); + } +return -EINVAL ; +} +static void aq_check_txsa_expiration (struct aq_nic_s *nic) { +u32 egress_sa_expired, egress_sa_threshold_expired; +struct aq_macsec_cfg *cfg = nic->macsec_cfg; +unsigned int sc_idx =0 , txsc_idx =0 ; +struct aq_hw_s *hw = nic->aq_hw; +struct aq_macsec_txsc *aq_txsc; +const struct macsec_secy *secy; +enum aq_macsec_sc_sa sc_sa; +struct macsec_tx_sa *tx_sa; +unsigned char an =0 ; +int ret; +int i; + + sc_sa = cfg->sc_sa; + + ret =aq_mss_get_egress_sa_expired (hw, &egress_sa_expired); +if (unlikely (ret)) +return ; + + ret =aq_mss_get_egress_sa_threshold_expired (hw, + &egress_sa_threshold_expired); + +for (i =0 ; i <AQ_MACSEC_MAX_SA ; i++) { +if (egress_sa_expired &BIT (i)) { + an =aq_sa_from_sa_idx (sc_sa, i); + sc_idx =aq_sc_idx_from_sa_idx (sc_sa, i); + txsc_idx =aq_get_txsc_idx_from_sc_idx (sc_sa, sc_idx); +if (txsc_idx <0 ) +continue ; + + aq_txsc = &cfg->aq_txsc[txsc_idx]; +if (!(cfg->txsc_idx_busy &BIT (txsc_idx))) { +netdev_warn (nic->ndev, +"PN threshold expired on invalid TX SC" ); +continue ; + } + + secy = aq_txsc->sw_secy; +if (!netif_running (secy->netdev)) { +netdev_warn (nic->ndev, +"PN threshold expired on down TX SC" ); +continue ; + } + +if (unlikely (!(aq_txsc->tx_sa_idx_busy &BIT (an)))) { +netdev_warn (nic->ndev, +"PN threshold expired on invalid TX SA" ); +continue ; + } + + tx_sa =rcu_dereference_bh (secy->tx_sc.sa[an]); +macsec_pn_wrapped ((struct macsec_secy *)secy, tx_sa); + } + } + +aq_mss_set_egress_sa_expired (hw, egress_sa_expired); +if (likely (!ret)) +aq_mss_set_egress_sa_threshold_expired (hw, + egress_sa_threshold_expired); }const struct macsec_ops aq_macsec_ops = {
@@ -134,10 +776,13 @@ void aq_macsec_free(struct aq_nic_s *nic)int aq_macsec_enable (struct aq_nic_s *nic) { +u32 ctl_ether_types[1 ] = {ETH_P_PAE };struct macsec_msg_fw_response resp = {0 };struct macsec_msg_fw_request msg = {0 };struct aq_hw_s *hw = nic->aq_hw; -int ret =0 ; +int num_ctl_ether_types =0 ; +int index =0 , tbl_idx; +int ret;if (!nic->macsec_cfg)return 0 ;
@@ -160,6 +805,26 @@ int aq_macsec_enable(struct aq_nic_s *nic) goto unlock; } +/* Init Ethertype bypass filters */ +for (index =0 ; index <ARRAY_SIZE (ctl_ether_types); index++) { +struct aq_mss_egress_ctlf_record tx_ctlf_rec; + +if (ctl_ether_types[index] ==0 ) +continue ; + +memset (&tx_ctlf_rec,0 ,sizeof (tx_ctlf_rec)); + tx_ctlf_rec.eth_type = ctl_ether_types[index]; + tx_ctlf_rec.match_type =4 ;/* Match eth_type only */ + tx_ctlf_rec.match_mask =0xf ;/* match for eth_type */ + tx_ctlf_rec.action =0 ;/* Bypass MACSEC modules */ + tbl_idx =NUMROWS_EGRESSCTLFRECORD - num_ctl_ether_types -1 ; +aq_mss_set_egress_ctlf_record (hw, &tx_ctlf_rec, tbl_idx); + + num_ctl_ether_types++; + } + + ret =aq_apply_macsec_cfg (nic); + unlock:rtnl_unlock ();return ret;
drivers/net/ethernet/aquantia/atlantic/aq_macsec.h +4 -0
@@ -29,6 +29,10 @@ enum aq_macsec_sc_sa { };struct aq_macsec_txsc { +u32 hw_sc_idx; +unsigned long tx_sa_idx_busy; +const struct macsec_secy *sw_secy; +u8 tx_sa_key[MACSEC_NUM_AN ][MACSEC_KEYID_LEN ]; };struct aq_macsec_rxsc {
Signature · 1 line
2.17.1
kbuild test robot
build botRe: [RFC v2 12/16] net: atlantic: MACSec egress offload implementation
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi Igor,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net/master]
[also build test WARNING on linus/master v5.6-rc6]
[cannot apply to net-next/master next-20200320]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Igor-Russkikh/net-atlantic-MACSec-support-for-AQC-devices/20200311-042119 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 2362059427494b9e318161f0447a10dc5513b2c3
If you fix the issue, kindly add following tag
smatch warnings:drivers/net/ethernet/aquantia/atlantic/aq_macsec.c:697 aq_check_txsa_expiration() warn: unsigned 'txsc_idx' is never less than zero.
vim +/txsc_idx +697 drivers/net/ethernet/aquantia/atlantic/aq_macsec.c
668
669 static void aq_check_txsa_expiration(struct aq_nic_s *nic)
670 {
671 u32 egress_sa_expired, egress_sa_threshold_expired;
672 struct aq_macsec_cfg *cfg = nic->macsec_cfg;
673 unsigned int sc_idx = 0, txsc_idx = 0;
674 struct aq_hw_s *hw = nic->aq_hw;
675 struct aq_macsec_txsc *aq_txsc;
676 const struct macsec_secy *secy;
677 enum aq_macsec_sc_sa sc_sa;
678 struct macsec_tx_sa *tx_sa;
679 unsigned char an = 0;
680 int ret;
681 int i;
682
683 sc_sa = cfg->sc_sa;
684
685 ret = aq_mss_get_egress_sa_expired(hw, &egress_sa_expired);
686 if (unlikely(ret))
687 return;
688
689 ret = aq_mss_get_egress_sa_threshold_expired(hw,
690 &egress_sa_threshold_expired);
691
692 for (i = 0; i < AQ_MACSEC_MAX_SA; i++) {
693 if (egress_sa_expired & BIT(i)) {
694 an = aq_sa_from_sa_idx(sc_sa, i);
695 sc_idx = aq_sc_idx_from_sa_idx(sc_sa, i);
696 txsc_idx = aq_get_txsc_idx_from_sc_idx(sc_sa, sc_idx);
> 697 if (txsc_idx < 0)
698 continue;
699
700 aq_txsc = &cfg->aq_txsc[txsc_idx];
701 if (!(cfg->txsc_idx_busy & BIT(txsc_idx))) {
702 netdev_warn(nic->ndev,
703 "PN threshold expired on invalid TX SC");
704 continue;
705 }
706
707 secy = aq_txsc->sw_secy;
708 if (!netif_running(secy->netdev)) {
709 netdev_warn(nic->ndev,
710 "PN threshold expired on down TX SC");
711 continue;
712 }
713
714 if (unlikely(!(aq_txsc->tx_sa_idx_busy & BIT(an)))) {
715 netdev_warn(nic->ndev,
716 "PN threshold expired on invalid TX SA");
717 continue;
718 }
719
720 tx_sa = rcu_dereference_bh(secy->tx_sc.sa[an]);
721 macsec_pn_wrapped((struct macsec_secy *)secy, tx_sa);
722 }
723 }
724
725 aq_mss_set_egress_sa_expired(hw, egress_sa_expired);
726 if (likely(!ret))
727 aq_mss_set_egress_sa_threshold_expired(hw,
728 egress_sa_threshold_expired);
729 }
730
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC v2 13/16 net: atlantic: MACSec ingress offload HW bindings
In reply to Igor RusskikhFrom: Mark Starovoytov <[email protected]>
This patch adds the Atlantic HW-specific bindings for MACSec ingress, e.g. register addresses / structs, helper function, etc, which will be used by actual callback implementations.
--- .../atlantic/macsec/MSS_Ingress_registers.h | 82 ++ .../aquantia/atlantic/macsec/macsec_api.c | 1239 +++++++++++++++++ .../aquantia/atlantic/macsec/macsec_api.h | 148 ++ .../aquantia/atlantic/macsec/macsec_struct.h | 383 +++++ 4 files changed, 1852 insertions(+) create mode 100644 drivers/net/ethernet/aquantia/atlantic/macsec/MSS_Ingress_registers.h
drivers/net/ethernet/aquantia/atlantic/macsec/MSS_Ingress_registers.h new file +82 -0
@@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Atlantic Network Driver +* +* Copyright (C) 2020 Marvell International Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef MSS_INGRESS_REGS_HEADER +#define MSS_INGRESS_REGS_HEADER + +#define MSS_INGRESS_CTL_REGISTER_ADDR 0x0000800E +#define MSS_INGRESS_LUT_ADDR_CTL_REGISTER_ADDR 0x00008080 +#define MSS_INGRESS_LUT_CTL_REGISTER_ADDR 0x00008081 +#define MSS_INGRESS_LUT_DATA_CTL_REGISTER_ADDR 0x000080A0 + +struct mss_ingress_ctl_register { +union { +struct { +unsigned int soft_reset :1 ; +unsigned int operation_point_to_point :1 ; +unsigned int create_sci :1 ; +/* Unused */ +unsigned int mask_short_length_error :1 ; +unsigned int drop_kay_packet :1 ; +unsigned int drop_igprc_miss :1 ; +/* Unused */ +unsigned int check_icv :1 ; +unsigned int clear_global_time :1 ; +unsigned int clear_count :1 ; +unsigned int high_prio :1 ; +unsigned int remove_sectag :1 ; +unsigned int global_validate_frames :2 ; +unsigned int icv_lsb_8bytes_enabled :1 ; +unsigned int reserved0 :2 ; + } bits_0; +unsigned short word_0; + }; +union { +struct { +unsigned int reserved0 :16 ; + } bits_1; +unsigned short word_1; + }; +}; + +struct mss_ingress_lut_addr_ctl_register { +union { +struct { +unsigned int lut_addr :9 ; +unsigned int reserved0 :3 ; +/* 0x0 : Ingress Pre-Security MAC Control FIlter +* (IGPRCTLF) LUT +* 0x1 : Ingress Pre-Security Classification LUT (IGPRC) +* 0x2 : Ingress Packet Format (IGPFMT) SAKey LUT +* 0x3 : Ingress Packet Format (IGPFMT) SC/SA LUT +* 0x4 : Ingress Post-Security Classification LUT +* (IGPOC) +* 0x5 : Ingress Post-Security MAC Control Filter +* (IGPOCTLF) LUT +* 0x6 : Ingress MIB (IGMIB) +*/ +unsigned int lut_select :4 ; + } bits_0; +unsigned short word_0; + }; +}; + +struct mss_ingress_lut_ctl_register { +union { +struct { +unsigned int reserved0 :14 ; +unsigned int lut_read :1 ; +unsigned int lut_write :1 ; + } bits_0; +unsigned short word_0; + }; +}; + +#endif /* MSS_INGRESS_REGS_HEADER */
drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.c +1239 -0
1,257 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.h +148 -0
160 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/macsec/macsec_struct.h +383 -0
387 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC v2 14/16 net: atlantic: MACSec ingress offload implementation
In reply to Igor RusskikhFrom: Mark Starovoytov <[email protected]>
This patch adds support for MACSec ingress HW offloading on Atlantic network cards.
--- .../ethernet/aquantia/atlantic/aq_macsec.c | 463 +++++++++++++++++- .../ethernet/aquantia/atlantic/aq_macsec.h | 5 + 2 files changed, 462 insertions(+), 6 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_macsec.c +457 -6
@@ -30,6 +30,10 @@ static int aq_clear_txsc(struct aq_nic_s *nic, const int txsc_idx, enum aq_clear_type clear_type);static int aq_clear_txsa (struct aq_nic_s *nic,struct aq_macsec_txsc *aq_txsc,const int sa_num,enum aq_clear_type clear_type); +static int aq_clear_rxsc (struct aq_nic_s *nic,const int rxsc_idx, +enum aq_clear_type clear_type); +static int aq_clear_rxsa (struct aq_nic_s *nic,struct aq_macsec_rxsc *aq_rxsc, +const int sa_num,enum aq_clear_type clear_type);static int aq_clear_secy (struct aq_nic_s *nic,const struct macsec_secy *secy,enum aq_clear_type clear_type);static int aq_apply_macsec_cfg (struct aq_nic_s *nic);
@@ -62,6 +66,22 @@ static int aq_get_txsc_idx_from_secy(struct aq_macsec_cfg *macsec_cfg,return -1 ; } +static int aq_get_rxsc_idx_from_rxsc (struct aq_macsec_cfg *macsec_cfg, +const struct macsec_rx_sc *rxsc) +{ +int i; + +if (unlikely (!rxsc)) +return -1 ; + +for (i =0 ; i <AQ_MACSEC_MAX_SC ; i++) { +if (macsec_cfg->aq_rxsc[i].sw_rxsc == rxsc) +return i; + } + +return -1 ; +} +static int aq_get_txsc_idx_from_sc_idx (const enum aq_macsec_sc_sa sc_sa,const unsigned int sc_idx) {
@@ -532,34 +552,393 @@ static int aq_mdo_del_txsa(struct macsec_context *ctx)return ret; } +static int aq_rxsc_validate_frames (const enum macsec_validation_type validate) +{ +switch (validate) { +case MACSEC_VALIDATE_DISABLED : +return 2 ; +case MACSEC_VALIDATE_CHECK : +return 1 ; +case MACSEC_VALIDATE_STRICT : +return 0 ; +default : +break ; + } + +/* should never be here */ +WARN_ON (true); +return 0 ; +} + +static int aq_set_rxsc (struct aq_nic_s *nic,const u32 rxsc_idx) +{ +const struct aq_macsec_rxsc *aq_rxsc = + &nic->macsec_cfg->aq_rxsc[rxsc_idx]; +struct aq_mss_ingress_preclass_record pre_class_record; +const struct macsec_rx_sc *rx_sc = aq_rxsc->sw_rxsc; +const struct macsec_secy *secy = aq_rxsc->sw_secy; +const u32 hw_sc_idx = aq_rxsc->hw_sc_idx; +struct aq_mss_ingress_sc_record sc_record; +struct aq_hw_s *hw = nic->aq_hw; +__be64 nsci; +int ret =0 ; + +netdev_dbg (nic->ndev, +"set rx_sc: rxsc_idx=%d, sci %#llx, hw_sc_idx=%d\n" , + rxsc_idx, rx_sc->sci, hw_sc_idx); + +memset (&pre_class_record,0 ,sizeof (pre_class_record)); + nsci =cpu_to_be64 ((__force u64 )rx_sc->sci); +memcpy (pre_class_record.sci, &nsci,sizeof (nsci)); + pre_class_record.sci_mask =0xff ; +/* match all MACSEC ethertype packets */ + pre_class_record.eth_type =ETH_P_MACSEC ; + pre_class_record.eth_type_mask =0x3 ; + +aq_ether_addr_to_mac (pre_class_record.mac_sa, (char *)&rx_sc->sci); + pre_class_record.sa_mask =0x3f ; + + pre_class_record.an_mask = nic->macsec_cfg->sc_sa; + pre_class_record.sc_idx = hw_sc_idx; +/* strip SecTAG & forward for decryption */ + pre_class_record.action =0x0 ; + pre_class_record.valid =1 ; + + ret =aq_mss_set_ingress_preclass_record (hw, &pre_class_record, +2 * rxsc_idx +1 ); +if (ret) { +netdev_err (nic->ndev, +"aq_mss_set_ingress_preclass_record failed with %d\n" , + ret); +return ret; + } + +/* If SCI is absent, then match by SA alone */ + pre_class_record.sci_mask =0 ; + pre_class_record.sci_from_table =1 ; + + ret =aq_mss_set_ingress_preclass_record (hw, &pre_class_record, +2 * rxsc_idx); +if (ret) { +netdev_err (nic->ndev, +"aq_mss_set_ingress_preclass_record failed with %d\n" , + ret); +return ret; + } + +memset (&sc_record,0 ,sizeof (sc_record)); + sc_record.validate_frames = +aq_rxsc_validate_frames (secy->validate_frames); +if (secy->replay_protect) { + sc_record.replay_protect =1 ; + sc_record.anti_replay_window = secy->replay_window; + } + sc_record.valid =1 ; + sc_record.fresh =1 ; + + ret =aq_mss_set_ingress_sc_record (hw, &sc_record, hw_sc_idx); +if (ret) { +netdev_err (nic->ndev, +"aq_mss_set_ingress_sc_record failed with %d\n" , + ret); +return ret; + } + +return ret; +} +static int aq_mdo_add_rxsc (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +struct aq_macsec_cfg *cfg = nic->macsec_cfg; +const u32 rxsc_idx_max =aq_sc_idx_max (cfg->sc_sa); +u32 rxsc_idx; +int ret =0 ; + +if (hweight32 (cfg->rxsc_idx_busy) >= rxsc_idx_max) +return -ENOSPC ; + + rxsc_idx =ffz (cfg->rxsc_idx_busy); +if (rxsc_idx >= rxsc_idx_max) +return -ENOSPC ; + +if (ctx->prepare) +return 0 ; + + cfg->aq_rxsc[rxsc_idx].hw_sc_idx =aq_to_hw_sc_idx (rxsc_idx, + cfg->sc_sa); + cfg->aq_rxsc[rxsc_idx].sw_secy = ctx->secy; + cfg->aq_rxsc[rxsc_idx].sw_rxsc = ctx->rx_sc; +netdev_dbg (nic->ndev,"add rxsc: rxsc_idx=%u, hw_sc_idx=%u, rxsc=%p\n" , + rxsc_idx, cfg->aq_rxsc[rxsc_idx].hw_sc_idx, + cfg->aq_rxsc[rxsc_idx].sw_rxsc); + +if (netif_carrier_ok (nic->ndev) &&netif_running (ctx->secy->netdev)) + ret =aq_set_rxsc (nic, rxsc_idx); + +if (ret <0 ) +return ret; + +set_bit (rxsc_idx, &cfg->rxsc_idx_busy); + +return 0 ; }static int aq_mdo_upd_rxsc (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +int rxsc_idx; +int ret =0 ; + + rxsc_idx =aq_get_rxsc_idx_from_rxsc (nic->macsec_cfg, ctx->rx_sc); +if (rxsc_idx <0 ) +return -ENOENT ; + +if (ctx->prepare) +return 0 ; + +if (netif_carrier_ok (nic->ndev) &&netif_running (ctx->secy->netdev)) + ret =aq_set_rxsc (nic, rxsc_idx); + +return ret; +} + +static int aq_clear_rxsc (struct aq_nic_s *nic,const int rxsc_idx, +enum aq_clear_type clear_type) +{ +struct aq_macsec_rxsc *rx_sc = &nic->macsec_cfg->aq_rxsc[rxsc_idx]; +struct aq_hw_s *hw = nic->aq_hw; +int ret =0 ; +int sa_num; + + for_each_set_bit (sa_num, &rx_sc->rx_sa_idx_busy, AQ_MACSEC_MAX_SA) { + ret =aq_clear_rxsa (nic, rx_sc, sa_num, clear_type); +if (ret) +return ret; + } + +if (clear_type &AQ_CLEAR_HW ) { +struct aq_mss_ingress_preclass_record pre_class_record; +struct aq_mss_ingress_sc_record sc_record; + +memset (&pre_class_record,0 ,sizeof (pre_class_record)); +memset (&sc_record,0 ,sizeof (sc_record)); + + ret =aq_mss_set_ingress_preclass_record (hw, &pre_class_record, +2 * rxsc_idx); +if (ret) { +netdev_err (nic->ndev, +"aq_mss_set_ingress_preclass_record failed with %d\n" , + ret); +return ret; + } + + ret =aq_mss_set_ingress_preclass_record (hw, &pre_class_record, +2 * rxsc_idx +1 ); +if (ret) { +netdev_err (nic->ndev, +"aq_mss_set_ingress_preclass_record failed with %d\n" , + ret); +return ret; + } + + sc_record.fresh =1 ; + ret =aq_mss_set_ingress_sc_record (hw, &sc_record, + rx_sc->hw_sc_idx); +if (ret) +return ret; + } + +if (clear_type &AQ_CLEAR_SW ) { +clear_bit (rxsc_idx, &nic->macsec_cfg->rxsc_idx_busy); + rx_sc->sw_secy =NULL ; + rx_sc->sw_rxsc =NULL ; + } + +return ret; }static int aq_mdo_del_rxsc (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +enum aq_clear_type clear_type =AQ_CLEAR_SW ; +int rxsc_idx; +int ret =0 ; + + rxsc_idx =aq_get_rxsc_idx_from_rxsc (nic->macsec_cfg, ctx->rx_sc); +if (rxsc_idx <0 ) +return -ENOENT ; + +if (ctx->prepare) +return 0 ; + +if (netif_carrier_ok (nic->ndev)) + clear_type =AQ_CLEAR_ALL ; + + ret =aq_clear_rxsc (nic, rxsc_idx, clear_type); + +return ret; +} + +static int aq_update_rxsa (struct aq_nic_s *nic,const unsigned int sc_idx, +const struct macsec_secy *secy, +const struct macsec_rx_sa *rx_sa, +const unsigned char *key,const unsigned char an) +{ +struct aq_mss_ingress_sakey_record sa_key_record; +struct aq_mss_ingress_sa_record sa_record; +struct aq_hw_s *hw = nic->aq_hw; +const int sa_idx = sc_idx | an; +int ret =0 ; + +netdev_dbg (nic->ndev,"set rx_sa %d: active=%d, next_pn=%d\n" , an, + rx_sa->active, rx_sa->next_pn); + +memset (&sa_record,0 ,sizeof (sa_record)); + sa_record.valid = rx_sa->active; + sa_record.fresh =1 ; + sa_record.next_pn = rx_sa->next_pn; + + ret =aq_mss_set_ingress_sa_record (hw, &sa_record, sa_idx); +if (ret) { +netdev_err (nic->ndev, +"aq_mss_set_ingress_sa_record failed with %d\n" , + ret); +return ret; + } + +if (!key) +return ret; + +memset (&sa_key_record,0 ,sizeof (sa_key_record)); +memcpy (&sa_key_record.key, key, secy->key_len); + +switch (secy->key_len) { +case AQ_MACSEC_KEY_LEN_128_BIT : + sa_key_record.key_len =0 ; +break ; +case AQ_MACSEC_KEY_LEN_192_BIT : + sa_key_record.key_len =1 ; +break ; +case AQ_MACSEC_KEY_LEN_256_BIT : + sa_key_record.key_len =2 ; +break ; +default : +return -1 ; + } + +aq_rotate_keys (&sa_key_record.key, secy->key_len); + + ret =aq_mss_set_ingress_sakey_record (hw, &sa_key_record, sa_idx); +if (ret) +netdev_err (nic->ndev, +"aq_mss_set_ingress_sakey_record failed with %d\n" , + ret); + +return ret; }static int aq_mdo_add_rxsa (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +const struct macsec_rx_sc *rx_sc = ctx->sa.rx_sa->sc; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +const struct macsec_secy *secy = ctx->secy; +struct aq_macsec_rxsc *aq_rxsc; +int rxsc_idx; +int ret =0 ; + + rxsc_idx =aq_get_rxsc_idx_from_rxsc (nic->macsec_cfg, rx_sc); +if (rxsc_idx <0 ) +return -EINVAL ; + +if (ctx->prepare) +return 0 ; + + aq_rxsc = &nic->macsec_cfg->aq_rxsc[rxsc_idx]; +set_bit (ctx->sa.assoc_num, &aq_rxsc->rx_sa_idx_busy); + +memcpy (aq_rxsc->rx_sa_key[ctx->sa.assoc_num], ctx->sa.key, + secy->key_len); + +if (netif_carrier_ok (nic->ndev) &&netif_running (secy->netdev)) + ret =aq_update_rxsa (nic, aq_rxsc->hw_sc_idx, secy, + ctx->sa.rx_sa, ctx->sa.key, + ctx->sa.assoc_num); + +return ret; }static int aq_mdo_upd_rxsa (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +const struct macsec_rx_sc *rx_sc = ctx->sa.rx_sa->sc; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +struct aq_macsec_cfg *cfg = nic->macsec_cfg; +const struct macsec_secy *secy = ctx->secy; +int rxsc_idx; +int ret =0 ; + + rxsc_idx =aq_get_rxsc_idx_from_rxsc (cfg, rx_sc); +if (rxsc_idx <0 ) +return -EINVAL ; + +if (ctx->prepare) +return 0 ; + +if (netif_carrier_ok (nic->ndev) &&netif_running (secy->netdev)) + ret =aq_update_rxsa (nic, cfg->aq_rxsc[rxsc_idx].hw_sc_idx, + secy, ctx->sa.rx_sa,NULL , + ctx->sa.assoc_num); + +return ret; +} + +static int aq_clear_rxsa (struct aq_nic_s *nic,struct aq_macsec_rxsc *aq_rxsc, +const int sa_num,enum aq_clear_type clear_type) +{ +int sa_idx = aq_rxsc->hw_sc_idx | sa_num; +struct aq_hw_s *hw = nic->aq_hw; +int ret =0 ; + +if (clear_type &AQ_CLEAR_SW ) +clear_bit (sa_num, &aq_rxsc->rx_sa_idx_busy); + +if ((clear_type &AQ_CLEAR_HW ) &&netif_carrier_ok (nic->ndev)) { +struct aq_mss_ingress_sakey_record sa_key_record; +struct aq_mss_ingress_sa_record sa_record; + +memset (&sa_key_record,0 ,sizeof (sa_key_record)); +memset (&sa_record,0 ,sizeof (sa_record)); + sa_record.fresh =1 ; + ret =aq_mss_set_ingress_sa_record (hw, &sa_record, sa_idx); +if (ret) +return ret; + +return aq_mss_set_ingress_sakey_record (hw, &sa_key_record, + sa_idx); + } + +return ret; }static int aq_mdo_del_rxsa (struct macsec_context *ctx) { -return -EOPNOTSUPP ; +const struct macsec_rx_sc *rx_sc = ctx->sa.rx_sa->sc; +struct aq_nic_s *nic =netdev_priv (ctx->netdev); +struct aq_macsec_cfg *cfg = nic->macsec_cfg; +int rxsc_idx; +int ret =0 ; + + rxsc_idx =aq_get_rxsc_idx_from_rxsc (cfg, rx_sc); +if (rxsc_idx <0 ) +return -EINVAL ; + +if (ctx->prepare) +return 0 ; + + ret =aq_clear_rxsa (nic, &cfg->aq_rxsc[rxsc_idx], ctx->sa.assoc_num, +AQ_CLEAR_ALL ); + +return ret; }static int apply_txsc_cfg (struct aq_nic_s *nic,const int txsc_idx)
@@ -590,10 +969,40 @@ static int apply_txsc_cfg(struct aq_nic_s *nic, const int txsc_idx)return ret; } +static int apply_rxsc_cfg (struct aq_nic_s *nic,const int rxsc_idx) +{ +struct aq_macsec_rxsc *aq_rxsc = &nic->macsec_cfg->aq_rxsc[rxsc_idx]; +const struct macsec_secy *secy = aq_rxsc->sw_secy; +struct macsec_rx_sa *rx_sa; +int ret =0 ; +int i; + +if (!netif_running (secy->netdev)) +return ret; + + ret =aq_set_rxsc (nic, rxsc_idx); +if (ret) +return ret; + +for (i =0 ; i <MACSEC_NUM_AN ; i++) { + rx_sa =rcu_dereference_bh (aq_rxsc->sw_rxsc->sa[i]); +if (rx_sa) { + ret =aq_update_rxsa (nic, aq_rxsc->hw_sc_idx, secy, + rx_sa, aq_rxsc->rx_sa_key[i], i); +if (ret) +return ret; + } + } + +return ret; +} +static int aq_clear_secy (struct aq_nic_s *nic,const struct macsec_secy *secy,enum aq_clear_type clear_type) { +struct macsec_rx_sc *rx_sc;int txsc_idx; +int rxsc_idx;int ret =0 ; txsc_idx =aq_get_txsc_idx_from_secy (nic->macsec_cfg, secy);
@@ -603,19 +1012,43 @@ static int aq_clear_secy(struct aq_nic_s *nic, const struct macsec_secy *secy,return ret; } +for (rx_sc =rcu_dereference_bh (secy->rx_sc); rx_sc; + rx_sc =rcu_dereference_bh (rx_sc->next)) { + rxsc_idx =aq_get_rxsc_idx_from_rxsc (nic->macsec_cfg, rx_sc); +if (rxsc_idx <0 ) +continue ; + + ret =aq_clear_rxsc (nic, rxsc_idx, clear_type); +if (ret) +return ret; + } +return ret; }static int aq_apply_secy_cfg (struct aq_nic_s *nic,const struct macsec_secy *secy) { +struct macsec_rx_sc *rx_sc;int txsc_idx; +int rxsc_idx;int ret =0 ; txsc_idx =aq_get_txsc_idx_from_secy (nic->macsec_cfg, secy);if (txsc_idx >=0 )apply_txsc_cfg (nic, txsc_idx); +for (rx_sc =rcu_dereference_bh (secy->rx_sc); rx_sc && rx_sc->active; + rx_sc =rcu_dereference_bh (rx_sc->next)) { + rxsc_idx =aq_get_rxsc_idx_from_rxsc (nic->macsec_cfg, rx_sc); +if (unlikely (rxsc_idx <0 )) +continue ; + + ret =apply_rxsc_cfg (nic, rxsc_idx); +if (ret) +return ret; + } +return ret; }
@@ -632,6 +1065,14 @@ static int aq_apply_macsec_cfg(struct aq_nic_s *nic) } } +for (i =0 ; i <AQ_MACSEC_MAX_SC ; i++) { +if (nic->macsec_cfg->rxsc_idx_busy &BIT (i)) { + ret =apply_rxsc_cfg (nic, i); +if (ret) +return ret; + } + } +return ret; }
@@ -807,6 +1248,7 @@ int aq_macsec_enable(struct aq_nic_s *nic)/* Init Ethertype bypass filters */ for (index =0 ; index <ARRAY_SIZE (ctl_ether_types); index++) { +struct aq_mss_ingress_prectlf_record rx_prectlf_rec;struct aq_mss_egress_ctlf_record tx_ctlf_rec;if (ctl_ether_types[index] ==0 )
@@ -820,6 +1262,15 @@ int aq_macsec_enable(struct aq_nic_s *nic) tbl_idx =NUMROWS_EGRESSCTLFRECORD - num_ctl_ether_types -1 ;aq_mss_set_egress_ctlf_record (hw, &tx_ctlf_rec, tbl_idx); +memset (&rx_prectlf_rec,0 ,sizeof (rx_prectlf_rec)); + rx_prectlf_rec.eth_type = ctl_ether_types[index]; + rx_prectlf_rec.match_type =4 ;/* Match eth_type only */ + rx_prectlf_rec.match_mask =0xf ;/* match for eth_type */ + rx_prectlf_rec.action =0 ;/* Bypass MACSEC modules */ + tbl_idx = +NUMROWS_INGRESSPRECTLFRECORD - num_ctl_ether_types -1 ; +aq_mss_set_ingress_prectlf_record (hw, &rx_prectlf_rec, tbl_idx); + num_ctl_ether_types++; }
drivers/net/ethernet/aquantia/atlantic/aq_macsec.h +5 -0
@@ -36,6 +36,11 @@ struct aq_macsec_txsc { };struct aq_macsec_rxsc { +u32 hw_sc_idx; +unsigned long rx_sa_idx_busy; +const struct macsec_secy *sw_secy; +const struct macsec_rx_sc *sw_rxsc; +u8 rx_sa_key[MACSEC_NUM_AN ][MACSEC_KEYID_LEN ]; };struct aq_macsec_cfg {
Signature · 1 line
2.17.1
RFC v2 15/16 net: atlantic: MACSec offload statistics HW bindings
In reply to Igor RusskikhFrom: Dmitry Bogdanov <[email protected]>
This patch adds the Atlantic HW-specific bindings for MACSec statistics, e.g. register addresses / structs, helper function, etc, which will be used by actual callback implementations.
--- .../aquantia/atlantic/macsec/macsec_api.c | 545 ++++++++++++++++++ .../aquantia/atlantic/macsec/macsec_api.h | 47 ++ .../aquantia/atlantic/macsec/macsec_struct.h | 214 +++++++ 3 files changed, 806 insertions(+)
drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.c +545 -0
@@ -2282,6 +2282,551 @@ int aq_mss_get_egress_sakey_record(struct aq_hw_s *hw,return AQ_API_CALL_SAFE (get_egress_sakey_record, hw, rec, table_index); } +static int get_egress_sc_counters (struct aq_hw_s *hw, +struct aq_mss_egress_sc_counters *counters, +u16 sc_index) +{ +u16 packed_record[4 ]; +int ret; + +if (sc_index >=NUMROWS_EGRESSSCRECORD ) +return -EINVAL ; + + ret =get_raw_egress_record (hw, packed_record,4 ,3 , sc_index *8 +4 ); +if (unlikely (ret)) +return ret; + counters->sc_protected_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->sc_protected_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 , sc_index *8 +5 ); +if (unlikely (ret)) +return ret; + counters->sc_encrypted_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->sc_encrypted_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 , sc_index *8 +6 ); +if (unlikely (ret)) +return ret; + counters->sc_protected_octets[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->sc_protected_octets[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 , sc_index *8 +7 ); +if (unlikely (ret)) +return ret; + counters->sc_encrypted_octets[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->sc_encrypted_octets[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + +return 0 ; +} + +int aq_mss_get_egress_sc_counters (struct aq_hw_s *hw, +struct aq_mss_egress_sc_counters *counters, +u16 sc_index) +{ +memset (counters,0 ,sizeof (*counters)); + +return AQ_API_CALL_SAFE (get_egress_sc_counters, hw, counters, sc_index); +} + +static int get_egress_sa_counters (struct aq_hw_s *hw, +struct aq_mss_egress_sa_counters *counters, +u16 sa_index) +{ +u16 packed_record[4 ]; +int ret; + +if (sa_index >=NUMROWS_EGRESSSARECORD ) +return -EINVAL ; + + ret =get_raw_egress_record (hw, packed_record,4 ,3 , sa_index *8 +0 ); +if (unlikely (ret)) +return ret; + counters->sa_hit_drop_redirect[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->sa_hit_drop_redirect[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 , sa_index *8 +1 ); +if (unlikely (ret)) +return ret; + counters->sa_protected2_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->sa_protected2_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 , sa_index *8 +2 ); +if (unlikely (ret)) +return ret; + counters->sa_protected_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->sa_protected_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 , sa_index *8 +3 ); +if (unlikely (ret)) +return ret; + counters->sa_encrypted_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->sa_encrypted_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + +return 0 ; +} + +int aq_mss_get_egress_sa_counters (struct aq_hw_s *hw, +struct aq_mss_egress_sa_counters *counters, +u16 sa_index) +{ +memset (counters,0 ,sizeof (*counters)); + +return AQ_API_CALL_SAFE (get_egress_sa_counters, hw, counters, sa_index); +} + +static int +get_egress_common_counters (struct aq_hw_s *hw, +struct aq_mss_egress_common_counters *counters) +{ +u16 packed_record[4 ]; +int ret; + + ret =get_raw_egress_record (hw, packed_record,4 ,3 ,256 +0 ); +if (unlikely (ret)) +return ret; + counters->ctl_pkt[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->ctl_pkt[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 ,256 +1 ); +if (unlikely (ret)) +return ret; + counters->unknown_sa_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->unknown_sa_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 ,256 +2 ); +if (unlikely (ret)) +return ret; + counters->untagged_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->untagged_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 ,256 +3 ); +if (unlikely (ret)) +return ret; + counters->too_long[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->too_long[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 ,256 +4 ); +if (unlikely (ret)) +return ret; + counters->ecc_error_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->ecc_error_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_egress_record (hw, packed_record,4 ,3 ,256 +5 ); +if (unlikely (ret)) +return ret; + counters->unctrl_hit_drop_redir[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->unctrl_hit_drop_redir[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + +return 0 ; +} + +int aq_mss_get_egress_common_counters (struct aq_hw_s *hw, +struct aq_mss_egress_common_counters *counters) +{ +memset (counters,0 ,sizeof (*counters)); + +return AQ_API_CALL_SAFE (get_egress_common_counters, hw, counters); +} + +static int clear_egress_counters (struct aq_hw_s *hw) +{ +struct mss_egress_ctl_register ctl_reg; +int ret; + +memset (&ctl_reg,0 ,sizeof (ctl_reg)); + + ret =aq_mss_mdio_read (hw,MDIO_MMD_VEND1 ,MSS_EGRESS_CTL_REGISTER_ADDR , + &ctl_reg.word_0); +if (unlikely (ret)) +return ret; + ret =aq_mss_mdio_read (hw,MDIO_MMD_VEND1 , +MSS_EGRESS_CTL_REGISTER_ADDR +4 , + &ctl_reg.word_1); +if (unlikely (ret)) +return ret; + +/* Toggle the Egress MIB clear bit 0->1->0 */ + ctl_reg.bits_0.clear_counter =0 ; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_EGRESS_CTL_REGISTER_ADDR , ctl_reg.word_0); +if (unlikely (ret)) +return ret; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_EGRESS_CTL_REGISTER_ADDR +4 , + ctl_reg.word_1); +if (unlikely (ret)) +return ret; + + ctl_reg.bits_0.clear_counter =1 ; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_EGRESS_CTL_REGISTER_ADDR , ctl_reg.word_0); +if (unlikely (ret)) +return ret; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_EGRESS_CTL_REGISTER_ADDR +4 , + ctl_reg.word_1); +if (unlikely (ret)) +return ret; + + ctl_reg.bits_0.clear_counter =0 ; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_EGRESS_CTL_REGISTER_ADDR , ctl_reg.word_0); +if (unlikely (ret)) +return ret; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_EGRESS_CTL_REGISTER_ADDR +4 , + ctl_reg.word_1); +if (unlikely (ret)) +return ret; + +return 0 ; +} + +int aq_mss_clear_egress_counters (struct aq_hw_s *hw) +{ +return AQ_API_CALL_SAFE (clear_egress_counters, hw); +} + +static int get_ingress_sa_counters (struct aq_hw_s *hw, +struct aq_mss_ingress_sa_counters *counters, +u16 sa_index) +{ +u16 packed_record[4 ]; +int ret; + +if (sa_index >=NUMROWS_INGRESSSARECORD ) +return -EINVAL ; + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +0 ); +if (unlikely (ret)) +return ret; + counters->untagged_hit_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->untagged_hit_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +1 ); +if (unlikely (ret)) +return ret; + counters->ctrl_hit_drop_redir_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->ctrl_hit_drop_redir_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +2 ); +if (unlikely (ret)) +return ret; + counters->not_using_sa[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->not_using_sa[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +3 ); +if (unlikely (ret)) +return ret; + counters->unused_sa[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->unused_sa[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +4 ); +if (unlikely (ret)) +return ret; + counters->not_valid_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->not_valid_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +5 ); +if (unlikely (ret)) +return ret; + counters->invalid_pkts[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->invalid_pkts[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +6 ); +if (unlikely (ret)) +return ret; + counters->ok_pkts[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->ok_pkts[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +7 ); +if (unlikely (ret)) +return ret; + counters->late_pkts[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->late_pkts[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +8 ); +if (unlikely (ret)) +return ret; + counters->delayed_pkts[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->delayed_pkts[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +9 ); +if (unlikely (ret)) +return ret; + counters->unchecked_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->unchecked_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +10 ); +if (unlikely (ret)) +return ret; + counters->validated_octets[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->validated_octets[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 , + sa_index *12 +11 ); +if (unlikely (ret)) +return ret; + counters->decrypted_octets[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->decrypted_octets[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + +return 0 ; +} + +int aq_mss_get_ingress_sa_counters (struct aq_hw_s *hw, +struct aq_mss_ingress_sa_counters *counters, +u16 sa_index) +{ +memset (counters,0 ,sizeof (*counters)); + +return AQ_API_CALL_SAFE (get_ingress_sa_counters, hw, counters, + sa_index); +} + +static int +get_ingress_common_counters (struct aq_hw_s *hw, +struct aq_mss_ingress_common_counters *counters) +{ +u16 packed_record[4 ]; +int ret; + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +0 ); +if (unlikely (ret)) +return ret; + counters->ctl_pkts[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->ctl_pkts[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +1 ); +if (unlikely (ret)) +return ret; + counters->tagged_miss_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->tagged_miss_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +2 ); +if (unlikely (ret)) +return ret; + counters->untagged_miss_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->untagged_miss_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +3 ); +if (unlikely (ret)) +return ret; + counters->notag_pkts[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->notag_pkts[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +4 ); +if (unlikely (ret)) +return ret; + counters->untagged_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->untagged_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +5 ); +if (unlikely (ret)) +return ret; + counters->bad_tag_pkts[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->bad_tag_pkts[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +6 ); +if (unlikely (ret)) +return ret; + counters->no_sci_pkts[0 ] = packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->no_sci_pkts[1 ] = packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +7 ); +if (unlikely (ret)) +return ret; + counters->unknown_sci_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->unknown_sci_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +8 ); +if (unlikely (ret)) +return ret; + counters->ctrl_prt_pass_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->ctrl_prt_pass_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +9 ); +if (unlikely (ret)) +return ret; + counters->unctrl_prt_pass_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->unctrl_prt_pass_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +10 ); +if (unlikely (ret)) +return ret; + counters->ctrl_prt_fail_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->ctrl_prt_fail_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +11 ); +if (unlikely (ret)) +return ret; + counters->unctrl_prt_fail_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->unctrl_prt_fail_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +12 ); +if (unlikely (ret)) +return ret; + counters->too_long_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->too_long_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +13 ); +if (unlikely (ret)) +return ret; + counters->igpoc_ctl_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->igpoc_ctl_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +14 ); +if (unlikely (ret)) +return ret; + counters->ecc_error_pkts[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->ecc_error_pkts[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + + ret =get_raw_ingress_record (hw, packed_record,4 ,6 ,385 +15 ); +if (unlikely (ret)) +return ret; + counters->unctrl_hit_drop_redir[0 ] = + packed_record[0 ] | (packed_record[1 ] <<16 ); + counters->unctrl_hit_drop_redir[1 ] = + packed_record[2 ] | (packed_record[3 ] <<16 ); + +return 0 ; +} + +int aq_mss_get_ingress_common_counters (struct aq_hw_s *hw, +struct aq_mss_ingress_common_counters *counters) +{ +memset (counters,0 ,sizeof (*counters)); + +return AQ_API_CALL_SAFE (get_ingress_common_counters, hw, counters); +} + +static int clear_ingress_counters (struct aq_hw_s *hw) +{ +struct mss_ingress_ctl_register ctl_reg; +int ret; + +memset (&ctl_reg,0 ,sizeof (ctl_reg)); + + ret =aq_mss_mdio_read (hw,MDIO_MMD_VEND1 , +MSS_INGRESS_CTL_REGISTER_ADDR , &ctl_reg.word_0); +if (unlikely (ret)) +return ret; + ret =aq_mss_mdio_read (hw,MDIO_MMD_VEND1 , +MSS_INGRESS_CTL_REGISTER_ADDR +4 , + &ctl_reg.word_1); +if (unlikely (ret)) +return ret; + +/* Toggle the Ingress MIB clear bit 0->1->0 */ + ctl_reg.bits_0.clear_count =0 ; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_INGRESS_CTL_REGISTER_ADDR , ctl_reg.word_0); +if (unlikely (ret)) +return ret; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_INGRESS_CTL_REGISTER_ADDR +4 , + ctl_reg.word_1); +if (unlikely (ret)) +return ret; + + ctl_reg.bits_0.clear_count =1 ; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_INGRESS_CTL_REGISTER_ADDR , ctl_reg.word_0); +if (unlikely (ret)) +return ret; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_INGRESS_CTL_REGISTER_ADDR +4 , + ctl_reg.word_1); +if (unlikely (ret)) +return ret; + + ctl_reg.bits_0.clear_count =0 ; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_INGRESS_CTL_REGISTER_ADDR , ctl_reg.word_0); +if (unlikely (ret)) +return ret; + ret =aq_mss_mdio_write (hw,MDIO_MMD_VEND1 , +MSS_INGRESS_CTL_REGISTER_ADDR +4 , + ctl_reg.word_1); +if (unlikely (ret)) +return ret; + +return 0 ; +} + +int aq_mss_clear_ingress_counters (struct aq_hw_s *hw) +{ +return AQ_API_CALL_SAFE (clear_ingress_counters, hw); +} +static int get_egress_sa_expired (struct aq_hw_s *hw,u32 *expired) {u16 val;
drivers/net/ethernet/aquantia/atlantic/macsec/macsec_api.h +47 -0
53 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/macsec/macsec_struct.h +214 -0
218 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC v2 16/16 net: atlantic: MACSec offload statistics implementation
In reply to Igor RusskikhFrom: Dmitry Bogdanov <[email protected]>
This patch adds support for MACSec statistics on Atlantic network cards.
--- .../ethernet/aquantia/atlantic/aq_ethtool.c | 160 ++++- .../ethernet/aquantia/atlantic/aq_macsec.c | 545 ++++++++++++++++++ .../ethernet/aquantia/atlantic/aq_macsec.h | 73 +++ .../net/ethernet/aquantia/atlantic/aq_nic.c | 5 +- .../net/ethernet/aquantia/atlantic/aq_nic.h | 2 +- 5 files changed, 766 insertions(+), 19 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c +143 -17
@@ -11,6 +11,7 @@#include "aq_vec.h" #include "aq_ptp.h" #include "aq_filters.h" +#include "aq_macsec.h" #include <linux/ptp_clock_kernel.h>
@@ -96,6 +97,62 @@ static const char aq_ethtool_queue_stat_names[][ETH_GSTRING_LEN] = { "Queue[%d] InErrors", }; +#if IS_ENABLED (CONFIG_MACSEC ) +static const char aq_macsec_stat_names[][ETH_GSTRING_LEN ] = { +"MACSec InCtlPackets" , +"MACSec InTaggedMissPackets" , +"MACSec InUntaggedMissPackets" , +"MACSec InNotagPackets" , +"MACSec InUntaggedPackets" , +"MACSec InBadTagPackets" , +"MACSec InNoSciPackets" , +"MACSec InUnknownSciPackets" , +"MACSec InCtrlPortPassPackets" , +"MACSec InUnctrlPortPassPackets" , +"MACSec InCtrlPortFailPackets" , +"MACSec InUnctrlPortFailPackets" , +"MACSec InTooLongPackets" , +"MACSec InIgpocCtlPackets" , +"MACSec InEccErrorPackets" , +"MACSec InUnctrlHitDropRedir" , +"MACSec OutCtlPackets" , +"MACSec OutUnknownSaPackets" , +"MACSec OutUntaggedPackets" , +"MACSec OutTooLong" , +"MACSec OutEccErrorPackets" , +"MACSec OutUnctrlHitDropRedir" , +}; + +static const char aq_macsec_txsc_stat_names[][ETH_GSTRING_LEN +1 ] = { +"MACSecTXSC%d ProtectedPkts\0" , +"MACSecTXSC%d EncryptedPkts\0" , +"MACSecTXSC%d ProtectedOctets\0" , +"MACSecTXSC%d EncryptedOctets\0" , +}; + +static const char aq_macsec_txsa_stat_names[][ETH_GSTRING_LEN +1 ] = { +"MACSecTXSC%dSA%d HitDropRedirect\0" , +"MACSecTXSC%dSA%d Protected2Pkts\0" , +"MACSecTXSC%dSA%d ProtectedPkts\0" , +"MACSecTXSC%dSA%d EncryptedPkts\0" , +}; + +static const char aq_macsec_rxsa_stat_names[][ETH_GSTRING_LEN +1 ] = { +"MACSecRXSC%dSA%d UntaggedHitPkts\0" , +"MACSecRXSC%dSA%d CtrlHitDrpRedir\0" , +"MACSecRXSC%dSA%d NotUsingSa\0" , +"MACSecRXSC%dSA%d UnusedSa\0" , +"MACSecRXSC%dSA%d NotValidPkts\0" , +"MACSecRXSC%dSA%d InvalidPkts\0" , +"MACSecRXSC%dSA%d OkPkts\0" , +"MACSecRXSC%dSA%d LatePkts\0" , +"MACSecRXSC%dSA%d DelayedPkts\0" , +"MACSecRXSC%dSA%d UncheckedPkts\0" , +"MACSecRXSC%dSA%d ValidatedOctets\0" , +"MACSecRXSC%dSA%d DecryptedOctets\0" , +}; +#endif +static const char aq_ethtool_priv_flag_names[][ETH_GSTRING_LEN ] = {"DMASystemLoopback" ,"PKTSystemLoopback" ,
@@ -104,18 +161,38 @@ static const char aq_ethtool_priv_flag_names[][ETH_GSTRING_LEN] = { "PHYExternalLoopback", }; +static u32 aq_ethtool_n_stats (struct net_device *ndev) +{ +struct aq_nic_s *nic =netdev_priv (ndev); +struct aq_nic_cfg_s *cfg =aq_nic_get_cfg (nic); +u32 n_stats =ARRAY_SIZE (aq_ethtool_stat_names) + +ARRAY_SIZE (aq_ethtool_queue_stat_names) * cfg->vecs; + +#if IS_ENABLED (CONFIG_MACSEC ) +if (nic->macsec_cfg) { + n_stats +=ARRAY_SIZE (aq_macsec_stat_names) + +ARRAY_SIZE (aq_macsec_txsc_stat_names) * +aq_macsec_tx_sc_cnt (nic) + +ARRAY_SIZE (aq_macsec_txsa_stat_names) * +aq_macsec_tx_sa_cnt (nic) + +ARRAY_SIZE (aq_macsec_rxsa_stat_names) * +aq_macsec_rx_sa_cnt (nic); + } +#endif + +return n_stats; +} +static void aq_ethtool_stats (struct net_device *ndev,struct ethtool_stats *stats,u64 *data) {struct aq_nic_s *aq_nic =netdev_priv (ndev); -struct aq_nic_cfg_s *cfg; - cfg =aq_nic_get_cfg (aq_nic); - -memset (data,0 , (ARRAY_SIZE (aq_ethtool_stat_names) + -ARRAY_SIZE (aq_ethtool_queue_stat_names) * - cfg->vecs) *sizeof (u64)); -aq_nic_get_stats (aq_nic, data); +memset (data,0 ,aq_ethtool_n_stats (ndev) *sizeof (u64)); + data =aq_nic_get_stats (aq_nic, data); +#if IS_ENABLED (CONFIG_MACSEC ) + data =aq_macsec_get_stats (aq_nic, data); +#endif } static void aq_ethtool_get_drvinfo(struct net_device *ndev,
@@ -123,11 +200,9 @@ static void aq_ethtool_get_drvinfo(struct net_device *ndev, {struct pci_dev *pdev =to_pci_dev (ndev->dev.parent);struct aq_nic_s *aq_nic =netdev_priv (ndev); -struct aq_nic_cfg_s *cfg;u32 firmware_version;u32 regs_count; - cfg =aq_nic_get_cfg (aq_nic); firmware_version =aq_nic_get_fw_version (aq_nic); regs_count =aq_nic_get_regs_count (aq_nic);
@@ -139,8 +214,7 @@ static void aq_ethtool_get_drvinfo(struct net_device *ndev,strlcpy (drvinfo->bus_info, pdev ?pci_name (pdev) :"" ,sizeof (drvinfo->bus_info)); - drvinfo->n_stats =ARRAY_SIZE (aq_ethtool_stat_names) + - cfg->vecs *ARRAY_SIZE (aq_ethtool_queue_stat_names); + drvinfo->n_stats =aq_ethtool_n_stats (ndev); drvinfo->testinfo_len =0 ; drvinfo->regdump_len = regs_count; drvinfo->eedump_len =0 ;
@@ -153,6 +227,9 @@ static void aq_ethtool_get_strings(struct net_device *ndev,struct aq_nic_cfg_s *cfg;u8 *p = data;int i, si; +#if IS_ENABLED (CONFIG_MACSEC ) +int sa; +#endif cfg =aq_nic_get_cfg (aq_nic);
@@ -170,6 +247,60 @@ static void aq_ethtool_get_strings(struct net_device *ndev, p +=ETH_GSTRING_LEN ; } } +#if IS_ENABLED (CONFIG_MACSEC ) +if (!aq_nic->macsec_cfg) +break ; + +memcpy (p, aq_macsec_stat_names,sizeof (aq_macsec_stat_names)); + p = p +sizeof (aq_macsec_stat_names); +for (i =0 ; i <AQ_MACSEC_MAX_SC ; i++) { +struct aq_macsec_txsc *aq_txsc; + +if (!(test_bit (i, &aq_nic->macsec_cfg->txsc_idx_busy))) +continue ; + +for (si =0 ; + si <ARRAY_SIZE (aq_macsec_txsc_stat_names); + si++) { +snprintf (p,ETH_GSTRING_LEN , + aq_macsec_txsc_stat_names[si], i); + p +=ETH_GSTRING_LEN ; + } + aq_txsc = &aq_nic->macsec_cfg->aq_txsc[i]; +for (sa =0 ; sa <MACSEC_NUM_AN ; sa++) { +if (!(test_bit (sa, &aq_txsc->tx_sa_idx_busy))) +continue ; +for (si =0 ; + si <ARRAY_SIZE (aq_macsec_txsa_stat_names); + si++) { +snprintf (p,ETH_GSTRING_LEN , + aq_macsec_txsa_stat_names[si], + i, sa); + p +=ETH_GSTRING_LEN ; + } + } + } +for (i =0 ; i <AQ_MACSEC_MAX_SC ; i++) { +struct aq_macsec_rxsc *aq_rxsc; + +if (!(test_bit (i, &aq_nic->macsec_cfg->rxsc_idx_busy))) +continue ; + + aq_rxsc = &aq_nic->macsec_cfg->aq_rxsc[i]; +for (sa =0 ; sa <MACSEC_NUM_AN ; sa++) { +if (!(test_bit (sa, &aq_rxsc->rx_sa_idx_busy))) +continue ; +for (si =0 ; + si <ARRAY_SIZE (aq_macsec_rxsa_stat_names); + si++) { +snprintf (p,ETH_GSTRING_LEN , + aq_macsec_rxsa_stat_names[si], + i, sa); + p +=ETH_GSTRING_LEN ; + } + } + } +#endif break ;case ETH_SS_PRIV_FLAGS : memcpy(p, aq_ethtool_priv_flag_names,
@@ -209,16 +340,11 @@ static int aq_ethtool_set_phys_id(struct net_device *ndev,static int aq_ethtool_get_sset_count (struct net_device *ndev,int stringset) { -struct aq_nic_s *aq_nic =netdev_priv (ndev); -struct aq_nic_cfg_s *cfg;int ret =0 ; - cfg =aq_nic_get_cfg (aq_nic); -switch (stringset) {case ETH_SS_STATS : - ret =ARRAY_SIZE (aq_ethtool_stat_names) + - cfg->vecs *ARRAY_SIZE (aq_ethtool_queue_stat_names); + ret =aq_ethtool_n_stats (ndev);break ;case ETH_SS_PRIV_FLAGS : ret =ARRAY_SIZE (aq_ethtool_priv_flag_names);
drivers/net/ethernet/aquantia/atlantic/aq_macsec.c +545 -0
566 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/aq_macsec.h +73 -0
102 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +4 -1
@@ -781,7 +781,7 @@ int aq_nic_get_regs_count(struct aq_nic_s *self)return self->aq_nic_cfg.aq_hw_caps->mac_regs_count; } -void aq_nic_get_stats (struct aq_nic_s *self,u64 *data) +u64 *aq_nic_get_stats (struct aq_nic_s *self,u64 *data) {struct aq_vec_s *aq_vec =NULL ;struct aq_stats_s *stats;
@@ -831,7 +831,10 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data)aq_vec_get_sw_stats (aq_vec, data, &count); } + data += count; + err_exit:; +return data; }static void aq_nic_update_ndev_stats (struct aq_nic_s *self)
drivers/net/ethernet/aquantia/atlantic/aq_nic.h +1 -1
@@ -158,7 +158,7 @@ unsigned int aq_nic_map_skb(struct aq_nic_s *self, struct sk_buff *skb,int aq_nic_xmit (struct aq_nic_s *self,struct sk_buff *skb);int aq_nic_get_regs (struct aq_nic_s *self,struct ethtool_regs *regs,void *p);int aq_nic_get_regs_count (struct aq_nic_s *self); -void aq_nic_get_stats (struct aq_nic_s *self,u64 *data); +u64 *aq_nic_get_stats (struct aq_nic_s *self,u64 *data);int aq_nic_stop (struct aq_nic_s *self);void aq_nic_deinit (struct aq_nic_s *self,bool link_down);void aq_nic_set_power (struct aq_nic_s *self);
Signature · 1 line
2.17.1
Hi Antoine,
Sorry forgot to CC you on a whole patchset.
Quoted 20 lines · Igor Russkikh
External Email
----------------------------------------------------------------------
This RFC patchset introduces MACSec HW offloading support in Marvell(Aquantia) AQC atlantic driver.This implementation is a joint effort of Marvell developers on top of the work started by Antoine Tenart.
RFC v2:
- Split out patch for updating the SCI upon MAC address change.Sent as a net tree fix; - Improved changelog for "net: macsec: add support for getting offloaded stats" patch (patch 0008 in this series);- Don't fallback to s/w stats when offloading is enabled;
- Removed the "enable HW offloading by default" patch. Separate patch will be submitted to enable specifying the desired offload upon macsec device creation (upon ip link add);
- Accommodated comments related to "MACSec offload skeleton" patch.
Signature · 2 lines
Regards, Igor