15 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/slab.h>
19 #include <linux/stddef.h>
20 #include <linux/module.h>
22 #include <linux/netdevice.h>
28 #include <linux/mii.h>
35 #include <asm/uaccess.h>
42 #include <asm/machdep.h>
48 #define ugeth_printk(level, format, arg...) \
49 printk(level format "\n", ## arg)
51 #define ugeth_dbg(format, arg...) \
52 ugeth_printk(KERN_DEBUG , format , ## arg)
53 #define ugeth_err(format, arg...) \
54 ugeth_printk(KERN_ERR , format , ## arg)
55 #define ugeth_info(format, arg...) \
56 ugeth_printk(KERN_INFO , format , ## arg)
57 #define ugeth_warn(format, arg...) \
58 ugeth_printk(KERN_WARNING , format , ## arg)
60 #ifdef UGETH_VERBOSE_DEBUG
61 #define ugeth_vdbg ugeth_dbg
63 #define ugeth_vdbg(fmt, args...) do { } while (0)
65 #define UGETH_MSG_DEFAULT (NETIF_MSG_IFUP << 1 ) - 1
79 .bd_mem_part = MEM_PART_SYSTEM,
81 .max_rx_buf_length = 1536,
101 .nonBackToBackIfgPart1 = 0x40,
102 .nonBackToBackIfgPart2 = 0x60,
103 .miminumInterFrameGapEnforcement = 0x50,
104 .backToBackInterFrameGap = 0x60,
108 .strictpriorityq = 0xff,
109 .altBebTruncation = 0xa,
111 .maxRetransmission = 0xf,
112 .collisionWindow = 0x37,
113 .receiveFlowControl = 1,
114 .transmitFlowControl = 1,
115 .maxGroupAddrInHash = 4,
116 .maxIndAddrInHash = 4,
118 .maxFrameLength = 1518+16,
119 .minFrameLength = 64,
120 .maxD1Length = 1520+16,
121 .maxD2Length = 1520+16,
125 .pausePeriod = 0xf000,
126 .interruptcoalescingmaxvalue = {1, 1, 1, 1, 1, 1, 1, 1},
148 .largestexternallookupkeysize =
149 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE,
160 .riscTx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
161 .riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
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)));
184 for (; (
u32) i < (
u32) addr + size4Aling; i += 4)
198 if (!list_empty(lh)) {
201 spin_unlock_irqrestore(&ugeth_lock, flags);
204 spin_unlock_irqrestore(&ugeth_lock, flags);
214 skb = netdev_alloc_skb(ugeth->
ndev,
215 ugeth->
ug_info->uf_info.max_rx_buf_length +
231 ugeth->
ug_info->uf_info.max_rx_buf_length +
253 skb = get_new_skb(ugeth, bd);
262 bd +=
sizeof(
struct qe_bd);
264 }
while (!(bd_status &
R_W));
273 u32 thread_alignment,
275 int skip_page_for_first_entry)
277 u32 init_enet_offset;
284 ugeth_err(
"fill_init_enet_entries: Can not get SNUM.");
287 if ((i == 0) && skip_page_for_first_entry)
289 init_enet_offset = 0;
292 qe_muram_alloc(thread_size, thread_alignment);
295 ugeth_err(
"fill_init_enet_entries: Can not allocate DPRAM memory.");
312 int skip_page_for_first_entry)
314 u32 init_enet_offset;
328 if (!((i == 0) && skip_page_for_first_entry)) {
332 qe_muram_free(init_enet_offset);
347 int skip_page_for_first_entry)
349 u32 init_enet_offset;
358 if ((val & ENET_INIT_PARAM_RISC_MASK) == risc) {
360 (
u32) (val & ENET_INIT_PARAM_SNUM_MASK) >>
363 if (!((i == 0) && skip_page_for_first_entry)) {
371 qe_muram_addr(init_enet_offset));
372 mem_disp(qe_muram_addr(init_enet_offset),
385 kfree(enet_addr_cont);
400 ugeth_warn(
"%s: Illagel paddr_num.", __func__);
434 set_mac_addr(&p_82xx_addr_filt->
taddr.h, p_enet_addr);
437 QE_CR_PROTOCOL_ETHERNET, 0);
448 tx_firmware_statistics,
450 rx_firmware_statistics,
453 struct ucc_fast
__iomem *uf_regs;
459 uf_regs = (
struct ucc_fast
__iomem *) ug_regs;
465 if (tx_firmware_statistics && p_tx_fw_statistics_pram) {
466 tx_firmware_statistics->
sicoltx =
478 tx_firmware_statistics->
frtxok =
494 if (rx_firmware_statistics && p_rx_fw_statistics_pram) {
506 rx_firmware_statistics->
runt =
512 rx_firmware_statistics->
dropbsy =
514 for (i = 0; i < 0x8; i++)
515 rx_firmware_statistics->
res0[i] =
516 p_rx_fw_statistics_pram->
res0[i];
521 rx_firmware_statistics->
pkts256 =
523 rx_firmware_statistics->
pkts512 =
531 rx_firmware_statistics->
pausefr =
533 for (i = 0; i < 0x4; i++)
534 rx_firmware_statistics->
res1[i] =
535 p_rx_fw_statistics_pram->
res1[i];
546 if (hardware_statistics &&
547 (
in_be32(&uf_regs->upsmr) & UCC_GETH_UPSMR_HSE)) {
571 for (i = 0; i < ugeth->
ug_info->numQueuesTx; i++) {
575 sizeof(
struct qe_bd));
580 for (i = 0; i < ugeth->
ug_info->numQueuesRx; i++) {
584 sizeof(
struct qe_bd));
598 ugeth_info(
"maccfg1 : addr - 0x%08x, val - 0x%08x",
601 ugeth_info(
"maccfg2 : addr - 0x%08x, val - 0x%08x",
604 ugeth_info(
"ipgifg : addr - 0x%08x, val - 0x%08x",
607 ugeth_info(
"hafdup : addr - 0x%08x, val - 0x%08x",
610 ugeth_info(
"ifctl : addr - 0x%08x, val - 0x%08x",
613 ugeth_info(
"ifstat : addr - 0x%08x, val - 0x%08x",
616 ugeth_info(
"macstnaddr1: addr - 0x%08x, val - 0x%08x",
619 ugeth_info(
"macstnaddr2: addr - 0x%08x, val - 0x%08x",
622 ugeth_info(
"uempr : addr - 0x%08x, val - 0x%08x",
625 ugeth_info(
"utbipar : addr - 0x%08x, val - 0x%08x",
628 ugeth_info(
"uescr : addr - 0x%08x, val - 0x%04x",
631 ugeth_info(
"tx64 : addr - 0x%08x, val - 0x%08x",
634 ugeth_info(
"tx127 : addr - 0x%08x, val - 0x%08x",
637 ugeth_info(
"tx255 : addr - 0x%08x, val - 0x%08x",
640 ugeth_info(
"rx64 : addr - 0x%08x, val - 0x%08x",
643 ugeth_info(
"rx127 : addr - 0x%08x, val - 0x%08x",
646 ugeth_info(
"rx255 : addr - 0x%08x, val - 0x%08x",
649 ugeth_info(
"txok : addr - 0x%08x, val - 0x%08x",
652 ugeth_info(
"txcf : addr - 0x%08x, val - 0x%04x",
655 ugeth_info(
"tmca : addr - 0x%08x, val - 0x%08x",
658 ugeth_info(
"tbca : addr - 0x%08x, val - 0x%08x",
661 ugeth_info(
"rxfok : addr - 0x%08x, val - 0x%08x",
664 ugeth_info(
"rxbok : addr - 0x%08x, val - 0x%08x",
667 ugeth_info(
"rbyt : addr - 0x%08x, val - 0x%08x",
670 ugeth_info(
"rmca : addr - 0x%08x, val - 0x%08x",
673 ugeth_info(
"rbca : addr - 0x%08x, val - 0x%08x",
676 ugeth_info(
"scar : addr - 0x%08x, val - 0x%08x",
679 ugeth_info(
"scam : addr - 0x%08x, val - 0x%08x",
684 int numThreadsTxNumerical;
685 switch (ugeth->
ug_info->numThreadsTx) {
687 numThreadsTxNumerical = 1;
690 numThreadsTxNumerical = 2;
693 numThreadsTxNumerical = 4;
696 numThreadsTxNumerical = 6;
699 numThreadsTxNumerical = 8;
702 numThreadsTxNumerical = 0;
709 for (i = 0; i < numThreadsTxNumerical; i++) {
718 int numThreadsRxNumerical;
719 switch (ugeth->
ug_info->numThreadsRx) {
721 numThreadsRxNumerical = 1;
724 numThreadsRxNumerical = 2;
727 numThreadsRxNumerical = 4;
730 numThreadsRxNumerical = 6;
733 numThreadsRxNumerical = 8;
736 numThreadsRxNumerical = 0;
743 for (i = 0; i < numThreadsRxNumerical; i++) {
761 ugeth_info(
"temoder : addr - 0x%08x, val - 0x%04x",
764 ugeth_info(
"sqptr : addr - 0x%08x, val - 0x%08x",
767 ugeth_info(
"schedulerbasepointer: addr - 0x%08x, val - 0x%08x",
770 schedulerbasepointer));
771 ugeth_info(
"txrmonbaseptr: addr - 0x%08x, val - 0x%08x",
774 ugeth_info(
"tstate : addr - 0x%08x, val - 0x%08x",
777 ugeth_info(
"iphoffset[0] : addr - 0x%08x, val - 0x%02x",
780 ugeth_info(
"iphoffset[1] : addr - 0x%08x, val - 0x%02x",
783 ugeth_info(
"iphoffset[2] : addr - 0x%08x, val - 0x%02x",
786 ugeth_info(
"iphoffset[3] : addr - 0x%08x, val - 0x%02x",
789 ugeth_info(
"iphoffset[4] : addr - 0x%08x, val - 0x%02x",
792 ugeth_info(
"iphoffset[5] : addr - 0x%08x, val - 0x%02x",
795 ugeth_info(
"iphoffset[6] : addr - 0x%08x, val - 0x%02x",
798 ugeth_info(
"iphoffset[7] : addr - 0x%08x, val - 0x%02x",
801 ugeth_info(
"vtagtable[0] : addr - 0x%08x, val - 0x%08x",
804 ugeth_info(
"vtagtable[1] : addr - 0x%08x, val - 0x%08x",
807 ugeth_info(
"vtagtable[2] : addr - 0x%08x, val - 0x%08x",
810 ugeth_info(
"vtagtable[3] : addr - 0x%08x, val - 0x%08x",
813 ugeth_info(
"vtagtable[4] : addr - 0x%08x, val - 0x%08x",
816 ugeth_info(
"vtagtable[5] : addr - 0x%08x, val - 0x%08x",
819 ugeth_info(
"vtagtable[6] : addr - 0x%08x, val - 0x%08x",
822 ugeth_info(
"vtagtable[7] : addr - 0x%08x, val - 0x%08x",
825 ugeth_info(
"tqptr : addr - 0x%08x, val - 0x%08x",
832 ugeth_info(
"remoder : addr - 0x%08x, val - 0x%08x",
835 ugeth_info(
"rqptr : addr - 0x%08x, val - 0x%08x",
838 ugeth_info(
"typeorlen : addr - 0x%08x, val - 0x%04x",
841 ugeth_info(
"rxgstpack : addr - 0x%08x, val - 0x%02x",
844 ugeth_info(
"rxrmonbaseptr : addr - 0x%08x, val - 0x%08x",
847 ugeth_info(
"intcoalescingptr: addr - 0x%08x, val - 0x%08x",
850 ugeth_info(
"rstate : addr - 0x%08x, val - 0x%02x",
853 ugeth_info(
"mrblr : addr - 0x%08x, val - 0x%04x",
856 ugeth_info(
"rbdqptr : addr - 0x%08x, val - 0x%08x",
859 ugeth_info(
"mflr : addr - 0x%08x, val - 0x%04x",
862 ugeth_info(
"minflr : addr - 0x%08x, val - 0x%04x",
865 ugeth_info(
"maxd1 : addr - 0x%08x, val - 0x%04x",
868 ugeth_info(
"maxd2 : addr - 0x%08x, val - 0x%04x",
871 ugeth_info(
"ecamptr : addr - 0x%08x, val - 0x%08x",
874 ugeth_info(
"l2qt : addr - 0x%08x, val - 0x%08x",
877 ugeth_info(
"l3qt[0] : addr - 0x%08x, val - 0x%08x",
880 ugeth_info(
"l3qt[1] : addr - 0x%08x, val - 0x%08x",
883 ugeth_info(
"l3qt[2] : addr - 0x%08x, val - 0x%08x",
886 ugeth_info(
"l3qt[3] : addr - 0x%08x, val - 0x%08x",
889 ugeth_info(
"l3qt[4] : addr - 0x%08x, val - 0x%08x",
892 ugeth_info(
"l3qt[5] : addr - 0x%08x, val - 0x%08x",
895 ugeth_info(
"l3qt[6] : addr - 0x%08x, val - 0x%08x",
898 ugeth_info(
"l3qt[7] : addr - 0x%08x, val - 0x%08x",
901 ugeth_info(
"vlantype : addr - 0x%08x, val - 0x%04x",
904 ugeth_info(
"vlantci : addr - 0x%08x, val - 0x%04x",
907 for (i = 0; i < 64; i++)
909 (
"addressfiltering[%d]: addr - 0x%08x, val - 0x%02x",
913 ugeth_info(
"exfGlobalParam : addr - 0x%08x, val - 0x%08x",
921 for (i = 0; i < ugeth->
ug_info->numQueuesTx; i++) {
953 for (i = 0; i < ugeth->
ug_info->numQueuesRx; i++) {
954 ugeth_info(
"RX IRQ coalescing table entry[%d]:", i);
959 (
"interruptcoalescingmaxvalue: addr - 0x%08x, val - 0x%08x",
961 coalescingentry[i].interruptcoalescingmaxvalue,
964 interruptcoalescingmaxvalue));
966 (
"interruptcoalescingcounter : addr - 0x%08x, val - 0x%08x",
968 coalescingentry[i].interruptcoalescingcounter,
971 interruptcoalescingcounter));
977 for (i = 0; i < ugeth->
ug_info->numQueuesRx; i++) {
982 (
"bdbaseptr : addr - 0x%08x, val - 0x%08x",
986 (
"bdptr : addr - 0x%08x, val - 0x%08x",
990 (
"externalbdbaseptr: addr - 0x%08x, val - 0x%08x",
995 (
"externalbdptr : addr - 0x%08x, val - 0x%08x",
1020 if (ugeth->
ug_info->rxExtendedFiltering) {
1023 if (ugeth->
ug_info->largestexternallookupkeysize ==
1024 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
1027 if (ugeth->
ug_info->largestexternallookupkeysize ==
1028 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
1033 dump_init_enet_entries(ugeth,
1039 dump_init_enet_entries(ugeth,
1048 static void init_default_reg_vals(
u32 __iomem *upsmr_register,
1057 static int init_half_duplex_params(
int alt_beb,
1058 int back_pressure_no_backoff,
1061 u8 alt_beb_truncation,
1062 u8 max_retransmissions,
1063 u8 collision_window,
1077 if (back_pressure_no_backoff)
1086 value |= collision_window;
1092 static int init_inter_frame_gap_params(
u8 non_btb_cs_ipg,
1102 if (non_btb_cs_ipg > non_btb_ipg)
1127 int rx_flow_control_enable,
1128 int tx_flow_control_enable,
1130 u16 extension_field,
1143 setbits32(upsmr_register, automatic_flow_control_mode);
1145 value =
in_be32(maccfg1_register);
1146 if (rx_flow_control_enable)
1148 if (tx_flow_control_enable)
1155 static int init_hw_statistics_gathering_mode(
int enable_hardware_statistics,
1156 int auto_zero_hardware_statistics,
1160 u16 uescr_value = 0;
1163 if (enable_hardware_statistics)
1164 setbits32(upsmr_register, UCC_GETH_UPSMR_HSE);
1167 uescr_value =
in_be16(uescr_register);
1171 if (auto_zero_hardware_statistics)
1173 out_be16(uescr_register, uescr_value);
1178 static int init_firmware_statistics_gathering_mode(
int
1179 enable_tx_firmware_statistics,
1180 int enable_rx_firmware_statistics,
1182 u32 tx_firmware_statistics_structure_address,
1184 u32 rx_firmware_statistics_structure_address,
1191 if (enable_tx_firmware_statistics) {
1193 tx_firmware_statistics_structure_address);
1197 if (enable_rx_firmware_statistics) {
1199 rx_firmware_statistics_structure_address);
1206 static int init_mac_station_addr_regs(
u8 address_byte_0,
1226 value |= (
u32) ((address_byte_2 << 0) & 0x000000FF);
1227 value |= (
u32) ((address_byte_3 << 8) & 0x0000FF00);
1228 value |= (
u32) ((address_byte_4 << 16) & 0x00FF0000);
1229 value |= (
u32) ((address_byte_5 << 24) & 0xFF000000);
1231 out_be32(macstnaddr1_register, value);
1240 value |= (
u32) ((address_byte_0 << 16) & 0x00FF0000);
1241 value |= (
u32) ((address_byte_1 << 24) & 0xFF000000);
1243 out_be32(macstnaddr2_register, value);
1248 static int init_check_frame_length_mode(
int length_check,
1253 value =
in_be32(maccfg2_register);
1264 static int init_preamble_length(
u8 preamble_length,
1267 if ((preamble_length < 3) || (preamble_length > 7))
1276 static int init_rx_parameters(
int reject_broadcast,
1277 int receive_short_frames,
1278 int promiscuous,
u32 __iomem *upsmr_register)
1282 value =
in_be32(upsmr_register);
1284 if (reject_broadcast)
1285 value |= UCC_GETH_UPSMR_BRO;
1287 value &= ~UCC_GETH_UPSMR_BRO;
1289 if (receive_short_frames)
1290 value |= UCC_GETH_UPSMR_RSH;
1292 value &= ~UCC_GETH_UPSMR_RSH;
1295 value |= UCC_GETH_UPSMR_PRO;
1297 value &= ~UCC_GETH_UPSMR_PRO;
1304 static int init_max_rx_buff_len(
u16 max_rx_buf_len,
1308 if ((max_rx_buf_len == 0) ||
1312 out_be16(mrblr_register, max_rx_buf_len);
1316 static int init_min_frame_len(
u16 min_frame_length,
1320 u16 mrblr_value = 0;
1322 mrblr_value =
in_be16(mrblr_register);
1323 if (min_frame_length >= (mrblr_value - 4))
1326 out_be16(minflr_register, min_frame_length);
1334 struct ucc_fast
__iomem *uf_regs;
1343 uf_regs = ugeth->
uccf->uf_regs;
1357 upsmr =
in_be32(&uf_regs->upsmr);
1358 upsmr &= ~(UCC_GETH_UPSMR_RPM | UCC_GETH_UPSMR_R10M |
1359 UCC_GETH_UPSMR_TBIM | UCC_GETH_UPSMR_RMM);
1367 upsmr |= UCC_GETH_UPSMR_RPM;
1370 upsmr |= UCC_GETH_UPSMR_R10M;
1374 upsmr |= UCC_GETH_UPSMR_RMM;
1379 upsmr |= UCC_GETH_UPSMR_TBIM;
1382 upsmr |= UCC_GETH_UPSMR_SGMM;
1395 ugeth_warn(
"TBI mode requires that the device "
1396 "tree specify a tbi-handle\n");
1409 ret_val = init_preamble_length(ug_info->
prel, &ug_regs->
maccfg2);
1412 ugeth_err(
"%s: Preamble length must be between 3 and 7 inclusive.",
1430 clrbits32(uccf->
p_uccm, UCC_GETH_UCCE_GRA);
1437 QE_CR_PROTOCOL_ETHERNET, 0);
1443 }
while (!(temp & UCC_GETH_UCCE_GRA) && --i);
1472 QE_CR_PROTOCOL_ETHERNET, 0);
1491 qe_issue_cmd(QE_RESTART_TX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET, 0);
1506 qe_issue_cmd(QE_RESTART_RX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
1523 ugeth_err(
"%s: ucc_num out of range.", __func__);
1532 if ((mode & COMM_DIR_TX) && (!enabled_tx) && uccf->
stopped_tx)
1533 ugeth_restart_tx(ugeth);
1534 if ((mode & COMM_DIR_RX) && (!enabled_rx) && uccf->
stopped_rx)
1535 ugeth_restart_rx(ugeth);
1543 static int ugeth_disable(
struct ucc_geth_private *ugeth,
enum comm_dir mode)
1552 ugeth_err(
"%s: ucc_num out of range.", __func__);
1558 ugeth_graceful_stop_tx(ugeth);
1562 ugeth_graceful_stop_rx(ugeth);
1575 netif_tx_disable(ugeth->
ndev);
1581 napi_disable(&ugeth->
napi);
1586 napi_enable(&ugeth->
napi);
1602 struct ucc_fast
__iomem *uf_regs;
1607 uf_regs = ugeth->
uccf->uf_regs;
1625 switch (phydev->
speed) {
1627 tempval = ((tempval &
1633 tempval = ((tempval &
1644 upsmr |= UCC_GETH_UPSMR_R10M;
1646 upsmr &= ~UCC_GETH_UPSMR_R10M;
1652 "%s: Ack! Speed (%d) is not 10/100/1000!",
1672 ugeth_quiesce(ugeth);
1673 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
1678 ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
1679 ugeth_activate(ugeth);
1700 static void uec_configure_serdes(
struct net_device *dev)
1707 dev_warn(&dev->
dev,
"SGMII mode requires that the device "
1708 "tree specify a tbi-handle\n");
1714 dev_err(&dev->
dev,
"error: Could not get TBI device\n");
1754 dev_err(&dev->
dev,
"Could not attach to PHY\n");
1759 uec_configure_serdes(dev);
1787 static int ugeth_82xx_filtering_clear_all_addr_in_hash(
struct ucc_geth_private *
1794 enum comm_dir comm_dir;
1808 addr_h = &(p_82xx_addr_filt->
gaddr_h);
1809 addr_l = &(p_82xx_addr_filt->
gaddr_l);
1813 addr_h = &(p_82xx_addr_filt->
iaddr_h);
1814 addr_l = &(p_82xx_addr_filt->
iaddr_l);
1822 comm_dir |= COMM_DIR_TX;
1824 comm_dir |= COMM_DIR_RX;
1826 ugeth_disable(ugeth, comm_dir);
1838 for (i = 0; i < num; i++)
1844 ugeth_enable(ugeth, comm_dir);
1849 static int ugeth_82xx_filtering_clear_addr_in_paddr(
struct ucc_geth_private *ugeth,
1853 return hw_clear_addr_in_paddr(ugeth, paddr_num);
1867 for (i = 0; i < ugeth->
ug_info->numQueuesRx; i++) {
1871 for (j = 0; j < ugeth->
ug_info->bdRingLenRx[
i]; j++) {
1883 bd +=
sizeof(
struct qe_bd);
1888 if (ugeth->
ug_info->uf_info.bd_mem_part ==
1891 else if (ugeth->
ug_info->uf_info.bd_mem_part ==
1910 for (i = 0; i < ugeth->
ug_info->numQueuesTx; i++) {
1914 for (j = 0; j < ugeth->
ug_info->bdRingLenTx[
i]; j++) {
1929 if (ugeth->
ug_info->uf_info.bd_mem_part ==
1932 else if (ugeth->
ug_info->uf_info.bd_mem_part ==
1996 return_init_enet_entries(ugeth,
2001 return_init_enet_entries(ugeth,
2009 ucc_geth_free_tx(ugeth);
2010 ucc_geth_free_rx(ugeth);
2023 static void ucc_geth_set_multi(
struct net_device *dev)
2027 struct ucc_fast
__iomem *uf_regs;
2030 ugeth = netdev_priv(dev);
2032 uf_regs = ugeth->
uccf->uf_regs;
2035 setbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
2037 clrbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
2041 p_rx_glbl_pram->addressfiltering;
2059 hw_add_addr_in_hash(ugeth, ha->
addr);
2080 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
2091 ucc_geth_memclean(ugeth);
2103 if (!((uf_info->
bd_mem_part == MEM_PART_SYSTEM) ||
2106 ugeth_err(
"%s: Bad memory partition value.",
2118 (
"%s: Rx BD ring length must be multiple of 4, no smaller than 8.",
2129 (
"%s: Tx BD ring length must be no smaller than 2.",
2140 (
"%s: max_rx_buf_length must be non-zero multiple of 128.",
2148 ugeth_err(
"%s: number of tx queues too large.", __func__);
2155 ugeth_err(
"%s: number of rx queues too large.", __func__);
2164 (
"%s: VLAN priority table entry must not be"
2165 " larger than number of Rx queues.",
2176 (
"%s: IP priority table entry must not be"
2177 " larger than number of Rx queues.",
2185 ugeth_err(
"%s: If cam mode is chosen, must supply cam ptr.",
2194 ugeth_err(
"%s: Number of station addresses greater than 1 "
2195 "not allowed in extended parsing mode.",
2203 uf_info->
uccm_mask |= (UCC_GETH_UCCE_RXF0 << i);
2206 uf_info->
uccm_mask |= (UCC_GETH_UCCE_TXB0 << i);
2210 ugeth_err(
"%s: Failed to init uccf.", __func__);
2218 ug_info->
riscTx = QE_RISC_ALLOCATION_FOUR_RISCS;
2219 ug_info->
riscRx = QE_RISC_ALLOCATION_FOUR_RISCS;
2225 ugeth_err(
"%s: Failed to ioremap regs.", __func__);
2248 length = ((ug_info->
bdRingLenTx[
j] *
sizeof(
struct qe_bd))
2251 if ((ug_info->
bdRingLenTx[j] *
sizeof(
struct qe_bd)) %
2252 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2264 align) & ~(align - 1));
2265 }
else if (uf_info->
bd_mem_part == MEM_PART_MURAM) {
2267 qe_muram_alloc(length,
2272 tx_bd_ring_offset[j]);
2277 (
"%s: Can not allocate memory for Tx bd rings.",
2283 ug_info->
bdRingLenTx[j] *
sizeof(
struct qe_bd)), 0,
2284 length - ug_info->
bdRingLenTx[j] *
sizeof(
struct qe_bd));
2291 ugeth->
ug_info->bdRingLenTx[j],
2296 ugeth_err(
"%s: Could not allocate tx_skbuff",
2301 for (i = 0; i < ugeth->
ug_info->bdRingLenTx[
j]; i++)
2311 bd +=
sizeof(
struct qe_bd);
2313 bd -=
sizeof(
struct qe_bd);
2334 length = ug_info->
bdRingLenRx[
j] *
sizeof(
struct qe_bd);
2344 align) & ~(align - 1));
2345 }
else if (uf_info->
bd_mem_part == MEM_PART_MURAM) {
2347 qe_muram_alloc(length,
2352 rx_bd_ring_offset[j]);
2357 (
"%s: Can not allocate memory for Rx bd rings.",
2367 ugeth->
ug_info->bdRingLenRx[j],
2372 ugeth_err(
"%s: Could not allocate rx_skbuff",
2377 for (i = 0; i < ugeth->
ug_info->bdRingLenRx[
j]; i++)
2387 bd +=
sizeof(
struct qe_bd);
2389 bd -=
sizeof(
struct qe_bd);
2404 struct ucc_fast
__iomem *uf_regs;
2408 u32 init_enet_pram_offset, cecr_subblock,
command;
2414 u8 numThreadsRxNumerical, numThreadsTxNumerical;
2425 numThreadsRxNumerical = 1;
2428 numThreadsRxNumerical = 2;
2431 numThreadsRxNumerical = 4;
2434 numThreadsRxNumerical = 6;
2437 numThreadsRxNumerical = 8;
2441 ugeth_err(
"%s: Bad number of Rx threads value.",
2449 numThreadsTxNumerical = 1;
2452 numThreadsTxNumerical = 2;
2455 numThreadsTxNumerical = 4;
2458 numThreadsTxNumerical = 6;
2461 numThreadsTxNumerical = 8;
2465 ugeth_err(
"%s: Bad number of Tx threads value.",
2482 init_default_reg_vals(&uf_regs->upsmr,
2487 init_rx_parameters(ug_info->
bro,
2488 ug_info->
rsh, ug_info->
pro, &uf_regs->upsmr);
2510 miminumInterFrameGapEnforcement,
2515 ugeth_err(
"%s: IPGIFG initialization parameter too large.",
2522 ret_val = init_half_duplex_params(ug_info->
altBeb,
2532 ugeth_err(
"%s: Half Duplex initialization parameter too large.",
2550 0, &uf_regs->upsmr, &ug_regs->
uescr);
2552 ret_val = ucc_geth_alloc_tx(ugeth);
2556 ret_val = ucc_geth_alloc_rx(ugeth);
2571 (
"%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
2577 tx_glbl_pram_offset);
2586 qe_muram_alloc(numThreadsTxNumerical *
2588 32 * (numThreadsTxNumerical == 1),
2593 (
"%s: Can not allocate DPRAM memory for p_thread_data_tx.",
2600 thread_dat_tx_offset);
2622 (
"%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
2629 send_q_mem_reg_offset);
2637 1) *
sizeof(
struct qe_bd);
2638 if (ugeth->
ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
2642 last_bd_completed_address,
2644 }
else if (ugeth->
ug_info->uf_info.bd_mem_part ==
2647 (
u32) immrbar_virt_to_phys(ugeth->
2650 last_bd_completed_address,
2651 (
u32) immrbar_virt_to_phys(endOfRing));
2665 (
"%s: Can not allocate DPRAM memory for p_scheduler.",
2708 qe_muram_alloc(
sizeof
2714 (
"%s: Can not allocate DPRAM memory for"
2715 " p_tx_fw_statistics_pram.",
2740 function_code = UCC_BMR_BO_BE | UCC_BMR_GBL;
2754 (
"%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
2760 rx_glbl_pram_offset);
2769 qe_muram_alloc(numThreadsRxNumerical *
2775 (
"%s: Can not allocate DPRAM memory for p_thread_data_rx.",
2782 thread_dat_rx_offset);
2792 qe_muram_alloc(
sizeof
2798 (
"%s: Can not allocate DPRAM memory for"
2799 " p_rx_fw_statistics_pram.", __func__);
2820 (
"%s: Can not allocate DPRAM memory for"
2821 " p_rx_irq_coalescing_tbl.", __func__);
2834 interruptcoalescingmaxvalue,
2837 interruptcoalescingcounter,
2858 l2qt |= (ug_info->
l2qt[i] << (28 - 4 * i));
2864 for (i = 0; i < 8; i++)
2865 l3qt |= (ug_info->
l3qt[j + i] << (28 - 4 * i));
2888 (
"%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
2895 rx_bd_qs_tbl_offset);
2906 if (ugeth->
ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
2909 }
else if (ugeth->
ug_info->uf_info.bd_mem_part ==
2912 (
u32) immrbar_virt_to_phys(ugeth->
2945 init_firmware_statistics_gathering_mode((ug_info->
2947 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX),
2949 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX),
2964 ugeth_err(
"%s: Null Extended Filtering Chain Pointer.",
2977 (
"%s: Can not allocate DPRAM memory for"
2978 " p_exf_glbl_param.", __func__);
2984 exf_glbl_param_offset);
2995 ugeth_82xx_filtering_clear_addr_in_paddr(ugeth, (
u8) j);
2999 p_rx_glbl_pram->addressfiltering;
3001 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
3003 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
3011 command = QE_INIT_TX_RX;
3024 (
"%s: Can not allocate memory for"
3025 " p_UccInitEnetParamShadows.", __func__);
3052 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE) &&
3054 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES) &&
3056 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) {
3058 ugeth_err(
"%s: Invalid largest External Lookup Key Size.",
3068 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
3072 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
3077 if ((ret_val = fill_init_enet_entries(ugeth, &(ugeth->
3078 p_init_enet_param_shadow->rxthread[0]),
3079 (
u8) (numThreadsRxNumerical + 1)
3082 ug_info->
riscRx, 1)) != 0) {
3084 ugeth_err(
"%s: Can not fill p_init_enet_param_shadow.",
3092 fill_init_enet_entries(ugeth,
3094 txthread[0]), numThreadsTxNumerical,
3097 ug_info->riscTx, 0)) != 0) {
3099 ugeth_err(
"%s: Can not fill p_init_enet_param_shadow.",
3106 if ((ret_val = rx_bd_buffer_set(ugeth, (
u8)
i)) != 0) {
3108 ugeth_err(
"%s: Can not fill Rx bds with buffers.",
3119 (
"%s: Can not allocate DPRAM memory for p_init_enet_pram.",
3153 qe_issue_cmd(command, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
3154 init_enet_pram_offset);
3157 qe_muram_free(init_enet_pram_offset);
3167 #ifdef CONFIG_UGETH_TX_ON_DEMAND
3173 unsigned long flags;
3182 bd = ugeth->
txBd[txQ];
3205 if (!(bd_status &
T_W))
3206 bd +=
sizeof(
struct qe_bd);
3212 if (bd == ugeth->
confBd[txQ]) {
3213 if (!netif_queue_stopped(dev))
3214 netif_stop_queue(dev);
3217 ugeth->
txBd[txQ] = bd;
3219 skb_tx_timestamp(skb);
3230 #ifdef CONFIG_UGETH_TX_ON_DEMAND
3232 out_be16(uccf->p_utodr, UCC_FAST_TOD);
3234 spin_unlock_irqrestore(&ugeth->
lock, flags);
3253 bd = ugeth->
rxBd[rxQ];
3258 while (!((bd_status & (
R_E)) || (--rx_work_limit < 0))) {
3266 (!(bd_status & (
R_F |
R_L))) ||
3269 ugeth_err(
"%s, %d: ERROR!!! skb - 0x%08x",
3270 __func__, __LINE__, (
u32)
skb);
3274 dev->
stats.rx_dropped++;
3276 dev->
stats.rx_packets++;
3290 skb = get_new_skb(ugeth, bd);
3293 ugeth_warn(
"%s: No Rx Data Buffer", __func__);
3294 dev->
stats.rx_dropped++;
3305 if (bd_status &
R_W)
3308 bd +=
sizeof(
struct qe_bd);
3313 ugeth->
rxBd[rxQ] = bd;
3328 while ((bd_status &
T_R) == 0) {
3339 dev->
stats.tx_packets++;
3349 if (netif_queue_stopped(dev))
3350 netif_wake_queue(dev);
3353 if (!(bd_status & T_W))
3354 bd +=
sizeof(
struct qe_bd);
3372 spin_lock(&ugeth->
lock);
3374 ucc_geth_tx(ugeth->
ndev, i);
3375 spin_unlock(&ugeth->
lock);
3379 howmany += ucc_geth_rx(ugeth, i, budget - howmany);
3381 if (howmany < budget) {
3411 if (napi_schedule_prep(&ugeth->
napi)) {
3420 if (ucce & UCC_GETH_UCCE_BSY)
3421 dev->
stats.rx_errors++;
3422 if (ucce & UCC_GETH_UCCE_TXE)
3423 dev->
stats.tx_errors++;
3429 #ifdef CONFIG_NET_POLL_CONTROLLER
3435 static void ucc_netpoll(
struct net_device *dev)
3438 int irq = ugeth->
ug_info->uf_info.irq;
3441 ucc_geth_irq_handler(irq, dev);
3446 static int ucc_geth_set_mac_addr(
struct net_device *dev,
void *
p)
3451 if (!is_valid_ether_addr(addr->
sa_data))
3460 if (!netif_running(dev))
3463 spin_lock_irq(&ugeth->
lock);
3464 init_mac_station_addr_regs(dev->
dev_addr[0],
3471 &ugeth->
ug_regs->macstnaddr2);
3472 spin_unlock_irq(&ugeth->
lock);
3482 err = ucc_struct_init(ugeth);
3485 ugeth_err(
"%s: Cannot configure internal struct, "
3486 "aborting.", dev->
name);
3490 err = ucc_geth_startup(ugeth);
3493 ugeth_err(
"%s: Cannot configure net device, aborting.",
3498 err = adjust_enet_interface(ugeth);
3501 ugeth_err(
"%s: Cannot configure net device, aborting.",
3508 init_mac_station_addr_regs(dev->
dev_addr[0],
3515 &ugeth->
ug_regs->macstnaddr2);
3517 err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
3520 ugeth_err(
"%s: Cannot enable net device, aborting.", dev->
name);
3526 ucc_geth_stop(ugeth);
3532 static int ucc_geth_open(
struct net_device *dev)
3542 ugeth_err(
"%s: Multicast address used for station "
3543 "address - is this what you wanted?",
3548 err = init_phy(dev);
3551 ugeth_err(
"%s: Cannot initialize PHY, aborting.",
3556 err = ucc_geth_init_mac(ugeth);
3559 ugeth_err(
"%s: Cannot initialize MAC, aborting.",
3565 0,
"UCC Geth", dev);
3568 ugeth_err(
"%s: Cannot get IRQ for net device, aborting.",
3574 napi_enable(&ugeth->
napi);
3575 netif_start_queue(dev);
3578 qe_alive_during_sleep() || ugeth->
phydev->irq);
3584 ucc_geth_stop(ugeth);
3589 static int ucc_geth_close(
struct net_device *dev)
3595 napi_disable(&ugeth->
napi);
3598 ucc_geth_stop(ugeth);
3604 netif_stop_queue(dev);
3620 dev->
stats.tx_errors++;
3622 ugeth_dump_regs(ugeth);
3629 netif_tx_stop_all_queues(dev);
3630 ucc_geth_stop(ugeth);
3631 ucc_geth_init_mac(ugeth);
3634 netif_tx_start_all_queues(dev);
3637 netif_tx_schedule_all(dev);
3644 static void ucc_geth_timeout(
struct net_device *dev)
3659 if (!netif_running(ndev))
3663 napi_disable(&ugeth->
napi);
3669 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
3672 setbits32(ugeth->
uccf->p_uccm, UCC_GETH_UCCE_MPD);
3688 if (!netif_running(ndev))
3691 if (qe_alive_during_sleep()) {
3695 clrbits32(ugeth->
uccf->p_uccm, UCC_GETH_UCCE_MPD);
3697 ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
3703 ucc_geth_memclean(ugeth);
3705 err = ucc_geth_init_mac(ugeth);
3707 ugeth_err(
"%s: Cannot initialize MAC, aborting.",
3720 napi_enable(&ugeth->
napi);
3727 #define ucc_geth_suspend NULL
3728 #define ucc_geth_resume NULL
3731 static phy_interface_t to_phy_interface(
const char *phy_connection_type)
3733 if (
strcasecmp(phy_connection_type,
"mii") == 0)
3735 if (
strcasecmp(phy_connection_type,
"gmii") == 0)
3737 if (
strcasecmp(phy_connection_type,
"tbi") == 0)
3739 if (
strcasecmp(phy_connection_type,
"rmii") == 0)
3741 if (
strcasecmp(phy_connection_type,
"rgmii") == 0)
3743 if (
strcasecmp(phy_connection_type,
"rgmii-id") == 0)
3745 if (
strcasecmp(phy_connection_type,
"rgmii-txid") == 0)
3747 if (
strcasecmp(phy_connection_type,
"rgmii-rxid") == 0)
3749 if (
strcasecmp(phy_connection_type,
"rtbi") == 0)
3751 if (
strcasecmp(phy_connection_type,
"sgmii") == 0)
3761 if (!netif_running(dev))
3771 .ndo_open = ucc_geth_open,
3772 .ndo_stop = ucc_geth_close,
3773 .ndo_start_xmit = ucc_geth_start_xmit,
3775 .ndo_set_mac_address = ucc_geth_set_mac_addr,
3777 .ndo_set_rx_mode = ucc_geth_set_multi,
3778 .ndo_tx_timeout = ucc_geth_timeout,
3779 .ndo_do_ioctl = ucc_geth_ioctl,
3780 #ifdef CONFIG_NET_POLL_CONTROLLER
3781 .ndo_poll_controller = ucc_netpoll,
3793 int err, ucc_num, max_speed = 0;
3794 const unsigned int *prop;
3798 static const int enet_to_speed[] = {
3821 ucc_num = *prop - 1;
3822 if ((ucc_num < 0) || (ucc_num > 7))
3826 if (ug_info ==
NULL) {
3828 ugeth_err(
"%s: [%d] Missing additional data!",
3833 ug_info->
uf_info.ucc_num = ucc_num;
3838 if ((ug_info->
uf_info.rx_clock < QE_CLK_NONE) ||
3839 (ug_info->
uf_info.rx_clock > QE_CLK24)) {
3841 "ucc_geth: invalid rx-clock-name property\n");
3850 "ucc_geth: missing rx-clock-name property\n");
3853 if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
3855 "ucc_geth: invalid rx-clock propperty\n");
3858 ug_info->
uf_info.rx_clock = *prop;
3864 if ((ug_info->
uf_info.tx_clock < QE_CLK_NONE) ||
3865 (ug_info->
uf_info.tx_clock > QE_CLK24)) {
3867 "ucc_geth: invalid tx-clock-name property\n");
3874 "ucc_geth: missing tx-clock-name property\n");
3877 if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
3879 "ucc_geth: invalid tx-clock property\n");
3882 ug_info->
uf_info.tx_clock = *prop;
3903 phy_interface = enet_to_phy_interface[*prop];
3904 max_speed = enet_to_speed[*prop];
3908 phy_interface = to_phy_interface((
const char *)prop);
3913 switch (phy_interface) {
3945 if ((snums == 76) || (snums == 46))
3957 dev = alloc_etherdev(
sizeof(*ugeth));
3962 ugeth = netdev_priv(dev);
3991 ugeth_err(
"%s: Cannot register net device, aborting.",
4002 ugeth->
dev = device;
4011 struct device *device = &ofdev->
dev;
4017 ucc_geth_memclean(ugeth);
4026 .compatible =
"ucc_geth",
4037 .of_match_table = ucc_geth_match,
4039 .probe = ucc_geth_probe,
4040 .remove = ucc_geth_remove,
4045 static int __init ucc_geth_init(
void)
4051 for (i = 0; i < 8; i++)
4053 sizeof(ugeth_primary_info));
4060 static void __exit ucc_geth_exit(
void)