提交 cedca418 编写于 作者: L Linus Walleij 提交者: David S. Miller

net: gemini: Look up L3 maxlen from table

The code to calculate the hardware register enumerator
for the maximum L3 length isn't entirely simple to read.
Use the existing defines and rewrite the function into a
table look-up.
Acked-by: NMichał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 750c721e
...@@ -401,26 +401,57 @@ static int gmac_setup_phy(struct net_device *netdev) ...@@ -401,26 +401,57 @@ static int gmac_setup_phy(struct net_device *netdev)
return 0; return 0;
} }
static int gmac_pick_rx_max_len(int max_l3_len) /* The maximum frame length is not logically enumerated in the
{ * hardware, so we do a table lookup to find the applicable max
/* index = CONFIG_MAXLEN_XXX values */ * frame length.
static const int max_len[8] = { */
1536, 1518, 1522, 1542, struct gmac_max_framelen {
9212, 10236, 1518, 1518 unsigned int max_l3_len;
}; u8 val;
int i, n = 5; };
max_l3_len += ETH_HLEN + VLAN_HLEN; static const struct gmac_max_framelen gmac_maxlens[] = {
{
.max_l3_len = 1518,
.val = CONFIG0_MAXLEN_1518,
},
{
.max_l3_len = 1522,
.val = CONFIG0_MAXLEN_1522,
},
{
.max_l3_len = 1536,
.val = CONFIG0_MAXLEN_1536,
},
{
.max_l3_len = 1542,
.val = CONFIG0_MAXLEN_1542,
},
{
.max_l3_len = 9212,
.val = CONFIG0_MAXLEN_9k,
},
{
.max_l3_len = 10236,
.val = CONFIG0_MAXLEN_10k,
},
};
if (max_l3_len > max_len[n]) static int gmac_pick_rx_max_len(unsigned int max_l3_len)
return -1; {
const struct gmac_max_framelen *maxlen;
int maxtot;
int i;
for (i = 0; i < 5; i++) { maxtot = max_l3_len + ETH_HLEN + VLAN_HLEN;
if (max_len[i] >= max_l3_len && max_len[i] < max_len[n])
n = i; for (i = 0; i < ARRAY_SIZE(gmac_maxlens); i++) {
maxlen = &gmac_maxlens[i];
if (maxtot <= maxlen->max_l3_len)
return maxlen->val;
} }
return n; return -1;
} }
static int gmac_init(struct net_device *netdev) static int gmac_init(struct net_device *netdev)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册