Skip to content

Commit 4525abe

Browse files
majdmellanoxSaeed Mahameed
authored andcommitted
net/mlx5: Expose command polling interface
Add a new interface for commands execution that allows the caller to wait for the command's completion in a busy-wait loop (polling mode). This is useful if we want to execute a command in a polling mode while the driver is working in events mode for the rest of the commands. This interface will be used in the downstream patches. Signed-off-by: Majd Dibbiny <[email protected]> Signed-off-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 3834a5e commit 4525abe

File tree

2 files changed

+26
-7
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core
  • include/linux/mlx5

2 files changed

+26
-7
lines changed

drivers/net/ethernet/mellanox/mlx5/core/cmd.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,8 @@ static void cmd_work_handler(struct work_struct *work)
785785
struct mlx5_cmd_layout *lay;
786786
struct semaphore *sem;
787787
unsigned long flags;
788+
bool poll_cmd = ent->polling;
789+
788790

789791
sem = ent->page_queue ? &cmd->pages_sem : &cmd->sem;
790792
down(sem);
@@ -845,7 +847,7 @@ static void cmd_work_handler(struct work_struct *work)
845847
iowrite32be(1 << ent->idx, &dev->iseg->cmd_dbell);
846848
mmiowb();
847849
/* if not in polling don't use ent after this point */
848-
if (cmd->mode == CMD_MODE_POLLING) {
850+
if (cmd->mode == CMD_MODE_POLLING || poll_cmd) {
849851
poll_timeout(ent);
850852
/* make sure we read the descriptor after ownership is SW */
851853
rmb();
@@ -889,7 +891,7 @@ static int wait_func(struct mlx5_core_dev *dev, struct mlx5_cmd_work_ent *ent)
889891
struct mlx5_cmd *cmd = &dev->cmd;
890892
int err;
891893

892-
if (cmd->mode == CMD_MODE_POLLING) {
894+
if (cmd->mode == CMD_MODE_POLLING || ent->polling) {
893895
wait_for_completion(&ent->done);
894896
} else if (!wait_for_completion_timeout(&ent->done, timeout)) {
895897
ent->ret = -ETIMEDOUT;
@@ -917,7 +919,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
917919
struct mlx5_cmd_msg *out, void *uout, int uout_size,
918920
mlx5_cmd_cbk_t callback,
919921
void *context, int page_queue, u8 *status,
920-
u8 token)
922+
u8 token, bool force_polling)
921923
{
922924
struct mlx5_cmd *cmd = &dev->cmd;
923925
struct mlx5_cmd_work_ent *ent;
@@ -935,6 +937,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
935937
return PTR_ERR(ent);
936938

937939
ent->token = token;
940+
ent->polling = force_polling;
938941

939942
if (!callback)
940943
init_completion(&ent->done);
@@ -1535,7 +1538,8 @@ static int is_manage_pages(void *in)
15351538
}
15361539

15371540
static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
1538-
int out_size, mlx5_cmd_cbk_t callback, void *context)
1541+
int out_size, mlx5_cmd_cbk_t callback, void *context,
1542+
bool force_polling)
15391543
{
15401544
struct mlx5_cmd_msg *inb;
15411545
struct mlx5_cmd_msg *outb;
@@ -1580,7 +1584,7 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
15801584
}
15811585

15821586
err = mlx5_cmd_invoke(dev, inb, outb, out, out_size, callback, context,
1583-
pages_queue, &status, token);
1587+
pages_queue, &status, token, force_polling);
15841588
if (err)
15851589
goto out_out;
15861590

@@ -1608,7 +1612,7 @@ int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
16081612
{
16091613
int err;
16101614

1611-
err = cmd_exec(dev, in, in_size, out, out_size, NULL, NULL);
1615+
err = cmd_exec(dev, in, in_size, out, out_size, NULL, NULL, false);
16121616
return err ? : mlx5_cmd_check(dev, in, out);
16131617
}
16141618
EXPORT_SYMBOL(mlx5_cmd_exec);
@@ -1617,10 +1621,22 @@ int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
16171621
void *out, int out_size, mlx5_cmd_cbk_t callback,
16181622
void *context)
16191623
{
1620-
return cmd_exec(dev, in, in_size, out, out_size, callback, context);
1624+
return cmd_exec(dev, in, in_size, out, out_size, callback, context,
1625+
false);
16211626
}
16221627
EXPORT_SYMBOL(mlx5_cmd_exec_cb);
16231628

1629+
int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
1630+
void *out, int out_size)
1631+
{
1632+
int err;
1633+
1634+
err = cmd_exec(dev, in, in_size, out, out_size, NULL, NULL, true);
1635+
1636+
return err ? : mlx5_cmd_check(dev, in, out);
1637+
}
1638+
EXPORT_SYMBOL(mlx5_cmd_exec_polling);
1639+
16241640
static void destroy_msg_cache(struct mlx5_core_dev *dev)
16251641
{
16261642
struct cmd_msg_cache *ch;

include/linux/mlx5/driver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ struct mlx5_cmd_work_ent {
817817
u64 ts1;
818818
u64 ts2;
819819
u16 op;
820+
bool polling;
820821
};
821822

822823
struct mlx5_pas {
@@ -915,6 +916,8 @@ int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
915916
int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
916917
void *out, int out_size, mlx5_cmd_cbk_t callback,
917918
void *context);
919+
int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
920+
void *out, int out_size);
918921
void mlx5_cmd_mbox_status(void *out, u8 *status, u32 *syndrome);
919922

920923
int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);

0 commit comments

Comments
 (0)