Commit 9dfe6aa0 authored by David S. Miller's avatar David S. Miller

Merge branch 'nfp-flower-improvement-and-SFF-module-EEPROM'

Jakub Kicinski says:

====================
nfp: flower improvement and SFF module EEPROM

The first patch in this series from Pieter improves the
handling of mangle actions in TC flower offload.  These
used to be sent down to the driver in groups, but after
Pablo N's patches they are split out causing suboptimal
expression.

The ramaining two patches from Dirk add support for reading
SFF module EEPROM data.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents ac9e81c2 61f7c6f4
......@@ -583,60 +583,23 @@ static u32 nfp_fl_csum_l4_to_flag(u8 ip_proto)
}
}
static int
nfp_fl_pedit(const struct flow_action_entry *act,
struct tc_cls_flower_offload *flow,
char *nfp_action, int *a_len, u32 *csum_updated)
{
struct flow_rule *rule = tc_cls_flower_offload_flow_rule(flow);
struct nfp_flower_pedit_acts {
struct nfp_fl_set_ipv6_addr set_ip6_dst, set_ip6_src;
struct nfp_fl_set_ipv6_tc_hl_fl set_ip6_tc_hl_fl;
struct nfp_fl_set_ip4_ttl_tos set_ip_ttl_tos;
struct nfp_fl_set_ip4_addrs set_ip_addr;
enum flow_action_mangle_base htype;
struct nfp_fl_set_tport set_tport;
struct nfp_fl_set_eth set_eth;
};
static int
nfp_fl_commit_mangle(struct tc_cls_flower_offload *flow, char *nfp_action,
int *a_len, struct nfp_flower_pedit_acts *set_act,
u32 *csum_updated)
{
struct flow_rule *rule = tc_cls_flower_offload_flow_rule(flow);
size_t act_size = 0;
u8 ip_proto = 0;
u32 offset;
int err;
memset(&set_ip6_tc_hl_fl, 0, sizeof(set_ip6_tc_hl_fl));
memset(&set_ip_ttl_tos, 0, sizeof(set_ip_ttl_tos));
memset(&set_ip6_dst, 0, sizeof(set_ip6_dst));
memset(&set_ip6_src, 0, sizeof(set_ip6_src));
memset(&set_ip_addr, 0, sizeof(set_ip_addr));
memset(&set_tport, 0, sizeof(set_tport));
memset(&set_eth, 0, sizeof(set_eth));
htype = act->mangle.htype;
offset = act->mangle.offset;
switch (htype) {
case TCA_PEDIT_KEY_EX_HDR_TYPE_ETH:
err = nfp_fl_set_eth(act, offset, &set_eth);
break;
case TCA_PEDIT_KEY_EX_HDR_TYPE_IP4:
err = nfp_fl_set_ip4(act, offset, &set_ip_addr,
&set_ip_ttl_tos);
break;
case TCA_PEDIT_KEY_EX_HDR_TYPE_IP6:
err = nfp_fl_set_ip6(act, offset, &set_ip6_dst,
&set_ip6_src, &set_ip6_tc_hl_fl);
break;
case TCA_PEDIT_KEY_EX_HDR_TYPE_TCP:
err = nfp_fl_set_tport(act, offset, &set_tport,
NFP_FL_ACTION_OPCODE_SET_TCP);
break;
case TCA_PEDIT_KEY_EX_HDR_TYPE_UDP:
err = nfp_fl_set_tport(act, offset, &set_tport,
NFP_FL_ACTION_OPCODE_SET_UDP);
break;
default:
return -EOPNOTSUPP;
}
if (err)
return err;
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
struct flow_match_basic match;
......@@ -645,77 +608,82 @@ nfp_fl_pedit(const struct flow_action_entry *act,
ip_proto = match.key->ip_proto;
}
if (set_eth.head.len_lw) {
act_size = sizeof(set_eth);
memcpy(nfp_action, &set_eth, act_size);
if (set_act->set_eth.head.len_lw) {
act_size = sizeof(set_act->set_eth);
memcpy(nfp_action, &set_act->set_eth, act_size);
*a_len += act_size;
}
if (set_ip_ttl_tos.head.len_lw) {
if (set_act->set_ip_ttl_tos.head.len_lw) {
nfp_action += act_size;
act_size = sizeof(set_ip_ttl_tos);
memcpy(nfp_action, &set_ip_ttl_tos, act_size);
act_size = sizeof(set_act->set_ip_ttl_tos);
memcpy(nfp_action, &set_act->set_ip_ttl_tos, act_size);
*a_len += act_size;
/* Hardware will automatically fix IPv4 and TCP/UDP checksum. */
*csum_updated |= TCA_CSUM_UPDATE_FLAG_IPV4HDR |
nfp_fl_csum_l4_to_flag(ip_proto);
}
if (set_ip_addr.head.len_lw) {
if (set_act->set_ip_addr.head.len_lw) {
nfp_action += act_size;
act_size = sizeof(set_ip_addr);
memcpy(nfp_action, &set_ip_addr, act_size);
act_size = sizeof(set_act->set_ip_addr);
memcpy(nfp_action, &set_act->set_ip_addr, act_size);
*a_len += act_size;
/* Hardware will automatically fix IPv4 and TCP/UDP checksum. */
*csum_updated |= TCA_CSUM_UPDATE_FLAG_IPV4HDR |
nfp_fl_csum_l4_to_flag(ip_proto);
}
if (set_ip6_tc_hl_fl.head.len_lw) {
if (set_act->set_ip6_tc_hl_fl.head.len_lw) {
nfp_action += act_size;
act_size = sizeof(set_ip6_tc_hl_fl);
memcpy(nfp_action, &set_ip6_tc_hl_fl, act_size);
act_size = sizeof(set_act->set_ip6_tc_hl_fl);
memcpy(nfp_action, &set_act->set_ip6_tc_hl_fl, act_size);
*a_len += act_size;
/* Hardware will automatically fix TCP/UDP checksum. */
*csum_updated |= nfp_fl_csum_l4_to_flag(ip_proto);
}
if (set_ip6_dst.head.len_lw && set_ip6_src.head.len_lw) {
if (set_act->set_ip6_dst.head.len_lw &&
set_act->set_ip6_src.head.len_lw) {
/* TC compiles set src and dst IPv6 address as a single action,
* the hardware requires this to be 2 separate actions.
*/
nfp_action += act_size;
act_size = sizeof(set_ip6_src);
memcpy(nfp_action, &set_ip6_src, act_size);
act_size = sizeof(set_act->set_ip6_src);
memcpy(nfp_action, &set_act->set_ip6_src, act_size);
*a_len += act_size;
act_size = sizeof(set_ip6_dst);
memcpy(&nfp_action[sizeof(set_ip6_src)], &set_ip6_dst,
act_size);
act_size = sizeof(set_act->set_ip6_dst);
memcpy(&nfp_action[sizeof(set_act->set_ip6_src)],
&set_act->set_ip6_dst, act_size);
*a_len += act_size;
/* Hardware will automatically fix TCP/UDP checksum. */
*csum_updated |= nfp_fl_csum_l4_to_flag(ip_proto);
} else if (set_ip6_dst.head.len_lw) {
} else if (set_act->set_ip6_dst.head.len_lw) {
nfp_action += act_size;
act_size = sizeof(set_ip6_dst);
memcpy(nfp_action, &set_ip6_dst, act_size);
act_size = sizeof(set_act->set_ip6_dst);
memcpy(nfp_action, &set_act->set_ip6_dst, act_size);
*a_len += act_size;
/* Hardware will automatically fix TCP/UDP checksum. */
*csum_updated |= nfp_fl_csum_l4_to_flag(ip_proto);
} else if (set_ip6_src.head.len_lw) {
} else if (set_act->set_ip6_src.head.len_lw) {
nfp_action += act_size;
act_size = sizeof(set_ip6_src);
memcpy(nfp_action, &set_ip6_src, act_size);
act_size = sizeof(set_act->set_ip6_src);
memcpy(nfp_action, &set_act->set_ip6_src, act_size);
*a_len += act_size;
/* Hardware will automatically fix TCP/UDP checksum. */
*csum_updated |= nfp_fl_csum_l4_to_flag(ip_proto);
}
if (set_tport.head.len_lw) {
if (set_act->set_tport.head.len_lw) {
nfp_action += act_size;
act_size = sizeof(set_tport);
memcpy(nfp_action, &set_tport, act_size);
act_size = sizeof(set_act->set_tport);
memcpy(nfp_action, &set_act->set_tport, act_size);
*a_len += act_size;
/* Hardware will automatically fix TCP/UDP checksum. */
......@@ -726,7 +694,40 @@ nfp_fl_pedit(const struct flow_action_entry *act,
}
static int
nfp_flower_output_action(struct nfp_app *app, const struct flow_action_entry *act,
nfp_fl_pedit(const struct flow_action_entry *act,
struct tc_cls_flower_offload *flow, char *nfp_action, int *a_len,
u32 *csum_updated, struct nfp_flower_pedit_acts *set_act)
{
enum flow_action_mangle_base htype;
u32 offset;
htype = act->mangle.htype;
offset = act->mangle.offset;
switch (htype) {
case TCA_PEDIT_KEY_EX_HDR_TYPE_ETH:
return nfp_fl_set_eth(act, offset, &set_act->set_eth);
case TCA_PEDIT_KEY_EX_HDR_TYPE_IP4:
return nfp_fl_set_ip4(act, offset, &set_act->set_ip_addr,
&set_act->set_ip_ttl_tos);
case TCA_PEDIT_KEY_EX_HDR_TYPE_IP6:
return nfp_fl_set_ip6(act, offset, &set_act->set_ip6_dst,
&set_act->set_ip6_src,
&set_act->set_ip6_tc_hl_fl);
case TCA_PEDIT_KEY_EX_HDR_TYPE_TCP:
return nfp_fl_set_tport(act, offset, &set_act->set_tport,
NFP_FL_ACTION_OPCODE_SET_TCP);
case TCA_PEDIT_KEY_EX_HDR_TYPE_UDP:
return nfp_fl_set_tport(act, offset, &set_act->set_tport,
NFP_FL_ACTION_OPCODE_SET_UDP);
default:
return -EOPNOTSUPP;
}
}
static int
nfp_flower_output_action(struct nfp_app *app,
const struct flow_action_entry *act,
struct nfp_fl_payload *nfp_fl, int *a_len,
struct net_device *netdev, bool last,
enum nfp_flower_tun_type *tun_type, int *tun_out_cnt,
......@@ -776,7 +777,8 @@ nfp_flower_loop_action(struct nfp_app *app, const struct flow_action_entry *act,
struct nfp_fl_payload *nfp_fl, int *a_len,
struct net_device *netdev,
enum nfp_flower_tun_type *tun_type, int *tun_out_cnt,
int *out_cnt, u32 *csum_updated)
int *out_cnt, u32 *csum_updated,
struct nfp_flower_pedit_acts *set_act)
{
struct nfp_fl_set_ipv4_udp_tun *set_tun;
struct nfp_fl_pre_tunnel *pre_tun;
......@@ -861,7 +863,7 @@ nfp_flower_loop_action(struct nfp_app *app, const struct flow_action_entry *act,
return 0;
case FLOW_ACTION_MANGLE:
if (nfp_fl_pedit(act, flow, &nfp_fl->action_data[*a_len],
a_len, csum_updated))
a_len, csum_updated, set_act))
return -EOPNOTSUPP;
break;
case FLOW_ACTION_CSUM:
......@@ -881,12 +883,49 @@ nfp_flower_loop_action(struct nfp_app *app, const struct flow_action_entry *act,
return 0;
}
static bool nfp_fl_check_mangle_start(struct flow_action *flow_act,
int current_act_idx)
{
struct flow_action_entry current_act;
struct flow_action_entry prev_act;
current_act = flow_act->entries[current_act_idx];
if (current_act.id != FLOW_ACTION_MANGLE)
return false;
if (current_act_idx == 0)
return true;
prev_act = flow_act->entries[current_act_idx - 1];
return prev_act.id != FLOW_ACTION_MANGLE;
}
static bool nfp_fl_check_mangle_end(struct flow_action *flow_act,
int current_act_idx)
{
struct flow_action_entry current_act;
struct flow_action_entry next_act;
current_act = flow_act->entries[current_act_idx];
if (current_act.id != FLOW_ACTION_MANGLE)
return false;
if (current_act_idx == flow_act->num_entries)
return true;
next_act = flow_act->entries[current_act_idx + 1];
return next_act.id != FLOW_ACTION_MANGLE;
}
int nfp_flower_compile_action(struct nfp_app *app,
struct tc_cls_flower_offload *flow,
struct net_device *netdev,
struct nfp_fl_payload *nfp_flow)
{
int act_len, act_cnt, err, tun_out_cnt, out_cnt, i;
struct nfp_flower_pedit_acts set_act;
enum nfp_flower_tun_type tun_type;
struct flow_action_entry *act;
u32 csum_updated = 0;
......@@ -900,12 +939,18 @@ int nfp_flower_compile_action(struct nfp_app *app,
out_cnt = 0;
flow_action_for_each(i, act, &flow->rule->action) {
if (nfp_fl_check_mangle_start(&flow->rule->action, i))
memset(&set_act, 0, sizeof(set_act));
err = nfp_flower_loop_action(app, act, flow, nfp_flow, &act_len,
netdev, &tun_type, &tun_out_cnt,
&out_cnt, &csum_updated);
&out_cnt, &csum_updated, &set_act);
if (err)
return err;
act_cnt++;
if (nfp_fl_check_mangle_end(&flow->rule->action, i))
nfp_fl_commit_mangle(flow,
&nfp_flow->action_data[act_len],
&act_len, &set_act, &csum_updated);
}
/* We optimise when the action list is small, this can unfortunately
......
......@@ -18,6 +18,7 @@
#include <linux/pci.h>
#include <linux/ethtool.h>
#include <linux/firmware.h>
#include <linux/sfp.h>
#include "nfpcore/nfp.h"
#include "nfpcore/nfp_nsp.h"
......@@ -152,6 +153,8 @@ static const struct nfp_et_stat nfp_mac_et_stats[] = {
#define NN_RVEC_GATHER_STATS 9
#define NN_RVEC_PER_Q_STATS 3
#define SFP_SFF_REV_COMPLIANCE 1
static void nfp_net_get_nspinfo(struct nfp_app *app, char *version)
{
struct nfp_nsp *nsp;
......@@ -1096,6 +1099,130 @@ nfp_app_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
buffer);
}
static int
nfp_port_get_module_info(struct net_device *netdev,
struct ethtool_modinfo *modinfo)
{
struct nfp_eth_table_port *eth_port;
struct nfp_port *port;
unsigned int read_len;
struct nfp_nsp *nsp;
int err = 0;
u8 data;
port = nfp_port_from_netdev(netdev);
eth_port = nfp_port_get_eth_port(port);
if (!eth_port)
return -EOPNOTSUPP;
nsp = nfp_nsp_open(port->app->cpp);
if (IS_ERR(nsp)) {
err = PTR_ERR(nsp);
netdev_err(netdev, "Failed to access the NSP: %d\n", err);
return err;
}
if (!nfp_nsp_has_read_module_eeprom(nsp)) {
netdev_info(netdev, "reading module EEPROM not supported. Please update flash\n");
err = -EOPNOTSUPP;
goto exit_close_nsp;
}
switch (eth_port->interface) {
case NFP_INTERFACE_SFP:
case NFP_INTERFACE_SFP28:
err = nfp_nsp_read_module_eeprom(nsp, eth_port->eth_index,
SFP_SFF8472_COMPLIANCE, &data,
1, &read_len);
if (err < 0)
goto exit_close_nsp;
if (!data) {
modinfo->type = ETH_MODULE_SFF_8079;
modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
} else {
modinfo->type = ETH_MODULE_SFF_8472;
modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
}
break;
case NFP_INTERFACE_QSFP:
err = nfp_nsp_read_module_eeprom(nsp, eth_port->eth_index,
SFP_SFF_REV_COMPLIANCE, &data,
1, &read_len);
if (err < 0)
goto exit_close_nsp;
if (data < 0x3) {
modinfo->type = ETH_MODULE_SFF_8436;
modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
} else {
modinfo->type = ETH_MODULE_SFF_8636;
modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
}
break;
case NFP_INTERFACE_QSFP28:
modinfo->type = ETH_MODULE_SFF_8636;
modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
break;
default:
netdev_err(netdev, "Unsupported module 0x%x detected\n",
eth_port->interface);
err = -EINVAL;
}
exit_close_nsp:
nfp_nsp_close(nsp);
return err;
}
static int
nfp_port_get_module_eeprom(struct net_device *netdev,
struct ethtool_eeprom *eeprom, u8 *data)
{
struct nfp_eth_table_port *eth_port;
struct nfp_port *port;
struct nfp_nsp *nsp;
int err;
port = nfp_port_from_netdev(netdev);
eth_port = __nfp_port_get_eth_port(port);
if (!eth_port)
return -EOPNOTSUPP;
nsp = nfp_nsp_open(port->app->cpp);
if (IS_ERR(nsp)) {
err = PTR_ERR(nsp);
netdev_err(netdev, "Failed to access the NSP: %d\n", err);
return err;
}
if (!nfp_nsp_has_read_module_eeprom(nsp)) {
netdev_info(netdev, "reading module EEPROM not supported. Please update flash\n");
err = -EOPNOTSUPP;
goto exit_close_nsp;
}
err = nfp_nsp_read_module_eeprom(nsp, eth_port->eth_index,
eeprom->offset, data, eeprom->len,
&eeprom->len);
if (err < 0) {
if (eeprom->len) {
netdev_warn(netdev,
"Incomplete read from module EEPROM: %d\n",
err);
err = 0;
} else {
netdev_err(netdev,
"Reading from module EEPROM failed: %d\n",
err);
}
}
exit_close_nsp:
nfp_nsp_close(nsp);
return err;
}
static int nfp_net_set_coalesce(struct net_device *netdev,
struct ethtool_coalesce *ec)
{
......@@ -1253,6 +1380,8 @@ static const struct ethtool_ops nfp_net_ethtool_ops = {
.set_dump = nfp_app_set_dump,
.get_dump_flag = nfp_app_get_dump_flag,
.get_dump_data = nfp_app_get_dump_data,
.get_module_info = nfp_port_get_module_info,
.get_module_eeprom = nfp_port_get_module_eeprom,
.get_coalesce = nfp_net_get_coalesce,
.set_coalesce = nfp_net_set_coalesce,
.get_channels = nfp_net_get_channels,
......@@ -1272,6 +1401,8 @@ const struct ethtool_ops nfp_port_ethtool_ops = {
.set_dump = nfp_app_set_dump,
.get_dump_flag = nfp_app_get_dump_flag,
.get_dump_data = nfp_app_get_dump_data,
.get_module_info = nfp_port_get_module_info,
.get_module_eeprom = nfp_port_get_module_eeprom,
.get_link_ksettings = nfp_net_get_link_ksettings,
.set_link_ksettings = nfp_net_set_link_ksettings,
.get_fecparam = nfp_port_get_fecparam,
......
......@@ -79,6 +79,8 @@
#define NFP_VERSIONS_NCSI_OFF 22
#define NFP_VERSIONS_CFGR_OFF 26
#define NSP_SFF_EEPROM_BLOCK_LEN 8
enum nfp_nsp_cmd {
SPCODE_NOOP = 0, /* No operation */
SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */
......@@ -95,6 +97,7 @@ enum nfp_nsp_cmd {
SPCODE_FW_STORED = 16, /* If no FW loaded, load flash app FW */
SPCODE_HWINFO_LOOKUP = 17, /* Lookup HWinfo with overwrites etc. */
SPCODE_VERSIONS = 21, /* Report FW versions */
SPCODE_READ_SFF_EEPROM = 22, /* Read module EEPROM */
};
struct nfp_nsp_dma_buf {
......@@ -965,3 +968,62 @@ const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash,
return (const char *)&buf[buf_off];
}
static int
__nfp_nsp_module_eeprom(struct nfp_nsp *state, void *buf, unsigned int size)
{
struct nfp_nsp_command_buf_arg module_eeprom = {
{
.code = SPCODE_READ_SFF_EEPROM,
.option = size,
},
.in_buf = buf,
.in_size = size,
.out_buf = buf,
.out_size = size,
};
return nfp_nsp_command_buf(state, &module_eeprom);
}
int nfp_nsp_read_module_eeprom(struct nfp_nsp *state, int eth_index,
unsigned int offset, void *data,
unsigned int len, unsigned int *read_len)
{
struct eeprom_buf {
u8 metalen;
__le16 length;
__le16 offset;
__le16 readlen;
u8 eth_index;
u8 data[0];
} __packed *buf;
int bufsz, ret;
BUILD_BUG_ON(offsetof(struct eeprom_buf, data) % 8);
/* Buffer must be large enough and rounded to the next block size. */
bufsz = struct_size(buf, data, round_up(len, NSP_SFF_EEPROM_BLOCK_LEN));
buf = kzalloc(bufsz, GFP_KERNEL);
if (!buf)
return -ENOMEM;
buf->metalen =
offsetof(struct eeprom_buf, data) / NSP_SFF_EEPROM_BLOCK_LEN;
buf->length = cpu_to_le16(len);
buf->offset = cpu_to_le16(offset);
buf->eth_index = eth_index;
ret = __nfp_nsp_module_eeprom(state, buf, bufsz);
*read_len = min_t(unsigned int, len, le16_to_cpu(buf->readlen));
if (*read_len)
memcpy(data, buf->data, *read_len);
if (!ret && *read_len < len)
ret = -EIO;
kfree(buf);
return ret;
}
......@@ -22,6 +22,9 @@ int nfp_nsp_write_flash(struct nfp_nsp *state, const struct firmware *fw);
int nfp_nsp_mac_reinit(struct nfp_nsp *state);
int nfp_nsp_load_stored_fw(struct nfp_nsp *state);
int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, unsigned int size);
int nfp_nsp_read_module_eeprom(struct nfp_nsp *state, int eth_index,
unsigned int offset, void *data,
unsigned int len, unsigned int *read_len);
static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state)
{
......@@ -43,6 +46,11 @@ static inline bool nfp_nsp_has_versions(struct nfp_nsp *state)
return nfp_nsp_get_abi_ver_minor(state) > 27;
}
static inline bool nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state)
{
return nfp_nsp_get_abi_ver_minor(state) > 28;
}
enum nfp_eth_interface {
NFP_INTERFACE_NONE = 0,
NFP_INTERFACE_SFP = 1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment