Skip to content

Commit a4a1139

Browse files
abrodkindavem330
authored andcommitted
arc_emac: fix compile-time errors & warnings on PPC64
As reported by "kbuild test robot" there were some errors and warnings on attempt to build kernel with "make ARCH=powerpc allmodconfig". And this patch addresses both errors and warnings. Below is a list of introduced changes: 1. Fix compile-time errors (misspellings in "dma_unmap_single") on PPC. 2. Use DMA address instead of "skb->data" as a pointer to data buffer. This fixed warnings on pointer to int conversion on 64-bit systems. 3. Re-implemented initial allocation of Rx buffers in "arc_emac_open" in the same way they're re-allocated during operation (receiving packets). So once again DMA address could be used instead of "skb->data". 4. Explicitly use EMAC_BUFFER_SIZE for Rx buffers allocation. Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com> Cc: netdev@vger.kernel.org Cc: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: Francois Romieu <romieu@fr.zoreil.com> Cc: Joe Perches <joe@perches.com> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Mischa Jonker <mjonker@synopsys.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Grant Likely <grant.likely@linaro.org> Cc: Rob Herring <rob.herring@calxeda.com> Cc: Paul Gortmaker <paul.gortmaker@windriver.com> Cc: linux-kernel@vger.kernel.org Cc: devicetree-discuss@lists.ozlabs.org Cc: Florian Fainelli <florian@openwrt.org> Cc: David Laight <david.laight@aculab.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8599b52 commit a4a1139

1 file changed

Lines changed: 39 additions & 26 deletions

File tree

‎drivers/net/ethernet/arc/emac_main.c‎

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ static void arc_emac_tx_clean(struct net_device *ndev)
171171
stats->tx_bytes += skb->len;
172172
}
173173

174-
dma_unmap_single(&ndev->dev, dma_unmap_addr(&tx_buff, addr),
175-
dma_unmap_len(&tx_buff, len), DMA_TO_DEVICE);
174+
dma_unmap_single(&ndev->dev, dma_unmap_addr(tx_buff, addr),
175+
dma_unmap_len(tx_buff, len), DMA_TO_DEVICE);
176176

177177
/* return the sk_buff to system */
178178
dev_kfree_skb_irq(skb);
@@ -204,7 +204,6 @@ static int arc_emac_rx(struct net_device *ndev, int budget)
204204
struct net_device_stats *stats = &priv->stats;
205205
struct buffer_state *rx_buff = &priv->rx_buff[*last_rx_bd];
206206
struct arc_emac_bd *rxbd = &priv->rxbd[*last_rx_bd];
207-
unsigned int buflen = EMAC_BUFFER_SIZE;
208207
unsigned int pktlen, info = le32_to_cpu(rxbd->info);
209208
struct sk_buff *skb;
210209
dma_addr_t addr;
@@ -226,7 +225,7 @@ static int arc_emac_rx(struct net_device *ndev, int budget)
226225
netdev_err(ndev, "incomplete packet received\n");
227226

228227
/* Return ownership to EMAC */
229-
rxbd->info = cpu_to_le32(FOR_EMAC | buflen);
228+
rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
230229
stats->rx_errors++;
231230
stats->rx_length_errors++;
232231
continue;
@@ -240,11 +239,12 @@ static int arc_emac_rx(struct net_device *ndev, int budget)
240239
skb->dev = ndev;
241240
skb->protocol = eth_type_trans(skb, ndev);
242241

243-
dma_unmap_single(&ndev->dev, dma_unmap_addr(&rx_buff, addr),
244-
dma_unmap_len(&rx_buff, len), DMA_FROM_DEVICE);
242+
dma_unmap_single(&ndev->dev, dma_unmap_addr(rx_buff, addr),
243+
dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE);
245244

246245
/* Prepare the BD for next cycle */
247-
rx_buff->skb = netdev_alloc_skb_ip_align(ndev, buflen);
246+
rx_buff->skb = netdev_alloc_skb_ip_align(ndev,
247+
EMAC_BUFFER_SIZE);
248248
if (unlikely(!rx_buff->skb)) {
249249
stats->rx_errors++;
250250
/* Because receive_skb is below, increment rx_dropped */
@@ -256,24 +256,24 @@ static int arc_emac_rx(struct net_device *ndev, int budget)
256256
netif_receive_skb(skb);
257257

258258
addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data,
259-
buflen, DMA_FROM_DEVICE);
259+
EMAC_BUFFER_SIZE, DMA_FROM_DEVICE);
260260
if (dma_mapping_error(&ndev->dev, addr)) {
261261
if (net_ratelimit())
262262
netdev_err(ndev, "cannot dma map\n");
263263
dev_kfree_skb(rx_buff->skb);
264264
stats->rx_errors++;
265265
continue;
266266
}
267-
dma_unmap_addr_set(&rx_buff, mapping, addr);
268-
dma_unmap_len_set(&rx_buff, len, buflen);
267+
dma_unmap_addr_set(rx_buff, addr, addr);
268+
dma_unmap_len_set(rx_buff, len, EMAC_BUFFER_SIZE);
269269

270-
rxbd->data = cpu_to_le32(rx_buff->skb->data);
270+
rxbd->data = cpu_to_le32(addr);
271271

272272
/* Make sure pointer to data buffer is set */
273273
wmb();
274274

275275
/* Return ownership to EMAC */
276-
rxbd->info = cpu_to_le32(FOR_EMAC | buflen);
276+
rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
277277
}
278278

279279
return work_done;
@@ -376,8 +376,6 @@ static int arc_emac_open(struct net_device *ndev)
376376
{
377377
struct arc_emac_priv *priv = netdev_priv(ndev);
378378
struct phy_device *phy_dev = priv->phy_dev;
379-
struct arc_emac_bd *bd;
380-
struct sk_buff *skb;
381379
int i;
382380

383381
phy_dev->autoneg = AUTONEG_ENABLE;
@@ -395,25 +393,40 @@ static int arc_emac_open(struct net_device *ndev)
395393
}
396394
}
397395

396+
priv->last_rx_bd = 0;
397+
398398
/* Allocate and set buffers for Rx BD's */
399-
bd = priv->rxbd;
400399
for (i = 0; i < RX_BD_NUM; i++) {
401-
skb = netdev_alloc_skb_ip_align(ndev, EMAC_BUFFER_SIZE);
402-
if (unlikely(!skb))
400+
dma_addr_t addr;
401+
unsigned int *last_rx_bd = &priv->last_rx_bd;
402+
struct arc_emac_bd *rxbd = &priv->rxbd[*last_rx_bd];
403+
struct buffer_state *rx_buff = &priv->rx_buff[*last_rx_bd];
404+
405+
rx_buff->skb = netdev_alloc_skb_ip_align(ndev,
406+
EMAC_BUFFER_SIZE);
407+
if (unlikely(!rx_buff->skb))
408+
return -ENOMEM;
409+
410+
addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data,
411+
EMAC_BUFFER_SIZE, DMA_FROM_DEVICE);
412+
if (dma_mapping_error(&ndev->dev, addr)) {
413+
netdev_err(ndev, "cannot dma map\n");
414+
dev_kfree_skb(rx_buff->skb);
403415
return -ENOMEM;
416+
}
417+
dma_unmap_addr_set(rx_buff, addr, addr);
418+
dma_unmap_len_set(rx_buff, len, EMAC_BUFFER_SIZE);
404419

405-
priv->rx_buff[i].skb = skb;
406-
bd->data = cpu_to_le32(skb->data);
420+
rxbd->data = cpu_to_le32(addr);
407421

408422
/* Make sure pointer to data buffer is set */
409423
wmb();
410424

411-
/* Set ownership to EMAC */
412-
bd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
413-
bd++;
414-
}
425+
/* Return ownership to EMAC */
426+
rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
415427

416-
priv->last_rx_bd = 0;
428+
*last_rx_bd = (*last_rx_bd + 1) % RX_BD_NUM;
429+
}
417430

418431
/* Clean Tx BD's */
419432
memset(priv->txbd, 0, TX_RING_SZ);
@@ -543,11 +556,11 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
543556
dev_kfree_skb(skb);
544557
return NETDEV_TX_OK;
545558
}
546-
dma_unmap_addr_set(&priv->tx_buff[*txbd_curr], mapping, addr);
559+
dma_unmap_addr_set(&priv->tx_buff[*txbd_curr], addr, addr);
547560
dma_unmap_len_set(&priv->tx_buff[*txbd_curr], len, len);
548561

549562
priv->tx_buff[*txbd_curr].skb = skb;
550-
priv->txbd[*txbd_curr].data = cpu_to_le32(skb->data);
563+
priv->txbd[*txbd_curr].data = cpu_to_le32(addr);
551564

552565
/* Make sure pointer to data buffer is set */
553566
wmb();

0 commit comments

Comments
 (0)