blob: 39b0aea2aab3ff71a51d2d049d654157782eb73f [file] [log] [blame]
Richard Ršöjforsb07878e2009-06-04 03:35:55 +00001/*
2 * ks8842_main.c timberdale KS8842 ethernet driver
3 * Copyright (c) 2009 Intel Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/* Supports:
20 * The Micrel KS8842 behind the timberdale FPGA
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/platform_device.h>
26#include <linux/netdevice.h>
27#include <linux/etherdevice.h>
28#include <linux/ethtool.h>
29
30#define DRV_NAME "ks8842"
31
32/* Timberdale specific Registers */
33#define REG_TIMB_RST 0x1c
34
35/* KS8842 registers */
36
37#define REG_SELECT_BANK 0x0e
38
39/* bank 0 registers */
40#define REG_QRFCR 0x04
41
42/* bank 2 registers */
43#define REG_MARL 0x00
44#define REG_MARM 0x02
45#define REG_MARH 0x04
46
47/* bank 3 registers */
48#define REG_GRR 0x06
49
50/* bank 16 registers */
51#define REG_TXCR 0x00
52#define REG_TXSR 0x02
53#define REG_RXCR 0x04
54#define REG_TXMIR 0x08
55#define REG_RXMIR 0x0A
56
57/* bank 17 registers */
58#define REG_TXQCR 0x00
59#define REG_RXQCR 0x02
60#define REG_TXFDPR 0x04
61#define REG_RXFDPR 0x06
62#define REG_QMU_DATA_LO 0x08
63#define REG_QMU_DATA_HI 0x0A
64
65/* bank 18 registers */
66#define REG_IER 0x00
67#define IRQ_LINK_CHANGE 0x8000
68#define IRQ_TX 0x4000
69#define IRQ_RX 0x2000
70#define IRQ_RX_OVERRUN 0x0800
71#define IRQ_TX_STOPPED 0x0200
72#define IRQ_RX_STOPPED 0x0100
73#define IRQ_RX_ERROR 0x0080
74#define ENABLED_IRQS (IRQ_LINK_CHANGE | IRQ_TX | IRQ_RX | IRQ_RX_STOPPED | \
75 IRQ_TX_STOPPED | IRQ_RX_OVERRUN | IRQ_RX_ERROR)
76#define REG_ISR 0x02
77#define REG_RXSR 0x04
78#define RXSR_VALID 0x8000
79#define RXSR_BROADCAST 0x80
80#define RXSR_MULTICAST 0x40
81#define RXSR_UNICAST 0x20
82#define RXSR_FRAMETYPE 0x08
83#define RXSR_TOO_LONG 0x04
84#define RXSR_RUNT 0x02
85#define RXSR_CRC_ERROR 0x01
86#define RXSR_ERROR (RXSR_TOO_LONG | RXSR_RUNT | RXSR_CRC_ERROR)
87
88/* bank 32 registers */
89#define REG_SW_ID_AND_ENABLE 0x00
90#define REG_SGCR1 0x02
91#define REG_SGCR2 0x04
92#define REG_SGCR3 0x06
93
94/* bank 39 registers */
95#define REG_MACAR1 0x00
96#define REG_MACAR2 0x02
97#define REG_MACAR3 0x04
98
99/* bank 45 registers */
100#define REG_P1MBCR 0x00
101#define REG_P1MBSR 0x02
102
103/* bank 46 registers */
104#define REG_P2MBCR 0x00
105#define REG_P2MBSR 0x02
106
107/* bank 48 registers */
108#define REG_P1CR2 0x02
109
110/* bank 49 registers */
111#define REG_P1CR4 0x02
112#define REG_P1SR 0x04
113
114struct ks8842_adapter {
115 void __iomem *hw_addr;
116 int irq;
117 struct tasklet_struct tasklet;
118 spinlock_t lock; /* spinlock to be interrupt safe */
119 struct platform_device *pdev;
120};
121
122static inline void ks8842_select_bank(struct ks8842_adapter *adapter, u16 bank)
123{
124 iowrite16(bank, adapter->hw_addr + REG_SELECT_BANK);
125}
126
127static inline void ks8842_write8(struct ks8842_adapter *adapter, u16 bank,
128 u8 value, int offset)
129{
130 ks8842_select_bank(adapter, bank);
131 iowrite8(value, adapter->hw_addr + offset);
132}
133
134static inline void ks8842_write16(struct ks8842_adapter *adapter, u16 bank,
135 u16 value, int offset)
136{
137 ks8842_select_bank(adapter, bank);
138 iowrite16(value, adapter->hw_addr + offset);
139}
140
141static inline void ks8842_enable_bits(struct ks8842_adapter *adapter, u16 bank,
142 u16 bits, int offset)
143{
144 u16 reg;
145 ks8842_select_bank(adapter, bank);
146 reg = ioread16(adapter->hw_addr + offset);
147 reg |= bits;
148 iowrite16(reg, adapter->hw_addr + offset);
149}
150
151static inline void ks8842_clear_bits(struct ks8842_adapter *adapter, u16 bank,
152 u16 bits, int offset)
153{
154 u16 reg;
155 ks8842_select_bank(adapter, bank);
156 reg = ioread16(adapter->hw_addr + offset);
157 reg &= ~bits;
158 iowrite16(reg, adapter->hw_addr + offset);
159}
160
161static inline void ks8842_write32(struct ks8842_adapter *adapter, u16 bank,
162 u32 value, int offset)
163{
164 ks8842_select_bank(adapter, bank);
165 iowrite32(value, adapter->hw_addr + offset);
166}
167
168static inline u8 ks8842_read8(struct ks8842_adapter *adapter, u16 bank,
169 int offset)
170{
171 ks8842_select_bank(adapter, bank);
172 return ioread8(adapter->hw_addr + offset);
173}
174
175static inline u16 ks8842_read16(struct ks8842_adapter *adapter, u16 bank,
176 int offset)
177{
178 ks8842_select_bank(adapter, bank);
179 return ioread16(adapter->hw_addr + offset);
180}
181
182static inline u32 ks8842_read32(struct ks8842_adapter *adapter, u16 bank,
183 int offset)
184{
185 ks8842_select_bank(adapter, bank);
186 return ioread32(adapter->hw_addr + offset);
187}
188
189static void ks8842_reset(struct ks8842_adapter *adapter)
190{
191 /* The KS8842 goes haywire when doing softare reset
192 * a work around in the timberdale IP is implemented to
193 * do a hardware reset instead
194 ks8842_write16(adapter, 3, 1, REG_GRR);
195 msleep(10);
196 iowrite16(0, adapter->hw_addr + REG_GRR);
197 */
198 iowrite16(32, adapter->hw_addr + REG_SELECT_BANK);
199 iowrite32(0x1, adapter->hw_addr + REG_TIMB_RST);
200 msleep(20);
201}
202
203static void ks8842_update_link_status(struct net_device *netdev,
204 struct ks8842_adapter *adapter)
205{
206 /* check the status of the link */
207 if (ks8842_read16(adapter, 45, REG_P1MBSR) & 0x4) {
208 netif_carrier_on(netdev);
209 netif_wake_queue(netdev);
210 } else {
211 netif_stop_queue(netdev);
212 netif_carrier_off(netdev);
213 }
214}
215
216static void ks8842_enable_tx(struct ks8842_adapter *adapter)
217{
218 ks8842_enable_bits(adapter, 16, 0x01, REG_TXCR);
219}
220
221static void ks8842_disable_tx(struct ks8842_adapter *adapter)
222{
223 ks8842_clear_bits(adapter, 16, 0x01, REG_TXCR);
224}
225
226static void ks8842_enable_rx(struct ks8842_adapter *adapter)
227{
228 ks8842_enable_bits(adapter, 16, 0x01, REG_RXCR);
229}
230
231static void ks8842_disable_rx(struct ks8842_adapter *adapter)
232{
233 ks8842_clear_bits(adapter, 16, 0x01, REG_RXCR);
234}
235
236static void ks8842_reset_hw(struct ks8842_adapter *adapter)
237{
238 /* reset the HW */
239 ks8842_reset(adapter);
240
241 /* Enable QMU Transmit flow control / transmit padding / Transmit CRC */
242 ks8842_write16(adapter, 16, 0x000E, REG_TXCR);
243
244 /* enable the receiver, uni + multi + broadcast + flow ctrl
245 + crc strip */
246 ks8842_write16(adapter, 16, 0x8 | 0x20 | 0x40 | 0x80 | 0x400,
247 REG_RXCR);
248
249 /* TX frame pointer autoincrement */
250 ks8842_write16(adapter, 17, 0x4000, REG_TXFDPR);
251
252 /* RX frame pointer autoincrement */
253 ks8842_write16(adapter, 17, 0x4000, REG_RXFDPR);
254
255 /* RX 2 kb high watermark */
256 ks8842_write16(adapter, 0, 0x1000, REG_QRFCR);
257
258 /* aggresive back off in half duplex */
259 ks8842_enable_bits(adapter, 32, 1 << 8, REG_SGCR1);
260
261 /* enable no excessive collison drop */
262 ks8842_enable_bits(adapter, 32, 1 << 3, REG_SGCR2);
263
264 /* Enable port 1 force flow control / back pressure / transmit / recv */
265 ks8842_write16(adapter, 48, 0x1E07, REG_P1CR2);
266
267 /* restart port auto-negotiation */
268 ks8842_enable_bits(adapter, 49, 1 << 13, REG_P1CR4);
269 /* only advertise 10Mbps */
270 ks8842_clear_bits(adapter, 49, 3 << 2, REG_P1CR4);
271
272 /* Enable the transmitter */
273 ks8842_enable_tx(adapter);
274
275 /* Enable the receiver */
276 ks8842_enable_rx(adapter);
277
278 /* clear all interrupts */
279 ks8842_write16(adapter, 18, 0xffff, REG_ISR);
280
281 /* enable interrupts */
282 ks8842_write16(adapter, 18, ENABLED_IRQS, REG_IER);
283
284 /* enable the switch */
285 ks8842_write16(adapter, 32, 0x1, REG_SW_ID_AND_ENABLE);
286}
287
288static void ks8842_read_mac_addr(struct ks8842_adapter *adapter, u8 *dest)
289{
290 int i;
291 u16 mac;
292
293 for (i = 0; i < ETH_ALEN; i++)
294 dest[ETH_ALEN - i - 1] = ks8842_read8(adapter, 2, REG_MARL + i);
295
296 /* make sure the switch port uses the same MAC as the QMU */
297 mac = ks8842_read16(adapter, 2, REG_MARL);
298 ks8842_write16(adapter, 39, mac, REG_MACAR1);
299 mac = ks8842_read16(adapter, 2, REG_MARM);
300 ks8842_write16(adapter, 39, mac, REG_MACAR2);
301 mac = ks8842_read16(adapter, 2, REG_MARH);
302 ks8842_write16(adapter, 39, mac, REG_MACAR3);
303}
304
305static inline u16 ks8842_tx_fifo_space(struct ks8842_adapter *adapter)
306{
307 return ks8842_read16(adapter, 16, REG_TXMIR) & 0x1fff;
308}
309
310static int ks8842_tx_frame(struct sk_buff *skb, struct net_device *netdev)
311{
312 struct ks8842_adapter *adapter = netdev_priv(netdev);
313 int len = skb->len;
314 u32 *ptr = (u32 *)skb->data;
315 u32 ctrl;
316
317 dev_dbg(&adapter->pdev->dev,
318 "%s: len %u head %p data %p tail %p end %p\n",
319 __func__, skb->len, skb->head, skb->data,
320 skb_tail_pointer(skb), skb_end_pointer(skb));
321
322 /* check FIFO buffer space, we need space for CRC and command bits */
323 if (ks8842_tx_fifo_space(adapter) < len + 8)
324 return NETDEV_TX_BUSY;
325
326 /* the control word, enable IRQ, port 1 and the length */
327 ctrl = 0x8000 | 0x100 | (len << 16);
328 ks8842_write32(adapter, 17, ctrl, REG_QMU_DATA_LO);
329
330 netdev->stats.tx_bytes += len;
331
332 /* copy buffer */
333 while (len > 0) {
334 iowrite32(*ptr, adapter->hw_addr + REG_QMU_DATA_LO);
335 len -= sizeof(u32);
336 ptr++;
337 }
338
339 /* enqueue packet */
340 ks8842_write16(adapter, 17, 1, REG_TXQCR);
341
342 dev_kfree_skb(skb);
343
344 return NETDEV_TX_OK;
345}
346
347static void ks8842_rx_frame(struct net_device *netdev,
348 struct ks8842_adapter *adapter)
349{
350 u32 status = ks8842_read32(adapter, 17, REG_QMU_DATA_LO);
351 int len = (status >> 16) & 0x7ff;
352
353 status &= 0xffff;
354
355 dev_dbg(&adapter->pdev->dev, "%s - rx_data: status: %x\n",
356 __func__, status);
357
358 /* check the status */
359 if ((status & RXSR_VALID) && !(status & RXSR_ERROR)) {
360 struct sk_buff *skb = netdev_alloc_skb(netdev, len + 2);
361
362 dev_dbg(&adapter->pdev->dev, "%s, got package, len: %d\n",
363 __func__, len);
364 if (skb) {
365 u32 *data;
366
367 netdev->stats.rx_packets++;
368 netdev->stats.rx_bytes += len;
369 if (status & RXSR_MULTICAST)
370 netdev->stats.multicast++;
371
372 /* Align socket buffer in 4-byte boundary for
373 better performance. */
374 skb_reserve(skb, 2);
375 data = (u32 *)skb_put(skb, len);
376
377 ks8842_select_bank(adapter, 17);
378 while (len > 0) {
379 *data++ = ioread32(adapter->hw_addr +
380 REG_QMU_DATA_LO);
381 len -= sizeof(u32);
382 }
383
384 skb->protocol = eth_type_trans(skb, netdev);
385 netif_rx(skb);
386 } else
387 netdev->stats.rx_dropped++;
388 } else {
389 dev_dbg(&adapter->pdev->dev, "RX error, status: %x\n", status);
390 netdev->stats.rx_errors++;
391 if (status & RXSR_TOO_LONG)
392 netdev->stats.rx_length_errors++;
393 if (status & RXSR_CRC_ERROR)
394 netdev->stats.rx_crc_errors++;
395 if (status & RXSR_RUNT)
396 netdev->stats.rx_frame_errors++;
397 }
398
399 /* set high watermark to 3K */
400 ks8842_clear_bits(adapter, 0, 1 << 12, REG_QRFCR);
401
402 /* release the frame */
403 ks8842_write16(adapter, 17, 0x01, REG_RXQCR);
404
405 /* set high watermark to 2K */
406 ks8842_enable_bits(adapter, 0, 1 << 12, REG_QRFCR);
407}
408
409void ks8842_handle_rx(struct net_device *netdev, struct ks8842_adapter *adapter)
410{
411 u16 rx_data = ks8842_read16(adapter, 16, REG_RXMIR) & 0x1fff;
412 dev_dbg(&adapter->pdev->dev, "%s Entry - rx_data: %d\n",
413 __func__, rx_data);
414 while (rx_data) {
415 ks8842_rx_frame(netdev, adapter);
416 rx_data = ks8842_read16(adapter, 16, REG_RXMIR) & 0x1fff;
417 }
418}
419
420void ks8842_handle_tx(struct net_device *netdev, struct ks8842_adapter *adapter)
421{
422 u16 sr = ks8842_read16(adapter, 16, REG_TXSR);
423 dev_dbg(&adapter->pdev->dev, "%s - entry, sr: %x\n", __func__, sr);
424 netdev->stats.tx_packets++;
425 if (netif_queue_stopped(netdev))
426 netif_wake_queue(netdev);
427}
428
429void ks8842_handle_rx_overrun(struct net_device *netdev,
430 struct ks8842_adapter *adapter)
431{
432 dev_dbg(&adapter->pdev->dev, "%s: entry\n", __func__);
433 netdev->stats.rx_errors++;
434 netdev->stats.rx_fifo_errors++;
435}
436
437void ks8842_tasklet(unsigned long arg)
438{
439 struct net_device *netdev = (struct net_device *)arg;
440 struct ks8842_adapter *adapter = netdev_priv(netdev);
441 u16 isr;
442 unsigned long flags;
443 u16 entry_bank;
444
445 /* read current bank to be able to set it back */
446 spin_lock_irqsave(&adapter->lock, flags);
447 entry_bank = ioread16(adapter->hw_addr + REG_SELECT_BANK);
448 spin_unlock_irqrestore(&adapter->lock, flags);
449
450 isr = ks8842_read16(adapter, 18, REG_ISR);
451 dev_dbg(&adapter->pdev->dev, "%s - ISR: 0x%x\n", __func__, isr);
452
453 /* Ack */
454 ks8842_write16(adapter, 18, isr, REG_ISR);
455
456 if (!netif_running(netdev))
457 return;
458
459 if (isr & IRQ_LINK_CHANGE)
460 ks8842_update_link_status(netdev, adapter);
461
462 if (isr & (IRQ_RX | IRQ_RX_ERROR))
463 ks8842_handle_rx(netdev, adapter);
464
465 if (isr & IRQ_TX)
466 ks8842_handle_tx(netdev, adapter);
467
468 if (isr & IRQ_RX_OVERRUN)
469 ks8842_handle_rx_overrun(netdev, adapter);
470
471 if (isr & IRQ_TX_STOPPED) {
472 ks8842_disable_tx(adapter);
473 ks8842_enable_tx(adapter);
474 }
475
476 if (isr & IRQ_RX_STOPPED) {
477 ks8842_disable_rx(adapter);
478 ks8842_enable_rx(adapter);
479 }
480
481 /* re-enable interrupts, put back the bank selection register */
482 spin_lock_irqsave(&adapter->lock, flags);
483 ks8842_write16(adapter, 18, ENABLED_IRQS, REG_IER);
484 iowrite16(entry_bank, adapter->hw_addr + REG_SELECT_BANK);
485 spin_unlock_irqrestore(&adapter->lock, flags);
486}
487
488static irqreturn_t ks8842_irq(int irq, void *devid)
489{
490 struct ks8842_adapter *adapter = devid;
491 u16 isr;
492 u16 entry_bank = ioread16(adapter->hw_addr + REG_SELECT_BANK);
493 irqreturn_t ret = IRQ_NONE;
494
495 isr = ks8842_read16(adapter, 18, REG_ISR);
496 dev_dbg(&adapter->pdev->dev, "%s - ISR: 0x%x\n", __func__, isr);
497
498 if (isr) {
499 /* disable IRQ */
500 ks8842_write16(adapter, 18, 0x00, REG_IER);
501
502 /* schedule tasklet */
503 tasklet_schedule(&adapter->tasklet);
504
505 ret = IRQ_HANDLED;
506 }
507
508 iowrite16(entry_bank, adapter->hw_addr + REG_SELECT_BANK);
509
510 return ret;
511}
512
513
514/* Netdevice operations */
515
516static int ks8842_open(struct net_device *netdev)
517{
518 struct ks8842_adapter *adapter = netdev_priv(netdev);
519 int err;
520
521 dev_dbg(&adapter->pdev->dev, "%s - entry\n", __func__);
522
523 /* reset the HW */
524 ks8842_reset_hw(adapter);
525
526 ks8842_update_link_status(netdev, adapter);
527
528 err = request_irq(adapter->irq, ks8842_irq, IRQF_SHARED, DRV_NAME,
529 adapter);
530 if (err) {
531 printk(KERN_ERR "Failed to request IRQ: %d: %d\n",
532 adapter->irq, err);
533 return err;
534 }
535
536 return 0;
537}
538
539static int ks8842_close(struct net_device *netdev)
540{
541 struct ks8842_adapter *adapter = netdev_priv(netdev);
542
543 dev_dbg(&adapter->pdev->dev, "%s - entry\n", __func__);
544
545 /* free the irq */
546 free_irq(adapter->irq, adapter);
547
548 /* disable the switch */
549 ks8842_write16(adapter, 32, 0x0, REG_SW_ID_AND_ENABLE);
550
551 return 0;
552}
553
554static int ks8842_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
555{
556 int ret;
557 struct ks8842_adapter *adapter = netdev_priv(netdev);
558
559 dev_dbg(&adapter->pdev->dev, "%s: entry\n", __func__);
560
561 ret = ks8842_tx_frame(skb, netdev);
562
563 if (ks8842_tx_fifo_space(adapter) < netdev->mtu + 8)
564 netif_stop_queue(netdev);
565
566 return ret;
567}
568
569static int ks8842_set_mac(struct net_device *netdev, void *p)
570{
571 struct ks8842_adapter *adapter = netdev_priv(netdev);
572 unsigned long flags;
573 struct sockaddr *addr = p;
574 char *mac = (u8 *)addr->sa_data;
575 int i;
576
577 dev_dbg(&adapter->pdev->dev, "%s: entry\n", __func__);
578
579 if (!is_valid_ether_addr(addr->sa_data))
580 return -EADDRNOTAVAIL;
581
582 memcpy(netdev->dev_addr, mac, netdev->addr_len);
583
584 spin_lock_irqsave(&adapter->lock, flags);
585 for (i = 0; i < ETH_ALEN; i++) {
586 ks8842_write8(adapter, 2, mac[ETH_ALEN - i - 1], REG_MARL + i);
587 ks8842_write8(adapter, 39, mac[ETH_ALEN - i - 1],
588 REG_MACAR1 + i);
589 }
590 spin_unlock_irqrestore(&adapter->lock, flags);
591 return 0;
592}
593
594static void ks8842_tx_timeout(struct net_device *netdev)
595{
596 struct ks8842_adapter *adapter = netdev_priv(netdev);
597 unsigned long flags;
598
599 dev_dbg(&adapter->pdev->dev, "%s: entry\n", __func__);
600
601 spin_lock_irqsave(&adapter->lock, flags);
602 /* disable interrupts */
603 ks8842_write16(adapter, 18, 0, REG_IER);
604 ks8842_write16(adapter, 18, 0xFFFF, REG_ISR);
605 spin_unlock_irqrestore(&adapter->lock, flags);
606
607 ks8842_reset_hw(adapter);
608
609 ks8842_update_link_status(netdev, adapter);
610}
611
612static const struct net_device_ops ks8842_netdev_ops = {
613 .ndo_open = ks8842_open,
614 .ndo_stop = ks8842_close,
615 .ndo_start_xmit = ks8842_xmit_frame,
616 .ndo_set_mac_address = ks8842_set_mac,
617 .ndo_tx_timeout = ks8842_tx_timeout,
618 .ndo_validate_addr = eth_validate_addr
619};
620
621static struct ethtool_ops ks8842_ethtool_ops = {
622 .get_link = ethtool_op_get_link,
623};
624
625static int __devinit ks8842_probe(struct platform_device *pdev)
626{
627 int err = -ENOMEM;
628 struct resource *iomem;
629 struct net_device *netdev;
630 struct ks8842_adapter *adapter;
631 u16 id;
632
633 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
634 if (!request_mem_region(iomem->start, resource_size(iomem), DRV_NAME))
635 goto err_mem_region;
636
637 netdev = alloc_etherdev(sizeof(struct ks8842_adapter));
638 if (!netdev)
639 goto err_alloc_etherdev;
640
641 SET_NETDEV_DEV(netdev, &pdev->dev);
642
643 adapter = netdev_priv(netdev);
644 adapter->hw_addr = ioremap(iomem->start, resource_size(iomem));
645 if (!adapter->hw_addr)
646 goto err_ioremap;
647
648 adapter->irq = platform_get_irq(pdev, 0);
649 if (adapter->irq < 0) {
650 err = adapter->irq;
651 goto err_get_irq;
652 }
653
654 adapter->pdev = pdev;
655
656 tasklet_init(&adapter->tasklet, ks8842_tasklet, (unsigned long)netdev);
657 spin_lock_init(&adapter->lock);
658
659 netdev->netdev_ops = &ks8842_netdev_ops;
660 netdev->ethtool_ops = &ks8842_ethtool_ops;
661
662 ks8842_read_mac_addr(adapter, netdev->dev_addr);
663
664 id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE);
665
666 strcpy(netdev->name, "eth%d");
667 err = register_netdev(netdev);
668 if (err)
669 goto err_register;
670
671 platform_set_drvdata(pdev, netdev);
672
673 printk(KERN_INFO DRV_NAME
674 " Found chip, family: 0x%x, id: 0x%x, rev: 0x%x\n",
675 (id >> 8) & 0xff, (id >> 4) & 0xf, (id >> 1) & 0x7);
676
677 return 0;
678
679err_register:
680err_get_irq:
681 iounmap(adapter->hw_addr);
682err_ioremap:
683 free_netdev(netdev);
684err_alloc_etherdev:
685 release_mem_region(iomem->start, resource_size(iomem));
686err_mem_region:
687 return err;
688}
689
690static int __devexit ks8842_remove(struct platform_device *pdev)
691{
692 struct net_device *netdev = platform_get_drvdata(pdev);
693 struct ks8842_adapter *adapter = netdev_priv(netdev);
694 struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
695
696 unregister_netdev(netdev);
697 tasklet_kill(&adapter->tasklet);
698 iounmap(adapter->hw_addr);
699 free_netdev(netdev);
700 release_mem_region(iomem->start, resource_size(iomem));
701 platform_set_drvdata(pdev, NULL);
702 return 0;
703}
704
705
706static struct platform_driver ks8842_platform_driver = {
707 .driver = {
708 .name = DRV_NAME,
709 .owner = THIS_MODULE,
710 },
711 .probe = ks8842_probe,
712 .remove = ks8842_remove,
713};
714
715static int __init ks8842_init(void)
716{
717 return platform_driver_register(&ks8842_platform_driver);
718}
719
720static void __exit ks8842_exit(void)
721{
722 platform_driver_unregister(&ks8842_platform_driver);
723}
724
725module_init(ks8842_init);
726module_exit(ks8842_exit);
727
728MODULE_DESCRIPTION("Timberdale KS8842 ethernet driver");
729MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
730MODULE_LICENSE("GPL v2");
731MODULE_ALIAS("platform:ks8842");
732