Commit a20af95f authored by David S. Miller's avatar David S. Miller

Merge branch 'marvell-prestera-firmware-3-0'

Vadym Kochan says:

====================
Marvell Prestera Switchdev initial updates for firmware version 3.0

This series adds minimal support for firmware version 3.0 which
has such changes like:

    - initial routing support

    - LAG support

    - events interrupt handling changes

Changes just make able to work with new firmware version but
supported features in driver will be added later.

New firmware version was recently merged into linux-firmware tree.

Added ability of loading previous fw major version if the latest one
is missing, also add support for previous FW ABI.

PATCH -> RFC:
    1) Load previous fw version if the latest one is missing (suggested by Andrew Lunn)

    2) Add support for previous FW ABI version (suggested by Andrew Lunn)

RFC v2:
    1) Get rid of automatic decrementing of
       major version but hard code it.

    2) Print error message with file path if
       previous FW could not be loaded.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0bf4d9af 47f26018
......@@ -2,6 +2,7 @@
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved */
#include <linux/etherdevice.h>
#include <linux/if_bridge.h>
#include <linux/ethtool.h>
#include <linux/list.h>
......@@ -85,6 +86,11 @@ enum {
PRESTERA_PORT_TP_AUTO,
};
enum {
PRESTERA_PORT_FLOOD_TYPE_UC = 0,
PRESTERA_PORT_FLOOD_TYPE_MC = 1,
};
enum {
PRESTERA_PORT_GOOD_OCTETS_RCV_CNT,
PRESTERA_PORT_BAD_OCTETS_RCV_CNT,
......@@ -188,6 +194,11 @@ struct prestera_msg_port_mdix_param {
u8 admin_mode;
};
struct prestera_msg_port_flood_param {
u8 type;
u8 enable;
};
union prestera_msg_port_param {
u8 admin_state;
u8 oper_state;
......@@ -205,6 +216,7 @@ union prestera_msg_port_param {
struct prestera_msg_port_mdix_param mdix;
struct prestera_msg_port_autoneg_param autoneg;
struct prestera_msg_port_cap_param cap;
struct prestera_msg_port_flood_param flood_ext;
};
struct prestera_msg_port_attr_req {
......@@ -988,7 +1000,43 @@ int prestera_hw_port_learning_set(struct prestera_port *port, bool enable)
&req.cmd, sizeof(req));
}
int prestera_hw_port_flood_set(struct prestera_port *port, bool flood)
static int prestera_hw_port_uc_flood_set(struct prestera_port *port, bool flood)
{
struct prestera_msg_port_attr_req req = {
.attr = PRESTERA_CMD_PORT_ATTR_FLOOD,
.port = port->hw_id,
.dev = port->dev_id,
.param = {
.flood_ext = {
.type = PRESTERA_PORT_FLOOD_TYPE_UC,
.enable = flood,
}
}
};
return prestera_cmd(port->sw, PRESTERA_CMD_TYPE_PORT_ATTR_SET,
&req.cmd, sizeof(req));
}
static int prestera_hw_port_mc_flood_set(struct prestera_port *port, bool flood)
{
struct prestera_msg_port_attr_req req = {
.attr = PRESTERA_CMD_PORT_ATTR_FLOOD,
.port = port->hw_id,
.dev = port->dev_id,
.param = {
.flood_ext = {
.type = PRESTERA_PORT_FLOOD_TYPE_MC,
.enable = flood,
}
}
};
return prestera_cmd(port->sw, PRESTERA_CMD_TYPE_PORT_ATTR_SET,
&req.cmd, sizeof(req));
}
static int prestera_hw_port_flood_set_v2(struct prestera_port *port, bool flood)
{
struct prestera_msg_port_attr_req req = {
.attr = PRESTERA_CMD_PORT_ATTR_FLOOD,
......@@ -1003,6 +1051,41 @@ int prestera_hw_port_flood_set(struct prestera_port *port, bool flood)
&req.cmd, sizeof(req));
}
int prestera_hw_port_flood_set(struct prestera_port *port, unsigned long mask,
unsigned long val)
{
int err;
if (port->sw->dev->fw_rev.maj <= 2) {
if (!(mask & BR_FLOOD))
return 0;
return prestera_hw_port_flood_set_v2(port, val & BR_FLOOD);
}
if (mask & BR_FLOOD) {
err = prestera_hw_port_uc_flood_set(port, val & BR_FLOOD);
if (err)
goto err_uc_flood;
}
if (mask & BR_MCAST_FLOOD) {
err = prestera_hw_port_mc_flood_set(port, val & BR_MCAST_FLOOD);
if (err)
goto err_mc_flood;
}
return 0;
err_mc_flood:
prestera_hw_port_mc_flood_set(port, 0);
err_uc_flood:
if (mask & BR_FLOOD)
prestera_hw_port_uc_flood_set(port, 0);
return err;
}
int prestera_hw_vlan_create(struct prestera_switch *sw, u16 vid)
{
struct prestera_msg_vlan_req req = {
......
......@@ -138,7 +138,8 @@ int prestera_hw_port_mdix_get(const struct prestera_port *port, u8 *status,
int prestera_hw_port_mdix_set(const struct prestera_port *port, u8 mode);
int prestera_hw_port_speed_get(const struct prestera_port *port, u32 *speed);
int prestera_hw_port_learning_set(struct prestera_port *port, bool enable);
int prestera_hw_port_flood_set(struct prestera_port *port, bool flood);
int prestera_hw_port_flood_set(struct prestera_port *port, unsigned long mask,
unsigned long val);
int prestera_hw_port_accept_frm_type(struct prestera_port *port,
enum prestera_accept_frm_type type);
/* Vlan API */
......
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved */
#include <linux/bitfield.h>
#include <linux/circ_buf.h>
#include <linux/device.h>
#include <linux/firmware.h>
......@@ -13,9 +14,12 @@
#define PRESTERA_MSG_MAX_SIZE 1500
#define PRESTERA_SUPP_FW_MAJ_VER 2
#define PRESTERA_SUPP_FW_MAJ_VER 3
#define PRESTERA_SUPP_FW_MIN_VER 0
#define PRESTERA_PREV_FW_MAJ_VER 2
#define PRESTERA_PREV_FW_MIN_VER 0
#define PRESTERA_FW_PATH_FMT "mrvl/prestera/mvsw_prestera_fw-v%u.%u.img"
#define PRESTERA_FW_HDR_MAGIC 0x351D9D06
......@@ -144,6 +148,11 @@ struct prestera_fw_regs {
/* PRESTERA_CMD_RCV_CTL_REG flags */
#define PRESTERA_CMD_F_REPL_SENT BIT(0)
#define PRESTERA_FW_EVT_CTL_STATUS_MASK GENMASK(1, 0)
#define PRESTERA_FW_EVT_CTL_STATUS_ON 0
#define PRESTERA_FW_EVT_CTL_STATUS_OFF 1
#define PRESTERA_EVTQ_REG_OFFSET(q, f) \
(PRESTERA_FW_REG_OFFSET(evtq_list) + \
(q) * sizeof(struct prestera_fw_evtq_regs) + \
......@@ -166,6 +175,8 @@ struct prestera_fw_evtq {
};
struct prestera_fw {
struct prestera_fw_rev rev_supp;
const struct firmware *bin;
struct workqueue_struct *wq;
struct prestera_device dev;
u8 __iomem *ldr_regs;
......@@ -260,6 +271,15 @@ static u8 prestera_fw_evtq_pick(struct prestera_fw *fw)
return PRESTERA_EVT_QNUM_MAX;
}
static void prestera_fw_evt_ctl_status_set(struct prestera_fw *fw, u32 val)
{
u32 status = prestera_fw_read(fw, PRESTERA_FW_STATUS_REG);
u32p_replace_bits(&status, val, PRESTERA_FW_EVT_CTL_STATUS_MASK);
prestera_fw_write(fw, PRESTERA_FW_STATUS_REG, status);
}
static void prestera_fw_evt_work_fn(struct work_struct *work)
{
struct prestera_fw *fw;
......@@ -269,6 +289,8 @@ static void prestera_fw_evt_work_fn(struct work_struct *work)
fw = container_of(work, struct prestera_fw, evt_work);
msg = fw->evt_msg;
prestera_fw_evt_ctl_status_set(fw, PRESTERA_FW_EVT_CTL_STATUS_OFF);
while ((qid = prestera_fw_evtq_pick(fw)) < PRESTERA_EVT_QNUM_MAX) {
u32 idx;
u32 len;
......@@ -288,6 +310,8 @@ static void prestera_fw_evt_work_fn(struct work_struct *work)
if (fw->dev.recv_msg)
fw->dev.recv_msg(&fw->dev, msg, len);
}
prestera_fw_evt_ctl_status_set(fw, PRESTERA_FW_EVT_CTL_STATUS_ON);
}
static int prestera_fw_wait_reg32(struct prestera_fw *fw, u32 reg, u32 cmp,
......@@ -576,25 +600,24 @@ static void prestera_fw_rev_parse(const struct prestera_fw_header *hdr,
static int prestera_fw_rev_check(struct prestera_fw *fw)
{
struct prestera_fw_rev *rev = &fw->dev.fw_rev;
u16 maj_supp = PRESTERA_SUPP_FW_MAJ_VER;
u16 min_supp = PRESTERA_SUPP_FW_MIN_VER;
if (rev->maj == maj_supp && rev->min >= min_supp)
if (rev->maj == fw->rev_supp.maj && rev->min >= fw->rev_supp.min)
return 0;
dev_err(fw->dev.dev, "Driver supports FW version only '%u.%u.x'",
PRESTERA_SUPP_FW_MAJ_VER, PRESTERA_SUPP_FW_MIN_VER);
fw->rev_supp.maj, fw->rev_supp.min);
return -EINVAL;
}
static int prestera_fw_hdr_parse(struct prestera_fw *fw,
const struct firmware *img)
static int prestera_fw_hdr_parse(struct prestera_fw *fw)
{
struct prestera_fw_header *hdr = (struct prestera_fw_header *)img->data;
struct prestera_fw_rev *rev = &fw->dev.fw_rev;
struct prestera_fw_header *hdr;
u32 magic;
hdr = (struct prestera_fw_header *)fw->bin->data;
magic = be32_to_cpu(hdr->magic_number);
if (magic != PRESTERA_FW_HDR_MAGIC) {
dev_err(fw->dev.dev, "FW img hdr magic is invalid");
......@@ -609,11 +632,52 @@ static int prestera_fw_hdr_parse(struct prestera_fw *fw,
return prestera_fw_rev_check(fw);
}
static int prestera_fw_get(struct prestera_fw *fw)
{
int ver_maj = PRESTERA_SUPP_FW_MAJ_VER;
int ver_min = PRESTERA_SUPP_FW_MIN_VER;
char fw_path[128];
int err;
pick_fw_ver:
snprintf(fw_path, sizeof(fw_path), PRESTERA_FW_PATH_FMT,
ver_maj, ver_min);
err = request_firmware_direct(&fw->bin, fw_path, fw->dev.dev);
if (err) {
if (ver_maj == PRESTERA_SUPP_FW_MAJ_VER) {
ver_maj = PRESTERA_PREV_FW_MAJ_VER;
ver_min = PRESTERA_PREV_FW_MIN_VER;
dev_warn(fw->dev.dev,
"missing latest %s firmware, fall-back to previous %u.%u version\n",
fw_path, ver_maj, ver_min);
goto pick_fw_ver;
} else {
dev_err(fw->dev.dev, "failed to request previous firmware: %s\n",
fw_path);
return err;
}
}
dev_info(fw->dev.dev, "Loading %s ...", fw_path);
fw->rev_supp.maj = ver_maj;
fw->rev_supp.min = ver_min;
fw->rev_supp.sub = 0;
return 0;
}
static void prestera_fw_put(struct prestera_fw *fw)
{
release_firmware(fw->bin);
}
static int prestera_fw_load(struct prestera_fw *fw)
{
size_t hlen = sizeof(struct prestera_fw_header);
const struct firmware *f;
char fw_path[128];
int err;
err = prestera_ldr_wait_reg32(fw, PRESTERA_LDR_READY_REG,
......@@ -632,30 +696,24 @@ static int prestera_fw_load(struct prestera_fw *fw)
fw->ldr_wr_idx = 0;
snprintf(fw_path, sizeof(fw_path), PRESTERA_FW_PATH_FMT,
PRESTERA_SUPP_FW_MAJ_VER, PRESTERA_SUPP_FW_MIN_VER);
err = request_firmware_direct(&f, fw_path, fw->dev.dev);
if (err) {
dev_err(fw->dev.dev, "failed to request firmware file\n");
err = prestera_fw_get(fw);
if (err)
return err;
}
err = prestera_fw_hdr_parse(fw, f);
err = prestera_fw_hdr_parse(fw);
if (err) {
dev_err(fw->dev.dev, "FW image header is invalid\n");
goto out_release;
}
prestera_ldr_write(fw, PRESTERA_LDR_IMG_SIZE_REG, f->size - hlen);
prestera_ldr_write(fw, PRESTERA_LDR_IMG_SIZE_REG, fw->bin->size - hlen);
prestera_ldr_write(fw, PRESTERA_LDR_CTL_REG, PRESTERA_LDR_CTL_DL_START);
dev_info(fw->dev.dev, "Loading %s ...", fw_path);
err = prestera_ldr_fw_send(fw, f->data + hlen, f->size - hlen);
err = prestera_ldr_fw_send(fw, fw->bin->data + hlen,
fw->bin->size - hlen);
out_release:
release_firmware(f);
prestera_fw_put(fw);
return err;
}
......
......@@ -404,7 +404,8 @@ prestera_bridge_1d_port_join(struct prestera_bridge_port *br_port)
if (err)
return err;
err = prestera_hw_port_flood_set(port, br_port->flags & BR_FLOOD);
err = prestera_hw_port_flood_set(port, BR_FLOOD | BR_MCAST_FLOOD,
br_port->flags);
if (err)
goto err_port_flood_set;
......@@ -415,7 +416,6 @@ prestera_bridge_1d_port_join(struct prestera_bridge_port *br_port)
return 0;
err_port_learning_set:
prestera_hw_port_flood_set(port, false);
err_port_flood_set:
prestera_hw_bridge_port_delete(port, bridge->bridge_id);
......@@ -528,7 +528,7 @@ static void prestera_port_bridge_leave(struct prestera_port *port,
prestera_bridge_1d_port_leave(br_port);
prestera_hw_port_learning_set(port, false);
prestera_hw_port_flood_set(port, false);
prestera_hw_port_flood_set(port, BR_FLOOD | BR_MCAST_FLOOD, 0);
prestera_port_vid_stp_set(port, PRESTERA_VID_ALL, BR_STATE_FORWARDING);
prestera_bridge_port_put(br_port);
}
......@@ -590,11 +590,9 @@ static int prestera_port_attr_br_flags_set(struct prestera_port *port,
if (!br_port)
return 0;
if (flags.mask & BR_FLOOD) {
err = prestera_hw_port_flood_set(port, flags.val & BR_FLOOD);
err = prestera_hw_port_flood_set(port, flags.mask, flags.val);
if (err)
return err;
}
if (flags.mask & BR_LEARNING) {
err = prestera_hw_port_learning_set(port,
......@@ -901,7 +899,8 @@ prestera_port_vlan_bridge_join(struct prestera_port_vlan *port_vlan,
if (port_vlan->br_port)
return 0;
err = prestera_hw_port_flood_set(port, br_port->flags & BR_FLOOD);
err = prestera_hw_port_flood_set(port, BR_FLOOD | BR_MCAST_FLOOD,
br_port->flags);
if (err)
return err;
......
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