OSDN Git Service

block: Fix partition support for host aware zoned block devices
[tomoyo/tomoyo-test1.git] / drivers / net / ethernet / micrel / ks8851_mll.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /**
3  * drivers/net/ethernet/micrel/ks8851_mll.c
4  * Copyright (c) 2009 Micrel Inc.
5  */
6
7 /* Supports:
8  * KS8851 16bit MLL chip from Micrel Inc.
9  */
10
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
13 #include <linux/interrupt.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/netdevice.h>
17 #include <linux/etherdevice.h>
18 #include <linux/ethtool.h>
19 #include <linux/cache.h>
20 #include <linux/crc32.h>
21 #include <linux/crc32poly.h>
22 #include <linux/mii.h>
23 #include <linux/platform_device.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/ks8851_mll.h>
27 #include <linux/of.h>
28 #include <linux/of_device.h>
29 #include <linux/of_net.h>
30
31 #include "ks8851.h"
32
33 #define DRV_NAME        "ks8851_mll"
34
35 static u8 KS_DEFAULT_MAC_ADDRESS[] = { 0x00, 0x10, 0xA1, 0x86, 0x95, 0x11 };
36 #define MAX_RECV_FRAMES                 255
37 #define MAX_BUF_SIZE                    2048
38 #define TX_BUF_SIZE                     2000
39 #define RX_BUF_SIZE                     2000
40
41 #define RXCR1_FILTER_MASK               (RXCR1_RXINVF | RXCR1_RXAE | \
42                                          RXCR1_RXMAFMA | RXCR1_RXPAFMA)
43 #define RXQCR_CMD_CNTL                  (RXQCR_RXFCTE|RXQCR_ADRFE)
44
45 #define ENUM_BUS_NONE                   0
46 #define ENUM_BUS_8BIT                   1
47 #define ENUM_BUS_16BIT                  2
48 #define ENUM_BUS_32BIT                  3
49
50 #define MAX_MCAST_LST                   32
51 #define HW_MCAST_SIZE                   8
52
53 /**
54  * union ks_tx_hdr - tx header data
55  * @txb: The header as bytes
56  * @txw: The header as 16bit, little-endian words
57  *
58  * A dual representation of the tx header data to allow
59  * access to individual bytes, and to allow 16bit accesses
60  * with 16bit alignment.
61  */
62 union ks_tx_hdr {
63         u8      txb[4];
64         __le16  txw[2];
65 };
66
67 /**
68  * struct ks_net - KS8851 driver private data
69  * @net_device  : The network device we're bound to
70  * @hw_addr     : start address of data register.
71  * @hw_addr_cmd : start address of command register.
72  * @txh         : temporaly buffer to save status/length.
73  * @lock        : Lock to ensure that the device is not accessed when busy.
74  * @pdev        : Pointer to platform device.
75  * @mii         : The MII state information for the mii calls.
76  * @frame_head_info     : frame header information for multi-pkt rx.
77  * @statelock   : Lock on this structure for tx list.
78  * @msg_enable  : The message flags controlling driver output (see ethtool).
79  * @frame_cnt   : number of frames received.
80  * @bus_width   : i/o bus width.
81  * @rc_rxqcr    : Cached copy of KS_RXQCR.
82  * @rc_txcr     : Cached copy of KS_TXCR.
83  * @rc_ier      : Cached copy of KS_IER.
84  * @sharedbus   : Multipex(addr and data bus) mode indicator.
85  * @cmd_reg_cache       : command register cached.
86  * @cmd_reg_cache_int   : command register cached. Used in the irq handler.
87  * @promiscuous : promiscuous mode indicator.
88  * @all_mcast   : mutlicast indicator.
89  * @mcast_lst_size      : size of multicast list.
90  * @mcast_lst           : multicast list.
91  * @mcast_bits          : multicast enabed.
92  * @mac_addr            : MAC address assigned to this device.
93  * @fid                 : frame id.
94  * @extra_byte          : number of extra byte prepended rx pkt.
95  * @enabled             : indicator this device works.
96  *
97  * The @lock ensures that the chip is protected when certain operations are
98  * in progress. When the read or write packet transfer is in progress, most
99  * of the chip registers are not accessible until the transfer is finished and
100  * the DMA has been de-asserted.
101  *
102  * The @statelock is used to protect information in the structure which may
103  * need to be accessed via several sources, such as the network driver layer
104  * or one of the work queues.
105  *
106  */
107
108 /* Receive multiplex framer header info */
109 struct type_frame_head {
110         u16     sts;         /* Frame status */
111         u16     len;         /* Byte count */
112 };
113
114 struct ks_net {
115         struct net_device       *netdev;
116         void __iomem            *hw_addr;
117         void __iomem            *hw_addr_cmd;
118         union ks_tx_hdr         txh ____cacheline_aligned;
119         struct mutex            lock; /* spinlock to be interrupt safe */
120         struct platform_device *pdev;
121         struct mii_if_info      mii;
122         struct type_frame_head  *frame_head_info;
123         spinlock_t              statelock;
124         u32                     msg_enable;
125         u32                     frame_cnt;
126         int                     bus_width;
127
128         u16                     rc_rxqcr;
129         u16                     rc_txcr;
130         u16                     rc_ier;
131         u16                     sharedbus;
132         u16                     cmd_reg_cache;
133         u16                     cmd_reg_cache_int;
134         u16                     promiscuous;
135         u16                     all_mcast;
136         u16                     mcast_lst_size;
137         u8                      mcast_lst[MAX_MCAST_LST][ETH_ALEN];
138         u8                      mcast_bits[HW_MCAST_SIZE];
139         u8                      mac_addr[6];
140         u8                      fid;
141         u8                      extra_byte;
142         u8                      enabled;
143 };
144
145 static int msg_enable;
146
147 #define BE3             0x8000      /* Byte Enable 3 */
148 #define BE2             0x4000      /* Byte Enable 2 */
149 #define BE1             0x2000      /* Byte Enable 1 */
150 #define BE0             0x1000      /* Byte Enable 0 */
151
152 /* register read/write calls.
153  *
154  * All these calls issue transactions to access the chip's registers. They
155  * all require that the necessary lock is held to prevent accesses when the
156  * chip is busy transferring packet data (RX/TX FIFO accesses).
157  */
158
159 /**
160  * ks_rdreg16 - read 16 bit register from device
161  * @ks    : The chip information
162  * @offset: The register address
163  *
164  * Read a 16bit register from the chip, returning the result
165  */
166
167 static u16 ks_rdreg16(struct ks_net *ks, int offset)
168 {
169         ks->cmd_reg_cache = (u16)offset | ((BE3 | BE2) >> (offset & 0x02));
170         iowrite16(ks->cmd_reg_cache, ks->hw_addr_cmd);
171         return ioread16(ks->hw_addr);
172 }
173
174 /**
175  * ks_wrreg16 - write 16bit register value to chip
176  * @ks: The chip information
177  * @offset: The register address
178  * @value: The value to write
179  *
180  */
181
182 static void ks_wrreg16(struct ks_net *ks, int offset, u16 value)
183 {
184         ks->cmd_reg_cache = (u16)offset | ((BE3 | BE2) >> (offset & 0x02));
185         iowrite16(ks->cmd_reg_cache, ks->hw_addr_cmd);
186         iowrite16(value, ks->hw_addr);
187 }
188
189 /**
190  * ks_inblk - read a block of data from QMU. This is called after sudo DMA mode enabled.
191  * @ks: The chip state
192  * @wptr: buffer address to save data
193  * @len: length in byte to read
194  *
195  */
196 static inline void ks_inblk(struct ks_net *ks, u16 *wptr, u32 len)
197 {
198         len >>= 1;
199         while (len--)
200                 *wptr++ = be16_to_cpu(ioread16(ks->hw_addr));
201 }
202
203 /**
204  * ks_outblk - write data to QMU. This is called after sudo DMA mode enabled.
205  * @ks: The chip information
206  * @wptr: buffer address
207  * @len: length in byte to write
208  *
209  */
210 static inline void ks_outblk(struct ks_net *ks, u16 *wptr, u32 len)
211 {
212         len >>= 1;
213         while (len--)
214                 iowrite16(cpu_to_be16(*wptr++), ks->hw_addr);
215 }
216
217 static void ks_disable_int(struct ks_net *ks)
218 {
219         ks_wrreg16(ks, KS_IER, 0x0000);
220 }  /* ks_disable_int */
221
222 static void ks_enable_int(struct ks_net *ks)
223 {
224         ks_wrreg16(ks, KS_IER, ks->rc_ier);
225 }  /* ks_enable_int */
226
227 /**
228  * ks_tx_fifo_space - return the available hardware buffer size.
229  * @ks: The chip information
230  *
231  */
232 static inline u16 ks_tx_fifo_space(struct ks_net *ks)
233 {
234         return ks_rdreg16(ks, KS_TXMIR) & 0x1fff;
235 }
236
237 /**
238  * ks_save_cmd_reg - save the command register from the cache.
239  * @ks: The chip information
240  *
241  */
242 static inline void ks_save_cmd_reg(struct ks_net *ks)
243 {
244         /*ks8851 MLL has a bug to read back the command register.
245         * So rely on software to save the content of command register.
246         */
247         ks->cmd_reg_cache_int = ks->cmd_reg_cache;
248 }
249
250 /**
251  * ks_restore_cmd_reg - restore the command register from the cache and
252  *      write to hardware register.
253  * @ks: The chip information
254  *
255  */
256 static inline void ks_restore_cmd_reg(struct ks_net *ks)
257 {
258         ks->cmd_reg_cache = ks->cmd_reg_cache_int;
259         iowrite16(ks->cmd_reg_cache, ks->hw_addr_cmd);
260 }
261
262 /**
263  * ks_set_powermode - set power mode of the device
264  * @ks: The chip information
265  * @pwrmode: The power mode value to write to KS_PMECR.
266  *
267  * Change the power mode of the chip.
268  */
269 static void ks_set_powermode(struct ks_net *ks, unsigned pwrmode)
270 {
271         unsigned pmecr;
272
273         netif_dbg(ks, hw, ks->netdev, "setting power mode %d\n", pwrmode);
274
275         ks_rdreg16(ks, KS_GRR);
276         pmecr = ks_rdreg16(ks, KS_PMECR);
277         pmecr &= ~PMECR_PM_MASK;
278         pmecr |= pwrmode;
279
280         ks_wrreg16(ks, KS_PMECR, pmecr);
281 }
282
283 /**
284  * ks_read_config - read chip configuration of bus width.
285  * @ks: The chip information
286  *
287  */
288 static void ks_read_config(struct ks_net *ks)
289 {
290         u16 reg_data = 0;
291
292         /* Regardless of bus width, 8 bit read should always work.*/
293         reg_data = ks_rdreg16(ks, KS_CCR);
294
295         /* addr/data bus are multiplexed */
296         ks->sharedbus = (reg_data & CCR_SHARED) == CCR_SHARED;
297
298         /* There are garbage data when reading data from QMU,
299         depending on bus-width.
300         */
301
302         if (reg_data & CCR_8BIT) {
303                 ks->bus_width = ENUM_BUS_8BIT;
304                 ks->extra_byte = 1;
305         } else if (reg_data & CCR_16BIT) {
306                 ks->bus_width = ENUM_BUS_16BIT;
307                 ks->extra_byte = 2;
308         } else {
309                 ks->bus_width = ENUM_BUS_32BIT;
310                 ks->extra_byte = 4;
311         }
312 }
313
314 /**
315  * ks_soft_reset - issue one of the soft reset to the device
316  * @ks: The device state.
317  * @op: The bit(s) to set in the GRR
318  *
319  * Issue the relevant soft-reset command to the device's GRR register
320  * specified by @op.
321  *
322  * Note, the delays are in there as a caution to ensure that the reset
323  * has time to take effect and then complete. Since the datasheet does
324  * not currently specify the exact sequence, we have chosen something
325  * that seems to work with our device.
326  */
327 static void ks_soft_reset(struct ks_net *ks, unsigned op)
328 {
329         /* Disable interrupt first */
330         ks_wrreg16(ks, KS_IER, 0x0000);
331         ks_wrreg16(ks, KS_GRR, op);
332         mdelay(10);     /* wait a short time to effect reset */
333         ks_wrreg16(ks, KS_GRR, 0);
334         mdelay(1);      /* wait for condition to clear */
335 }
336
337
338 static void ks_enable_qmu(struct ks_net *ks)
339 {
340         u16 w;
341
342         w = ks_rdreg16(ks, KS_TXCR);
343         /* Enables QMU Transmit (TXCR). */
344         ks_wrreg16(ks, KS_TXCR, w | TXCR_TXE);
345
346         /*
347          * RX Frame Count Threshold Enable and Auto-Dequeue RXQ Frame
348          * Enable
349          */
350
351         w = ks_rdreg16(ks, KS_RXQCR);
352         ks_wrreg16(ks, KS_RXQCR, w | RXQCR_RXFCTE);
353
354         /* Enables QMU Receive (RXCR1). */
355         w = ks_rdreg16(ks, KS_RXCR1);
356         ks_wrreg16(ks, KS_RXCR1, w | RXCR1_RXE);
357         ks->enabled = true;
358 }  /* ks_enable_qmu */
359
360 static void ks_disable_qmu(struct ks_net *ks)
361 {
362         u16     w;
363
364         w = ks_rdreg16(ks, KS_TXCR);
365
366         /* Disables QMU Transmit (TXCR). */
367         w  &= ~TXCR_TXE;
368         ks_wrreg16(ks, KS_TXCR, w);
369
370         /* Disables QMU Receive (RXCR1). */
371         w = ks_rdreg16(ks, KS_RXCR1);
372         w &= ~RXCR1_RXE ;
373         ks_wrreg16(ks, KS_RXCR1, w);
374
375         ks->enabled = false;
376
377 }  /* ks_disable_qmu */
378
379 /**
380  * ks_read_qmu - read 1 pkt data from the QMU.
381  * @ks: The chip information
382  * @buf: buffer address to save 1 pkt
383  * @len: Pkt length
384  * Here is the sequence to read 1 pkt:
385  *      1. set sudo DMA mode
386  *      2. read prepend data
387  *      3. read pkt data
388  *      4. reset sudo DMA Mode
389  */
390 static inline void ks_read_qmu(struct ks_net *ks, u16 *buf, u32 len)
391 {
392         u32 r =  ks->extra_byte & 0x1 ;
393         u32 w = ks->extra_byte - r;
394
395         /* 1. set sudo DMA mode */
396         ks_wrreg16(ks, KS_RXFDPR, RXFDPR_RXFPAI);
397         ks_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr | RXQCR_SDA);
398
399         /* 2. read prepend data */
400         /**
401          * read 4 + extra bytes and discard them.
402          * extra bytes for dummy, 2 for status, 2 for len
403          */
404
405         /* use likely(r) for 8 bit access for performance */
406         if (unlikely(r))
407                 ioread8(ks->hw_addr);
408         ks_inblk(ks, buf, w + 2 + 2);
409
410         /* 3. read pkt data */
411         ks_inblk(ks, buf, ALIGN(len, 4));
412
413         /* 4. reset sudo DMA Mode */
414         ks_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr);
415 }
416
417 /**
418  * ks_rcv - read multiple pkts data from the QMU.
419  * @ks: The chip information
420  * @netdev: The network device being opened.
421  *
422  * Read all of header information before reading pkt content.
423  * It is not allowed only port of pkts in QMU after issuing
424  * interrupt ack.
425  */
426 static void ks_rcv(struct ks_net *ks, struct net_device *netdev)
427 {
428         u32     i;
429         struct type_frame_head *frame_hdr = ks->frame_head_info;
430         struct sk_buff *skb;
431
432         ks->frame_cnt = ks_rdreg16(ks, KS_RXFCTR) >> 8;
433
434         /* read all header information */
435         for (i = 0; i < ks->frame_cnt; i++) {
436                 /* Checking Received packet status */
437                 frame_hdr->sts = ks_rdreg16(ks, KS_RXFHSR);
438                 /* Get packet len from hardware */
439                 frame_hdr->len = ks_rdreg16(ks, KS_RXFHBCR);
440                 frame_hdr++;
441         }
442
443         frame_hdr = ks->frame_head_info;
444         while (ks->frame_cnt--) {
445                 if (unlikely(!(frame_hdr->sts & RXFSHR_RXFV) ||
446                              frame_hdr->len >= RX_BUF_SIZE ||
447                              frame_hdr->len <= 0)) {
448
449                         /* discard an invalid packet */
450                         ks_wrreg16(ks, KS_RXQCR, (ks->rc_rxqcr | RXQCR_RRXEF));
451                         netdev->stats.rx_dropped++;
452                         if (!(frame_hdr->sts & RXFSHR_RXFV))
453                                 netdev->stats.rx_frame_errors++;
454                         else
455                                 netdev->stats.rx_length_errors++;
456                         frame_hdr++;
457                         continue;
458                 }
459
460                 skb = netdev_alloc_skb(netdev, frame_hdr->len + 16);
461                 if (likely(skb)) {
462                         skb_reserve(skb, 2);
463                         /* read data block including CRC 4 bytes */
464                         ks_read_qmu(ks, (u16 *)skb->data, frame_hdr->len);
465                         skb_put(skb, frame_hdr->len - 4);
466                         skb->protocol = eth_type_trans(skb, netdev);
467                         netif_rx(skb);
468                         /* exclude CRC size */
469                         netdev->stats.rx_bytes += frame_hdr->len - 4;
470                         netdev->stats.rx_packets++;
471                 } else {
472                         ks_wrreg16(ks, KS_RXQCR, (ks->rc_rxqcr | RXQCR_RRXEF));
473                         netdev->stats.rx_dropped++;
474                 }
475                 frame_hdr++;
476         }
477 }
478
479 /**
480  * ks_update_link_status - link status update.
481  * @netdev: The network device being opened.
482  * @ks: The chip information
483  *
484  */
485
486 static void ks_update_link_status(struct net_device *netdev, struct ks_net *ks)
487 {
488         /* check the status of the link */
489         u32 link_up_status;
490         if (ks_rdreg16(ks, KS_P1SR) & P1SR_LINK_GOOD) {
491                 netif_carrier_on(netdev);
492                 link_up_status = true;
493         } else {
494                 netif_carrier_off(netdev);
495                 link_up_status = false;
496         }
497         netif_dbg(ks, link, ks->netdev,
498                   "%s: %s\n", __func__, link_up_status ? "UP" : "DOWN");
499 }
500
501 /**
502  * ks_irq - device interrupt handler
503  * @irq: Interrupt number passed from the IRQ handler.
504  * @pw: The private word passed to register_irq(), our struct ks_net.
505  *
506  * This is the handler invoked to find out what happened
507  *
508  * Read the interrupt status, work out what needs to be done and then clear
509  * any of the interrupts that are not needed.
510  */
511
512 static irqreturn_t ks_irq(int irq, void *pw)
513 {
514         struct net_device *netdev = pw;
515         struct ks_net *ks = netdev_priv(netdev);
516         u16 status;
517
518         /*this should be the first in IRQ handler */
519         ks_save_cmd_reg(ks);
520
521         status = ks_rdreg16(ks, KS_ISR);
522         if (unlikely(!status)) {
523                 ks_restore_cmd_reg(ks);
524                 return IRQ_NONE;
525         }
526
527         ks_wrreg16(ks, KS_ISR, status);
528
529         if (likely(status & IRQ_RXI))
530                 ks_rcv(ks, netdev);
531
532         if (unlikely(status & IRQ_LCI))
533                 ks_update_link_status(netdev, ks);
534
535         if (unlikely(status & IRQ_TXI))
536                 netif_wake_queue(netdev);
537
538         if (unlikely(status & IRQ_LDI)) {
539
540                 u16 pmecr = ks_rdreg16(ks, KS_PMECR);
541                 pmecr &= ~PMECR_WKEVT_MASK;
542                 ks_wrreg16(ks, KS_PMECR, pmecr | PMECR_WKEVT_LINK);
543         }
544
545         if (unlikely(status & IRQ_RXOI))
546                 ks->netdev->stats.rx_over_errors++;
547         /* this should be the last in IRQ handler*/
548         ks_restore_cmd_reg(ks);
549         return IRQ_HANDLED;
550 }
551
552
553 /**
554  * ks_net_open - open network device
555  * @netdev: The network device being opened.
556  *
557  * Called when the network device is marked active, such as a user executing
558  * 'ifconfig up' on the device.
559  */
560 static int ks_net_open(struct net_device *netdev)
561 {
562         struct ks_net *ks = netdev_priv(netdev);
563         int err;
564
565 #define KS_INT_FLAGS    IRQF_TRIGGER_LOW
566         /* lock the card, even if we may not actually do anything
567          * else at the moment.
568          */
569
570         netif_dbg(ks, ifup, ks->netdev, "%s - entry\n", __func__);
571
572         /* reset the HW */
573         err = request_irq(netdev->irq, ks_irq, KS_INT_FLAGS, DRV_NAME, netdev);
574
575         if (err) {
576                 pr_err("Failed to request IRQ: %d: %d\n", netdev->irq, err);
577                 return err;
578         }
579
580         /* wake up powermode to normal mode */
581         ks_set_powermode(ks, PMECR_PM_NORMAL);
582         mdelay(1);      /* wait for normal mode to take effect */
583
584         ks_wrreg16(ks, KS_ISR, 0xffff);
585         ks_enable_int(ks);
586         ks_enable_qmu(ks);
587         netif_start_queue(ks->netdev);
588
589         netif_dbg(ks, ifup, ks->netdev, "network device up\n");
590
591         return 0;
592 }
593
594 /**
595  * ks_net_stop - close network device
596  * @netdev: The device being closed.
597  *
598  * Called to close down a network device which has been active. Cancell any
599  * work, shutdown the RX and TX process and then place the chip into a low
600  * power state whilst it is not being used.
601  */
602 static int ks_net_stop(struct net_device *netdev)
603 {
604         struct ks_net *ks = netdev_priv(netdev);
605
606         netif_info(ks, ifdown, netdev, "shutting down\n");
607
608         netif_stop_queue(netdev);
609
610         mutex_lock(&ks->lock);
611
612         /* turn off the IRQs and ack any outstanding */
613         ks_wrreg16(ks, KS_IER, 0x0000);
614         ks_wrreg16(ks, KS_ISR, 0xffff);
615
616         /* shutdown RX/TX QMU */
617         ks_disable_qmu(ks);
618
619         /* set powermode to soft power down to save power */
620         ks_set_powermode(ks, PMECR_PM_SOFTDOWN);
621         free_irq(netdev->irq, netdev);
622         mutex_unlock(&ks->lock);
623         return 0;
624 }
625
626
627 /**
628  * ks_write_qmu - write 1 pkt data to the QMU.
629  * @ks: The chip information
630  * @pdata: buffer address to save 1 pkt
631  * @len: Pkt length in byte
632  * Here is the sequence to write 1 pkt:
633  *      1. set sudo DMA mode
634  *      2. write status/length
635  *      3. write pkt data
636  *      4. reset sudo DMA Mode
637  *      5. reset sudo DMA mode
638  *      6. Wait until pkt is out
639  */
640 static void ks_write_qmu(struct ks_net *ks, u8 *pdata, u16 len)
641 {
642         /* start header at txb[0] to align txw entries */
643         ks->txh.txw[0] = 0;
644         ks->txh.txw[1] = cpu_to_le16(len);
645
646         /* 1. set sudo-DMA mode */
647         ks_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr | RXQCR_SDA);
648         /* 2. write status/lenth info */
649         ks_outblk(ks, ks->txh.txw, 4);
650         /* 3. write pkt data */
651         ks_outblk(ks, (u16 *)pdata, ALIGN(len, 4));
652         /* 4. reset sudo-DMA mode */
653         ks_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr);
654         /* 5. Enqueue Tx(move the pkt from TX buffer into TXQ) */
655         ks_wrreg16(ks, KS_TXQCR, TXQCR_METFE);
656         /* 6. wait until TXQCR_METFE is auto-cleared */
657         while (ks_rdreg16(ks, KS_TXQCR) & TXQCR_METFE)
658                 ;
659 }
660
661 /**
662  * ks_start_xmit - transmit packet
663  * @skb         : The buffer to transmit
664  * @netdev      : The device used to transmit the packet.
665  *
666  * Called by the network layer to transmit the @skb.
667  * spin_lock_irqsave is required because tx and rx should be mutual exclusive.
668  * So while tx is in-progress, prevent IRQ interrupt from happenning.
669  */
670 static netdev_tx_t ks_start_xmit(struct sk_buff *skb, struct net_device *netdev)
671 {
672         netdev_tx_t retv = NETDEV_TX_OK;
673         struct ks_net *ks = netdev_priv(netdev);
674
675         disable_irq(netdev->irq);
676         ks_disable_int(ks);
677         spin_lock(&ks->statelock);
678
679         /* Extra space are required:
680         *  4 byte for alignment, 4 for status/length, 4 for CRC
681         */
682
683         if (likely(ks_tx_fifo_space(ks) >= skb->len + 12)) {
684                 ks_write_qmu(ks, skb->data, skb->len);
685                 /* add tx statistics */
686                 netdev->stats.tx_bytes += skb->len;
687                 netdev->stats.tx_packets++;
688                 dev_kfree_skb(skb);
689         } else
690                 retv = NETDEV_TX_BUSY;
691         spin_unlock(&ks->statelock);
692         ks_enable_int(ks);
693         enable_irq(netdev->irq);
694         return retv;
695 }
696
697 /**
698  * ks_start_rx - ready to serve pkts
699  * @ks          : The chip information
700  *
701  */
702 static void ks_start_rx(struct ks_net *ks)
703 {
704         u16 cntl;
705
706         /* Enables QMU Receive (RXCR1). */
707         cntl = ks_rdreg16(ks, KS_RXCR1);
708         cntl |= RXCR1_RXE ;
709         ks_wrreg16(ks, KS_RXCR1, cntl);
710 }  /* ks_start_rx */
711
712 /**
713  * ks_stop_rx - stop to serve pkts
714  * @ks          : The chip information
715  *
716  */
717 static void ks_stop_rx(struct ks_net *ks)
718 {
719         u16 cntl;
720
721         /* Disables QMU Receive (RXCR1). */
722         cntl = ks_rdreg16(ks, KS_RXCR1);
723         cntl &= ~RXCR1_RXE ;
724         ks_wrreg16(ks, KS_RXCR1, cntl);
725
726 }  /* ks_stop_rx */
727
728 static unsigned long const ethernet_polynomial = CRC32_POLY_BE;
729
730 static unsigned long ether_gen_crc(int length, u8 *data)
731 {
732         long crc = -1;
733         while (--length >= 0) {
734                 u8 current_octet = *data++;
735                 int bit;
736
737                 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
738                         crc = (crc << 1) ^
739                                 ((crc < 0) ^ (current_octet & 1) ?
740                         ethernet_polynomial : 0);
741                 }
742         }
743         return (unsigned long)crc;
744 }  /* ether_gen_crc */
745
746 /**
747 * ks_set_grpaddr - set multicast information
748 * @ks : The chip information
749 */
750
751 static void ks_set_grpaddr(struct ks_net *ks)
752 {
753         u8      i;
754         u32     index, position, value;
755
756         memset(ks->mcast_bits, 0, sizeof(u8) * HW_MCAST_SIZE);
757
758         for (i = 0; i < ks->mcast_lst_size; i++) {
759                 position = (ether_gen_crc(6, ks->mcast_lst[i]) >> 26) & 0x3f;
760                 index = position >> 3;
761                 value = 1 << (position & 7);
762                 ks->mcast_bits[index] |= (u8)value;
763         }
764
765         for (i  = 0; i < HW_MCAST_SIZE; i++) {
766                 if (i & 1) {
767                         ks_wrreg16(ks, (u16)((KS_MAHTR0 + i) & ~1),
768                                 (ks->mcast_bits[i] << 8) |
769                                 ks->mcast_bits[i - 1]);
770                 }
771         }
772 }  /* ks_set_grpaddr */
773
774 /**
775 * ks_clear_mcast - clear multicast information
776 *
777 * @ks : The chip information
778 * This routine removes all mcast addresses set in the hardware.
779 */
780
781 static void ks_clear_mcast(struct ks_net *ks)
782 {
783         u16     i, mcast_size;
784         for (i = 0; i < HW_MCAST_SIZE; i++)
785                 ks->mcast_bits[i] = 0;
786
787         mcast_size = HW_MCAST_SIZE >> 2;
788         for (i = 0; i < mcast_size; i++)
789                 ks_wrreg16(ks, KS_MAHTR0 + (2*i), 0);
790 }
791
792 static void ks_set_promis(struct ks_net *ks, u16 promiscuous_mode)
793 {
794         u16             cntl;
795         ks->promiscuous = promiscuous_mode;
796         ks_stop_rx(ks);  /* Stop receiving for reconfiguration */
797         cntl = ks_rdreg16(ks, KS_RXCR1);
798
799         cntl &= ~RXCR1_FILTER_MASK;
800         if (promiscuous_mode)
801                 /* Enable Promiscuous mode */
802                 cntl |= RXCR1_RXAE | RXCR1_RXINVF;
803         else
804                 /* Disable Promiscuous mode (default normal mode) */
805                 cntl |= RXCR1_RXPAFMA;
806
807         ks_wrreg16(ks, KS_RXCR1, cntl);
808
809         if (ks->enabled)
810                 ks_start_rx(ks);
811
812 }  /* ks_set_promis */
813
814 static void ks_set_mcast(struct ks_net *ks, u16 mcast)
815 {
816         u16     cntl;
817
818         ks->all_mcast = mcast;
819         ks_stop_rx(ks);  /* Stop receiving for reconfiguration */
820         cntl = ks_rdreg16(ks, KS_RXCR1);
821         cntl &= ~RXCR1_FILTER_MASK;
822         if (mcast)
823                 /* Enable "Perfect with Multicast address passed mode" */
824                 cntl |= (RXCR1_RXAE | RXCR1_RXMAFMA | RXCR1_RXPAFMA);
825         else
826                 /**
827                  * Disable "Perfect with Multicast address passed
828                  * mode" (normal mode).
829                  */
830                 cntl |= RXCR1_RXPAFMA;
831
832         ks_wrreg16(ks, KS_RXCR1, cntl);
833
834         if (ks->enabled)
835                 ks_start_rx(ks);
836 }  /* ks_set_mcast */
837
838 static void ks_set_rx_mode(struct net_device *netdev)
839 {
840         struct ks_net *ks = netdev_priv(netdev);
841         struct netdev_hw_addr *ha;
842
843         /* Turn on/off promiscuous mode. */
844         if ((netdev->flags & IFF_PROMISC) == IFF_PROMISC)
845                 ks_set_promis(ks,
846                         (u16)((netdev->flags & IFF_PROMISC) == IFF_PROMISC));
847         /* Turn on/off all mcast mode. */
848         else if ((netdev->flags & IFF_ALLMULTI) == IFF_ALLMULTI)
849                 ks_set_mcast(ks,
850                         (u16)((netdev->flags & IFF_ALLMULTI) == IFF_ALLMULTI));
851         else
852                 ks_set_promis(ks, false);
853
854         if ((netdev->flags & IFF_MULTICAST) && netdev_mc_count(netdev)) {
855                 if (netdev_mc_count(netdev) <= MAX_MCAST_LST) {
856                         int i = 0;
857
858                         netdev_for_each_mc_addr(ha, netdev) {
859                                 if (i >= MAX_MCAST_LST)
860                                         break;
861                                 memcpy(ks->mcast_lst[i++], ha->addr, ETH_ALEN);
862                         }
863                         ks->mcast_lst_size = (u8)i;
864                         ks_set_grpaddr(ks);
865                 } else {
866                         /**
867                          * List too big to support so
868                          * turn on all mcast mode.
869                          */
870                         ks->mcast_lst_size = MAX_MCAST_LST;
871                         ks_set_mcast(ks, true);
872                 }
873         } else {
874                 ks->mcast_lst_size = 0;
875                 ks_clear_mcast(ks);
876         }
877 } /* ks_set_rx_mode */
878
879 static void ks_set_mac(struct ks_net *ks, u8 *data)
880 {
881         u16 *pw = (u16 *)data;
882         u16 w, u;
883
884         ks_stop_rx(ks);  /* Stop receiving for reconfiguration */
885
886         u = *pw++;
887         w = ((u & 0xFF) << 8) | ((u >> 8) & 0xFF);
888         ks_wrreg16(ks, KS_MARH, w);
889
890         u = *pw++;
891         w = ((u & 0xFF) << 8) | ((u >> 8) & 0xFF);
892         ks_wrreg16(ks, KS_MARM, w);
893
894         u = *pw;
895         w = ((u & 0xFF) << 8) | ((u >> 8) & 0xFF);
896         ks_wrreg16(ks, KS_MARL, w);
897
898         memcpy(ks->mac_addr, data, ETH_ALEN);
899
900         if (ks->enabled)
901                 ks_start_rx(ks);
902 }
903
904 static int ks_set_mac_address(struct net_device *netdev, void *paddr)
905 {
906         struct ks_net *ks = netdev_priv(netdev);
907         struct sockaddr *addr = paddr;
908         u8 *da;
909
910         memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
911
912         da = (u8 *)netdev->dev_addr;
913
914         ks_set_mac(ks, da);
915         return 0;
916 }
917
918 static int ks_net_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
919 {
920         struct ks_net *ks = netdev_priv(netdev);
921
922         if (!netif_running(netdev))
923                 return -EINVAL;
924
925         return generic_mii_ioctl(&ks->mii, if_mii(req), cmd, NULL);
926 }
927
928 static const struct net_device_ops ks_netdev_ops = {
929         .ndo_open               = ks_net_open,
930         .ndo_stop               = ks_net_stop,
931         .ndo_do_ioctl           = ks_net_ioctl,
932         .ndo_start_xmit         = ks_start_xmit,
933         .ndo_set_mac_address    = ks_set_mac_address,
934         .ndo_set_rx_mode        = ks_set_rx_mode,
935         .ndo_validate_addr      = eth_validate_addr,
936 };
937
938 /* ethtool support */
939
940 static void ks_get_drvinfo(struct net_device *netdev,
941                                struct ethtool_drvinfo *di)
942 {
943         strlcpy(di->driver, DRV_NAME, sizeof(di->driver));
944         strlcpy(di->version, "1.00", sizeof(di->version));
945         strlcpy(di->bus_info, dev_name(netdev->dev.parent),
946                 sizeof(di->bus_info));
947 }
948
949 static u32 ks_get_msglevel(struct net_device *netdev)
950 {
951         struct ks_net *ks = netdev_priv(netdev);
952         return ks->msg_enable;
953 }
954
955 static void ks_set_msglevel(struct net_device *netdev, u32 to)
956 {
957         struct ks_net *ks = netdev_priv(netdev);
958         ks->msg_enable = to;
959 }
960
961 static int ks_get_link_ksettings(struct net_device *netdev,
962                                  struct ethtool_link_ksettings *cmd)
963 {
964         struct ks_net *ks = netdev_priv(netdev);
965
966         mii_ethtool_get_link_ksettings(&ks->mii, cmd);
967
968         return 0;
969 }
970
971 static int ks_set_link_ksettings(struct net_device *netdev,
972                                  const struct ethtool_link_ksettings *cmd)
973 {
974         struct ks_net *ks = netdev_priv(netdev);
975         return mii_ethtool_set_link_ksettings(&ks->mii, cmd);
976 }
977
978 static u32 ks_get_link(struct net_device *netdev)
979 {
980         struct ks_net *ks = netdev_priv(netdev);
981         return mii_link_ok(&ks->mii);
982 }
983
984 static int ks_nway_reset(struct net_device *netdev)
985 {
986         struct ks_net *ks = netdev_priv(netdev);
987         return mii_nway_restart(&ks->mii);
988 }
989
990 static const struct ethtool_ops ks_ethtool_ops = {
991         .get_drvinfo    = ks_get_drvinfo,
992         .get_msglevel   = ks_get_msglevel,
993         .set_msglevel   = ks_set_msglevel,
994         .get_link       = ks_get_link,
995         .nway_reset     = ks_nway_reset,
996         .get_link_ksettings = ks_get_link_ksettings,
997         .set_link_ksettings = ks_set_link_ksettings,
998 };
999
1000 /* MII interface controls */
1001
1002 /**
1003  * ks_phy_reg - convert MII register into a KS8851 register
1004  * @reg: MII register number.
1005  *
1006  * Return the KS8851 register number for the corresponding MII PHY register
1007  * if possible. Return zero if the MII register has no direct mapping to the
1008  * KS8851 register set.
1009  */
1010 static int ks_phy_reg(int reg)
1011 {
1012         switch (reg) {
1013         case MII_BMCR:
1014                 return KS_P1MBCR;
1015         case MII_BMSR:
1016                 return KS_P1MBSR;
1017         case MII_PHYSID1:
1018                 return KS_PHY1ILR;
1019         case MII_PHYSID2:
1020                 return KS_PHY1IHR;
1021         case MII_ADVERTISE:
1022                 return KS_P1ANAR;
1023         case MII_LPA:
1024                 return KS_P1ANLPR;
1025         }
1026
1027         return 0x0;
1028 }
1029
1030 /**
1031  * ks_phy_read - MII interface PHY register read.
1032  * @netdev: The network device the PHY is on.
1033  * @phy_addr: Address of PHY (ignored as we only have one)
1034  * @reg: The register to read.
1035  *
1036  * This call reads data from the PHY register specified in @reg. Since the
1037  * device does not support all the MII registers, the non-existent values
1038  * are always returned as zero.
1039  *
1040  * We return zero for unsupported registers as the MII code does not check
1041  * the value returned for any error status, and simply returns it to the
1042  * caller. The mii-tool that the driver was tested with takes any -ve error
1043  * as real PHY capabilities, thus displaying incorrect data to the user.
1044  */
1045 static int ks_phy_read(struct net_device *netdev, int phy_addr, int reg)
1046 {
1047         struct ks_net *ks = netdev_priv(netdev);
1048         int ksreg;
1049         int result;
1050
1051         ksreg = ks_phy_reg(reg);
1052         if (!ksreg)
1053                 return 0x0;     /* no error return allowed, so use zero */
1054
1055         mutex_lock(&ks->lock);
1056         result = ks_rdreg16(ks, ksreg);
1057         mutex_unlock(&ks->lock);
1058
1059         return result;
1060 }
1061
1062 static void ks_phy_write(struct net_device *netdev,
1063                              int phy, int reg, int value)
1064 {
1065         struct ks_net *ks = netdev_priv(netdev);
1066         int ksreg;
1067
1068         ksreg = ks_phy_reg(reg);
1069         if (ksreg) {
1070                 mutex_lock(&ks->lock);
1071                 ks_wrreg16(ks, ksreg, value);
1072                 mutex_unlock(&ks->lock);
1073         }
1074 }
1075
1076 /**
1077  * ks_read_selftest - read the selftest memory info.
1078  * @ks: The device state
1079  *
1080  * Read and check the TX/RX memory selftest information.
1081  */
1082 static int ks_read_selftest(struct ks_net *ks)
1083 {
1084         unsigned both_done = MBIR_TXMBF | MBIR_RXMBF;
1085         int ret = 0;
1086         unsigned rd;
1087
1088         rd = ks_rdreg16(ks, KS_MBIR);
1089
1090         if ((rd & both_done) != both_done) {
1091                 netdev_warn(ks->netdev, "Memory selftest not finished\n");
1092                 return 0;
1093         }
1094
1095         if (rd & MBIR_TXMBFA) {
1096                 netdev_err(ks->netdev, "TX memory selftest fails\n");
1097                 ret |= 1;
1098         }
1099
1100         if (rd & MBIR_RXMBFA) {
1101                 netdev_err(ks->netdev, "RX memory selftest fails\n");
1102                 ret |= 2;
1103         }
1104
1105         netdev_info(ks->netdev, "the selftest passes\n");
1106         return ret;
1107 }
1108
1109 static void ks_setup(struct ks_net *ks)
1110 {
1111         u16     w;
1112
1113         /**
1114          * Configure QMU Transmit
1115          */
1116
1117         /* Setup Transmit Frame Data Pointer Auto-Increment (TXFDPR) */
1118         ks_wrreg16(ks, KS_TXFDPR, TXFDPR_TXFPAI);
1119
1120         /* Setup Receive Frame Data Pointer Auto-Increment */
1121         ks_wrreg16(ks, KS_RXFDPR, RXFDPR_RXFPAI);
1122
1123         /* Setup Receive Frame Threshold - 1 frame (RXFCTFC) */
1124         ks_wrreg16(ks, KS_RXFCTR, 1 & RXFCTR_RXFCT_MASK);
1125
1126         /* Setup RxQ Command Control (RXQCR) */
1127         ks->rc_rxqcr = RXQCR_CMD_CNTL;
1128         ks_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr);
1129
1130         /**
1131          * set the force mode to half duplex, default is full duplex
1132          *  because if the auto-negotiation fails, most switch uses
1133          *  half-duplex.
1134          */
1135
1136         w = ks_rdreg16(ks, KS_P1MBCR);
1137         w &= ~BMCR_FULLDPLX;
1138         ks_wrreg16(ks, KS_P1MBCR, w);
1139
1140         w = TXCR_TXFCE | TXCR_TXPE | TXCR_TXCRC | TXCR_TCGIP;
1141         ks_wrreg16(ks, KS_TXCR, w);
1142
1143         w = RXCR1_RXFCE | RXCR1_RXBE | RXCR1_RXUE | RXCR1_RXME | RXCR1_RXIPFCC;
1144
1145         if (ks->promiscuous)         /* bPromiscuous */
1146                 w |= (RXCR1_RXAE | RXCR1_RXINVF);
1147         else if (ks->all_mcast) /* Multicast address passed mode */
1148                 w |= (RXCR1_RXAE | RXCR1_RXMAFMA | RXCR1_RXPAFMA);
1149         else                                   /* Normal mode */
1150                 w |= RXCR1_RXPAFMA;
1151
1152         ks_wrreg16(ks, KS_RXCR1, w);
1153 }  /*ks_setup */
1154
1155
1156 static void ks_setup_int(struct ks_net *ks)
1157 {
1158         ks->rc_ier = 0x00;
1159         /* Clear the interrupts status of the hardware. */
1160         ks_wrreg16(ks, KS_ISR, 0xffff);
1161
1162         /* Enables the interrupts of the hardware. */
1163         ks->rc_ier = (IRQ_LCI | IRQ_TXI | IRQ_RXI);
1164 }  /* ks_setup_int */
1165
1166 static int ks_hw_init(struct ks_net *ks)
1167 {
1168 #define MHEADER_SIZE    (sizeof(struct type_frame_head) * MAX_RECV_FRAMES)
1169         ks->promiscuous = 0;
1170         ks->all_mcast = 0;
1171         ks->mcast_lst_size = 0;
1172
1173         ks->frame_head_info = devm_kmalloc(&ks->pdev->dev, MHEADER_SIZE,
1174                                            GFP_KERNEL);
1175         if (!ks->frame_head_info)
1176                 return false;
1177
1178         ks_set_mac(ks, KS_DEFAULT_MAC_ADDRESS);
1179         return true;
1180 }
1181
1182 #if defined(CONFIG_OF)
1183 static const struct of_device_id ks8851_ml_dt_ids[] = {
1184         { .compatible = "micrel,ks8851-mll" },
1185         { /* sentinel */ }
1186 };
1187 MODULE_DEVICE_TABLE(of, ks8851_ml_dt_ids);
1188 #endif
1189
1190 static int ks8851_probe(struct platform_device *pdev)
1191 {
1192         int err;
1193         struct net_device *netdev;
1194         struct ks_net *ks;
1195         u16 id, data;
1196         const char *mac;
1197
1198         netdev = alloc_etherdev(sizeof(struct ks_net));
1199         if (!netdev)
1200                 return -ENOMEM;
1201
1202         SET_NETDEV_DEV(netdev, &pdev->dev);
1203
1204         ks = netdev_priv(netdev);
1205         ks->netdev = netdev;
1206
1207         ks->hw_addr = devm_platform_ioremap_resource(pdev, 0);
1208         if (IS_ERR(ks->hw_addr)) {
1209                 err = PTR_ERR(ks->hw_addr);
1210                 goto err_free;
1211         }
1212
1213         ks->hw_addr_cmd = devm_platform_ioremap_resource(pdev, 1);
1214         if (IS_ERR(ks->hw_addr_cmd)) {
1215                 err = PTR_ERR(ks->hw_addr_cmd);
1216                 goto err_free;
1217         }
1218
1219         netdev->irq = platform_get_irq(pdev, 0);
1220
1221         if ((int)netdev->irq < 0) {
1222                 err = netdev->irq;
1223                 goto err_free;
1224         }
1225
1226         ks->pdev = pdev;
1227
1228         mutex_init(&ks->lock);
1229         spin_lock_init(&ks->statelock);
1230
1231         netdev->netdev_ops = &ks_netdev_ops;
1232         netdev->ethtool_ops = &ks_ethtool_ops;
1233
1234         /* setup mii state */
1235         ks->mii.dev             = netdev;
1236         ks->mii.phy_id          = 1,
1237         ks->mii.phy_id_mask     = 1;
1238         ks->mii.reg_num_mask    = 0xf;
1239         ks->mii.mdio_read       = ks_phy_read;
1240         ks->mii.mdio_write      = ks_phy_write;
1241
1242         netdev_info(netdev, "message enable is %d\n", msg_enable);
1243         /* set the default message enable */
1244         ks->msg_enable = netif_msg_init(msg_enable, (NETIF_MSG_DRV |
1245                                                      NETIF_MSG_PROBE |
1246                                                      NETIF_MSG_LINK));
1247         ks_read_config(ks);
1248
1249         /* simple check for a valid chip being connected to the bus */
1250         if ((ks_rdreg16(ks, KS_CIDER) & ~CIDER_REV_MASK) != CIDER_ID) {
1251                 netdev_err(netdev, "failed to read device ID\n");
1252                 err = -ENODEV;
1253                 goto err_free;
1254         }
1255
1256         if (ks_read_selftest(ks)) {
1257                 netdev_err(netdev, "failed to read device ID\n");
1258                 err = -ENODEV;
1259                 goto err_free;
1260         }
1261
1262         err = register_netdev(netdev);
1263         if (err)
1264                 goto err_free;
1265
1266         platform_set_drvdata(pdev, netdev);
1267
1268         ks_soft_reset(ks, GRR_GSR);
1269         ks_hw_init(ks);
1270         ks_disable_qmu(ks);
1271         ks_setup(ks);
1272         ks_setup_int(ks);
1273
1274         data = ks_rdreg16(ks, KS_OBCR);
1275         ks_wrreg16(ks, KS_OBCR, data | OBCR_ODS_16mA);
1276
1277         /* overwriting the default MAC address */
1278         if (pdev->dev.of_node) {
1279                 mac = of_get_mac_address(pdev->dev.of_node);
1280                 if (!IS_ERR(mac))
1281                         ether_addr_copy(ks->mac_addr, mac);
1282         } else {
1283                 struct ks8851_mll_platform_data *pdata;
1284
1285                 pdata = dev_get_platdata(&pdev->dev);
1286                 if (!pdata) {
1287                         netdev_err(netdev, "No platform data\n");
1288                         err = -ENODEV;
1289                         goto err_pdata;
1290                 }
1291                 memcpy(ks->mac_addr, pdata->mac_addr, ETH_ALEN);
1292         }
1293         if (!is_valid_ether_addr(ks->mac_addr)) {
1294                 /* Use random MAC address if none passed */
1295                 eth_random_addr(ks->mac_addr);
1296                 netdev_info(netdev, "Using random mac address\n");
1297         }
1298         netdev_info(netdev, "Mac address is: %pM\n", ks->mac_addr);
1299
1300         memcpy(netdev->dev_addr, ks->mac_addr, ETH_ALEN);
1301
1302         ks_set_mac(ks, netdev->dev_addr);
1303
1304         id = ks_rdreg16(ks, KS_CIDER);
1305
1306         netdev_info(netdev, "Found chip, family: 0x%x, id: 0x%x, rev: 0x%x\n",
1307                     (id >> 8) & 0xff, (id >> 4) & 0xf, (id >> 1) & 0x7);
1308         return 0;
1309
1310 err_pdata:
1311         unregister_netdev(netdev);
1312 err_free:
1313         free_netdev(netdev);
1314         return err;
1315 }
1316
1317 static int ks8851_remove(struct platform_device *pdev)
1318 {
1319         struct net_device *netdev = platform_get_drvdata(pdev);
1320
1321         unregister_netdev(netdev);
1322         free_netdev(netdev);
1323         return 0;
1324
1325 }
1326
1327 static struct platform_driver ks8851_platform_driver = {
1328         .driver = {
1329                 .name = DRV_NAME,
1330                 .of_match_table = of_match_ptr(ks8851_ml_dt_ids),
1331         },
1332         .probe = ks8851_probe,
1333         .remove = ks8851_remove,
1334 };
1335
1336 module_platform_driver(ks8851_platform_driver);
1337
1338 MODULE_DESCRIPTION("KS8851 MLL Network driver");
1339 MODULE_AUTHOR("David Choi <david.choi@micrel.com>");
1340 MODULE_LICENSE("GPL");
1341 module_param_named(message, msg_enable, int, 0);
1342 MODULE_PARM_DESC(message, "Message verbosity level (0=none, 31=all)");
1343