]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/net/ethernet/xilinx/xilinx_emaclite.c
net: xilinx_emaclite: fix receive buffer overflow
[linux.git] / drivers / net / ethernet / xilinx / xilinx_emaclite.c
1 /*
2  * Xilinx EmacLite Linux driver for the Xilinx Ethernet MAC Lite device.
3  *
4  * This is a new flat driver which is based on the original emac_lite
5  * driver from John Williams <john.williams@xilinx.com>.
6  *
7  * 2007 - 2013 (c) Xilinx, Inc.
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version.
13  */
14
15 #include <linux/module.h>
16 #include <linux/uaccess.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/skbuff.h>
20 #include <linux/io.h>
21 #include <linux/slab.h>
22 #include <linux/of_address.h>
23 #include <linux/of_device.h>
24 #include <linux/of_platform.h>
25 #include <linux/of_mdio.h>
26 #include <linux/of_net.h>
27 #include <linux/phy.h>
28 #include <linux/interrupt.h>
29
30 #define DRIVER_NAME "xilinx_emaclite"
31
32 /* Register offsets for the EmacLite Core */
33 #define XEL_TXBUFF_OFFSET       0x0             /* Transmit Buffer */
34 #define XEL_MDIOADDR_OFFSET     0x07E4          /* MDIO Address Register */
35 #define XEL_MDIOWR_OFFSET       0x07E8          /* MDIO Write Data Register */
36 #define XEL_MDIORD_OFFSET       0x07EC          /* MDIO Read Data Register */
37 #define XEL_MDIOCTRL_OFFSET     0x07F0          /* MDIO Control Register */
38 #define XEL_GIER_OFFSET         0x07F8          /* GIE Register */
39 #define XEL_TSR_OFFSET          0x07FC          /* Tx status */
40 #define XEL_TPLR_OFFSET         0x07F4          /* Tx packet length */
41
42 #define XEL_RXBUFF_OFFSET       0x1000          /* Receive Buffer */
43 #define XEL_RPLR_OFFSET         0x100C          /* Rx packet length */
44 #define XEL_RSR_OFFSET          0x17FC          /* Rx status */
45
46 #define XEL_BUFFER_OFFSET       0x0800          /* Next Tx/Rx buffer's offset */
47
48 /* MDIO Address Register Bit Masks */
49 #define XEL_MDIOADDR_REGADR_MASK  0x0000001F    /* Register Address */
50 #define XEL_MDIOADDR_PHYADR_MASK  0x000003E0    /* PHY Address */
51 #define XEL_MDIOADDR_PHYADR_SHIFT 5
52 #define XEL_MDIOADDR_OP_MASK      0x00000400    /* RD/WR Operation */
53
54 /* MDIO Write Data Register Bit Masks */
55 #define XEL_MDIOWR_WRDATA_MASK    0x0000FFFF    /* Data to be Written */
56
57 /* MDIO Read Data Register Bit Masks */
58 #define XEL_MDIORD_RDDATA_MASK    0x0000FFFF    /* Data to be Read */
59
60 /* MDIO Control Register Bit Masks */
61 #define XEL_MDIOCTRL_MDIOSTS_MASK 0x00000001    /* MDIO Status Mask */
62 #define XEL_MDIOCTRL_MDIOEN_MASK  0x00000008    /* MDIO Enable */
63
64 /* Global Interrupt Enable Register (GIER) Bit Masks */
65 #define XEL_GIER_GIE_MASK       0x80000000      /* Global Enable */
66
67 /* Transmit Status Register (TSR) Bit Masks */
68 #define XEL_TSR_XMIT_BUSY_MASK   0x00000001     /* Tx complete */
69 #define XEL_TSR_PROGRAM_MASK     0x00000002     /* Program the MAC address */
70 #define XEL_TSR_XMIT_IE_MASK     0x00000008     /* Tx interrupt enable bit */
71 #define XEL_TSR_XMIT_ACTIVE_MASK 0x80000000     /* Buffer is active, SW bit
72                                                  * only. This is not documented
73                                                  * in the HW spec */
74
75 /* Define for programming the MAC address into the EmacLite */
76 #define XEL_TSR_PROG_MAC_ADDR   (XEL_TSR_XMIT_BUSY_MASK | XEL_TSR_PROGRAM_MASK)
77
78 /* Receive Status Register (RSR) */
79 #define XEL_RSR_RECV_DONE_MASK  0x00000001      /* Rx complete */
80 #define XEL_RSR_RECV_IE_MASK    0x00000008      /* Rx interrupt enable bit */
81
82 /* Transmit Packet Length Register (TPLR) */
83 #define XEL_TPLR_LENGTH_MASK    0x0000FFFF      /* Tx packet length */
84
85 /* Receive Packet Length Register (RPLR) */
86 #define XEL_RPLR_LENGTH_MASK    0x0000FFFF      /* Rx packet length */
87
88 #define XEL_HEADER_OFFSET       12              /* Offset to length field */
89 #define XEL_HEADER_SHIFT        16              /* Shift value for length */
90
91 /* General Ethernet Definitions */
92 #define XEL_ARP_PACKET_SIZE             28      /* Max ARP packet size */
93 #define XEL_HEADER_IP_LENGTH_OFFSET     16      /* IP Length Offset */
94
95
96
97 #define TX_TIMEOUT              (60*HZ)         /* Tx timeout is 60 seconds. */
98 #define ALIGNMENT               4
99
100 /* BUFFER_ALIGN(adr) calculates the number of bytes to the next alignment. */
101 #define BUFFER_ALIGN(adr) ((ALIGNMENT - ((u32) adr)) % ALIGNMENT)
102
103 /**
104  * struct net_local - Our private per device data
105  * @ndev:               instance of the network device
106  * @tx_ping_pong:       indicates whether Tx Pong buffer is configured in HW
107  * @rx_ping_pong:       indicates whether Rx Pong buffer is configured in HW
108  * @next_tx_buf_to_use: next Tx buffer to write to
109  * @next_rx_buf_to_use: next Rx buffer to read from
110  * @base_addr:          base address of the Emaclite device
111  * @reset_lock:         lock used for synchronization
112  * @deferred_skb:       holds an skb (for transmission at a later time) when the
113  *                      Tx buffer is not free
114  * @phy_dev:            pointer to the PHY device
115  * @phy_node:           pointer to the PHY device node
116  * @mii_bus:            pointer to the MII bus
117  * @last_link:          last link status
118  * @has_mdio:           indicates whether MDIO is included in the HW
119  */
120 struct net_local {
121
122         struct net_device *ndev;
123
124         bool tx_ping_pong;
125         bool rx_ping_pong;
126         u32 next_tx_buf_to_use;
127         u32 next_rx_buf_to_use;
128         void __iomem *base_addr;
129
130         spinlock_t reset_lock;
131         struct sk_buff *deferred_skb;
132
133         struct phy_device *phy_dev;
134         struct device_node *phy_node;
135
136         struct mii_bus *mii_bus;
137
138         int last_link;
139         bool has_mdio;
140 };
141
142
143 /*************************/
144 /* EmacLite driver calls */
145 /*************************/
146
147 /**
148  * xemaclite_enable_interrupts - Enable the interrupts for the EmacLite device
149  * @drvdata:    Pointer to the Emaclite device private data
150  *
151  * This function enables the Tx and Rx interrupts for the Emaclite device along
152  * with the Global Interrupt Enable.
153  */
154 static void xemaclite_enable_interrupts(struct net_local *drvdata)
155 {
156         u32 reg_data;
157
158         /* Enable the Tx interrupts for the first Buffer */
159         reg_data = __raw_readl(drvdata->base_addr + XEL_TSR_OFFSET);
160         __raw_writel(reg_data | XEL_TSR_XMIT_IE_MASK,
161                      drvdata->base_addr + XEL_TSR_OFFSET);
162
163         /* Enable the Rx interrupts for the first buffer */
164         __raw_writel(XEL_RSR_RECV_IE_MASK, drvdata->base_addr + XEL_RSR_OFFSET);
165
166         /* Enable the Global Interrupt Enable */
167         __raw_writel(XEL_GIER_GIE_MASK, drvdata->base_addr + XEL_GIER_OFFSET);
168 }
169
170 /**
171  * xemaclite_disable_interrupts - Disable the interrupts for the EmacLite device
172  * @drvdata:    Pointer to the Emaclite device private data
173  *
174  * This function disables the Tx and Rx interrupts for the Emaclite device,
175  * along with the Global Interrupt Enable.
176  */
177 static void xemaclite_disable_interrupts(struct net_local *drvdata)
178 {
179         u32 reg_data;
180
181         /* Disable the Global Interrupt Enable */
182         __raw_writel(XEL_GIER_GIE_MASK, drvdata->base_addr + XEL_GIER_OFFSET);
183
184         /* Disable the Tx interrupts for the first buffer */
185         reg_data = __raw_readl(drvdata->base_addr + XEL_TSR_OFFSET);
186         __raw_writel(reg_data & (~XEL_TSR_XMIT_IE_MASK),
187                      drvdata->base_addr + XEL_TSR_OFFSET);
188
189         /* Disable the Rx interrupts for the first buffer */
190         reg_data = __raw_readl(drvdata->base_addr + XEL_RSR_OFFSET);
191         __raw_writel(reg_data & (~XEL_RSR_RECV_IE_MASK),
192                      drvdata->base_addr + XEL_RSR_OFFSET);
193 }
194
195 /**
196  * xemaclite_aligned_write - Write from 16-bit aligned to 32-bit aligned address
197  * @src_ptr:    Void pointer to the 16-bit aligned source address
198  * @dest_ptr:   Pointer to the 32-bit aligned destination address
199  * @length:     Number bytes to write from source to destination
200  *
201  * This function writes data from a 16-bit aligned buffer to a 32-bit aligned
202  * address in the EmacLite device.
203  */
204 static void xemaclite_aligned_write(void *src_ptr, u32 *dest_ptr,
205                                     unsigned length)
206 {
207         u32 align_buffer;
208         u32 *to_u32_ptr;
209         u16 *from_u16_ptr, *to_u16_ptr;
210
211         to_u32_ptr = dest_ptr;
212         from_u16_ptr = src_ptr;
213         align_buffer = 0;
214
215         for (; length > 3; length -= 4) {
216                 to_u16_ptr = (u16 *)&align_buffer;
217                 *to_u16_ptr++ = *from_u16_ptr++;
218                 *to_u16_ptr++ = *from_u16_ptr++;
219
220                 /* This barrier resolves occasional issues seen around
221                  * cases where the data is not properly flushed out
222                  * from the processor store buffers to the destination
223                  * memory locations.
224                  */
225                 wmb();
226
227                 /* Output a word */
228                 *to_u32_ptr++ = align_buffer;
229         }
230         if (length) {
231                 u8 *from_u8_ptr, *to_u8_ptr;
232
233                 /* Set up to output the remaining data */
234                 align_buffer = 0;
235                 to_u8_ptr = (u8 *) &align_buffer;
236                 from_u8_ptr = (u8 *) from_u16_ptr;
237
238                 /* Output the remaining data */
239                 for (; length > 0; length--)
240                         *to_u8_ptr++ = *from_u8_ptr++;
241
242                 /* This barrier resolves occasional issues seen around
243                  * cases where the data is not properly flushed out
244                  * from the processor store buffers to the destination
245                  * memory locations.
246                  */
247                 wmb();
248                 *to_u32_ptr = align_buffer;
249         }
250 }
251
252 /**
253  * xemaclite_aligned_read - Read from 32-bit aligned to 16-bit aligned buffer
254  * @src_ptr:    Pointer to the 32-bit aligned source address
255  * @dest_ptr:   Pointer to the 16-bit aligned destination address
256  * @length:     Number bytes to read from source to destination
257  *
258  * This function reads data from a 32-bit aligned address in the EmacLite device
259  * to a 16-bit aligned buffer.
260  */
261 static void xemaclite_aligned_read(u32 *src_ptr, u8 *dest_ptr,
262                                    unsigned length)
263 {
264         u16 *to_u16_ptr, *from_u16_ptr;
265         u32 *from_u32_ptr;
266         u32 align_buffer;
267
268         from_u32_ptr = src_ptr;
269         to_u16_ptr = (u16 *) dest_ptr;
270
271         for (; length > 3; length -= 4) {
272                 /* Copy each word into the temporary buffer */
273                 align_buffer = *from_u32_ptr++;
274                 from_u16_ptr = (u16 *)&align_buffer;
275
276                 /* Read data from source */
277                 *to_u16_ptr++ = *from_u16_ptr++;
278                 *to_u16_ptr++ = *from_u16_ptr++;
279         }
280
281         if (length) {
282                 u8 *to_u8_ptr, *from_u8_ptr;
283
284                 /* Set up to read the remaining data */
285                 to_u8_ptr = (u8 *) to_u16_ptr;
286                 align_buffer = *from_u32_ptr++;
287                 from_u8_ptr = (u8 *) &align_buffer;
288
289                 /* Read the remaining data */
290                 for (; length > 0; length--)
291                         *to_u8_ptr = *from_u8_ptr;
292         }
293 }
294
295 /**
296  * xemaclite_send_data - Send an Ethernet frame
297  * @drvdata:    Pointer to the Emaclite device private data
298  * @data:       Pointer to the data to be sent
299  * @byte_count: Total frame size, including header
300  *
301  * This function checks if the Tx buffer of the Emaclite device is free to send
302  * data. If so, it fills the Tx buffer with data for transmission. Otherwise, it
303  * returns an error.
304  *
305  * Return:      0 upon success or -1 if the buffer(s) are full.
306  *
307  * Note:        The maximum Tx packet size can not be more than Ethernet header
308  *              (14 Bytes) + Maximum MTU (1500 bytes). This is excluding FCS.
309  */
310 static int xemaclite_send_data(struct net_local *drvdata, u8 *data,
311                                unsigned int byte_count)
312 {
313         u32 reg_data;
314         void __iomem *addr;
315
316         /* Determine the expected Tx buffer address */
317         addr = drvdata->base_addr + drvdata->next_tx_buf_to_use;
318
319         /* If the length is too large, truncate it */
320         if (byte_count > ETH_FRAME_LEN)
321                 byte_count = ETH_FRAME_LEN;
322
323         /* Check if the expected buffer is available */
324         reg_data = __raw_readl(addr + XEL_TSR_OFFSET);
325         if ((reg_data & (XEL_TSR_XMIT_BUSY_MASK |
326              XEL_TSR_XMIT_ACTIVE_MASK)) == 0) {
327
328                 /* Switch to next buffer if configured */
329                 if (drvdata->tx_ping_pong != 0)
330                         drvdata->next_tx_buf_to_use ^= XEL_BUFFER_OFFSET;
331         } else if (drvdata->tx_ping_pong != 0) {
332                 /* If the expected buffer is full, try the other buffer,
333                  * if it is configured in HW */
334
335                 addr = (void __iomem __force *)((u32 __force)addr ^
336                                                  XEL_BUFFER_OFFSET);
337                 reg_data = __raw_readl(addr + XEL_TSR_OFFSET);
338
339                 if ((reg_data & (XEL_TSR_XMIT_BUSY_MASK |
340                      XEL_TSR_XMIT_ACTIVE_MASK)) != 0)
341                         return -1; /* Buffers were full, return failure */
342         } else
343                 return -1; /* Buffer was full, return failure */
344
345         /* Write the frame to the buffer */
346         xemaclite_aligned_write(data, (u32 __force *) addr, byte_count);
347
348         __raw_writel((byte_count & XEL_TPLR_LENGTH_MASK),
349                      addr + XEL_TPLR_OFFSET);
350
351         /* Update the Tx Status Register to indicate that there is a
352          * frame to send. Set the XEL_TSR_XMIT_ACTIVE_MASK flag which
353          * is used by the interrupt handler to check whether a frame
354          * has been transmitted */
355         reg_data = __raw_readl(addr + XEL_TSR_OFFSET);
356         reg_data |= (XEL_TSR_XMIT_BUSY_MASK | XEL_TSR_XMIT_ACTIVE_MASK);
357         __raw_writel(reg_data, addr + XEL_TSR_OFFSET);
358
359         return 0;
360 }
361
362 /**
363  * xemaclite_recv_data - Receive a frame
364  * @drvdata:    Pointer to the Emaclite device private data
365  * @data:       Address where the data is to be received
366  *
367  * This function is intended to be called from the interrupt context or
368  * with a wrapper which waits for the receive frame to be available.
369  *
370  * Return:      Total number of bytes received
371  */
372 static u16 xemaclite_recv_data(struct net_local *drvdata, u8 *data, int maxlen)
373 {
374         void __iomem *addr;
375         u16 length, proto_type;
376         u32 reg_data;
377
378         /* Determine the expected buffer address */
379         addr = (drvdata->base_addr + drvdata->next_rx_buf_to_use);
380
381         /* Verify which buffer has valid data */
382         reg_data = __raw_readl(addr + XEL_RSR_OFFSET);
383
384         if ((reg_data & XEL_RSR_RECV_DONE_MASK) == XEL_RSR_RECV_DONE_MASK) {
385                 if (drvdata->rx_ping_pong != 0)
386                         drvdata->next_rx_buf_to_use ^= XEL_BUFFER_OFFSET;
387         } else {
388                 /* The instance is out of sync, try other buffer if other
389                  * buffer is configured, return 0 otherwise. If the instance is
390                  * out of sync, do not update the 'next_rx_buf_to_use' since it
391                  * will correct on subsequent calls */
392                 if (drvdata->rx_ping_pong != 0)
393                         addr = (void __iomem __force *)((u32 __force)addr ^
394                                                          XEL_BUFFER_OFFSET);
395                 else
396                         return 0;       /* No data was available */
397
398                 /* Verify that buffer has valid data */
399                 reg_data = __raw_readl(addr + XEL_RSR_OFFSET);
400                 if ((reg_data & XEL_RSR_RECV_DONE_MASK) !=
401                      XEL_RSR_RECV_DONE_MASK)
402                         return 0;       /* No data was available */
403         }
404
405         /* Get the protocol type of the ethernet frame that arrived */
406         proto_type = ((ntohl(__raw_readl(addr + XEL_HEADER_OFFSET +
407                         XEL_RXBUFF_OFFSET)) >> XEL_HEADER_SHIFT) &
408                         XEL_RPLR_LENGTH_MASK);
409
410         /* Check if received ethernet frame is a raw ethernet frame
411          * or an IP packet or an ARP packet */
412         if (proto_type > ETH_DATA_LEN) {
413
414                 if (proto_type == ETH_P_IP) {
415                         length = ((ntohl(__raw_readl(addr +
416                                         XEL_HEADER_IP_LENGTH_OFFSET +
417                                         XEL_RXBUFF_OFFSET)) >>
418                                         XEL_HEADER_SHIFT) &
419                                         XEL_RPLR_LENGTH_MASK);
420                         length = min_t(u16, length, ETH_DATA_LEN);
421                         length += ETH_HLEN + ETH_FCS_LEN;
422
423                 } else if (proto_type == ETH_P_ARP)
424                         length = XEL_ARP_PACKET_SIZE + ETH_HLEN + ETH_FCS_LEN;
425                 else
426                         /* Field contains type other than IP or ARP, use max
427                          * frame size and let user parse it */
428                         length = ETH_FRAME_LEN + ETH_FCS_LEN;
429         } else
430                 /* Use the length in the frame, plus the header and trailer */
431                 length = proto_type + ETH_HLEN + ETH_FCS_LEN;
432
433         if (WARN_ON(length > maxlen))
434                 length = maxlen;
435
436         /* Read from the EmacLite device */
437         xemaclite_aligned_read((u32 __force *) (addr + XEL_RXBUFF_OFFSET),
438                                 data, length);
439
440         /* Acknowledge the frame */
441         reg_data = __raw_readl(addr + XEL_RSR_OFFSET);
442         reg_data &= ~XEL_RSR_RECV_DONE_MASK;
443         __raw_writel(reg_data, addr + XEL_RSR_OFFSET);
444
445         return length;
446 }
447
448 /**
449  * xemaclite_update_address - Update the MAC address in the device
450  * @drvdata:    Pointer to the Emaclite device private data
451  * @address_ptr:Pointer to the MAC address (MAC address is a 48-bit value)
452  *
453  * Tx must be idle and Rx should be idle for deterministic results.
454  * It is recommended that this function should be called after the
455  * initialization and before transmission of any packets from the device.
456  * The MAC address can be programmed using any of the two transmit
457  * buffers (if configured).
458  */
459 static void xemaclite_update_address(struct net_local *drvdata,
460                                      u8 *address_ptr)
461 {
462         void __iomem *addr;
463         u32 reg_data;
464
465         /* Determine the expected Tx buffer address */
466         addr = drvdata->base_addr + drvdata->next_tx_buf_to_use;
467
468         xemaclite_aligned_write(address_ptr, (u32 __force *) addr, ETH_ALEN);
469
470         __raw_writel(ETH_ALEN, addr + XEL_TPLR_OFFSET);
471
472         /* Update the MAC address in the EmacLite */
473         reg_data = __raw_readl(addr + XEL_TSR_OFFSET);
474         __raw_writel(reg_data | XEL_TSR_PROG_MAC_ADDR, addr + XEL_TSR_OFFSET);
475
476         /* Wait for EmacLite to finish with the MAC address update */
477         while ((__raw_readl(addr + XEL_TSR_OFFSET) &
478                 XEL_TSR_PROG_MAC_ADDR) != 0)
479                 ;
480 }
481
482 /**
483  * xemaclite_set_mac_address - Set the MAC address for this device
484  * @dev:        Pointer to the network device instance
485  * @addr:       Void pointer to the sockaddr structure
486  *
487  * This function copies the HW address from the sockaddr strucutre to the
488  * net_device structure and updates the address in HW.
489  *
490  * Return:      Error if the net device is busy or 0 if the addr is set
491  *              successfully
492  */
493 static int xemaclite_set_mac_address(struct net_device *dev, void *address)
494 {
495         struct net_local *lp = netdev_priv(dev);
496         struct sockaddr *addr = address;
497
498         if (netif_running(dev))
499                 return -EBUSY;
500
501         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
502         xemaclite_update_address(lp, dev->dev_addr);
503         return 0;
504 }
505
506 /**
507  * xemaclite_tx_timeout - Callback for Tx Timeout
508  * @dev:        Pointer to the network device
509  *
510  * This function is called when Tx time out occurs for Emaclite device.
511  */
512 static void xemaclite_tx_timeout(struct net_device *dev)
513 {
514         struct net_local *lp = netdev_priv(dev);
515         unsigned long flags;
516
517         dev_err(&lp->ndev->dev, "Exceeded transmit timeout of %lu ms\n",
518                 TX_TIMEOUT * 1000UL / HZ);
519
520         dev->stats.tx_errors++;
521
522         /* Reset the device */
523         spin_lock_irqsave(&lp->reset_lock, flags);
524
525         /* Shouldn't really be necessary, but shouldn't hurt */
526         netif_stop_queue(dev);
527
528         xemaclite_disable_interrupts(lp);
529         xemaclite_enable_interrupts(lp);
530
531         if (lp->deferred_skb) {
532                 dev_kfree_skb(lp->deferred_skb);
533                 lp->deferred_skb = NULL;
534                 dev->stats.tx_errors++;
535         }
536
537         /* To exclude tx timeout */
538         netif_trans_update(dev); /* prevent tx timeout */
539
540         /* We're all ready to go. Start the queue */
541         netif_wake_queue(dev);
542         spin_unlock_irqrestore(&lp->reset_lock, flags);
543 }
544
545 /**********************/
546 /* Interrupt Handlers */
547 /**********************/
548
549 /**
550  * xemaclite_tx_handler - Interrupt handler for frames sent
551  * @dev:        Pointer to the network device
552  *
553  * This function updates the number of packets transmitted and handles the
554  * deferred skb, if there is one.
555  */
556 static void xemaclite_tx_handler(struct net_device *dev)
557 {
558         struct net_local *lp = netdev_priv(dev);
559
560         dev->stats.tx_packets++;
561         if (lp->deferred_skb) {
562                 if (xemaclite_send_data(lp,
563                                         (u8 *) lp->deferred_skb->data,
564                                         lp->deferred_skb->len) != 0)
565                         return;
566                 else {
567                         dev->stats.tx_bytes += lp->deferred_skb->len;
568                         dev_kfree_skb_irq(lp->deferred_skb);
569                         lp->deferred_skb = NULL;
570                         netif_trans_update(dev); /* prevent tx timeout */
571                         netif_wake_queue(dev);
572                 }
573         }
574 }
575
576 /**
577  * xemaclite_rx_handler- Interrupt handler for frames received
578  * @dev:        Pointer to the network device
579  *
580  * This function allocates memory for a socket buffer, fills it with data
581  * received and hands it over to the TCP/IP stack.
582  */
583 static void xemaclite_rx_handler(struct net_device *dev)
584 {
585         struct net_local *lp = netdev_priv(dev);
586         struct sk_buff *skb;
587         unsigned int align;
588         u32 len;
589
590         len = ETH_FRAME_LEN + ETH_FCS_LEN;
591         skb = netdev_alloc_skb(dev, len + ALIGNMENT);
592         if (!skb) {
593                 /* Couldn't get memory. */
594                 dev->stats.rx_dropped++;
595                 dev_err(&lp->ndev->dev, "Could not allocate receive buffer\n");
596                 return;
597         }
598
599         /*
600          * A new skb should have the data halfword aligned, but this code is
601          * here just in case that isn't true. Calculate how many
602          * bytes we should reserve to get the data to start on a word
603          * boundary */
604         align = BUFFER_ALIGN(skb->data);
605         if (align)
606                 skb_reserve(skb, align);
607
608         skb_reserve(skb, 2);
609
610         len = xemaclite_recv_data(lp, (u8 *) skb->data, len);
611
612         if (!len) {
613                 dev->stats.rx_errors++;
614                 dev_kfree_skb_irq(skb);
615                 return;
616         }
617
618         skb_put(skb, len);      /* Tell the skb how much data we got */
619
620         skb->protocol = eth_type_trans(skb, dev);
621         skb_checksum_none_assert(skb);
622
623         dev->stats.rx_packets++;
624         dev->stats.rx_bytes += len;
625
626         if (!skb_defer_rx_timestamp(skb))
627                 netif_rx(skb);  /* Send the packet upstream */
628 }
629
630 /**
631  * xemaclite_interrupt - Interrupt handler for this driver
632  * @irq:        Irq of the Emaclite device
633  * @dev_id:     Void pointer to the network device instance used as callback
634  *              reference
635  *
636  * This function handles the Tx and Rx interrupts of the EmacLite device.
637  */
638 static irqreturn_t xemaclite_interrupt(int irq, void *dev_id)
639 {
640         bool tx_complete = false;
641         struct net_device *dev = dev_id;
642         struct net_local *lp = netdev_priv(dev);
643         void __iomem *base_addr = lp->base_addr;
644         u32 tx_status;
645
646         /* Check if there is Rx Data available */
647         if ((__raw_readl(base_addr + XEL_RSR_OFFSET) &
648                          XEL_RSR_RECV_DONE_MASK) ||
649             (__raw_readl(base_addr + XEL_BUFFER_OFFSET + XEL_RSR_OFFSET)
650                          & XEL_RSR_RECV_DONE_MASK))
651
652                 xemaclite_rx_handler(dev);
653
654         /* Check if the Transmission for the first buffer is completed */
655         tx_status = __raw_readl(base_addr + XEL_TSR_OFFSET);
656         if (((tx_status & XEL_TSR_XMIT_BUSY_MASK) == 0) &&
657                 (tx_status & XEL_TSR_XMIT_ACTIVE_MASK) != 0) {
658
659                 tx_status &= ~XEL_TSR_XMIT_ACTIVE_MASK;
660                 __raw_writel(tx_status, base_addr + XEL_TSR_OFFSET);
661
662                 tx_complete = true;
663         }
664
665         /* Check if the Transmission for the second buffer is completed */
666         tx_status = __raw_readl(base_addr + XEL_BUFFER_OFFSET + XEL_TSR_OFFSET);
667         if (((tx_status & XEL_TSR_XMIT_BUSY_MASK) == 0) &&
668                 (tx_status & XEL_TSR_XMIT_ACTIVE_MASK) != 0) {
669
670                 tx_status &= ~XEL_TSR_XMIT_ACTIVE_MASK;
671                 __raw_writel(tx_status, base_addr + XEL_BUFFER_OFFSET +
672                              XEL_TSR_OFFSET);
673
674                 tx_complete = true;
675         }
676
677         /* If there was a Tx interrupt, call the Tx Handler */
678         if (tx_complete != 0)
679                 xemaclite_tx_handler(dev);
680
681         return IRQ_HANDLED;
682 }
683
684 /**********************/
685 /* MDIO Bus functions */
686 /**********************/
687
688 /**
689  * xemaclite_mdio_wait - Wait for the MDIO to be ready to use
690  * @lp:         Pointer to the Emaclite device private data
691  *
692  * This function waits till the device is ready to accept a new MDIO
693  * request.
694  *
695  * Return:      0 for success or ETIMEDOUT for a timeout
696  */
697
698 static int xemaclite_mdio_wait(struct net_local *lp)
699 {
700         unsigned long end = jiffies + 2;
701
702         /* wait for the MDIO interface to not be busy or timeout
703            after some time.
704         */
705         while (__raw_readl(lp->base_addr + XEL_MDIOCTRL_OFFSET) &
706                         XEL_MDIOCTRL_MDIOSTS_MASK) {
707                 if (time_before_eq(end, jiffies)) {
708                         WARN_ON(1);
709                         return -ETIMEDOUT;
710                 }
711                 msleep(1);
712         }
713         return 0;
714 }
715
716 /**
717  * xemaclite_mdio_read - Read from a given MII management register
718  * @bus:        the mii_bus struct
719  * @phy_id:     the phy address
720  * @reg:        register number to read from
721  *
722  * This function waits till the device is ready to accept a new MDIO
723  * request and then writes the phy address to the MDIO Address register
724  * and reads data from MDIO Read Data register, when its available.
725  *
726  * Return:      Value read from the MII management register
727  */
728 static int xemaclite_mdio_read(struct mii_bus *bus, int phy_id, int reg)
729 {
730         struct net_local *lp = bus->priv;
731         u32 ctrl_reg;
732         u32 rc;
733
734         if (xemaclite_mdio_wait(lp))
735                 return -ETIMEDOUT;
736
737         /* Write the PHY address, register number and set the OP bit in the
738          * MDIO Address register. Set the Status bit in the MDIO Control
739          * register to start a MDIO read transaction.
740          */
741         ctrl_reg = __raw_readl(lp->base_addr + XEL_MDIOCTRL_OFFSET);
742         __raw_writel(XEL_MDIOADDR_OP_MASK |
743                      ((phy_id << XEL_MDIOADDR_PHYADR_SHIFT) | reg),
744                      lp->base_addr + XEL_MDIOADDR_OFFSET);
745         __raw_writel(ctrl_reg | XEL_MDIOCTRL_MDIOSTS_MASK,
746                      lp->base_addr + XEL_MDIOCTRL_OFFSET);
747
748         if (xemaclite_mdio_wait(lp))
749                 return -ETIMEDOUT;
750
751         rc = __raw_readl(lp->base_addr + XEL_MDIORD_OFFSET);
752
753         dev_dbg(&lp->ndev->dev,
754                 "xemaclite_mdio_read(phy_id=%i, reg=%x) == %x\n",
755                 phy_id, reg, rc);
756
757         return rc;
758 }
759
760 /**
761  * xemaclite_mdio_write - Write to a given MII management register
762  * @bus:        the mii_bus struct
763  * @phy_id:     the phy address
764  * @reg:        register number to write to
765  * @val:        value to write to the register number specified by reg
766  *
767  * This function waits till the device is ready to accept a new MDIO
768  * request and then writes the val to the MDIO Write Data register.
769  */
770 static int xemaclite_mdio_write(struct mii_bus *bus, int phy_id, int reg,
771                                 u16 val)
772 {
773         struct net_local *lp = bus->priv;
774         u32 ctrl_reg;
775
776         dev_dbg(&lp->ndev->dev,
777                 "xemaclite_mdio_write(phy_id=%i, reg=%x, val=%x)\n",
778                 phy_id, reg, val);
779
780         if (xemaclite_mdio_wait(lp))
781                 return -ETIMEDOUT;
782
783         /* Write the PHY address, register number and clear the OP bit in the
784          * MDIO Address register and then write the value into the MDIO Write
785          * Data register. Finally, set the Status bit in the MDIO Control
786          * register to start a MDIO write transaction.
787          */
788         ctrl_reg = __raw_readl(lp->base_addr + XEL_MDIOCTRL_OFFSET);
789         __raw_writel(~XEL_MDIOADDR_OP_MASK &
790                      ((phy_id << XEL_MDIOADDR_PHYADR_SHIFT) | reg),
791                      lp->base_addr + XEL_MDIOADDR_OFFSET);
792         __raw_writel(val, lp->base_addr + XEL_MDIOWR_OFFSET);
793         __raw_writel(ctrl_reg | XEL_MDIOCTRL_MDIOSTS_MASK,
794                      lp->base_addr + XEL_MDIOCTRL_OFFSET);
795
796         return 0;
797 }
798
799 /**
800  * xemaclite_mdio_setup - Register mii_bus for the Emaclite device
801  * @lp:         Pointer to the Emaclite device private data
802  * @ofdev:      Pointer to OF device structure
803  *
804  * This function enables MDIO bus in the Emaclite device and registers a
805  * mii_bus.
806  *
807  * Return:      0 upon success or a negative error upon failure
808  */
809 static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
810 {
811         struct mii_bus *bus;
812         int rc;
813         struct resource res;
814         struct device_node *np = of_get_parent(lp->phy_node);
815         struct device_node *npp;
816
817         /* Don't register the MDIO bus if the phy_node or its parent node
818          * can't be found.
819          */
820         if (!np) {
821                 dev_err(dev, "Failed to register mdio bus.\n");
822                 return -ENODEV;
823         }
824         npp = of_get_parent(np);
825
826         of_address_to_resource(npp, 0, &res);
827         if (lp->ndev->mem_start != res.start) {
828                 struct phy_device *phydev;
829                 phydev = of_phy_find_device(lp->phy_node);
830                 if (!phydev)
831                         dev_info(dev,
832                                  "MDIO of the phy is not registered yet\n");
833                 else
834                         put_device(&phydev->mdio.dev);
835                 return 0;
836         }
837
838         /* Enable the MDIO bus by asserting the enable bit in MDIO Control
839          * register.
840          */
841         __raw_writel(XEL_MDIOCTRL_MDIOEN_MASK,
842                      lp->base_addr + XEL_MDIOCTRL_OFFSET);
843
844         bus = mdiobus_alloc();
845         if (!bus) {
846                 dev_err(dev, "Failed to allocate mdiobus\n");
847                 return -ENOMEM;
848         }
849
850         snprintf(bus->id, MII_BUS_ID_SIZE, "%.8llx",
851                  (unsigned long long)res.start);
852         bus->priv = lp;
853         bus->name = "Xilinx Emaclite MDIO";
854         bus->read = xemaclite_mdio_read;
855         bus->write = xemaclite_mdio_write;
856         bus->parent = dev;
857
858         lp->mii_bus = bus;
859
860         rc = of_mdiobus_register(bus, np);
861         if (rc) {
862                 dev_err(dev, "Failed to register mdio bus.\n");
863                 goto err_register;
864         }
865
866         return 0;
867
868 err_register:
869         mdiobus_free(bus);
870         return rc;
871 }
872
873 /**
874  * xemaclite_adjust_link - Link state callback for the Emaclite device
875  * @ndev: pointer to net_device struct
876  *
877  * There's nothing in the Emaclite device to be configured when the link
878  * state changes. We just print the status.
879  */
880 static void xemaclite_adjust_link(struct net_device *ndev)
881 {
882         struct net_local *lp = netdev_priv(ndev);
883         struct phy_device *phy = lp->phy_dev;
884         int link_state;
885
886         /* hash together the state values to decide if something has changed */
887         link_state = phy->speed | (phy->duplex << 1) | phy->link;
888
889         if (lp->last_link != link_state) {
890                 lp->last_link = link_state;
891                 phy_print_status(phy);
892         }
893 }
894
895 /**
896  * xemaclite_open - Open the network device
897  * @dev:        Pointer to the network device
898  *
899  * This function sets the MAC address, requests an IRQ and enables interrupts
900  * for the Emaclite device and starts the Tx queue.
901  * It also connects to the phy device, if MDIO is included in Emaclite device.
902  */
903 static int xemaclite_open(struct net_device *dev)
904 {
905         struct net_local *lp = netdev_priv(dev);
906         int retval;
907
908         /* Just to be safe, stop the device first */
909         xemaclite_disable_interrupts(lp);
910
911         if (lp->phy_node) {
912                 u32 bmcr;
913
914                 lp->phy_dev = of_phy_connect(lp->ndev, lp->phy_node,
915                                              xemaclite_adjust_link, 0,
916                                              PHY_INTERFACE_MODE_MII);
917                 if (!lp->phy_dev) {
918                         dev_err(&lp->ndev->dev, "of_phy_connect() failed\n");
919                         return -ENODEV;
920                 }
921
922                 /* EmacLite doesn't support giga-bit speeds */
923                 lp->phy_dev->supported &= (PHY_BASIC_FEATURES);
924                 lp->phy_dev->advertising = lp->phy_dev->supported;
925
926                 /* Don't advertise 1000BASE-T Full/Half duplex speeds */
927                 phy_write(lp->phy_dev, MII_CTRL1000, 0);
928
929                 /* Advertise only 10 and 100mbps full/half duplex speeds */
930                 phy_write(lp->phy_dev, MII_ADVERTISE, ADVERTISE_ALL |
931                           ADVERTISE_CSMA);
932
933                 /* Restart auto negotiation */
934                 bmcr = phy_read(lp->phy_dev, MII_BMCR);
935                 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
936                 phy_write(lp->phy_dev, MII_BMCR, bmcr);
937
938                 phy_start(lp->phy_dev);
939         }
940
941         /* Set the MAC address each time opened */
942         xemaclite_update_address(lp, dev->dev_addr);
943
944         /* Grab the IRQ */
945         retval = request_irq(dev->irq, xemaclite_interrupt, 0, dev->name, dev);
946         if (retval) {
947                 dev_err(&lp->ndev->dev, "Could not allocate interrupt %d\n",
948                         dev->irq);
949                 if (lp->phy_dev)
950                         phy_disconnect(lp->phy_dev);
951                 lp->phy_dev = NULL;
952
953                 return retval;
954         }
955
956         /* Enable Interrupts */
957         xemaclite_enable_interrupts(lp);
958
959         /* We're ready to go */
960         netif_start_queue(dev);
961
962         return 0;
963 }
964
965 /**
966  * xemaclite_close - Close the network device
967  * @dev:        Pointer to the network device
968  *
969  * This function stops the Tx queue, disables interrupts and frees the IRQ for
970  * the Emaclite device.
971  * It also disconnects the phy device associated with the Emaclite device.
972  */
973 static int xemaclite_close(struct net_device *dev)
974 {
975         struct net_local *lp = netdev_priv(dev);
976
977         netif_stop_queue(dev);
978         xemaclite_disable_interrupts(lp);
979         free_irq(dev->irq, dev);
980
981         if (lp->phy_dev)
982                 phy_disconnect(lp->phy_dev);
983         lp->phy_dev = NULL;
984
985         return 0;
986 }
987
988 /**
989  * xemaclite_send - Transmit a frame
990  * @orig_skb:   Pointer to the socket buffer to be transmitted
991  * @dev:        Pointer to the network device
992  *
993  * This function checks if the Tx buffer of the Emaclite device is free to send
994  * data. If so, it fills the Tx buffer with data from socket buffer data,
995  * updates the stats and frees the socket buffer. The Tx completion is signaled
996  * by an interrupt. If the Tx buffer isn't free, then the socket buffer is
997  * deferred and the Tx queue is stopped so that the deferred socket buffer can
998  * be transmitted when the Emaclite device is free to transmit data.
999  *
1000  * Return:      0, always.
1001  */
1002 static int xemaclite_send(struct sk_buff *orig_skb, struct net_device *dev)
1003 {
1004         struct net_local *lp = netdev_priv(dev);
1005         struct sk_buff *new_skb;
1006         unsigned int len;
1007         unsigned long flags;
1008
1009         len = orig_skb->len;
1010
1011         new_skb = orig_skb;
1012
1013         spin_lock_irqsave(&lp->reset_lock, flags);
1014         if (xemaclite_send_data(lp, (u8 *) new_skb->data, len) != 0) {
1015                 /* If the Emaclite Tx buffer is busy, stop the Tx queue and
1016                  * defer the skb for transmission during the ISR, after the
1017                  * current transmission is complete */
1018                 netif_stop_queue(dev);
1019                 lp->deferred_skb = new_skb;
1020                 /* Take the time stamp now, since we can't do this in an ISR. */
1021                 skb_tx_timestamp(new_skb);
1022                 spin_unlock_irqrestore(&lp->reset_lock, flags);
1023                 return 0;
1024         }
1025         spin_unlock_irqrestore(&lp->reset_lock, flags);
1026
1027         skb_tx_timestamp(new_skb);
1028
1029         dev->stats.tx_bytes += len;
1030         dev_consume_skb_any(new_skb);
1031
1032         return 0;
1033 }
1034
1035 /**
1036  * xemaclite_remove_ndev - Free the network device
1037  * @ndev:       Pointer to the network device to be freed
1038  *
1039  * This function un maps the IO region of the Emaclite device and frees the net
1040  * device.
1041  */
1042 static void xemaclite_remove_ndev(struct net_device *ndev)
1043 {
1044         if (ndev) {
1045                 free_netdev(ndev);
1046         }
1047 }
1048
1049 /**
1050  * get_bool - Get a parameter from the OF device
1051  * @ofdev:      Pointer to OF device structure
1052  * @s:          Property to be retrieved
1053  *
1054  * This function looks for a property in the device node and returns the value
1055  * of the property if its found or 0 if the property is not found.
1056  *
1057  * Return:      Value of the parameter if the parameter is found, or 0 otherwise
1058  */
1059 static bool get_bool(struct platform_device *ofdev, const char *s)
1060 {
1061         u32 *p = (u32 *)of_get_property(ofdev->dev.of_node, s, NULL);
1062
1063         if (p) {
1064                 return (bool)*p;
1065         } else {
1066                 dev_warn(&ofdev->dev, "Parameter %s not found,"
1067                         "defaulting to false\n", s);
1068                 return false;
1069         }
1070 }
1071
1072 static struct net_device_ops xemaclite_netdev_ops;
1073
1074 /**
1075  * xemaclite_of_probe - Probe method for the Emaclite device.
1076  * @ofdev:      Pointer to OF device structure
1077  * @match:      Pointer to the structure used for matching a device
1078  *
1079  * This function probes for the Emaclite device in the device tree.
1080  * It initializes the driver data structure and the hardware, sets the MAC
1081  * address and registers the network device.
1082  * It also registers a mii_bus for the Emaclite device, if MDIO is included
1083  * in the device.
1084  *
1085  * Return:      0, if the driver is bound to the Emaclite device, or
1086  *              a negative error if there is failure.
1087  */
1088 static int xemaclite_of_probe(struct platform_device *ofdev)
1089 {
1090         struct resource *res;
1091         struct net_device *ndev = NULL;
1092         struct net_local *lp = NULL;
1093         struct device *dev = &ofdev->dev;
1094         const void *mac_address;
1095
1096         int rc = 0;
1097
1098         dev_info(dev, "Device Tree Probing\n");
1099
1100         /* Create an ethernet device instance */
1101         ndev = alloc_etherdev(sizeof(struct net_local));
1102         if (!ndev)
1103                 return -ENOMEM;
1104
1105         dev_set_drvdata(dev, ndev);
1106         SET_NETDEV_DEV(ndev, &ofdev->dev);
1107
1108         lp = netdev_priv(ndev);
1109         lp->ndev = ndev;
1110
1111         /* Get IRQ for the device */
1112         res = platform_get_resource(ofdev, IORESOURCE_IRQ, 0);
1113         if (!res) {
1114                 dev_err(dev, "no IRQ found\n");
1115                 rc = -ENXIO;
1116                 goto error;
1117         }
1118
1119         ndev->irq = res->start;
1120
1121         res = platform_get_resource(ofdev, IORESOURCE_MEM, 0);
1122         lp->base_addr = devm_ioremap_resource(&ofdev->dev, res);
1123         if (IS_ERR(lp->base_addr)) {
1124                 rc = PTR_ERR(lp->base_addr);
1125                 goto error;
1126         }
1127
1128         ndev->mem_start = res->start;
1129         ndev->mem_end = res->end;
1130
1131         spin_lock_init(&lp->reset_lock);
1132         lp->next_tx_buf_to_use = 0x0;
1133         lp->next_rx_buf_to_use = 0x0;
1134         lp->tx_ping_pong = get_bool(ofdev, "xlnx,tx-ping-pong");
1135         lp->rx_ping_pong = get_bool(ofdev, "xlnx,rx-ping-pong");
1136         mac_address = of_get_mac_address(ofdev->dev.of_node);
1137
1138         if (mac_address) {
1139                 /* Set the MAC address. */
1140                 memcpy(ndev->dev_addr, mac_address, ETH_ALEN);
1141         } else {
1142                 dev_warn(dev, "No MAC address found, using random\n");
1143                 eth_hw_addr_random(ndev);
1144         }
1145
1146         /* Clear the Tx CSR's in case this is a restart */
1147         __raw_writel(0, lp->base_addr + XEL_TSR_OFFSET);
1148         __raw_writel(0, lp->base_addr + XEL_BUFFER_OFFSET + XEL_TSR_OFFSET);
1149
1150         /* Set the MAC address in the EmacLite device */
1151         xemaclite_update_address(lp, ndev->dev_addr);
1152
1153         lp->phy_node = of_parse_phandle(ofdev->dev.of_node, "phy-handle", 0);
1154         rc = xemaclite_mdio_setup(lp, &ofdev->dev);
1155         if (rc)
1156                 dev_warn(&ofdev->dev, "error registering MDIO bus\n");
1157
1158         dev_info(dev, "MAC address is now %pM\n", ndev->dev_addr);
1159
1160         ndev->netdev_ops = &xemaclite_netdev_ops;
1161         ndev->flags &= ~IFF_MULTICAST;
1162         ndev->watchdog_timeo = TX_TIMEOUT;
1163
1164         /* Finally, register the device */
1165         rc = register_netdev(ndev);
1166         if (rc) {
1167                 dev_err(dev,
1168                         "Cannot register network device, aborting\n");
1169                 goto error;
1170         }
1171
1172         dev_info(dev,
1173                  "Xilinx EmacLite at 0x%08X mapped to 0x%08X, irq=%d\n",
1174                  (unsigned int __force)ndev->mem_start,
1175                  (unsigned int __force)lp->base_addr, ndev->irq);
1176         return 0;
1177
1178 error:
1179         xemaclite_remove_ndev(ndev);
1180         return rc;
1181 }
1182
1183 /**
1184  * xemaclite_of_remove - Unbind the driver from the Emaclite device.
1185  * @of_dev:     Pointer to OF device structure
1186  *
1187  * This function is called if a device is physically removed from the system or
1188  * if the driver module is being unloaded. It frees any resources allocated to
1189  * the device.
1190  *
1191  * Return:      0, always.
1192  */
1193 static int xemaclite_of_remove(struct platform_device *of_dev)
1194 {
1195         struct net_device *ndev = platform_get_drvdata(of_dev);
1196
1197         struct net_local *lp = netdev_priv(ndev);
1198
1199         /* Un-register the mii_bus, if configured */
1200         if (lp->has_mdio) {
1201                 mdiobus_unregister(lp->mii_bus);
1202                 mdiobus_free(lp->mii_bus);
1203                 lp->mii_bus = NULL;
1204         }
1205
1206         unregister_netdev(ndev);
1207
1208         of_node_put(lp->phy_node);
1209         lp->phy_node = NULL;
1210
1211         xemaclite_remove_ndev(ndev);
1212
1213         return 0;
1214 }
1215
1216 #ifdef CONFIG_NET_POLL_CONTROLLER
1217 static void
1218 xemaclite_poll_controller(struct net_device *ndev)
1219 {
1220         disable_irq(ndev->irq);
1221         xemaclite_interrupt(ndev->irq, ndev);
1222         enable_irq(ndev->irq);
1223 }
1224 #endif
1225
1226 static struct net_device_ops xemaclite_netdev_ops = {
1227         .ndo_open               = xemaclite_open,
1228         .ndo_stop               = xemaclite_close,
1229         .ndo_start_xmit         = xemaclite_send,
1230         .ndo_set_mac_address    = xemaclite_set_mac_address,
1231         .ndo_tx_timeout         = xemaclite_tx_timeout,
1232 #ifdef CONFIG_NET_POLL_CONTROLLER
1233         .ndo_poll_controller = xemaclite_poll_controller,
1234 #endif
1235 };
1236
1237 /* Match table for OF platform binding */
1238 static const struct of_device_id xemaclite_of_match[] = {
1239         { .compatible = "xlnx,opb-ethernetlite-1.01.a", },
1240         { .compatible = "xlnx,opb-ethernetlite-1.01.b", },
1241         { .compatible = "xlnx,xps-ethernetlite-1.00.a", },
1242         { .compatible = "xlnx,xps-ethernetlite-2.00.a", },
1243         { .compatible = "xlnx,xps-ethernetlite-2.01.a", },
1244         { .compatible = "xlnx,xps-ethernetlite-3.00.a", },
1245         { /* end of list */ },
1246 };
1247 MODULE_DEVICE_TABLE(of, xemaclite_of_match);
1248
1249 static struct platform_driver xemaclite_of_driver = {
1250         .driver = {
1251                 .name = DRIVER_NAME,
1252                 .of_match_table = xemaclite_of_match,
1253         },
1254         .probe          = xemaclite_of_probe,
1255         .remove         = xemaclite_of_remove,
1256 };
1257
1258 module_platform_driver(xemaclite_of_driver);
1259
1260 MODULE_AUTHOR("Xilinx, Inc.");
1261 MODULE_DESCRIPTION("Xilinx Ethernet MAC Lite driver");
1262 MODULE_LICENSE("GPL");