Skip to content

Commit 55e84c3

Browse files
Danielmachondavem330
authored andcommitted
net: sparx5: use contiguous memory for tx buffers
Currently, the driver uses a linked list for storing the tx buffer addresses. This requires a good amount of extra bookkeeping code. Ditch the linked list in favor of tx buffers being in the same contiguous memory space as the DCB's and the DB's. The FDMA library has a helper for this - so use that. The tx buffer addresses are now retrieved as an offset into the FDMA memory space. Signed-off-by: Daniel Machon <[email protected]> Reviewed-by: Steen Hegelund <[email protected]> Reviewed-by: Jens Emil Schulz Østergaard <[email protected]> Reviewed-by: Horatiu Vultur <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bb7a60d commit 55e84c3

File tree

2 files changed

+13
-45
lines changed

2 files changed

+13
-45
lines changed

drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,11 @@
2424
#define FDMA_XTR_BUFFER_SIZE 2048
2525
#define FDMA_WEIGHT 4
2626

27-
/* For each hardware DB there is an entry in this list and when the HW DB
28-
* entry is used, this SW DB entry is moved to the back of the list
29-
*/
30-
struct sparx5_db {
31-
struct list_head list;
32-
void *cpu_addr;
33-
};
34-
3527
static int sparx5_fdma_tx_dataptr_cb(struct fdma *fdma, int dcb, int db,
3628
u64 *dataptr)
3729
{
38-
struct sparx5 *sparx5 = fdma->priv;
39-
struct sparx5_tx *tx = &sparx5->tx;
40-
struct sparx5_db *db_buf;
41-
42-
db_buf = list_first_entry(&tx->db_list, struct sparx5_db, list);
43-
list_move_tail(&db_buf->list, &tx->db_list);
44-
45-
*dataptr = virt_to_phys(db_buf->cpu_addr);
30+
*dataptr = fdma->dma + (sizeof(struct fdma_dcb) * fdma->n_dcbs) +
31+
((dcb * fdma->n_dbs + db) * fdma->db_size);
4632

4733
return 0;
4834
}
@@ -236,15 +222,19 @@ int sparx5_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb)
236222
struct sparx5_tx *tx = &sparx5->tx;
237223
struct fdma *fdma = &tx->fdma;
238224
static bool first_time = true;
239-
struct sparx5_db *db;
225+
void *virt_addr;
240226

241227
fdma_dcb_advance(fdma);
242228
if (!fdma_db_is_done(fdma_db_get(fdma, fdma->dcb_index, 0)))
243229
return -EINVAL;
244-
db = list_first_entry(&tx->db_list, struct sparx5_db, list);
245-
memset(db->cpu_addr, 0, FDMA_XTR_BUFFER_SIZE);
246-
memcpy(db->cpu_addr, ifh, IFH_LEN * 4);
247-
memcpy(db->cpu_addr + IFH_LEN * 4, skb->data, skb->len);
230+
231+
/* Get the virtual address of the dataptr for the next DB */
232+
virt_addr = ((u8 *)fdma->dcbs +
233+
(sizeof(struct fdma_dcb) * fdma->n_dcbs) +
234+
((fdma->dcb_index * fdma->n_dbs) * fdma->db_size));
235+
236+
memcpy(virt_addr, ifh, IFH_LEN * 4);
237+
memcpy(virt_addr + IFH_LEN * 4, skb->data, skb->len);
248238

249239
fdma_dcb_add(fdma, fdma->dcb_index, 0,
250240
FDMA_DCB_STATUS_SOF |
@@ -285,28 +275,7 @@ static int sparx5_fdma_tx_alloc(struct sparx5 *sparx5)
285275
{
286276
struct sparx5_tx *tx = &sparx5->tx;
287277
struct fdma *fdma = &tx->fdma;
288-
int idx, jdx, err;
289-
290-
INIT_LIST_HEAD(&tx->db_list);
291-
/* Now for each dcb allocate the db */
292-
for (idx = 0; idx < fdma->n_dcbs; ++idx) {
293-
/* TX databuffers must be 16byte aligned */
294-
for (jdx = 0; jdx < fdma->n_dbs; ++jdx) {
295-
struct sparx5_db *db;
296-
void *cpu_addr;
297-
298-
cpu_addr = devm_kzalloc(sparx5->dev,
299-
FDMA_XTR_BUFFER_SIZE,
300-
GFP_KERNEL);
301-
if (!cpu_addr)
302-
return -ENOMEM;
303-
db = devm_kzalloc(sparx5->dev, sizeof(*db), GFP_KERNEL);
304-
if (!db)
305-
return -ENOMEM;
306-
db->cpu_addr = cpu_addr;
307-
list_add_tail(&db->list, &tx->db_list);
308-
}
309-
}
278+
int err;
310279

311280
err = fdma_alloc_phys(fdma);
312281
if (err)
@@ -353,7 +322,7 @@ static void sparx5_fdma_tx_init(struct sparx5 *sparx5,
353322
fdma->n_dbs = FDMA_TX_DCB_MAX_DBS;
354323
fdma->priv = sparx5;
355324
fdma->db_size = ALIGN(FDMA_XTR_BUFFER_SIZE, PAGE_SIZE);
356-
fdma->size = fdma_get_size(&sparx5->tx.fdma);
325+
fdma->size = fdma_get_size_contiguous(&sparx5->tx.fdma);
357326
fdma->ops.dataptr_cb = &sparx5_fdma_tx_dataptr_cb;
358327
fdma->ops.nextptr_cb = &fdma_nextptr_cb;
359328
}

drivers/net/ethernet/microchip/sparx5/sparx5_main.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ struct sparx5_rx {
122122
*/
123123
struct sparx5_tx {
124124
struct fdma fdma;
125-
struct list_head db_list;
126125
u64 packets;
127126
u64 dropped;
128127
};

0 commit comments

Comments
 (0)