2018-05-04 16:01:38 +07:00
|
|
|
// SPDX-License-Identifier: (GPL-2.0 OR MIT)
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Synopsys, Inc. and/or its affiliates.
|
|
|
|
* stmmac TC Handling (HW only)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <net/pkt_cls.h>
|
|
|
|
#include <net/tc_act/tc_gact.h>
|
|
|
|
#include "common.h"
|
|
|
|
#include "dwmac4.h"
|
|
|
|
#include "dwmac5.h"
|
|
|
|
#include "stmmac.h"
|
|
|
|
|
|
|
|
static void tc_fill_all_pass_entry(struct stmmac_tc_entry *entry)
|
|
|
|
{
|
|
|
|
memset(entry, 0, sizeof(*entry));
|
|
|
|
entry->in_use = true;
|
|
|
|
entry->is_last = true;
|
|
|
|
entry->is_frag = false;
|
|
|
|
entry->prio = ~0x0;
|
|
|
|
entry->handle = 0;
|
|
|
|
entry->val.match_data = 0x0;
|
|
|
|
entry->val.match_en = 0x0;
|
|
|
|
entry->val.af = 1;
|
|
|
|
entry->val.dma_ch_no = 0x0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct stmmac_tc_entry *tc_find_entry(struct stmmac_priv *priv,
|
|
|
|
struct tc_cls_u32_offload *cls,
|
|
|
|
bool free)
|
|
|
|
{
|
|
|
|
struct stmmac_tc_entry *entry, *first = NULL, *dup = NULL;
|
|
|
|
u32 loc = cls->knode.handle;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->tc_entries_max; i++) {
|
|
|
|
entry = &priv->tc_entries[i];
|
|
|
|
if (!entry->in_use && !first && free)
|
|
|
|
first = entry;
|
2019-08-06 20:16:18 +07:00
|
|
|
if ((entry->handle == loc) && !free && !entry->is_frag)
|
2018-05-04 16:01:38 +07:00
|
|
|
dup = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dup)
|
|
|
|
return dup;
|
|
|
|
if (first) {
|
|
|
|
first->handle = loc;
|
|
|
|
first->in_use = true;
|
|
|
|
|
|
|
|
/* Reset HW values */
|
|
|
|
memset(&first->val, 0, sizeof(first->val));
|
|
|
|
}
|
|
|
|
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tc_fill_actions(struct stmmac_tc_entry *entry,
|
|
|
|
struct stmmac_tc_entry *frag,
|
|
|
|
struct tc_cls_u32_offload *cls)
|
|
|
|
{
|
|
|
|
struct stmmac_tc_entry *action_entry = entry;
|
|
|
|
const struct tc_action *act;
|
|
|
|
struct tcf_exts *exts;
|
2018-08-20 02:22:09 +07:00
|
|
|
int i;
|
2018-05-04 16:01:38 +07:00
|
|
|
|
|
|
|
exts = cls->knode.exts;
|
|
|
|
if (!tcf_exts_has_actions(exts))
|
|
|
|
return -EINVAL;
|
|
|
|
if (frag)
|
|
|
|
action_entry = frag;
|
|
|
|
|
2018-08-20 02:22:09 +07:00
|
|
|
tcf_exts_for_each_action(i, act, exts) {
|
2018-05-04 16:01:38 +07:00
|
|
|
/* Accept */
|
|
|
|
if (is_tcf_gact_ok(act)) {
|
|
|
|
action_entry->val.af = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Drop */
|
|
|
|
if (is_tcf_gact_shot(act)) {
|
|
|
|
action_entry->val.rf = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unsupported */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tc_fill_entry(struct stmmac_priv *priv,
|
|
|
|
struct tc_cls_u32_offload *cls)
|
|
|
|
{
|
|
|
|
struct stmmac_tc_entry *entry, *frag = NULL;
|
|
|
|
struct tc_u32_sel *sel = cls->knode.sel;
|
|
|
|
u32 off, data, mask, real_off, rem;
|
2019-08-16 08:24:09 +07:00
|
|
|
u32 prio = cls->common.prio << 16;
|
2018-05-04 16:01:38 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Only 1 match per entry */
|
|
|
|
if (sel->nkeys <= 0 || sel->nkeys > 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
off = sel->keys[0].off << sel->offshift;
|
|
|
|
data = sel->keys[0].val;
|
|
|
|
mask = sel->keys[0].mask;
|
|
|
|
|
|
|
|
switch (ntohs(cls->common.protocol)) {
|
|
|
|
case ETH_P_ALL:
|
|
|
|
break;
|
|
|
|
case ETH_P_IP:
|
|
|
|
off += ETH_HLEN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (off > priv->tc_off_max)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
real_off = off / 4;
|
|
|
|
rem = off % 4;
|
|
|
|
|
|
|
|
entry = tc_find_entry(priv, cls, true);
|
|
|
|
if (!entry)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (rem) {
|
|
|
|
frag = tc_find_entry(priv, cls, true);
|
|
|
|
if (!frag) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_unuse;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->frag_ptr = frag;
|
|
|
|
entry->val.match_en = (mask << (rem * 8)) &
|
|
|
|
GENMASK(31, rem * 8);
|
|
|
|
entry->val.match_data = (data << (rem * 8)) &
|
|
|
|
GENMASK(31, rem * 8);
|
|
|
|
entry->val.frame_offset = real_off;
|
|
|
|
entry->prio = prio;
|
|
|
|
|
|
|
|
frag->val.match_en = (mask >> (rem * 8)) &
|
|
|
|
GENMASK(rem * 8 - 1, 0);
|
|
|
|
frag->val.match_data = (data >> (rem * 8)) &
|
|
|
|
GENMASK(rem * 8 - 1, 0);
|
|
|
|
frag->val.frame_offset = real_off + 1;
|
|
|
|
frag->prio = prio;
|
|
|
|
frag->is_frag = true;
|
|
|
|
} else {
|
|
|
|
entry->frag_ptr = NULL;
|
|
|
|
entry->val.match_en = mask;
|
|
|
|
entry->val.match_data = data;
|
|
|
|
entry->val.frame_offset = real_off;
|
|
|
|
entry->prio = prio;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = tc_fill_actions(entry, frag, cls);
|
|
|
|
if (ret)
|
|
|
|
goto err_unuse;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_unuse:
|
|
|
|
if (frag)
|
|
|
|
frag->in_use = false;
|
|
|
|
entry->in_use = false;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tc_unfill_entry(struct stmmac_priv *priv,
|
|
|
|
struct tc_cls_u32_offload *cls)
|
|
|
|
{
|
|
|
|
struct stmmac_tc_entry *entry;
|
|
|
|
|
|
|
|
entry = tc_find_entry(priv, cls, false);
|
|
|
|
if (!entry)
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry->in_use = false;
|
|
|
|
if (entry->frag_ptr) {
|
|
|
|
entry = entry->frag_ptr;
|
|
|
|
entry->is_frag = false;
|
|
|
|
entry->in_use = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tc_config_knode(struct stmmac_priv *priv,
|
|
|
|
struct tc_cls_u32_offload *cls)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = tc_fill_entry(priv, cls);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = stmmac_rxp_config(priv, priv->hw->pcsr, priv->tc_entries,
|
|
|
|
priv->tc_entries_max);
|
|
|
|
if (ret)
|
|
|
|
goto err_unfill;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_unfill:
|
|
|
|
tc_unfill_entry(priv, cls);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tc_delete_knode(struct stmmac_priv *priv,
|
|
|
|
struct tc_cls_u32_offload *cls)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Set entry and fragments as not used */
|
|
|
|
tc_unfill_entry(priv, cls);
|
|
|
|
|
|
|
|
ret = stmmac_rxp_config(priv, priv->hw->pcsr, priv->tc_entries,
|
|
|
|
priv->tc_entries_max);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tc_setup_cls_u32(struct stmmac_priv *priv,
|
|
|
|
struct tc_cls_u32_offload *cls)
|
|
|
|
{
|
|
|
|
switch (cls->command) {
|
|
|
|
case TC_CLSU32_REPLACE_KNODE:
|
|
|
|
tc_unfill_entry(priv, cls);
|
|
|
|
/* Fall through */
|
|
|
|
case TC_CLSU32_NEW_KNODE:
|
|
|
|
return tc_config_knode(priv, cls);
|
|
|
|
case TC_CLSU32_DELETE_KNODE:
|
|
|
|
return tc_delete_knode(priv, cls);
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tc_init(struct stmmac_priv *priv)
|
|
|
|
{
|
|
|
|
struct dma_features *dma_cap = &priv->dma_cap;
|
|
|
|
unsigned int count;
|
|
|
|
|
|
|
|
if (!dma_cap->frpsel)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (dma_cap->frpbs) {
|
|
|
|
case 0x0:
|
|
|
|
priv->tc_off_max = 64;
|
|
|
|
break;
|
|
|
|
case 0x1:
|
|
|
|
priv->tc_off_max = 128;
|
|
|
|
break;
|
|
|
|
case 0x2:
|
|
|
|
priv->tc_off_max = 256;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dma_cap->frpes) {
|
|
|
|
case 0x0:
|
|
|
|
count = 64;
|
|
|
|
break;
|
|
|
|
case 0x1:
|
|
|
|
count = 128;
|
|
|
|
break;
|
|
|
|
case 0x2:
|
|
|
|
count = 256;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserve one last filter which lets all pass */
|
|
|
|
priv->tc_entries_max = count;
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:07:58 +07:00
|
|
|
priv->tc_entries = devm_kcalloc(priv->device,
|
|
|
|
count, sizeof(*priv->tc_entries), GFP_KERNEL);
|
2018-05-04 16:01:38 +07:00
|
|
|
if (!priv->tc_entries)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
tc_fill_all_pass_entry(&priv->tc_entries[count - 1]);
|
|
|
|
|
|
|
|
dev_info(priv->device, "Enabling HW TC (entries=%d, max_off=%d)\n",
|
|
|
|
priv->tc_entries_max, priv->tc_off_max);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-27 21:57:02 +07:00
|
|
|
static int tc_setup_cbs(struct stmmac_priv *priv,
|
|
|
|
struct tc_cbs_qopt_offload *qopt)
|
|
|
|
{
|
|
|
|
u32 tx_queues_count = priv->plat->tx_queues_to_use;
|
|
|
|
u32 queue = qopt->queue;
|
|
|
|
u32 ptr, speed_div;
|
|
|
|
u32 mode_to_use;
|
|
|
|
u64 value;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Queue 0 is not AVB capable */
|
|
|
|
if (queue <= 0 || queue >= tx_queues_count)
|
|
|
|
return -EINVAL;
|
2019-01-09 16:05:58 +07:00
|
|
|
if (!priv->dma_cap.av)
|
|
|
|
return -EOPNOTSUPP;
|
2018-06-27 21:57:02 +07:00
|
|
|
if (priv->speed != SPEED_100 && priv->speed != SPEED_1000)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
mode_to_use = priv->plat->tx_queues_cfg[queue].mode_to_use;
|
|
|
|
if (mode_to_use == MTL_QUEUE_DCB && qopt->enable) {
|
|
|
|
ret = stmmac_dma_qmode(priv, priv->ioaddr, queue, MTL_QUEUE_AVB);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
priv->plat->tx_queues_cfg[queue].mode_to_use = MTL_QUEUE_AVB;
|
|
|
|
} else if (!qopt->enable) {
|
|
|
|
return stmmac_dma_qmode(priv, priv->ioaddr, queue, MTL_QUEUE_DCB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Port Transmit Rate and Speed Divider */
|
|
|
|
ptr = (priv->speed == SPEED_100) ? 4 : 8;
|
|
|
|
speed_div = (priv->speed == SPEED_100) ? 100000 : 1000000;
|
|
|
|
|
|
|
|
/* Final adjustments for HW */
|
2018-07-06 20:36:07 +07:00
|
|
|
value = div_s64(qopt->idleslope * 1024ll * ptr, speed_div);
|
2018-06-27 21:57:02 +07:00
|
|
|
priv->plat->tx_queues_cfg[queue].idle_slope = value & GENMASK(31, 0);
|
|
|
|
|
2018-07-06 20:36:07 +07:00
|
|
|
value = div_s64(-qopt->sendslope * 1024ll * ptr, speed_div);
|
2018-06-27 21:57:02 +07:00
|
|
|
priv->plat->tx_queues_cfg[queue].send_slope = value & GENMASK(31, 0);
|
|
|
|
|
2018-07-06 20:36:07 +07:00
|
|
|
value = qopt->hicredit * 1024ll * 8;
|
2018-06-27 21:57:02 +07:00
|
|
|
priv->plat->tx_queues_cfg[queue].high_credit = value & GENMASK(31, 0);
|
|
|
|
|
2018-07-06 20:36:07 +07:00
|
|
|
value = qopt->locredit * 1024ll * 8;
|
2018-06-27 21:57:02 +07:00
|
|
|
priv->plat->tx_queues_cfg[queue].low_credit = value & GENMASK(31, 0);
|
|
|
|
|
|
|
|
ret = stmmac_config_cbs(priv, priv->hw,
|
|
|
|
priv->plat->tx_queues_cfg[queue].send_slope,
|
|
|
|
priv->plat->tx_queues_cfg[queue].idle_slope,
|
|
|
|
priv->plat->tx_queues_cfg[queue].high_credit,
|
|
|
|
priv->plat->tx_queues_cfg[queue].low_credit,
|
|
|
|
queue);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
dev_info(priv->device, "CBS queue %d: send %d, idle %d, hi %d, lo %d\n",
|
|
|
|
queue, qopt->sendslope, qopt->idleslope,
|
|
|
|
qopt->hicredit, qopt->locredit);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-04 16:01:38 +07:00
|
|
|
const struct stmmac_tc_ops dwmac510_tc_ops = {
|
|
|
|
.init = tc_init,
|
|
|
|
.setup_cls_u32 = tc_setup_cls_u32,
|
2018-06-27 21:57:02 +07:00
|
|
|
.setup_cbs = tc_setup_cbs,
|
2018-05-04 16:01:38 +07:00
|
|
|
};
|