forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/ethernet/toshiba/ps3_gelic_net.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * PS3 gelic network driver.
34 *
....@@ -10,20 +11,6 @@
1011 *
1112 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
1213 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
13
- *
14
- * This program is free software; you can redistribute it and/or modify
15
- * it under the terms of the GNU General Public License as published by
16
- * the Free Software Foundation; either version 2, or (at your option)
17
- * any later version.
18
- *
19
- * This program is distributed in the hope that it will be useful,
20
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
- * GNU General Public License for more details.
23
- *
24
- * You should have received a copy of the GNU General Public License
25
- * along with this program; if not, write to the Free Software
26
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2714 */
2815
2916 #undef DEBUG
....@@ -330,15 +317,17 @@
330317
331318 /* set up the hardware pointers in each descriptor */
332319 for (i = 0; i < no; i++, descr++) {
333
- gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
334
- descr->bus_addr =
335
- dma_map_single(ctodev(card), descr,
336
- GELIC_DESCR_SIZE,
337
- DMA_BIDIRECTIONAL);
320
+ dma_addr_t cpu_addr;
338321
339
- if (!descr->bus_addr)
322
+ gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
323
+
324
+ cpu_addr = dma_map_single(ctodev(card), descr,
325
+ GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
326
+
327
+ if (dma_mapping_error(ctodev(card), cpu_addr))
340328 goto iommu_error;
341329
330
+ descr->bus_addr = cpu_to_be32(cpu_addr);
342331 descr->next = descr + 1;
343332 descr->prev = descr - 1;
344333 }
....@@ -378,28 +367,28 @@
378367 *
379368 * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
380369 * Activate the descriptor state-wise
370
+ *
371
+ * Gelic RX sk_buffs must be aligned to GELIC_NET_RXBUF_ALIGN and the length
372
+ * must be a multiple of GELIC_NET_RXBUF_ALIGN.
381373 */
382374 static int gelic_descr_prepare_rx(struct gelic_card *card,
383375 struct gelic_descr *descr)
384376 {
377
+ static const unsigned int rx_skb_size =
378
+ ALIGN(GELIC_NET_MAX_FRAME, GELIC_NET_RXBUF_ALIGN) +
379
+ GELIC_NET_RXBUF_ALIGN - 1;
380
+ dma_addr_t cpu_addr;
385381 int offset;
386
- unsigned int bufsize;
387382
388383 if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE)
389384 dev_info(ctodev(card), "%s: ERROR status\n", __func__);
390
- /* we need to round up the buffer size to a multiple of 128 */
391
- bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
392385
393
- /* and we need to have it 128 byte aligned, therefore we allocate a
394
- * bit more */
395
- descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
386
+ descr->skb = netdev_alloc_skb(*card->netdev, rx_skb_size);
396387 if (!descr->skb) {
397388 descr->buf_addr = 0; /* tell DMAC don't touch memory */
398
- dev_info(ctodev(card),
399
- "%s:allocate skb failed !!\n", __func__);
400389 return -ENOMEM;
401390 }
402
- descr->buf_size = cpu_to_be32(bufsize);
391
+ descr->buf_size = cpu_to_be32(rx_skb_size);
403392 descr->dmac_cmd_status = 0;
404393 descr->result_size = 0;
405394 descr->valid_size = 0;
....@@ -410,11 +399,10 @@
410399 if (offset)
411400 skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
412401 /* io-mmu-map the skb */
413
- descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
414
- descr->skb->data,
415
- GELIC_NET_MAX_MTU,
416
- DMA_FROM_DEVICE));
417
- if (!descr->buf_addr) {
402
+ cpu_addr = dma_map_single(ctodev(card), descr->skb->data,
403
+ GELIC_NET_MAX_FRAME, DMA_FROM_DEVICE);
404
+ descr->buf_addr = cpu_to_be32(cpu_addr);
405
+ if (dma_mapping_error(ctodev(card), cpu_addr)) {
418406 dev_kfree_skb_any(descr->skb);
419407 descr->skb = NULL;
420408 dev_info(ctodev(card),
....@@ -794,7 +782,7 @@
794782
795783 buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
796784
797
- if (!buf) {
785
+ if (dma_mapping_error(ctodev(card), buf)) {
798786 dev_err(ctodev(card),
799787 "dma map 2 failed (%p, %i). Dropping packet\n",
800788 skb->data, skb->len);
....@@ -930,7 +918,7 @@
930918 data_error = be32_to_cpu(descr->data_error);
931919 /* unmap skb buffer */
932920 dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr),
933
- GELIC_NET_MAX_MTU,
921
+ GELIC_NET_MAX_FRAME,
934922 DMA_FROM_DEVICE);
935923
936924 skb_put(skb, be32_to_cpu(descr->valid_size)?
....@@ -1163,7 +1151,7 @@
11631151 * gelic_net_poll_controller - artificial interrupt for netconsole etc.
11641152 * @netdev: interface device structure
11651153 *
1166
- * see Documentation/networking/netconsole.txt
1154
+ * see Documentation/networking/netconsole.rst
11671155 */
11681156 void gelic_net_poll_controller(struct net_device *netdev)
11691157 {
....@@ -1418,7 +1406,7 @@
14181406 *
14191407 * called, if tx hangs. Schedules a task that resets the interface
14201408 */
1421
-void gelic_net_tx_timeout(struct net_device *netdev)
1409
+void gelic_net_tx_timeout(struct net_device *netdev, unsigned int txqueue)
14221410 {
14231411 struct gelic_card *card;
14241412