1 /*----------------------------------------------------------------------
4 . Driver: MoreThanIP 10/100/1000Mbps Emac IP
6 . Copyright (C) 2004 Microtronix Datacom Ltd.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 . o MoreThanIP 10/100/1000Mbps Reference Guide V3.2 - May 2003
20 . o MoreThanIP Altera Plugs sources
21 . - mtip_10_100_1000.c
22 . - mtip_10_100_1000_adapter.c
24 . o Smc9111 uClinux port(s)
27 . o Apr2004 DGT Microtronix Datacom - Linux 2.6.5
29 -----------------------------------------------------------------------*/
31 static const char version
[] =
32 "MoreThanIP 10/100/1000 Driver"
34 ", Linux 2.6.5 Apr2004\n";
36 #include <linux/module.h>
37 #include <linux/version.h>
38 #include <linux/kernel.h>
39 #include <linux/sched.h>
40 #include <linux/types.h>
41 #include <linux/fcntl.h>
42 #include <linux/interrupt.h>
43 #include <linux/ptrace.h>
44 #include <linux/ioport.h>
46 #include <linux/slab.h>
47 #include <linux/string.h>
48 #include <linux/init.h>
49 #include <asm/bitops.h>
50 #include <asm/system.h>
54 #ifdef CONFIG_EXCALIBUR
57 #include <asm/cacheflush.h>
58 #endif // CONFIG_EXCALIBUR
60 #include <linux/errno.h>
61 #include <linux/delay.h>
63 #include <linux/netdevice.h>
64 #include <linux/etherdevice.h>
65 #include <linux/skbuff.h>
73 //#undef MTIPPHYIRQ_AVAIL
75 #if defined (na_mii_irq_irq)
76 #define MTIPPHYIRQ_AVAIL
77 #define mtip_mii_control_port ((unsigned int *) (((unsigned int) (na_mii_irq)) | 0x80000000))
78 #endif // na_mii_irq_irq
88 #include "ns83865phy.h"
89 #define PHYTYPE "NS83865"
93 #define PHYTYPE "TDK78Q2120"
98 #include <linux/proc_fs.h>
99 #include <linux/sysctl.h>
100 #endif // CONFIG_SYSCTL
102 //#undef na_dma // Force "Pio" mode
104 #define MTIPDMA_AVAIL
105 #define mtip_dma_control_port ((np_dma *) (((unsigned int) (na_dma)) | 0x80000000))
114 /*----------------------------------------------------------------------
117 . 0 for normal operation
118 . 1 for slightly more details
119 . 2 for interrupt tracking, status flags
121 . 4 for complete packet dumps
122 -----------------------------------------------------------------------*/
123 //#define MTIP_DEBUG 4
124 //#define MTIP_DEBUG 3
125 //#define MTIP_DEBUG 2
126 //#define MTIP_DEBUG 1
129 #if (MTIP_DEBUG > 2 )
130 #define PRINTK3(args...) printk(args)
132 #define PRINTK3(args...)
136 #define PRINTK2(args...) printk(args)
138 #define PRINTK2(args...)
142 #define PRINTK(args...) printk(args)
144 #define PRINTK(args...)
148 typedef unsigned char byte
;
149 typedef unsigned short word
;
150 typedef unsigned long int dword
;
153 /*-----------------------------------------------------------
154 Port address(es). Array must end in zero.
156 #if defined(CONFIG_EXCALIBUR)
157 static unsigned int mtip_portlist
[] =
159 ((((unsigned int) (na_mtip_mac_control_port
)) | 0x80000000)))
161 static unsigned int mtip_irqlist
[] =
162 { na_mtip_mac_rxFIFO_irq
, 0 };
163 #define PIO_port_rxFIFO (((unsigned int) (na_mtip_mac_rxFIFO)) | 0x80000000)
164 #define PIO_port_txFIFO (((unsigned int) (na_mtip_mac_txFIFO)) | 0x80000000)
166 #define PIO_port_rxFIFO (((unsigned int) (na_mtip_mac_rxFIFO)))
167 #define PIO_port_txFIFO (((unsigned int) (na_mtip_mac_txFIFO)))
169 #endif // CONFIG_EXCALIBUR
174 struct net_device_stats stats
;
178 // Root directory /proc/sys/dev
179 // Second entry must be null to terminate the table
180 ctl_table root_table
[2];
182 // Directory for this device /proc/sys/dev/ethX
183 // Again the second entry must be zero to terminate
184 ctl_table eth_table
[2];
186 // This is the parameters (file) table
187 ctl_table param_table
[CTL_MTIP_LAST_ENTRY
];
189 // Saves the sysctl header returned by register_sysctl_table()
190 // we send this to unregister_sysctl_table()
191 struct ctl_table_header
*sysctl_header
;
193 // Parameter variables (files) go here
194 char ctl_info
[1024]; // ?...?
199 ......................*/
201 #endif // CONFIG_SYSCTL
205 /*-----------------------------------------------------------
206 | Print out a packet.
209 static void print_packet( byte
* buf
, int length
)
218 printk("Packet length %d \n", length
);
222 remainder
= length
% 16;
224 for ( i
= 0; i
< lines
; i
++ ) {
227 for ( cur
= 0; cur
< 8; cur
++ ) {
232 printk("%02x %02x ", a
, b
);
236 for ( i
= 0; i
< remainder
/2 ; i
++ ) {
241 printk("%02x %02x ", a
, b
);
250 /*-----------------------------------------------------------
252 #define PRINTSTDPHYREGS(pmac) \
254 printk(" PhyCtl0: %04X" \
257 (pmac->mdio0).CONTROL, \
258 (pmac->mdio0).STATUS, \
259 (pmac->mdio0).PHY_ID1); \
260 printk(" PhyID2: %04X" \
262 " PhyRemcap5: %04X\n", \
263 (pmac->mdio0).PHY_ID2, \
265 (pmac->mdio0).REMADV);
269 #define PRINTNS83PHYREGS(pmac, \
274 PRINTSTDPHYREGS(pmac); \
276 printk(" Ns20Ists:%04X" \
278 " Ns17Lnksts: %04X\n", \
286 #define PRINTTDKPHYREGS(pmac, \
290 PRINTSTDPHYREGS(pmac); \
292 printk(" Tdk16: %04X" \
294 " Tdk18Diag: %04X\n", \
295 (pmac->mdio0).reg10, \
301 /*-----------------------------------------------------------
303 unsigned int gMtipDisabledRxints
;
304 unsigned int gMtipDisabledTxints
;
305 unsigned long gMtipDiscardSink
; // RxFifo discard
306 unsigned int gMtipDmaints
;
307 unsigned int gMtipDmaintsBusy
;
308 unsigned int gMtipDmaintsBusyDone
;
309 unsigned int gMtipDmaintsNoDone
;
310 unsigned int gMtipRxints
;
311 unsigned int gMtipRxintsRxdmaBusy
;
312 unsigned int gMtipRxintsRxdmaQued
;
313 unsigned int gMtipRxNoints
;
314 int gMtipRxSkbFifoNumL32s
;
315 word gMtipRxSkbframelenbyts
;
316 unsigned int gMtipTxints
;
317 unsigned int gMtipTxintsIncomplete
;
318 int gMtipTxSkbFifoNumL32s
;
319 word gMtipTxSkbframelenbyts
;
320 unsigned int gMtipUnexpDmaints
;
321 unsigned int gMtipUnexpRxints
;
322 unsigned int gMtipUnexpTxints
;
324 struct sk_buff
*gpMtipRxSkbInProg
;
326 struct sk_buff
*gpMtipTxSkbInProg
;
328 #if defined (MTIPDMA_AVAIL)
330 unsigned int gMtipDmaQ
;
331 unsigned int gMtipDmaState
;
333 unsigned char gMtipTmpDmaBuf
[MTIP_MAC_MAX_FRAME_SIZE
+ MTIP_MI_XBUF_BYTS
];
334 // Nios alignment requirements...very inconvenient...
335 // for now...but should be in "on chip sram" if any...
336 // (perhaps used as "ring[s]"...
337 // for now...rx and tx share same temporary 1 only "dma buffer"
341 Mtip_DmaQ_TxSkb2Tmp
= (1 << 0)
342 , Mtip_DmaQ_RxFifo2Tmp
= (1 << 1)
343 , Mtip_DmaQ_RxFifo2Trash
= (1 << 2)
348 Mtip_DmaState_Idle
= 0
349 , Mtip_DmaState_RxFifo2Tmp
= 1
350 , Mtip_DmaState_RxTmp2Skb
= 2
351 , Mtip_DmaState_TxSkb2Tmp
= 3
352 , Mtip_DmaState_TxTmp2Fifo
= 4
353 , Mtip_DmaState_RxFifo2Trash
= 5
357 /*-----------------------------------------------------------
359 static void dma_start
360 (int bytes_per_transfer
,
361 void *source_address
,
362 void *destination_address
,
363 int transfer_count
, // In units of bytes_per_transfer
364 int mode
) // wcon, rcon, i_en, ... bit(s)
366 // Caller must have already flushed any "memory" range
367 // involved in this transfer that stands at risk.
369 int control_bits
= 0;
370 np_dma
*dma
= mtip_dma_control_port
;
372 dma
->np_dmacontrol
= 0;
373 // | 1. Halt anything that's going on
375 dma
->np_dmastatus
= 0;
376 dma
->np_dmareadaddress
= (int)source_address
;
377 dma
->np_dmawriteaddress
= (int)destination_address
;
378 dma
->np_dmalength
= transfer_count
* bytes_per_transfer
;
382 | (bytes_per_transfer
& 7) // low three bits of control reg
383 | ((bytes_per_transfer
& 8) ? np_dmacontrol_doubleword_mask
: 0)
384 | ((bytes_per_transfer
& 16) ? np_dmacontrol_quadword_mask
: 0)
385 | np_dmacontrol_leen_mask
// enable length
386 // | np_dmacontrol_reen_mask //;dgt;tmp;test; Enable read end-of-packet
387 // | np_dmacontrol_ween_mask //;dgt;tmp;test; Enable write end-of-packet
388 | np_dmacontrol_go_mask
; // and... go!
390 dma
->np_dmacontrol
= control_bits
;
395 /*-----------------------------------------------------------
397 void dma_start_RxFifo2Tmp(void)
399 // Caller must have already set gMtipDmaState
400 // to Mtip_DmaState_RxFifo2Tmp (under semaphore),
401 // and disabled Rx ready interrupts.
403 dcache_push (((unsigned long) (gpMtipRxData
)),
404 gMtipRxSkbframelenbyts
);
407 (4, // Byts per transfer
408 ((void *) (na_mtip_mac_rxFIFO
)), // 32 bit source fifo
409 gMtipTmpDmaBuf
, // 32 bit aligned dest
410 gMtipRxSkbFifoNumL32s
, // # of 4 byte transfers
411 ( np_dmacontrol_rcon_mask
// Source is a Fifo
412 | np_dmacontrol_i_en_mask
// Dma done:interrupt
416 /*-----------------------------------------------------------
418 void dma_start_TxSkb2Tmp(void)
420 // Caller must have already set gMtipDmaState
421 // to Mtip_DmaState_TxSkb2Tmp (under semaphore)
423 dcache_push (((unsigned long) (gpMtipTxData
)),
424 gMtipTxSkbframelenbyts
);
426 (2, // Byts per transfer
427 gpMtipTxData
, // 16 bit aligned src,
428 gMtipTmpDmaBuf
, // 32 bit aligned dest,
429 (gMtipTxSkbFifoNumL32s
<< 1), // # of 2 byte transfers
430 ( 0 // Neither end a fifo
431 | np_dmacontrol_i_en_mask
// Dma done:interrupt
433 // At the risk of possibly incurring twice the copy
434 // time, save some cpu cycles by assuming outbound
435 // data starts on a 16 bit boundary (Have never
436 // empirically observed it on anything but...)...
439 /*-----------------------------------------------------------
441 void dma_start_RxFifo2Trash(void)
443 // Caller must have already set gMtipDmaState
444 // to Mtip_DmaState_RxFifo2Trash (under semaphore),
445 // and disabled Rx ready interrupts.
448 (4, // Byts per transfer
449 ((void *) (na_mtip_mac_rxFIFO
)), // 32 bit source fifo
451 &(gMtipDiscardSink
)), // 32 bit aligned dest
452 gMtipRxSkbFifoNumL32s
, // # of 4 byte transfers
453 ( np_dmacontrol_rcon_mask
// Source is a Fifo
454 | np_dmacontrol_wcon_mask
// Dest is a sinkhole
455 | np_dmacontrol_i_en_mask
// Dma done:interrupt
458 #endif // MTIPDMA_AVAIL
460 /*-----------------------------------------------------------
461 | Entry condition: Cpu interrupts DISabled.
463 static void mtip_NuRxReady(struct net_device
*dev
,
464 unsigned int cmplnstatus
)
466 // Caller must have already verified cmplnstatus's
467 // mmac_rcs_VALID_mask bit is SET.
469 struct mtip_local
*lp
;
472 lp
= (struct mtip_local
*)dev
->priv
;
473 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
475 gMtipRxSkbframelenbyts
= ( cmplnstatus
& mmac_rcs_FRAME_LENGTH_mask
);
480 "mtip_NuRxReady:%s, asts:0x%04X, csts:0x%08X, Len:%d\n",
484 gMtipRxSkbframelenbyts
);
486 if(gMtipRxSkbframelenbyts
== 0)
491 "mtip_NuRxReady:%s, ZERO len frame,"
492 " asts:0x%04X, csts:0x%08X\n",
498 gMtipRxSkbFifoNumL32s
= ((gMtipRxSkbframelenbyts
+ 3) >> 2);
500 if( cmplnstatus
& mmac_rcs_ERROR_mask
)
505 "mtip_NuRxReady:%s, Bad frame:0x%08X, Len:%d\n",
508 gMtipRxSkbframelenbyts
);
510 lp
->stats
.rx_errors
++;
512 //;...can't differentiate...lp->stats.rx_frame_errors++;
513 //;...can't differentiate...lp->stats.rx_length_errors++;
514 //;...can't differentiate...lp->stats.rx_crc_errors++;
516 #if defined (MTIPDMA_AVAIL)
517 pmac
->IRQ_CONFIG
&= (~(mmac_ic_EN_RX_FRAME_AVAILABLE_mask
));
518 // disable rx ready interrupt
520 if(gMtipDmaState
== Mtip_DmaState_Idle
)
522 gMtipDmaState
= Mtip_DmaState_RxFifo2Trash
;
524 dma_start_RxFifo2Trash();
528 gMtipDmaQ
|= Mtip_DmaQ_RxFifo2Trash
;
535 pmac
->RX_CMD_STAT
= mmac_rcs_READ_CMD_mask
;
536 while( (pmac
->RX_CMD_STAT
) & mmac_rcs_READ_CMD_mask
)
538 FifoL32
|= *((volatile unsigned long *) PIO_port_rxFIFO
);
540 gMtipDiscardSink
= FifoL32
;
544 #endif // MTIPDMA_AVAIL
547 //;...?...lp->stats.multicast++;
549 if(gMtipRxSkbframelenbyts
> MTIP_MAC_MAX_FRAME_SIZE
)
555 "mtip_NuRxReady:%s, oversized %d byte packet.\n",
557 gMtipRxSkbframelenbyts
);
562 dev_alloc_skb( (gMtipRxSkbFifoNumL32s
<< 2) +
563 MTIP_SKB_XBUF_BYTS
);
564 // Extra bytes: Dma requirements
566 if ( gpMtipRxSkbInProg
== NULL
)
572 "mtip_NuRxReady:%s, Low memory, packet dropped.\n",
577 skb_reserve( gpMtipRxSkbInProg
, 2 ); /* 16 bit alignment */
579 gpMtipRxSkbInProg
->dev
= dev
;
581 gpMtipRxData
= skb_put( gpMtipRxSkbInProg
, gMtipRxSkbframelenbyts
);
583 lp
->stats
.rx_packets
++;
585 #if defined (MTIPDMA_AVAIL)
586 pmac
->IRQ_CONFIG
&= (~(mmac_ic_EN_RX_FRAME_AVAILABLE_mask
));
587 // disable rx ready interrupt
589 if(gMtipDmaState
== Mtip_DmaState_Idle
)
591 gMtipDmaState
= Mtip_DmaState_RxFifo2Tmp
;
593 dma_start_RxFifo2Tmp();
597 gMtipDmaQ
|= Mtip_DmaQ_RxFifo2Tmp
;
602 insl(((unsigned long) PIO_port_rxFIFO
),
604 gMtipRxSkbFifoNumL32s
);
608 "%s:Received %d byte Packet 0x%08X\n",
610 gMtipRxSkbframelenbyts
,
611 ((unsigned long) gpMtipRxData
));
614 print_packet( gpMtipRxData
, gMtipRxSkbframelenbyts
);
617 gpMtipRxSkbInProg
->protocol
=
618 eth_type_trans(gpMtipRxSkbInProg
, dev
);
620 netif_rx(gpMtipRxSkbInProg
);
622 pmac
->RX_CMD_STAT
= mmac_rcs_READ_CMD_mask
;
623 // acknowledge frame reception
626 #endif // MTIPDMA_AVAIL
630 /* Oversized Rx frame, or dev_alloc_skb(...) failure */
632 lp
->stats
.rx_dropped
++;
634 #if defined (MTIPDMA_AVAIL)
635 pmac
->IRQ_CONFIG
&= (~(mmac_ic_EN_RX_FRAME_AVAILABLE_mask
));
636 // disable rx ready interrupt
638 if(gMtipDmaState
== Mtip_DmaState_Idle
)
640 gMtipDmaState
= Mtip_DmaState_RxFifo2Trash
;
642 dma_start_RxFifo2Trash();
646 gMtipDmaQ
|= Mtip_DmaQ_RxFifo2Trash
;
654 for ( FifoLoop
= 0; FifoLoop
< gMtipRxSkbFifoNumL32s
; FifoLoop
++ )
656 FifoL32
|= *((volatile unsigned long *) PIO_port_rxFIFO
);
658 gMtipDiscardSink
= FifoL32
;
661 pmac
->RX_CMD_STAT
= mmac_rcs_READ_CMD_mask
;
662 // acknowledge frame reception
665 #endif // MTIPDMA_AVAIL
668 #if defined (MTIPDMA_AVAIL)
669 /*-----------------------------------------------------------
672 | Entry condition: Cpu interrupts DISabled.
674 static irqreturn_t
mtip_DmaInterrupt(int irq
,
676 struct pt_regs
*regs
)
678 unsigned int cmplnstatus
;
679 struct net_device
*dev
= dev_id
;
680 np_dma
*dma
= mtip_dma_control_port
;
686 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
687 old_dmastatus
= dma
->np_dmastatus
;
689 if(old_dmastatus
& np_dmastatus_busy_mask
)
693 if(old_dmastatus
& np_dmastatus_done_mask
)
695 ++gMtipDmaintsBusyDone
;
699 // ...This could be interesting...!
702 if(!(old_dmastatus
& np_dmastatus_done_mask
))
704 ++gMtipDmaintsNoDone
;
705 // presumably gMtipDmaState .eq. Mtip_DmaState_Idle
708 dma
->np_dmastatus
= 0; // Clear done bit (and ack the interrupt)
710 switch (gMtipDmaState
)
712 case Mtip_DmaState_RxFifo2Tmp
:
714 pmac
->RX_CMD_STAT
= mmac_rcs_READ_CMD_mask
;
715 // acknowledge frame reception
717 gMtipDmaState
= Mtip_DmaState_RxTmp2Skb
;
719 (2, // Byts per transfer
720 gMtipTmpDmaBuf
, // 32 bit aligned src
721 gpMtipRxData
, // 16 bit aligned dest
722 (gMtipRxSkbFifoNumL32s
<< 1), // # of 2 byte transfers
723 ( 0 // Neither end a fifo
724 | np_dmacontrol_i_en_mask
// Dma done:interrupt
727 goto DmaIntExit_label
;
729 case Mtip_DmaState_RxTmp2Skb
:
731 //;see state RxFifo2Tmp; pmac->RX_CMD_STAT = mmac_rcs_READ_CMD_mask;
732 // acknowledge frame reception
736 "%s:Received %d byte Packet 0x%08X\n",
738 gMtipRxSkbframelenbyts
,
739 ((unsigned long) gpMtipRxData
));
742 print_packet( gpMtipRxData
, gMtipRxSkbframelenbyts
);
745 gpMtipRxSkbInProg
->protocol
=
746 eth_type_trans(gpMtipRxSkbInProg
, dev
);
748 netif_rx(gpMtipRxSkbInProg
);
750 pmac
->IRQ_CONFIG
|= mmac_ic_EN_RX_FRAME_AVAILABLE_mask
;
751 // enable rx ready interrupt
752 // Note DmaMaybe2Idle_label will find NEITHER
753 // of gMtipDmaQ's Mtip_DmaQ_RxFifo2Tmp NOR
754 // Mtip_DmaQ_RxFifo2Trash bits set!
756 goto DmaMaybe2Idle_label
;
758 case Mtip_DmaState_TxSkb2Tmp
:
760 gMtipDmaState
= Mtip_DmaState_TxTmp2Fifo
;
761 pmac
->TX_CMD_STAT
= (gMtipTxSkbframelenbyts
|
762 mmac_tcs_FRAME_COMPLETE_mask
);
764 (4, // Byts per transfer
765 gMtipTmpDmaBuf
, // 32 bit aligned src
766 ((void *) (na_mtip_mac_txFIFO
)), // 32 bit dest fifo
767 gMtipTxSkbFifoNumL32s
, // # of 4 byte transfers
768 ( np_dmacontrol_wcon_mask
// Dest is a Fifo
769 | np_dmacontrol_i_en_mask
// Dma done:interrupt
772 goto DmaIntExit_label
;
774 case Mtip_DmaState_TxTmp2Fifo
:
776 pmac
->IRQ_CONFIG
|= mmac_ic_EN_TX_FIFO_EMPTY_mask
;
777 // enable tx done interrupt
779 goto DmaMaybe2Idle_label
;
781 case Mtip_DmaState_RxFifo2Trash
:
783 pmac
->RX_CMD_STAT
= mmac_rcs_READ_CMD_mask
;
784 // acknowledge frame reception
786 pmac
->IRQ_CONFIG
|= mmac_ic_EN_RX_FRAME_AVAILABLE_mask
;
787 // enable rx ready interrupt
788 // Note DmaMaybe2Idle_label will find NEITHER
789 // of gMtipDmaQ's Mtip_DmaQ_RxFifo2Tmp NOR
790 // Mtip_DmaQ_RxFifo2Trash bits set!
791 goto DmaMaybe2Idle_label
;
793 // case Mtip_DmaState_Idle:
801 "mtip_DmaInterrupt:%s,"
802 " Unexpected state:0x%02X"
810 // fall thru to DmaMaybe2Idle_label
815 if(gMtipDmaQ
& Mtip_DmaQ_TxSkb2Tmp
)
817 gMtipDmaQ
&= (~(Mtip_DmaQ_TxSkb2Tmp
));
819 gMtipDmaState
= Mtip_DmaState_TxSkb2Tmp
;
821 dma_start_TxSkb2Tmp();
823 else if (gMtipDmaQ
& Mtip_DmaQ_RxFifo2Tmp
)
825 gMtipDmaQ
&= (~(Mtip_DmaQ_RxFifo2Tmp
));
827 gMtipDmaState
= Mtip_DmaState_RxFifo2Tmp
;
829 dma_start_RxFifo2Tmp();
831 else if (gMtipDmaQ
& Mtip_DmaQ_RxFifo2Trash
)
833 gMtipDmaQ
&= (~(Mtip_DmaQ_RxFifo2Trash
));
835 gMtipDmaState
= Mtip_DmaState_RxFifo2Trash
;
837 dma_start_RxFifo2Trash();
841 gMtipDmaState
= Mtip_DmaState_Idle
;
843 if(( (pmac
->AVL_STATUS
) & (mmac_as_RX_FRAME_AVAILABLE_mask
) ))
845 cmplnstatus
= pmac
->RX_CMD_STAT
;
846 if(( cmplnstatus
& mmac_rcs_VALID_mask
))
850 mtip_NuRxReady(dev
, cmplnstatus
);
851 // mtip_NuRxReady (re)disables Rx interrupts...
860 #endif // MTIPDMA_AVAIL
864 /*-----------------------------------------------------------
867 static const char mtip_info_string
[] =
869 "info Provides this information blurb\n"
870 ".... Remind author to complete\n"
872 ".... Remind author to complete\n"
874 #endif /* endif CONFIG_SYSCTL */
878 /*-----------------------------------------------------------
879 | Sysctl handler for all integer parameters
881 static int mtip_sysctl_handler(ctl_table
*ctl
,
892 .....................*/
896 #endif /* endif CONFIG_SYSCTL */
900 /*-----------------------------------------------------------
901 | Sysctl registration function for all parameters (files)
903 | Initilizes device's sysctl proc filesystem
905 | Entry condition: Cpu interrupts ENabled.
907 static void mtip_sysctl_register(struct net_device
*dev
)
909 struct mtip_local
*lp
= (struct mtip_local
*)dev
->priv
;
910 static int ctl_name
= CTL_MTIP1000
;
914 // Make sure the ctl_tables start out as all zeros
915 memset(lp
->root_table
, 0, sizeof lp
->root_table
);
916 memset(lp
->eth_table
, 0, sizeof lp
->eth_table
);
917 memset(lp
->param_table
, 0, sizeof lp
->param_table
);
919 // Initialize the root table
921 ct
->ctl_name
= CTL_DEV
;
922 ct
->procname
= "dev";
925 ct
->child
= lp
->eth_table
;
926 // remaining fields are zero
928 // Initialize the ethX table (this device's table)
930 ct
->ctl_name
= ctl_name
++; // Must be unique
931 ct
->procname
= dev
->name
;
934 ct
->child
= lp
->param_table
;
935 // remaining fields are zero
937 // Initialize the parameter (files) table
938 // Make sure the last entry remains null
939 ct
= lp
->param_table
;
940 for (i
= 0; i
< (CTL_MTIP_LAST_ENTRY
-1); ++i
)
942 // Initialize fields common to all table entries
943 ct
[i
].proc_handler
= mtip_sysctl_handler
;
944 ct
[i
].extra1
= (void*)dev
; // Save our device pointer
945 ct
[i
].extra2
= (void*)lp
; // Save our mtip_local data pointer
948 // INFO - this is our only string parameter
950 ct
[i
].proc_handler
= proc_dostring
; // use default handler
951 ct
[i
].ctl_name
= CTL_MTIP_INFO
;
952 ct
[i
].procname
= "info";
953 ct
[i
].data
= (void*)mtip_info_string
;
954 ct
[i
].maxlen
= sizeof mtip_info_string
;
955 ct
[i
].mode
= 0444; // Read only
959 ct
[i
].proc_handler
= proc_dostring
; // use default handler
960 ct
[i
].ctl_name
= CTL_MTIP_SWVER
;
961 ct
[i
].procname
= "swver";
962 ct
[i
].data
= (void*)version
;
963 ct
[i
].maxlen
= sizeof version
;
964 ct
[i
].mode
= 0444; // Read only
968 .....................*/
972 .....................*/
975 // Register /proc/sys/dev/ethX
976 lp
->sysctl_header
= register_sysctl_table(lp
->root_table
, 1);
978 #endif /* endif CONFIG_SYSCTL */
982 /*-----------------------------------------------------------
983 | Sysctl unregistration when driver closed
985 static void mtip_sysctl_unregister(struct net_device
*dev
)
987 struct mtip_local
*lp
= (struct mtip_local
*)dev
->priv
;
989 unregister_sysctl_table(lp
->sysctl_header
);
991 #endif /* endif CONFIG_SYSCTL */
994 void mtip_phymac_synch (struct net_device
*dev
, int callerflg
)
996 unsigned long cmdcfg
;
997 unsigned long phy100mbitflg
;
998 unsigned long phyfulldupflg
;
999 unsigned long phymr1sts
;
1000 unsigned long phyanegfailedflg
;
1003 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1005 phymr1sts
= (pmac
->mdio0
).STATUS
;
1006 /* Read twice to get CURRENT status...?... */
1007 phymr1sts
= (pmac
->mdio0
).STATUS
;
1009 cmdcfg
= pmac
->COMMAND_CONFIG
;
1012 unsigned long phymr17linkan
;
1014 phymr17linkan
= (pmac
->mdio0
).reg11
;
1016 phy100mbitflg
= (phymr17linkan
& 0x0008);
1017 phyfulldupflg
= (phymr17linkan
& 0x0002);
1019 phyanegfailedflg
= (((pmac
->mdio0
).reg14
) & 0x0100);
1021 #if defined(TDK78Q2120PHY)
1023 unsigned long phymr18diag
;
1025 phymr18diag
= (pmac
->mdio0
).reg12
;
1027 phy100mbitflg
= (phymr18diag
& 0x0400);
1028 phyanegfailedflg
= (phymr18diag
& 0x1000);
1029 phyfulldupflg
= (phymr18diag
& 0x0800);
1034 #endif // TDK78Q2120PHY
1035 #endif // NS83865PHY
1039 // Caller = NOT Phy interrupt handler
1041 if((phymr1sts
& 0x00000004) != 0)
1043 // Link is ostensibly OK
1045 if((((pmac
->mdio0
).CONTROL
) & 0x00001000) != 0)
1047 // Auto negotiation ostensibly enabled
1049 if((phymr1sts
& 0x00000020) != 0)
1051 // Auto negotiation ostensibly has completed
1053 if(phyanegfailedflg
)
1055 // Auto negotiation ostensibly has failed
1057 if(phy100mbitflg
| phyfulldupflg
)
1059 // Auto negotiation failure expected to
1060 // have fallen back to 10 mbit half
1061 // duplex - perhaps phy registers aren't
1062 // actually available, and we've been
1063 // reading 0xFFFF's...
1065 // A 10 mbit, 1/2 duplex remote partner
1066 // mandates a 1/2 duplex Emac (else any
1067 // amount of traffic at all will almost
1068 // certainly collide up a storm...)
1069 // 100 mbit remote partners seem to allow
1070 // duplex mismatches without severe
1071 // loss, at least at the low end of
1072 // their nominal capacity.
1073 // A 10 mbit, full duplex remote partner
1074 // probably also requires a matched Emac,
1075 // but hasn't been confirmed...
1077 printk("\nmtip_phymac_synch:%s"
1078 " No phyregs?-assuming HalfD\n",
1081 pmac
->COMMAND_CONFIG
|= mmac_cc_HD_ENA_mask
;
1083 if((pmac
->COMMAND_CONFIG
&
1084 mmac_cc_HD_ENA_mask
) == 0)
1086 printk("\nmtip_phymac_synch:%s"
1087 " HalfD phy, but FullD emac\n",
1100 // // Caller = Phy interrupt handler
1101 // // If we've got a phy interrupt, then we're so likely
1102 // // to also have actual phy registers that we won't
1103 // // bother trying to confirm...
1106 #if defined(ANNOUNCEPHY)
1107 printk("\nmtip_phymac_synch:%s MR1: 0x%08lX\n",
1110 if((phymr1sts
& 0x00000002) != 0)
1112 printk(" Jabber\n");
1114 if((phymr1sts
& 0x00000010) != 0)
1116 printk(" Remote Fault\n");
1118 if((phymr1sts
& 0x00000020) != 0)
1120 printk(" Autoneg'd\n");
1124 if((phymr1sts
& 0x00000004) != 0)
1126 /* Phy MR1 (status register) indicates link is (now) OK. */
1128 #if defined(ANNOUNCEPHY)
1129 printk(" Link OK:\n");
1134 /* Link is (now) running full duplex. */
1136 pmac
->COMMAND_CONFIG
= (cmdcfg
&
1137 (~(mmac_cc_HD_ENA_mask
)));
1139 #if defined(ANNOUNCEPHY)
1145 /* Link is (now) running half duplex. */
1147 pmac
->COMMAND_CONFIG
= (cmdcfg
| mmac_cc_HD_ENA_mask
);
1149 if((pmac
->COMMAND_CONFIG
& mmac_cc_HD_ENA_mask
) == 0)
1151 printk("\nmtip_phymac_synch:%s"
1152 " HalfD phy, but FullD emac\n",
1156 #if defined(ANNOUNCEPHY)
1161 #if defined(ANNOUNCEPHY)
1163 (phy100mbitflg
) ? "100BASE-TX" : "10BASE-T");
1166 #if defined(ANNOUNCEPHY)
1169 printk(" Link Down\n");
1171 // ...what if link comes up without a phy interrupt
1172 // ... and the emac/phy duplexs don't match...?...
1176 #if defined(ANNOUNCEPHY)
1177 printk(" CMDCF: 0x%08X\n",
1178 pmac
->COMMAND_CONFIG
);
1186 /*-----------------------------------------------------------
1187 | Entry condition: Cpu interrupts ENabled.
1189 static void mtip_phy_configure(struct net_device
* dev
)
1191 /* No need to (re)configure advertisement register or (re)start */
1192 /* auto negotiation after the reset that our caller has probably */
1193 /* recently performed if auto negotiation is enabled by default */
1194 /* and all capabilities are to be advertised. Advertisement */
1195 /* register has already defaulted to our capabilities on last */
1196 /* reset, and phy automatically renegotiates when reset, and/or */
1197 /* when link comes (back) up, etc. */
1199 /* If phy interrupts are required, DO need to reconfigure the */
1200 /* phy's interrupt control register after the reset our caller */
1201 /* has probably recently performed. */
1203 unsigned int msecswaited
;
1204 unsigned int my_ad_caps
; // My Advertised capabilities
1205 unsigned int my_phy_caps
; // My PHY capabilities
1208 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1210 my_ad_caps
= PHY_ADV_CSMA
;
1211 my_phy_caps
= (pmac
->mdio0
).STATUS
;
1213 /* Note Mx TDK phy board's (9) switches control its inherrent */
1214 /* capabilibles (at the moment, prototype:all off = */
1215 /* all capabilities available).. */
1217 if(my_phy_caps
& (PHY_STS_CAP_TXF_MASK
))
1219 // if(..we're allowing 100mbit full duplex...)
1221 my_ad_caps
|= PHY_ADV_TX_FDX
;
1225 if(my_phy_caps
& (PHY_STS_CAP_TXH_MASK
))
1227 // if(..we're allowing 100mbit half duplex...)
1229 my_ad_caps
|= PHY_ADV_TX_HDX
;
1233 if(my_phy_caps
& (PHY_STS_CAP_TF_MASK
))
1235 // if(..we're allowing 10mbit full duplex...)
1237 my_ad_caps
|= PHY_ADV_10_FDX
;
1241 if(my_phy_caps
& (PHY_STS_CAP_TH_MASK
))
1243 // if(..we're allowing 10mbit half duplex...)
1245 my_ad_caps
|= PHY_ADV_10_HDX
;
1249 (pmac
->mdio0
).ADV
= my_ad_caps
;
1251 #if defined (MTIPPHYIRQ_AVAIL)
1253 (pmac
->mdio0
).reg15
=
1255 | NS883865_INTIE_ANEGDONE_MASK
1256 | NS883865_INTIE_LSCHG_MASK
1259 #ifdef TDK78Q2120PHY
1260 (pmac
->mdio0
).reg11
=
1262 | TDK78_INTIE_ANEGDONE_MASK
1263 | TDK78_INTIE_LSCHG_MASK
1264 // | TDK78_INTIE_RXER_MASK
1268 #endif // TDK78Q2120PHY
1269 #endif // NS83865PHY
1270 #endif // MTIPPHYIRQ_AVAIL
1272 (pmac
->mdio0
).CONTROL
=
1274 | PHY_CTL_ANEG_EN_MASK
1275 | PHY_CTL_ANEG_RST_MASK
1279 while(((((pmac
->mdio0
).STATUS
) & 0x00000020) == 0) &
1280 (msecswaited
< 15000))
1287 if((((pmac
->mdio0
).STATUS
) & 0x00000020) != 0)
1289 printk("mtip_phy_configure:%s, autoneg complete\n",
1294 printk("mtip_phy_configure:%s, autoneg started\n",
1299 PRINTNS83PHYREGS(pmac
,
1300 ((unsigned int) ((pmac
->mdio0
).reg14
)),
1301 ((unsigned int) ((pmac
->mdio0
).reg15
)),
1302 ((unsigned int) ((pmac
->mdio0
).reg11
)));
1304 #ifdef TDK78Q2120PHY
1305 PRINTTDKPHYREGS(pmac
,
1306 ((unsigned int) ((pmac
->mdio0
).reg11
)),
1307 ((unsigned int) ((pmac
->mdio0
).reg12
)));
1316 /*-----------------------------------------------------------
1317 | Enable Receive and Transmit, and Rx Interrupts
1319 | Entry condition: Cpu interrupts ENabled.
1321 static void mtip_enable( struct net_device
*dev
)
1325 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1327 PRINTK2("%s:mtip_enable\n", dev
->name
);
1329 pmac
->COMMAND_CONFIG
=
1330 ( mmac_cc_TX_ENA_mask
// enable transmit
1331 | mmac_cc_RX_ENA_mask
// enable receive
1332 | mmac_cc_TX_ADDR_INS_mask
// always overwrite source MAC addr
1335 pmac
->IRQ_CONFIG
= mmac_ic_EN_RX_FRAME_AVAILABLE_mask
;
1336 // enable rx ready interrupt
1338 #if defined (MTIPPHYIRQ_AVAIL)
1339 #if defined (na_mii_irq)
1340 (*(volatile unsigned long *)
1343 (((int) (mtip_mii_control_port
)) +
1345 ((unsigned long) (0x0001));
1346 // Enable phy interrupt pass thru to na_mii_irq
1347 #endif // na_mii_irq
1348 #endif // MTIPPHYIRQ_AVAIL
1352 /*-----------------------------------------------------------
1353 | Perform a software Reset.
1354 | Takes some time so we need to wait until it is finshed.
1356 | Entry condition: Cpu interrupts ENabled.
1358 static void mtip_mac_SwReset( struct net_device
* dev
)
1360 //// struct mtip_local *lp = (struct mtip_local *)dev->priv;
1364 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1366 (pmac
->mdio0
).CONTROL
= PHY_CTL_RST_MASK
; // Reset the phy
1368 // set reset and Gig-Speed bits to make sure we have an
1369 // incoming clock on tx side.
1370 // If there is a 10/100 PHY, we will still have a valid clock on
1371 // tx_clk no matter what setting we have here, but on a Gig phy the
1372 // MII clock may be missing.
1374 pmac
->COMMAND_CONFIG
= mmac_cc_SW_RESET_mask
| mmac_cc_ETH_SPEED_mask
;
1376 // wait for completion with fallback in case there is no PHY or it is
1377 // not connected and hence might not provide any clocks at all.
1379 while( (pmac
->COMMAND_CONFIG
& mmac_cc_SW_RESET_mask
) != 0 &&
1380 timeout
< 10000) timeout
++;
1382 pmac
->COMMAND_CONFIG
= 0;
1384 // Cleanup pending "forgotten" DMAs
1386 #if defined (MTIPDMA_AVAIL)
1387 ((np_dma
*) (na_dma
))->np_dmacontrol
= 0;
1388 ((np_dma
*) (na_dma
))->np_dmastatus
= 0;
1389 gMtipDmaState
= Mtip_DmaState_Idle
;
1390 #endif // MTIPDMA_AVAIL
1395 ....?...tbd....?............
1396 ............................*/
1400 /*-----------------------------------------------------------
1401 | soft reset the device
1403 | Sets the Emac to its normal state.
1405 | Entry condition: Cpu interrupts ENabled.
1407 static void mtip_reset( struct net_device
* dev
)
1411 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1413 PRINTK2("%s:mtip_reset\n", dev
->name
);
1415 mtip_mac_SwReset( dev
);
1419 pmac
->IRQ_CONFIG
= 0;
1422 (pmac
->mdio0
).reg15
= 0;
1424 #ifdef TDK78Q2120PHY
1425 (pmac
->mdio0
).reg11
= 0;
1431 #if defined (MTIPPHYIRQ_AVAIL)
1432 #if defined (na_mii_irq)
1433 (*(volatile unsigned long *)
1436 (((int) (mtip_mii_control_port
)) +
1438 ((unsigned long) (0x0000));
1439 // Disable phy interrupt pass thru to na_mii_irq
1440 #endif // na_mii_irq
1441 #endif // MTIPPHYIRQ_AVAIL
1445 /*-----------------------------------------------------------
1447 static void mtip_reset_config(struct net_device
*dev
)
1451 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1457 (*((unsigned long *)
1458 (&(((unsigned char *)
1459 (dev
->dev_addr
))[0])))));
1462 (*((unsigned short *)
1463 (&(((unsigned char *)
1464 (dev
->dev_addr
))[4])))));
1466 pmac
->FRM_LENGTH
= MTIP_MAC_MAX_FRAME_SIZE
;
1467 pmac
->PAUSE_QUANT
= 0xff00;
1469 pmac
->RX_SECTION_EMPTY
= 0; // Auto tx pause DISabled
1470 // pmac->RX_SECTION_EMPTY = 1900/4;
1471 // If RX FIFO fills to this level, PAUSE frame is sent
1473 pmac
->RX_SECTION_FULL
= 0; // Store&forward (must be zero)
1474 pmac
->TX_SECTION_EMPTY
= (256-16)/4;
1476 pmac
->TX_SECTION_FULL
= 0; // NO Early start tx
1477 // pmac->TX_SECTION_FULL = 128/4; // Early start tx: 128 bytes in FIFO
1478 // If TxFifo smaller than outbound packet, early start Tx
1480 // Slow memory feeding TxFifo must NOT enable early start Tx.
1482 pmac
->RX_ALMOST_EMPTY
= 8; //
1483 pmac
->RX_ALMOST_FULL
= 10; //
1484 pmac
->TX_ALMOST_EMPTY
= 8; //
1485 pmac
->TX_ALMOST_FULL
= 16; // Need at least 14 to cope
1486 // with Avalon/DMA latency
1491 /*-----------------------------------------------------------
1492 | Driver entry point
1494 | Entry condition: Cpu interrupts ENabled
1496 static void mtip_timeout (struct net_device
*dev
)
1502 "%s:mtip_timeout\n",
1505 /* If we get here, some higher level has decided we are broken. */
1508 ....FIXME
:...preemption sensitive stuff to be accessed with
1509 .... cpu interrupts DISabled
...
1510 ....If Dma state one of the TX states
, must stop the
1511 .... Dma
and change to idle state
or handle gMtipDmaQ
1512 .... Mtip_DmaQ_RxFifo2Tmp
/Mtip_DmaQ_RxFifo2Trash
flag(s
)
1513 ....Ensure Tx
"done" interrupt is DISabled
1515 ....Empirical observation
: we are toast no matter
1516 .... what we
do [not]do...........
1517 if(gpMtipTxSkbInProg
)
1520 printk("%s:mtip_timeout, txSkb 0x%08X freed\n",
1522 ((unsigned int) (gpMtipTxSkbInProg
)));
1525 dev_kfree_skb_any (gpMtipTxSkbInProg
);
1526 gpMtipTxSkbInProg
= NULL
;
1528 #if defined (MTIPDMA_AVAIL)
1529 gMtipDmaQ
&= (~(Mtip_DmaQ_TxSkb2Tmp
));
1533 mtip_reset_config( dev
);
1535 mtip_phy_configure(dev
);
1537 mtip_phymac_synch(dev
,
1538 0); // Caller = NOT Phy interrupt handler
1540 netif_wake_queue(dev
);
1545 /*-----------------------------------------------------------
1546 | Driver entry point
1548 | Entry condition: Cpu interrupts ENabled.
1550 static int mtip_hard_start_xmit( struct sk_buff
* skb
,
1551 struct net_device
* dev
)
1553 unsigned long flags
;
1554 struct mtip_local
*lp
= (struct mtip_local
*)dev
->priv
;
1557 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1559 dev
->trans_start
= jiffies
;
1560 netif_stop_queue(dev
);
1562 PRINTK3("%s:mtip_hard_start_xmit\n", dev
->name
);
1564 if ( gpMtipTxSkbInProg
) {
1565 lp
->stats
.tx_aborted_errors
++;
1566 printk("mtip_hard_start_xmit:%s, - tx request while busy.\n",
1568 return 1; // Tell caller to retry "later" (if/after someone
1569 // invokes netif_wake_queue(...))...
1572 gMtipTxSkbframelenbyts
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
1574 if(gMtipTxSkbframelenbyts
> MTIP_MAC_MAX_FRAME_SIZE
)
1576 printk("mtip_hard_start_xmit:%s, oversized %d byte packet.\n",
1578 gMtipTxSkbframelenbyts
);
1579 dev_kfree_skb (skb
);
1580 netif_wake_queue(dev
);
1584 gpMtipTxData
= skb
->data
;
1588 "%s:Transmitting %d byte Packet 0x%08X\n",
1590 gMtipTxSkbframelenbyts
,
1591 ((unsigned long) (gpMtipTxData
)));
1593 print_packet( gpMtipTxData
, gMtipTxSkbframelenbyts
);
1596 gMtipTxSkbFifoNumL32s
= ((gMtipTxSkbframelenbyts
+ 3) >> 2);
1598 ++(lp
->stats
.tx_packets
);
1600 local_irq_save(flags
);
1602 gpMtipTxSkbInProg
= skb
;
1604 #if defined (MTIPDMA_AVAIL)
1606 if(gMtipDmaState
== Mtip_DmaState_Idle
)
1608 gMtipDmaState
= Mtip_DmaState_TxSkb2Tmp
;
1609 local_irq_restore(flags
);
1611 dma_start_TxSkb2Tmp();
1615 gMtipDmaQ
|= Mtip_DmaQ_TxSkb2Tmp
;
1617 local_irq_restore(flags
);
1620 pmac
->TX_CMD_STAT
= (gMtipTxSkbframelenbyts
|
1621 mmac_tcs_FRAME_COMPLETE_mask
);
1623 outsl(((unsigned long) PIO_port_txFIFO
),
1625 gMtipTxSkbFifoNumL32s
);
1626 // If TxFifo smaller than outbound packet, early start Tx
1627 // must be enabled, else we'll overrun the TxFifo (which
1628 // "could" happen anyway with a "fast" cpu).
1629 // If early start Tx enabled, preemption must be disabled,
1630 // else we might underrun the TxFifo.
1632 local_irq_restore(flags
);
1634 pmac
->IRQ_CONFIG
|= mmac_ic_EN_TX_FIFO_EMPTY_mask
;
1635 // enable tx done interrupt
1636 #endif // MTIPDMA_AVAIL
1642 /*-----------------------------------------------------------
1643 | Driver entry point
1645 | Entry condition: Cpu interrupts DISabled.
1647 static irqreturn_t
mtip_RxInterrupt(int irq
,
1649 struct pt_regs
*regs
)
1651 unsigned int cmplnstatus
;
1652 struct net_device
*dev
= dev_id
;
1655 /* RxInterrupt condition self clears if/when RxFifo accessed. */
1657 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1661 if(!((pmac
->IRQ_CONFIG
) & (mmac_ic_EN_RX_FRAME_AVAILABLE_mask
)))
1663 ++gMtipDisabledRxints
;
1666 #if defined (MTIPDMA_AVAIL)
1668 switch (gMtipDmaState
)
1670 case Mtip_DmaState_RxFifo2Tmp
:
1671 case Mtip_DmaState_RxTmp2Skb
:
1672 case Mtip_DmaState_RxFifo2Trash
:
1674 ++gMtipRxintsRxdmaBusy
;
1677 // ...This could be interesting...!
1679 // case Mtip_DmaState_TxSkb2Tmp:
1680 // case Mtip_DmaState_TxTmp2Fifo:
1681 // case Mtip_DmaState_Idle:
1685 if (gMtipDmaQ
& (Mtip_DmaQ_TxSkb2Tmp
|
1686 Mtip_DmaQ_RxFifo2Tmp
|
1687 Mtip_DmaQ_RxFifo2Trash
))
1689 ++gMtipRxintsRxdmaQued
;
1692 // ...This could be interesting...!
1695 #endif // MTIPDMA_AVAIL
1697 cmplnstatus
= pmac
->RX_CMD_STAT
;
1699 if(!( cmplnstatus
& mmac_rcs_VALID_mask
))
1706 "mtip_RxInterrupt:%s, but RxStatus:0x%08X INvalid\n",
1710 /* ?...RxInterrupt condition...? */
1714 mtip_NuRxReady(dev
, cmplnstatus
);
1721 /*-----------------------------------------------------------
1722 | Driver entry point
1724 | Entry condition: Cpu interrupts DISabled.
1726 static irqreturn_t
mtip_TxInterrupt(int irq
,
1728 struct pt_regs
*regs
)
1730 unsigned long cmdcfg
;
1731 struct net_device
*dev
= dev_id
;
1732 struct mtip_local
*lp
;
1736 // Mtip's Tx fifo supposedly could alternatively
1737 // "flow control" the Dma adequately enough to let
1738 // us save this interrupt (if we don't need tx done
1740 //...Jun2004...NOT the case?...perhaps early tx start
1741 //... plays a part therein...?...
1743 lp
= (struct mtip_local
*)dev
->priv
;
1744 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1748 if(!((pmac
->IRQ_CONFIG
) & (mmac_ic_EN_TX_FIFO_EMPTY_mask
)))
1750 ++gMtipDisabledTxints
;
1753 cmdcfg
= pmac
->COMMAND_CONFIG
;
1754 if((cmdcfg
& mmac_cc_EXCESS_COL_mask
) != 0)
1756 ++(lp
->stats
.collisions
);
1758 if((cmdcfg
& mmac_cc_LATE_COL_mask
) != 0)
1760 lp
->stats
.tx_window_errors
++;
1761 // ifconfig displays as "carrier" errors.
1767 "mtip_TxInterrupt:%s, Late collision on last xmit.\n",
1771 old_txcmdstat
= pmac
->TX_CMD_STAT
;
1773 if(gpMtipTxSkbInProg
)
1775 if(!(old_txcmdstat
& mmac_tcs_FRAME_COMPLETE_mask
))
1777 dev_kfree_skb_any (gpMtipTxSkbInProg
);
1778 gpMtipTxSkbInProg
= NULL
;
1782 ++gMtipTxintsIncomplete
;
1785 // ...This could be interesting...!
1793 pmac
->IRQ_CONFIG
&= (~(mmac_ic_EN_TX_FIFO_EMPTY_mask
));
1795 netif_wake_queue(dev
);
1801 #if defined (MTIPPHYIRQ_AVAIL)
1802 /*-----------------------------------------------------------
1803 | Driver entry point
1805 | Entry condition: Cpu interrupts DISabled.
1807 static irqreturn_t
mtip_PhyInterrupt(int irq
,
1809 struct pt_regs
*regs
)
1811 struct net_device
*dev
= dev_id
;
1814 unsigned int nsIntstsReg20
;
1815 unsigned int nsIntieReg21
;
1816 unsigned int nsLnkstsReg17
;
1818 #ifdef TDK78Q2120PHY
1819 unsigned int tdkDiagReg18
;
1820 unsigned int tdkintCtlStsReg17
;
1824 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1826 #if defined(ANNOUNCEPHY)
1829 "mtip_PhyInterrupt:%s\n",
1834 nsIntstsReg20
= (pmac
->mdio0
).reg14
;
1835 nsIntieReg21
= (pmac
->mdio0
).reg15
;
1836 nsLnkstsReg17
= (pmac
->mdio0
).reg11
;
1839 PRINTNS83PHYREGS(pmac
,
1845 (pmac
->mdio0
).reg17
= nsIntstsReg20
;
1846 // Ack (all) interrupt condition(s)
1848 #ifdef TDK78Q2120PHY
1849 tdkintCtlStsReg17
= (pmac
->mdio0
).reg11
;
1850 // Read TDK 78Q2120 interrupt control/status register
1851 // Also acks the interrupt condition(s)
1853 tdkDiagReg18
= (pmac
->mdio0
).reg12
;
1854 // Read TDK 78Q2120 diagnostic register
1855 // Also clears auto-negotiation failed bit
1858 PRINTTDKPHYREGS(pmac
, tdkintCtlStsReg17
, tdkDiagReg18
);
1865 mtip_phymac_synch((struct net_device
*) dev_id
,
1866 1); // Caller = Phy interrupt handler
1870 #endif // MTIPPHYIRQ_AVAIL
1873 /*-----------------------------------------------------------
1874 | Driver entry point (eg: ifconfig ethX up).
1875 | (eg: ifattach ...)
1877 | Open and Initialize the board
1879 | Set up everything, reset the card, etc ..
1881 | Entry condition: Cpu interrupts ENabled.
1883 static int mtip_open(struct net_device
*dev
)
1887 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
1889 PRINTK2("%s:mtip_open\n", dev
->name
);
1891 memset(dev
->priv
, 0, sizeof(struct mtip_local
));
1894 #ifdef CONFIG_SYSCTL
1895 // Set default parameters (files)
1897 ....tbd.............
1898 .....................*/
1901 mtip_reset_config( dev
);
1903 mtip_phy_configure(dev
);
1905 mtip_phymac_synch(dev
,
1906 0); // Caller = NOT Phy interrupt handler
1908 #ifdef CONFIG_SYSCTL
1909 mtip_sysctl_register(dev
);
1910 #endif /* CONFIG_SYSCTL */
1912 netif_start_queue(dev
);
1918 /*-----------------------------------------------------------
1919 | close down the Emac
1921 | put the device in an inactive state
1924 static void mtip_shutdown( struct net_device
*dev
)
1926 PRINTK2("%s:mtip_shutdown\n", dev
->name
);
1929 ....tbd.............
1930 ...........................*/
1934 /*-----------------------------------------------------------
1935 | Driver entry point (eg: ifconfig ethX down).
1937 | Clean up everything from the open routine
1939 static int mtip_close(struct net_device
*dev
)
1941 PRINTK2("%s:mtip_close\n", dev
->name
);
1943 netif_stop_queue(dev
);
1945 if(gpMtipTxSkbInProg
)
1947 dev_kfree_skb_any (gpMtipTxSkbInProg
);
1948 gpMtipTxSkbInProg
= NULL
;
1950 #if defined (MTIPDMA_AVAIL)
1951 gMtipDmaQ
&= (~(Mtip_DmaQ_TxSkb2Tmp
));
1955 #if defined (MTIPDMA_AVAIL)
1957 gMtipDmaState
= Mtip_DmaState_Idle
;
1958 #endif // MTIPDMA_AVAIL
1960 #ifdef CONFIG_SYSCTL
1961 mtip_sysctl_unregister(dev
);
1962 #endif /* CONFIG_SYSCTL */
1964 /* clear everything */
1965 mtip_shutdown( dev
);
1967 /* Update the statistics here. */
1973 /*-----------------------------------------------------------
1974 | Driver entry point (re unregister_netdev()).
1976 | Cleaning up before driver finally unregistered and discarded.
1979 | dev, pointer to the device structure
1984 ---------------------------------------------------------------------------
1986 void mtip_destructor(struct net_device
*dev
)
1988 PRINTK2("%s:mtip_destructor\n", dev
->name
);
1992 /*-----------------------------------------------------------
1993 | Driver entry point.
1995 | Get the current statistics.
1997 | Allows proc file system to query the driver's statistics.
1999 | May be called with the card open or closed.
2001 | Entry condition: Cpu interrupts ENabled.
2003 static struct net_device_stats
* mtip_query_statistics(struct net_device
*dev
)
2005 struct mtip_local
*lp
= (struct mtip_local
*)dev
->priv
;
2007 PRINTK2("%s:mtip_query_statistics\n", dev
->name
);
2013 /*-----------------------------------------------------------
2014 | Clear the multicast table to disable multicast reception.
2016 | Entry condition: Cpu interrupts ENabled.
2018 static void mtip_mac_clearMulticast(struct net_device
*dev
)
2023 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
2025 for(i
=0; i
< 64; i
++ )
2027 (pmac
->hashtable
)[i
] = 0;
2032 /*-----------------------------------------------------------
2033 | Fill the multicast table to enable reception of all multicast frames.
2035 | Entry condition: Cpu interrupts ENabled.
2037 static void mtip_mac_promiscuousMulticast(struct net_device
*dev
)
2042 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
2044 for(i
=0; i
< 64; i
++ )
2046 (pmac
->hashtable
)[i
] = 1;
2051 /*-----------------------------------------------------------
2052 | Reprogram multicast mac addresses into hardware multicast table
2054 | Caller has already cleared existing hash entries as appropriate
2056 | Entry condition: Cpu interrupts ENabled.
2058 static void mtip_setmulticast( struct net_device
*dev
,
2060 struct dev_mc_list
*addrs
)
2068 struct dev_mc_list
*cur_addr
;
2071 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
2075 "mtip_setmulticast:%s\n",
2080 for ( i
= 0; i
< count
; i
++, cur_addr
= cur_addr
->next
)
2082 /* do we have a pointer here? */
2086 /* make sure this is a multicast address */
2087 if ( !( *cur_addr
->dmi_addr
& 1 ) )
2090 hash
= 0; // the hash value
2092 for(a
=5; a
>= 0; a
--)
2094 // loop through all 6 bytes of this mac address
2096 bit
= 0; // the bit calculated from the byte
2097 ch
= (cur_addr
->dmi_addr
)[a
];
2099 for(bitidx
=0;bitidx
< 8;bitidx
++)
2101 bit
^= (int)((ch
>> bitidx
) & 0x01);
2104 hash
= (hash
<< 1) | bit
;
2107 #if (MTIP_DEBUG > 2 )
2109 printk("mtip_setmulticast: ");
2110 for(a
=0; a
< 6; a
++)
2112 ch
= (cur_addr
->dmi_addr
)[a
];
2116 printk(" hash(%d)\n",hash
);
2119 (pmac
->hashtable
)[ hash
] = 1;
2124 /*-----------------------------------------------------------
2125 | Driver entry point.
2127 | This routine will, depending on the values passed to it,
2128 | either make it accept multicast packets, go into
2129 | promiscuous mode ( for TCPDUMP and cousins ) or accept
2130 | a select set of multicast packets
2132 | Entry condition: Cpu interrupts ENabled.
2134 static void mtip_set_multicast_list(struct net_device
*dev
)
2138 pmac
= ((np_mtip_mac
*) dev
->base_addr
);
2142 "%s:mtip_set_multicast_list\n",
2145 if ( dev
->flags
& IFF_PROMISC
)
2150 "%s:mtip_set_multicast_list:RCR_PRMS\n", dev
->name
);
2152 mtip_mac_setPromiscuous(pmac
);
2159 "%s:mtip_set_multicast_list:~RCR_PRMS\n", dev
->name
);
2161 mtip_mac_clearPromiscuous(pmac
);
2164 if (dev
->flags
& IFF_ALLMULTI
)
2169 "%s:mtip_set_multicast_list:RCR_ALMUL\n", dev
->name
);
2171 mtip_mac_promiscuousMulticast(dev
);
2177 "%s:mtip_set_multicast_list:~RCR_ALMUL\n", dev
->name
);
2179 mtip_mac_clearMulticast(dev
); // Clear any existing hash entries
2183 mtip_setmulticast( dev
,
2191 /*-----------------------------------------------------------
2192 | Entry condition: Cpu interrupts ENabled
2193 | (in SPITE of claims disabled...).
2195 static int __init
mtip_probe(struct net_device
*dev
, unsigned int ioaddr
)
2200 static unsigned version_printed
= 0;
2203 pmac
= ((np_mtip_mac
*) ioaddr
);
2205 PRINTK2("%s:mtip_probe\n", dev
->name
);
2207 SET_MODULE_OWNER (dev
);
2210 #ifdef CONFIG_EXCALIBUR
2211 printk("mtip_probe:%s, %d Khz Nios (%s) (%s)\n",
2213 nasys_clock_freq_1000
,
2219 /* Grab the region so that no one else tries to probe our ioports. */
2220 if (!request_region(ioaddr
,
2222 dev
->name
)) return -EBUSY
;
2224 if (version_printed
++ == 0) printk("%s", version
);
2226 dev
->base_addr
= ioaddr
;
2233 // Empirical observation: expect NS83865PHY's phy address = 2
2235 oldmdioaddr0
= pmac
->MDIO_ADDR0
;
2237 for (i
= 0; i
<= 31; i
++)
2239 pmac
->MDIO_ADDR0
= i
;
2241 if(((pmac
->mdio0
).PHY_ID1
) == 0x2000)
2251 pmac
->MDIO_ADDR0
= phyaddr
;
2255 pmac
->MDIO_ADDR0
= oldmdioaddr0
;
2257 printk("mtip_probe:%s, (%s) phy not found"
2258 ", defaulting to addr:0x%02X\n",
2265 #ifdef TDK78Q2120PHY
2266 // TDK78Q2120PHY's respond to the "broadcast" phy address 0,
2267 // so leave pmac->MDIO_ADDR0 at its default value 0
2271 #endif // NS83865PHY
2275 printk("mtip_probe:%s, REV=0x%08x, (%s) Phyaddr:0x%02X\n",
2283 PRINTNS83PHYREGS(pmac
,
2284 ((unsigned int) ((pmac
->mdio0
).reg14
)),
2285 ((unsigned int) ((pmac
->mdio0
).reg15
)),
2286 ((unsigned int) ((pmac
->mdio0
).reg11
)));
2288 #ifdef TDK78Q2120PHY
2289 PRINTTDKPHYREGS(pmac
,
2290 ((unsigned int) ((pmac
->mdio0
).reg11
)),
2291 ((unsigned int) ((pmac
->mdio0
).reg12
)));
2298 #ifdef CONFIG_EXCALIBUR
2300 extern unsigned char *excalibur_enet_hwaddr
;
2302 memcpy(dev
->dev_addr
, excalibur_enet_hwaddr
, 6);
2309 . Print the Ethernet address
2312 for (i
= 0; i
< 5; i
++)
2313 printk("%2.2x:", dev
->dev_addr
[i
] );
2314 printk("%2.2x \n", dev
->dev_addr
[5] );
2316 /* set the private data to zero by default */
2317 memset(dev
->priv
, 0, sizeof(struct mtip_local
));
2319 /* Fill in the fields of the device structure with ethernet values. */
2322 /* Grab the RxIRQ */
2323 retval
= request_irq(dev
->irq
,
2329 printk("mtip_probe:%s unable to hook RxIRQ %d (retval=%d).\n",
2334 goto frepriv_err_out
;
2337 retval
= request_irq(na_mtip_mac_txFIFO_irq
,
2343 printk("mtip_probe:%s unable to hook TxIRQ %d (retval=%d).\n",
2345 na_mtip_mac_txFIFO_irq
,
2348 goto freRxIrq_err_out
;
2351 #if defined (MTIPPHYIRQ_AVAIL)
2352 /* Grab the PhyIRQ */
2353 retval
= request_irq(na_mii_irq_irq
,
2360 printk("mtip_probe:%s unable to hook PhyIRQ %d (retval=%d).\n",
2365 goto freTxIrq_err_out
;
2367 #endif // MTIPPHYIRQ_AVAIL
2369 gMtipDisabledRxints
= 0;
2370 gMtipDisabledTxints
= 0;
2372 gMtipDmaintsBusy
= 0;
2373 gMtipDmaintsBusyDone
= 0;
2374 gMtipDmaintsNoDone
= 0;
2376 gMtipRxintsRxdmaBusy
= 0;
2377 gMtipRxintsRxdmaQued
= 0;
2380 gMtipTxintsIncomplete
= 0;
2381 gMtipUnexpDmaints
= 0;
2382 gMtipUnexpRxints
= 0;
2383 gMtipUnexpTxints
= 0;
2384 gpMtipTxSkbInProg
= NULL
;
2386 #if defined (MTIPDMA_AVAIL)
2388 gMtipDmaState
= Mtip_DmaState_Idle
;
2390 /* Grab the DmaIRQ */
2391 retval
= request_irq(na_dma_irq
,
2397 printk("mtip_probe:%s unable to hook DmaIRQ %d (retval=%d).\n",
2402 goto frePhyIrq_err_out
;
2404 #endif // MTIPDMA_AVAIL
2406 // see mtip_phymac_synch for full/half duplex coordination
2408 dev
->open
= mtip_open
;
2409 dev
->stop
= mtip_close
;
2410 dev
->hard_start_xmit
= mtip_hard_start_xmit
;
2411 dev
->tx_timeout
= mtip_timeout
;
2412 dev
->get_stats
= mtip_query_statistics
;
2413 #ifdef HAVE_MULTICAST
2414 dev
->set_multicast_list
= &mtip_set_multicast_list
;
2419 #if defined (MTIPPHYIRQ_AVAIL)
2420 #if defined (MTIPDMA_AVAIL)
2422 #endif // MTIPDMA_AVAIL
2424 free_irq(na_mii_irq_irq
, dev
);
2427 #endif // MTIPPHYIRQ_AVAIL
2429 free_irq(na_mtip_mac_txFIFO_irq
,
2434 free_irq(na_mtip_mac_rxFIFO_irq
,
2443 release_region (ioaddr
, MTIP1000_IO_EXTENT
);
2448 /*-----------------------------------------------------------
2449 | Driver entry point (called by ethif_probe2()).
2451 | Return: 0 success.
2453 | Entry condition: Cpu interrupts ENabled
2454 | (in SPITE of claims disabled...).
2456 struct net_device
* __init
mtip1000_init(int unit
)
2458 struct net_device
*dev
= alloc_etherdev(sizeof(struct mtip_local
));
2462 if (!dev
) return ERR_PTR(-ENODEV
);
2464 sprintf(dev
->name
, "eth%d", unit
);
2465 netdev_boot_setup_check(dev
);
2467 PRINTK2("%s:mtip1000_init\n", dev
->name
);
2469 for (i
= 0; mtip_portlist
[i
]; i
++) {
2470 dev
->irq
= mtip_irqlist
[i
];
2472 if (mtip_probe(dev
, mtip_portlist
[i
]) == 0) break;
2475 if (!mtip_portlist
[i
]) err
= -ENODEV
;
2478 err
= register_netdev(dev
);
2483 // printk(KERN_WARNING "mtip1000: no emac unit %d detected.\n",unit);
2484 return ERR_PTR(err
);