2 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
4 * Author: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com>
8 * QE UCC Gigabit Ethernet Driver
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/errno.h>
18 #include <linux/slab.h>
19 #include <linux/stddef.h>
20 #include <linux/interrupt.h>
21 #include <linux/netdevice.h>
22 #include <linux/etherdevice.h>
23 #include <linux/skbuff.h>
24 #include <linux/spinlock.h>
26 #include <linux/ethtool.h>
27 #include <linux/delay.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/fsl_devices.h>
30 #include <linux/ethtool.h>
31 #include <linux/mii.h>
32 #include <linux/workqueue.h>
34 #include <asm/of_platform.h>
35 #include <asm/uaccess.h>
38 #include <asm/immap_qe.h>
41 #include <asm/ucc_fast.h>
44 #include "ucc_geth_phy.h"
48 #define DRV_DESC "QE UCC Gigabit Ethernet Controller version:Sept 11, 2006"
49 #define DRV_NAME "ucc_geth"
51 #define ugeth_printk(level, format, arg...) \
52 printk(level format "\n", ## arg)
54 #define ugeth_dbg(format, arg...) \
55 ugeth_printk(KERN_DEBUG , format , ## arg)
56 #define ugeth_err(format, arg...) \
57 ugeth_printk(KERN_ERR , format , ## arg)
58 #define ugeth_info(format, arg...) \
59 ugeth_printk(KERN_INFO , format , ## arg)
60 #define ugeth_warn(format, arg...) \
61 ugeth_printk(KERN_WARNING , format , ## arg)
63 #ifdef UGETH_VERBOSE_DEBUG
64 #define ugeth_vdbg ugeth_dbg
66 #define ugeth_vdbg(fmt, args...) do { } while (0)
67 #endif /* UGETH_VERBOSE_DEBUG */
69 static DEFINE_SPINLOCK(ugeth_lock);
71 static struct ucc_geth_info ugeth_primary_info = {
73 .bd_mem_part = MEM_PART_SYSTEM,
74 .rtsm = UCC_FAST_SEND_IDLES_BETWEEN_FRAMES,
75 .max_rx_buf_length = 1536,
76 /* FIXME: should be changed in run time for 1G and 100M */
77 #ifdef CONFIG_UGETH_HAS_GIGA
78 .urfs = UCC_GETH_URFS_GIGA_INIT,
79 .urfet = UCC_GETH_URFET_GIGA_INIT,
80 .urfset = UCC_GETH_URFSET_GIGA_INIT,
81 .utfs = UCC_GETH_UTFS_GIGA_INIT,
82 .utfet = UCC_GETH_UTFET_GIGA_INIT,
83 .utftt = UCC_GETH_UTFTT_GIGA_INIT,
85 .urfs = UCC_GETH_URFS_INIT,
86 .urfet = UCC_GETH_URFET_INIT,
87 .urfset = UCC_GETH_URFSET_INIT,
88 .utfs = UCC_GETH_UTFS_INIT,
89 .utfet = UCC_GETH_UTFET_INIT,
90 .utftt = UCC_GETH_UTFTT_INIT,
93 .mode = UCC_FAST_PROTOCOL_MODE_ETHERNET,
94 .ttx_trx = UCC_FAST_GUMR_TRANSPARENT_TTX_TRX_NORMAL,
95 .tenc = UCC_FAST_TX_ENCODING_NRZ,
96 .renc = UCC_FAST_RX_ENCODING_NRZ,
97 .tcrc = UCC_FAST_16_BIT_CRC,
98 .synl = UCC_FAST_SYNC_LEN_NOT_USED,
102 .extendedFilteringChainPointer = ((uint32_t) NULL),
103 .typeorlen = 3072 /*1536 */ ,
104 .nonBackToBackIfgPart1 = 0x40,
105 .nonBackToBackIfgPart2 = 0x60,
106 .miminumInterFrameGapEnforcement = 0x50,
107 .backToBackInterFrameGap = 0x60,
111 .strictpriorityq = 0xff,
112 .altBebTruncation = 0xa,
114 .maxRetransmission = 0xf,
115 .collisionWindow = 0x37,
116 .receiveFlowControl = 1,
117 .maxGroupAddrInHash = 4,
118 .maxIndAddrInHash = 4,
120 .maxFrameLength = 1518,
121 .minFrameLength = 64,
125 .ecamptr = ((uint32_t) NULL),
126 .eventRegMask = UCCE_OTHER,
127 .pausePeriod = 0xf000,
128 .interruptcoalescingmaxvalue = {1, 1, 1, 1, 1, 1, 1, 1},
149 .numStationAddresses = UCC_GETH_NUM_OF_STATION_ADDRESSES_1,
150 .largestexternallookupkeysize =
151 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE,
152 .statisticsMode = UCC_GETH_STATISTICS_GATHERING_MODE_NONE,
153 .vlanOperationTagged = UCC_GETH_VLAN_OPERATION_TAGGED_NOP,
154 .vlanOperationNonTagged = UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP,
155 .rxQoSMode = UCC_GETH_QOS_MODE_DEFAULT,
156 .aufc = UPSMR_AUTOMATIC_FLOW_CONTROL_MODE_NONE,
157 .padAndCrc = MACCFG2_PAD_AND_CRC_MODE_PAD_AND_CRC,
158 .numThreadsTx = UCC_GETH_NUM_OF_THREADS_4,
159 .numThreadsRx = UCC_GETH_NUM_OF_THREADS_4,
160 .riscTx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
161 .riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
164 static struct ucc_geth_info ugeth_info[8];
167 static void mem_disp(u8 *addr, int size)
170 int size16Aling = (size >> 4) << 4;
171 int size4Aling = (size >> 2) << 2;
176 for (i = addr; (u32) i < (u32) addr + size16Aling; i += 16)
177 printk("0x%08x: %08x %08x %08x %08x\r\n",
181 *((u32 *) (i + 8)), *((u32 *) (i + 12)));
183 printk("0x%08x: ", (u32) i);
184 for (; (u32) i < (u32) addr + size4Aling; i += 4)
185 printk("%08x ", *((u32 *) (i)));
186 for (; (u32) i < (u32) addr + size; i++)
187 printk("%02x", *((u8 *) (i)));
193 #ifdef CONFIG_UGETH_FILTERING
194 static void enqueue(struct list_head *node, struct list_head *lh)
198 spin_lock_irqsave(&ugeth_lock, flags);
199 list_add_tail(node, lh);
200 spin_unlock_irqrestore(&ugeth_lock, flags);
202 #endif /* CONFIG_UGETH_FILTERING */
204 static struct list_head *dequeue(struct list_head *lh)
208 spin_lock_irqsave(&ugeth_lock, flags);
209 if (!list_empty(lh)) {
210 struct list_head *node = lh->next;
212 spin_unlock_irqrestore(&ugeth_lock, flags);
215 spin_unlock_irqrestore(&ugeth_lock, flags);
220 static int get_interface_details(enum enet_interface enet_interface,
221 enum enet_speed *speed,
225 int *tbi, int *limited_to_full_duplex)
227 /* Analyze enet_interface according to Interface Mode
228 Configuration table */
229 switch (enet_interface) {
231 *speed = ENET_SPEED_10BT;
234 *speed = ENET_SPEED_10BT;
239 *speed = ENET_SPEED_10BT;
242 *limited_to_full_duplex = 1;
245 *speed = ENET_SPEED_100BT;
248 *speed = ENET_SPEED_100BT;
252 *speed = ENET_SPEED_100BT;
254 *limited_to_full_duplex = 1;
257 *speed = ENET_SPEED_1000BT;
258 *limited_to_full_duplex = 1;
260 case ENET_1000_RGMII:
261 *speed = ENET_SPEED_1000BT;
263 *limited_to_full_duplex = 1;
266 *speed = ENET_SPEED_1000BT;
268 *limited_to_full_duplex = 1;
271 *speed = ENET_SPEED_1000BT;
274 *limited_to_full_duplex = 1;
284 static struct sk_buff *get_new_skb(struct ucc_geth_private *ugeth, u8 *bd)
286 struct sk_buff *skb = NULL;
288 skb = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length +
289 UCC_GETH_RX_DATA_BUF_ALIGNMENT);
294 /* We need the data buffer to be aligned properly. We will reserve
295 * as many bytes as needed to align the data properly
298 UCC_GETH_RX_DATA_BUF_ALIGNMENT -
299 (((unsigned)skb->data) & (UCC_GETH_RX_DATA_BUF_ALIGNMENT -
302 skb->dev = ugeth->dev;
304 out_be32(&((struct qe_bd *)bd)->buf,
307 ugeth->ug_info->uf_info.max_rx_buf_length +
308 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
311 out_be32((u32 *)bd, (R_E | R_I | (in_be32((u32 *)bd) & R_W)));
316 static int rx_bd_buffer_set(struct ucc_geth_private *ugeth, u8 rxQ)
323 bd = ugeth->p_rx_bd_ring[rxQ];
327 bd_status = in_be32((u32*)bd);
328 skb = get_new_skb(ugeth, bd);
330 if (!skb) /* If can not allocate data buffer,
331 abort. Cleanup will be elsewhere */
334 ugeth->rx_skbuff[rxQ][i] = skb;
336 /* advance the BD pointer */
337 bd += sizeof(struct qe_bd);
339 } while (!(bd_status & R_W));
344 static int fill_init_enet_entries(struct ucc_geth_private *ugeth,
345 volatile u32 *p_start,
348 u32 thread_alignment,
349 enum qe_risc_allocation risc,
350 int skip_page_for_first_entry)
352 u32 init_enet_offset;
356 for (i = 0; i < num_entries; i++) {
357 if ((snum = qe_get_snum()) < 0) {
358 ugeth_err("fill_init_enet_entries: Can not get SNUM.");
361 if ((i == 0) && skip_page_for_first_entry)
362 /* First entry of Rx does not have page */
363 init_enet_offset = 0;
366 qe_muram_alloc(thread_size, thread_alignment);
367 if (IS_MURAM_ERR(init_enet_offset)) {
369 ("fill_init_enet_entries: Can not allocate DPRAM memory.");
370 qe_put_snum((u8) snum);
375 ((u8) snum << ENET_INIT_PARAM_SNUM_SHIFT) | init_enet_offset
382 static int return_init_enet_entries(struct ucc_geth_private *ugeth,
383 volatile u32 *p_start,
385 enum qe_risc_allocation risc,
386 int skip_page_for_first_entry)
388 u32 init_enet_offset;
392 for (i = 0; i < num_entries; i++) {
393 /* Check that this entry was actually valid --
394 needed in case failed in allocations */
395 if ((*p_start & ENET_INIT_PARAM_RISC_MASK) == risc) {
397 (u32) (*p_start & ENET_INIT_PARAM_SNUM_MASK) >>
398 ENET_INIT_PARAM_SNUM_SHIFT;
399 qe_put_snum((u8) snum);
400 if (!((i == 0) && skip_page_for_first_entry)) {
401 /* First entry of Rx does not have page */
404 ENET_INIT_PARAM_PTR_MASK);
405 qe_muram_free(init_enet_offset);
407 *(p_start++) = 0; /* Just for cosmetics */
415 static int dump_init_enet_entries(struct ucc_geth_private *ugeth,
416 volatile u32 *p_start,
419 enum qe_risc_allocation risc,
420 int skip_page_for_first_entry)
422 u32 init_enet_offset;
426 for (i = 0; i < num_entries; i++) {
427 /* Check that this entry was actually valid --
428 needed in case failed in allocations */
429 if ((*p_start & ENET_INIT_PARAM_RISC_MASK) == risc) {
431 (u32) (*p_start & ENET_INIT_PARAM_SNUM_MASK) >>
432 ENET_INIT_PARAM_SNUM_SHIFT;
433 qe_put_snum((u8) snum);
434 if (!((i == 0) && skip_page_for_first_entry)) {
435 /* First entry of Rx does not have page */
438 ENET_INIT_PARAM_PTR_MASK);
439 ugeth_info("Init enet entry %d:", i);
440 ugeth_info("Base address: 0x%08x",
442 qe_muram_addr(init_enet_offset));
443 mem_disp(qe_muram_addr(init_enet_offset),
454 #ifdef CONFIG_UGETH_FILTERING
455 static struct enet_addr_container *get_enet_addr_container(void)
457 struct enet_addr_container *enet_addr_cont;
459 /* allocate memory */
460 enet_addr_cont = kmalloc(sizeof(struct enet_addr_container), GFP_KERNEL);
461 if (!enet_addr_cont) {
462 ugeth_err("%s: No memory for enet_addr_container object.",
467 return enet_addr_cont;
469 #endif /* CONFIG_UGETH_FILTERING */
471 static void put_enet_addr_container(struct enet_addr_container *enet_addr_cont)
473 kfree(enet_addr_cont);
476 static void set_mac_addr(__be16 __iomem *reg, u8 *mac)
478 out_be16(®[0], ((u16)mac[5] << 8) | mac[4]);
479 out_be16(®[1], ((u16)mac[3] << 8) | mac[2]);
480 out_be16(®[2], ((u16)mac[1] << 8) | mac[0]);
483 #ifdef CONFIG_UGETH_FILTERING
484 static int hw_add_addr_in_paddr(struct ucc_geth_private *ugeth,
485 u8 *p_enet_addr, u8 paddr_num)
487 struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
489 if (!(paddr_num < NUM_OF_PADDRS)) {
490 ugeth_warn("%s: Illegal paddr_num.", __FUNCTION__);
495 (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
498 /* Ethernet frames are defined in Little Endian mode, */
499 /* therefore to insert the address we reverse the bytes. */
500 set_mac_addr(&p_82xx_addr_filt->paddr[paddr_num].h, p_enet_addr);
503 #endif /* CONFIG_UGETH_FILTERING */
505 static int hw_clear_addr_in_paddr(struct ucc_geth_private *ugeth, u8 paddr_num)
507 struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
509 if (!(paddr_num < NUM_OF_PADDRS)) {
510 ugeth_warn("%s: Illagel paddr_num.", __FUNCTION__);
515 (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
518 /* Writing address ff.ff.ff.ff.ff.ff disables address
519 recognition for this register */
520 out_be16(&p_82xx_addr_filt->paddr[paddr_num].h, 0xffff);
521 out_be16(&p_82xx_addr_filt->paddr[paddr_num].m, 0xffff);
522 out_be16(&p_82xx_addr_filt->paddr[paddr_num].l, 0xffff);
527 static void hw_add_addr_in_hash(struct ucc_geth_private *ugeth,
530 struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
534 (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
538 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
540 /* Ethernet frames are defined in Little Endian mode,
541 therefor to insert */
542 /* the address to the hash (Big Endian mode), we reverse the bytes.*/
544 set_mac_addr(&p_82xx_addr_filt->taddr.h, p_enet_addr);
546 qe_issue_cmd(QE_SET_GROUP_ADDRESS, cecr_subblock,
547 QE_CR_PROTOCOL_ETHERNET, 0);
550 #ifdef CONFIG_UGETH_MAGIC_PACKET
551 static void magic_packet_detection_enable(struct ucc_geth_private *ugeth)
553 struct ucc_fast_private *uccf;
554 struct ucc_geth *ug_regs;
558 ug_regs = ugeth->ug_regs;
560 /* Enable interrupts for magic packet detection */
561 uccm = in_be32(uccf->p_uccm);
563 out_be32(uccf->p_uccm, uccm);
565 /* Enable magic packet detection */
566 maccfg2 = in_be32(&ug_regs->maccfg2);
567 maccfg2 |= MACCFG2_MPE;
568 out_be32(&ug_regs->maccfg2, maccfg2);
571 static void magic_packet_detection_disable(struct ucc_geth_private *ugeth)
573 struct ucc_fast_private *uccf;
574 struct ucc_geth *ug_regs;
578 ug_regs = ugeth->ug_regs;
580 /* Disable interrupts for magic packet detection */
581 uccm = in_be32(uccf->p_uccm);
583 out_be32(uccf->p_uccm, uccm);
585 /* Disable magic packet detection */
586 maccfg2 = in_be32(&ug_regs->maccfg2);
587 maccfg2 &= ~MACCFG2_MPE;
588 out_be32(&ug_regs->maccfg2, maccfg2);
590 #endif /* MAGIC_PACKET */
592 static inline int compare_addr(u8 **addr1, u8 **addr2)
594 return memcmp(addr1, addr2, ENET_NUM_OCTETS_PER_ADDRESS);
598 static void get_statistics(struct ucc_geth_private *ugeth,
599 struct ucc_geth_tx_firmware_statistics *
600 tx_firmware_statistics,
601 struct ucc_geth_rx_firmware_statistics *
602 rx_firmware_statistics,
603 struct ucc_geth_hardware_statistics *hardware_statistics)
605 struct ucc_fast *uf_regs;
606 struct ucc_geth *ug_regs;
607 struct ucc_geth_tx_firmware_statistics_pram *p_tx_fw_statistics_pram;
608 struct ucc_geth_rx_firmware_statistics_pram *p_rx_fw_statistics_pram;
610 ug_regs = ugeth->ug_regs;
611 uf_regs = (struct ucc_fast *) ug_regs;
612 p_tx_fw_statistics_pram = ugeth->p_tx_fw_statistics_pram;
613 p_rx_fw_statistics_pram = ugeth->p_rx_fw_statistics_pram;
615 /* Tx firmware only if user handed pointer and driver actually
616 gathers Tx firmware statistics */
617 if (tx_firmware_statistics && p_tx_fw_statistics_pram) {
618 tx_firmware_statistics->sicoltx =
619 in_be32(&p_tx_fw_statistics_pram->sicoltx);
620 tx_firmware_statistics->mulcoltx =
621 in_be32(&p_tx_fw_statistics_pram->mulcoltx);
622 tx_firmware_statistics->latecoltxfr =
623 in_be32(&p_tx_fw_statistics_pram->latecoltxfr);
624 tx_firmware_statistics->frabortduecol =
625 in_be32(&p_tx_fw_statistics_pram->frabortduecol);
626 tx_firmware_statistics->frlostinmactxer =
627 in_be32(&p_tx_fw_statistics_pram->frlostinmactxer);
628 tx_firmware_statistics->carriersenseertx =
629 in_be32(&p_tx_fw_statistics_pram->carriersenseertx);
630 tx_firmware_statistics->frtxok =
631 in_be32(&p_tx_fw_statistics_pram->frtxok);
632 tx_firmware_statistics->txfrexcessivedefer =
633 in_be32(&p_tx_fw_statistics_pram->txfrexcessivedefer);
634 tx_firmware_statistics->txpkts256 =
635 in_be32(&p_tx_fw_statistics_pram->txpkts256);
636 tx_firmware_statistics->txpkts512 =
637 in_be32(&p_tx_fw_statistics_pram->txpkts512);
638 tx_firmware_statistics->txpkts1024 =
639 in_be32(&p_tx_fw_statistics_pram->txpkts1024);
640 tx_firmware_statistics->txpktsjumbo =
641 in_be32(&p_tx_fw_statistics_pram->txpktsjumbo);
644 /* Rx firmware only if user handed pointer and driver actually
645 * gathers Rx firmware statistics */
646 if (rx_firmware_statistics && p_rx_fw_statistics_pram) {
648 rx_firmware_statistics->frrxfcser =
649 in_be32(&p_rx_fw_statistics_pram->frrxfcser);
650 rx_firmware_statistics->fraligner =
651 in_be32(&p_rx_fw_statistics_pram->fraligner);
652 rx_firmware_statistics->inrangelenrxer =
653 in_be32(&p_rx_fw_statistics_pram->inrangelenrxer);
654 rx_firmware_statistics->outrangelenrxer =
655 in_be32(&p_rx_fw_statistics_pram->outrangelenrxer);
656 rx_firmware_statistics->frtoolong =
657 in_be32(&p_rx_fw_statistics_pram->frtoolong);
658 rx_firmware_statistics->runt =
659 in_be32(&p_rx_fw_statistics_pram->runt);
660 rx_firmware_statistics->verylongevent =
661 in_be32(&p_rx_fw_statistics_pram->verylongevent);
662 rx_firmware_statistics->symbolerror =
663 in_be32(&p_rx_fw_statistics_pram->symbolerror);
664 rx_firmware_statistics->dropbsy =
665 in_be32(&p_rx_fw_statistics_pram->dropbsy);
666 for (i = 0; i < 0x8; i++)
667 rx_firmware_statistics->res0[i] =
668 p_rx_fw_statistics_pram->res0[i];
669 rx_firmware_statistics->mismatchdrop =
670 in_be32(&p_rx_fw_statistics_pram->mismatchdrop);
671 rx_firmware_statistics->underpkts =
672 in_be32(&p_rx_fw_statistics_pram->underpkts);
673 rx_firmware_statistics->pkts256 =
674 in_be32(&p_rx_fw_statistics_pram->pkts256);
675 rx_firmware_statistics->pkts512 =
676 in_be32(&p_rx_fw_statistics_pram->pkts512);
677 rx_firmware_statistics->pkts1024 =
678 in_be32(&p_rx_fw_statistics_pram->pkts1024);
679 rx_firmware_statistics->pktsjumbo =
680 in_be32(&p_rx_fw_statistics_pram->pktsjumbo);
681 rx_firmware_statistics->frlossinmacer =
682 in_be32(&p_rx_fw_statistics_pram->frlossinmacer);
683 rx_firmware_statistics->pausefr =
684 in_be32(&p_rx_fw_statistics_pram->pausefr);
685 for (i = 0; i < 0x4; i++)
686 rx_firmware_statistics->res1[i] =
687 p_rx_fw_statistics_pram->res1[i];
688 rx_firmware_statistics->removevlan =
689 in_be32(&p_rx_fw_statistics_pram->removevlan);
690 rx_firmware_statistics->replacevlan =
691 in_be32(&p_rx_fw_statistics_pram->replacevlan);
692 rx_firmware_statistics->insertvlan =
693 in_be32(&p_rx_fw_statistics_pram->insertvlan);
696 /* Hardware only if user handed pointer and driver actually
697 gathers hardware statistics */
698 if (hardware_statistics && (in_be32(&uf_regs->upsmr) & UPSMR_HSE)) {
699 hardware_statistics->tx64 = in_be32(&ug_regs->tx64);
700 hardware_statistics->tx127 = in_be32(&ug_regs->tx127);
701 hardware_statistics->tx255 = in_be32(&ug_regs->tx255);
702 hardware_statistics->rx64 = in_be32(&ug_regs->rx64);
703 hardware_statistics->rx127 = in_be32(&ug_regs->rx127);
704 hardware_statistics->rx255 = in_be32(&ug_regs->rx255);
705 hardware_statistics->txok = in_be32(&ug_regs->txok);
706 hardware_statistics->txcf = in_be16(&ug_regs->txcf);
707 hardware_statistics->tmca = in_be32(&ug_regs->tmca);
708 hardware_statistics->tbca = in_be32(&ug_regs->tbca);
709 hardware_statistics->rxfok = in_be32(&ug_regs->rxfok);
710 hardware_statistics->rxbok = in_be32(&ug_regs->rxbok);
711 hardware_statistics->rbyt = in_be32(&ug_regs->rbyt);
712 hardware_statistics->rmca = in_be32(&ug_regs->rmca);
713 hardware_statistics->rbca = in_be32(&ug_regs->rbca);
717 static void dump_bds(struct ucc_geth_private *ugeth)
722 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
723 if (ugeth->p_tx_bd_ring[i]) {
725 (ugeth->ug_info->bdRingLenTx[i] *
726 sizeof(struct qe_bd));
727 ugeth_info("TX BDs[%d]", i);
728 mem_disp(ugeth->p_tx_bd_ring[i], length);
731 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
732 if (ugeth->p_rx_bd_ring[i]) {
734 (ugeth->ug_info->bdRingLenRx[i] *
735 sizeof(struct qe_bd));
736 ugeth_info("RX BDs[%d]", i);
737 mem_disp(ugeth->p_rx_bd_ring[i], length);
742 static void dump_regs(struct ucc_geth_private *ugeth)
746 ugeth_info("UCC%d Geth registers:", ugeth->ug_info->uf_info.ucc_num);
747 ugeth_info("Base address: 0x%08x", (u32) ugeth->ug_regs);
749 ugeth_info("maccfg1 : addr - 0x%08x, val - 0x%08x",
750 (u32) & ugeth->ug_regs->maccfg1,
751 in_be32(&ugeth->ug_regs->maccfg1));
752 ugeth_info("maccfg2 : addr - 0x%08x, val - 0x%08x",
753 (u32) & ugeth->ug_regs->maccfg2,
754 in_be32(&ugeth->ug_regs->maccfg2));
755 ugeth_info("ipgifg : addr - 0x%08x, val - 0x%08x",
756 (u32) & ugeth->ug_regs->ipgifg,
757 in_be32(&ugeth->ug_regs->ipgifg));
758 ugeth_info("hafdup : addr - 0x%08x, val - 0x%08x",
759 (u32) & ugeth->ug_regs->hafdup,
760 in_be32(&ugeth->ug_regs->hafdup));
761 ugeth_info("miimcfg : addr - 0x%08x, val - 0x%08x",
762 (u32) & ugeth->ug_regs->miimng.miimcfg,
763 in_be32(&ugeth->ug_regs->miimng.miimcfg));
764 ugeth_info("miimcom : addr - 0x%08x, val - 0x%08x",
765 (u32) & ugeth->ug_regs->miimng.miimcom,
766 in_be32(&ugeth->ug_regs->miimng.miimcom));
767 ugeth_info("miimadd : addr - 0x%08x, val - 0x%08x",
768 (u32) & ugeth->ug_regs->miimng.miimadd,
769 in_be32(&ugeth->ug_regs->miimng.miimadd));
770 ugeth_info("miimcon : addr - 0x%08x, val - 0x%08x",
771 (u32) & ugeth->ug_regs->miimng.miimcon,
772 in_be32(&ugeth->ug_regs->miimng.miimcon));
773 ugeth_info("miimstat : addr - 0x%08x, val - 0x%08x",
774 (u32) & ugeth->ug_regs->miimng.miimstat,
775 in_be32(&ugeth->ug_regs->miimng.miimstat));
776 ugeth_info("miimmind : addr - 0x%08x, val - 0x%08x",
777 (u32) & ugeth->ug_regs->miimng.miimind,
778 in_be32(&ugeth->ug_regs->miimng.miimind));
779 ugeth_info("ifctl : addr - 0x%08x, val - 0x%08x",
780 (u32) & ugeth->ug_regs->ifctl,
781 in_be32(&ugeth->ug_regs->ifctl));
782 ugeth_info("ifstat : addr - 0x%08x, val - 0x%08x",
783 (u32) & ugeth->ug_regs->ifstat,
784 in_be32(&ugeth->ug_regs->ifstat));
785 ugeth_info("macstnaddr1: addr - 0x%08x, val - 0x%08x",
786 (u32) & ugeth->ug_regs->macstnaddr1,
787 in_be32(&ugeth->ug_regs->macstnaddr1));
788 ugeth_info("macstnaddr2: addr - 0x%08x, val - 0x%08x",
789 (u32) & ugeth->ug_regs->macstnaddr2,
790 in_be32(&ugeth->ug_regs->macstnaddr2));
791 ugeth_info("uempr : addr - 0x%08x, val - 0x%08x",
792 (u32) & ugeth->ug_regs->uempr,
793 in_be32(&ugeth->ug_regs->uempr));
794 ugeth_info("utbipar : addr - 0x%08x, val - 0x%08x",
795 (u32) & ugeth->ug_regs->utbipar,
796 in_be32(&ugeth->ug_regs->utbipar));
797 ugeth_info("uescr : addr - 0x%08x, val - 0x%04x",
798 (u32) & ugeth->ug_regs->uescr,
799 in_be16(&ugeth->ug_regs->uescr));
800 ugeth_info("tx64 : addr - 0x%08x, val - 0x%08x",
801 (u32) & ugeth->ug_regs->tx64,
802 in_be32(&ugeth->ug_regs->tx64));
803 ugeth_info("tx127 : addr - 0x%08x, val - 0x%08x",
804 (u32) & ugeth->ug_regs->tx127,
805 in_be32(&ugeth->ug_regs->tx127));
806 ugeth_info("tx255 : addr - 0x%08x, val - 0x%08x",
807 (u32) & ugeth->ug_regs->tx255,
808 in_be32(&ugeth->ug_regs->tx255));
809 ugeth_info("rx64 : addr - 0x%08x, val - 0x%08x",
810 (u32) & ugeth->ug_regs->rx64,
811 in_be32(&ugeth->ug_regs->rx64));
812 ugeth_info("rx127 : addr - 0x%08x, val - 0x%08x",
813 (u32) & ugeth->ug_regs->rx127,
814 in_be32(&ugeth->ug_regs->rx127));
815 ugeth_info("rx255 : addr - 0x%08x, val - 0x%08x",
816 (u32) & ugeth->ug_regs->rx255,
817 in_be32(&ugeth->ug_regs->rx255));
818 ugeth_info("txok : addr - 0x%08x, val - 0x%08x",
819 (u32) & ugeth->ug_regs->txok,
820 in_be32(&ugeth->ug_regs->txok));
821 ugeth_info("txcf : addr - 0x%08x, val - 0x%04x",
822 (u32) & ugeth->ug_regs->txcf,
823 in_be16(&ugeth->ug_regs->txcf));
824 ugeth_info("tmca : addr - 0x%08x, val - 0x%08x",
825 (u32) & ugeth->ug_regs->tmca,
826 in_be32(&ugeth->ug_regs->tmca));
827 ugeth_info("tbca : addr - 0x%08x, val - 0x%08x",
828 (u32) & ugeth->ug_regs->tbca,
829 in_be32(&ugeth->ug_regs->tbca));
830 ugeth_info("rxfok : addr - 0x%08x, val - 0x%08x",
831 (u32) & ugeth->ug_regs->rxfok,
832 in_be32(&ugeth->ug_regs->rxfok));
833 ugeth_info("rxbok : addr - 0x%08x, val - 0x%08x",
834 (u32) & ugeth->ug_regs->rxbok,
835 in_be32(&ugeth->ug_regs->rxbok));
836 ugeth_info("rbyt : addr - 0x%08x, val - 0x%08x",
837 (u32) & ugeth->ug_regs->rbyt,
838 in_be32(&ugeth->ug_regs->rbyt));
839 ugeth_info("rmca : addr - 0x%08x, val - 0x%08x",
840 (u32) & ugeth->ug_regs->rmca,
841 in_be32(&ugeth->ug_regs->rmca));
842 ugeth_info("rbca : addr - 0x%08x, val - 0x%08x",
843 (u32) & ugeth->ug_regs->rbca,
844 in_be32(&ugeth->ug_regs->rbca));
845 ugeth_info("scar : addr - 0x%08x, val - 0x%08x",
846 (u32) & ugeth->ug_regs->scar,
847 in_be32(&ugeth->ug_regs->scar));
848 ugeth_info("scam : addr - 0x%08x, val - 0x%08x",
849 (u32) & ugeth->ug_regs->scam,
850 in_be32(&ugeth->ug_regs->scam));
852 if (ugeth->p_thread_data_tx) {
853 int numThreadsTxNumerical;
854 switch (ugeth->ug_info->numThreadsTx) {
855 case UCC_GETH_NUM_OF_THREADS_1:
856 numThreadsTxNumerical = 1;
858 case UCC_GETH_NUM_OF_THREADS_2:
859 numThreadsTxNumerical = 2;
861 case UCC_GETH_NUM_OF_THREADS_4:
862 numThreadsTxNumerical = 4;
864 case UCC_GETH_NUM_OF_THREADS_6:
865 numThreadsTxNumerical = 6;
867 case UCC_GETH_NUM_OF_THREADS_8:
868 numThreadsTxNumerical = 8;
871 numThreadsTxNumerical = 0;
875 ugeth_info("Thread data TXs:");
876 ugeth_info("Base address: 0x%08x",
877 (u32) ugeth->p_thread_data_tx);
878 for (i = 0; i < numThreadsTxNumerical; i++) {
879 ugeth_info("Thread data TX[%d]:", i);
880 ugeth_info("Base address: 0x%08x",
881 (u32) & ugeth->p_thread_data_tx[i]);
882 mem_disp((u8 *) & ugeth->p_thread_data_tx[i],
883 sizeof(struct ucc_geth_thread_data_tx));
886 if (ugeth->p_thread_data_rx) {
887 int numThreadsRxNumerical;
888 switch (ugeth->ug_info->numThreadsRx) {
889 case UCC_GETH_NUM_OF_THREADS_1:
890 numThreadsRxNumerical = 1;
892 case UCC_GETH_NUM_OF_THREADS_2:
893 numThreadsRxNumerical = 2;
895 case UCC_GETH_NUM_OF_THREADS_4:
896 numThreadsRxNumerical = 4;
898 case UCC_GETH_NUM_OF_THREADS_6:
899 numThreadsRxNumerical = 6;
901 case UCC_GETH_NUM_OF_THREADS_8:
902 numThreadsRxNumerical = 8;
905 numThreadsRxNumerical = 0;
909 ugeth_info("Thread data RX:");
910 ugeth_info("Base address: 0x%08x",
911 (u32) ugeth->p_thread_data_rx);
912 for (i = 0; i < numThreadsRxNumerical; i++) {
913 ugeth_info("Thread data RX[%d]:", i);
914 ugeth_info("Base address: 0x%08x",
915 (u32) & ugeth->p_thread_data_rx[i]);
916 mem_disp((u8 *) & ugeth->p_thread_data_rx[i],
917 sizeof(struct ucc_geth_thread_data_rx));
920 if (ugeth->p_exf_glbl_param) {
921 ugeth_info("EXF global param:");
922 ugeth_info("Base address: 0x%08x",
923 (u32) ugeth->p_exf_glbl_param);
924 mem_disp((u8 *) ugeth->p_exf_glbl_param,
925 sizeof(*ugeth->p_exf_glbl_param));
927 if (ugeth->p_tx_glbl_pram) {
928 ugeth_info("TX global param:");
929 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_tx_glbl_pram);
930 ugeth_info("temoder : addr - 0x%08x, val - 0x%04x",
931 (u32) & ugeth->p_tx_glbl_pram->temoder,
932 in_be16(&ugeth->p_tx_glbl_pram->temoder));
933 ugeth_info("sqptr : addr - 0x%08x, val - 0x%08x",
934 (u32) & ugeth->p_tx_glbl_pram->sqptr,
935 in_be32(&ugeth->p_tx_glbl_pram->sqptr));
936 ugeth_info("schedulerbasepointer: addr - 0x%08x, val - 0x%08x",
937 (u32) & ugeth->p_tx_glbl_pram->schedulerbasepointer,
938 in_be32(&ugeth->p_tx_glbl_pram->
939 schedulerbasepointer));
940 ugeth_info("txrmonbaseptr: addr - 0x%08x, val - 0x%08x",
941 (u32) & ugeth->p_tx_glbl_pram->txrmonbaseptr,
942 in_be32(&ugeth->p_tx_glbl_pram->txrmonbaseptr));
943 ugeth_info("tstate : addr - 0x%08x, val - 0x%08x",
944 (u32) & ugeth->p_tx_glbl_pram->tstate,
945 in_be32(&ugeth->p_tx_glbl_pram->tstate));
946 ugeth_info("iphoffset[0] : addr - 0x%08x, val - 0x%02x",
947 (u32) & ugeth->p_tx_glbl_pram->iphoffset[0],
948 ugeth->p_tx_glbl_pram->iphoffset[0]);
949 ugeth_info("iphoffset[1] : addr - 0x%08x, val - 0x%02x",
950 (u32) & ugeth->p_tx_glbl_pram->iphoffset[1],
951 ugeth->p_tx_glbl_pram->iphoffset[1]);
952 ugeth_info("iphoffset[2] : addr - 0x%08x, val - 0x%02x",
953 (u32) & ugeth->p_tx_glbl_pram->iphoffset[2],
954 ugeth->p_tx_glbl_pram->iphoffset[2]);
955 ugeth_info("iphoffset[3] : addr - 0x%08x, val - 0x%02x",
956 (u32) & ugeth->p_tx_glbl_pram->iphoffset[3],
957 ugeth->p_tx_glbl_pram->iphoffset[3]);
958 ugeth_info("iphoffset[4] : addr - 0x%08x, val - 0x%02x",
959 (u32) & ugeth->p_tx_glbl_pram->iphoffset[4],
960 ugeth->p_tx_glbl_pram->iphoffset[4]);
961 ugeth_info("iphoffset[5] : addr - 0x%08x, val - 0x%02x",
962 (u32) & ugeth->p_tx_glbl_pram->iphoffset[5],
963 ugeth->p_tx_glbl_pram->iphoffset[5]);
964 ugeth_info("iphoffset[6] : addr - 0x%08x, val - 0x%02x",
965 (u32) & ugeth->p_tx_glbl_pram->iphoffset[6],
966 ugeth->p_tx_glbl_pram->iphoffset[6]);
967 ugeth_info("iphoffset[7] : addr - 0x%08x, val - 0x%02x",
968 (u32) & ugeth->p_tx_glbl_pram->iphoffset[7],
969 ugeth->p_tx_glbl_pram->iphoffset[7]);
970 ugeth_info("vtagtable[0] : addr - 0x%08x, val - 0x%08x",
971 (u32) & ugeth->p_tx_glbl_pram->vtagtable[0],
972 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[0]));
973 ugeth_info("vtagtable[1] : addr - 0x%08x, val - 0x%08x",
974 (u32) & ugeth->p_tx_glbl_pram->vtagtable[1],
975 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[1]));
976 ugeth_info("vtagtable[2] : addr - 0x%08x, val - 0x%08x",
977 (u32) & ugeth->p_tx_glbl_pram->vtagtable[2],
978 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[2]));
979 ugeth_info("vtagtable[3] : addr - 0x%08x, val - 0x%08x",
980 (u32) & ugeth->p_tx_glbl_pram->vtagtable[3],
981 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[3]));
982 ugeth_info("vtagtable[4] : addr - 0x%08x, val - 0x%08x",
983 (u32) & ugeth->p_tx_glbl_pram->vtagtable[4],
984 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[4]));
985 ugeth_info("vtagtable[5] : addr - 0x%08x, val - 0x%08x",
986 (u32) & ugeth->p_tx_glbl_pram->vtagtable[5],
987 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[5]));
988 ugeth_info("vtagtable[6] : addr - 0x%08x, val - 0x%08x",
989 (u32) & ugeth->p_tx_glbl_pram->vtagtable[6],
990 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[6]));
991 ugeth_info("vtagtable[7] : addr - 0x%08x, val - 0x%08x",
992 (u32) & ugeth->p_tx_glbl_pram->vtagtable[7],
993 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[7]));
994 ugeth_info("tqptr : addr - 0x%08x, val - 0x%08x",
995 (u32) & ugeth->p_tx_glbl_pram->tqptr,
996 in_be32(&ugeth->p_tx_glbl_pram->tqptr));
998 if (ugeth->p_rx_glbl_pram) {
999 ugeth_info("RX global param:");
1000 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_glbl_pram);
1001 ugeth_info("remoder : addr - 0x%08x, val - 0x%08x",
1002 (u32) & ugeth->p_rx_glbl_pram->remoder,
1003 in_be32(&ugeth->p_rx_glbl_pram->remoder));
1004 ugeth_info("rqptr : addr - 0x%08x, val - 0x%08x",
1005 (u32) & ugeth->p_rx_glbl_pram->rqptr,
1006 in_be32(&ugeth->p_rx_glbl_pram->rqptr));
1007 ugeth_info("typeorlen : addr - 0x%08x, val - 0x%04x",
1008 (u32) & ugeth->p_rx_glbl_pram->typeorlen,
1009 in_be16(&ugeth->p_rx_glbl_pram->typeorlen));
1010 ugeth_info("rxgstpack : addr - 0x%08x, val - 0x%02x",
1011 (u32) & ugeth->p_rx_glbl_pram->rxgstpack,
1012 ugeth->p_rx_glbl_pram->rxgstpack);
1013 ugeth_info("rxrmonbaseptr : addr - 0x%08x, val - 0x%08x",
1014 (u32) & ugeth->p_rx_glbl_pram->rxrmonbaseptr,
1015 in_be32(&ugeth->p_rx_glbl_pram->rxrmonbaseptr));
1016 ugeth_info("intcoalescingptr: addr - 0x%08x, val - 0x%08x",
1017 (u32) & ugeth->p_rx_glbl_pram->intcoalescingptr,
1018 in_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr));
1019 ugeth_info("rstate : addr - 0x%08x, val - 0x%02x",
1020 (u32) & ugeth->p_rx_glbl_pram->rstate,
1021 ugeth->p_rx_glbl_pram->rstate);
1022 ugeth_info("mrblr : addr - 0x%08x, val - 0x%04x",
1023 (u32) & ugeth->p_rx_glbl_pram->mrblr,
1024 in_be16(&ugeth->p_rx_glbl_pram->mrblr));
1025 ugeth_info("rbdqptr : addr - 0x%08x, val - 0x%08x",
1026 (u32) & ugeth->p_rx_glbl_pram->rbdqptr,
1027 in_be32(&ugeth->p_rx_glbl_pram->rbdqptr));
1028 ugeth_info("mflr : addr - 0x%08x, val - 0x%04x",
1029 (u32) & ugeth->p_rx_glbl_pram->mflr,
1030 in_be16(&ugeth->p_rx_glbl_pram->mflr));
1031 ugeth_info("minflr : addr - 0x%08x, val - 0x%04x",
1032 (u32) & ugeth->p_rx_glbl_pram->minflr,
1033 in_be16(&ugeth->p_rx_glbl_pram->minflr));
1034 ugeth_info("maxd1 : addr - 0x%08x, val - 0x%04x",
1035 (u32) & ugeth->p_rx_glbl_pram->maxd1,
1036 in_be16(&ugeth->p_rx_glbl_pram->maxd1));
1037 ugeth_info("maxd2 : addr - 0x%08x, val - 0x%04x",
1038 (u32) & ugeth->p_rx_glbl_pram->maxd2,
1039 in_be16(&ugeth->p_rx_glbl_pram->maxd2));
1040 ugeth_info("ecamptr : addr - 0x%08x, val - 0x%08x",
1041 (u32) & ugeth->p_rx_glbl_pram->ecamptr,
1042 in_be32(&ugeth->p_rx_glbl_pram->ecamptr));
1043 ugeth_info("l2qt : addr - 0x%08x, val - 0x%08x",
1044 (u32) & ugeth->p_rx_glbl_pram->l2qt,
1045 in_be32(&ugeth->p_rx_glbl_pram->l2qt));
1046 ugeth_info("l3qt[0] : addr - 0x%08x, val - 0x%08x",
1047 (u32) & ugeth->p_rx_glbl_pram->l3qt[0],
1048 in_be32(&ugeth->p_rx_glbl_pram->l3qt[0]));
1049 ugeth_info("l3qt[1] : addr - 0x%08x, val - 0x%08x",
1050 (u32) & ugeth->p_rx_glbl_pram->l3qt[1],
1051 in_be32(&ugeth->p_rx_glbl_pram->l3qt[1]));
1052 ugeth_info("l3qt[2] : addr - 0x%08x, val - 0x%08x",
1053 (u32) & ugeth->p_rx_glbl_pram->l3qt[2],
1054 in_be32(&ugeth->p_rx_glbl_pram->l3qt[2]));
1055 ugeth_info("l3qt[3] : addr - 0x%08x, val - 0x%08x",
1056 (u32) & ugeth->p_rx_glbl_pram->l3qt[3],
1057 in_be32(&ugeth->p_rx_glbl_pram->l3qt[3]));
1058 ugeth_info("l3qt[4] : addr - 0x%08x, val - 0x%08x",
1059 (u32) & ugeth->p_rx_glbl_pram->l3qt[4],
1060 in_be32(&ugeth->p_rx_glbl_pram->l3qt[4]));
1061 ugeth_info("l3qt[5] : addr - 0x%08x, val - 0x%08x",
1062 (u32) & ugeth->p_rx_glbl_pram->l3qt[5],
1063 in_be32(&ugeth->p_rx_glbl_pram->l3qt[5]));
1064 ugeth_info("l3qt[6] : addr - 0x%08x, val - 0x%08x",
1065 (u32) & ugeth->p_rx_glbl_pram->l3qt[6],
1066 in_be32(&ugeth->p_rx_glbl_pram->l3qt[6]));
1067 ugeth_info("l3qt[7] : addr - 0x%08x, val - 0x%08x",
1068 (u32) & ugeth->p_rx_glbl_pram->l3qt[7],
1069 in_be32(&ugeth->p_rx_glbl_pram->l3qt[7]));
1070 ugeth_info("vlantype : addr - 0x%08x, val - 0x%04x",
1071 (u32) & ugeth->p_rx_glbl_pram->vlantype,
1072 in_be16(&ugeth->p_rx_glbl_pram->vlantype));
1073 ugeth_info("vlantci : addr - 0x%08x, val - 0x%04x",
1074 (u32) & ugeth->p_rx_glbl_pram->vlantci,
1075 in_be16(&ugeth->p_rx_glbl_pram->vlantci));
1076 for (i = 0; i < 64; i++)
1078 ("addressfiltering[%d]: addr - 0x%08x, val - 0x%02x",
1080 (u32) & ugeth->p_rx_glbl_pram->addressfiltering[i],
1081 ugeth->p_rx_glbl_pram->addressfiltering[i]);
1082 ugeth_info("exfGlobalParam : addr - 0x%08x, val - 0x%08x",
1083 (u32) & ugeth->p_rx_glbl_pram->exfGlobalParam,
1084 in_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam));
1086 if (ugeth->p_send_q_mem_reg) {
1087 ugeth_info("Send Q memory registers:");
1088 ugeth_info("Base address: 0x%08x",
1089 (u32) ugeth->p_send_q_mem_reg);
1090 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
1091 ugeth_info("SQQD[%d]:", i);
1092 ugeth_info("Base address: 0x%08x",
1093 (u32) & ugeth->p_send_q_mem_reg->sqqd[i]);
1094 mem_disp((u8 *) & ugeth->p_send_q_mem_reg->sqqd[i],
1095 sizeof(struct ucc_geth_send_queue_qd));
1098 if (ugeth->p_scheduler) {
1099 ugeth_info("Scheduler:");
1100 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_scheduler);
1101 mem_disp((u8 *) ugeth->p_scheduler,
1102 sizeof(*ugeth->p_scheduler));
1104 if (ugeth->p_tx_fw_statistics_pram) {
1105 ugeth_info("TX FW statistics pram:");
1106 ugeth_info("Base address: 0x%08x",
1107 (u32) ugeth->p_tx_fw_statistics_pram);
1108 mem_disp((u8 *) ugeth->p_tx_fw_statistics_pram,
1109 sizeof(*ugeth->p_tx_fw_statistics_pram));
1111 if (ugeth->p_rx_fw_statistics_pram) {
1112 ugeth_info("RX FW statistics pram:");
1113 ugeth_info("Base address: 0x%08x",
1114 (u32) ugeth->p_rx_fw_statistics_pram);
1115 mem_disp((u8 *) ugeth->p_rx_fw_statistics_pram,
1116 sizeof(*ugeth->p_rx_fw_statistics_pram));
1118 if (ugeth->p_rx_irq_coalescing_tbl) {
1119 ugeth_info("RX IRQ coalescing tables:");
1120 ugeth_info("Base address: 0x%08x",
1121 (u32) ugeth->p_rx_irq_coalescing_tbl);
1122 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
1123 ugeth_info("RX IRQ coalescing table entry[%d]:", i);
1124 ugeth_info("Base address: 0x%08x",
1125 (u32) & ugeth->p_rx_irq_coalescing_tbl->
1126 coalescingentry[i]);
1128 ("interruptcoalescingmaxvalue: addr - 0x%08x, val - 0x%08x",
1129 (u32) & ugeth->p_rx_irq_coalescing_tbl->
1130 coalescingentry[i].interruptcoalescingmaxvalue,
1131 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
1133 interruptcoalescingmaxvalue));
1135 ("interruptcoalescingcounter : addr - 0x%08x, val - 0x%08x",
1136 (u32) & ugeth->p_rx_irq_coalescing_tbl->
1137 coalescingentry[i].interruptcoalescingcounter,
1138 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
1140 interruptcoalescingcounter));
1143 if (ugeth->p_rx_bd_qs_tbl) {
1144 ugeth_info("RX BD QS tables:");
1145 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_bd_qs_tbl);
1146 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
1147 ugeth_info("RX BD QS table[%d]:", i);
1148 ugeth_info("Base address: 0x%08x",
1149 (u32) & ugeth->p_rx_bd_qs_tbl[i]);
1151 ("bdbaseptr : addr - 0x%08x, val - 0x%08x",
1152 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdbaseptr,
1153 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdbaseptr));
1155 ("bdptr : addr - 0x%08x, val - 0x%08x",
1156 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdptr,
1157 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdptr));
1159 ("externalbdbaseptr: addr - 0x%08x, val - 0x%08x",
1160 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
1161 in_be32(&ugeth->p_rx_bd_qs_tbl[i].
1162 externalbdbaseptr));
1164 ("externalbdptr : addr - 0x%08x, val - 0x%08x",
1165 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdptr,
1166 in_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdptr));
1167 ugeth_info("ucode RX Prefetched BDs:");
1168 ugeth_info("Base address: 0x%08x",
1170 qe_muram_addr(in_be32
1171 (&ugeth->p_rx_bd_qs_tbl[i].
1174 qe_muram_addr(in_be32
1175 (&ugeth->p_rx_bd_qs_tbl[i].
1177 sizeof(struct ucc_geth_rx_prefetched_bds));
1180 if (ugeth->p_init_enet_param_shadow) {
1182 ugeth_info("Init enet param shadow:");
1183 ugeth_info("Base address: 0x%08x",
1184 (u32) ugeth->p_init_enet_param_shadow);
1185 mem_disp((u8 *) ugeth->p_init_enet_param_shadow,
1186 sizeof(*ugeth->p_init_enet_param_shadow));
1188 size = sizeof(struct ucc_geth_thread_rx_pram);
1189 if (ugeth->ug_info->rxExtendedFiltering) {
1191 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
1192 if (ugeth->ug_info->largestexternallookupkeysize ==
1193 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
1195 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
1196 if (ugeth->ug_info->largestexternallookupkeysize ==
1197 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
1199 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
1202 dump_init_enet_entries(ugeth,
1203 &(ugeth->p_init_enet_param_shadow->
1205 ENET_INIT_PARAM_MAX_ENTRIES_TX,
1206 sizeof(struct ucc_geth_thread_tx_pram),
1207 ugeth->ug_info->riscTx, 0);
1208 dump_init_enet_entries(ugeth,
1209 &(ugeth->p_init_enet_param_shadow->
1211 ENET_INIT_PARAM_MAX_ENTRIES_RX, size,
1212 ugeth->ug_info->riscRx, 1);
1217 static void init_default_reg_vals(volatile u32 *upsmr_register,
1218 volatile u32 *maccfg1_register,
1219 volatile u32 *maccfg2_register)
1221 out_be32(upsmr_register, UCC_GETH_UPSMR_INIT);
1222 out_be32(maccfg1_register, UCC_GETH_MACCFG1_INIT);
1223 out_be32(maccfg2_register, UCC_GETH_MACCFG2_INIT);
1226 static int init_half_duplex_params(int alt_beb,
1227 int back_pressure_no_backoff,
1230 u8 alt_beb_truncation,
1231 u8 max_retransmissions,
1232 u8 collision_window,
1233 volatile u32 *hafdup_register)
1237 if ((alt_beb_truncation > HALFDUP_ALT_BEB_TRUNCATION_MAX) ||
1238 (max_retransmissions > HALFDUP_MAX_RETRANSMISSION_MAX) ||
1239 (collision_window > HALFDUP_COLLISION_WINDOW_MAX))
1242 value = (u32) (alt_beb_truncation << HALFDUP_ALT_BEB_TRUNCATION_SHIFT);
1245 value |= HALFDUP_ALT_BEB;
1246 if (back_pressure_no_backoff)
1247 value |= HALFDUP_BACK_PRESSURE_NO_BACKOFF;
1249 value |= HALFDUP_NO_BACKOFF;
1251 value |= HALFDUP_EXCESSIVE_DEFER;
1253 value |= (max_retransmissions << HALFDUP_MAX_RETRANSMISSION_SHIFT);
1255 value |= collision_window;
1257 out_be32(hafdup_register, value);
1261 static int init_inter_frame_gap_params(u8 non_btb_cs_ipg,
1265 volatile u32 *ipgifg_register)
1269 /* Non-Back-to-back IPG part 1 should be <= Non-Back-to-back
1271 if (non_btb_cs_ipg > non_btb_ipg)
1274 if ((non_btb_cs_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART1_MAX) ||
1275 (non_btb_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART2_MAX) ||
1276 /*(min_ifg > IPGIFG_MINIMUM_IFG_ENFORCEMENT_MAX) || */
1277 (btb_ipg > IPGIFG_BACK_TO_BACK_IFG_MAX))
1281 ((non_btb_cs_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART1_SHIFT) &
1282 IPGIFG_NBTB_CS_IPG_MASK);
1284 ((non_btb_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART2_SHIFT) &
1285 IPGIFG_NBTB_IPG_MASK);
1287 ((min_ifg << IPGIFG_MINIMUM_IFG_ENFORCEMENT_SHIFT) &
1288 IPGIFG_MIN_IFG_MASK);
1289 value |= (btb_ipg & IPGIFG_BTB_IPG_MASK);
1291 out_be32(ipgifg_register, value);
1295 static int init_flow_control_params(u32 automatic_flow_control_mode,
1296 int rx_flow_control_enable,
1297 int tx_flow_control_enable,
1299 u16 extension_field,
1300 volatile u32 *upsmr_register,
1301 volatile u32 *uempr_register,
1302 volatile u32 *maccfg1_register)
1306 /* Set UEMPR register */
1307 value = (u32) pause_period << UEMPR_PAUSE_TIME_VALUE_SHIFT;
1308 value |= (u32) extension_field << UEMPR_EXTENDED_PAUSE_TIME_VALUE_SHIFT;
1309 out_be32(uempr_register, value);
1311 /* Set UPSMR register */
1312 value = in_be32(upsmr_register);
1313 value |= automatic_flow_control_mode;
1314 out_be32(upsmr_register, value);
1316 value = in_be32(maccfg1_register);
1317 if (rx_flow_control_enable)
1318 value |= MACCFG1_FLOW_RX;
1319 if (tx_flow_control_enable)
1320 value |= MACCFG1_FLOW_TX;
1321 out_be32(maccfg1_register, value);
1326 static int init_hw_statistics_gathering_mode(int enable_hardware_statistics,
1327 int auto_zero_hardware_statistics,
1328 volatile u32 *upsmr_register,
1329 volatile u16 *uescr_register)
1331 u32 upsmr_value = 0;
1332 u16 uescr_value = 0;
1333 /* Enable hardware statistics gathering if requested */
1334 if (enable_hardware_statistics) {
1335 upsmr_value = in_be32(upsmr_register);
1336 upsmr_value |= UPSMR_HSE;
1337 out_be32(upsmr_register, upsmr_value);
1340 /* Clear hardware statistics counters */
1341 uescr_value = in_be16(uescr_register);
1342 uescr_value |= UESCR_CLRCNT;
1343 /* Automatically zero hardware statistics counters on read,
1345 if (auto_zero_hardware_statistics)
1346 uescr_value |= UESCR_AUTOZ;
1347 out_be16(uescr_register, uescr_value);
1352 static int init_firmware_statistics_gathering_mode(int
1353 enable_tx_firmware_statistics,
1354 int enable_rx_firmware_statistics,
1355 volatile u32 *tx_rmon_base_ptr,
1356 u32 tx_firmware_statistics_structure_address,
1357 volatile u32 *rx_rmon_base_ptr,
1358 u32 rx_firmware_statistics_structure_address,
1359 volatile u16 *temoder_register,
1360 volatile u32 *remoder_register)
1362 /* Note: this function does not check if */
1363 /* the parameters it receives are NULL */
1367 if (enable_tx_firmware_statistics) {
1368 out_be32(tx_rmon_base_ptr,
1369 tx_firmware_statistics_structure_address);
1370 temoder_value = in_be16(temoder_register);
1371 temoder_value |= TEMODER_TX_RMON_STATISTICS_ENABLE;
1372 out_be16(temoder_register, temoder_value);
1375 if (enable_rx_firmware_statistics) {
1376 out_be32(rx_rmon_base_ptr,
1377 rx_firmware_statistics_structure_address);
1378 remoder_value = in_be32(remoder_register);
1379 remoder_value |= REMODER_RX_RMON_STATISTICS_ENABLE;
1380 out_be32(remoder_register, remoder_value);
1386 static int init_mac_station_addr_regs(u8 address_byte_0,
1392 volatile u32 *macstnaddr1_register,
1393 volatile u32 *macstnaddr2_register)
1397 /* Example: for a station address of 0x12345678ABCD, */
1398 /* 0x12 is byte 0, 0x34 is byte 1 and so on and 0xCD is byte 5 */
1400 /* MACSTNADDR1 Register: */
1403 /* station address byte 5 station address byte 4 */
1405 /* station address byte 3 station address byte 2 */
1406 value |= (u32) ((address_byte_2 << 0) & 0x000000FF);
1407 value |= (u32) ((address_byte_3 << 8) & 0x0000FF00);
1408 value |= (u32) ((address_byte_4 << 16) & 0x00FF0000);
1409 value |= (u32) ((address_byte_5 << 24) & 0xFF000000);
1411 out_be32(macstnaddr1_register, value);
1413 /* MACSTNADDR2 Register: */
1416 /* station address byte 1 station address byte 0 */
1418 /* reserved reserved */
1420 value |= (u32) ((address_byte_0 << 16) & 0x00FF0000);
1421 value |= (u32) ((address_byte_1 << 24) & 0xFF000000);
1423 out_be32(macstnaddr2_register, value);
1428 static int init_mac_duplex_mode(int full_duplex,
1429 int limited_to_full_duplex,
1430 volatile u32 *maccfg2_register)
1434 /* some interfaces must work in full duplex mode */
1435 if ((full_duplex == 0) && (limited_to_full_duplex == 1))
1438 value = in_be32(maccfg2_register);
1441 value |= MACCFG2_FDX;
1443 value &= ~MACCFG2_FDX;
1445 out_be32(maccfg2_register, value);
1449 static int init_check_frame_length_mode(int length_check,
1450 volatile u32 *maccfg2_register)
1454 value = in_be32(maccfg2_register);
1457 value |= MACCFG2_LC;
1459 value &= ~MACCFG2_LC;
1461 out_be32(maccfg2_register, value);
1465 static int init_preamble_length(u8 preamble_length,
1466 volatile u32 *maccfg2_register)
1470 if ((preamble_length < 3) || (preamble_length > 7))
1473 value = in_be32(maccfg2_register);
1474 value &= ~MACCFG2_PREL_MASK;
1475 value |= (preamble_length << MACCFG2_PREL_SHIFT);
1476 out_be32(maccfg2_register, value);
1480 static int init_mii_management_configuration(int reset_mgmt,
1481 int preamble_supress,
1482 volatile u32 *miimcfg_register,
1483 volatile u32 *miimind_register)
1485 unsigned int timeout = PHY_INIT_TIMEOUT;
1488 value = in_be32(miimcfg_register);
1490 value |= MIIMCFG_RESET_MANAGEMENT;
1491 out_be32(miimcfg_register, value);
1496 if (preamble_supress)
1497 value |= MIIMCFG_NO_PREAMBLE;
1499 value |= UCC_GETH_MIIMCFG_MNGMNT_CLC_DIV_INIT;
1500 out_be32(miimcfg_register, value);
1502 /* Wait until the bus is free */
1503 while ((in_be32(miimind_register) & MIIMIND_BUSY) && timeout--)
1507 ugeth_err("%s: The MII Bus is stuck!", __FUNCTION__);
1514 static int init_rx_parameters(int reject_broadcast,
1515 int receive_short_frames,
1516 int promiscuous, volatile u32 *upsmr_register)
1520 value = in_be32(upsmr_register);
1522 if (reject_broadcast)
1525 value &= ~UPSMR_BRO;
1527 if (receive_short_frames)
1530 value &= ~UPSMR_RSH;
1535 value &= ~UPSMR_PRO;
1537 out_be32(upsmr_register, value);
1542 static int init_max_rx_buff_len(u16 max_rx_buf_len,
1543 volatile u16 *mrblr_register)
1545 /* max_rx_buf_len value must be a multiple of 128 */
1546 if ((max_rx_buf_len == 0)
1547 || (max_rx_buf_len % UCC_GETH_MRBLR_ALIGNMENT))
1550 out_be16(mrblr_register, max_rx_buf_len);
1554 static int init_min_frame_len(u16 min_frame_length,
1555 volatile u16 *minflr_register,
1556 volatile u16 *mrblr_register)
1558 u16 mrblr_value = 0;
1560 mrblr_value = in_be16(mrblr_register);
1561 if (min_frame_length >= (mrblr_value - 4))
1564 out_be16(minflr_register, min_frame_length);
1568 static int adjust_enet_interface(struct ucc_geth_private *ugeth)
1570 struct ucc_geth_info *ug_info;
1571 struct ucc_geth *ug_regs;
1572 struct ucc_fast *uf_regs;
1573 enum enet_speed speed;
1574 int ret_val, rpm = 0, tbi = 0, r10m = 0, rmm =
1575 0, limited_to_full_duplex = 0;
1576 u32 upsmr, maccfg2, utbipar, tbiBaseAddress;
1579 ugeth_vdbg("%s: IN", __FUNCTION__);
1581 ug_info = ugeth->ug_info;
1582 ug_regs = ugeth->ug_regs;
1583 uf_regs = ugeth->uccf->uf_regs;
1585 /* Analyze enet_interface according to Interface Mode Configuration
1588 get_interface_details(ug_info->enet_interface, &speed, &r10m, &rmm,
1589 &rpm, &tbi, &limited_to_full_duplex);
1592 ("%s: half duplex not supported in requested configuration.",
1598 maccfg2 = in_be32(&ug_regs->maccfg2);
1599 maccfg2 &= ~MACCFG2_INTERFACE_MODE_MASK;
1600 if ((speed == ENET_SPEED_10BT) || (speed == ENET_SPEED_100BT))
1601 maccfg2 |= MACCFG2_INTERFACE_MODE_NIBBLE;
1602 else if (speed == ENET_SPEED_1000BT)
1603 maccfg2 |= MACCFG2_INTERFACE_MODE_BYTE;
1604 maccfg2 |= ug_info->padAndCrc;
1605 out_be32(&ug_regs->maccfg2, maccfg2);
1608 upsmr = in_be32(&uf_regs->upsmr);
1609 upsmr &= ~(UPSMR_RPM | UPSMR_R10M | UPSMR_TBIM | UPSMR_RMM);
1613 upsmr |= UPSMR_R10M;
1615 upsmr |= UPSMR_TBIM;
1618 out_be32(&uf_regs->upsmr, upsmr);
1621 utbipar = in_be32(&ug_regs->utbipar);
1622 utbipar &= ~UTBIPAR_PHY_ADDRESS_MASK;
1625 (ug_info->phy_address +
1626 ugeth->ug_info->uf_info.
1627 ucc_num) << UTBIPAR_PHY_ADDRESS_SHIFT;
1631 ugeth->ug_info->uf_info.
1632 ucc_num) << UTBIPAR_PHY_ADDRESS_SHIFT;
1633 out_be32(&ug_regs->utbipar, utbipar);
1635 /* Disable autonegotiation in tbi mode, because by default it
1636 comes up in autonegotiation mode. */
1637 /* Note that this depends on proper setting in utbipar register. */
1639 tbiBaseAddress = in_be32(&ug_regs->utbipar);
1640 tbiBaseAddress &= UTBIPAR_PHY_ADDRESS_MASK;
1641 tbiBaseAddress >>= UTBIPAR_PHY_ADDRESS_SHIFT;
1643 ugeth->mii_info->mdio_read(ugeth->dev, (u8) tbiBaseAddress,
1645 value &= ~0x1000; /* Turn off autonegotiation */
1646 ugeth->mii_info->mdio_write(ugeth->dev, (u8) tbiBaseAddress,
1647 ENET_TBI_MII_CR, value);
1650 ret_val = init_mac_duplex_mode(1,
1651 limited_to_full_duplex,
1655 ("%s: half duplex not supported in requested configuration.",
1660 init_check_frame_length_mode(ug_info->lengthCheckRx, &ug_regs->maccfg2);
1662 ret_val = init_preamble_length(ug_info->prel, &ug_regs->maccfg2);
1665 ("%s: Preamble length must be between 3 and 7 inclusive.",
1673 /* Called every time the controller might need to be made
1674 * aware of new link state. The PHY code conveys this
1675 * information through variables in the ugeth structure, and this
1676 * function converts those variables into the appropriate
1677 * register values, and can bring down the device if needed.
1679 static void adjust_link(struct net_device *dev)
1681 struct ucc_geth_private *ugeth = netdev_priv(dev);
1682 struct ucc_geth *ug_regs;
1684 struct ugeth_mii_info *mii_info = ugeth->mii_info;
1686 ug_regs = ugeth->ug_regs;
1688 if (mii_info->link) {
1689 /* Now we make sure that we can be in full duplex mode.
1690 * If not, we operate in half-duplex mode. */
1691 if (mii_info->duplex != ugeth->oldduplex) {
1692 if (!(mii_info->duplex)) {
1693 tempval = in_be32(&ug_regs->maccfg2);
1694 tempval &= ~(MACCFG2_FDX);
1695 out_be32(&ug_regs->maccfg2, tempval);
1697 ugeth_info("%s: Half Duplex", dev->name);
1699 tempval = in_be32(&ug_regs->maccfg2);
1700 tempval |= MACCFG2_FDX;
1701 out_be32(&ug_regs->maccfg2, tempval);
1703 ugeth_info("%s: Full Duplex", dev->name);
1706 ugeth->oldduplex = mii_info->duplex;
1709 if (mii_info->speed != ugeth->oldspeed) {
1710 switch (mii_info->speed) {
1712 #ifdef CONFIG_PPC_MPC836x
1713 /* FIXME: This code is for 100Mbs BUG fixing,
1714 remove this when it is fixed!!! */
1715 if (ugeth->ug_info->enet_interface ==
1717 /* Run the commands which initialize the PHY */
1720 (u32) mii_info->mdio_read(ugeth->
1721 dev, mii_info->mii_id, 0x1b);
1723 mii_info->mdio_write(ugeth->dev,
1724 mii_info->mii_id, 0x1b,
1727 (u32) mii_info->mdio_read(ugeth->
1728 dev, mii_info->mii_id,
1730 mii_info->mdio_write(ugeth->dev,
1731 mii_info->mii_id, MII_BMCR,
1732 (u16) (tempval | BMCR_RESET));
1733 } else if (ugeth->ug_info->enet_interface ==
1735 /* Run the commands which initialize the PHY */
1738 (u32) mii_info->mdio_read(ugeth->
1739 dev, mii_info->mii_id, 0x1b);
1740 tempval = (tempval & ~0x000f) | 0x000b;
1741 mii_info->mdio_write(ugeth->dev,
1742 mii_info->mii_id, 0x1b,
1745 (u32) mii_info->mdio_read(ugeth->
1746 dev, mii_info->mii_id,
1748 mii_info->mdio_write(ugeth->dev,
1749 mii_info->mii_id, MII_BMCR,
1750 (u16) (tempval | BMCR_RESET));
1753 #endif /* CONFIG_MPC8360 */
1754 adjust_enet_interface(ugeth);
1758 #ifdef CONFIG_PPC_MPC836x
1759 /* FIXME: This code is for 100Mbs BUG fixing,
1760 remove this lines when it will be fixed!!! */
1761 ugeth->ug_info->enet_interface = ENET_100_RGMII;
1763 (u32) mii_info->mdio_read(ugeth->dev,
1766 tempval = (tempval & ~0x000f) | 0x000b;
1767 mii_info->mdio_write(ugeth->dev,
1768 mii_info->mii_id, 0x1b,
1771 (u32) mii_info->mdio_read(ugeth->dev,
1774 mii_info->mdio_write(ugeth->dev,
1775 mii_info->mii_id, MII_BMCR,
1779 #endif /* CONFIG_MPC8360 */
1780 adjust_enet_interface(ugeth);
1784 ("%s: Ack! Speed (%d) is not 10/100/1000!",
1785 dev->name, mii_info->speed);
1789 ugeth_info("%s: Speed %dBT", dev->name,
1792 ugeth->oldspeed = mii_info->speed;
1795 if (!ugeth->oldlink) {
1796 ugeth_info("%s: Link is up", dev->name);
1798 netif_carrier_on(dev);
1799 netif_schedule(dev);
1802 if (ugeth->oldlink) {
1803 ugeth_info("%s: Link is down", dev->name);
1805 ugeth->oldspeed = 0;
1806 ugeth->oldduplex = -1;
1807 netif_carrier_off(dev);
1812 /* Configure the PHY for dev.
1813 * returns 0 if success. -1 if failure
1815 static int init_phy(struct net_device *dev)
1817 struct ucc_geth_private *ugeth = netdev_priv(dev);
1818 struct phy_info *curphy;
1819 struct ucc_mii_mng *mii_regs;
1820 struct ugeth_mii_info *mii_info;
1823 mii_regs = &ugeth->ug_regs->miimng;
1826 ugeth->oldspeed = 0;
1827 ugeth->oldduplex = -1;
1829 mii_info = kmalloc(sizeof(struct ugeth_mii_info), GFP_KERNEL);
1831 if (NULL == mii_info) {
1832 ugeth_err("%s: Could not allocate mii_info", dev->name);
1836 mii_info->mii_regs = mii_regs;
1837 mii_info->speed = SPEED_1000;
1838 mii_info->duplex = DUPLEX_FULL;
1839 mii_info->pause = 0;
1842 mii_info->advertising = (ADVERTISED_10baseT_Half |
1843 ADVERTISED_10baseT_Full |
1844 ADVERTISED_100baseT_Half |
1845 ADVERTISED_100baseT_Full |
1846 ADVERTISED_1000baseT_Full);
1847 mii_info->autoneg = 1;
1849 mii_info->mii_id = ugeth->ug_info->phy_address;
1851 mii_info->dev = dev;
1853 mii_info->mdio_read = &read_phy_reg;
1854 mii_info->mdio_write = &write_phy_reg;
1856 spin_lock_init(&mii_info->mdio_lock);
1858 ugeth->mii_info = mii_info;
1860 spin_lock_irq(&ugeth->lock);
1862 /* Set this UCC to be the master of the MII managment */
1863 ucc_set_qe_mux_mii_mng(ugeth->ug_info->uf_info.ucc_num);
1865 if (init_mii_management_configuration(1,
1869 &mii_regs->miimind)) {
1870 ugeth_err("%s: The MII Bus is stuck!", dev->name);
1875 spin_unlock_irq(&ugeth->lock);
1877 /* get info for this PHY */
1878 curphy = get_phy_info(ugeth->mii_info);
1880 if (curphy == NULL) {
1881 ugeth_err("%s: No PHY found", dev->name);
1886 mii_info->phyinfo = curphy;
1888 /* Run the commands which initialize the PHY */
1890 err = curphy->init(ugeth->mii_info);
1905 #ifdef CONFIG_UGETH_TX_ON_DEMOND
1906 static int ugeth_transmit_on_demand(struct ucc_geth_private *ugeth)
1908 struct ucc_fastransmit_on_demand(ugeth->uccf);
1914 static int ugeth_graceful_stop_tx(struct ucc_geth_private *ugeth)
1916 struct ucc_fast_private *uccf;
1922 /* Mask GRACEFUL STOP TX interrupt bit and clear it */
1923 temp = in_be32(uccf->p_uccm);
1925 out_be32(uccf->p_uccm, temp);
1926 out_be32(uccf->p_ucce, UCCE_GRA); /* clear by writing 1 */
1928 /* Issue host command */
1930 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1931 qe_issue_cmd(QE_GRACEFUL_STOP_TX, cecr_subblock,
1932 QE_CR_PROTOCOL_ETHERNET, 0);
1934 /* Wait for command to complete */
1936 temp = in_be32(uccf->p_ucce);
1937 } while (!(temp & UCCE_GRA));
1939 uccf->stopped_tx = 1;
1944 static int ugeth_graceful_stop_rx(struct ucc_geth_private * ugeth)
1946 struct ucc_fast_private *uccf;
1952 /* Clear acknowledge bit */
1953 temp = ugeth->p_rx_glbl_pram->rxgstpack;
1954 temp &= ~GRACEFUL_STOP_ACKNOWLEDGE_RX;
1955 ugeth->p_rx_glbl_pram->rxgstpack = temp;
1957 /* Keep issuing command and checking acknowledge bit until
1958 it is asserted, according to spec */
1960 /* Issue host command */
1962 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.
1964 qe_issue_cmd(QE_GRACEFUL_STOP_RX, cecr_subblock,
1965 QE_CR_PROTOCOL_ETHERNET, 0);
1967 temp = ugeth->p_rx_glbl_pram->rxgstpack;
1968 } while (!(temp & GRACEFUL_STOP_ACKNOWLEDGE_RX));
1970 uccf->stopped_rx = 1;
1975 static int ugeth_restart_tx(struct ucc_geth_private *ugeth)
1977 struct ucc_fast_private *uccf;
1983 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1984 qe_issue_cmd(QE_RESTART_TX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET, 0);
1985 uccf->stopped_tx = 0;
1990 static int ugeth_restart_rx(struct ucc_geth_private *ugeth)
1992 struct ucc_fast_private *uccf;
1998 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1999 qe_issue_cmd(QE_RESTART_RX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
2001 uccf->stopped_rx = 0;
2006 static int ugeth_enable(struct ucc_geth_private *ugeth, enum comm_dir mode)
2008 struct ucc_fast_private *uccf;
2009 int enabled_tx, enabled_rx;
2013 /* check if the UCC number is in range. */
2014 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
2015 ugeth_err("%s: ucc_num out of range.", __FUNCTION__);
2019 enabled_tx = uccf->enabled_tx;
2020 enabled_rx = uccf->enabled_rx;
2022 /* Get Tx and Rx going again, in case this channel was actively
2024 if ((mode & COMM_DIR_TX) && (!enabled_tx) && uccf->stopped_tx)
2025 ugeth_restart_tx(ugeth);
2026 if ((mode & COMM_DIR_RX) && (!enabled_rx) && uccf->stopped_rx)
2027 ugeth_restart_rx(ugeth);
2029 ucc_fast_enable(uccf, mode); /* OK to do even if not disabled */
2035 static int ugeth_disable(struct ucc_geth_private * ugeth, enum comm_dir mode)
2037 struct ucc_fast_private *uccf;
2041 /* check if the UCC number is in range. */
2042 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
2043 ugeth_err("%s: ucc_num out of range.", __FUNCTION__);
2047 /* Stop any transmissions */
2048 if ((mode & COMM_DIR_TX) && uccf->enabled_tx && !uccf->stopped_tx)
2049 ugeth_graceful_stop_tx(ugeth);
2051 /* Stop any receptions */
2052 if ((mode & COMM_DIR_RX) && uccf->enabled_rx && !uccf->stopped_rx)
2053 ugeth_graceful_stop_rx(ugeth);
2055 ucc_fast_disable(ugeth->uccf, mode); /* OK to do even if not enabled */
2060 static void ugeth_dump_regs(struct ucc_geth_private *ugeth)
2063 ucc_fast_dump_regs(ugeth->uccf);
2069 #ifdef CONFIG_UGETH_FILTERING
2070 static int ugeth_ext_filtering_serialize_tad(struct ucc_geth_tad_params *
2072 struct qe_fltr_tad *qe_fltr_tad)
2076 /* Zero serialized TAD */
2077 memset(qe_fltr_tad, 0, QE_FLTR_TAD_SIZE);
2079 qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_V; /* Must have this */
2080 if (p_UccGethTadParams->rx_non_dynamic_extended_features_mode ||
2081 (p_UccGethTadParams->vtag_op != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
2082 || (p_UccGethTadParams->vnontag_op !=
2083 UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP)
2085 qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_EF;
2086 if (p_UccGethTadParams->reject_frame)
2087 qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_REJ;
2089 (u16) (((u16) p_UccGethTadParams->
2090 vtag_op) << UCC_GETH_TAD_VTAG_OP_SHIFT);
2091 qe_fltr_tad->serialized[0] |= (u8) (temp >> 8); /* upper bits */
2093 qe_fltr_tad->serialized[1] |= (u8) (temp & 0x00ff); /* lower bits */
2094 if (p_UccGethTadParams->vnontag_op ==
2095 UCC_GETH_VLAN_OPERATION_NON_TAGGED_Q_TAG_INSERT)
2096 qe_fltr_tad->serialized[1] |= UCC_GETH_TAD_V_NON_VTAG_OP;
2097 qe_fltr_tad->serialized[1] |=
2098 p_UccGethTadParams->rqos << UCC_GETH_TAD_RQOS_SHIFT;
2100 qe_fltr_tad->serialized[2] |=
2101 p_UccGethTadParams->vpri << UCC_GETH_TAD_V_PRIORITY_SHIFT;
2103 qe_fltr_tad->serialized[2] |= (u8) (p_UccGethTadParams->vid >> 8);
2105 qe_fltr_tad->serialized[3] |= (u8) (p_UccGethTadParams->vid & 0x00ff);
2110 static struct enet_addr_container_t
2111 *ugeth_82xx_filtering_get_match_addr_in_hash(struct ucc_geth_private *ugeth,
2112 struct enet_addr *p_enet_addr)
2114 struct enet_addr_container *enet_addr_cont;
2115 struct list_head *p_lh;
2120 if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
2121 p_lh = &ugeth->group_hash_q;
2122 p_counter = &(ugeth->numGroupAddrInHash);
2124 p_lh = &ugeth->ind_hash_q;
2125 p_counter = &(ugeth->numIndAddrInHash);
2133 for (i = 0; i < num; i++) {
2135 (struct enet_addr_container *)
2136 ENET_ADDR_CONT_ENTRY(dequeue(p_lh));
2137 for (j = ENET_NUM_OCTETS_PER_ADDRESS - 1; j >= 0; j--) {
2138 if ((*p_enet_addr)[j] != (enet_addr_cont->address)[j])
2141 return enet_addr_cont; /* Found */
2143 enqueue(p_lh, &enet_addr_cont->node); /* Put it back */
2148 static int ugeth_82xx_filtering_add_addr_in_hash(struct ucc_geth_private *ugeth,
2149 struct enet_addr *p_enet_addr)
2151 enum ucc_geth_enet_address_recognition_location location;
2152 struct enet_addr_container *enet_addr_cont;
2153 struct list_head *p_lh;
2158 if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
2159 p_lh = &ugeth->group_hash_q;
2160 limit = ugeth->ug_info->maxGroupAddrInHash;
2162 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_GROUP_HASH;
2163 p_counter = &(ugeth->numGroupAddrInHash);
2165 p_lh = &ugeth->ind_hash_q;
2166 limit = ugeth->ug_info->maxIndAddrInHash;
2168 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_INDIVIDUAL_HASH;
2169 p_counter = &(ugeth->numIndAddrInHash);
2172 if ((enet_addr_cont =
2173 ugeth_82xx_filtering_get_match_addr_in_hash(ugeth, p_enet_addr))) {
2174 list_add(p_lh, &enet_addr_cont->node); /* Put it back */
2177 if ((!p_lh) || (!(*p_counter < limit)))
2179 if (!(enet_addr_cont = get_enet_addr_container()))
2181 for (i = 0; i < ENET_NUM_OCTETS_PER_ADDRESS; i++)
2182 (enet_addr_cont->address)[i] = (*p_enet_addr)[i];
2183 enet_addr_cont->location = location;
2184 enqueue(p_lh, &enet_addr_cont->node); /* Put it back */
2187 hw_add_addr_in_hash(ugeth, enet_addr_cont->address);
2191 static int ugeth_82xx_filtering_clear_addr_in_hash(struct ucc_geth_private *ugeth,
2192 struct enet_addr *p_enet_addr)
2194 struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
2195 struct enet_addr_container *enet_addr_cont;
2196 struct ucc_fast_private *uccf;
2197 enum comm_dir comm_dir;
2199 struct list_head *p_lh;
2200 u32 *addr_h, *addr_l;
2206 (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
2211 ugeth_82xx_filtering_get_match_addr_in_hash(ugeth, p_enet_addr)))
2214 /* It's been found and removed from the CQ. */
2215 /* Now destroy its container */
2216 put_enet_addr_container(enet_addr_cont);
2218 if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
2219 addr_h = &(p_82xx_addr_filt->gaddr_h);
2220 addr_l = &(p_82xx_addr_filt->gaddr_l);
2221 p_lh = &ugeth->group_hash_q;
2222 p_counter = &(ugeth->numGroupAddrInHash);
2224 addr_h = &(p_82xx_addr_filt->iaddr_h);
2225 addr_l = &(p_82xx_addr_filt->iaddr_l);
2226 p_lh = &ugeth->ind_hash_q;
2227 p_counter = &(ugeth->numIndAddrInHash);
2231 if (uccf->enabled_tx)
2232 comm_dir |= COMM_DIR_TX;
2233 if (uccf->enabled_rx)
2234 comm_dir |= COMM_DIR_RX;
2236 ugeth_disable(ugeth, comm_dir);
2238 /* Clear the hash table. */
2239 out_be32(addr_h, 0x00000000);
2240 out_be32(addr_l, 0x00000000);
2242 /* Add all remaining CQ elements back into hash */
2243 num = --(*p_counter);
2244 for (i = 0; i < num; i++) {
2246 (struct enet_addr_container *)
2247 ENET_ADDR_CONT_ENTRY(dequeue(p_lh));
2248 hw_add_addr_in_hash(ugeth, enet_addr_cont->address);
2249 enqueue(p_lh, &enet_addr_cont->node); /* Put it back */
2253 ugeth_enable(ugeth, comm_dir);
2257 #endif /* CONFIG_UGETH_FILTERING */
2259 static int ugeth_82xx_filtering_clear_all_addr_in_hash(struct ucc_geth_private *
2264 struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
2265 struct ucc_fast_private *uccf;
2266 enum comm_dir comm_dir;
2267 struct list_head *p_lh;
2269 u32 *addr_h, *addr_l;
2275 (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
2278 if (enet_addr_type == ENET_ADDR_TYPE_GROUP) {
2279 addr_h = &(p_82xx_addr_filt->gaddr_h);
2280 addr_l = &(p_82xx_addr_filt->gaddr_l);
2281 p_lh = &ugeth->group_hash_q;
2282 p_counter = &(ugeth->numGroupAddrInHash);
2283 } else if (enet_addr_type == ENET_ADDR_TYPE_INDIVIDUAL) {
2284 addr_h = &(p_82xx_addr_filt->iaddr_h);
2285 addr_l = &(p_82xx_addr_filt->iaddr_l);
2286 p_lh = &ugeth->ind_hash_q;
2287 p_counter = &(ugeth->numIndAddrInHash);
2292 if (uccf->enabled_tx)
2293 comm_dir |= COMM_DIR_TX;
2294 if (uccf->enabled_rx)
2295 comm_dir |= COMM_DIR_RX;
2297 ugeth_disable(ugeth, comm_dir);
2299 /* Clear the hash table. */
2300 out_be32(addr_h, 0x00000000);
2301 out_be32(addr_l, 0x00000000);
2308 /* Delete all remaining CQ elements */
2309 for (i = 0; i < num; i++)
2310 put_enet_addr_container(ENET_ADDR_CONT_ENTRY(dequeue(p_lh)));
2315 ugeth_enable(ugeth, comm_dir);
2320 #ifdef CONFIG_UGETH_FILTERING
2321 static int ugeth_82xx_filtering_add_addr_in_paddr(struct ucc_geth_private *ugeth,
2322 struct enet_addr *p_enet_addr,
2327 if ((*p_enet_addr)[0] & ENET_GROUP_ADDR)
2329 ("%s: multicast address added to paddr will have no "
2330 "effect - is this what you wanted?",
2333 ugeth->indAddrRegUsed[paddr_num] = 1; /* mark this paddr as used */
2334 /* store address in our database */
2335 for (i = 0; i < ENET_NUM_OCTETS_PER_ADDRESS; i++)
2336 ugeth->paddr[paddr_num][i] = (*p_enet_addr)[i];
2337 /* put in hardware */
2338 return hw_add_addr_in_paddr(ugeth, p_enet_addr, paddr_num);
2340 #endif /* CONFIG_UGETH_FILTERING */
2342 static int ugeth_82xx_filtering_clear_addr_in_paddr(struct ucc_geth_private *ugeth,
2345 ugeth->indAddrRegUsed[paddr_num] = 0; /* mark this paddr as not used */
2346 return hw_clear_addr_in_paddr(ugeth, paddr_num);/* clear in hardware */
2349 static void ucc_geth_memclean(struct ucc_geth_private *ugeth)
2358 ucc_fast_free(ugeth->uccf);
2360 if (ugeth->p_thread_data_tx) {
2361 qe_muram_free(ugeth->thread_dat_tx_offset);
2362 ugeth->p_thread_data_tx = NULL;
2364 if (ugeth->p_thread_data_rx) {
2365 qe_muram_free(ugeth->thread_dat_rx_offset);
2366 ugeth->p_thread_data_rx = NULL;
2368 if (ugeth->p_exf_glbl_param) {
2369 qe_muram_free(ugeth->exf_glbl_param_offset);
2370 ugeth->p_exf_glbl_param = NULL;
2372 if (ugeth->p_rx_glbl_pram) {
2373 qe_muram_free(ugeth->rx_glbl_pram_offset);
2374 ugeth->p_rx_glbl_pram = NULL;
2376 if (ugeth->p_tx_glbl_pram) {
2377 qe_muram_free(ugeth->tx_glbl_pram_offset);
2378 ugeth->p_tx_glbl_pram = NULL;
2380 if (ugeth->p_send_q_mem_reg) {
2381 qe_muram_free(ugeth->send_q_mem_reg_offset);
2382 ugeth->p_send_q_mem_reg = NULL;
2384 if (ugeth->p_scheduler) {
2385 qe_muram_free(ugeth->scheduler_offset);
2386 ugeth->p_scheduler = NULL;
2388 if (ugeth->p_tx_fw_statistics_pram) {
2389 qe_muram_free(ugeth->tx_fw_statistics_pram_offset);
2390 ugeth->p_tx_fw_statistics_pram = NULL;
2392 if (ugeth->p_rx_fw_statistics_pram) {
2393 qe_muram_free(ugeth->rx_fw_statistics_pram_offset);
2394 ugeth->p_rx_fw_statistics_pram = NULL;
2396 if (ugeth->p_rx_irq_coalescing_tbl) {
2397 qe_muram_free(ugeth->rx_irq_coalescing_tbl_offset);
2398 ugeth->p_rx_irq_coalescing_tbl = NULL;
2400 if (ugeth->p_rx_bd_qs_tbl) {
2401 qe_muram_free(ugeth->rx_bd_qs_tbl_offset);
2402 ugeth->p_rx_bd_qs_tbl = NULL;
2404 if (ugeth->p_init_enet_param_shadow) {
2405 return_init_enet_entries(ugeth,
2406 &(ugeth->p_init_enet_param_shadow->
2408 ENET_INIT_PARAM_MAX_ENTRIES_RX,
2409 ugeth->ug_info->riscRx, 1);
2410 return_init_enet_entries(ugeth,
2411 &(ugeth->p_init_enet_param_shadow->
2413 ENET_INIT_PARAM_MAX_ENTRIES_TX,
2414 ugeth->ug_info->riscTx, 0);
2415 kfree(ugeth->p_init_enet_param_shadow);
2416 ugeth->p_init_enet_param_shadow = NULL;
2418 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
2419 bd = ugeth->p_tx_bd_ring[i];
2420 for (j = 0; j < ugeth->ug_info->bdRingLenTx[i]; j++) {
2421 if (ugeth->tx_skbuff[i][j]) {
2422 dma_unmap_single(NULL,
2423 ((qe_bd_t *)bd)->buf,
2424 (in_be32((u32 *)bd) &
2427 dev_kfree_skb_any(ugeth->tx_skbuff[i][j]);
2428 ugeth->tx_skbuff[i][j] = NULL;
2432 kfree(ugeth->tx_skbuff[i]);
2434 if (ugeth->p_tx_bd_ring[i]) {
2435 if (ugeth->ug_info->uf_info.bd_mem_part ==
2437 kfree((void *)ugeth->tx_bd_ring_offset[i]);
2438 else if (ugeth->ug_info->uf_info.bd_mem_part ==
2440 qe_muram_free(ugeth->tx_bd_ring_offset[i]);
2441 ugeth->p_tx_bd_ring[i] = NULL;
2444 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
2445 if (ugeth->p_rx_bd_ring[i]) {
2446 /* Return existing data buffers in ring */
2447 bd = ugeth->p_rx_bd_ring[i];
2448 for (j = 0; j < ugeth->ug_info->bdRingLenRx[i]; j++) {
2449 if (ugeth->rx_skbuff[i][j]) {
2450 dma_unmap_single(NULL,
2451 ((struct qe_bd *)bd)->buf,
2453 uf_info.max_rx_buf_length +
2454 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
2457 ugeth->rx_skbuff[i][j]);
2458 ugeth->rx_skbuff[i][j] = NULL;
2460 bd += sizeof(struct qe_bd);
2463 kfree(ugeth->rx_skbuff[i]);
2465 if (ugeth->ug_info->uf_info.bd_mem_part ==
2467 kfree((void *)ugeth->rx_bd_ring_offset[i]);
2468 else if (ugeth->ug_info->uf_info.bd_mem_part ==
2470 qe_muram_free(ugeth->rx_bd_ring_offset[i]);
2471 ugeth->p_rx_bd_ring[i] = NULL;
2474 while (!list_empty(&ugeth->group_hash_q))
2475 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
2476 (dequeue(&ugeth->group_hash_q)));
2477 while (!list_empty(&ugeth->ind_hash_q))
2478 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
2479 (dequeue(&ugeth->ind_hash_q)));
2483 static void ucc_geth_set_multi(struct net_device *dev)
2485 struct ucc_geth_private *ugeth;
2486 struct dev_mc_list *dmi;
2487 struct ucc_fast *uf_regs;
2488 struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
2493 ugeth = netdev_priv(dev);
2495 uf_regs = ugeth->uccf->uf_regs;
2497 if (dev->flags & IFF_PROMISC) {
2499 uf_regs->upsmr |= UPSMR_PRO;
2503 uf_regs->upsmr &= ~UPSMR_PRO;
2506 (struct ucc_geth_82xx_address_filtering_pram *) ugeth->
2507 p_rx_glbl_pram->addressfiltering;
2509 if (dev->flags & IFF_ALLMULTI) {
2510 /* Catch all multicast addresses, so set the
2511 * filter to all 1's.
2513 out_be32(&p_82xx_addr_filt->gaddr_h, 0xffffffff);
2514 out_be32(&p_82xx_addr_filt->gaddr_l, 0xffffffff);
2516 /* Clear filter and add the addresses in the list.
2518 out_be32(&p_82xx_addr_filt->gaddr_h, 0x0);
2519 out_be32(&p_82xx_addr_filt->gaddr_l, 0x0);
2523 for (i = 0; i < dev->mc_count; i++, dmi = dmi->next) {
2525 /* Only support group multicast for now.
2527 if (!(dmi->dmi_addr[0] & 1))
2530 /* The address in dmi_addr is LSB first,
2531 * and taddr is MSB first. We have to
2532 * copy bytes MSB first from dmi_addr.
2534 mcptr = (u8 *) dmi->dmi_addr + 5;
2535 tdptr = (u8 *) tempaddr;
2536 for (j = 0; j < 6; j++)
2537 *tdptr++ = *mcptr--;
2539 /* Ask CPM to run CRC and set bit in
2542 hw_add_addr_in_hash(ugeth, tempaddr);
2548 static void ucc_geth_stop(struct ucc_geth_private *ugeth)
2550 struct ucc_geth *ug_regs = ugeth->ug_regs;
2553 ugeth_vdbg("%s: IN", __FUNCTION__);
2555 /* Disable the controller */
2556 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
2558 /* Tell the kernel the link is down */
2559 ugeth->mii_info->link = 0;
2560 adjust_link(ugeth->dev);
2562 /* Mask all interrupts */
2563 out_be32(ugeth->uccf->p_ucce, 0x00000000);
2565 /* Clear all interrupts */
2566 out_be32(ugeth->uccf->p_ucce, 0xffffffff);
2568 /* Disable Rx and Tx */
2569 tempval = in_be32(&ug_regs->maccfg1);
2570 tempval &= ~(MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
2571 out_be32(&ug_regs->maccfg1, tempval);
2573 if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR) {
2574 /* Clear any pending interrupts */
2575 mii_clear_phy_interrupt(ugeth->mii_info);
2577 /* Disable PHY Interrupts */
2578 mii_configure_phy_interrupt(ugeth->mii_info,
2579 MII_INTERRUPT_DISABLED);
2582 free_irq(ugeth->ug_info->uf_info.irq, ugeth->dev);
2584 if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR) {
2585 free_irq(ugeth->ug_info->phy_interrupt, ugeth->dev);
2587 del_timer_sync(&ugeth->phy_info_timer);
2590 ucc_geth_memclean(ugeth);
2593 static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2595 struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
2596 struct ucc_geth_init_pram *p_init_enet_pram;
2597 struct ucc_fast_private *uccf;
2598 struct ucc_geth_info *ug_info;
2599 struct ucc_fast_info *uf_info;
2600 struct ucc_fast *uf_regs;
2601 struct ucc_geth *ug_regs;
2602 int ret_val = -EINVAL;
2603 u32 remoder = UCC_GETH_REMODER_INIT;
2604 u32 init_enet_pram_offset, cecr_subblock, command, maccfg1;
2605 u32 ifstat, i, j, size, l2qt, l3qt, length;
2606 u16 temoder = UCC_GETH_TEMODER_INIT;
2608 u8 function_code = 0;
2610 u8 numThreadsRxNumerical, numThreadsTxNumerical;
2612 ugeth_vdbg("%s: IN", __FUNCTION__);
2614 ug_info = ugeth->ug_info;
2615 uf_info = &ug_info->uf_info;
2617 if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
2618 (uf_info->bd_mem_part == MEM_PART_MURAM))) {
2619 ugeth_err("%s: Bad memory partition value.", __FUNCTION__);
2624 for (i = 0; i < ug_info->numQueuesRx; i++) {
2625 if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) ||
2626 (ug_info->bdRingLenRx[i] %
2627 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) {
2629 ("%s: Rx BD ring length must be multiple of 4,"
2630 " no smaller than 8.", __FUNCTION__);
2636 for (i = 0; i < ug_info->numQueuesTx; i++) {
2637 if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) {
2639 ("%s: Tx BD ring length must be no smaller than 2.",
2646 if ((uf_info->max_rx_buf_length == 0) ||
2647 (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) {
2649 ("%s: max_rx_buf_length must be non-zero multiple of 128.",
2655 if (ug_info->numQueuesTx > NUM_TX_QUEUES) {
2656 ugeth_err("%s: number of tx queues too large.", __FUNCTION__);
2661 if (ug_info->numQueuesRx > NUM_RX_QUEUES) {
2662 ugeth_err("%s: number of rx queues too large.", __FUNCTION__);
2667 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) {
2668 if (ug_info->l2qt[i] >= ug_info->numQueuesRx) {
2670 ("%s: VLAN priority table entry must not be"
2671 " larger than number of Rx queues.",
2678 for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) {
2679 if (ug_info->l3qt[i] >= ug_info->numQueuesRx) {
2681 ("%s: IP priority table entry must not be"
2682 " larger than number of Rx queues.",
2688 if (ug_info->cam && !ug_info->ecamptr) {
2689 ugeth_err("%s: If cam mode is chosen, must supply cam ptr.",
2694 if ((ug_info->numStationAddresses !=
2695 UCC_GETH_NUM_OF_STATION_ADDRESSES_1)
2696 && ug_info->rxExtendedFiltering) {
2697 ugeth_err("%s: Number of station addresses greater than 1 "
2698 "not allowed in extended parsing mode.",
2703 /* Generate uccm_mask for receive */
2704 uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */
2705 for (i = 0; i < ug_info->numQueuesRx; i++)
2706 uf_info->uccm_mask |= (UCCE_RXBF_SINGLE_MASK << i);
2708 for (i = 0; i < ug_info->numQueuesTx; i++)
2709 uf_info->uccm_mask |= (UCCE_TXBF_SINGLE_MASK << i);
2710 /* Initialize the general fast UCC block. */
2711 if (ucc_fast_init(uf_info, &uccf)) {
2712 ugeth_err("%s: Failed to init uccf.", __FUNCTION__);
2713 ucc_geth_memclean(ugeth);
2718 switch (ug_info->numThreadsRx) {
2719 case UCC_GETH_NUM_OF_THREADS_1:
2720 numThreadsRxNumerical = 1;
2722 case UCC_GETH_NUM_OF_THREADS_2:
2723 numThreadsRxNumerical = 2;
2725 case UCC_GETH_NUM_OF_THREADS_4:
2726 numThreadsRxNumerical = 4;
2728 case UCC_GETH_NUM_OF_THREADS_6:
2729 numThreadsRxNumerical = 6;
2731 case UCC_GETH_NUM_OF_THREADS_8:
2732 numThreadsRxNumerical = 8;
2735 ugeth_err("%s: Bad number of Rx threads value.", __FUNCTION__);
2736 ucc_geth_memclean(ugeth);
2741 switch (ug_info->numThreadsTx) {
2742 case UCC_GETH_NUM_OF_THREADS_1:
2743 numThreadsTxNumerical = 1;
2745 case UCC_GETH_NUM_OF_THREADS_2:
2746 numThreadsTxNumerical = 2;
2748 case UCC_GETH_NUM_OF_THREADS_4:
2749 numThreadsTxNumerical = 4;
2751 case UCC_GETH_NUM_OF_THREADS_6:
2752 numThreadsTxNumerical = 6;
2754 case UCC_GETH_NUM_OF_THREADS_8:
2755 numThreadsTxNumerical = 8;
2758 ugeth_err("%s: Bad number of Tx threads value.", __FUNCTION__);
2759 ucc_geth_memclean(ugeth);
2764 /* Calculate rx_extended_features */
2765 ugeth->rx_non_dynamic_extended_features = ug_info->ipCheckSumCheck ||
2766 ug_info->ipAddressAlignment ||
2767 (ug_info->numStationAddresses !=
2768 UCC_GETH_NUM_OF_STATION_ADDRESSES_1);
2770 ugeth->rx_extended_features = ugeth->rx_non_dynamic_extended_features ||
2771 (ug_info->vlanOperationTagged != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
2772 || (ug_info->vlanOperationNonTagged !=
2773 UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP);
2775 uf_regs = uccf->uf_regs;
2776 ug_regs = (struct ucc_geth *) (uccf->uf_regs);
2777 ugeth->ug_regs = ug_regs;
2779 init_default_reg_vals(&uf_regs->upsmr,
2780 &ug_regs->maccfg1, &ug_regs->maccfg2);
2783 /* For more details see the hardware spec. */
2784 init_rx_parameters(ug_info->bro,
2785 ug_info->rsh, ug_info->pro, &uf_regs->upsmr);
2787 /* We're going to ignore other registers for now, */
2788 /* except as needed to get up and running */
2791 /* For more details see the hardware spec. */
2792 init_flow_control_params(ug_info->aufc,
2793 ug_info->receiveFlowControl,
2795 ug_info->pausePeriod,
2796 ug_info->extensionField,
2798 &ug_regs->uempr, &ug_regs->maccfg1);
2800 maccfg1 = in_be32(&ug_regs->maccfg1);
2801 maccfg1 |= MACCFG1_ENABLE_RX;
2802 maccfg1 |= MACCFG1_ENABLE_TX;
2803 out_be32(&ug_regs->maccfg1, maccfg1);
2806 /* For more details see the hardware spec. */
2807 ret_val = init_inter_frame_gap_params(ug_info->nonBackToBackIfgPart1,
2808 ug_info->nonBackToBackIfgPart2,
2810 miminumInterFrameGapEnforcement,
2811 ug_info->backToBackInterFrameGap,
2814 ugeth_err("%s: IPGIFG initialization parameter too large.",
2816 ucc_geth_memclean(ugeth);
2821 /* For more details see the hardware spec. */
2822 ret_val = init_half_duplex_params(ug_info->altBeb,
2823 ug_info->backPressureNoBackoff,
2825 ug_info->excessDefer,
2826 ug_info->altBebTruncation,
2827 ug_info->maxRetransmission,
2828 ug_info->collisionWindow,
2831 ugeth_err("%s: Half Duplex initialization parameter too large.",
2833 ucc_geth_memclean(ugeth);
2838 /* For more details see the hardware spec. */
2839 /* Read only - resets upon read */
2840 ifstat = in_be32(&ug_regs->ifstat);
2843 /* For more details see the hardware spec. */
2844 out_be32(&ug_regs->uempr, 0);
2847 /* For more details see the hardware spec. */
2848 init_hw_statistics_gathering_mode((ug_info->statisticsMode &
2849 UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE),
2850 0, &uf_regs->upsmr, &ug_regs->uescr);
2852 /* Allocate Tx bds */
2853 for (j = 0; j < ug_info->numQueuesTx; j++) {
2854 /* Allocate in multiple of
2855 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT,
2856 according to spec */
2857 length = ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd))
2858 / UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2859 * UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
2860 if ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)) %
2861 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2862 length += UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
2863 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2865 if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
2866 align = UCC_GETH_TX_BD_RING_ALIGNMENT;
2867 ugeth->tx_bd_ring_offset[j] =
2868 (u32) (kmalloc((u32) (length + align),
2870 if (ugeth->tx_bd_ring_offset[j] != 0)
2871 ugeth->p_tx_bd_ring[j] =
2872 (void*)((ugeth->tx_bd_ring_offset[j] +
2873 align) & ~(align - 1));
2874 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2875 ugeth->tx_bd_ring_offset[j] =
2876 qe_muram_alloc(length,
2877 UCC_GETH_TX_BD_RING_ALIGNMENT);
2878 if (!IS_MURAM_ERR(ugeth->tx_bd_ring_offset[j]))
2879 ugeth->p_tx_bd_ring[j] =
2880 (u8 *) qe_muram_addr(ugeth->
2881 tx_bd_ring_offset[j]);
2883 if (!ugeth->p_tx_bd_ring[j]) {
2885 ("%s: Can not allocate memory for Tx bd rings.",
2887 ucc_geth_memclean(ugeth);
2890 /* Zero unused end of bd ring, according to spec */
2891 memset(ugeth->p_tx_bd_ring[j] +
2892 ug_info->bdRingLenTx[j] * sizeof(struct qe_bd), 0,
2893 length - ug_info->bdRingLenTx[j] * sizeof(struct qe_bd));
2896 /* Allocate Rx bds */
2897 for (j = 0; j < ug_info->numQueuesRx; j++) {
2898 length = ug_info->bdRingLenRx[j] * sizeof(struct qe_bd);
2899 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2901 if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
2902 align = UCC_GETH_RX_BD_RING_ALIGNMENT;
2903 ugeth->rx_bd_ring_offset[j] =
2904 (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
2905 if (ugeth->rx_bd_ring_offset[j] != 0)
2906 ugeth->p_rx_bd_ring[j] =
2907 (void*)((ugeth->rx_bd_ring_offset[j] +
2908 align) & ~(align - 1));
2909 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2910 ugeth->rx_bd_ring_offset[j] =
2911 qe_muram_alloc(length,
2912 UCC_GETH_RX_BD_RING_ALIGNMENT);
2913 if (!IS_MURAM_ERR(ugeth->rx_bd_ring_offset[j]))
2914 ugeth->p_rx_bd_ring[j] =
2915 (u8 *) qe_muram_addr(ugeth->
2916 rx_bd_ring_offset[j]);
2918 if (!ugeth->p_rx_bd_ring[j]) {
2920 ("%s: Can not allocate memory for Rx bd rings.",
2922 ucc_geth_memclean(ugeth);
2928 for (j = 0; j < ug_info->numQueuesTx; j++) {
2929 /* Setup the skbuff rings */
2930 ugeth->tx_skbuff[j] =
2931 (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
2932 ugeth->ug_info->bdRingLenTx[j],
2935 if (ugeth->tx_skbuff[j] == NULL) {
2936 ugeth_err("%s: Could not allocate tx_skbuff",
2938 ucc_geth_memclean(ugeth);
2942 for (i = 0; i < ugeth->ug_info->bdRingLenTx[j]; i++)
2943 ugeth->tx_skbuff[j][i] = NULL;
2945 ugeth->skb_curtx[j] = ugeth->skb_dirtytx[j] = 0;
2946 bd = ugeth->confBd[j] = ugeth->txBd[j] = ugeth->p_tx_bd_ring[j];
2947 for (i = 0; i < ug_info->bdRingLenTx[j]; i++) {
2948 /* clear bd buffer */
2949 out_be32(&((struct qe_bd *)bd)->buf, 0);
2950 /* set bd status and length */
2951 out_be32((u32 *)bd, 0);
2952 bd += sizeof(struct qe_bd);
2954 bd -= sizeof(struct qe_bd);
2955 /* set bd status and length */
2956 out_be32((u32 *)bd, T_W); /* for last BD set Wrap bit */
2960 for (j = 0; j < ug_info->numQueuesRx; j++) {
2961 /* Setup the skbuff rings */
2962 ugeth->rx_skbuff[j] =
2963 (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
2964 ugeth->ug_info->bdRingLenRx[j],
2967 if (ugeth->rx_skbuff[j] == NULL) {
2968 ugeth_err("%s: Could not allocate rx_skbuff",
2970 ucc_geth_memclean(ugeth);
2974 for (i = 0; i < ugeth->ug_info->bdRingLenRx[j]; i++)
2975 ugeth->rx_skbuff[j][i] = NULL;
2977 ugeth->skb_currx[j] = 0;
2978 bd = ugeth->rxBd[j] = ugeth->p_rx_bd_ring[j];
2979 for (i = 0; i < ug_info->bdRingLenRx[j]; i++) {
2980 /* set bd status and length */
2981 out_be32((u32 *)bd, R_I);
2982 /* clear bd buffer */
2983 out_be32(&((struct qe_bd *)bd)->buf, 0);
2984 bd += sizeof(struct qe_bd);
2986 bd -= sizeof(struct qe_bd);
2987 /* set bd status and length */
2988 out_be32((u32 *)bd, R_W); /* for last BD set Wrap bit */
2994 /* Tx global PRAM */
2995 /* Allocate global tx parameter RAM page */
2996 ugeth->tx_glbl_pram_offset =
2997 qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram),
2998 UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
2999 if (IS_MURAM_ERR(ugeth->tx_glbl_pram_offset)) {
3001 ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
3003 ucc_geth_memclean(ugeth);
3006 ugeth->p_tx_glbl_pram =
3007 (struct ucc_geth_tx_global_pram *) qe_muram_addr(ugeth->
3008 tx_glbl_pram_offset);
3009 /* Zero out p_tx_glbl_pram */
3010 memset(ugeth->p_tx_glbl_pram, 0, sizeof(struct ucc_geth_tx_global_pram));
3012 /* Fill global PRAM */
3015 /* Size varies with number of Tx threads */
3016 ugeth->thread_dat_tx_offset =
3017 qe_muram_alloc(numThreadsTxNumerical *
3018 sizeof(struct ucc_geth_thread_data_tx) +
3019 32 * (numThreadsTxNumerical == 1),
3020 UCC_GETH_THREAD_DATA_ALIGNMENT);
3021 if (IS_MURAM_ERR(ugeth->thread_dat_tx_offset)) {
3023 ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
3025 ucc_geth_memclean(ugeth);