2 * File: drivers/net/bfin_mac.c
5 * Bryan Wu <bryan.wu@analog.com>
8 * Luke Yang <luke.yang@analog.com>
14 * Copyright 2004-2006 Analog Devices Inc.
16 * Bugs: Enter bugs at http://blackfin.uclinux.org/
18 * This program is free software ; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation ; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY ; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program ; see the file COPYING.
30 * If not, write to the Free Software Foundation,
31 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <linux/init.h>
35 #include <linux/module.h>
36 #include <linux/kernel.h>
37 #include <linux/sched.h>
38 #include <linux/slab.h>
39 #include <linux/delay.h>
40 #include <linux/timer.h>
41 #include <linux/errno.h>
42 #include <linux/irq.h>
44 #include <linux/ioport.h>
45 #include <linux/crc32.h>
46 #include <linux/device.h>
47 #include <linux/spinlock.h>
48 #include <linux/ethtool.h>
49 #include <linux/mii.h>
50 #include <linux/netdevice.h>
51 #include <linux/etherdevice.h>
52 #include <linux/skbuff.h>
53 #include <linux/platform_device.h>
56 #include <linux/dma-mapping.h>
58 #include <asm/blackfin.h>
59 #include <asm/cacheflush.h>
60 #include <asm/portmux.h>
64 #define DRV_NAME "bfin_mac"
65 #define DRV_VERSION "1.1"
66 #define DRV_AUTHOR "Bryan Wu, Luke Yang"
67 #define DRV_DESC "Blackfin BF53[67] on-chip Ethernet MAC driver"
69 MODULE_AUTHOR(DRV_AUTHOR
);
70 MODULE_LICENSE("GPL");
71 MODULE_DESCRIPTION(DRV_DESC
);
73 #if defined(CONFIG_BFIN_MAC_USE_L1)
74 # define bfin_mac_alloc(dma_handle, size) l1_data_sram_zalloc(size)
75 # define bfin_mac_free(dma_handle, ptr) l1_data_sram_free(ptr)
77 # define bfin_mac_alloc(dma_handle, size) \
78 dma_alloc_coherent(NULL, size, dma_handle, GFP_KERNEL)
79 # define bfin_mac_free(dma_handle, ptr) \
80 dma_free_coherent(NULL, sizeof(*ptr), ptr, dma_handle)
83 #define PKT_BUF_SZ 1580
85 #define MAX_TIMEOUT_CNT 500
87 /* pointers to maintain transmit list */
88 static struct net_dma_desc_tx
*tx_list_head
;
89 static struct net_dma_desc_tx
*tx_list_tail
;
90 static struct net_dma_desc_rx
*rx_list_head
;
91 static struct net_dma_desc_rx
*rx_list_tail
;
92 static struct net_dma_desc_rx
*current_rx_ptr
;
93 static struct net_dma_desc_tx
*current_tx_ptr
;
94 static struct net_dma_desc_tx
*tx_desc
;
95 static struct net_dma_desc_rx
*rx_desc
;
97 static void desc_list_free(void)
99 struct net_dma_desc_rx
*r
;
100 struct net_dma_desc_tx
*t
;
102 #if !defined(CONFIG_BFIN_MAC_USE_L1)
103 dma_addr_t dma_handle
= 0;
108 for (i
= 0; i
< CONFIG_BFIN_TX_DESC_NUM
; i
++) {
111 dev_kfree_skb(t
->skb
);
117 bfin_mac_free(dma_handle
, tx_desc
);
122 for (i
= 0; i
< CONFIG_BFIN_RX_DESC_NUM
; i
++) {
125 dev_kfree_skb(r
->skb
);
131 bfin_mac_free(dma_handle
, rx_desc
);
135 static int desc_list_init(void)
138 struct sk_buff
*new_skb
;
139 #if !defined(CONFIG_BFIN_MAC_USE_L1)
141 * This dma_handle is useless in Blackfin dma_alloc_coherent().
142 * The real dma handler is the return value of dma_alloc_coherent().
144 dma_addr_t dma_handle
;
147 tx_desc
= bfin_mac_alloc(&dma_handle
,
148 sizeof(struct net_dma_desc_tx
) *
149 CONFIG_BFIN_TX_DESC_NUM
);
153 rx_desc
= bfin_mac_alloc(&dma_handle
,
154 sizeof(struct net_dma_desc_rx
) *
155 CONFIG_BFIN_RX_DESC_NUM
);
160 tx_list_head
= tx_list_tail
= tx_desc
;
162 for (i
= 0; i
< CONFIG_BFIN_TX_DESC_NUM
; i
++) {
163 struct net_dma_desc_tx
*t
= tx_desc
+ i
;
164 struct dma_descriptor
*a
= &(t
->desc_a
);
165 struct dma_descriptor
*b
= &(t
->desc_b
);
169 * read from memory WNR = 0
170 * wordsize is 32 bits
171 * 6 half words is desc size
174 a
->config
= WDSIZE_32
| NDSIZE_6
| DMAFLOW_LARGE
;
175 a
->start_addr
= (unsigned long)t
->packet
;
177 a
->next_dma_desc
= b
;
181 * write to memory WNR = 1
182 * wordsize is 32 bits
184 * 6 half words is desc size
187 b
->config
= DMAEN
| WNR
| WDSIZE_32
| NDSIZE_6
| DMAFLOW_LARGE
;
188 b
->start_addr
= (unsigned long)(&(t
->status
));
192 tx_list_tail
->desc_b
.next_dma_desc
= a
;
193 tx_list_tail
->next
= t
;
196 tx_list_tail
->next
= tx_list_head
; /* tx_list is a circle */
197 tx_list_tail
->desc_b
.next_dma_desc
= &(tx_list_head
->desc_a
);
198 current_tx_ptr
= tx_list_head
;
201 rx_list_head
= rx_list_tail
= rx_desc
;
203 for (i
= 0; i
< CONFIG_BFIN_RX_DESC_NUM
; i
++) {
204 struct net_dma_desc_rx
*r
= rx_desc
+ i
;
205 struct dma_descriptor
*a
= &(r
->desc_a
);
206 struct dma_descriptor
*b
= &(r
->desc_b
);
208 /* allocate a new skb for next time receive */
209 new_skb
= dev_alloc_skb(PKT_BUF_SZ
+ 2);
211 printk(KERN_NOTICE DRV_NAME
212 ": init: low on mem - packet dropped\n");
215 skb_reserve(new_skb
, 2);
220 * write to memory WNR = 1
221 * wordsize is 32 bits
223 * 6 half words is desc size
226 a
->config
= DMAEN
| WNR
| WDSIZE_32
| NDSIZE_6
| DMAFLOW_LARGE
;
227 /* since RXDWA is enabled */
228 a
->start_addr
= (unsigned long)new_skb
->data
- 2;
230 a
->next_dma_desc
= b
;
234 * write to memory WNR = 1
235 * wordsize is 32 bits
237 * 6 half words is desc size
240 b
->config
= DMAEN
| WNR
| WDSIZE_32
| DI_EN
|
241 NDSIZE_6
| DMAFLOW_LARGE
;
242 b
->start_addr
= (unsigned long)(&(r
->status
));
245 rx_list_tail
->desc_b
.next_dma_desc
= a
;
246 rx_list_tail
->next
= r
;
249 rx_list_tail
->next
= rx_list_head
; /* rx_list is a circle */
250 rx_list_tail
->desc_b
.next_dma_desc
= &(rx_list_head
->desc_a
);
251 current_rx_ptr
= rx_list_head
;
257 printk(KERN_ERR DRV_NAME
": kmalloc failed\n");
262 /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
264 /* Set FER regs to MUX in Ethernet pins */
265 static int setup_pin_mux(int action
)
267 #if defined(CONFIG_BFIN_MAC_RMII)
268 u16 pin_req
[] = P_RMII0
;
270 u16 pin_req
[] = P_MII0
;
274 if (peripheral_request_list(pin_req
, DRV_NAME
)) {
275 printk(KERN_ERR DRV_NAME
276 ": Requesting Peripherals failed\n");
280 peripheral_free_list(pin_req
);
285 /* Wait until the previous MDC/MDIO transaction has completed */
286 static void poll_mdc_done(void)
288 int timeout_cnt
= MAX_TIMEOUT_CNT
;
290 /* poll the STABUSY bit */
291 while ((bfin_read_EMAC_STAADD()) & STABUSY
) {
293 if (timeout_cnt
-- < 0) {
294 printk(KERN_ERR DRV_NAME
295 ": wait MDC/MDIO transaction to complete timeout\n");
301 /* Read an off-chip register in a PHY through the MDC/MDIO port */
302 static u16
read_phy_reg(u16 PHYAddr
, u16 RegAddr
)
306 bfin_write_EMAC_STAADD(SET_PHYAD(PHYAddr
) |
311 return (u16
) bfin_read_EMAC_STADAT();
314 /* Write an off-chip register in a PHY through the MDC/MDIO port */
315 static void raw_write_phy_reg(u16 PHYAddr
, u16 RegAddr
, u32 Data
)
317 bfin_write_EMAC_STADAT(Data
);
320 bfin_write_EMAC_STAADD(SET_PHYAD(PHYAddr
) |
328 static void write_phy_reg(u16 PHYAddr
, u16 RegAddr
, u32 Data
)
331 raw_write_phy_reg(PHYAddr
, RegAddr
, Data
);
335 static void bf537mac_setphy(struct net_device
*dev
)
338 struct bf537mac_local
*lp
= netdev_priv(dev
);
340 /* Program PHY registers */
341 pr_debug("start setting up phy\n");
344 raw_write_phy_reg(lp
->PhyAddr
, PHYREG_MODECTL
, 0x8000);
346 /* wait half a second */
349 phydat
= read_phy_reg(lp
->PhyAddr
, PHYREG_MODECTL
);
351 /* advertise flow control supported */
352 phydat
= read_phy_reg(lp
->PhyAddr
, PHYREG_ANAR
);
354 write_phy_reg(lp
->PhyAddr
, PHYREG_ANAR
, phydat
);
358 phydat
|= 0x1000; /* enable auto negotiation */
361 phydat
|= (1 << 8); /* full duplex */
363 phydat
&= (~(1 << 8)); /* half duplex */
366 phydat
|= (1 << 13); /* 100 Mbps */
368 phydat
&= (~(1 << 13)); /* 10 Mbps */
372 phydat
|= (1 << 14); /* enable TX->RX loopback */
374 write_phy_reg(lp
->PhyAddr
, PHYREG_MODECTL
, phydat
);
377 phydat
= read_phy_reg(lp
->PhyAddr
, PHYREG_MODECTL
);
378 /* check for SMSC PHY */
379 if ((read_phy_reg(lp
->PhyAddr
, PHYREG_PHYID1
) == 0x7) &&
380 ((read_phy_reg(lp
->PhyAddr
, PHYREG_PHYID2
) & 0xfff0) == 0xC0A0)) {
382 * we have SMSC PHY so reqest interrupt
383 * on link down condition
386 /* enable interrupts */
387 write_phy_reg(lp
->PhyAddr
, 30, 0x0ff);
391 /**************************************************************************/
392 void setup_system_regs(struct net_device
*dev
)
395 unsigned short sysctl
, phydat
;
397 struct bf537mac_local
*lp
= netdev_priv(dev
);
400 phyaddr
= lp
->PhyAddr
;
402 /* Enable PHY output */
403 if (!(bfin_read_VR_CTL() & PHYCLKOE
))
404 bfin_write_VR_CTL(bfin_read_VR_CTL() | PHYCLKOE
);
407 sysctl
= SET_MDCDIV(24);
408 /* Odd word alignment for Receive Frame DMA word */
409 /* Configure checksum support and rcve frame word alignment */
410 #if defined(BFIN_MAC_CSUM_OFFLOAD)
411 sysctl
|= RXDWA
| RXCKS
;
415 bfin_write_EMAC_SYSCTL(sysctl
);
416 /* auto negotiation on */
419 phydat
= PHY_ANEG_EN
| PHY_DUPLEX
| PHY_SPD_SET
;
420 write_phy_reg(phyaddr
, PHYREG_MODECTL
, phydat
);
422 /* test if full duplex supported */
425 phydat
= read_phy_reg(phyaddr
, PHYREG_MODESTAT
);
427 printk(KERN_NOTICE DRV_NAME
": Link is down\n");
428 printk(KERN_NOTICE DRV_NAME
429 "please check your network connection\n");
433 } while (!(phydat
& 0x0004));
435 phydat
= read_phy_reg(phyaddr
, PHYREG_ANLPAR
);
437 if ((phydat
& 0x0100) || (phydat
& 0x0040)) {
441 printk(KERN_INFO DRV_NAME
442 ": Network is set to half duplex\n");
445 #if defined(CONFIG_BFIN_MAC_RMII)
446 opmode
|= RMII
; /* For Now only 100MBit are supported */
449 bfin_write_EMAC_OPMODE(opmode
);
451 bfin_write_EMAC_MMC_CTL(RSTC
| CROLL
);
453 /* Initialize the TX DMA channel registers */
454 bfin_write_DMA2_X_COUNT(0);
455 bfin_write_DMA2_X_MODIFY(4);
456 bfin_write_DMA2_Y_COUNT(0);
457 bfin_write_DMA2_Y_MODIFY(0);
459 /* Initialize the RX DMA channel registers */
460 bfin_write_DMA1_X_COUNT(0);
461 bfin_write_DMA1_X_MODIFY(4);
462 bfin_write_DMA1_Y_COUNT(0);
463 bfin_write_DMA1_Y_MODIFY(0);
466 void setup_mac_addr(u8
* mac_addr
)
468 u32 addr_low
= le32_to_cpu(*(__le32
*) & mac_addr
[0]);
469 u16 addr_hi
= le16_to_cpu(*(__le16
*) & mac_addr
[4]);
471 /* this depends on a little-endian machine */
472 bfin_write_EMAC_ADDRLO(addr_low
);
473 bfin_write_EMAC_ADDRHI(addr_hi
);
476 static void adjust_tx_list(void)
478 int timeout_cnt
= MAX_TIMEOUT_CNT
;
480 if (tx_list_head
->status
.status_word
!= 0
481 && current_tx_ptr
!= tx_list_head
) {
482 goto adjust_head
; /* released something, just return; */
486 * if nothing released, check wait condition
487 * current's next can not be the head,
488 * otherwise the dma will not stop as we want
490 if (current_tx_ptr
->next
->next
== tx_list_head
) {
491 while (tx_list_head
->status
.status_word
== 0) {
493 if (tx_list_head
->status
.status_word
!= 0
494 || !(bfin_read_DMA2_IRQ_STATUS() & 0x08)) {
497 if (timeout_cnt
-- < 0) {
498 printk(KERN_ERR DRV_NAME
499 ": wait for adjust tx list head timeout\n");
503 if (tx_list_head
->status
.status_word
!= 0) {
512 tx_list_head
->desc_a
.config
&= ~DMAEN
;
513 tx_list_head
->status
.status_word
= 0;
514 if (tx_list_head
->skb
) {
515 dev_kfree_skb(tx_list_head
->skb
);
516 tx_list_head
->skb
= NULL
;
518 printk(KERN_ERR DRV_NAME
519 ": no sk_buff in a transmitted frame!\n");
521 tx_list_head
= tx_list_head
->next
;
522 } while (tx_list_head
->status
.status_word
!= 0
523 && current_tx_ptr
!= tx_list_head
);
528 static int bf537mac_hard_start_xmit(struct sk_buff
*skb
,
529 struct net_device
*dev
)
531 struct bf537mac_local
*lp
= netdev_priv(dev
);
534 current_tx_ptr
->skb
= skb
;
537 * Is skb->data always 16-bit aligned?
538 * Do we need to memcpy((char *)(tail->packet + 2), skb->data, len)?
540 if ((((unsigned int)(skb
->data
)) & 0x02) == 2) {
541 /* move skb->data to current_tx_ptr payload */
542 data
= (unsigned int)(skb
->data
) - 2;
543 *((unsigned short *)data
) = (unsigned short)(skb
->len
);
544 current_tx_ptr
->desc_a
.start_addr
= (unsigned long)data
;
545 /* this is important! */
546 blackfin_dcache_flush_range(data
, (data
+ (skb
->len
)) + 2);
549 *((unsigned short *)(current_tx_ptr
->packet
)) =
550 (unsigned short)(skb
->len
);
551 memcpy((char *)(current_tx_ptr
->packet
+ 2), skb
->data
,
553 current_tx_ptr
->desc_a
.start_addr
=
554 (unsigned long)current_tx_ptr
->packet
;
555 if (current_tx_ptr
->status
.status_word
!= 0)
556 current_tx_ptr
->status
.status_word
= 0;
557 blackfin_dcache_flush_range((unsigned int)current_tx_ptr
->
559 (unsigned int)(current_tx_ptr
->
564 /* enable this packet's dma */
565 current_tx_ptr
->desc_a
.config
|= DMAEN
;
567 /* tx dma is running, just return */
568 if (bfin_read_DMA2_IRQ_STATUS() & 0x08)
571 /* tx dma is not running */
572 bfin_write_DMA2_NEXT_DESC_PTR(&(current_tx_ptr
->desc_a
));
573 /* dma enabled, read from memory, size is 6 */
574 bfin_write_DMA2_CONFIG(current_tx_ptr
->desc_a
.config
);
575 /* Turn on the EMAC tx */
576 bfin_write_EMAC_OPMODE(bfin_read_EMAC_OPMODE() | TE
);
580 current_tx_ptr
= current_tx_ptr
->next
;
581 dev
->trans_start
= jiffies
;
582 lp
->stats
.tx_packets
++;
583 lp
->stats
.tx_bytes
+= (skb
->len
);
587 static void bf537mac_rx(struct net_device
*dev
)
589 struct sk_buff
*skb
, *new_skb
;
590 struct bf537mac_local
*lp
= netdev_priv(dev
);
593 /* allocate a new skb for next time receive */
594 skb
= current_rx_ptr
->skb
;
595 new_skb
= dev_alloc_skb(PKT_BUF_SZ
+ 2);
597 printk(KERN_NOTICE DRV_NAME
598 ": rx: low on mem - packet dropped\n");
599 lp
->stats
.rx_dropped
++;
602 /* reserve 2 bytes for RXDWA padding */
603 skb_reserve(new_skb
, 2);
604 current_rx_ptr
->skb
= new_skb
;
605 current_rx_ptr
->desc_a
.start_addr
= (unsigned long)new_skb
->data
- 2;
607 len
= (unsigned short)((current_rx_ptr
->status
.status_word
) & RX_FRLEN
);
609 blackfin_dcache_invalidate_range((unsigned long)skb
->head
,
610 (unsigned long)skb
->tail
);
612 dev
->last_rx
= jiffies
;
614 skb
->protocol
= eth_type_trans(skb
, dev
);
615 #if defined(BFIN_MAC_CSUM_OFFLOAD)
616 skb
->csum
= current_rx_ptr
->status
.ip_payload_csum
;
617 skb
->ip_summed
= CHECKSUM_PARTIAL
;
621 lp
->stats
.rx_packets
++;
622 lp
->stats
.rx_bytes
+= len
;
623 current_rx_ptr
->status
.status_word
= 0x00000000;
624 current_rx_ptr
= current_rx_ptr
->next
;
630 /* interrupt routine to handle rx and error signal */
631 static irqreturn_t
bf537mac_interrupt(int irq
, void *dev_id
)
633 struct net_device
*dev
= dev_id
;
637 if (current_rx_ptr
->status
.status_word
== 0) {
638 /* no more new packet received */
640 if (current_rx_ptr
->next
->status
.status_word
!= 0) {
641 current_rx_ptr
= current_rx_ptr
->next
;
645 bfin_write_DMA1_IRQ_STATUS(bfin_read_DMA1_IRQ_STATUS() |
656 #ifdef CONFIG_NET_POLL_CONTROLLER
657 static void bf537mac_poll(struct net_device
*dev
)
659 disable_irq(IRQ_MAC_RX
);
660 bf537mac_interrupt(IRQ_MAC_RX
, dev
);
661 enable_irq(IRQ_MAC_RX
);
663 #endif /* CONFIG_NET_POLL_CONTROLLER */
665 static void bf537mac_reset(void)
669 opmode
= bfin_read_EMAC_OPMODE();
672 /* Turn off the EMAC */
673 bfin_write_EMAC_OPMODE(opmode
);
677 * Enable Interrupts, Receive, and Transmit
679 static int bf537mac_enable(struct net_device
*dev
)
683 pr_debug("%s: %s\n", dev
->name
, __FUNCTION__
);
686 bfin_write_DMA1_NEXT_DESC_PTR(&(rx_list_head
->desc_a
));
687 bfin_write_DMA1_CONFIG(rx_list_head
->desc_a
.config
);
692 /* We enable only RX here */
693 /* ASTP : Enable Automatic Pad Stripping
694 PR : Promiscuous Mode for test
695 PSF : Receive frames with total length less than 64 bytes.
696 FDMODE : Full Duplex Mode
697 LB : Internal Loopback for test
698 RE : Receiver Enable */
699 opmode
= bfin_read_EMAC_OPMODE();
703 opmode
|= DRO
| DC
| PSF
;
706 #if defined(CONFIG_BFIN_MAC_RMII)
707 opmode
|= RMII
; /* For Now only 100MBit are supported */
708 #ifdef CONFIG_BF_REV_0_2
712 /* Turn on the EMAC rx */
713 bfin_write_EMAC_OPMODE(opmode
);
718 /* Our watchdog timed out. Called by the networking layer */
719 static void bf537mac_timeout(struct net_device
*dev
)
721 pr_debug("%s: %s\n", dev
->name
, __FUNCTION__
);
726 tx_list_tail
= tx_list_head
->next
;
728 bf537mac_enable(dev
);
730 /* We can accept TX packets again */
731 dev
->trans_start
= jiffies
;
732 netif_wake_queue(dev
);
736 * Get the current statistics.
737 * This may be called with the card open or closed.
739 static struct net_device_stats
*bf537mac_query_statistics(struct net_device
742 struct bf537mac_local
*lp
= netdev_priv(dev
);
744 pr_debug("%s: %s\n", dev
->name
, __FUNCTION__
);
750 * This routine will, depending on the values passed to it,
751 * either make it accept multicast packets, go into
752 * promiscuous mode (for TCPDUMP and cousins) or accept
753 * a select set of multicast packets
755 static void bf537mac_set_multicast_list(struct net_device
*dev
)
759 if (dev
->flags
& IFF_PROMISC
) {
760 printk(KERN_INFO
"%s: set to promisc mode\n", dev
->name
);
761 sysctl
= bfin_read_EMAC_OPMODE();
763 bfin_write_EMAC_OPMODE(sysctl
);
764 } else if (dev
->flags
& IFF_ALLMULTI
|| dev
->mc_count
) {
765 /* accept all multicast */
766 sysctl
= bfin_read_EMAC_OPMODE();
768 bfin_write_EMAC_OPMODE(sysctl
);
770 /* clear promisc or multicast mode */
771 sysctl
= bfin_read_EMAC_OPMODE();
772 sysctl
&= ~(RAF
| PAM
);
773 bfin_write_EMAC_OPMODE(sysctl
);
778 * this puts the device in an inactive state
780 static void bf537mac_shutdown(struct net_device
*dev
)
782 /* Turn off the EMAC */
783 bfin_write_EMAC_OPMODE(0x00000000);
784 /* Turn off the EMAC RX DMA */
785 bfin_write_DMA1_CONFIG(0x0000);
786 bfin_write_DMA2_CONFIG(0x0000);
790 * Open and Initialize the interface
792 * Set up everything, reset the card, etc..
794 static int bf537mac_open(struct net_device
*dev
)
797 pr_debug("%s: %s\n", dev
->name
, __FUNCTION__
);
800 * Check that the address is valid. If its not, refuse
801 * to bring the device up. The user must specify an
802 * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
804 if (!is_valid_ether_addr(dev
->dev_addr
)) {
805 printk(KERN_WARNING DRV_NAME
": no valid ethernet hw addr\n");
809 /* initial rx and tx list */
810 retval
= desc_list_init();
815 bf537mac_setphy(dev
);
816 setup_system_regs(dev
);
818 bf537mac_enable(dev
);
820 pr_debug("hardware init finished\n");
821 netif_start_queue(dev
);
822 netif_carrier_on(dev
);
829 * this makes the board clean up everything that it can
830 * and not talk to the outside world. Caused by
831 * an 'ifconfig ethX down'
833 static int bf537mac_close(struct net_device
*dev
)
835 pr_debug("%s: %s\n", dev
->name
, __FUNCTION__
);
837 netif_stop_queue(dev
);
838 netif_carrier_off(dev
);
840 /* clear everything */
841 bf537mac_shutdown(dev
);
843 /* free the rx/tx buffers */
849 static int __init
bf537mac_probe(struct net_device
*dev
)
851 struct bf537mac_local
*lp
= netdev_priv(dev
);
854 /* Grab the MAC address in the MAC */
855 *(__le32
*) (&(dev
->dev_addr
[0])) = cpu_to_le32(bfin_read_EMAC_ADDRLO());
856 *(__le16
*) (&(dev
->dev_addr
[4])) = cpu_to_le16((u16
) bfin_read_EMAC_ADDRHI());
859 /*todo: how to proble? which is revision_register */
860 bfin_write_EMAC_ADDRLO(0x12345678);
861 if (bfin_read_EMAC_ADDRLO() != 0x12345678) {
862 pr_debug("can't detect bf537 mac!\n");
867 /* set the GPIO pins to Ethernet mode */
868 retval
= setup_pin_mux(1);
873 /*Is it valid? (Did bootloader initialize it?) */
874 if (!is_valid_ether_addr(dev
->dev_addr
)) {
875 /* Grab the MAC from the board somehow - this is done in the
876 arch/blackfin/mach-bf537/boards/eth_mac.c */
877 get_bf537_ether_addr(dev
->dev_addr
);
880 /* If still not valid, get a random one */
881 if (!is_valid_ether_addr(dev
->dev_addr
)) {
882 random_ether_addr(dev
->dev_addr
);
885 setup_mac_addr(dev
->dev_addr
);
887 /* Fill in the fields of the device structure with ethernet values. */
890 dev
->open
= bf537mac_open
;
891 dev
->stop
= bf537mac_close
;
892 dev
->hard_start_xmit
= bf537mac_hard_start_xmit
;
893 dev
->tx_timeout
= bf537mac_timeout
;
894 dev
->get_stats
= bf537mac_query_statistics
;
895 dev
->set_multicast_list
= bf537mac_set_multicast_list
;
896 #ifdef CONFIG_NET_POLL_CONTROLLER
897 dev
->poll_controller
= bf537mac_poll
;
900 /* fill in some of the fields */
907 spin_lock_init(&lp
->lock
);
909 /* now, enable interrupts */
910 /* register irq handler */
912 (IRQ_MAC_RX
, bf537mac_interrupt
, IRQF_DISABLED
| IRQF_SHARED
,
913 "BFIN537_MAC_RX", dev
)) {
914 printk(KERN_WARNING DRV_NAME
915 ": Unable to attach BlackFin MAC RX interrupt\n");
919 /* Enable PHY output early */
920 if (!(bfin_read_VR_CTL() & PHYCLKOE
))
921 bfin_write_VR_CTL(bfin_read_VR_CTL() | PHYCLKOE
);
923 retval
= register_netdev(dev
);
925 /* now, print out the card info, in a short format.. */
926 printk(KERN_INFO
"%s: Version %s, %s\n",
927 DRV_NAME
, DRV_VERSION
, DRV_DESC
);
934 static int bfin_mac_probe(struct platform_device
*pdev
)
936 struct net_device
*ndev
;
938 ndev
= alloc_etherdev(sizeof(struct bf537mac_local
));
940 printk(KERN_WARNING DRV_NAME
": could not allocate device\n");
944 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
946 platform_set_drvdata(pdev
, ndev
);
948 if (bf537mac_probe(ndev
) != 0) {
949 platform_set_drvdata(pdev
, NULL
);
951 printk(KERN_WARNING DRV_NAME
": not found\n");
958 static int bfin_mac_remove(struct platform_device
*pdev
)
960 struct net_device
*ndev
= platform_get_drvdata(pdev
);
962 platform_set_drvdata(pdev
, NULL
);
964 unregister_netdev(ndev
);
966 free_irq(IRQ_MAC_RX
, ndev
);
975 static int bfin_mac_suspend(struct platform_device
*pdev
, pm_message_t state
)
980 static int bfin_mac_resume(struct platform_device
*pdev
)
985 static struct platform_driver bfin_mac_driver
= {
986 .probe
= bfin_mac_probe
,
987 .remove
= bfin_mac_remove
,
988 .resume
= bfin_mac_resume
,
989 .suspend
= bfin_mac_suspend
,
995 static int __init
bfin_mac_init(void)
997 return platform_driver_register(&bfin_mac_driver
);
1000 module_init(bfin_mac_init
);
1002 static void __exit
bfin_mac_cleanup(void)
1004 platform_driver_unregister(&bfin_mac_driver
);
1007 module_exit(bfin_mac_cleanup
);