Skip to content

Commit ed644fa

Browse files
Moshe ShemeshSaeed Mahameed
authored andcommitted
net/mlx5: Refactor num of blocks in mailbox calculation
Get the logic that calculates the number of blocks in a command mailbox into a dedicated function. Signed-off-by: Moshe Shemesh <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent d034294 commit ed644fa

File tree

1 file changed

+12
-12
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ static struct mlx5_cmd_layout *get_inst(struct mlx5_cmd *cmd, int idx)
135135
return cmd->cmd_buf + (idx << cmd->log_stride);
136136
}
137137

138+
static int mlx5_calc_cmd_blocks(struct mlx5_cmd_msg *msg)
139+
{
140+
int size = msg->len;
141+
int blen = size - min_t(int, sizeof(msg->first.data), size);
142+
143+
return DIV_ROUND_UP(blen, MLX5_CMD_DATA_BLOCK_SIZE);
144+
}
145+
138146
static u8 xor8_buf(void *buf, size_t offset, int len)
139147
{
140148
u8 *ptr = buf;
@@ -174,10 +182,7 @@ static void calc_block_sig(struct mlx5_cmd_prot_block *block)
174182
static void calc_chain_sig(struct mlx5_cmd_msg *msg)
175183
{
176184
struct mlx5_cmd_mailbox *next = msg->next;
177-
int size = msg->len;
178-
int blen = size - min_t(int, sizeof(msg->first.data), size);
179-
int n = (blen + MLX5_CMD_DATA_BLOCK_SIZE - 1)
180-
/ MLX5_CMD_DATA_BLOCK_SIZE;
185+
int n = mlx5_calc_cmd_blocks(msg);
181186
int i = 0;
182187

183188
for (i = 0; i < n && next; i++) {
@@ -220,12 +225,9 @@ static void free_cmd(struct mlx5_cmd_work_ent *ent)
220225
static int verify_signature(struct mlx5_cmd_work_ent *ent)
221226
{
222227
struct mlx5_cmd_mailbox *next = ent->out->next;
228+
int n = mlx5_calc_cmd_blocks(ent->out);
223229
int err;
224230
u8 sig;
225-
int size = ent->out->len;
226-
int blen = size - min_t(int, sizeof(ent->out->first.data), size);
227-
int n = (blen + MLX5_CMD_DATA_BLOCK_SIZE - 1)
228-
/ MLX5_CMD_DATA_BLOCK_SIZE;
229231
int i = 0;
230232

231233
sig = xor8_buf(ent->lay, 0, sizeof(*ent->lay));
@@ -1137,7 +1139,6 @@ static struct mlx5_cmd_msg *mlx5_alloc_cmd_msg(struct mlx5_core_dev *dev,
11371139
struct mlx5_cmd_mailbox *tmp, *head = NULL;
11381140
struct mlx5_cmd_prot_block *block;
11391141
struct mlx5_cmd_msg *msg;
1140-
int blen;
11411142
int err;
11421143
int n;
11431144
int i;
@@ -1146,8 +1147,8 @@ static struct mlx5_cmd_msg *mlx5_alloc_cmd_msg(struct mlx5_core_dev *dev,
11461147
if (!msg)
11471148
return ERR_PTR(-ENOMEM);
11481149

1149-
blen = size - min_t(int, sizeof(msg->first.data), size);
1150-
n = (blen + MLX5_CMD_DATA_BLOCK_SIZE - 1) / MLX5_CMD_DATA_BLOCK_SIZE;
1150+
msg->len = size;
1151+
n = mlx5_calc_cmd_blocks(msg);
11511152

11521153
for (i = 0; i < n; i++) {
11531154
tmp = alloc_cmd_box(dev, flags);
@@ -1165,7 +1166,6 @@ static struct mlx5_cmd_msg *mlx5_alloc_cmd_msg(struct mlx5_core_dev *dev,
11651166
head = tmp;
11661167
}
11671168
msg->next = head;
1168-
msg->len = size;
11691169
return msg;
11701170

11711171
err_alloc:

0 commit comments

Comments
 (0)