1
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
- /*
3
- * Xilinx EmacLite Linux driver for the Xilinx Ethernet MAC Lite device.
2
+ /* Xilinx EmacLite Linux driver for the Xilinx Ethernet MAC Lite device.
4
3
*
5
4
* This is a new flat driver which is based on the original emac_lite
6
5
* driver from John Williams <[email protected] >.
7
6
*
8
- * 2007 - 2013 (c) Xilinx, Inc.
7
+ * Copyright (c) 2007 - 2013 Xilinx, Inc.
9
8
*/
10
9
11
10
#include <linux/module.h>
91
90
#define XEL_ARP_PACKET_SIZE 28 /* Max ARP packet size */
92
91
#define XEL_HEADER_IP_LENGTH_OFFSET 16 /* IP Length Offset */
93
92
94
-
95
-
96
93
#define TX_TIMEOUT (60 * HZ) /* Tx timeout is 60 seconds. */
97
- #define ALIGNMENT 4
98
-
99
- /* BUFFER_ALIGN(adr) calculates the number of bytes to the next alignment. */
100
- #define BUFFER_ALIGN (adr ) ((ALIGNMENT - ((uintptr_t)adr)) % ALIGNMENT)
101
94
102
95
#ifdef __BIG_ENDIAN
103
96
#define xemaclite_readl ioread32be
124
117
* @last_link: last link status
125
118
*/
126
119
struct net_local {
127
-
128
120
struct net_device * ndev ;
129
121
130
122
bool tx_ping_pong ;
@@ -133,7 +125,7 @@ struct net_local {
133
125
u32 next_rx_buf_to_use ;
134
126
void __iomem * base_addr ;
135
127
136
- spinlock_t reset_lock ;
128
+ spinlock_t reset_lock ; /* serialize xmit and tx_timeout execution */
137
129
struct sk_buff * deferred_skb ;
138
130
139
131
struct phy_device * phy_dev ;
@@ -144,7 +136,6 @@ struct net_local {
144
136
int last_link ;
145
137
};
146
138
147
-
148
139
/*************************/
149
140
/* EmacLite driver calls */
150
141
/*************************/
@@ -207,7 +198,7 @@ static void xemaclite_disable_interrupts(struct net_local *drvdata)
207
198
* address in the EmacLite device.
208
199
*/
209
200
static void xemaclite_aligned_write (const void * src_ptr , u32 * dest_ptr ,
210
- unsigned length )
201
+ unsigned int length )
211
202
{
212
203
const u16 * from_u16_ptr ;
213
204
u32 align_buffer ;
@@ -265,7 +256,7 @@ static void xemaclite_aligned_write(const void *src_ptr, u32 *dest_ptr,
265
256
* to a 16-bit aligned buffer.
266
257
*/
267
258
static void xemaclite_aligned_read (u32 * src_ptr , u8 * dest_ptr ,
268
- unsigned length )
259
+ unsigned int length )
269
260
{
270
261
u16 * to_u16_ptr , * from_u16_ptr ;
271
262
u32 * from_u32_ptr ;
@@ -330,7 +321,6 @@ static int xemaclite_send_data(struct net_local *drvdata, u8 *data,
330
321
reg_data = xemaclite_readl (addr + XEL_TSR_OFFSET );
331
322
if ((reg_data & (XEL_TSR_XMIT_BUSY_MASK |
332
323
XEL_TSR_XMIT_ACTIVE_MASK )) == 0 ) {
333
-
334
324
/* Switch to next buffer if configured */
335
325
if (drvdata -> tx_ping_pong != 0 )
336
326
drvdata -> next_tx_buf_to_use ^= XEL_BUFFER_OFFSET ;
@@ -346,8 +336,9 @@ static int xemaclite_send_data(struct net_local *drvdata, u8 *data,
346
336
if ((reg_data & (XEL_TSR_XMIT_BUSY_MASK |
347
337
XEL_TSR_XMIT_ACTIVE_MASK )) != 0 )
348
338
return -1 ; /* Buffers were full, return failure */
349
- } else
339
+ } else {
350
340
return -1 ; /* Buffer was full, return failure */
341
+ }
351
342
352
343
/* Write the frame to the buffer */
353
344
xemaclite_aligned_write (data , (u32 __force * )addr , byte_count );
@@ -423,7 +414,6 @@ static u16 xemaclite_recv_data(struct net_local *drvdata, u8 *data, int maxlen)
423
414
* or an IP packet or an ARP packet
424
415
*/
425
416
if (proto_type > ETH_DATA_LEN ) {
426
-
427
417
if (proto_type == ETH_P_IP ) {
428
418
length = ((ntohl (xemaclite_readl (addr +
429
419
XEL_HEADER_IP_LENGTH_OFFSET +
@@ -433,23 +423,25 @@ static u16 xemaclite_recv_data(struct net_local *drvdata, u8 *data, int maxlen)
433
423
length = min_t (u16 , length , ETH_DATA_LEN );
434
424
length += ETH_HLEN + ETH_FCS_LEN ;
435
425
436
- } else if (proto_type == ETH_P_ARP )
426
+ } else if (proto_type == ETH_P_ARP ) {
437
427
length = XEL_ARP_PACKET_SIZE + ETH_HLEN + ETH_FCS_LEN ;
438
- else
428
+ } else {
439
429
/* Field contains type other than IP or ARP, use max
440
430
* frame size and let user parse it
441
431
*/
442
432
length = ETH_FRAME_LEN + ETH_FCS_LEN ;
443
- } else
433
+ }
434
+ } else {
444
435
/* Use the length in the frame, plus the header and trailer */
445
436
length = proto_type + ETH_HLEN + ETH_FCS_LEN ;
437
+ }
446
438
447
439
if (WARN_ON (length > maxlen ))
448
440
length = maxlen ;
449
441
450
442
/* Read from the EmacLite device */
451
443
xemaclite_aligned_read ((u32 __force * )(addr + XEL_RXBUFF_OFFSET ),
452
- data , length );
444
+ data , length );
453
445
454
446
/* Acknowledge the frame */
455
447
reg_data = xemaclite_readl (addr + XEL_RSR_OFFSET );
@@ -599,28 +591,18 @@ static void xemaclite_rx_handler(struct net_device *dev)
599
591
{
600
592
struct net_local * lp = netdev_priv (dev );
601
593
struct sk_buff * skb ;
602
- unsigned int align ;
603
594
u32 len ;
604
595
605
596
len = ETH_FRAME_LEN + ETH_FCS_LEN ;
606
- skb = netdev_alloc_skb (dev , len + ALIGNMENT );
597
+ skb = netdev_alloc_skb (dev , len + NET_IP_ALIGN );
607
598
if (!skb ) {
608
599
/* Couldn't get memory. */
609
600
dev -> stats .rx_dropped ++ ;
610
601
dev_err (& lp -> ndev -> dev , "Could not allocate receive buffer\n" );
611
602
return ;
612
603
}
613
604
614
- /* A new skb should have the data halfword aligned, but this code is
615
- * here just in case that isn't true. Calculate how many
616
- * bytes we should reserve to get the data to start on a word
617
- * boundary
618
- */
619
- align = BUFFER_ALIGN (skb -> data );
620
- if (align )
621
- skb_reserve (skb , align );
622
-
623
- skb_reserve (skb , 2 );
605
+ skb_reserve (skb , NET_IP_ALIGN );
624
606
625
607
len = xemaclite_recv_data (lp , (u8 * )skb -> data , len );
626
608
@@ -671,8 +653,7 @@ static irqreturn_t xemaclite_interrupt(int irq, void *dev_id)
671
653
/* Check if the Transmission for the first buffer is completed */
672
654
tx_status = xemaclite_readl (base_addr + XEL_TSR_OFFSET );
673
655
if (((tx_status & XEL_TSR_XMIT_BUSY_MASK ) == 0 ) &&
674
- (tx_status & XEL_TSR_XMIT_ACTIVE_MASK ) != 0 ) {
675
-
656
+ (tx_status & XEL_TSR_XMIT_ACTIVE_MASK ) != 0 ) {
676
657
tx_status &= ~XEL_TSR_XMIT_ACTIVE_MASK ;
677
658
xemaclite_writel (tx_status , base_addr + XEL_TSR_OFFSET );
678
659
@@ -682,8 +663,7 @@ static irqreturn_t xemaclite_interrupt(int irq, void *dev_id)
682
663
/* Check if the Transmission for the second buffer is completed */
683
664
tx_status = xemaclite_readl (base_addr + XEL_BUFFER_OFFSET + XEL_TSR_OFFSET );
684
665
if (((tx_status & XEL_TSR_XMIT_BUSY_MASK ) == 0 ) &&
685
- (tx_status & XEL_TSR_XMIT_ACTIVE_MASK ) != 0 ) {
686
-
666
+ (tx_status & XEL_TSR_XMIT_ACTIVE_MASK ) != 0 ) {
687
667
tx_status &= ~XEL_TSR_XMIT_ACTIVE_MASK ;
688
668
xemaclite_writel (tx_status , base_addr + XEL_BUFFER_OFFSET +
689
669
XEL_TSR_OFFSET );
@@ -840,6 +820,7 @@ static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
840
820
of_address_to_resource (npp , 0 , & res );
841
821
if (lp -> ndev -> mem_start != res .start ) {
842
822
struct phy_device * phydev ;
823
+
843
824
phydev = of_phy_find_device (lp -> phy_node );
844
825
if (!phydev )
845
826
dev_info (dev ,
0 commit comments