Skip to content

Commit

Permalink
[Mellanox] Add patches for i2c API (sonic-net#162)
Browse files Browse the repository at this point in the history
From 6360f7272a370eee26118d46d963bb91ea36dfa2 Mon Sep 17 00:00:00 2001
From: Vadim Pasternak <[email protected]>
Date: Tue, 29 Sep 2020 08:58:57 +0300
Subject: [PATCH backport v4.19 0/8] 

Patchset contians backport of the below commits:
commit 3dcfe179570550c888ecfcd3d443d4de90a2d855
commit 3029a693beda5bff599feccc3beb9df1e141c786
commit 6a986993e43f176e07c28df560b1cfc3e9b80505
commit 95b75cbd1bc57ec5898517a3fb2f7621f16b26cd
commit f43d9d9b4eb869b1c1513ce8b931389b64b92db1
commit 27758c801663d17eafcd4e45179e7294a9c290b8

From commit 3dcfe179570550c888ecfcd3d443d4de90a2d855 backported only
setting of I2C bus frequnecy, other code from this commit has been
applied in older commits.
commit.

Patchset contians 'mlxsw: i2c: Add device info log', adding info log
to probe() routine to report firmware setting in 'dmesg'.
This is not upstream commit, but this code has been exist in Sonic from
day one and used for debug purpose.

Vadim Pasternak (7):
  mlxsw: i2c: Fix comment misspelling torvalds/linux@27758c8
  mlxsw: i2c: Modify input parameter name in initialization API
  mlxsw: i2c: Extend input parameters list of command API
  mlxsw: i2c: Extend initialization by querying resources data
  mlxsw: i2c: Extend initialization with querying firmware info
  mlxsw: i2c: Allow flexible setting of I2C transactions size
  mlxsw: core: Set different thermal polling time based on bus frequency capability

 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c |   6 +-
 drivers/net/ethernet/mellanox/mlxsw/i2c.c          | 212 +++++++++++++++++----
 2 files changed, 178 insertions(+), 40 deletions(-)

torvalds/linux@27758c8 mlxsw: i2c: Fix comment misspelling (5.1-rc1)
torvalds/linux@f43d9d9b mlxsw: i2c: Modify input parameter name in initialization API (5.1-rc1)
torvalds/linux@95b75cb mlxsw: i2c: Extend input parameters list of command API (5.1-rc1)
torvalds/linux@6a986993 mlxsw: i2c: Extend initialization by querying resources data (5.1-rc1)
torvalds/linux@9bbd7ef mlxsw: i2c: Extend initialization with querying firmware info (5.3-rc1)
torvalds/linux@3029a69 mlxsw: i2c: Allow flexible setting of I2C transactions size (5.3-rc1)
torvalds/linux@3dcfe17 mlxsw: core: Set different thermal polling time based on bus frequency capability (5.1-rc1)

Signed-off-by: Volodymyr Samotiy <[email protected]>
  • Loading branch information
volodymyrsamotiy authored Nov 6, 2020
1 parent af486c6 commit a28b399
Show file tree
Hide file tree
Showing 8 changed files with 638 additions and 0 deletions.
31 changes: 31 additions & 0 deletions patch/0014-mlxsw-i2c-Fix-comment-misspelling.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From bb549427f1fcf0ac05d6d72546847b1d98eaf771 Mon Sep 17 00:00:00 2001
From: Vadim Pasternak <[email protected]>
Date: Sun, 3 Mar 2019 09:12:12 +0000
Subject: [PATCH backport v4.19 1/8] mlxsw: i2c: Fix comment misspelling

Fix comment for mlxsw_i2c_write_cmd().

Signed-off-by: Vadim Pasternak <[email protected]>
Acked-by: Jiri Pirko <[email protected]>
Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
---
drivers/net/ethernet/mellanox/mlxsw/i2c.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/i2c.c b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
index 798bd5aca384..cdeee35b829b 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/i2c.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
@@ -167,7 +167,7 @@ static int mlxsw_i2c_wait_go_bit(struct i2c_client *client,
return err > 0 ? 0 : err;
}

-/* Routine posts a command to ASIC though mail box. */
+/* Routine posts a command to ASIC through mail box. */
static int mlxsw_i2c_write_cmd(struct i2c_client *client,
struct mlxsw_i2c *mlxsw_i2c,
int immediate)
--
2.11.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From 1d4de996de20444fdb4b2c1ab63bf7fa981dc997 Mon Sep 17 00:00:00 2001
From: Vadim Pasternak <[email protected]>
Date: Sun, 3 Mar 2019 09:12:14 +0000
Subject: [PATCH backport v4.19 2/8] mlxsw: i2c: Modify input parameter name in
initialization API

Change input parameter name "resource" to "res" in mlxsw_i2c_init() in
order to align it with mlxsw_pci_init().

Signed-off-by: Vadim Pasternak <[email protected]>
Acked-by: Jiri Pirko <[email protected]>
Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
---
drivers/net/ethernet/mellanox/mlxsw/i2c.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/i2c.c b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
index cdeee35b829b..0a53c3bff388 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/i2c.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
@@ -414,7 +414,7 @@ static int mlxsw_i2c_skb_transmit(void *bus_priv, struct sk_buff *skb,
static int
mlxsw_i2c_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
const struct mlxsw_config_profile *profile,
- struct mlxsw_res *resources)
+ struct mlxsw_res *res)
{
struct mlxsw_i2c *mlxsw_i2c = bus_priv;

--
2.11.0

199 changes: 199 additions & 0 deletions patch/0016-mlxsw-i2c-Extend-input-parameters-list-of-command-AP.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
From 00c82f8ba6cce3434f5f83611ab149cf02d3f801 Mon Sep 17 00:00:00 2001
From: Vadim Pasternak <[email protected]>
Date: Sun, 3 Mar 2019 09:12:15 +0000
Subject: [PATCH backport v4.19 3/8] mlxsw: i2c: Extend input parameters list
of command API

Extend input parameters list of command API in mlxsw_i2c_cmd() in order
to support initialization commands. Up until now, only access commands
were supported by I2C driver.

Signed-off-by: Vadim Pasternak <[email protected]>
Acked-by: Jiri Pirko <[email protected]>
Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
---
drivers/net/ethernet/mellanox/mlxsw/i2c.c | 120 +++++++++++++++++++++++++-----
1 file changed, 101 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/i2c.c b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
index 0a53c3bff388..3f95692be816 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/i2c.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
@@ -20,8 +20,10 @@
#define MLXSW_I2C_CIR2_OFF_STATUS (MLXSW_I2C_CIR2_BASE + \
MLXSW_I2C_CIR_STATUS_OFF)
#define MLXSW_I2C_OPMOD_SHIFT 12
+#define MLXSW_I2C_EVENT_BIT_SHIFT 22
#define MLXSW_I2C_GO_BIT_SHIFT 23
#define MLXSW_I2C_CIR_CTRL_STATUS_SHIFT 24
+#define MLXSW_I2C_EVENT_BIT BIT(MLXSW_I2C_EVENT_BIT_SHIFT)
#define MLXSW_I2C_GO_BIT BIT(MLXSW_I2C_GO_BIT_SHIFT)
#define MLXSW_I2C_GO_OPMODE BIT(MLXSW_I2C_OPMOD_SHIFT)
#define MLXSW_I2C_SET_IMM_CMD (MLXSW_I2C_GO_OPMODE | \
@@ -33,6 +35,9 @@
#define MLXSW_I2C_TLV_HDR_SIZE 0x10
#define MLXSW_I2C_ADDR_WIDTH 4
#define MLXSW_I2C_PUSH_CMD_SIZE (MLXSW_I2C_ADDR_WIDTH + 4)
+#define MLXSW_I2C_SET_EVENT_CMD (MLXSW_I2C_EVENT_BIT)
+#define MLXSW_I2C_PUSH_EVENT_CMD (MLXSW_I2C_GO_BIT | \
+ MLXSW_I2C_SET_EVENT_CMD)
#define MLXSW_I2C_READ_SEMA_SIZE 4
#define MLXSW_I2C_PREP_SIZE (MLXSW_I2C_ADDR_WIDTH + 28)
#define MLXSW_I2C_MBOX_SIZE 20
@@ -44,6 +49,7 @@
#define MLXSW_I2C_BLK_MAX 32
#define MLXSW_I2C_RETRY 5
#define MLXSW_I2C_TIMEOUT_MSECS 5000
+#define MLXSW_I2C_MAX_DATA_SIZE 256

/**
* struct mlxsw_i2c - device private data:
@@ -213,6 +219,66 @@ static int mlxsw_i2c_write_cmd(struct i2c_client *client,
return 0;
}

+/* Routine posts initialization command to ASIC through mail box. */
+static int
+mlxsw_i2c_write_init_cmd(struct i2c_client *client,
+ struct mlxsw_i2c *mlxsw_i2c, u16 opcode, u32 in_mod)
+{
+ __be32 push_cmd_buf[MLXSW_I2C_PUSH_CMD_SIZE / 4] = {
+ 0, cpu_to_be32(MLXSW_I2C_PUSH_EVENT_CMD)
+ };
+ __be32 prep_cmd_buf[MLXSW_I2C_PREP_SIZE / 4] = {
+ 0, 0, 0, 0, 0, 0,
+ cpu_to_be32(client->adapter->nr & 0xffff),
+ cpu_to_be32(MLXSW_I2C_SET_EVENT_CMD)
+ };
+ struct i2c_msg push_cmd =
+ MLXSW_I2C_WRITE_MSG(client, push_cmd_buf,
+ MLXSW_I2C_PUSH_CMD_SIZE);
+ struct i2c_msg prep_cmd =
+ MLXSW_I2C_WRITE_MSG(client, prep_cmd_buf, MLXSW_I2C_PREP_SIZE);
+ u8 status;
+ int err;
+
+ push_cmd_buf[1] = cpu_to_be32(MLXSW_I2C_PUSH_EVENT_CMD | opcode);
+ prep_cmd_buf[3] = cpu_to_be32(in_mod);
+ prep_cmd_buf[7] = cpu_to_be32(MLXSW_I2C_GO_BIT | opcode);
+ mlxsw_i2c_set_slave_addr((u8 *)prep_cmd_buf,
+ MLXSW_I2C_CIR2_BASE);
+ mlxsw_i2c_set_slave_addr((u8 *)push_cmd_buf,
+ MLXSW_I2C_CIR2_OFF_STATUS);
+
+ /* Prepare Command Interface Register for transaction */
+ err = i2c_transfer(client->adapter, &prep_cmd, 1);
+ if (err < 0)
+ return err;
+ else if (err != 1)
+ return -EIO;
+
+ /* Write out Command Interface Register GO bit to push transaction */
+ err = i2c_transfer(client->adapter, &push_cmd, 1);
+ if (err < 0)
+ return err;
+ else if (err != 1)
+ return -EIO;
+
+ /* Wait until go bit is cleared. */
+ err = mlxsw_i2c_wait_go_bit(client, mlxsw_i2c, &status);
+ if (err) {
+ dev_err(&client->dev, "HW semaphore is not released");
+ return err;
+ }
+
+ /* Validate transaction completion status. */
+ if (status) {
+ dev_err(&client->dev, "Bad transaction completion status %x\n",
+ status);
+ return -EIO;
+ }
+
+ return 0;
+}
+
/* Routine obtains mail box offsets from ASIC register space. */
static int mlxsw_i2c_get_mbox(struct i2c_client *client,
struct mlxsw_i2c *mlxsw_i2c)
@@ -310,8 +376,8 @@ mlxsw_i2c_write(struct device *dev, size_t in_mbox_size, u8 *in_mbox, int num,

/* Routine executes I2C command. */
static int
-mlxsw_i2c_cmd(struct device *dev, size_t in_mbox_size, u8 *in_mbox,
- size_t out_mbox_size, u8 *out_mbox, u8 *status)
+mlxsw_i2c_cmd(struct device *dev, u16 opcode, u32 in_mod, size_t in_mbox_size,
+ u8 *in_mbox, size_t out_mbox_size, u8 *out_mbox, u8 *status)
{
struct i2c_client *client = to_i2c_client(dev);
struct mlxsw_i2c *mlxsw_i2c = i2c_get_clientdata(client);
@@ -326,24 +392,40 @@ mlxsw_i2c_cmd(struct device *dev, size_t in_mbox_size, u8 *in_mbox,

WARN_ON(in_mbox_size % sizeof(u32) || out_mbox_size % sizeof(u32));

- reg_size = mlxsw_i2c_get_reg_size(in_mbox);
- num = reg_size / MLXSW_I2C_BLK_MAX;
- if (reg_size % MLXSW_I2C_BLK_MAX)
- num++;
+ if (in_mbox) {
+ reg_size = mlxsw_i2c_get_reg_size(in_mbox);
+ num = reg_size / MLXSW_I2C_BLK_MAX;
+ if (reg_size % MLXSW_I2C_BLK_MAX)
+ num++;

- if (mutex_lock_interruptible(&mlxsw_i2c->cmd.lock) < 0) {
- dev_err(&client->dev, "Could not acquire lock");
- return -EINVAL;
- }
+ if (mutex_lock_interruptible(&mlxsw_i2c->cmd.lock) < 0) {
+ dev_err(&client->dev, "Could not acquire lock");
+ return -EINVAL;
+ }

- err = mlxsw_i2c_write(dev, reg_size, in_mbox, num, status);
- if (err)
- goto cmd_fail;
+ err = mlxsw_i2c_write(dev, reg_size, in_mbox, num, status);
+ if (err)
+ goto cmd_fail;
+
+ /* No out mailbox is case of write transaction. */
+ if (!out_mbox) {
+ mutex_unlock(&mlxsw_i2c->cmd.lock);
+ return 0;
+ }
+ } else {
+ /* No input mailbox is case of initialization query command. */
+ reg_size = MLXSW_I2C_MAX_DATA_SIZE;
+ num = reg_size / MLXSW_I2C_BLK_MAX;

- /* No out mailbox is case of write transaction. */
- if (!out_mbox) {
- mutex_unlock(&mlxsw_i2c->cmd.lock);
- return 0;
+ if (mutex_lock_interruptible(&mlxsw_i2c->cmd.lock) < 0) {
+ dev_err(&client->dev, "Could not acquire lock");
+ return -EINVAL;
+ }
+
+ err = mlxsw_i2c_write_init_cmd(client, mlxsw_i2c, opcode,
+ in_mod);
+ if (err)
+ goto cmd_fail;
}

/* Send read transaction to get output mailbox content. */
@@ -395,8 +477,8 @@ static int mlxsw_i2c_cmd_exec(void *bus_priv, u16 opcode, u8 opcode_mod,
{
struct mlxsw_i2c *mlxsw_i2c = bus_priv;

- return mlxsw_i2c_cmd(mlxsw_i2c->dev, in_mbox_size, in_mbox,
- out_mbox_size, out_mbox, status);
+ return mlxsw_i2c_cmd(mlxsw_i2c->dev, opcode, in_mod, in_mbox_size,
+ in_mbox, out_mbox_size, out_mbox, status);
}

static bool mlxsw_i2c_skb_transmit_busy(void *bus_priv,
--
2.11.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
From 31f7829248a15f3b9faed7e3bac186b4dbb223cd Mon Sep 17 00:00:00 2001
From: Vadim Pasternak <[email protected]>
Date: Sun, 3 Mar 2019 09:12:16 +0000
Subject: [PATCH backport v4.19 4/8] mlxsw: i2c: Extend initialization by
querying resources data

Extend initialization flow by query requests for chip resources data in
order to obtain chip's specific capabilities, like the number of ports.

Signed-off-by: Vadim Pasternak <[email protected]>
Acked-by: Jiri Pirko <[email protected]>
Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
---
drivers/net/ethernet/mellanox/mlxsw/i2c.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/i2c.c b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
index 3f95692be816..d46a655e3001 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/i2c.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
@@ -14,6 +14,7 @@
#include "cmd.h"
#include "core.h"
#include "i2c.h"
+#include "resources.h"

#define MLXSW_I2C_CIR2_BASE 0x72000
#define MLXSW_I2C_CIR_STATUS_OFF 0x18
@@ -499,10 +500,19 @@ mlxsw_i2c_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
struct mlxsw_res *res)
{
struct mlxsw_i2c *mlxsw_i2c = bus_priv;
+ char *mbox;
+ int err;

mlxsw_i2c->core = mlxsw_core;

- return 0;
+ mbox = mlxsw_cmd_mbox_alloc();
+ if (!mbox)
+ return -ENOMEM;
+
+ err = mlxsw_core_resources_query(mlxsw_core, mbox, res);
+
+ mlxsw_cmd_mbox_free(mbox);
+ return err;
}

static void mlxsw_i2c_fini(void *bus_priv)
--
2.11.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
From 4b70b08c3bd12b6819bf438b9ac5c646167f8803 Mon Sep 17 00:00:00 2001
From: Vadim Pasternak <[email protected]>
Date: Wed, 29 May 2019 11:47:15 +0300
Subject: [PATCH backport v4.19 5/8] mlxsw: i2c: Extend initialization with
querying firmware info

Extend initialization flow with query request for firmware info in
order to obtain firmware version info.
This info is to be provided to minimal driver to support ethtool
get_drvinfo() interface.

Signed-off-by: Vadim Pasternak <[email protected]>
Acked-by: Jiri Pirko <[email protected]>
Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
---
drivers/net/ethernet/mellanox/mlxsw/i2c.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/i2c.c b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
index d46a655e3001..472352977527 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/i2c.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/i2c.c
@@ -509,8 +509,20 @@ mlxsw_i2c_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
if (!mbox)
return -ENOMEM;

+ err = mlxsw_cmd_query_fw(mlxsw_core, mbox);
+ if (err)
+ goto mbox_put;
+
+ mlxsw_i2c->bus_info.fw_rev.major =
+ mlxsw_cmd_mbox_query_fw_fw_rev_major_get(mbox);
+ mlxsw_i2c->bus_info.fw_rev.minor =
+ mlxsw_cmd_mbox_query_fw_fw_rev_minor_get(mbox);
+ mlxsw_i2c->bus_info.fw_rev.subminor =
+ mlxsw_cmd_mbox_query_fw_fw_rev_subminor_get(mbox);
+
err = mlxsw_core_resources_query(mlxsw_core, mbox, res);

+mbox_put:
mlxsw_cmd_mbox_free(mbox);
return err;
}
--
2.11.0

Loading

0 comments on commit a28b399

Please sign in to comment.