2 * Micrel KS8695 (Centaur) Ethernet.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * Copyright 2008 Simtec Electronics
15 * Daniel Silverstone <dsilvers@simtec.co.uk>
16 * Vincent Sanders <vince@simtec.co.uk>
19 #include <linux/module.h>
20 #include <linux/ioport.h>
21 #include <linux/netdevice.h>
22 #include <linux/etherdevice.h>
23 #include <linux/init.h>
24 #include <linux/skbuff.h>
25 #include <linux/spinlock.h>
26 #include <linux/crc32.h>
27 #include <linux/mii.h>
28 #include <linux/ethtool.h>
29 #include <linux/delay.h>
30 #include <linux/platform_device.h>
31 #include <linux/irq.h>
32 #include <linux/delay.h>
37 #include <mach/regs-switch.h>
38 #include <mach/regs-misc.h>
40 #include "ks8695net.h"
42 #define MODULENAME "ks8695_ether"
43 #define MODULEVERSION "1.01"
46 * Transmit and device reset timeout, default 5 seconds.
48 static int watchdog
= 5000;
50 /* Hardware structures */
53 * struct rx_ring_desc - Receive descriptor ring element
54 * @status: The status of the descriptor element (E.g. who owns it)
55 * @length: The number of bytes in the block pointed to by data_ptr
56 * @data_ptr: The physical address of the data block to receive into
57 * @next_desc: The physical address of the next descriptor element.
67 * struct tx_ring_desc - Transmit descriptor ring element
68 * @owner: Who owns the descriptor
69 * @status: The number of bytes in the block pointed to by data_ptr
70 * @data_ptr: The physical address of the data block to receive into
71 * @next_desc: The physical address of the next descriptor element.
81 * struct ks8695_skbuff - sk_buff wrapper for rx/tx rings.
82 * @skb: The buffer in the ring
83 * @dma_ptr: The mapped DMA pointer of the buffer
84 * @length: The number of bytes mapped to dma_ptr
86 struct ks8695_skbuff
{
92 /* Private device structure */
95 #define MAX_TX_DESC_MASK 0x7
96 #define MAX_RX_DESC 16
97 #define MAX_RX_DESC_MASK 0xf
99 #define MAX_RXBUF_SIZE 0x700
101 #define TX_RING_DMA_SIZE (sizeof(struct tx_ring_desc) * MAX_TX_DESC)
102 #define RX_RING_DMA_SIZE (sizeof(struct rx_ring_desc) * MAX_RX_DESC)
103 #define RING_DMA_SIZE (TX_RING_DMA_SIZE + RX_RING_DMA_SIZE)
106 * enum ks8695_dtype - Device type
107 * @KS8695_DTYPE_WAN: This device is a WAN interface
108 * @KS8695_DTYPE_LAN: This device is a LAN interface
109 * @KS8695_DTYPE_HPNA: This device is an HPNA interface
118 * struct ks8695_priv - Private data for the KS8695 Ethernet
119 * @in_suspend: Flag to indicate if we're suspending/resuming
120 * @ndev: The net_device for this interface
121 * @dev: The platform device object for this interface
122 * @dtype: The type of this device
123 * @io_regs: The ioremapped registers for this interface
124 * @rx_irq_name: The textual name of the RX IRQ from the platform data
125 * @tx_irq_name: The textual name of the TX IRQ from the platform data
126 * @link_irq_name: The textual name of the link IRQ from the
127 * platform data if available
128 * @rx_irq: The IRQ number for the RX IRQ
129 * @tx_irq: The IRQ number for the TX IRQ
130 * @link_irq: The IRQ number for the link IRQ if available
131 * @regs_req: The resource request for the registers region
132 * @phyiface_req: The resource request for the phy/switch region
134 * @phyiface_regs: The ioremapped registers for the phy/switch if available
135 * @ring_base: The base pointer of the dma coherent memory for the rings
136 * @ring_base_dma: The DMA mapped equivalent of ring_base
137 * @tx_ring: The pointer in ring_base of the TX ring
138 * @tx_ring_used: The number of slots in the TX ring which are occupied
139 * @tx_ring_next_slot: The next slot to fill in the TX ring
140 * @tx_ring_dma: The DMA mapped equivalent of tx_ring
141 * @tx_buffers: The sk_buff mappings for the TX ring
142 * @txq_lock: A lock to protect the tx_buffers tx_ring_used etc variables
143 * @rx_ring: The pointer in ring_base of the RX ring
144 * @rx_ring_dma: The DMA mapped equivalent of rx_ring
145 * @rx_buffers: The sk_buff mappings for the RX ring
146 * @next_rx_desc_read: The next RX descriptor to read from on IRQ
147 * @msg_enable: The flags for which messages to emit
151 struct net_device
*ndev
;
153 enum ks8695_dtype dtype
;
154 void __iomem
*io_regs
;
156 const char *rx_irq_name
, *tx_irq_name
, *link_irq_name
;
157 int rx_irq
, tx_irq
, link_irq
;
159 struct resource
*regs_req
, *phyiface_req
;
160 void __iomem
*phyiface_regs
;
163 dma_addr_t ring_base_dma
;
165 struct tx_ring_desc
*tx_ring
;
167 int tx_ring_next_slot
;
168 dma_addr_t tx_ring_dma
;
169 struct ks8695_skbuff tx_buffers
[MAX_TX_DESC
];
172 struct rx_ring_desc
*rx_ring
;
173 dma_addr_t rx_ring_dma
;
174 struct ks8695_skbuff rx_buffers
[MAX_RX_DESC
];
175 int next_rx_desc_read
;
180 /* Register access */
183 * ks8695_readreg - Read from a KS8695 ethernet register
184 * @ksp: The device to read from
185 * @reg: The register to read
188 ks8695_readreg(struct ks8695_priv
*ksp
, int reg
)
190 return readl(ksp
->io_regs
+ reg
);
194 * ks8695_writereg - Write to a KS8695 ethernet register
195 * @ksp: The device to write to
196 * @reg: The register to write
197 * @value: The value to write to the register
200 ks8695_writereg(struct ks8695_priv
*ksp
, int reg
, u32 value
)
202 writel(value
, ksp
->io_regs
+ reg
);
205 /* Utility functions */
208 * ks8695_port_type - Retrieve port-type as user-friendly string
209 * @ksp: The device to return the type for
211 * Returns a string indicating which of the WAN, LAN or HPNA
212 * ports this device is likely to represent.
215 ks8695_port_type(struct ks8695_priv
*ksp
)
217 switch (ksp
->dtype
) {
218 case KS8695_DTYPE_LAN
:
220 case KS8695_DTYPE_WAN
:
222 case KS8695_DTYPE_HPNA
:
230 * ks8695_update_mac - Update the MAC registers in the device
231 * @ksp: The device to update
233 * Updates the MAC registers in the KS8695 device from the address in the
234 * net_device structure associated with this interface.
237 ks8695_update_mac(struct ks8695_priv
*ksp
)
239 /* Update the HW with the MAC from the net_device */
240 struct net_device
*ndev
= ksp
->ndev
;
243 maclow
= ((ndev
->dev_addr
[2] << 24) | (ndev
->dev_addr
[3] << 16) |
244 (ndev
->dev_addr
[4] << 8) | (ndev
->dev_addr
[5] << 0));
245 machigh
= ((ndev
->dev_addr
[0] << 8) | (ndev
->dev_addr
[1] << 0));
247 ks8695_writereg(ksp
, KS8695_MAL
, maclow
);
248 ks8695_writereg(ksp
, KS8695_MAH
, machigh
);
253 * ks8695_refill_rxbuffers - Re-fill the RX buffer ring
254 * @ksp: The device to refill
256 * Iterates the RX ring of the device looking for empty slots.
257 * For each empty slot, we allocate and map a new SKB and give it
259 * This can be called from interrupt context safely.
262 ks8695_refill_rxbuffers(struct ks8695_priv
*ksp
)
264 /* Run around the RX ring, filling in any missing sk_buff's */
267 for (buff_n
= 0; buff_n
< MAX_RX_DESC
; ++buff_n
) {
268 if (!ksp
->rx_buffers
[buff_n
].skb
) {
269 struct sk_buff
*skb
= dev_alloc_skb(MAX_RXBUF_SIZE
);
272 ksp
->rx_buffers
[buff_n
].skb
= skb
;
274 /* Failed to allocate one, perhaps
275 * we'll try again later.
280 mapping
= dma_map_single(ksp
->dev
, skb
->data
,
283 if (unlikely(dma_mapping_error(ksp
->dev
, mapping
))) {
284 /* Failed to DMA map this SKB, try later */
285 dev_kfree_skb_irq(skb
);
286 ksp
->rx_buffers
[buff_n
].skb
= NULL
;
289 ksp
->rx_buffers
[buff_n
].dma_ptr
= mapping
;
290 skb
->dev
= ksp
->ndev
;
291 ksp
->rx_buffers
[buff_n
].length
= MAX_RXBUF_SIZE
;
293 /* Record this into the DMA ring */
294 ksp
->rx_ring
[buff_n
].data_ptr
= cpu_to_le32(mapping
);
295 ksp
->rx_ring
[buff_n
].length
=
296 cpu_to_le32(MAX_RXBUF_SIZE
);
300 /* And give ownership over to the hardware */
301 ksp
->rx_ring
[buff_n
].status
= cpu_to_le32(RDES_OWN
);
306 /* Maximum number of multicast addresses which the KS8695 HW supports */
307 #define KS8695_NR_ADDRESSES 16
310 * ks8695_init_partial_multicast - Init the mcast addr registers
311 * @ksp: The device to initialise
312 * @addr: The multicast address list to use
313 * @nr_addr: The number of addresses in the list
315 * This routine is a helper for ks8695_set_multicast - it writes
316 * the additional-address registers in the KS8695 ethernet device
317 * and cleans up any others left behind.
320 ks8695_init_partial_multicast(struct ks8695_priv
*ksp
,
321 struct dev_mc_list
*addr
,
327 for (i
= 0; i
< nr_addr
; i
++, addr
= addr
->next
) {
328 /* Ran out of addresses? */
331 /* Ran out of space in chip? */
332 BUG_ON(i
== KS8695_NR_ADDRESSES
);
334 low
= (addr
->dmi_addr
[2] << 24) | (addr
->dmi_addr
[3] << 16) |
335 (addr
->dmi_addr
[4] << 8) | (addr
->dmi_addr
[5]);
336 high
= (addr
->dmi_addr
[0] << 8) | (addr
->dmi_addr
[1]);
338 ks8695_writereg(ksp
, KS8695_AAL_(i
), low
);
339 ks8695_writereg(ksp
, KS8695_AAH_(i
), AAH_E
| high
);
342 /* Clear the remaining Additional Station Addresses */
343 for (; i
< KS8695_NR_ADDRESSES
; i
++) {
344 ks8695_writereg(ksp
, KS8695_AAL_(i
), 0);
345 ks8695_writereg(ksp
, KS8695_AAH_(i
), 0);
349 /* Interrupt handling */
352 * ks8695_tx_irq - Transmit IRQ handler
353 * @irq: The IRQ which went off (ignored)
354 * @dev_id: The net_device for the interrupt
356 * Process the TX ring, clearing out any transmitted slots.
357 * Allows the net_device to pass us new packets once slots are
361 ks8695_tx_irq(int irq
, void *dev_id
)
363 struct net_device
*ndev
= (struct net_device
*)dev_id
;
364 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
367 for (buff_n
= 0; buff_n
< MAX_TX_DESC
; ++buff_n
) {
368 if (ksp
->tx_buffers
[buff_n
].skb
&&
369 !(ksp
->tx_ring
[buff_n
].owner
& cpu_to_le32(TDES_OWN
))) {
371 /* An SKB which is not owned by HW is present */
372 /* Update the stats for the net_device */
373 ndev
->stats
.tx_packets
++;
374 ndev
->stats
.tx_bytes
+= ksp
->tx_buffers
[buff_n
].length
;
376 /* Free the packet from the ring */
377 ksp
->tx_ring
[buff_n
].data_ptr
= 0;
379 /* Free the sk_buff */
380 dma_unmap_single(ksp
->dev
,
381 ksp
->tx_buffers
[buff_n
].dma_ptr
,
382 ksp
->tx_buffers
[buff_n
].length
,
384 dev_kfree_skb_irq(ksp
->tx_buffers
[buff_n
].skb
);
385 ksp
->tx_buffers
[buff_n
].skb
= NULL
;
390 netif_wake_queue(ndev
);
396 * ks8695_rx_irq - Receive IRQ handler
397 * @irq: The IRQ which went off (ignored)
398 * @dev_id: The net_device for the interrupt
400 * Process the RX ring, passing any received packets up to the
401 * host. If we received anything other than errors, we then
405 ks8695_rx_irq(int irq
, void *dev_id
)
407 struct net_device
*ndev
= (struct net_device
*)dev_id
;
408 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
413 int last_rx_processed
= -1;
415 buff_n
= ksp
->next_rx_desc_read
;
417 if (ksp
->rx_buffers
[buff_n
].skb
&&
418 !(ksp
->rx_ring
[buff_n
].status
& cpu_to_le32(RDES_OWN
))) {
420 flags
= le32_to_cpu(ksp
->rx_ring
[buff_n
].status
);
421 /* Found an SKB which we own, this means we
424 if ((flags
& (RDES_FS
| RDES_LS
)) !=
425 (RDES_FS
| RDES_LS
)) {
426 /* This packet is not the first and
427 * the last segment. Therefore it is
428 * a "spanning" packet and we can't
434 if (flags
& (RDES_ES
| RDES_RE
)) {
435 /* It's an error packet */
436 ndev
->stats
.rx_errors
++;
438 ndev
->stats
.rx_length_errors
++;
440 ndev
->stats
.rx_length_errors
++;
442 ndev
->stats
.rx_crc_errors
++;
444 ndev
->stats
.rx_missed_errors
++;
449 pktlen
= flags
& RDES_FLEN
;
450 pktlen
-= 4; /* Drop the CRC */
452 /* Retrieve the sk_buff */
453 skb
= ksp
->rx_buffers
[buff_n
].skb
;
455 /* Clear it from the ring */
456 ksp
->rx_buffers
[buff_n
].skb
= NULL
;
457 ksp
->rx_ring
[buff_n
].data_ptr
= 0;
460 dma_unmap_single(ksp
->dev
,
461 ksp
->rx_buffers
[buff_n
].dma_ptr
,
462 ksp
->rx_buffers
[buff_n
].length
,
465 /* Relinquish the SKB to the network layer */
466 skb_put(skb
, pktlen
);
467 skb
->protocol
= eth_type_trans(skb
, ndev
);
471 ndev
->last_rx
= jiffies
;
472 ndev
->stats
.rx_packets
++;
473 ndev
->stats
.rx_bytes
+= pktlen
;
477 /* This ring entry is an error, but we can
480 /* Give the ring entry back to the hardware */
481 ksp
->rx_ring
[buff_n
].status
= cpu_to_le32(RDES_OWN
);
483 /* And note this as processed so we can start
484 * from here next time
486 last_rx_processed
= buff_n
;
488 /* Ran out of things to process, stop now */
491 buff_n
= (buff_n
+ 1) & MAX_RX_DESC_MASK
;
492 } while (buff_n
!= ksp
->next_rx_desc_read
);
494 /* And note which RX descriptor we last did anything with */
495 if (likely(last_rx_processed
!= -1))
496 ksp
->next_rx_desc_read
=
497 (last_rx_processed
+ 1) & MAX_RX_DESC_MASK
;
499 /* And refill the buffers */
500 ks8695_refill_rxbuffers(ksp
);
502 /* Kick the RX DMA engine, in case it became suspended */
503 ks8695_writereg(ksp
, KS8695_DRSC
, 0);
509 * ks8695_link_irq - Link change IRQ handler
510 * @irq: The IRQ which went off (ignored)
511 * @dev_id: The net_device for the interrupt
513 * The WAN interface can generate an IRQ when the link changes,
514 * report this to the net layer and the user.
517 ks8695_link_irq(int irq
, void *dev_id
)
519 struct net_device
*ndev
= (struct net_device
*)dev_id
;
520 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
523 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
524 if (ctrl
& WMC_WLS
) {
525 netif_carrier_on(ndev
);
526 if (netif_msg_link(ksp
))
528 "%s: Link is now up (10%sMbps/%s-duplex)\n",
530 (ctrl
& WMC_WSS
) ? "0" : "",
531 (ctrl
& WMC_WDS
) ? "Full" : "Half");
533 netif_carrier_off(ndev
);
534 if (netif_msg_link(ksp
))
535 dev_info(ksp
->dev
, "%s: Link is now down.\n",
543 /* KS8695 Device functions */
546 * ks8695_reset - Reset a KS8695 ethernet interface
547 * @ksp: The interface to reset
549 * Perform an engine reset of the interface and re-program it
550 * with sensible defaults.
553 ks8695_reset(struct ks8695_priv
*ksp
)
555 int reset_timeout
= watchdog
;
556 /* Issue the reset via the TX DMA control register */
557 ks8695_writereg(ksp
, KS8695_DTXC
, DTXC_TRST
);
558 while (reset_timeout
--) {
559 if (!(ks8695_readreg(ksp
, KS8695_DTXC
) & DTXC_TRST
))
564 if (reset_timeout
== 0) {
566 "Timeout waiting for DMA engines to reset\n");
567 /* And blithely carry on */
570 /* Definitely wait long enough before attempting to program
575 /* RX: unicast and broadcast */
576 ks8695_writereg(ksp
, KS8695_DRXC
, DRXC_RU
| DRXC_RB
);
577 /* TX: pad and add CRC */
578 ks8695_writereg(ksp
, KS8695_DTXC
, DTXC_TEP
| DTXC_TAC
);
582 * ks8695_shutdown - Shut down a KS8695 ethernet interface
583 * @ksp: The interface to shut down
585 * This disables packet RX/TX, cleans up IRQs, drains the rings,
586 * and basically places the interface into a clean shutdown
590 ks8695_shutdown(struct ks8695_priv
*ksp
)
595 /* Disable packet transmission */
596 ctrl
= ks8695_readreg(ksp
, KS8695_DTXC
);
597 ks8695_writereg(ksp
, KS8695_DTXC
, ctrl
& ~DTXC_TE
);
599 /* Disable packet reception */
600 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
601 ks8695_writereg(ksp
, KS8695_DRXC
, ctrl
& ~DRXC_RE
);
603 /* Release the IRQs */
604 free_irq(ksp
->rx_irq
, ksp
->ndev
);
605 free_irq(ksp
->tx_irq
, ksp
->ndev
);
606 if (ksp
->link_irq
!= -1)
607 free_irq(ksp
->link_irq
, ksp
->ndev
);
609 /* Throw away any pending TX packets */
610 for (buff_n
= 0; buff_n
< MAX_TX_DESC
; ++buff_n
) {
611 if (ksp
->tx_buffers
[buff_n
].skb
) {
612 /* Remove this SKB from the TX ring */
613 ksp
->tx_ring
[buff_n
].owner
= 0;
614 ksp
->tx_ring
[buff_n
].status
= 0;
615 ksp
->tx_ring
[buff_n
].data_ptr
= 0;
617 /* Unmap and bin this SKB */
618 dma_unmap_single(ksp
->dev
,
619 ksp
->tx_buffers
[buff_n
].dma_ptr
,
620 ksp
->tx_buffers
[buff_n
].length
,
622 dev_kfree_skb_irq(ksp
->tx_buffers
[buff_n
].skb
);
623 ksp
->tx_buffers
[buff_n
].skb
= NULL
;
627 /* Purge the RX buffers */
628 for (buff_n
= 0; buff_n
< MAX_RX_DESC
; ++buff_n
) {
629 if (ksp
->rx_buffers
[buff_n
].skb
) {
630 /* Remove the SKB from the RX ring */
631 ksp
->rx_ring
[buff_n
].status
= 0;
632 ksp
->rx_ring
[buff_n
].data_ptr
= 0;
634 /* Unmap and bin the SKB */
635 dma_unmap_single(ksp
->dev
,
636 ksp
->rx_buffers
[buff_n
].dma_ptr
,
637 ksp
->rx_buffers
[buff_n
].length
,
639 dev_kfree_skb_irq(ksp
->rx_buffers
[buff_n
].skb
);
640 ksp
->rx_buffers
[buff_n
].skb
= NULL
;
647 * ks8695_setup_irq - IRQ setup helper function
648 * @irq: The IRQ number to claim
649 * @irq_name: The name to give the IRQ claimant
650 * @handler: The function to call to handle the IRQ
651 * @ndev: The net_device to pass in as the dev_id argument to the handler
653 * Return 0 on success.
656 ks8695_setup_irq(int irq
, const char *irq_name
,
657 irq_handler_t handler
, struct net_device
*ndev
)
661 ret
= request_irq(irq
, handler
, IRQF_SHARED
, irq_name
, ndev
);
664 dev_err(&ndev
->dev
, "failure to request IRQ %d\n", irq
);
672 * ks8695_init_net - Initialise a KS8695 ethernet interface
673 * @ksp: The interface to initialise
675 * This routine fills the RX ring, initialises the DMA engines,
676 * allocates the IRQs and then starts the packet TX and RX
680 ks8695_init_net(struct ks8695_priv
*ksp
)
685 ks8695_refill_rxbuffers(ksp
);
687 /* Initialise the DMA engines */
688 ks8695_writereg(ksp
, KS8695_RDLB
, (u32
) ksp
->rx_ring_dma
);
689 ks8695_writereg(ksp
, KS8695_TDLB
, (u32
) ksp
->tx_ring_dma
);
691 /* Request the IRQs */
692 ret
= ks8695_setup_irq(ksp
->rx_irq
, ksp
->rx_irq_name
,
693 ks8695_rx_irq
, ksp
->ndev
);
696 ret
= ks8695_setup_irq(ksp
->tx_irq
, ksp
->tx_irq_name
,
697 ks8695_tx_irq
, ksp
->ndev
);
700 if (ksp
->link_irq
!= -1) {
701 ret
= ks8695_setup_irq(ksp
->link_irq
, ksp
->link_irq_name
,
702 ks8695_link_irq
, ksp
->ndev
);
707 /* Set up the ring indices */
708 ksp
->next_rx_desc_read
= 0;
709 ksp
->tx_ring_next_slot
= 0;
710 ksp
->tx_ring_used
= 0;
712 /* Bring up transmission */
713 ctrl
= ks8695_readreg(ksp
, KS8695_DTXC
);
714 /* Enable packet transmission */
715 ks8695_writereg(ksp
, KS8695_DTXC
, ctrl
| DTXC_TE
);
717 /* Bring up the reception */
718 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
719 /* Enable packet reception */
720 ks8695_writereg(ksp
, KS8695_DRXC
, ctrl
| DRXC_RE
);
721 /* And start the DMA engine */
722 ks8695_writereg(ksp
, KS8695_DRSC
, 0);
729 * ks8695_release_device - HW resource release for KS8695 e-net
730 * @ksp: The device to be freed
732 * This unallocates io memory regions, dma-coherent regions etc
733 * which were allocated in ks8695_probe.
736 ks8695_release_device(struct ks8695_priv
*ksp
)
738 /* Unmap the registers */
739 iounmap(ksp
->io_regs
);
740 if (ksp
->phyiface_regs
)
741 iounmap(ksp
->phyiface_regs
);
743 /* And release the request */
744 release_resource(ksp
->regs_req
);
745 kfree(ksp
->regs_req
);
746 if (ksp
->phyiface_req
) {
747 release_resource(ksp
->phyiface_req
);
748 kfree(ksp
->phyiface_req
);
751 /* Free the ring buffers */
752 dma_free_coherent(ksp
->dev
, RING_DMA_SIZE
,
753 ksp
->ring_base
, ksp
->ring_base_dma
);
756 /* Ethtool support */
759 * ks8695_get_msglevel - Get the messages enabled for emission
760 * @ndev: The network device to read from
763 ks8695_get_msglevel(struct net_device
*ndev
)
765 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
767 return ksp
->msg_enable
;
771 * ks8695_set_msglevel - Set the messages enabled for emission
772 * @ndev: The network device to configure
773 * @value: The messages to set for emission
776 ks8695_set_msglevel(struct net_device
*ndev
, u32 value
)
778 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
780 ksp
->msg_enable
= value
;
784 * ks8695_get_settings - Get device-specific settings.
785 * @ndev: The network device to read settings from
786 * @cmd: The ethtool structure to read into
789 ks8695_get_settings(struct net_device
*ndev
, struct ethtool_cmd
*cmd
)
791 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
794 /* All ports on the KS8695 support these... */
795 cmd
->supported
= (SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
|
796 SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
|
797 SUPPORTED_TP
| SUPPORTED_MII
);
798 cmd
->transceiver
= XCVR_INTERNAL
;
800 /* Port specific extras */
801 switch (ksp
->dtype
) {
802 case KS8695_DTYPE_HPNA
:
803 cmd
->phy_address
= 0;
804 /* not supported for HPNA */
805 cmd
->autoneg
= AUTONEG_DISABLE
;
807 /* BUG: Erm, dtype hpna implies no phy regs */
809 ctrl = readl(KS8695_MISC_VA + KS8695_HMC);
810 cmd->speed = (ctrl & HMC_HSS) ? SPEED_100 : SPEED_10;
811 cmd->duplex = (ctrl & HMC_HDS) ? DUPLEX_FULL : DUPLEX_HALF;
814 case KS8695_DTYPE_WAN
:
815 cmd
->advertising
= ADVERTISED_TP
| ADVERTISED_MII
;
816 cmd
->port
= PORT_MII
;
817 cmd
->supported
|= (SUPPORTED_Autoneg
| SUPPORTED_Pause
);
818 cmd
->phy_address
= 0;
820 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
821 if ((ctrl
& WMC_WAND
) == 0) {
822 /* auto-negotiation is enabled */
823 cmd
->advertising
|= ADVERTISED_Autoneg
;
824 if (ctrl
& WMC_WANA100F
)
825 cmd
->advertising
|= ADVERTISED_100baseT_Full
;
826 if (ctrl
& WMC_WANA100H
)
827 cmd
->advertising
|= ADVERTISED_100baseT_Half
;
828 if (ctrl
& WMC_WANA10F
)
829 cmd
->advertising
|= ADVERTISED_10baseT_Full
;
830 if (ctrl
& WMC_WANA10H
)
831 cmd
->advertising
|= ADVERTISED_10baseT_Half
;
832 if (ctrl
& WMC_WANAP
)
833 cmd
->advertising
|= ADVERTISED_Pause
;
834 cmd
->autoneg
= AUTONEG_ENABLE
;
836 cmd
->speed
= (ctrl
& WMC_WSS
) ? SPEED_100
: SPEED_10
;
837 cmd
->duplex
= (ctrl
& WMC_WDS
) ?
838 DUPLEX_FULL
: DUPLEX_HALF
;
840 /* auto-negotiation is disabled */
841 cmd
->autoneg
= AUTONEG_DISABLE
;
843 cmd
->speed
= (ctrl
& WMC_WANF100
) ?
844 SPEED_100
: SPEED_10
;
845 cmd
->duplex
= (ctrl
& WMC_WANFF
) ?
846 DUPLEX_FULL
: DUPLEX_HALF
;
849 case KS8695_DTYPE_LAN
:
857 * ks8695_set_settings - Set device-specific settings.
858 * @ndev: The network device to configure
859 * @cmd: The settings to configure
862 ks8695_set_settings(struct net_device
*ndev
, struct ethtool_cmd
*cmd
)
864 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
867 if ((cmd
->speed
!= SPEED_10
) && (cmd
->speed
!= SPEED_100
))
869 if ((cmd
->duplex
!= DUPLEX_HALF
) && (cmd
->duplex
!= DUPLEX_FULL
))
871 if (cmd
->port
!= PORT_MII
)
873 if (cmd
->transceiver
!= XCVR_INTERNAL
)
875 if ((cmd
->autoneg
!= AUTONEG_DISABLE
) &&
876 (cmd
->autoneg
!= AUTONEG_ENABLE
))
879 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
880 if ((cmd
->advertising
& (ADVERTISED_10baseT_Half
|
881 ADVERTISED_10baseT_Full
|
882 ADVERTISED_100baseT_Half
|
883 ADVERTISED_100baseT_Full
)) == 0)
886 switch (ksp
->dtype
) {
887 case KS8695_DTYPE_HPNA
:
888 /* HPNA does not support auto-negotiation. */
890 case KS8695_DTYPE_WAN
:
891 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
893 ctrl
&= ~(WMC_WAND
| WMC_WANA100F
| WMC_WANA100H
|
894 WMC_WANA10F
| WMC_WANA10H
);
895 if (cmd
->advertising
& ADVERTISED_100baseT_Full
)
896 ctrl
|= WMC_WANA100F
;
897 if (cmd
->advertising
& ADVERTISED_100baseT_Half
)
898 ctrl
|= WMC_WANA100H
;
899 if (cmd
->advertising
& ADVERTISED_10baseT_Full
)
901 if (cmd
->advertising
& ADVERTISED_10baseT_Half
)
904 /* force a re-negotiation */
906 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_WMC
);
908 case KS8695_DTYPE_LAN
:
913 switch (ksp
->dtype
) {
914 case KS8695_DTYPE_HPNA
:
915 /* BUG: dtype_hpna implies no phy registers */
917 ctrl = __raw_readl(KS8695_MISC_VA + KS8695_HMC);
919 ctrl &= ~(HMC_HSS | HMC_HDS);
920 if (cmd->speed == SPEED_100)
922 if (cmd->duplex == DUPLEX_FULL)
925 __raw_writel(ctrl, KS8695_MISC_VA + KS8695_HMC);
928 case KS8695_DTYPE_WAN
:
929 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
931 /* disable auto-negotiation */
933 ctrl
&= ~(WMC_WANF100
| WMC_WANFF
);
935 if (cmd
->speed
== SPEED_100
)
937 if (cmd
->duplex
== DUPLEX_FULL
)
940 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_WMC
);
942 case KS8695_DTYPE_LAN
:
951 * ks8695_nwayreset - Restart the autonegotiation on the port.
952 * @ndev: The network device to restart autoneotiation on
955 ks8695_nwayreset(struct net_device
*ndev
)
957 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
960 switch (ksp
->dtype
) {
961 case KS8695_DTYPE_HPNA
:
962 /* No phy means no autonegotiation on hpna */
964 case KS8695_DTYPE_WAN
:
965 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
967 if ((ctrl
& WMC_WAND
) == 0)
968 writel(ctrl
| WMC_WANR
,
969 ksp
->phyiface_regs
+ KS8695_WMC
);
971 /* auto-negotiation not enabled */
974 case KS8695_DTYPE_LAN
:
982 * ks8695_get_link - Retrieve link status of network interface
983 * @ndev: The network interface to retrive the link status of.
986 ks8695_get_link(struct net_device
*ndev
)
988 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
991 switch (ksp
->dtype
) {
992 case KS8695_DTYPE_HPNA
:
993 /* HPNA always has link */
995 case KS8695_DTYPE_WAN
:
996 /* WAN we can read the PHY for */
997 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
998 return ctrl
& WMC_WLS
;
999 case KS8695_DTYPE_LAN
:
1006 * ks8695_get_pause - Retrieve network pause/flow-control advertising
1007 * @ndev: The device to retrieve settings from
1008 * @param: The structure to fill out with the information
1011 ks8695_get_pause(struct net_device
*ndev
, struct ethtool_pauseparam
*param
)
1013 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1016 switch (ksp
->dtype
) {
1017 case KS8695_DTYPE_HPNA
:
1018 /* No phy link on hpna to configure */
1020 case KS8695_DTYPE_WAN
:
1021 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
1023 /* advertise Pause */
1024 param
->autoneg
= (ctrl
& WMC_WANAP
);
1026 /* current Rx Flow-control */
1027 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
1028 param
->rx_pause
= (ctrl
& DRXC_RFCE
);
1030 /* current Tx Flow-control */
1031 ctrl
= ks8695_readreg(ksp
, KS8695_DTXC
);
1032 param
->tx_pause
= (ctrl
& DTXC_TFCE
);
1034 case KS8695_DTYPE_LAN
:
1035 /* The LAN's "phy" is a direct-attached switch */
1041 * ks8695_set_pause - Configure pause/flow-control
1042 * @ndev: The device to configure
1043 * @param: The pause parameters to set
1045 * TODO: Implement this
1048 ks8695_set_pause(struct net_device
*ndev
, struct ethtool_pauseparam
*param
)
1054 * ks8695_get_drvinfo - Retrieve driver information
1055 * @ndev: The network device to retrieve info about
1056 * @info: The info structure to fill out.
1059 ks8695_get_drvinfo(struct net_device
*ndev
, struct ethtool_drvinfo
*info
)
1061 strlcpy(info
->driver
, MODULENAME
, sizeof(info
->driver
));
1062 strlcpy(info
->version
, MODULEVERSION
, sizeof(info
->version
));
1063 strlcpy(info
->bus_info
, ndev
->dev
.parent
->bus_id
,
1064 sizeof(info
->bus_info
));
1067 static struct ethtool_ops ks8695_ethtool_ops
= {
1068 .get_msglevel
= ks8695_get_msglevel
,
1069 .set_msglevel
= ks8695_set_msglevel
,
1070 .get_settings
= ks8695_get_settings
,
1071 .set_settings
= ks8695_set_settings
,
1072 .nway_reset
= ks8695_nwayreset
,
1073 .get_link
= ks8695_get_link
,
1074 .get_pauseparam
= ks8695_get_pause
,
1075 .set_pauseparam
= ks8695_set_pause
,
1076 .get_drvinfo
= ks8695_get_drvinfo
,
1079 /* Network device interface functions */
1082 * ks8695_set_mac - Update MAC in net dev and HW
1083 * @ndev: The network device to update
1084 * @addr: The new MAC address to set
1087 ks8695_set_mac(struct net_device
*ndev
, void *addr
)
1089 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1090 struct sockaddr
*address
= addr
;
1092 if (!is_valid_ether_addr(address
->sa_data
))
1093 return -EADDRNOTAVAIL
;
1095 memcpy(ndev
->dev_addr
, address
->sa_data
, ndev
->addr_len
);
1097 ks8695_update_mac(ksp
);
1099 dev_dbg(ksp
->dev
, "%s: Updated MAC address to %pM\n",
1100 ndev
->name
, ndev
->dev_addr
);
1106 * ks8695_set_multicast - Set up the multicast behaviour of the interface
1107 * @ndev: The net_device to configure
1109 * This routine, called by the net layer, configures promiscuity
1110 * and multicast reception behaviour for the interface.
1113 ks8695_set_multicast(struct net_device
*ndev
)
1115 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1118 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
1120 if (ndev
->flags
& IFF_PROMISC
) {
1121 /* enable promiscuous mode */
1123 } else if (ndev
->flags
& ~IFF_PROMISC
) {
1124 /* disable promiscuous mode */
1128 if (ndev
->flags
& IFF_ALLMULTI
) {
1129 /* enable all multicast mode */
1131 } else if (ndev
->mc_count
> KS8695_NR_ADDRESSES
) {
1132 /* more specific multicast addresses than can be
1133 * handled in hardware
1137 /* enable specific multicasts */
1139 ks8695_init_partial_multicast(ksp
, ndev
->mc_list
,
1143 ks8695_writereg(ksp
, KS8695_DRXC
, ctrl
);
1147 * ks8695_timeout - Handle a network tx/rx timeout.
1148 * @ndev: The net_device which timed out.
1150 * A network transaction timed out, reset the device.
1153 ks8695_timeout(struct net_device
*ndev
)
1155 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1157 netif_stop_queue(ndev
);
1158 ks8695_shutdown(ksp
);
1162 ks8695_update_mac(ksp
);
1164 /* We ignore the return from this since it managed to init
1165 * before it probably will be okay to init again.
1167 ks8695_init_net(ksp
);
1169 /* Reconfigure promiscuity etc */
1170 ks8695_set_multicast(ndev
);
1172 /* And start the TX queue once more */
1173 netif_start_queue(ndev
);
1177 * ks8695_start_xmit - Start a packet transmission
1178 * @skb: The packet to transmit
1179 * @ndev: The network device to send the packet on
1181 * This routine, called by the net layer, takes ownership of the
1182 * sk_buff and adds it to the TX ring. It then kicks the TX DMA
1183 * engine to ensure transmission begins.
1186 ks8695_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
1188 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1192 spin_lock_irq(&ksp
->txq_lock
);
1194 if (ksp
->tx_ring_used
== MAX_TX_DESC
) {
1195 /* Somehow we got entered when we have no room */
1196 spin_unlock_irq(&ksp
->txq_lock
);
1197 return NETDEV_TX_BUSY
;
1200 buff_n
= ksp
->tx_ring_next_slot
;
1202 BUG_ON(ksp
->tx_buffers
[buff_n
].skb
);
1204 dmap
= dma_map_single(ksp
->dev
, skb
->data
, skb
->len
, DMA_TO_DEVICE
);
1205 if (unlikely(dma_mapping_error(ksp
->dev
, dmap
))) {
1206 /* Failed to DMA map this SKB, give it back for now */
1207 spin_unlock_irq(&ksp
->txq_lock
);
1208 dev_dbg(ksp
->dev
, "%s: Could not map DMA memory for "\
1209 "transmission, trying later\n", ndev
->name
);
1210 return NETDEV_TX_BUSY
;
1213 ksp
->tx_buffers
[buff_n
].dma_ptr
= dmap
;
1214 /* Mapped okay, store the buffer pointer and length for later */
1215 ksp
->tx_buffers
[buff_n
].skb
= skb
;
1216 ksp
->tx_buffers
[buff_n
].length
= skb
->len
;
1218 /* Fill out the TX descriptor */
1219 ksp
->tx_ring
[buff_n
].data_ptr
=
1220 cpu_to_le32(ksp
->tx_buffers
[buff_n
].dma_ptr
);
1221 ksp
->tx_ring
[buff_n
].status
=
1222 cpu_to_le32(TDES_IC
| TDES_FS
| TDES_LS
|
1223 (skb
->len
& TDES_TBS
));
1227 /* Hand it over to the hardware */
1228 ksp
->tx_ring
[buff_n
].owner
= cpu_to_le32(TDES_OWN
);
1230 if (++ksp
->tx_ring_used
== MAX_TX_DESC
)
1231 netif_stop_queue(ndev
);
1233 ndev
->trans_start
= jiffies
;
1235 /* Kick the TX DMA in case it decided to go IDLE */
1236 ks8695_writereg(ksp
, KS8695_DTSC
, 0);
1238 /* And update the next ring slot */
1239 ksp
->tx_ring_next_slot
= (buff_n
+ 1) & MAX_TX_DESC_MASK
;
1241 spin_unlock_irq(&ksp
->txq_lock
);
1242 return NETDEV_TX_OK
;
1246 * ks8695_stop - Stop (shutdown) a KS8695 ethernet interface
1247 * @ndev: The net_device to stop
1249 * This disables the TX queue and cleans up a KS8695 ethernet
1253 ks8695_stop(struct net_device
*ndev
)
1255 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1257 netif_stop_queue(ndev
);
1258 netif_carrier_off(ndev
);
1260 ks8695_shutdown(ksp
);
1266 * ks8695_open - Open (bring up) a KS8695 ethernet interface
1267 * @ndev: The net_device to open
1269 * This resets, configures the MAC, initialises the RX ring and
1270 * DMA engines and starts the TX queue for a KS8695 ethernet
1274 ks8695_open(struct net_device
*ndev
)
1276 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1279 if (!is_valid_ether_addr(ndev
->dev_addr
))
1280 return -EADDRNOTAVAIL
;
1284 ks8695_update_mac(ksp
);
1286 ret
= ks8695_init_net(ksp
);
1288 ks8695_shutdown(ksp
);
1292 netif_start_queue(ndev
);
1297 /* Platform device driver */
1300 * ks8695_init_switch - Init LAN switch to known good defaults.
1301 * @ksp: The device to initialise
1303 * This initialises the LAN switch in the KS8695 to a known-good
1306 static void __devinit
1307 ks8695_init_switch(struct ks8695_priv
*ksp
)
1311 /* Default value for SEC0 according to datasheet */
1314 /* LED0 = Speed LED1 = Link/Activity */
1315 ctrl
&= ~(SEC0_LLED1S
| SEC0_LLED0S
);
1316 ctrl
|= (LLED0S_LINK
| LLED1S_LINK_ACTIVITY
);
1319 ctrl
|= SEC0_ENABLE
;
1321 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_SEC0
);
1323 /* Defaults for SEC1 */
1324 writel(0x9400100, ksp
->phyiface_regs
+ KS8695_SEC1
);
1328 * ks8695_init_wan_phy - Initialise the WAN PHY to sensible defaults
1329 * @ksp: The device to initialise
1331 * This initialises a KS8695's WAN phy to sensible values for
1332 * autonegotiation etc.
1334 static void __devinit
1335 ks8695_init_wan_phy(struct ks8695_priv
*ksp
)
1339 /* Support auto-negotiation */
1340 ctrl
= (WMC_WANAP
| WMC_WANA100F
| WMC_WANA100H
|
1341 WMC_WANA10F
| WMC_WANA10H
);
1343 /* LED0 = Activity , LED1 = Link */
1344 ctrl
|= (WLED0S_ACTIVITY
| WLED1S_LINK
);
1346 /* Restart Auto-negotiation */
1349 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_WMC
);
1351 writel(0, ksp
->phyiface_regs
+ KS8695_WPPM
);
1352 writel(0, ksp
->phyiface_regs
+ KS8695_PPS
);
1355 static const struct net_device_ops ks8695_netdev_ops
= {
1356 .ndo_open
= ks8695_open
,
1357 .ndo_stop
= ks8695_stop
,
1358 .ndo_start_xmit
= ks8695_start_xmit
,
1359 .ndo_tx_timeout
= ks8695_timeout
,
1360 .ndo_set_mac_address
= ks8695_set_mac
,
1361 .ndo_set_multicast_list
= ks8695_set_multicast
,
1365 * ks8695_probe - Probe and initialise a KS8695 ethernet interface
1366 * @pdev: The platform device to probe
1368 * Initialise a KS8695 ethernet device from platform data.
1370 * This driver requires at least one IORESOURCE_MEM for the
1371 * registers and two IORESOURCE_IRQ for the RX and TX IRQs
1372 * respectively. It can optionally take an additional
1373 * IORESOURCE_MEM for the switch or phy in the case of the lan or
1374 * wan ports, and an IORESOURCE_IRQ for the link IRQ for the wan
1377 static int __devinit
1378 ks8695_probe(struct platform_device
*pdev
)
1380 struct ks8695_priv
*ksp
;
1381 struct net_device
*ndev
;
1382 struct resource
*regs_res
, *phyiface_res
;
1383 struct resource
*rxirq_res
, *txirq_res
, *linkirq_res
;
1386 u32 machigh
, maclow
;
1388 /* Initialise a net_device */
1389 ndev
= alloc_etherdev(sizeof(struct ks8695_priv
));
1391 dev_err(&pdev
->dev
, "could not allocate device.\n");
1395 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
1397 dev_dbg(&pdev
->dev
, "ks8695_probe() called\n");
1399 /* Configure our private structure a little */
1400 ksp
= netdev_priv(ndev
);
1401 memset(ksp
, 0, sizeof(struct ks8695_priv
));
1403 ksp
->dev
= &pdev
->dev
;
1405 ksp
->msg_enable
= NETIF_MSG_LINK
;
1407 /* Retrieve resources */
1408 regs_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1409 phyiface_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1411 rxirq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1412 txirq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 1);
1413 linkirq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 2);
1415 if (!(regs_res
&& rxirq_res
&& txirq_res
)) {
1416 dev_err(ksp
->dev
, "insufficient resources\n");
1421 ksp
->regs_req
= request_mem_region(regs_res
->start
,
1422 resource_size(regs_res
),
1425 if (!ksp
->regs_req
) {
1426 dev_err(ksp
->dev
, "cannot claim register space\n");
1431 ksp
->io_regs
= ioremap(regs_res
->start
, resource_size(regs_res
));
1433 if (!ksp
->io_regs
) {
1434 dev_err(ksp
->dev
, "failed to ioremap registers\n");
1441 request_mem_region(phyiface_res
->start
,
1442 resource_size(phyiface_res
),
1443 phyiface_res
->name
);
1445 if (!ksp
->phyiface_req
) {
1447 "cannot claim switch register space\n");
1452 ksp
->phyiface_regs
= ioremap(phyiface_res
->start
,
1453 resource_size(phyiface_res
));
1455 if (!ksp
->phyiface_regs
) {
1457 "failed to ioremap switch registers\n");
1463 ksp
->rx_irq
= rxirq_res
->start
;
1464 ksp
->rx_irq_name
= rxirq_res
->name
? rxirq_res
->name
: "Ethernet RX";
1465 ksp
->tx_irq
= txirq_res
->start
;
1466 ksp
->tx_irq_name
= txirq_res
->name
? txirq_res
->name
: "Ethernet TX";
1467 ksp
->link_irq
= (linkirq_res
? linkirq_res
->start
: -1);
1468 ksp
->link_irq_name
= (linkirq_res
&& linkirq_res
->name
) ?
1469 linkirq_res
->name
: "Ethernet Link";
1471 /* driver system setup */
1472 ndev
->netdev_ops
= &ks8695_netdev_ops
;
1473 SET_ETHTOOL_OPS(ndev
, &ks8695_ethtool_ops
);
1474 ndev
->watchdog_timeo
= msecs_to_jiffies(watchdog
);
1476 /* Retrieve the default MAC addr from the chip. */
1477 /* The bootloader should have left it in there for us. */
1479 machigh
= ks8695_readreg(ksp
, KS8695_MAH
);
1480 maclow
= ks8695_readreg(ksp
, KS8695_MAL
);
1482 ndev
->dev_addr
[0] = (machigh
>> 8) & 0xFF;
1483 ndev
->dev_addr
[1] = machigh
& 0xFF;
1484 ndev
->dev_addr
[2] = (maclow
>> 24) & 0xFF;
1485 ndev
->dev_addr
[3] = (maclow
>> 16) & 0xFF;
1486 ndev
->dev_addr
[4] = (maclow
>> 8) & 0xFF;
1487 ndev
->dev_addr
[5] = maclow
& 0xFF;
1489 if (!is_valid_ether_addr(ndev
->dev_addr
))
1490 dev_warn(ksp
->dev
, "%s: Invalid ethernet MAC address. Please "
1491 "set using ifconfig\n", ndev
->name
);
1493 /* In order to be efficient memory-wise, we allocate both
1496 ksp
->ring_base
= dma_alloc_coherent(&pdev
->dev
, RING_DMA_SIZE
,
1497 &ksp
->ring_base_dma
, GFP_KERNEL
);
1498 if (!ksp
->ring_base
) {
1503 /* Specify the TX DMA ring buffer */
1504 ksp
->tx_ring
= ksp
->ring_base
;
1505 ksp
->tx_ring_dma
= ksp
->ring_base_dma
;
1507 /* And initialise the queue's lock */
1508 spin_lock_init(&ksp
->txq_lock
);
1510 /* Specify the RX DMA ring buffer */
1511 ksp
->rx_ring
= ksp
->ring_base
+ TX_RING_DMA_SIZE
;
1512 ksp
->rx_ring_dma
= ksp
->ring_base_dma
+ TX_RING_DMA_SIZE
;
1514 /* Zero the descriptor rings */
1515 memset(ksp
->tx_ring
, 0, TX_RING_DMA_SIZE
);
1516 memset(ksp
->rx_ring
, 0, RX_RING_DMA_SIZE
);
1518 /* Build the rings */
1519 for (buff_n
= 0; buff_n
< MAX_TX_DESC
; ++buff_n
) {
1520 ksp
->tx_ring
[buff_n
].next_desc
=
1521 cpu_to_le32(ksp
->tx_ring_dma
+
1522 (sizeof(struct tx_ring_desc
) *
1523 ((buff_n
+ 1) & MAX_TX_DESC_MASK
)));
1526 for (buff_n
= 0; buff_n
< MAX_RX_DESC
; ++buff_n
) {
1527 ksp
->rx_ring
[buff_n
].next_desc
=
1528 cpu_to_le32(ksp
->rx_ring_dma
+
1529 (sizeof(struct rx_ring_desc
) *
1530 ((buff_n
+ 1) & MAX_RX_DESC_MASK
)));
1533 /* Initialise the port (physically) */
1534 if (ksp
->phyiface_regs
&& ksp
->link_irq
== -1) {
1535 ks8695_init_switch(ksp
);
1536 ksp
->dtype
= KS8695_DTYPE_LAN
;
1537 } else if (ksp
->phyiface_regs
&& ksp
->link_irq
!= -1) {
1538 ks8695_init_wan_phy(ksp
);
1539 ksp
->dtype
= KS8695_DTYPE_WAN
;
1541 /* No initialisation since HPNA does not have a PHY */
1542 ksp
->dtype
= KS8695_DTYPE_HPNA
;
1545 /* And bring up the net_device with the net core */
1546 platform_set_drvdata(pdev
, ndev
);
1547 ret
= register_netdev(ndev
);
1550 dev_info(ksp
->dev
, "ks8695 ethernet (%s) MAC: %pM\n",
1551 ks8695_port_type(ksp
), ndev
->dev_addr
);
1553 /* Report the failure to register the net_device */
1554 dev_err(ksp
->dev
, "ks8695net: failed to register netdev.\n");
1561 /* Error exit path */
1563 ks8695_release_device(ksp
);
1570 * ks8695_drv_suspend - Suspend a KS8695 ethernet platform device.
1571 * @pdev: The device to suspend
1572 * @state: The suspend state
1574 * This routine detaches and shuts down a KS8695 ethernet device.
1577 ks8695_drv_suspend(struct platform_device
*pdev
, pm_message_t state
)
1579 struct net_device
*ndev
= platform_get_drvdata(pdev
);
1580 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1582 ksp
->in_suspend
= 1;
1584 if (netif_running(ndev
)) {
1585 netif_device_detach(ndev
);
1586 ks8695_shutdown(ksp
);
1593 * ks8695_drv_resume - Resume a KS8695 ethernet platform device.
1594 * @pdev: The device to resume
1596 * This routine re-initialises and re-attaches a KS8695 ethernet
1600 ks8695_drv_resume(struct platform_device
*pdev
)
1602 struct net_device
*ndev
= platform_get_drvdata(pdev
);
1603 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1605 if (netif_running(ndev
)) {
1607 ks8695_init_net(ksp
);
1608 ks8695_set_multicast(ndev
);
1609 netif_device_attach(ndev
);
1612 ksp
->in_suspend
= 0;
1618 * ks8695_drv_remove - Remove a KS8695 net device on driver unload.
1619 * @pdev: The platform device to remove
1621 * This unregisters and releases a KS8695 ethernet device.
1623 static int __devexit
1624 ks8695_drv_remove(struct platform_device
*pdev
)
1626 struct net_device
*ndev
= platform_get_drvdata(pdev
);
1627 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1629 platform_set_drvdata(pdev
, NULL
);
1631 unregister_netdev(ndev
);
1632 ks8695_release_device(ksp
);
1635 dev_dbg(&pdev
->dev
, "released and freed device\n");
1639 static struct platform_driver ks8695_driver
= {
1642 .owner
= THIS_MODULE
,
1644 .probe
= ks8695_probe
,
1645 .remove
= __devexit_p(ks8695_drv_remove
),
1646 .suspend
= ks8695_drv_suspend
,
1647 .resume
= ks8695_drv_resume
,
1650 /* Module interface */
1655 printk(KERN_INFO
"%s Ethernet driver, V%s\n",
1656 MODULENAME
, MODULEVERSION
);
1658 return platform_driver_register(&ks8695_driver
);
1662 ks8695_cleanup(void)
1664 platform_driver_unregister(&ks8695_driver
);
1667 module_init(ks8695_init
);
1668 module_exit(ks8695_cleanup
);
1670 MODULE_AUTHOR("Simtec Electronics")
1671 MODULE_DESCRIPTION("Micrel KS8695 (Centaur) Ethernet driver");
1672 MODULE_LICENSE("GPL");
1673 MODULE_ALIAS("platform:" MODULENAME
);
1675 module_param(watchdog
, int, 0400);
1676 MODULE_PARM_DESC(watchdog
, "transmit timeout in milliseconds");