Commit 0cc11cdb authored by Po Liu's avatar Po Liu Committed by David S. Miller

net:enetc: command BD ring data memory alloc as one function alone

Separate the CBDR data memory alloc standalone. It is convenient for
other part loading, for example the ENETC QOS part.
Reported-and-suggested-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarPo Liu <po.liu@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b3a723db
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#define ENETC_MAX_MTU (ENETC_MAC_MAXFRM_SIZE - \ #define ENETC_MAX_MTU (ENETC_MAC_MAXFRM_SIZE - \
(ETH_FCS_LEN + ETH_HLEN + VLAN_HLEN)) (ETH_FCS_LEN + ETH_HLEN + VLAN_HLEN))
#define ENETC_CBD_DATA_MEM_ALIGN 64
struct enetc_tx_swbd { struct enetc_tx_swbd {
union { union {
struct sk_buff *skb; struct sk_buff *skb;
...@@ -415,6 +417,42 @@ int enetc_get_rss_table(struct enetc_si *si, u32 *table, int count); ...@@ -415,6 +417,42 @@ int enetc_get_rss_table(struct enetc_si *si, u32 *table, int count);
int enetc_set_rss_table(struct enetc_si *si, const u32 *table, int count); int enetc_set_rss_table(struct enetc_si *si, const u32 *table, int count);
int enetc_send_cmd(struct enetc_si *si, struct enetc_cbd *cbd); int enetc_send_cmd(struct enetc_si *si, struct enetc_cbd *cbd);
static inline void *enetc_cbd_alloc_data_mem(struct enetc_si *si,
struct enetc_cbd *cbd,
int size, dma_addr_t *dma,
void **data_align)
{
struct enetc_cbdr *ring = &si->cbd_ring;
dma_addr_t dma_align;
void *data;
data = dma_alloc_coherent(ring->dma_dev,
size + ENETC_CBD_DATA_MEM_ALIGN,
dma, GFP_KERNEL);
if (!data) {
dev_err(ring->dma_dev, "CBD alloc data memory failed!\n");
return NULL;
}
dma_align = ALIGN(*dma, ENETC_CBD_DATA_MEM_ALIGN);
*data_align = PTR_ALIGN(data, ENETC_CBD_DATA_MEM_ALIGN);
cbd->addr[0] = cpu_to_le32(lower_32_bits(dma_align));
cbd->addr[1] = cpu_to_le32(upper_32_bits(dma_align));
cbd->length = cpu_to_le16(size);
return data;
}
static inline void enetc_cbd_free_data_mem(struct enetc_si *si, int size,
void *data, dma_addr_t *dma)
{
struct enetc_cbdr *ring = &si->cbd_ring;
dma_free_coherent(ring->dma_dev, size + ENETC_CBD_DATA_MEM_ALIGN,
data, *dma);
}
#ifdef CONFIG_FSL_ENETC_QOS #ifdef CONFIG_FSL_ENETC_QOS
int enetc_setup_tc_taprio(struct net_device *ndev, void *type_data); int enetc_setup_tc_taprio(struct net_device *ndev, void *type_data);
void enetc_sched_speed_set(struct enetc_ndev_priv *priv, int speed); void enetc_sched_speed_set(struct enetc_ndev_priv *priv, int speed);
......
...@@ -166,70 +166,55 @@ int enetc_set_mac_flt_entry(struct enetc_si *si, int index, ...@@ -166,70 +166,55 @@ int enetc_set_mac_flt_entry(struct enetc_si *si, int index,
return enetc_send_cmd(si, &cbd); return enetc_send_cmd(si, &cbd);
} }
#define RFSE_ALIGN 64
/* Set entry in RFS table */ /* Set entry in RFS table */
int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse, int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse,
int index) int index)
{ {
struct enetc_cbdr *ring = &si->cbd_ring; struct enetc_cbdr *ring = &si->cbd_ring;
struct enetc_cbd cbd = {.cmd = 0}; struct enetc_cbd cbd = {.cmd = 0};
dma_addr_t dma, dma_align;
void *tmp, *tmp_align; void *tmp, *tmp_align;
dma_addr_t dma;
int err; int err;
/* fill up the "set" descriptor */ /* fill up the "set" descriptor */
cbd.cmd = 0; cbd.cmd = 0;
cbd.cls = 4; cbd.cls = 4;
cbd.index = cpu_to_le16(index); cbd.index = cpu_to_le16(index);
cbd.length = cpu_to_le16(sizeof(*rfse));
cbd.opt[3] = cpu_to_le32(0); /* SI */ cbd.opt[3] = cpu_to_le32(0); /* SI */
tmp = dma_alloc_coherent(ring->dma_dev, sizeof(*rfse) + RFSE_ALIGN, tmp = enetc_cbd_alloc_data_mem(si, &cbd, sizeof(*rfse),
&dma, GFP_KERNEL); &dma, &tmp_align);
if (!tmp) { if (!tmp)
dev_err(ring->dma_dev, "DMA mapping of RFS entry failed!\n");
return -ENOMEM; return -ENOMEM;
}
dma_align = ALIGN(dma, RFSE_ALIGN);
tmp_align = PTR_ALIGN(tmp, RFSE_ALIGN);
memcpy(tmp_align, rfse, sizeof(*rfse)); memcpy(tmp_align, rfse, sizeof(*rfse));
cbd.addr[0] = cpu_to_le32(lower_32_bits(dma_align));
cbd.addr[1] = cpu_to_le32(upper_32_bits(dma_align));
err = enetc_send_cmd(si, &cbd); err = enetc_send_cmd(si, &cbd);
if (err) if (err)
dev_err(ring->dma_dev, "FS entry add failed (%d)!", err); dev_err(ring->dma_dev, "FS entry add failed (%d)!", err);
dma_free_coherent(ring->dma_dev, sizeof(*rfse) + RFSE_ALIGN, enetc_cbd_free_data_mem(si, sizeof(*rfse), tmp, &dma);
tmp, dma);
return err; return err;
} }
#define RSSE_ALIGN 64
static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count, static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count,
bool read) bool read)
{ {
struct enetc_cbdr *ring = &si->cbd_ring; struct enetc_cbdr *ring = &si->cbd_ring;
struct enetc_cbd cbd = {.cmd = 0}; struct enetc_cbd cbd = {.cmd = 0};
dma_addr_t dma, dma_align;
u8 *tmp, *tmp_align; u8 *tmp, *tmp_align;
dma_addr_t dma;
int err, i; int err, i;
if (count < RSSE_ALIGN) if (count < ENETC_CBD_DATA_MEM_ALIGN)
/* HW only takes in a full 64 entry table */ /* HW only takes in a full 64 entry table */
return -EINVAL; return -EINVAL;
tmp = dma_alloc_coherent(ring->dma_dev, count + RSSE_ALIGN, tmp = enetc_cbd_alloc_data_mem(si, &cbd, count,
&dma, GFP_KERNEL); &dma, (void *)&tmp_align);
if (!tmp) { if (!tmp)
dev_err(ring->dma_dev, "DMA mapping of RSS table failed!\n");
return -ENOMEM; return -ENOMEM;
}
dma_align = ALIGN(dma, RSSE_ALIGN);
tmp_align = PTR_ALIGN(tmp, RSSE_ALIGN);
if (!read) if (!read)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
...@@ -238,10 +223,6 @@ static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count, ...@@ -238,10 +223,6 @@ static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count,
/* fill up the descriptor */ /* fill up the descriptor */
cbd.cmd = read ? 2 : 1; cbd.cmd = read ? 2 : 1;
cbd.cls = 3; cbd.cls = 3;
cbd.length = cpu_to_le16(count);
cbd.addr[0] = cpu_to_le32(lower_32_bits(dma_align));
cbd.addr[1] = cpu_to_le32(upper_32_bits(dma_align));
err = enetc_send_cmd(si, &cbd); err = enetc_send_cmd(si, &cbd);
if (err) if (err)
...@@ -251,7 +232,7 @@ static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count, ...@@ -251,7 +232,7 @@ static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count,
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
table[i] = tmp_align[i]; table[i] = tmp_align[i];
dma_free_coherent(ring->dma_dev, count + RSSE_ALIGN, tmp, dma); enetc_cbd_free_data_mem(si, count, tmp, &dma);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment