|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
| 2 | +/* Atlantic Network Driver |
| 3 | + * Copyright (C) 2020 Marvell International Ltd. |
| 4 | + */ |
| 5 | + |
| 6 | +#include "aq_macsec.h" |
| 7 | +#include "aq_nic.h" |
| 8 | +#include <linux/rtnetlink.h> |
| 9 | + |
| 10 | +static int aq_mdo_dev_open(struct macsec_context *ctx) |
| 11 | +{ |
| 12 | + return 0; |
| 13 | +} |
| 14 | + |
| 15 | +static int aq_mdo_dev_stop(struct macsec_context *ctx) |
| 16 | +{ |
| 17 | + return 0; |
| 18 | +} |
| 19 | + |
| 20 | +static int aq_mdo_add_secy(struct macsec_context *ctx) |
| 21 | +{ |
| 22 | + return -EOPNOTSUPP; |
| 23 | +} |
| 24 | + |
| 25 | +static int aq_mdo_upd_secy(struct macsec_context *ctx) |
| 26 | +{ |
| 27 | + return -EOPNOTSUPP; |
| 28 | +} |
| 29 | + |
| 30 | +static int aq_mdo_del_secy(struct macsec_context *ctx) |
| 31 | +{ |
| 32 | + return -EOPNOTSUPP; |
| 33 | +} |
| 34 | + |
| 35 | +static int aq_mdo_add_txsa(struct macsec_context *ctx) |
| 36 | +{ |
| 37 | + return -EOPNOTSUPP; |
| 38 | +} |
| 39 | + |
| 40 | +static int aq_mdo_upd_txsa(struct macsec_context *ctx) |
| 41 | +{ |
| 42 | + return -EOPNOTSUPP; |
| 43 | +} |
| 44 | + |
| 45 | +static int aq_mdo_del_txsa(struct macsec_context *ctx) |
| 46 | +{ |
| 47 | + return -EOPNOTSUPP; |
| 48 | +} |
| 49 | + |
| 50 | +static int aq_mdo_add_rxsc(struct macsec_context *ctx) |
| 51 | +{ |
| 52 | + return -EOPNOTSUPP; |
| 53 | +} |
| 54 | + |
| 55 | +static int aq_mdo_upd_rxsc(struct macsec_context *ctx) |
| 56 | +{ |
| 57 | + return -EOPNOTSUPP; |
| 58 | +} |
| 59 | + |
| 60 | +static int aq_mdo_del_rxsc(struct macsec_context *ctx) |
| 61 | +{ |
| 62 | + return -EOPNOTSUPP; |
| 63 | +} |
| 64 | + |
| 65 | +static int aq_mdo_add_rxsa(struct macsec_context *ctx) |
| 66 | +{ |
| 67 | + return -EOPNOTSUPP; |
| 68 | +} |
| 69 | + |
| 70 | +static int aq_mdo_upd_rxsa(struct macsec_context *ctx) |
| 71 | +{ |
| 72 | + return -EOPNOTSUPP; |
| 73 | +} |
| 74 | + |
| 75 | +static int aq_mdo_del_rxsa(struct macsec_context *ctx) |
| 76 | +{ |
| 77 | + return -EOPNOTSUPP; |
| 78 | +} |
| 79 | + |
| 80 | +static void aq_check_txsa_expiration(struct aq_nic_s *nic) |
| 81 | +{ |
| 82 | +} |
| 83 | + |
| 84 | +const struct macsec_ops aq_macsec_ops = { |
| 85 | + .mdo_dev_open = aq_mdo_dev_open, |
| 86 | + .mdo_dev_stop = aq_mdo_dev_stop, |
| 87 | + .mdo_add_secy = aq_mdo_add_secy, |
| 88 | + .mdo_upd_secy = aq_mdo_upd_secy, |
| 89 | + .mdo_del_secy = aq_mdo_del_secy, |
| 90 | + .mdo_add_rxsc = aq_mdo_add_rxsc, |
| 91 | + .mdo_upd_rxsc = aq_mdo_upd_rxsc, |
| 92 | + .mdo_del_rxsc = aq_mdo_del_rxsc, |
| 93 | + .mdo_add_rxsa = aq_mdo_add_rxsa, |
| 94 | + .mdo_upd_rxsa = aq_mdo_upd_rxsa, |
| 95 | + .mdo_del_rxsa = aq_mdo_del_rxsa, |
| 96 | + .mdo_add_txsa = aq_mdo_add_txsa, |
| 97 | + .mdo_upd_txsa = aq_mdo_upd_txsa, |
| 98 | + .mdo_del_txsa = aq_mdo_del_txsa, |
| 99 | +}; |
| 100 | + |
| 101 | +int aq_macsec_init(struct aq_nic_s *nic) |
| 102 | +{ |
| 103 | + struct aq_macsec_cfg *cfg; |
| 104 | + u32 caps_lo; |
| 105 | + |
| 106 | + if (!nic->aq_fw_ops->get_link_capabilities) |
| 107 | + return 0; |
| 108 | + |
| 109 | + caps_lo = nic->aq_fw_ops->get_link_capabilities(nic->aq_hw); |
| 110 | + |
| 111 | + if (!(caps_lo & BIT(CAPS_LO_MACSEC))) |
| 112 | + return 0; |
| 113 | + |
| 114 | + nic->macsec_cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); |
| 115 | + if (!nic->macsec_cfg) |
| 116 | + return -ENOMEM; |
| 117 | + |
| 118 | + nic->ndev->features |= NETIF_F_HW_MACSEC; |
| 119 | + nic->ndev->macsec_ops = &aq_macsec_ops; |
| 120 | + |
| 121 | + return 0; |
| 122 | +} |
| 123 | + |
| 124 | +void aq_macsec_free(struct aq_nic_s *nic) |
| 125 | +{ |
| 126 | + kfree(nic->macsec_cfg); |
| 127 | + nic->macsec_cfg = NULL; |
| 128 | +} |
| 129 | + |
| 130 | +int aq_macsec_enable(struct aq_nic_s *nic) |
| 131 | +{ |
| 132 | + struct macsec_msg_fw_response resp = { 0 }; |
| 133 | + struct macsec_msg_fw_request msg = { 0 }; |
| 134 | + struct aq_hw_s *hw = nic->aq_hw; |
| 135 | + int ret = 0; |
| 136 | + |
| 137 | + if (!nic->macsec_cfg) |
| 138 | + return 0; |
| 139 | + |
| 140 | + rtnl_lock(); |
| 141 | + |
| 142 | + if (nic->aq_fw_ops->send_macsec_req) { |
| 143 | + struct macsec_cfg_request cfg = { 0 }; |
| 144 | + |
| 145 | + cfg.enabled = 1; |
| 146 | + cfg.egress_threshold = 0xffffffff; |
| 147 | + cfg.ingress_threshold = 0xffffffff; |
| 148 | + cfg.interrupts_enabled = 1; |
| 149 | + |
| 150 | + msg.msg_type = macsec_cfg_msg; |
| 151 | + msg.cfg = cfg; |
| 152 | + |
| 153 | + ret = nic->aq_fw_ops->send_macsec_req(hw, &msg, &resp); |
| 154 | + if (ret) |
| 155 | + goto unlock; |
| 156 | + } |
| 157 | + |
| 158 | +unlock: |
| 159 | + rtnl_unlock(); |
| 160 | + return ret; |
| 161 | +} |
| 162 | + |
| 163 | +void aq_macsec_work(struct aq_nic_s *nic) |
| 164 | +{ |
| 165 | + if (!nic->macsec_cfg) |
| 166 | + return; |
| 167 | + |
| 168 | + if (!netif_carrier_ok(nic->ndev)) |
| 169 | + return; |
| 170 | + |
| 171 | + rtnl_lock(); |
| 172 | + aq_check_txsa_expiration(nic); |
| 173 | + rtnl_unlock(); |
| 174 | +} |
0 commit comments