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/dma-mapping.h>
20 #include <linux/module.h>
21 #include <linux/ioport.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/interrupt.h>
25 #include <linux/skbuff.h>
26 #include <linux/spinlock.h>
27 #include <linux/crc32.h>
28 #include <linux/mii.h>
29 #include <linux/ethtool.h>
30 #include <linux/delay.h>
31 #include <linux/platform_device.h>
32 #include <linux/irq.h>
34 #include <linux/slab.h>
38 #include <mach/regs-switch.h>
39 #include <mach/regs-misc.h>
40 #include <asm/mach/irq.h>
41 #include <mach/regs-irq.h>
43 #include "ks8695net.h"
45 #define MODULENAME "ks8695_ether"
46 #define MODULEVERSION "1.02"
49 * Transmit and device reset timeout, default 5 seconds.
51 static int watchdog
= 5000;
53 /* Hardware structures */
56 * struct rx_ring_desc - Receive descriptor ring element
57 * @status: The status of the descriptor element (E.g. who owns it)
58 * @length: The number of bytes in the block pointed to by data_ptr
59 * @data_ptr: The physical address of the data block to receive into
60 * @next_desc: The physical address of the next descriptor element.
70 * struct tx_ring_desc - Transmit descriptor ring element
71 * @owner: Who owns the descriptor
72 * @status: The number of bytes in the block pointed to by data_ptr
73 * @data_ptr: The physical address of the data block to receive into
74 * @next_desc: The physical address of the next descriptor element.
84 * struct ks8695_skbuff - sk_buff wrapper for rx/tx rings.
85 * @skb: The buffer in the ring
86 * @dma_ptr: The mapped DMA pointer of the buffer
87 * @length: The number of bytes mapped to dma_ptr
89 struct ks8695_skbuff
{
95 /* Private device structure */
98 #define MAX_TX_DESC_MASK 0x7
99 #define MAX_RX_DESC 16
100 #define MAX_RX_DESC_MASK 0xf
102 /*napi_weight have better more than rx DMA buffers*/
103 #define NAPI_WEIGHT 64
105 #define MAX_RXBUF_SIZE 0x700
107 #define TX_RING_DMA_SIZE (sizeof(struct tx_ring_desc) * MAX_TX_DESC)
108 #define RX_RING_DMA_SIZE (sizeof(struct rx_ring_desc) * MAX_RX_DESC)
109 #define RING_DMA_SIZE (TX_RING_DMA_SIZE + RX_RING_DMA_SIZE)
112 * enum ks8695_dtype - Device type
113 * @KS8695_DTYPE_WAN: This device is a WAN interface
114 * @KS8695_DTYPE_LAN: This device is a LAN interface
115 * @KS8695_DTYPE_HPNA: This device is an HPNA interface
124 * struct ks8695_priv - Private data for the KS8695 Ethernet
125 * @in_suspend: Flag to indicate if we're suspending/resuming
126 * @ndev: The net_device for this interface
127 * @dev: The platform device object for this interface
128 * @dtype: The type of this device
129 * @io_regs: The ioremapped registers for this interface
130 * @napi : Add support NAPI for Rx
131 * @rx_irq_name: The textual name of the RX IRQ from the platform data
132 * @tx_irq_name: The textual name of the TX IRQ from the platform data
133 * @link_irq_name: The textual name of the link IRQ from the
134 * platform data if available
135 * @rx_irq: The IRQ number for the RX IRQ
136 * @tx_irq: The IRQ number for the TX IRQ
137 * @link_irq: The IRQ number for the link IRQ if available
138 * @regs_req: The resource request for the registers region
139 * @phyiface_req: The resource request for the phy/switch region
141 * @phyiface_regs: The ioremapped registers for the phy/switch if available
142 * @ring_base: The base pointer of the dma coherent memory for the rings
143 * @ring_base_dma: The DMA mapped equivalent of ring_base
144 * @tx_ring: The pointer in ring_base of the TX ring
145 * @tx_ring_used: The number of slots in the TX ring which are occupied
146 * @tx_ring_next_slot: The next slot to fill in the TX ring
147 * @tx_ring_dma: The DMA mapped equivalent of tx_ring
148 * @tx_buffers: The sk_buff mappings for the TX ring
149 * @txq_lock: A lock to protect the tx_buffers tx_ring_used etc variables
150 * @rx_ring: The pointer in ring_base of the RX ring
151 * @rx_ring_dma: The DMA mapped equivalent of rx_ring
152 * @rx_buffers: The sk_buff mappings for the RX ring
153 * @next_rx_desc_read: The next RX descriptor to read from on IRQ
154 * @rx_lock: A lock to protect Rx irq function
155 * @msg_enable: The flags for which messages to emit
159 struct net_device
*ndev
;
161 enum ks8695_dtype dtype
;
162 void __iomem
*io_regs
;
164 struct napi_struct napi
;
166 const char *rx_irq_name
, *tx_irq_name
, *link_irq_name
;
167 int rx_irq
, tx_irq
, link_irq
;
169 struct resource
*regs_req
, *phyiface_req
;
170 void __iomem
*phyiface_regs
;
173 dma_addr_t ring_base_dma
;
175 struct tx_ring_desc
*tx_ring
;
177 int tx_ring_next_slot
;
178 dma_addr_t tx_ring_dma
;
179 struct ks8695_skbuff tx_buffers
[MAX_TX_DESC
];
182 struct rx_ring_desc
*rx_ring
;
183 dma_addr_t rx_ring_dma
;
184 struct ks8695_skbuff rx_buffers
[MAX_RX_DESC
];
185 int next_rx_desc_read
;
191 /* Register access */
194 * ks8695_readreg - Read from a KS8695 ethernet register
195 * @ksp: The device to read from
196 * @reg: The register to read
199 ks8695_readreg(struct ks8695_priv
*ksp
, int reg
)
201 return readl(ksp
->io_regs
+ reg
);
205 * ks8695_writereg - Write to a KS8695 ethernet register
206 * @ksp: The device to write to
207 * @reg: The register to write
208 * @value: The value to write to the register
211 ks8695_writereg(struct ks8695_priv
*ksp
, int reg
, u32 value
)
213 writel(value
, ksp
->io_regs
+ reg
);
216 /* Utility functions */
219 * ks8695_port_type - Retrieve port-type as user-friendly string
220 * @ksp: The device to return the type for
222 * Returns a string indicating which of the WAN, LAN or HPNA
223 * ports this device is likely to represent.
226 ks8695_port_type(struct ks8695_priv
*ksp
)
228 switch (ksp
->dtype
) {
229 case KS8695_DTYPE_LAN
:
231 case KS8695_DTYPE_WAN
:
233 case KS8695_DTYPE_HPNA
:
241 * ks8695_update_mac - Update the MAC registers in the device
242 * @ksp: The device to update
244 * Updates the MAC registers in the KS8695 device from the address in the
245 * net_device structure associated with this interface.
248 ks8695_update_mac(struct ks8695_priv
*ksp
)
250 /* Update the HW with the MAC from the net_device */
251 struct net_device
*ndev
= ksp
->ndev
;
254 maclow
= ((ndev
->dev_addr
[2] << 24) | (ndev
->dev_addr
[3] << 16) |
255 (ndev
->dev_addr
[4] << 8) | (ndev
->dev_addr
[5] << 0));
256 machigh
= ((ndev
->dev_addr
[0] << 8) | (ndev
->dev_addr
[1] << 0));
258 ks8695_writereg(ksp
, KS8695_MAL
, maclow
);
259 ks8695_writereg(ksp
, KS8695_MAH
, machigh
);
264 * ks8695_refill_rxbuffers - Re-fill the RX buffer ring
265 * @ksp: The device to refill
267 * Iterates the RX ring of the device looking for empty slots.
268 * For each empty slot, we allocate and map a new SKB and give it
270 * This can be called from interrupt context safely.
273 ks8695_refill_rxbuffers(struct ks8695_priv
*ksp
)
275 /* Run around the RX ring, filling in any missing sk_buff's */
278 for (buff_n
= 0; buff_n
< MAX_RX_DESC
; ++buff_n
) {
279 if (!ksp
->rx_buffers
[buff_n
].skb
) {
280 struct sk_buff
*skb
=
281 netdev_alloc_skb(ksp
->ndev
, MAX_RXBUF_SIZE
);
284 ksp
->rx_buffers
[buff_n
].skb
= skb
;
286 /* Failed to allocate one, perhaps
287 * we'll try again later.
292 mapping
= dma_map_single(ksp
->dev
, skb
->data
,
295 if (unlikely(dma_mapping_error(ksp
->dev
, mapping
))) {
296 /* Failed to DMA map this SKB, try later */
297 dev_kfree_skb_irq(skb
);
298 ksp
->rx_buffers
[buff_n
].skb
= NULL
;
301 ksp
->rx_buffers
[buff_n
].dma_ptr
= mapping
;
302 ksp
->rx_buffers
[buff_n
].length
= MAX_RXBUF_SIZE
;
304 /* Record this into the DMA ring */
305 ksp
->rx_ring
[buff_n
].data_ptr
= cpu_to_le32(mapping
);
306 ksp
->rx_ring
[buff_n
].length
=
307 cpu_to_le32(MAX_RXBUF_SIZE
);
311 /* And give ownership over to the hardware */
312 ksp
->rx_ring
[buff_n
].status
= cpu_to_le32(RDES_OWN
);
317 /* Maximum number of multicast addresses which the KS8695 HW supports */
318 #define KS8695_NR_ADDRESSES 16
321 * ks8695_init_partial_multicast - Init the mcast addr registers
322 * @ksp: The device to initialise
323 * @addr: The multicast address list to use
324 * @nr_addr: The number of addresses in the list
326 * This routine is a helper for ks8695_set_multicast - it writes
327 * the additional-address registers in the KS8695 ethernet device
328 * and cleans up any others left behind.
331 ks8695_init_partial_multicast(struct ks8695_priv
*ksp
,
332 struct net_device
*ndev
)
336 struct netdev_hw_addr
*ha
;
339 netdev_for_each_mc_addr(ha
, ndev
) {
340 /* Ran out of space in chip? */
341 BUG_ON(i
== KS8695_NR_ADDRESSES
);
343 low
= (ha
->addr
[2] << 24) | (ha
->addr
[3] << 16) |
344 (ha
->addr
[4] << 8) | (ha
->addr
[5]);
345 high
= (ha
->addr
[0] << 8) | (ha
->addr
[1]);
347 ks8695_writereg(ksp
, KS8695_AAL_(i
), low
);
348 ks8695_writereg(ksp
, KS8695_AAH_(i
), AAH_E
| high
);
352 /* Clear the remaining Additional Station Addresses */
353 for (; i
< KS8695_NR_ADDRESSES
; i
++) {
354 ks8695_writereg(ksp
, KS8695_AAL_(i
), 0);
355 ks8695_writereg(ksp
, KS8695_AAH_(i
), 0);
359 /* Interrupt handling */
362 * ks8695_tx_irq - Transmit IRQ handler
363 * @irq: The IRQ which went off (ignored)
364 * @dev_id: The net_device for the interrupt
366 * Process the TX ring, clearing out any transmitted slots.
367 * Allows the net_device to pass us new packets once slots are
371 ks8695_tx_irq(int irq
, void *dev_id
)
373 struct net_device
*ndev
= (struct net_device
*)dev_id
;
374 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
377 for (buff_n
= 0; buff_n
< MAX_TX_DESC
; ++buff_n
) {
378 if (ksp
->tx_buffers
[buff_n
].skb
&&
379 !(ksp
->tx_ring
[buff_n
].owner
& cpu_to_le32(TDES_OWN
))) {
381 /* An SKB which is not owned by HW is present */
382 /* Update the stats for the net_device */
383 ndev
->stats
.tx_packets
++;
384 ndev
->stats
.tx_bytes
+= ksp
->tx_buffers
[buff_n
].length
;
386 /* Free the packet from the ring */
387 ksp
->tx_ring
[buff_n
].data_ptr
= 0;
389 /* Free the sk_buff */
390 dma_unmap_single(ksp
->dev
,
391 ksp
->tx_buffers
[buff_n
].dma_ptr
,
392 ksp
->tx_buffers
[buff_n
].length
,
394 dev_kfree_skb_irq(ksp
->tx_buffers
[buff_n
].skb
);
395 ksp
->tx_buffers
[buff_n
].skb
= NULL
;
400 netif_wake_queue(ndev
);
406 * ks8695_get_rx_enable_bit - Get rx interrupt enable/status bit
407 * @ksp: Private data for the KS8695 Ethernet
409 * For KS8695 document:
410 * Interrupt Enable Register (offset 0xE204)
411 * Bit29 : WAN MAC Receive Interrupt Enable
412 * Bit16 : LAN MAC Receive Interrupt Enable
413 * Interrupt Status Register (Offset 0xF208)
414 * Bit29: WAN MAC Receive Status
415 * Bit16: LAN MAC Receive Status
416 * So, this Rx interrupt enable/status bit number is equal
419 static inline u32
ks8695_get_rx_enable_bit(struct ks8695_priv
*ksp
)
425 * ks8695_rx_irq - Receive IRQ handler
426 * @irq: The IRQ which went off (ignored)
427 * @dev_id: The net_device for the interrupt
429 * Inform NAPI that packet reception needs to be scheduled
433 ks8695_rx_irq(int irq
, void *dev_id
)
435 struct net_device
*ndev
= (struct net_device
*)dev_id
;
436 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
438 spin_lock(&ksp
->rx_lock
);
440 if (napi_schedule_prep(&ksp
->napi
)) {
441 unsigned long status
= readl(KS8695_IRQ_VA
+ KS8695_INTEN
);
442 unsigned long mask_bit
= 1 << ks8695_get_rx_enable_bit(ksp
);
443 /*disable rx interrupt*/
445 writel(status
, KS8695_IRQ_VA
+ KS8695_INTEN
);
446 __napi_schedule(&ksp
->napi
);
449 spin_unlock(&ksp
->rx_lock
);
454 * ks8695_rx - Receive packets called by NAPI poll method
455 * @ksp: Private data for the KS8695 Ethernet
456 * @budget: Number of packets allowed to process
458 static int ks8695_rx(struct ks8695_priv
*ksp
, int budget
)
460 struct net_device
*ndev
= ksp
->ndev
;
467 buff_n
= ksp
->next_rx_desc_read
;
468 while (received
< budget
469 && ksp
->rx_buffers
[buff_n
].skb
470 && (!(ksp
->rx_ring
[buff_n
].status
&
471 cpu_to_le32(RDES_OWN
)))) {
473 flags
= le32_to_cpu(ksp
->rx_ring
[buff_n
].status
);
475 /* Found an SKB which we own, this means we
478 if ((flags
& (RDES_FS
| RDES_LS
)) !=
479 (RDES_FS
| RDES_LS
)) {
480 /* This packet is not the first and
481 * the last segment. Therefore it is
482 * a "spanning" packet and we can't
488 if (flags
& (RDES_ES
| RDES_RE
)) {
489 /* It's an error packet */
490 ndev
->stats
.rx_errors
++;
492 ndev
->stats
.rx_length_errors
++;
494 ndev
->stats
.rx_length_errors
++;
496 ndev
->stats
.rx_crc_errors
++;
498 ndev
->stats
.rx_missed_errors
++;
503 pktlen
= flags
& RDES_FLEN
;
504 pktlen
-= 4; /* Drop the CRC */
506 /* Retrieve the sk_buff */
507 skb
= ksp
->rx_buffers
[buff_n
].skb
;
509 /* Clear it from the ring */
510 ksp
->rx_buffers
[buff_n
].skb
= NULL
;
511 ksp
->rx_ring
[buff_n
].data_ptr
= 0;
514 dma_unmap_single(ksp
->dev
,
515 ksp
->rx_buffers
[buff_n
].dma_ptr
,
516 ksp
->rx_buffers
[buff_n
].length
,
519 /* Relinquish the SKB to the network layer */
520 skb_put(skb
, pktlen
);
521 skb
->protocol
= eth_type_trans(skb
, ndev
);
522 netif_receive_skb(skb
);
525 ndev
->stats
.rx_packets
++;
526 ndev
->stats
.rx_bytes
+= pktlen
;
530 /* This ring entry is an error, but we can
533 /* Give the ring entry back to the hardware */
534 ksp
->rx_ring
[buff_n
].status
= cpu_to_le32(RDES_OWN
);
537 buff_n
= (buff_n
+ 1) & MAX_RX_DESC_MASK
;
540 /* And note which RX descriptor we last did */
541 ksp
->next_rx_desc_read
= buff_n
;
543 /* And refill the buffers */
544 ks8695_refill_rxbuffers(ksp
);
546 /* Kick the RX DMA engine, in case it became suspended */
547 ks8695_writereg(ksp
, KS8695_DRSC
, 0);
554 * ks8695_poll - Receive packet by NAPI poll method
555 * @ksp: Private data for the KS8695 Ethernet
556 * @budget: The remaining number packets for network subsystem
558 * Invoked by the network core when it requests for new
559 * packets from the driver
561 static int ks8695_poll(struct napi_struct
*napi
, int budget
)
563 struct ks8695_priv
*ksp
= container_of(napi
, struct ks8695_priv
, napi
);
564 unsigned long work_done
;
566 unsigned long isr
= readl(KS8695_IRQ_VA
+ KS8695_INTEN
);
567 unsigned long mask_bit
= 1 << ks8695_get_rx_enable_bit(ksp
);
569 work_done
= ks8695_rx(ksp
, budget
);
571 if (work_done
< budget
) {
573 spin_lock_irqsave(&ksp
->rx_lock
, flags
);
574 __napi_complete(napi
);
575 /*enable rx interrupt*/
576 writel(isr
| mask_bit
, KS8695_IRQ_VA
+ KS8695_INTEN
);
577 spin_unlock_irqrestore(&ksp
->rx_lock
, flags
);
583 * ks8695_link_irq - Link change IRQ handler
584 * @irq: The IRQ which went off (ignored)
585 * @dev_id: The net_device for the interrupt
587 * The WAN interface can generate an IRQ when the link changes,
588 * report this to the net layer and the user.
591 ks8695_link_irq(int irq
, void *dev_id
)
593 struct net_device
*ndev
= (struct net_device
*)dev_id
;
594 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
597 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
598 if (ctrl
& WMC_WLS
) {
599 netif_carrier_on(ndev
);
600 if (netif_msg_link(ksp
))
602 "%s: Link is now up (10%sMbps/%s-duplex)\n",
604 (ctrl
& WMC_WSS
) ? "0" : "",
605 (ctrl
& WMC_WDS
) ? "Full" : "Half");
607 netif_carrier_off(ndev
);
608 if (netif_msg_link(ksp
))
609 dev_info(ksp
->dev
, "%s: Link is now down.\n",
617 /* KS8695 Device functions */
620 * ks8695_reset - Reset a KS8695 ethernet interface
621 * @ksp: The interface to reset
623 * Perform an engine reset of the interface and re-program it
624 * with sensible defaults.
627 ks8695_reset(struct ks8695_priv
*ksp
)
629 int reset_timeout
= watchdog
;
630 /* Issue the reset via the TX DMA control register */
631 ks8695_writereg(ksp
, KS8695_DTXC
, DTXC_TRST
);
632 while (reset_timeout
--) {
633 if (!(ks8695_readreg(ksp
, KS8695_DTXC
) & DTXC_TRST
))
638 if (reset_timeout
< 0) {
640 "Timeout waiting for DMA engines to reset\n");
641 /* And blithely carry on */
644 /* Definitely wait long enough before attempting to program
649 /* RX: unicast and broadcast */
650 ks8695_writereg(ksp
, KS8695_DRXC
, DRXC_RU
| DRXC_RB
);
651 /* TX: pad and add CRC */
652 ks8695_writereg(ksp
, KS8695_DTXC
, DTXC_TEP
| DTXC_TAC
);
656 * ks8695_shutdown - Shut down a KS8695 ethernet interface
657 * @ksp: The interface to shut down
659 * This disables packet RX/TX, cleans up IRQs, drains the rings,
660 * and basically places the interface into a clean shutdown
664 ks8695_shutdown(struct ks8695_priv
*ksp
)
669 /* Disable packet transmission */
670 ctrl
= ks8695_readreg(ksp
, KS8695_DTXC
);
671 ks8695_writereg(ksp
, KS8695_DTXC
, ctrl
& ~DTXC_TE
);
673 /* Disable packet reception */
674 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
675 ks8695_writereg(ksp
, KS8695_DRXC
, ctrl
& ~DRXC_RE
);
677 /* Release the IRQs */
678 free_irq(ksp
->rx_irq
, ksp
->ndev
);
679 free_irq(ksp
->tx_irq
, ksp
->ndev
);
680 if (ksp
->link_irq
!= -1)
681 free_irq(ksp
->link_irq
, ksp
->ndev
);
683 /* Throw away any pending TX packets */
684 for (buff_n
= 0; buff_n
< MAX_TX_DESC
; ++buff_n
) {
685 if (ksp
->tx_buffers
[buff_n
].skb
) {
686 /* Remove this SKB from the TX ring */
687 ksp
->tx_ring
[buff_n
].owner
= 0;
688 ksp
->tx_ring
[buff_n
].status
= 0;
689 ksp
->tx_ring
[buff_n
].data_ptr
= 0;
691 /* Unmap and bin this SKB */
692 dma_unmap_single(ksp
->dev
,
693 ksp
->tx_buffers
[buff_n
].dma_ptr
,
694 ksp
->tx_buffers
[buff_n
].length
,
696 dev_kfree_skb_irq(ksp
->tx_buffers
[buff_n
].skb
);
697 ksp
->tx_buffers
[buff_n
].skb
= NULL
;
701 /* Purge the RX buffers */
702 for (buff_n
= 0; buff_n
< MAX_RX_DESC
; ++buff_n
) {
703 if (ksp
->rx_buffers
[buff_n
].skb
) {
704 /* Remove the SKB from the RX ring */
705 ksp
->rx_ring
[buff_n
].status
= 0;
706 ksp
->rx_ring
[buff_n
].data_ptr
= 0;
708 /* Unmap and bin the SKB */
709 dma_unmap_single(ksp
->dev
,
710 ksp
->rx_buffers
[buff_n
].dma_ptr
,
711 ksp
->rx_buffers
[buff_n
].length
,
713 dev_kfree_skb_irq(ksp
->rx_buffers
[buff_n
].skb
);
714 ksp
->rx_buffers
[buff_n
].skb
= NULL
;
721 * ks8695_setup_irq - IRQ setup helper function
722 * @irq: The IRQ number to claim
723 * @irq_name: The name to give the IRQ claimant
724 * @handler: The function to call to handle the IRQ
725 * @ndev: The net_device to pass in as the dev_id argument to the handler
727 * Return 0 on success.
730 ks8695_setup_irq(int irq
, const char *irq_name
,
731 irq_handler_t handler
, struct net_device
*ndev
)
735 ret
= request_irq(irq
, handler
, IRQF_SHARED
, irq_name
, ndev
);
738 dev_err(&ndev
->dev
, "failure to request IRQ %d\n", irq
);
746 * ks8695_init_net - Initialise a KS8695 ethernet interface
747 * @ksp: The interface to initialise
749 * This routine fills the RX ring, initialises the DMA engines,
750 * allocates the IRQs and then starts the packet TX and RX
754 ks8695_init_net(struct ks8695_priv
*ksp
)
759 ks8695_refill_rxbuffers(ksp
);
761 /* Initialise the DMA engines */
762 ks8695_writereg(ksp
, KS8695_RDLB
, (u32
) ksp
->rx_ring_dma
);
763 ks8695_writereg(ksp
, KS8695_TDLB
, (u32
) ksp
->tx_ring_dma
);
765 /* Request the IRQs */
766 ret
= ks8695_setup_irq(ksp
->rx_irq
, ksp
->rx_irq_name
,
767 ks8695_rx_irq
, ksp
->ndev
);
770 ret
= ks8695_setup_irq(ksp
->tx_irq
, ksp
->tx_irq_name
,
771 ks8695_tx_irq
, ksp
->ndev
);
774 if (ksp
->link_irq
!= -1) {
775 ret
= ks8695_setup_irq(ksp
->link_irq
, ksp
->link_irq_name
,
776 ks8695_link_irq
, ksp
->ndev
);
781 /* Set up the ring indices */
782 ksp
->next_rx_desc_read
= 0;
783 ksp
->tx_ring_next_slot
= 0;
784 ksp
->tx_ring_used
= 0;
786 /* Bring up transmission */
787 ctrl
= ks8695_readreg(ksp
, KS8695_DTXC
);
788 /* Enable packet transmission */
789 ks8695_writereg(ksp
, KS8695_DTXC
, ctrl
| DTXC_TE
);
791 /* Bring up the reception */
792 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
793 /* Enable packet reception */
794 ks8695_writereg(ksp
, KS8695_DRXC
, ctrl
| DRXC_RE
);
795 /* And start the DMA engine */
796 ks8695_writereg(ksp
, KS8695_DRSC
, 0);
803 * ks8695_release_device - HW resource release for KS8695 e-net
804 * @ksp: The device to be freed
806 * This unallocates io memory regions, dma-coherent regions etc
807 * which were allocated in ks8695_probe.
810 ks8695_release_device(struct ks8695_priv
*ksp
)
812 /* Unmap the registers */
813 iounmap(ksp
->io_regs
);
814 if (ksp
->phyiface_regs
)
815 iounmap(ksp
->phyiface_regs
);
817 /* And release the request */
818 release_resource(ksp
->regs_req
);
819 kfree(ksp
->regs_req
);
820 if (ksp
->phyiface_req
) {
821 release_resource(ksp
->phyiface_req
);
822 kfree(ksp
->phyiface_req
);
825 /* Free the ring buffers */
826 dma_free_coherent(ksp
->dev
, RING_DMA_SIZE
,
827 ksp
->ring_base
, ksp
->ring_base_dma
);
830 /* Ethtool support */
833 * ks8695_get_msglevel - Get the messages enabled for emission
834 * @ndev: The network device to read from
837 ks8695_get_msglevel(struct net_device
*ndev
)
839 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
841 return ksp
->msg_enable
;
845 * ks8695_set_msglevel - Set the messages enabled for emission
846 * @ndev: The network device to configure
847 * @value: The messages to set for emission
850 ks8695_set_msglevel(struct net_device
*ndev
, u32 value
)
852 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
854 ksp
->msg_enable
= value
;
858 * ks8695_wan_get_settings - Get device-specific settings.
859 * @ndev: The network device to read settings from
860 * @cmd: The ethtool structure to read into
863 ks8695_wan_get_settings(struct net_device
*ndev
, struct ethtool_cmd
*cmd
)
865 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
868 /* All ports on the KS8695 support these... */
869 cmd
->supported
= (SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
|
870 SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
|
871 SUPPORTED_TP
| SUPPORTED_MII
);
872 cmd
->transceiver
= XCVR_INTERNAL
;
874 cmd
->advertising
= ADVERTISED_TP
| ADVERTISED_MII
;
875 cmd
->port
= PORT_MII
;
876 cmd
->supported
|= (SUPPORTED_Autoneg
| SUPPORTED_Pause
);
877 cmd
->phy_address
= 0;
879 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
880 if ((ctrl
& WMC_WAND
) == 0) {
881 /* auto-negotiation is enabled */
882 cmd
->advertising
|= ADVERTISED_Autoneg
;
883 if (ctrl
& WMC_WANA100F
)
884 cmd
->advertising
|= ADVERTISED_100baseT_Full
;
885 if (ctrl
& WMC_WANA100H
)
886 cmd
->advertising
|= ADVERTISED_100baseT_Half
;
887 if (ctrl
& WMC_WANA10F
)
888 cmd
->advertising
|= ADVERTISED_10baseT_Full
;
889 if (ctrl
& WMC_WANA10H
)
890 cmd
->advertising
|= ADVERTISED_10baseT_Half
;
891 if (ctrl
& WMC_WANAP
)
892 cmd
->advertising
|= ADVERTISED_Pause
;
893 cmd
->autoneg
= AUTONEG_ENABLE
;
895 ethtool_cmd_speed_set(cmd
,
896 (ctrl
& WMC_WSS
) ? SPEED_100
: SPEED_10
);
897 cmd
->duplex
= (ctrl
& WMC_WDS
) ?
898 DUPLEX_FULL
: DUPLEX_HALF
;
900 /* auto-negotiation is disabled */
901 cmd
->autoneg
= AUTONEG_DISABLE
;
903 ethtool_cmd_speed_set(cmd
, ((ctrl
& WMC_WANF100
) ?
904 SPEED_100
: SPEED_10
));
905 cmd
->duplex
= (ctrl
& WMC_WANFF
) ?
906 DUPLEX_FULL
: DUPLEX_HALF
;
913 * ks8695_wan_set_settings - Set device-specific settings.
914 * @ndev: The network device to configure
915 * @cmd: The settings to configure
918 ks8695_wan_set_settings(struct net_device
*ndev
, struct ethtool_cmd
*cmd
)
920 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
923 if ((cmd
->speed
!= SPEED_10
) && (cmd
->speed
!= SPEED_100
))
925 if ((cmd
->duplex
!= DUPLEX_HALF
) && (cmd
->duplex
!= DUPLEX_FULL
))
927 if (cmd
->port
!= PORT_MII
)
929 if (cmd
->transceiver
!= XCVR_INTERNAL
)
931 if ((cmd
->autoneg
!= AUTONEG_DISABLE
) &&
932 (cmd
->autoneg
!= AUTONEG_ENABLE
))
935 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
936 if ((cmd
->advertising
& (ADVERTISED_10baseT_Half
|
937 ADVERTISED_10baseT_Full
|
938 ADVERTISED_100baseT_Half
|
939 ADVERTISED_100baseT_Full
)) == 0)
942 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
944 ctrl
&= ~(WMC_WAND
| WMC_WANA100F
| WMC_WANA100H
|
945 WMC_WANA10F
| WMC_WANA10H
);
946 if (cmd
->advertising
& ADVERTISED_100baseT_Full
)
947 ctrl
|= WMC_WANA100F
;
948 if (cmd
->advertising
& ADVERTISED_100baseT_Half
)
949 ctrl
|= WMC_WANA100H
;
950 if (cmd
->advertising
& ADVERTISED_10baseT_Full
)
952 if (cmd
->advertising
& ADVERTISED_10baseT_Half
)
955 /* force a re-negotiation */
957 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_WMC
);
959 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
961 /* disable auto-negotiation */
963 ctrl
&= ~(WMC_WANF100
| WMC_WANFF
);
965 if (cmd
->speed
== SPEED_100
)
967 if (cmd
->duplex
== DUPLEX_FULL
)
970 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_WMC
);
977 * ks8695_wan_nwayreset - Restart the autonegotiation on the port.
978 * @ndev: The network device to restart autoneotiation on
981 ks8695_wan_nwayreset(struct net_device
*ndev
)
983 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
986 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
988 if ((ctrl
& WMC_WAND
) == 0)
989 writel(ctrl
| WMC_WANR
,
990 ksp
->phyiface_regs
+ KS8695_WMC
);
992 /* auto-negotiation not enabled */
999 * ks8695_wan_get_pause - Retrieve network pause/flow-control advertising
1000 * @ndev: The device to retrieve settings from
1001 * @param: The structure to fill out with the information
1004 ks8695_wan_get_pause(struct net_device
*ndev
, struct ethtool_pauseparam
*param
)
1006 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1009 ctrl
= readl(ksp
->phyiface_regs
+ KS8695_WMC
);
1011 /* advertise Pause */
1012 param
->autoneg
= (ctrl
& WMC_WANAP
);
1014 /* current Rx Flow-control */
1015 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
1016 param
->rx_pause
= (ctrl
& DRXC_RFCE
);
1018 /* current Tx Flow-control */
1019 ctrl
= ks8695_readreg(ksp
, KS8695_DTXC
);
1020 param
->tx_pause
= (ctrl
& DTXC_TFCE
);
1024 * ks8695_get_drvinfo - Retrieve driver information
1025 * @ndev: The network device to retrieve info about
1026 * @info: The info structure to fill out.
1029 ks8695_get_drvinfo(struct net_device
*ndev
, struct ethtool_drvinfo
*info
)
1031 strlcpy(info
->driver
, MODULENAME
, sizeof(info
->driver
));
1032 strlcpy(info
->version
, MODULEVERSION
, sizeof(info
->version
));
1033 strlcpy(info
->bus_info
, dev_name(ndev
->dev
.parent
),
1034 sizeof(info
->bus_info
));
1037 static const struct ethtool_ops ks8695_ethtool_ops
= {
1038 .get_msglevel
= ks8695_get_msglevel
,
1039 .set_msglevel
= ks8695_set_msglevel
,
1040 .get_drvinfo
= ks8695_get_drvinfo
,
1043 static const struct ethtool_ops ks8695_wan_ethtool_ops
= {
1044 .get_msglevel
= ks8695_get_msglevel
,
1045 .set_msglevel
= ks8695_set_msglevel
,
1046 .get_settings
= ks8695_wan_get_settings
,
1047 .set_settings
= ks8695_wan_set_settings
,
1048 .nway_reset
= ks8695_wan_nwayreset
,
1049 .get_link
= ethtool_op_get_link
,
1050 .get_pauseparam
= ks8695_wan_get_pause
,
1051 .get_drvinfo
= ks8695_get_drvinfo
,
1054 /* Network device interface functions */
1057 * ks8695_set_mac - Update MAC in net dev and HW
1058 * @ndev: The network device to update
1059 * @addr: The new MAC address to set
1062 ks8695_set_mac(struct net_device
*ndev
, void *addr
)
1064 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1065 struct sockaddr
*address
= addr
;
1067 if (!is_valid_ether_addr(address
->sa_data
))
1068 return -EADDRNOTAVAIL
;
1070 memcpy(ndev
->dev_addr
, address
->sa_data
, ndev
->addr_len
);
1072 ks8695_update_mac(ksp
);
1074 dev_dbg(ksp
->dev
, "%s: Updated MAC address to %pM\n",
1075 ndev
->name
, ndev
->dev_addr
);
1081 * ks8695_set_multicast - Set up the multicast behaviour of the interface
1082 * @ndev: The net_device to configure
1084 * This routine, called by the net layer, configures promiscuity
1085 * and multicast reception behaviour for the interface.
1088 ks8695_set_multicast(struct net_device
*ndev
)
1090 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1093 ctrl
= ks8695_readreg(ksp
, KS8695_DRXC
);
1095 if (ndev
->flags
& IFF_PROMISC
) {
1096 /* enable promiscuous mode */
1098 } else if (ndev
->flags
& ~IFF_PROMISC
) {
1099 /* disable promiscuous mode */
1103 if (ndev
->flags
& IFF_ALLMULTI
) {
1104 /* enable all multicast mode */
1106 } else if (netdev_mc_count(ndev
) > KS8695_NR_ADDRESSES
) {
1107 /* more specific multicast addresses than can be
1108 * handled in hardware
1112 /* enable specific multicasts */
1114 ks8695_init_partial_multicast(ksp
, ndev
);
1117 ks8695_writereg(ksp
, KS8695_DRXC
, ctrl
);
1121 * ks8695_timeout - Handle a network tx/rx timeout.
1122 * @ndev: The net_device which timed out.
1124 * A network transaction timed out, reset the device.
1127 ks8695_timeout(struct net_device
*ndev
)
1129 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1131 netif_stop_queue(ndev
);
1132 ks8695_shutdown(ksp
);
1136 ks8695_update_mac(ksp
);
1138 /* We ignore the return from this since it managed to init
1139 * before it probably will be okay to init again.
1141 ks8695_init_net(ksp
);
1143 /* Reconfigure promiscuity etc */
1144 ks8695_set_multicast(ndev
);
1146 /* And start the TX queue once more */
1147 netif_start_queue(ndev
);
1151 * ks8695_start_xmit - Start a packet transmission
1152 * @skb: The packet to transmit
1153 * @ndev: The network device to send the packet on
1155 * This routine, called by the net layer, takes ownership of the
1156 * sk_buff and adds it to the TX ring. It then kicks the TX DMA
1157 * engine to ensure transmission begins.
1160 ks8695_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
1162 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1166 spin_lock_irq(&ksp
->txq_lock
);
1168 if (ksp
->tx_ring_used
== MAX_TX_DESC
) {
1169 /* Somehow we got entered when we have no room */
1170 spin_unlock_irq(&ksp
->txq_lock
);
1171 return NETDEV_TX_BUSY
;
1174 buff_n
= ksp
->tx_ring_next_slot
;
1176 BUG_ON(ksp
->tx_buffers
[buff_n
].skb
);
1178 dmap
= dma_map_single(ksp
->dev
, skb
->data
, skb
->len
, DMA_TO_DEVICE
);
1179 if (unlikely(dma_mapping_error(ksp
->dev
, dmap
))) {
1180 /* Failed to DMA map this SKB, give it back for now */
1181 spin_unlock_irq(&ksp
->txq_lock
);
1182 dev_dbg(ksp
->dev
, "%s: Could not map DMA memory for "\
1183 "transmission, trying later\n", ndev
->name
);
1184 return NETDEV_TX_BUSY
;
1187 ksp
->tx_buffers
[buff_n
].dma_ptr
= dmap
;
1188 /* Mapped okay, store the buffer pointer and length for later */
1189 ksp
->tx_buffers
[buff_n
].skb
= skb
;
1190 ksp
->tx_buffers
[buff_n
].length
= skb
->len
;
1192 /* Fill out the TX descriptor */
1193 ksp
->tx_ring
[buff_n
].data_ptr
=
1194 cpu_to_le32(ksp
->tx_buffers
[buff_n
].dma_ptr
);
1195 ksp
->tx_ring
[buff_n
].status
=
1196 cpu_to_le32(TDES_IC
| TDES_FS
| TDES_LS
|
1197 (skb
->len
& TDES_TBS
));
1201 /* Hand it over to the hardware */
1202 ksp
->tx_ring
[buff_n
].owner
= cpu_to_le32(TDES_OWN
);
1204 if (++ksp
->tx_ring_used
== MAX_TX_DESC
)
1205 netif_stop_queue(ndev
);
1207 /* Kick the TX DMA in case it decided to go IDLE */
1208 ks8695_writereg(ksp
, KS8695_DTSC
, 0);
1210 /* And update the next ring slot */
1211 ksp
->tx_ring_next_slot
= (buff_n
+ 1) & MAX_TX_DESC_MASK
;
1213 spin_unlock_irq(&ksp
->txq_lock
);
1214 return NETDEV_TX_OK
;
1218 * ks8695_stop - Stop (shutdown) a KS8695 ethernet interface
1219 * @ndev: The net_device to stop
1221 * This disables the TX queue and cleans up a KS8695 ethernet
1225 ks8695_stop(struct net_device
*ndev
)
1227 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1229 netif_stop_queue(ndev
);
1230 napi_disable(&ksp
->napi
);
1232 ks8695_shutdown(ksp
);
1238 * ks8695_open - Open (bring up) a KS8695 ethernet interface
1239 * @ndev: The net_device to open
1241 * This resets, configures the MAC, initialises the RX ring and
1242 * DMA engines and starts the TX queue for a KS8695 ethernet
1246 ks8695_open(struct net_device
*ndev
)
1248 struct ks8695_priv
*ksp
= netdev_priv(ndev
);
1253 ks8695_update_mac(ksp
);
1255 ret
= ks8695_init_net(ksp
);
1257 ks8695_shutdown(ksp
);
1261 napi_enable(&ksp
->napi
);
1262 netif_start_queue(ndev
);
1267 /* Platform device driver */
1270 * ks8695_init_switch - Init LAN switch to known good defaults.
1271 * @ksp: The device to initialise
1273 * This initialises the LAN switch in the KS8695 to a known-good
1277 ks8695_init_switch(struct ks8695_priv
*ksp
)
1281 /* Default value for SEC0 according to datasheet */
1284 /* LED0 = Speed LED1 = Link/Activity */
1285 ctrl
&= ~(SEC0_LLED1S
| SEC0_LLED0S
);
1286 ctrl
|= (LLED0S_LINK
| LLED1S_LINK_ACTIVITY
);
1289 ctrl
|= SEC0_ENABLE
;
1291 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_SEC0
);
1293 /* Defaults for SEC1 */
1294 writel(0x9400100, ksp
->phyiface_regs
+ KS8695_SEC1
);
1298 * ks8695_init_wan_phy - Initialise the WAN PHY to sensible defaults
1299 * @ksp: The device to initialise
1301 * This initialises a KS8695's WAN phy to sensible values for
1302 * autonegotiation etc.
1305 ks8695_init_wan_phy(struct ks8695_priv
*ksp
)
1309 /* Support auto-negotiation */
1310 ctrl
= (WMC_WANAP
| WMC_WANA100F
| WMC_WANA100H
|
1311 WMC_WANA10F
| WMC_WANA10H
);
1313 /* LED0 = Activity , LED1 = Link */
1314 ctrl
|= (WLED0S_ACTIVITY
| WLED1S_LINK
);
1316 /* Restart Auto-negotiation */
1319 writel(ctrl
, ksp
->phyiface_regs
+ KS8695_WMC
);
1321 writel(0, ksp
->phyiface_regs
+ KS8695_WPPM
);
1322 writel(0, ksp
->phyiface_regs
+ KS8695_PPS
);
1325 static const struct net_device_ops ks8695_netdev_ops
= {
1326 .ndo_open
= ks8695_open
,
1327 .ndo_stop
= ks8695_stop
,
1328 .ndo_start_xmit
= ks8695_start_xmit
,
1329 .ndo_tx_timeout
= ks8695_timeout
,
1330 .ndo_set_mac_address
= ks8695_set_mac
,
1331 .ndo_validate_addr
= eth_validate_addr
,
1332 .ndo_set_rx_mode
= ks8695_set_multicast
,
1336 * ks8695_probe - Probe and initialise a KS8695 ethernet interface
1337 * @pdev: The platform device to probe
1339 * Initialise a KS8695 ethernet device from platform data.
1341 * This driver requires at least one IORESOURCE_MEM for the
1342 * registers and two IORESOURCE_IRQ for the RX and TX IRQs
1343 * respectively. It can optionally take an additional
1344 * IORESOURCE_MEM for the switch or phy in the case of the lan or
1345 * wan ports, and an IORESOURCE_IRQ for the link IRQ for the wan
1349 ks8695_probe(struct platform_device
*pdev
)
1351 struct ks8695_priv
*ksp
;
1352 struct net_device
*ndev
;
1353 struct resource
*regs_res
, *phyiface_res
;
1354 struct resource
*rxirq_res
, *txirq_res
, *linkirq_res
;
1357 bool inv_mac_addr
= false;
1358 u32 machigh
, maclow
;
1360 /* Initialise a net_device */
1361 ndev
= alloc_etherdev(sizeof(struct ks8695_priv
));
1365 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
1367 dev_dbg(&pdev
->dev
, "ks8695_probe() called\n");
1369 /* Configure our private structure a little */
1370 ksp
= netdev_priv(ndev
);
1372 ksp
->dev
= &pdev
->dev
;
1374 ksp
->msg_enable
= NETIF_MSG_LINK
;
1376 /* Retrieve resources */
1377 regs_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1378 phyiface_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1380 rxirq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1381 txirq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 1);
1382 linkirq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 2);
1384 if (!(regs_res
&& rxirq_res
&& txirq_res
)) {
1385 dev_err(ksp
->dev
, "insufficient resources\n");
1390 ksp
->regs_req
= request_mem_region(regs_res
->start
,
1391 resource_size(regs_res
),
1394 if (!ksp
->regs_req
) {
1395 dev_err(ksp
->dev
, "cannot claim register space\n");
1400 ksp
->io_regs
= ioremap(regs_res
->start
, resource_size(regs_res
));
1402 if (!ksp
->io_regs
) {
1403 dev_err(ksp
->dev
, "failed to ioremap registers\n");
1410 request_mem_region(phyiface_res
->start
,
1411 resource_size(phyiface_res
),
1412 phyiface_res
->name
);
1414 if (!ksp
->phyiface_req
) {
1416 "cannot claim switch register space\n");
1421 ksp
->phyiface_regs
= ioremap(phyiface_res
->start
,
1422 resource_size(phyiface_res
));
1424 if (!ksp
->phyiface_regs
) {
1426 "failed to ioremap switch registers\n");
1432 ksp
->rx_irq
= rxirq_res
->start
;
1433 ksp
->rx_irq_name
= rxirq_res
->name
? rxirq_res
->name
: "Ethernet RX";
1434 ksp
->tx_irq
= txirq_res
->start
;
1435 ksp
->tx_irq_name
= txirq_res
->name
? txirq_res
->name
: "Ethernet TX";
1436 ksp
->link_irq
= (linkirq_res
? linkirq_res
->start
: -1);
1437 ksp
->link_irq_name
= (linkirq_res
&& linkirq_res
->name
) ?
1438 linkirq_res
->name
: "Ethernet Link";
1440 /* driver system setup */
1441 ndev
->netdev_ops
= &ks8695_netdev_ops
;
1442 ndev
->watchdog_timeo
= msecs_to_jiffies(watchdog
);
1444 netif_napi_add(ndev
, &ksp
->napi
, ks8695_poll
, NAPI_WEIGHT
);
1446 /* Retrieve the default MAC addr from the chip. */
1447 /* The bootloader should have left it in there for us. */
1449 machigh
= ks8695_readreg(ksp
, KS8695_MAH
);
1450 maclow
= ks8695_readreg(ksp
, KS8695_MAL
);
1452 ndev
->dev_addr
[0] = (machigh
>> 8) & 0xFF;
1453 ndev
->dev_addr
[1] = machigh
& 0xFF;
1454 ndev
->dev_addr
[2] = (maclow
>> 24) & 0xFF;
1455 ndev
->dev_addr
[3] = (maclow
>> 16) & 0xFF;
1456 ndev
->dev_addr
[4] = (maclow
>> 8) & 0xFF;
1457 ndev
->dev_addr
[5] = maclow
& 0xFF;
1459 if (!is_valid_ether_addr(ndev
->dev_addr
))
1460 inv_mac_addr
= true;
1462 /* In order to be efficient memory-wise, we allocate both
1465 ksp
->ring_base
= dma_alloc_coherent(&pdev
->dev
, RING_DMA_SIZE
,
1466 &ksp
->ring_base_dma
, GFP_KERNEL
);
1467 if (!ksp
->ring_base
) {
1472 /* Specify the TX DMA ring buffer */
1473 ksp
->tx_ring
= ksp
->ring_base
;
1474 ksp
->tx_ring_dma
= ksp
->ring_base_dma
;
1476 /* And initialise the queue's lock */
1477 spin_lock_init(&ksp
->txq_lock
);
1478 spin_lock_init(&ksp
->rx_lock
);
1480 /* Specify the RX DMA ring buffer */
1481 ksp
->rx_ring
= ksp
->ring_base
+ TX_RING_DMA_SIZE
;
1482 ksp
->rx_ring_dma
= ksp
->ring_base_dma
+ TX_RING_DMA_SIZE
;
1484 /* Zero the descriptor rings */
1485 memset(ksp
->tx_ring
, 0, TX_RING_DMA_SIZE
);
1486 memset(ksp
->rx_ring
, 0, RX_RING_DMA_SIZE
);
1488 /* Build the rings */
1489 for (buff_n
= 0; buff_n
< MAX_TX_DESC
; ++buff_n
) {
1490 ksp
->tx_ring
[buff_n
].next_desc
=
1491 cpu_to_le32(ksp
->tx_ring_dma
+
1492 (sizeof(struct tx_ring_desc
) *
1493 ((buff_n
+ 1) & MAX_TX_DESC_MASK
)));
1496 for (buff_n
= 0; buff_n
< MAX_RX_DESC
; ++buff_n
) {
1497 ksp
->rx_ring
[buff_n
].next_desc
=
1498 cpu_to_le32(ksp
->rx_ring_dma
+
1499 (sizeof(struct rx_ring_desc
) *
1500 ((buff_n
+ 1) & MAX_RX_DESC_MASK
)));
1503 /* Initialise the port (physically) */
1504 if (ksp
->phyiface_regs
&& ksp
->link_irq
== -1) {
1505 ks8695_init_switch(ksp
);
1506 ksp
->dtype
= KS8695_DTYPE_LAN
;
1507 ndev
->ethtool_ops
= &ks8695_ethtool_ops
;
1508 } else if (ksp
->phyiface_regs
&& ksp
->link_irq
!= -1) {
1509 ks8695_init_wan_phy(ksp
);
1510 ksp
->dtype
= KS8695_DTYPE_WAN
;
1511 ndev
->ethtool_ops
= &ks8695_wan_ethtool_ops
;
1513 /* No initialisation since HPNA does not have a PHY */
1514 ksp
->dtype
= KS8695_DTYPE_HPNA
;
1515 ndev
->ethtool_ops
= &ks8695_ethtool_ops
;
1518 /* And bring up the net_device with the net core */
1519 platform_set_drvdata(pdev
, ndev
);
1520 ret
= register_netdev(ndev
);
1524 dev_warn(ksp
->dev
, "%s: Invalid ethernet MAC address. Please set using ip\n",
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.
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 netif_napi_del(&ksp
->napi
);
1607 unregister_netdev(ndev
);
1608 ks8695_release_device(ksp
);
1611 dev_dbg(&pdev
->dev
, "released and freed device\n");
1615 static struct platform_driver ks8695_driver
= {
1619 .probe
= ks8695_probe
,
1620 .remove
= ks8695_drv_remove
,
1621 .suspend
= ks8695_drv_suspend
,
1622 .resume
= ks8695_drv_resume
,
1625 module_platform_driver(ks8695_driver
);
1627 MODULE_AUTHOR("Simtec Electronics");
1628 MODULE_DESCRIPTION("Micrel KS8695 (Centaur) Ethernet driver");
1629 MODULE_LICENSE("GPL");
1630 MODULE_ALIAS("platform:" MODULENAME
);
1632 module_param(watchdog
, int, 0400);
1633 MODULE_PARM_DESC(watchdog
, "transmit timeout in milliseconds");