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>
33 #include <linux/slab.h>
37 #include <mach/regs-switch.h>
38 #include <mach/regs-misc.h>
39 #include <asm/mach/irq.h>
40 #include <mach/regs-irq.h>
42 #include "ks8695net.h"
44 #define MODULENAME "ks8695_ether"
45 #define MODULEVERSION "1.02"
48 * Transmit and device reset timeout, default 5 seconds.
50 static int watchdog
= 5000;
52 /* Hardware structures */
55 * struct rx_ring_desc - Receive descriptor ring element
56 * @status: The status of the descriptor element (E.g. who owns it)
57 * @length: The number of bytes in the block pointed to by data_ptr
58 * @data_ptr: The physical address of the data block to receive into
59 * @next_desc: The physical address of the next descriptor element.
69 * struct tx_ring_desc - Transmit descriptor ring element
70 * @owner: Who owns the descriptor
71 * @status: The number of bytes in the block pointed to by data_ptr
72 * @data_ptr: The physical address of the data block to receive into
73 * @next_desc: The physical address of the next descriptor element.
83 * struct ks8695_skbuff - sk_buff wrapper for rx/tx rings.
84 * @skb: The buffer in the ring
85 * @dma_ptr: The mapped DMA pointer of the buffer
86 * @length: The number of bytes mapped to dma_ptr
88 struct ks8695_skbuff
{
94 /* Private device structure */
97 #define MAX_TX_DESC_MASK 0x7
98 #define MAX_RX_DESC 16
99 #define MAX_RX_DESC_MASK 0xf
101 /*napi_weight have better more than rx DMA buffers*/
102 #define NAPI_WEIGHT 64
104 #define MAX_RXBUF_SIZE 0x700
106 #define TX_RING_DMA_SIZE (sizeof(struct tx_ring_desc) * MAX_TX_DESC)
107 #define RX_RING_DMA_SIZE (sizeof(struct rx_ring_desc) * MAX_RX_DESC)
108 #define RING_DMA_SIZE (TX_RING_DMA_SIZE + RX_RING_DMA_SIZE)
111 * enum ks8695_dtype - Device type
112 * @KS8695_DTYPE_WAN: This device is a WAN interface
113 * @KS8695_DTYPE_LAN: This device is a LAN interface
114 * @KS8695_DTYPE_HPNA: This device is an HPNA interface
123 * struct ks8695_priv - Private data for the KS8695 Ethernet
124 * @in_suspend: Flag to indicate if we're suspending/resuming
125 * @ndev: The net_device for this interface
126 * @dev: The platform device object for this interface
127 * @dtype: The type of this device
128 * @io_regs: The ioremapped registers for this interface
129 * @napi : Add support NAPI for Rx
130 * @rx_irq_name: The textual name of the RX IRQ from the platform data
131 * @tx_irq_name: The textual name of the TX IRQ from the platform data
132 * @link_irq_name: The textual name of the link IRQ from the
133 * platform data if available
134 * @rx_irq: The IRQ number for the RX IRQ
135 * @tx_irq: The IRQ number for the TX IRQ
136 * @link_irq: The IRQ number for the link IRQ if available
137 * @regs_req: The resource request for the registers region
138 * @phyiface_req: The resource request for the phy/switch region
140 * @phyiface_regs: The ioremapped registers for the phy/switch if available
141 * @ring_base: The base pointer of the dma coherent memory for the rings
142 * @ring_base_dma: The DMA mapped equivalent of ring_base
143 * @tx_ring: The pointer in ring_base of the TX ring
144 * @tx_ring_used: The number of slots in the TX ring which are occupied
145 * @tx_ring_next_slot: The next slot to fill in the TX ring
146 * @tx_ring_dma: The DMA mapped equivalent of tx_ring
147 * @tx_buffers: The sk_buff mappings for the TX ring
148 * @txq_lock: A lock to protect the tx_buffers tx_ring_used etc variables
149 * @rx_ring: The pointer in ring_base of the RX ring
150 * @rx_ring_dma: The DMA mapped equivalent of rx_ring
151 * @rx_buffers: The sk_buff mappings for the RX ring
152 * @next_rx_desc_read: The next RX descriptor to read from on IRQ
153 * @rx_lock: A lock to protect Rx irq function
154 * @msg_enable: The flags for which messages to emit
158 struct net_device
*ndev
;
160 enum ks8695_dtype dtype
;
161 void __iomem
*io_regs
;
163 struct napi_struct napi
;
165 const char *rx_irq_name
, *tx_irq_name
, *link_irq_name
;
166 int rx_irq
, tx_irq
, link_irq
;
168 struct resource
*regs_req
, *phyiface_req
;
169 void __iomem
*phyiface_regs
;
172 dma_addr_t ring_base_dma
;
174 struct tx_ring_desc
*tx_ring
;
176 int tx_ring_next_slot
;
177 dma_addr_t tx_ring_dma
;
178 struct ks8695_skbuff tx_buffers
[MAX_TX_DESC
];
181 struct rx_ring_desc
*rx_ring
;
182 dma_addr_t rx_ring_dma
;
183 struct ks8695_skbuff rx_buffers
[MAX_RX_DESC
];
184 int next_rx_desc_read
;
190 /* Register access */
193 * ks8695_readreg - Read from a KS8695 ethernet register
194 * @ksp: The device to read from
195 * @reg: The register to read
198 ks8695_readreg(struct ks8695_priv
*ksp
, int reg
)
200 return readl(ksp
->io_regs
+ reg
);
204 * ks8695_writereg - Write to a KS8695 ethernet register
205 * @ksp: The device to write to
206 * @reg: The register to write
207 * @value: The value to write to the register
210 ks8695_writereg(struct ks8695_priv
*ksp
, int reg
, u32 value
)
212 writel(value
, ksp
->io_regs
+ reg
);
215 /* Utility functions */
218 * ks8695_port_type - Retrieve port-type as user-friendly string
219 * @ksp: The device to return the type for
221 * Returns a string indicating which of the WAN, LAN or HPNA
222 * ports this device is likely to represent.
225 ks8695_port_type(struct ks8695_priv
*ksp
)
227 switch (ksp
->dtype
) {
228 case KS8695_DTYPE_LAN
:
230 case KS8695_DTYPE_WAN
:
232 case KS8695_DTYPE_HPNA
:
240 * ks8695_update_mac - Update the MAC registers in the device
241 * @ksp: The device to update
243 * Updates the MAC registers in the KS8695 device from the address in the
244 * net_device structure associated with this interface.
247 ks8695_update_mac(struct ks8695_priv
*ksp
)
249 /* Update the HW with the MAC from the net_device */
250 struct net_device
*ndev
= ksp
->ndev
;
253 maclow
= ((ndev
->dev_addr
[2] << 24) | (ndev
->dev_addr
[3] << 16) |
254 (ndev
->dev_addr
[4] << 8) | (ndev
->dev_addr
[5] << 0));
255 machigh
= ((ndev
->dev_addr
[0] << 8) | (ndev
->dev_addr
[1] << 0));
257 ks8695_writereg(ksp
, KS8695_MAL
, maclow
);
258 ks8695_writereg(ksp
, KS8695_MAH
, machigh
);
263 * ks8695_refill_rxbuffers - Re-fill the RX buffer ring
264 * @ksp: The device to refill
266 * Iterates the RX ring of the device looking for empty slots.
267 * For each empty slot, we allocate and map a new SKB and give it
269 * This can be called from interrupt context safely.
272 ks8695_refill_rxbuffers(struct ks8695_priv
*ksp
)
274 /* Run around the RX ring, filling in any missing sk_buff's */
277 for (buff_n
= 0; buff_n
< MAX_RX_DESC
; ++buff_n
) {
278 if (!ksp
->rx_buffers
[buff_n
].skb
) {
279 struct sk_buff
*skb
= dev_alloc_skb(MAX_RXBUF_SIZE
);
282 ksp
->rx_buffers
[buff_n
].skb
= skb
;
284 /* Failed to allocate one, perhaps
285 * we'll try again later.
290 mapping
= dma_map_single(ksp
->dev
, skb
->data
,
293 if (unlikely(dma_mapping_error(ksp
->dev
, mapping
))) {
294 /* Failed to DMA map this SKB, try later */
295 dev_kfree_skb_irq(skb
);
296 ksp
->rx_buffers
[buff_n
].skb
= NULL
;
299 ksp
->rx_buffers
[buff_n
].dma_ptr
= mapping
;
300 skb
->dev
= ksp
->ndev
;
301 ksp
->rx_buffers
[buff_n
].length
= MAX_RXBUF_SIZE
;
303 /* Record this into the DMA ring */
304 ksp
->rx_ring
[buff_n
].data_ptr
= cpu_to_le32(mapping
);
305 ksp
->rx_ring
[buff_n
].length
=
306 cpu_to_le32(MAX_RXBUF_SIZE
);
310 /* And give ownership over to the hardware */
311 ksp
->rx_ring
[buff_n
].status
= cpu_to_le32(RDES_OWN
);
316 /* Maximum number of multicast addresses which the KS8695 HW supports */
317 #define KS8695_NR_ADDRESSES 16
320 * ks8695_init_partial_multicast - Init the mcast addr registers
321 * @ksp: The device to initialise
322 * @addr: The multicast address list to use
323 * @nr_addr: The number of addresses in the list
325 * This routine is a helper for ks8695_set_multicast - it writes
326 * the additional-address registers in the KS8695 ethernet device
327 * and cleans up any others left behind.
330 ks8695_init_partial_multicast(struct ks8695_priv
*ksp
,
331 struct net_device
*ndev
)
335 struct netdev_hw_addr
*ha
;
338 netdev_for_each_mc_addr(ha
, ndev
) {
339 /* Ran out of space in chip? */
340 BUG_ON(i
== KS8695_NR_ADDRESSES
);
342 low
= (ha
->addr
[2] << 24) | (ha
->addr
[3] << 16) |
343 (ha
->addr
[4] << 8) | (ha
->addr
[5]);
344 high
= (ha
->addr
[0] << 8) | (ha
->addr
[1]);
346 ks8695_writereg(ksp
, KS8695_AAL_(i
), low
);
347 ks8695_writereg(ksp
, KS8695_AAH_(i
), AAH_E
| high
);
351 /* Clear the remaining Additional Station Addresses */
352 for (; i
< KS8695_NR_ADDRESSES
; i
++) {
353 ks8695_writereg(ksp
, KS8695_AAL_(i
), 0);
354 ks8695_writereg(ksp
, KS8695_AAH_(i
), 0);
358 /* Interrupt handling */
361 * ks8695_tx_irq - Transmit IRQ handler
362 * @irq: The IRQ which went off (ignored)
363 * @dev_id: The net_device for the interrupt
365 * Process the TX ring, clearing out any transmitted slots.
366 * Allows the net_device to pass us new packets once slots are
370 ks8695_tx_irq(int irq
, void *dev_id
)
372 struct net_device
*ndev
= (struct net_device
*)dev_id
;
373 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
376 for (buff_n
= 0; buff_n
< MAX_TX_DESC
; ++buff_n
) {
377 if (ksp
->tx_buffers
[buff_n
].skb
&&
378 !(ksp
->tx_ring
[buff_n
].owner
& cpu_to_le32(TDES_OWN
))) {
380 /* An SKB which is not owned by HW is present */
381 /* Update the stats for the net_device */
382 ndev
->stats
.tx_packets
++;
383 ndev
->stats
.tx_bytes
+= ksp
->tx_buffers
[buff_n
].length
;
385 /* Free the packet from the ring */
386 ksp
->tx_ring
[buff_n
].data_ptr
= 0;
388 /* Free the sk_buff */
389 dma_unmap_single(ksp
->dev
,
390 ksp
->tx_buffers
[buff_n
].dma_ptr
,
391 ksp
->tx_buffers
[buff_n
].length
,
393 dev_kfree_skb_irq(ksp
->tx_buffers
[buff_n
].skb
);
394 ksp
->tx_buffers
[buff_n
].skb
= NULL
;
399 netif_wake_queue(ndev
);
405 * ks8695_get_rx_enable_bit - Get rx interrupt enable/status bit
406 * @ksp: Private data for the KS8695 Ethernet
408 * For KS8695 document:
409 * Interrupt Enable Register (offset 0xE204)
410 * Bit29 : WAN MAC Receive Interrupt Enable
411 * Bit16 : LAN MAC Receive Interrupt Enable
412 * Interrupt Status Register (Offset 0xF208)
413 * Bit29: WAN MAC Receive Status
414 * Bit16: LAN MAC Receive Status
415 * So, this Rx interrrupt enable/status bit number is equal
418 static inline u32
ks8695_get_rx_enable_bit(struct ks8695_priv
*ksp
)
424 * ks8695_rx_irq - Receive IRQ handler
425 * @irq: The IRQ which went off (ignored)
426 * @dev_id: The net_device for the interrupt
428 * Inform NAPI that packet reception needs to be scheduled
432 ks8695_rx_irq(int irq
, void *dev_id
)
434 struct net_device
*ndev
= (struct net_device
*)dev_id
;
435 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
437 spin_lock(&ksp
->rx_lock
);
439 if (napi_schedule_prep(&ksp
->napi
)) {
440 unsigned long status
= readl(KS8695_IRQ_VA
+ KS8695_INTEN
);
441 unsigned long mask_bit
= 1 << ks8695_get_rx_enable_bit(ksp
);
442 /*disable rx interrupt*/
444 writel(status
, KS8695_IRQ_VA
+ KS8695_INTEN
);
445 __napi_schedule(&ksp
->napi
);
448 spin_unlock(&ksp
->rx_lock
);
453 * ks8695_rx - Receive packets called by NAPI poll method
454 * @ksp: Private data for the KS8695 Ethernet
455 * @budget: Number of packets allowed to process
457 static int ks8695_rx(struct ks8695_priv
*ksp
, int budget
)
459 struct net_device
*ndev
= ksp
->ndev
;
466 buff_n
= ksp
->next_rx_desc_read
;
467 while (received
< budget
468 && ksp
->rx_buffers
[buff_n
].skb
469 && (!(ksp
->rx_ring
[buff_n
].status
&
470 cpu_to_le32(RDES_OWN
)))) {
472 flags
= le32_to_cpu(ksp
->rx_ring
[buff_n
].status
);
474 /* Found an SKB which we own, this means we
477 if ((flags
& (RDES_FS
| RDES_LS
)) !=
478 (RDES_FS
| RDES_LS
)) {
479 /* This packet is not the first and
480 * the last segment. Therefore it is
481 * a "spanning" packet and we can't
487 if (flags
& (RDES_ES
| RDES_RE
)) {
488 /* It's an error packet */
489 ndev
->stats
.rx_errors
++;
491 ndev
->stats
.rx_length_errors
++;
493 ndev
->stats
.rx_length_errors
++;
495 ndev
->stats
.rx_crc_errors
++;
497 ndev
->stats
.rx_missed_errors
++;
502 pktlen
= flags
& RDES_FLEN
;
503 pktlen
-= 4; /* Drop the CRC */
505 /* Retrieve the sk_buff */
506 skb
= ksp
->rx_buffers
[buff_n
].skb
;
508 /* Clear it from the ring */
509 ksp
->rx_buffers
[buff_n
].skb
= NULL
;
510 ksp
->rx_ring
[buff_n
].data_ptr
= 0;
513 dma_unmap_single(ksp
->dev
,
514 ksp
->rx_buffers
[buff_n
].dma_ptr
,
515 ksp
->rx_buffers
[buff_n
].length
,
518 /* Relinquish the SKB to the network layer */
519 skb_put(skb
, pktlen
);
520 skb
->protocol
= eth_type_trans(skb
, ndev
);
521 netif_receive_skb(skb
);
524 ndev
->stats
.rx_packets
++;
525 ndev
->stats
.rx_bytes
+= pktlen
;
529 /* This ring entry is an error, but we can
532 /* Give the ring entry back to the hardware */
533 ksp
->rx_ring
[buff_n
].status
= cpu_to_le32(RDES_OWN
);
536 buff_n
= (buff_n
+ 1) & MAX_RX_DESC_MASK
;
539 /* And note which RX descriptor we last did */
540 ksp
->next_rx_desc_read
= buff_n
;
542 /* And refill the buffers */
543 ks8695_refill_rxbuffers(ksp
);
545 /* Kick the RX DMA engine, in case it became suspended */
546 ks8695_writereg(ksp
, KS8695_DRSC
, 0);
553 * ks8695_poll - Receive packet by NAPI poll method
554 * @ksp: Private data for the KS8695 Ethernet
555 * @budget: The remaining number packets for network subsystem
557 * Invoked by the network core when it requests for new
558 * packets from the driver
560 static int ks8695_poll(struct napi_struct
*napi
, int budget
)
562 struct ks8695_priv
*ksp
= container_of(napi
, struct ks8695_priv
, napi
);
563 unsigned long work_done
;
565 unsigned long isr
= readl(KS8695_IRQ_VA
+ KS8695_INTEN
);
566 unsigned long mask_bit
= 1 << ks8695_get_rx_enable_bit(ksp
);
568 work_done
= ks8695_rx(ksp
, budget
);
570 if (work_done
< budget
) {
572 spin_lock_irqsave(&ksp
->rx_lock
, flags
);
573 __napi_complete(napi
);
574 /*enable rx interrupt*/
575 writel(isr
| mask_bit
, KS8695_IRQ_VA
+ KS8695_INTEN
);
576 spin_unlock_irqrestore(&ksp
->rx_lock
, flags
);
582 * ks8695_link_irq - Link change IRQ handler
583 * @irq: The IRQ which went off (ignored)
584 * @dev_id: The net_device for the interrupt
586 * The WAN interface can generate an IRQ when the link changes,
587 * report this to the net layer and the user.
590 ks8695_link_irq(int irq
, void *dev_id
)
592 struct net_device
*ndev
= (struct net_device
*)dev_id
;
593 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
596 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
597 if (ctrl
& WMC_WLS
) {
598 netif_carrier_on(ndev
);
599 if (netif_msg_link(ksp
))
601 "%s: Link is now up (10%sMbps/%s-duplex)\n",
603 (ctrl
& WMC_WSS
) ? "0" : "",
604 (ctrl
& WMC_WDS
) ? "Full" : "Half");
606 netif_carrier_off(ndev
);
607 if (netif_msg_link(ksp
))
608 dev_info(ksp
->dev
, "%s: Link is now down.\n",
616 /* KS8695 Device functions */
619 * ks8695_reset - Reset a KS8695 ethernet interface
620 * @ksp: The interface to reset
622 * Perform an engine reset of the interface and re-program it
623 * with sensible defaults.
626 ks8695_reset(struct ks8695_priv
*ksp
)
628 int reset_timeout
= watchdog
;
629 /* Issue the reset via the TX DMA control register */
630 ks8695_writereg(ksp
, KS8695_DTXC
, DTXC_TRST
);
631 while (reset_timeout
--) {
632 if (!(ks8695_readreg(ksp
, KS8695_DTXC
) & DTXC_TRST
))
637 if (reset_timeout
< 0) {
639 "Timeout waiting for DMA engines to reset\n");
640 /* And blithely carry on */
643 /* Definitely wait long enough before attempting to program
648 /* RX: unicast and broadcast */
649 ks8695_writereg(ksp
, KS8695_DRXC
, DRXC_RU
| DRXC_RB
);
650 /* TX: pad and add CRC */
651 ks8695_writereg(ksp
, KS8695_DTXC
, DTXC_TEP
| DTXC_TAC
);
655 * ks8695_shutdown - Shut down a KS8695 ethernet interface
656 * @ksp: The interface to shut down
658 * This disables packet RX/TX, cleans up IRQs, drains the rings,
659 * and basically places the interface into a clean shutdown
663 ks8695_shutdown(struct ks8695_priv
*ksp
)
668 /* Disable packet transmission */
669 ctrl
= ks8695_readreg(ksp
, KS8695_DTXC
);
670 ks8695_writereg(ksp
, KS8695_DTXC
, ctrl
& ~DTXC_TE
);
672 /* Disable packet reception */
673 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
674 ks8695_writereg(ksp
, KS8695_DRXC
, ctrl
& ~DRXC_RE
);
676 /* Release the IRQs */
677 free_irq(ksp
->rx_irq
, ksp
->ndev
);
678 free_irq(ksp
->tx_irq
, ksp
->ndev
);
679 if (ksp
->link_irq
!= -1)
680 free_irq(ksp
->link_irq
, ksp
->ndev
);
682 /* Throw away any pending TX packets */
683 for (buff_n
= 0; buff_n
< MAX_TX_DESC
; ++buff_n
) {
684 if (ksp
->tx_buffers
[buff_n
].skb
) {
685 /* Remove this SKB from the TX ring */
686 ksp
->tx_ring
[buff_n
].owner
= 0;
687 ksp
->tx_ring
[buff_n
].status
= 0;
688 ksp
->tx_ring
[buff_n
].data_ptr
= 0;
690 /* Unmap and bin this SKB */
691 dma_unmap_single(ksp
->dev
,
692 ksp
->tx_buffers
[buff_n
].dma_ptr
,
693 ksp
->tx_buffers
[buff_n
].length
,
695 dev_kfree_skb_irq(ksp
->tx_buffers
[buff_n
].skb
);
696 ksp
->tx_buffers
[buff_n
].skb
= NULL
;
700 /* Purge the RX buffers */
701 for (buff_n
= 0; buff_n
< MAX_RX_DESC
; ++buff_n
) {
702 if (ksp
->rx_buffers
[buff_n
].skb
) {
703 /* Remove the SKB from the RX ring */
704 ksp
->rx_ring
[buff_n
].status
= 0;
705 ksp
->rx_ring
[buff_n
].data_ptr
= 0;
707 /* Unmap and bin the SKB */
708 dma_unmap_single(ksp
->dev
,
709 ksp
->rx_buffers
[buff_n
].dma_ptr
,
710 ksp
->rx_buffers
[buff_n
].length
,
712 dev_kfree_skb_irq(ksp
->rx_buffers
[buff_n
].skb
);
713 ksp
->rx_buffers
[buff_n
].skb
= NULL
;
720 * ks8695_setup_irq - IRQ setup helper function
721 * @irq: The IRQ number to claim
722 * @irq_name: The name to give the IRQ claimant
723 * @handler: The function to call to handle the IRQ
724 * @ndev: The net_device to pass in as the dev_id argument to the handler
726 * Return 0 on success.
729 ks8695_setup_irq(int irq
, const char *irq_name
,
730 irq_handler_t handler
, struct net_device
*ndev
)
734 ret
= request_irq(irq
, handler
, IRQF_SHARED
, irq_name
, ndev
);
737 dev_err(&ndev
->dev
, "failure to request IRQ %d\n", irq
);
745 * ks8695_init_net - Initialise a KS8695 ethernet interface
746 * @ksp: The interface to initialise
748 * This routine fills the RX ring, initialises the DMA engines,
749 * allocates the IRQs and then starts the packet TX and RX
753 ks8695_init_net(struct ks8695_priv
*ksp
)
758 ks8695_refill_rxbuffers(ksp
);
760 /* Initialise the DMA engines */
761 ks8695_writereg(ksp
, KS8695_RDLB
, (u32
) ksp
->rx_ring_dma
);
762 ks8695_writereg(ksp
, KS8695_TDLB
, (u32
) ksp
->tx_ring_dma
);
764 /* Request the IRQs */
765 ret
= ks8695_setup_irq(ksp
->rx_irq
, ksp
->rx_irq_name
,
766 ks8695_rx_irq
, ksp
->ndev
);
769 ret
= ks8695_setup_irq(ksp
->tx_irq
, ksp
->tx_irq_name
,
770 ks8695_tx_irq
, ksp
->ndev
);
773 if (ksp
->link_irq
!= -1) {
774 ret
= ks8695_setup_irq(ksp
->link_irq
, ksp
->link_irq_name
,
775 ks8695_link_irq
, ksp
->ndev
);
780 /* Set up the ring indices */
781 ksp
->next_rx_desc_read
= 0;
782 ksp
->tx_ring_next_slot
= 0;
783 ksp
->tx_ring_used
= 0;
785 /* Bring up transmission */
786 ctrl
= ks8695_readreg(ksp
, KS8695_DTXC
);
787 /* Enable packet transmission */
788 ks8695_writereg(ksp
, KS8695_DTXC
, ctrl
| DTXC_TE
);
790 /* Bring up the reception */
791 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
792 /* Enable packet reception */
793 ks8695_writereg(ksp
, KS8695_DRXC
, ctrl
| DRXC_RE
);
794 /* And start the DMA engine */
795 ks8695_writereg(ksp
, KS8695_DRSC
, 0);
802 * ks8695_release_device - HW resource release for KS8695 e-net
803 * @ksp: The device to be freed
805 * This unallocates io memory regions, dma-coherent regions etc
806 * which were allocated in ks8695_probe.
809 ks8695_release_device(struct ks8695_priv
*ksp
)
811 /* Unmap the registers */
812 iounmap(ksp
->io_regs
);
813 if (ksp
->phyiface_regs
)
814 iounmap(ksp
->phyiface_regs
);
816 /* And release the request */
817 release_resource(ksp
->regs_req
);
818 kfree(ksp
->regs_req
);
819 if (ksp
->phyiface_req
) {
820 release_resource(ksp
->phyiface_req
);
821 kfree(ksp
->phyiface_req
);
824 /* Free the ring buffers */
825 dma_free_coherent(ksp
->dev
, RING_DMA_SIZE
,
826 ksp
->ring_base
, ksp
->ring_base_dma
);
829 /* Ethtool support */
832 * ks8695_get_msglevel - Get the messages enabled for emission
833 * @ndev: The network device to read from
836 ks8695_get_msglevel(struct net_device
*ndev
)
838 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
840 return ksp
->msg_enable
;
844 * ks8695_set_msglevel - Set the messages enabled for emission
845 * @ndev: The network device to configure
846 * @value: The messages to set for emission
849 ks8695_set_msglevel(struct net_device
*ndev
, u32 value
)
851 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
853 ksp
->msg_enable
= value
;
857 * ks8695_wan_get_settings - Get device-specific settings.
858 * @ndev: The network device to read settings from
859 * @cmd: The ethtool structure to read into
862 ks8695_wan_get_settings(struct net_device
*ndev
, struct ethtool_cmd
*cmd
)
864 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
867 /* All ports on the KS8695 support these... */
868 cmd
->supported
= (SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
|
869 SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
|
870 SUPPORTED_TP
| SUPPORTED_MII
);
871 cmd
->transceiver
= XCVR_INTERNAL
;
873 cmd
->advertising
= ADVERTISED_TP
| ADVERTISED_MII
;
874 cmd
->port
= PORT_MII
;
875 cmd
->supported
|= (SUPPORTED_Autoneg
| SUPPORTED_Pause
);
876 cmd
->phy_address
= 0;
878 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
879 if ((ctrl
& WMC_WAND
) == 0) {
880 /* auto-negotiation is enabled */
881 cmd
->advertising
|= ADVERTISED_Autoneg
;
882 if (ctrl
& WMC_WANA100F
)
883 cmd
->advertising
|= ADVERTISED_100baseT_Full
;
884 if (ctrl
& WMC_WANA100H
)
885 cmd
->advertising
|= ADVERTISED_100baseT_Half
;
886 if (ctrl
& WMC_WANA10F
)
887 cmd
->advertising
|= ADVERTISED_10baseT_Full
;
888 if (ctrl
& WMC_WANA10H
)
889 cmd
->advertising
|= ADVERTISED_10baseT_Half
;
890 if (ctrl
& WMC_WANAP
)
891 cmd
->advertising
|= ADVERTISED_Pause
;
892 cmd
->autoneg
= AUTONEG_ENABLE
;
894 cmd
->speed
= (ctrl
& WMC_WSS
) ? SPEED_100
: SPEED_10
;
895 cmd
->duplex
= (ctrl
& WMC_WDS
) ?
896 DUPLEX_FULL
: DUPLEX_HALF
;
898 /* auto-negotiation is disabled */
899 cmd
->autoneg
= AUTONEG_DISABLE
;
901 cmd
->speed
= (ctrl
& WMC_WANF100
) ?
902 SPEED_100
: SPEED_10
;
903 cmd
->duplex
= (ctrl
& WMC_WANFF
) ?
904 DUPLEX_FULL
: DUPLEX_HALF
;
911 * ks8695_wan_set_settings - Set device-specific settings.
912 * @ndev: The network device to configure
913 * @cmd: The settings to configure
916 ks8695_wan_set_settings(struct net_device
*ndev
, struct ethtool_cmd
*cmd
)
918 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
921 if ((cmd
->speed
!= SPEED_10
) && (cmd
->speed
!= SPEED_100
))
923 if ((cmd
->duplex
!= DUPLEX_HALF
) && (cmd
->duplex
!= DUPLEX_FULL
))
925 if (cmd
->port
!= PORT_MII
)
927 if (cmd
->transceiver
!= XCVR_INTERNAL
)
929 if ((cmd
->autoneg
!= AUTONEG_DISABLE
) &&
930 (cmd
->autoneg
!= AUTONEG_ENABLE
))
933 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
934 if ((cmd
->advertising
& (ADVERTISED_10baseT_Half
|
935 ADVERTISED_10baseT_Full
|
936 ADVERTISED_100baseT_Half
|
937 ADVERTISED_100baseT_Full
)) == 0)
940 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
942 ctrl
&= ~(WMC_WAND
| WMC_WANA100F
| WMC_WANA100H
|
943 WMC_WANA10F
| WMC_WANA10H
);
944 if (cmd
->advertising
& ADVERTISED_100baseT_Full
)
945 ctrl
|= WMC_WANA100F
;
946 if (cmd
->advertising
& ADVERTISED_100baseT_Half
)
947 ctrl
|= WMC_WANA100H
;
948 if (cmd
->advertising
& ADVERTISED_10baseT_Full
)
950 if (cmd
->advertising
& ADVERTISED_10baseT_Half
)
953 /* force a re-negotiation */
955 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_WMC
);
957 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
959 /* disable auto-negotiation */
961 ctrl
&= ~(WMC_WANF100
| WMC_WANFF
);
963 if (cmd
->speed
== SPEED_100
)
965 if (cmd
->duplex
== DUPLEX_FULL
)
968 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_WMC
);
975 * ks8695_wan_nwayreset - Restart the autonegotiation on the port.
976 * @ndev: The network device to restart autoneotiation on
979 ks8695_wan_nwayreset(struct net_device
*ndev
)
981 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
984 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
986 if ((ctrl
& WMC_WAND
) == 0)
987 writel(ctrl
| WMC_WANR
,
988 ksp
->phyiface_regs
+ KS8695_WMC
);
990 /* auto-negotiation not enabled */
997 * ks8695_wan_get_pause - Retrieve network pause/flow-control advertising
998 * @ndev: The device to retrieve settings from
999 * @param: The structure to fill out with the information
1002 ks8695_wan_get_pause(struct net_device
*ndev
, struct ethtool_pauseparam
*param
)
1004 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1007 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
1009 /* advertise Pause */
1010 param
->autoneg
= (ctrl
& WMC_WANAP
);
1012 /* current Rx Flow-control */
1013 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
1014 param
->rx_pause
= (ctrl
& DRXC_RFCE
);
1016 /* current Tx Flow-control */
1017 ctrl
= ks8695_readreg(ksp
, KS8695_DTXC
);
1018 param
->tx_pause
= (ctrl
& DTXC_TFCE
);
1022 * ks8695_get_drvinfo - Retrieve driver information
1023 * @ndev: The network device to retrieve info about
1024 * @info: The info structure to fill out.
1027 ks8695_get_drvinfo(struct net_device
*ndev
, struct ethtool_drvinfo
*info
)
1029 strlcpy(info
->driver
, MODULENAME
, sizeof(info
->driver
));
1030 strlcpy(info
->version
, MODULEVERSION
, sizeof(info
->version
));
1031 strlcpy(info
->bus_info
, dev_name(ndev
->dev
.parent
),
1032 sizeof(info
->bus_info
));
1035 static const struct ethtool_ops ks8695_ethtool_ops
= {
1036 .get_msglevel
= ks8695_get_msglevel
,
1037 .set_msglevel
= ks8695_set_msglevel
,
1038 .get_drvinfo
= ks8695_get_drvinfo
,
1041 static const struct ethtool_ops ks8695_wan_ethtool_ops
= {
1042 .get_msglevel
= ks8695_get_msglevel
,
1043 .set_msglevel
= ks8695_set_msglevel
,
1044 .get_settings
= ks8695_wan_get_settings
,
1045 .set_settings
= ks8695_wan_set_settings
,
1046 .nway_reset
= ks8695_wan_nwayreset
,
1047 .get_link
= ethtool_op_get_link
,
1048 .get_pauseparam
= ks8695_wan_get_pause
,
1049 .get_drvinfo
= ks8695_get_drvinfo
,
1052 /* Network device interface functions */
1055 * ks8695_set_mac - Update MAC in net dev and HW
1056 * @ndev: The network device to update
1057 * @addr: The new MAC address to set
1060 ks8695_set_mac(struct net_device
*ndev
, void *addr
)
1062 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1063 struct sockaddr
*address
= addr
;
1065 if (!is_valid_ether_addr(address
->sa_data
))
1066 return -EADDRNOTAVAIL
;
1068 memcpy(ndev
->dev_addr
, address
->sa_data
, ndev
->addr_len
);
1070 ks8695_update_mac(ksp
);
1072 dev_dbg(ksp
->dev
, "%s: Updated MAC address to %pM\n",
1073 ndev
->name
, ndev
->dev_addr
);
1079 * ks8695_set_multicast - Set up the multicast behaviour of the interface
1080 * @ndev: The net_device to configure
1082 * This routine, called by the net layer, configures promiscuity
1083 * and multicast reception behaviour for the interface.
1086 ks8695_set_multicast(struct net_device
*ndev
)
1088 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1091 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
1093 if (ndev
->flags
& IFF_PROMISC
) {
1094 /* enable promiscuous mode */
1096 } else if (ndev
->flags
& ~IFF_PROMISC
) {
1097 /* disable promiscuous mode */
1101 if (ndev
->flags
& IFF_ALLMULTI
) {
1102 /* enable all multicast mode */
1104 } else if (netdev_mc_count(ndev
) > KS8695_NR_ADDRESSES
) {
1105 /* more specific multicast addresses than can be
1106 * handled in hardware
1110 /* enable specific multicasts */
1112 ks8695_init_partial_multicast(ksp
, ndev
);
1115 ks8695_writereg(ksp
, KS8695_DRXC
, ctrl
);
1119 * ks8695_timeout - Handle a network tx/rx timeout.
1120 * @ndev: The net_device which timed out.
1122 * A network transaction timed out, reset the device.
1125 ks8695_timeout(struct net_device
*ndev
)
1127 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1129 netif_stop_queue(ndev
);
1130 ks8695_shutdown(ksp
);
1134 ks8695_update_mac(ksp
);
1136 /* We ignore the return from this since it managed to init
1137 * before it probably will be okay to init again.
1139 ks8695_init_net(ksp
);
1141 /* Reconfigure promiscuity etc */
1142 ks8695_set_multicast(ndev
);
1144 /* And start the TX queue once more */
1145 netif_start_queue(ndev
);
1149 * ks8695_start_xmit - Start a packet transmission
1150 * @skb: The packet to transmit
1151 * @ndev: The network device to send the packet on
1153 * This routine, called by the net layer, takes ownership of the
1154 * sk_buff and adds it to the TX ring. It then kicks the TX DMA
1155 * engine to ensure transmission begins.
1158 ks8695_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
1160 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1164 spin_lock_irq(&ksp
->txq_lock
);
1166 if (ksp
->tx_ring_used
== MAX_TX_DESC
) {
1167 /* Somehow we got entered when we have no room */
1168 spin_unlock_irq(&ksp
->txq_lock
);
1169 return NETDEV_TX_BUSY
;
1172 buff_n
= ksp
->tx_ring_next_slot
;
1174 BUG_ON(ksp
->tx_buffers
[buff_n
].skb
);
1176 dmap
= dma_map_single(ksp
->dev
, skb
->data
, skb
->len
, DMA_TO_DEVICE
);
1177 if (unlikely(dma_mapping_error(ksp
->dev
, dmap
))) {
1178 /* Failed to DMA map this SKB, give it back for now */
1179 spin_unlock_irq(&ksp
->txq_lock
);
1180 dev_dbg(ksp
->dev
, "%s: Could not map DMA memory for "\
1181 "transmission, trying later\n", ndev
->name
);
1182 return NETDEV_TX_BUSY
;
1185 ksp
->tx_buffers
[buff_n
].dma_ptr
= dmap
;
1186 /* Mapped okay, store the buffer pointer and length for later */
1187 ksp
->tx_buffers
[buff_n
].skb
= skb
;
1188 ksp
->tx_buffers
[buff_n
].length
= skb
->len
;
1190 /* Fill out the TX descriptor */
1191 ksp
->tx_ring
[buff_n
].data_ptr
=
1192 cpu_to_le32(ksp
->tx_buffers
[buff_n
].dma_ptr
);
1193 ksp
->tx_ring
[buff_n
].status
=
1194 cpu_to_le32(TDES_IC
| TDES_FS
| TDES_LS
|
1195 (skb
->len
& TDES_TBS
));
1199 /* Hand it over to the hardware */
1200 ksp
->tx_ring
[buff_n
].owner
= cpu_to_le32(TDES_OWN
);
1202 if (++ksp
->tx_ring_used
== MAX_TX_DESC
)
1203 netif_stop_queue(ndev
);
1205 /* Kick the TX DMA in case it decided to go IDLE */
1206 ks8695_writereg(ksp
, KS8695_DTSC
, 0);
1208 /* And update the next ring slot */
1209 ksp
->tx_ring_next_slot
= (buff_n
+ 1) & MAX_TX_DESC_MASK
;
1211 spin_unlock_irq(&ksp
->txq_lock
);
1212 return NETDEV_TX_OK
;
1216 * ks8695_stop - Stop (shutdown) a KS8695 ethernet interface
1217 * @ndev: The net_device to stop
1219 * This disables the TX queue and cleans up a KS8695 ethernet
1223 ks8695_stop(struct net_device
*ndev
)
1225 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1227 netif_stop_queue(ndev
);
1228 napi_disable(&ksp
->napi
);
1230 ks8695_shutdown(ksp
);
1236 * ks8695_open - Open (bring up) a KS8695 ethernet interface
1237 * @ndev: The net_device to open
1239 * This resets, configures the MAC, initialises the RX ring and
1240 * DMA engines and starts the TX queue for a KS8695 ethernet
1244 ks8695_open(struct net_device
*ndev
)
1246 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1249 if (!is_valid_ether_addr(ndev
->dev_addr
))
1250 return -EADDRNOTAVAIL
;
1254 ks8695_update_mac(ksp
);
1256 ret
= ks8695_init_net(ksp
);
1258 ks8695_shutdown(ksp
);
1262 napi_enable(&ksp
->napi
);
1263 netif_start_queue(ndev
);
1268 /* Platform device driver */
1271 * ks8695_init_switch - Init LAN switch to known good defaults.
1272 * @ksp: The device to initialise
1274 * This initialises the LAN switch in the KS8695 to a known-good
1277 static void __devinit
1278 ks8695_init_switch(struct ks8695_priv
*ksp
)
1282 /* Default value for SEC0 according to datasheet */
1285 /* LED0 = Speed LED1 = Link/Activity */
1286 ctrl
&= ~(SEC0_LLED1S
| SEC0_LLED0S
);
1287 ctrl
|= (LLED0S_LINK
| LLED1S_LINK_ACTIVITY
);
1290 ctrl
|= SEC0_ENABLE
;
1292 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_SEC0
);
1294 /* Defaults for SEC1 */
1295 writel(0x9400100, ksp
->phyiface_regs
+ KS8695_SEC1
);
1299 * ks8695_init_wan_phy - Initialise the WAN PHY to sensible defaults
1300 * @ksp: The device to initialise
1302 * This initialises a KS8695's WAN phy to sensible values for
1303 * autonegotiation etc.
1305 static void __devinit
1306 ks8695_init_wan_phy(struct ks8695_priv
*ksp
)
1310 /* Support auto-negotiation */
1311 ctrl
= (WMC_WANAP
| WMC_WANA100F
| WMC_WANA100H
|
1312 WMC_WANA10F
| WMC_WANA10H
);
1314 /* LED0 = Activity , LED1 = Link */
1315 ctrl
|= (WLED0S_ACTIVITY
| WLED1S_LINK
);
1317 /* Restart Auto-negotiation */
1320 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_WMC
);
1322 writel(0, ksp
->phyiface_regs
+ KS8695_WPPM
);
1323 writel(0, ksp
->phyiface_regs
+ KS8695_PPS
);
1326 static const struct net_device_ops ks8695_netdev_ops
= {
1327 .ndo_open
= ks8695_open
,
1328 .ndo_stop
= ks8695_stop
,
1329 .ndo_start_xmit
= ks8695_start_xmit
,
1330 .ndo_tx_timeout
= ks8695_timeout
,
1331 .ndo_set_mac_address
= ks8695_set_mac
,
1332 .ndo_validate_addr
= eth_validate_addr
,
1333 .ndo_set_multicast_list
= ks8695_set_multicast
,
1337 * ks8695_probe - Probe and initialise a KS8695 ethernet interface
1338 * @pdev: The platform device to probe
1340 * Initialise a KS8695 ethernet device from platform data.
1342 * This driver requires at least one IORESOURCE_MEM for the
1343 * registers and two IORESOURCE_IRQ for the RX and TX IRQs
1344 * respectively. It can optionally take an additional
1345 * IORESOURCE_MEM for the switch or phy in the case of the lan or
1346 * wan ports, and an IORESOURCE_IRQ for the link IRQ for the wan
1349 static int __devinit
1350 ks8695_probe(struct platform_device
*pdev
)
1352 struct ks8695_priv
*ksp
;
1353 struct net_device
*ndev
;
1354 struct resource
*regs_res
, *phyiface_res
;
1355 struct resource
*rxirq_res
, *txirq_res
, *linkirq_res
;
1358 u32 machigh
, maclow
;
1360 /* Initialise a net_device */
1361 ndev
= alloc_etherdev(sizeof(struct ks8695_priv
));
1363 dev_err(&pdev
->dev
, "could not allocate device.\n");
1367 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
1369 dev_dbg(&pdev
->dev
, "ks8695_probe() called\n");
1371 /* Configure our private structure a little */
1372 ksp
= netdev_priv(ndev
);
1374 ksp
->dev
= &pdev
->dev
;
1376 ksp
->msg_enable
= NETIF_MSG_LINK
;
1378 /* Retrieve resources */
1379 regs_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1380 phyiface_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1382 rxirq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1383 txirq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 1);
1384 linkirq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 2);
1386 if (!(regs_res
&& rxirq_res
&& txirq_res
)) {
1387 dev_err(ksp
->dev
, "insufficient resources\n");
1392 ksp
->regs_req
= request_mem_region(regs_res
->start
,
1393 resource_size(regs_res
),
1396 if (!ksp
->regs_req
) {
1397 dev_err(ksp
->dev
, "cannot claim register space\n");
1402 ksp
->io_regs
= ioremap(regs_res
->start
, resource_size(regs_res
));
1404 if (!ksp
->io_regs
) {
1405 dev_err(ksp
->dev
, "failed to ioremap registers\n");
1412 request_mem_region(phyiface_res
->start
,
1413 resource_size(phyiface_res
),
1414 phyiface_res
->name
);
1416 if (!ksp
->phyiface_req
) {
1418 "cannot claim switch register space\n");
1423 ksp
->phyiface_regs
= ioremap(phyiface_res
->start
,
1424 resource_size(phyiface_res
));
1426 if (!ksp
->phyiface_regs
) {
1428 "failed to ioremap switch registers\n");
1434 ksp
->rx_irq
= rxirq_res
->start
;
1435 ksp
->rx_irq_name
= rxirq_res
->name
? rxirq_res
->name
: "Ethernet RX";
1436 ksp
->tx_irq
= txirq_res
->start
;
1437 ksp
->tx_irq_name
= txirq_res
->name
? txirq_res
->name
: "Ethernet TX";
1438 ksp
->link_irq
= (linkirq_res
? linkirq_res
->start
: -1);
1439 ksp
->link_irq_name
= (linkirq_res
&& linkirq_res
->name
) ?
1440 linkirq_res
->name
: "Ethernet Link";
1442 /* driver system setup */
1443 ndev
->netdev_ops
= &ks8695_netdev_ops
;
1444 ndev
->watchdog_timeo
= msecs_to_jiffies(watchdog
);
1446 netif_napi_add(ndev
, &ksp
->napi
, ks8695_poll
, NAPI_WEIGHT
);
1448 /* Retrieve the default MAC addr from the chip. */
1449 /* The bootloader should have left it in there for us. */
1451 machigh
= ks8695_readreg(ksp
, KS8695_MAH
);
1452 maclow
= ks8695_readreg(ksp
, KS8695_MAL
);
1454 ndev
->dev_addr
[0] = (machigh
>> 8) & 0xFF;
1455 ndev
->dev_addr
[1] = machigh
& 0xFF;
1456 ndev
->dev_addr
[2] = (maclow
>> 24) & 0xFF;
1457 ndev
->dev_addr
[3] = (maclow
>> 16) & 0xFF;
1458 ndev
->dev_addr
[4] = (maclow
>> 8) & 0xFF;
1459 ndev
->dev_addr
[5] = maclow
& 0xFF;
1461 if (!is_valid_ether_addr(ndev
->dev_addr
))
1462 dev_warn(ksp
->dev
, "%s: Invalid ethernet MAC address. Please "
1463 "set using ifconfig\n", ndev
->name
);
1465 /* In order to be efficient memory-wise, we allocate both
1468 ksp
->ring_base
= dma_alloc_coherent(&pdev
->dev
, RING_DMA_SIZE
,
1469 &ksp
->ring_base_dma
, GFP_KERNEL
);
1470 if (!ksp
->ring_base
) {
1475 /* Specify the TX DMA ring buffer */
1476 ksp
->tx_ring
= ksp
->ring_base
;
1477 ksp
->tx_ring_dma
= ksp
->ring_base_dma
;
1479 /* And initialise the queue's lock */
1480 spin_lock_init(&ksp
->txq_lock
);
1481 spin_lock_init(&ksp
->rx_lock
);
1483 /* Specify the RX DMA ring buffer */
1484 ksp
->rx_ring
= ksp
->ring_base
+ TX_RING_DMA_SIZE
;
1485 ksp
->rx_ring_dma
= ksp
->ring_base_dma
+ TX_RING_DMA_SIZE
;
1487 /* Zero the descriptor rings */
1488 memset(ksp
->tx_ring
, 0, TX_RING_DMA_SIZE
);
1489 memset(ksp
->rx_ring
, 0, RX_RING_DMA_SIZE
);
1491 /* Build the rings */
1492 for (buff_n
= 0; buff_n
< MAX_TX_DESC
; ++buff_n
) {
1493 ksp
->tx_ring
[buff_n
].next_desc
=
1494 cpu_to_le32(ksp
->tx_ring_dma
+
1495 (sizeof(struct tx_ring_desc
) *
1496 ((buff_n
+ 1) & MAX_TX_DESC_MASK
)));
1499 for (buff_n
= 0; buff_n
< MAX_RX_DESC
; ++buff_n
) {
1500 ksp
->rx_ring
[buff_n
].next_desc
=
1501 cpu_to_le32(ksp
->rx_ring_dma
+
1502 (sizeof(struct rx_ring_desc
) *
1503 ((buff_n
+ 1) & MAX_RX_DESC_MASK
)));
1506 /* Initialise the port (physically) */
1507 if (ksp
->phyiface_regs
&& ksp
->link_irq
== -1) {
1508 ks8695_init_switch(ksp
);
1509 ksp
->dtype
= KS8695_DTYPE_LAN
;
1510 SET_ETHTOOL_OPS(ndev
, &ks8695_ethtool_ops
);
1511 } else if (ksp
->phyiface_regs
&& ksp
->link_irq
!= -1) {
1512 ks8695_init_wan_phy(ksp
);
1513 ksp
->dtype
= KS8695_DTYPE_WAN
;
1514 SET_ETHTOOL_OPS(ndev
, &ks8695_wan_ethtool_ops
);
1516 /* No initialisation since HPNA does not have a PHY */
1517 ksp
->dtype
= KS8695_DTYPE_HPNA
;
1518 SET_ETHTOOL_OPS(ndev
, &ks8695_ethtool_ops
);
1521 /* And bring up the net_device with the net core */
1522 platform_set_drvdata(pdev
, ndev
);
1523 ret
= register_netdev(ndev
);
1526 dev_info(ksp
->dev
, "ks8695 ethernet (%s) MAC: %pM\n",
1527 ks8695_port_type(ksp
), ndev
->dev_addr
);
1529 /* Report the failure to register the net_device */
1530 dev_err(ksp
->dev
, "ks8695net: failed to register netdev.\n");
1537 /* Error exit path */
1539 ks8695_release_device(ksp
);
1546 * ks8695_drv_suspend - Suspend a KS8695 ethernet platform device.
1547 * @pdev: The device to suspend
1548 * @state: The suspend state
1550 * This routine detaches and shuts down a KS8695 ethernet device.
1553 ks8695_drv_suspend(struct platform_device
*pdev
, pm_message_t state
)
1555 struct net_device
*ndev
= platform_get_drvdata(pdev
);
1556 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1558 ksp
->in_suspend
= 1;
1560 if (netif_running(ndev
)) {
1561 netif_device_detach(ndev
);
1562 ks8695_shutdown(ksp
);
1569 * ks8695_drv_resume - Resume a KS8695 ethernet platform device.
1570 * @pdev: The device to resume
1572 * This routine re-initialises and re-attaches a KS8695 ethernet
1576 ks8695_drv_resume(struct platform_device
*pdev
)
1578 struct net_device
*ndev
= platform_get_drvdata(pdev
);
1579 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1581 if (netif_running(ndev
)) {
1583 ks8695_init_net(ksp
);
1584 ks8695_set_multicast(ndev
);
1585 netif_device_attach(ndev
);
1588 ksp
->in_suspend
= 0;
1594 * ks8695_drv_remove - Remove a KS8695 net device on driver unload.
1595 * @pdev: The platform device to remove
1597 * This unregisters and releases a KS8695 ethernet device.
1599 static int __devexit
1600 ks8695_drv_remove(struct platform_device
*pdev
)
1602 struct net_device
*ndev
= platform_get_drvdata(pdev
);
1603 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1605 platform_set_drvdata(pdev
, NULL
);
1606 netif_napi_del(&ksp
->napi
);
1608 unregister_netdev(ndev
);
1609 ks8695_release_device(ksp
);
1612 dev_dbg(&pdev
->dev
, "released and freed device\n");
1616 static struct platform_driver ks8695_driver
= {
1619 .owner
= THIS_MODULE
,
1621 .probe
= ks8695_probe
,
1622 .remove
= __devexit_p(ks8695_drv_remove
),
1623 .suspend
= ks8695_drv_suspend
,
1624 .resume
= ks8695_drv_resume
,
1627 /* Module interface */
1632 printk(KERN_INFO
"%s Ethernet driver, V%s\n",
1633 MODULENAME
, MODULEVERSION
);
1635 return platform_driver_register(&ks8695_driver
);
1639 ks8695_cleanup(void)
1641 platform_driver_unregister(&ks8695_driver
);
1644 module_init(ks8695_init
);
1645 module_exit(ks8695_cleanup
);
1647 MODULE_AUTHOR("Simtec Electronics");
1648 MODULE_DESCRIPTION("Micrel KS8695 (Centaur) Ethernet driver");
1649 MODULE_LICENSE("GPL");
1650 MODULE_ALIAS("platform:" MODULENAME
);
1652 module_param(watchdog
, int, 0400);
1653 MODULE_PARM_DESC(watchdog
, "transmit timeout in milliseconds");