Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1 | /* |
Haiying Wang | 047584c | 2009-06-02 04:04:15 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006-2009 Freescale Semicondutor, Inc. All rights reserved. |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3 | * |
| 4 | * Author: Shlomi Gridish <gridish@freescale.com> |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 5 | * Li Yang <leoli@freescale.com> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 6 | * |
| 7 | * Description: |
| 8 | * QE UCC Gigabit Ethernet Driver |
| 9 | * |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 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. |
| 14 | */ |
| 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> |
| 25 | #include <linux/mm.h> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 26 | #include <linux/dma-mapping.h> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 27 | #include <linux/mii.h> |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 28 | #include <linux/phy.h> |
Timur Tabi | df19b6b | 2007-01-09 12:31:38 -0600 | [diff] [blame] | 29 | #include <linux/workqueue.h> |
Grant Likely | 0b9da33 | 2009-04-25 12:53:23 +0000 | [diff] [blame] | 30 | #include <linux/of_mdio.h> |
David Daney | 4b6ba8a | 2010-10-26 15:07:13 -0700 | [diff] [blame] | 31 | #include <linux/of_net.h> |
Stephen Rothwell | 55b6c8e | 2008-05-23 16:28:54 +1000 | [diff] [blame] | 32 | #include <linux/of_platform.h> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 33 | |
| 34 | #include <asm/uaccess.h> |
| 35 | #include <asm/irq.h> |
| 36 | #include <asm/io.h> |
| 37 | #include <asm/immap_qe.h> |
| 38 | #include <asm/qe.h> |
| 39 | #include <asm/ucc.h> |
| 40 | #include <asm/ucc_fast.h> |
Liu Yu-B13201 | 81abb43 | 2010-01-13 22:13:18 +0000 | [diff] [blame] | 41 | #include <asm/machdep.h> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 42 | |
| 43 | #include "ucc_geth.h" |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 44 | #include "fsl_pq_mdio.h" |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 45 | |
| 46 | #undef DEBUG |
| 47 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 48 | #define ugeth_printk(level, format, arg...) \ |
| 49 | printk(level format "\n", ## arg) |
| 50 | |
| 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) |
| 59 | |
| 60 | #ifdef UGETH_VERBOSE_DEBUG |
| 61 | #define ugeth_vdbg ugeth_dbg |
| 62 | #else |
| 63 | #define ugeth_vdbg(fmt, args...) do { } while (0) |
| 64 | #endif /* UGETH_VERBOSE_DEBUG */ |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 65 | #define UGETH_MSG_DEFAULT (NETIF_MSG_IFUP << 1 ) - 1 |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 66 | |
Emil Medve | 88a15f2 | 2007-10-15 08:43:50 -0500 | [diff] [blame] | 67 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 68 | static DEFINE_SPINLOCK(ugeth_lock); |
| 69 | |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 70 | static struct { |
| 71 | u32 msg_enable; |
| 72 | } debug = { -1 }; |
| 73 | |
| 74 | module_param_named(debug, debug.msg_enable, int, 0); |
| 75 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 0xffff=all)"); |
| 76 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 77 | static struct ucc_geth_info ugeth_primary_info = { |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 78 | .uf_info = { |
| 79 | .bd_mem_part = MEM_PART_SYSTEM, |
| 80 | .rtsm = UCC_FAST_SEND_IDLES_BETWEEN_FRAMES, |
| 81 | .max_rx_buf_length = 1536, |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 82 | /* adjusted at startup if max-speed 1000 */ |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 83 | .urfs = UCC_GETH_URFS_INIT, |
| 84 | .urfet = UCC_GETH_URFET_INIT, |
| 85 | .urfset = UCC_GETH_URFSET_INIT, |
| 86 | .utfs = UCC_GETH_UTFS_INIT, |
| 87 | .utfet = UCC_GETH_UTFET_INIT, |
| 88 | .utftt = UCC_GETH_UTFTT_INIT, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 89 | .ufpt = 256, |
| 90 | .mode = UCC_FAST_PROTOCOL_MODE_ETHERNET, |
| 91 | .ttx_trx = UCC_FAST_GUMR_TRANSPARENT_TTX_TRX_NORMAL, |
| 92 | .tenc = UCC_FAST_TX_ENCODING_NRZ, |
| 93 | .renc = UCC_FAST_RX_ENCODING_NRZ, |
| 94 | .tcrc = UCC_FAST_16_BIT_CRC, |
| 95 | .synl = UCC_FAST_SYNC_LEN_NOT_USED, |
| 96 | }, |
| 97 | .numQueuesTx = 1, |
| 98 | .numQueuesRx = 1, |
| 99 | .extendedFilteringChainPointer = ((uint32_t) NULL), |
| 100 | .typeorlen = 3072 /*1536 */ , |
| 101 | .nonBackToBackIfgPart1 = 0x40, |
| 102 | .nonBackToBackIfgPart2 = 0x60, |
| 103 | .miminumInterFrameGapEnforcement = 0x50, |
| 104 | .backToBackInterFrameGap = 0x60, |
| 105 | .mblinterval = 128, |
| 106 | .nortsrbytetime = 5, |
| 107 | .fracsiz = 1, |
| 108 | .strictpriorityq = 0xff, |
| 109 | .altBebTruncation = 0xa, |
| 110 | .excessDefer = 1, |
| 111 | .maxRetransmission = 0xf, |
| 112 | .collisionWindow = 0x37, |
| 113 | .receiveFlowControl = 1, |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 114 | .transmitFlowControl = 1, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 115 | .maxGroupAddrInHash = 4, |
| 116 | .maxIndAddrInHash = 4, |
| 117 | .prel = 7, |
| 118 | .maxFrameLength = 1518, |
| 119 | .minFrameLength = 64, |
| 120 | .maxD1Length = 1520, |
| 121 | .maxD2Length = 1520, |
| 122 | .vlantype = 0x8100, |
| 123 | .ecamptr = ((uint32_t) NULL), |
| 124 | .eventRegMask = UCCE_OTHER, |
| 125 | .pausePeriod = 0xf000, |
| 126 | .interruptcoalescingmaxvalue = {1, 1, 1, 1, 1, 1, 1, 1}, |
| 127 | .bdRingLenTx = { |
| 128 | TX_BD_RING_LEN, |
| 129 | TX_BD_RING_LEN, |
| 130 | TX_BD_RING_LEN, |
| 131 | TX_BD_RING_LEN, |
| 132 | TX_BD_RING_LEN, |
| 133 | TX_BD_RING_LEN, |
| 134 | TX_BD_RING_LEN, |
| 135 | TX_BD_RING_LEN}, |
| 136 | |
| 137 | .bdRingLenRx = { |
| 138 | RX_BD_RING_LEN, |
| 139 | RX_BD_RING_LEN, |
| 140 | RX_BD_RING_LEN, |
| 141 | RX_BD_RING_LEN, |
| 142 | RX_BD_RING_LEN, |
| 143 | RX_BD_RING_LEN, |
| 144 | RX_BD_RING_LEN, |
| 145 | RX_BD_RING_LEN}, |
| 146 | |
| 147 | .numStationAddresses = UCC_GETH_NUM_OF_STATION_ADDRESSES_1, |
| 148 | .largestexternallookupkeysize = |
| 149 | QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE, |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 150 | .statisticsMode = UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE | |
| 151 | UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX | |
| 152 | UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 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, |
Joakim Tjernlund | ffea31e | 2008-03-06 18:48:46 +0800 | [diff] [blame] | 158 | .numThreadsTx = UCC_GETH_NUM_OF_THREADS_1, |
| 159 | .numThreadsRx = UCC_GETH_NUM_OF_THREADS_1, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 160 | .riscTx = QE_RISC_ALLOCATION_RISC1_AND_RISC2, |
| 161 | .riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2, |
| 162 | }; |
| 163 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 164 | static struct ucc_geth_info ugeth_info[8]; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 165 | |
| 166 | #ifdef DEBUG |
| 167 | static void mem_disp(u8 *addr, int size) |
| 168 | { |
| 169 | u8 *i; |
| 170 | int size16Aling = (size >> 4) << 4; |
| 171 | int size4Aling = (size >> 2) << 2; |
| 172 | int notAlign = 0; |
| 173 | if (size % 16) |
| 174 | notAlign = 1; |
| 175 | |
| 176 | for (i = addr; (u32) i < (u32) addr + size16Aling; i += 16) |
| 177 | printk("0x%08x: %08x %08x %08x %08x\r\n", |
| 178 | (u32) i, |
| 179 | *((u32 *) (i)), |
| 180 | *((u32 *) (i + 4)), |
| 181 | *((u32 *) (i + 8)), *((u32 *) (i + 12))); |
| 182 | if (notAlign == 1) |
| 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))); |
| 188 | if (notAlign == 1) |
| 189 | printk("\r\n"); |
| 190 | } |
| 191 | #endif /* DEBUG */ |
| 192 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 193 | static struct list_head *dequeue(struct list_head *lh) |
| 194 | { |
| 195 | unsigned long flags; |
| 196 | |
Scott Wood | 1083cfe | 2006-12-07 13:31:07 -0600 | [diff] [blame] | 197 | spin_lock_irqsave(&ugeth_lock, flags); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 198 | if (!list_empty(lh)) { |
| 199 | struct list_head *node = lh->next; |
| 200 | list_del(node); |
Scott Wood | 1083cfe | 2006-12-07 13:31:07 -0600 | [diff] [blame] | 201 | spin_unlock_irqrestore(&ugeth_lock, flags); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 202 | return node; |
| 203 | } else { |
Scott Wood | 1083cfe | 2006-12-07 13:31:07 -0600 | [diff] [blame] | 204 | spin_unlock_irqrestore(&ugeth_lock, flags); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 205 | return NULL; |
| 206 | } |
| 207 | } |
| 208 | |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 209 | static struct sk_buff *get_new_skb(struct ucc_geth_private *ugeth, |
| 210 | u8 __iomem *bd) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 211 | { |
| 212 | struct sk_buff *skb = NULL; |
| 213 | |
Anton Vorontsov | 50f238f | 2009-07-07 08:38:42 +0000 | [diff] [blame] | 214 | skb = __skb_dequeue(&ugeth->rx_recycle); |
| 215 | if (!skb) |
| 216 | skb = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length + |
| 217 | UCC_GETH_RX_DATA_BUF_ALIGNMENT); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 218 | if (skb == NULL) |
| 219 | return NULL; |
| 220 | |
| 221 | /* We need the data buffer to be aligned properly. We will reserve |
| 222 | * as many bytes as needed to align the data properly |
| 223 | */ |
| 224 | skb_reserve(skb, |
| 225 | UCC_GETH_RX_DATA_BUF_ALIGNMENT - |
| 226 | (((unsigned)skb->data) & (UCC_GETH_RX_DATA_BUF_ALIGNMENT - |
| 227 | 1))); |
| 228 | |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 229 | skb->dev = ugeth->ndev; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 230 | |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 231 | out_be32(&((struct qe_bd __iomem *)bd)->buf, |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 232 | dma_map_single(ugeth->dev, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 233 | skb->data, |
| 234 | ugeth->ug_info->uf_info.max_rx_buf_length + |
| 235 | UCC_GETH_RX_DATA_BUF_ALIGNMENT, |
| 236 | DMA_FROM_DEVICE)); |
| 237 | |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 238 | out_be32((u32 __iomem *)bd, |
| 239 | (R_E | R_I | (in_be32((u32 __iomem*)bd) & R_W))); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 240 | |
| 241 | return skb; |
| 242 | } |
| 243 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 244 | static int rx_bd_buffer_set(struct ucc_geth_private *ugeth, u8 rxQ) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 245 | { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 246 | u8 __iomem *bd; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 247 | u32 bd_status; |
| 248 | struct sk_buff *skb; |
| 249 | int i; |
| 250 | |
| 251 | bd = ugeth->p_rx_bd_ring[rxQ]; |
| 252 | i = 0; |
| 253 | |
| 254 | do { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 255 | bd_status = in_be32((u32 __iomem *)bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 256 | skb = get_new_skb(ugeth, bd); |
| 257 | |
| 258 | if (!skb) /* If can not allocate data buffer, |
| 259 | abort. Cleanup will be elsewhere */ |
| 260 | return -ENOMEM; |
| 261 | |
| 262 | ugeth->rx_skbuff[rxQ][i] = skb; |
| 263 | |
| 264 | /* advance the BD pointer */ |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 265 | bd += sizeof(struct qe_bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 266 | i++; |
| 267 | } while (!(bd_status & R_W)); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 272 | static int fill_init_enet_entries(struct ucc_geth_private *ugeth, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 273 | u32 *p_start, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 274 | u8 num_entries, |
| 275 | u32 thread_size, |
| 276 | u32 thread_alignment, |
Haiying Wang | 345f842 | 2009-04-29 14:14:35 -0400 | [diff] [blame] | 277 | unsigned int risc, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 278 | int skip_page_for_first_entry) |
| 279 | { |
| 280 | u32 init_enet_offset; |
| 281 | u8 i; |
| 282 | int snum; |
| 283 | |
| 284 | for (i = 0; i < num_entries; i++) { |
| 285 | if ((snum = qe_get_snum()) < 0) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 286 | if (netif_msg_ifup(ugeth)) |
| 287 | ugeth_err("fill_init_enet_entries: Can not get SNUM."); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 288 | return snum; |
| 289 | } |
| 290 | if ((i == 0) && skip_page_for_first_entry) |
| 291 | /* First entry of Rx does not have page */ |
| 292 | init_enet_offset = 0; |
| 293 | else { |
| 294 | init_enet_offset = |
| 295 | qe_muram_alloc(thread_size, thread_alignment); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 296 | if (IS_ERR_VALUE(init_enet_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 297 | if (netif_msg_ifup(ugeth)) |
| 298 | ugeth_err("fill_init_enet_entries: Can not allocate DPRAM memory."); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 299 | qe_put_snum((u8) snum); |
| 300 | return -ENOMEM; |
| 301 | } |
| 302 | } |
| 303 | *(p_start++) = |
| 304 | ((u8) snum << ENET_INIT_PARAM_SNUM_SHIFT) | init_enet_offset |
| 305 | | risc; |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 311 | static int return_init_enet_entries(struct ucc_geth_private *ugeth, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 312 | u32 *p_start, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 313 | u8 num_entries, |
Haiying Wang | 345f842 | 2009-04-29 14:14:35 -0400 | [diff] [blame] | 314 | unsigned int risc, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 315 | int skip_page_for_first_entry) |
| 316 | { |
| 317 | u32 init_enet_offset; |
| 318 | u8 i; |
| 319 | int snum; |
| 320 | |
| 321 | for (i = 0; i < num_entries; i++) { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 322 | u32 val = *p_start; |
| 323 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 324 | /* Check that this entry was actually valid -- |
| 325 | needed in case failed in allocations */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 326 | if ((val & ENET_INIT_PARAM_RISC_MASK) == risc) { |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 327 | snum = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 328 | (u32) (val & ENET_INIT_PARAM_SNUM_MASK) >> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 329 | ENET_INIT_PARAM_SNUM_SHIFT; |
| 330 | qe_put_snum((u8) snum); |
| 331 | if (!((i == 0) && skip_page_for_first_entry)) { |
| 332 | /* First entry of Rx does not have page */ |
| 333 | init_enet_offset = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 334 | (val & ENET_INIT_PARAM_PTR_MASK); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 335 | qe_muram_free(init_enet_offset); |
| 336 | } |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 337 | *p_start++ = 0; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | #ifdef DEBUG |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 345 | static int dump_init_enet_entries(struct ucc_geth_private *ugeth, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 346 | u32 __iomem *p_start, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 347 | u8 num_entries, |
| 348 | u32 thread_size, |
Haiying Wang | 345f842 | 2009-04-29 14:14:35 -0400 | [diff] [blame] | 349 | unsigned int risc, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 350 | int skip_page_for_first_entry) |
| 351 | { |
| 352 | u32 init_enet_offset; |
| 353 | u8 i; |
| 354 | int snum; |
| 355 | |
| 356 | for (i = 0; i < num_entries; i++) { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 357 | u32 val = in_be32(p_start); |
| 358 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 359 | /* Check that this entry was actually valid -- |
| 360 | needed in case failed in allocations */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 361 | if ((val & ENET_INIT_PARAM_RISC_MASK) == risc) { |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 362 | snum = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 363 | (u32) (val & ENET_INIT_PARAM_SNUM_MASK) >> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 364 | ENET_INIT_PARAM_SNUM_SHIFT; |
| 365 | qe_put_snum((u8) snum); |
| 366 | if (!((i == 0) && skip_page_for_first_entry)) { |
| 367 | /* First entry of Rx does not have page */ |
| 368 | init_enet_offset = |
| 369 | (in_be32(p_start) & |
| 370 | ENET_INIT_PARAM_PTR_MASK); |
| 371 | ugeth_info("Init enet entry %d:", i); |
| 372 | ugeth_info("Base address: 0x%08x", |
| 373 | (u32) |
| 374 | qe_muram_addr(init_enet_offset)); |
| 375 | mem_disp(qe_muram_addr(init_enet_offset), |
| 376 | thread_size); |
| 377 | } |
| 378 | p_start++; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | #endif |
| 385 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 386 | static void put_enet_addr_container(struct enet_addr_container *enet_addr_cont) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 387 | { |
| 388 | kfree(enet_addr_cont); |
| 389 | } |
| 390 | |
Timur Tabi | df19b6b | 2007-01-09 12:31:38 -0600 | [diff] [blame] | 391 | static void set_mac_addr(__be16 __iomem *reg, u8 *mac) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 392 | { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 393 | out_be16(®[0], ((u16)mac[5] << 8) | mac[4]); |
| 394 | out_be16(®[1], ((u16)mac[3] << 8) | mac[2]); |
| 395 | out_be16(®[2], ((u16)mac[1] << 8) | mac[0]); |
| 396 | } |
| 397 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 398 | static int hw_clear_addr_in_paddr(struct ucc_geth_private *ugeth, u8 paddr_num) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 399 | { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 400 | struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 401 | |
| 402 | if (!(paddr_num < NUM_OF_PADDRS)) { |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 403 | ugeth_warn("%s: Illagel paddr_num.", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 404 | return -EINVAL; |
| 405 | } |
| 406 | |
| 407 | p_82xx_addr_filt = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 408 | (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->p_rx_glbl_pram-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 409 | addressfiltering; |
| 410 | |
| 411 | /* Writing address ff.ff.ff.ff.ff.ff disables address |
| 412 | recognition for this register */ |
| 413 | out_be16(&p_82xx_addr_filt->paddr[paddr_num].h, 0xffff); |
| 414 | out_be16(&p_82xx_addr_filt->paddr[paddr_num].m, 0xffff); |
| 415 | out_be16(&p_82xx_addr_filt->paddr[paddr_num].l, 0xffff); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 420 | static void hw_add_addr_in_hash(struct ucc_geth_private *ugeth, |
| 421 | u8 *p_enet_addr) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 422 | { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 423 | struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 424 | u32 cecr_subblock; |
| 425 | |
| 426 | p_82xx_addr_filt = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 427 | (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->p_rx_glbl_pram-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 428 | addressfiltering; |
| 429 | |
| 430 | cecr_subblock = |
| 431 | ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num); |
| 432 | |
| 433 | /* Ethernet frames are defined in Little Endian mode, |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 434 | therefore to insert */ |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 435 | /* the address to the hash (Big Endian mode), we reverse the bytes.*/ |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 436 | |
| 437 | set_mac_addr(&p_82xx_addr_filt->taddr.h, p_enet_addr); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 438 | |
| 439 | qe_issue_cmd(QE_SET_GROUP_ADDRESS, cecr_subblock, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 440 | QE_CR_PROTOCOL_ETHERNET, 0); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 443 | static inline int compare_addr(u8 **addr1, u8 **addr2) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 444 | { |
| 445 | return memcmp(addr1, addr2, ENET_NUM_OCTETS_PER_ADDRESS); |
| 446 | } |
| 447 | |
| 448 | #ifdef DEBUG |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 449 | static void get_statistics(struct ucc_geth_private *ugeth, |
| 450 | struct ucc_geth_tx_firmware_statistics * |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 451 | tx_firmware_statistics, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 452 | struct ucc_geth_rx_firmware_statistics * |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 453 | rx_firmware_statistics, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 454 | struct ucc_geth_hardware_statistics *hardware_statistics) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 455 | { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 456 | struct ucc_fast __iomem *uf_regs; |
| 457 | struct ucc_geth __iomem *ug_regs; |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 458 | struct ucc_geth_tx_firmware_statistics_pram *p_tx_fw_statistics_pram; |
| 459 | struct ucc_geth_rx_firmware_statistics_pram *p_rx_fw_statistics_pram; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 460 | |
| 461 | ug_regs = ugeth->ug_regs; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 462 | uf_regs = (struct ucc_fast __iomem *) ug_regs; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 463 | p_tx_fw_statistics_pram = ugeth->p_tx_fw_statistics_pram; |
| 464 | p_rx_fw_statistics_pram = ugeth->p_rx_fw_statistics_pram; |
| 465 | |
| 466 | /* Tx firmware only if user handed pointer and driver actually |
| 467 | gathers Tx firmware statistics */ |
| 468 | if (tx_firmware_statistics && p_tx_fw_statistics_pram) { |
| 469 | tx_firmware_statistics->sicoltx = |
| 470 | in_be32(&p_tx_fw_statistics_pram->sicoltx); |
| 471 | tx_firmware_statistics->mulcoltx = |
| 472 | in_be32(&p_tx_fw_statistics_pram->mulcoltx); |
| 473 | tx_firmware_statistics->latecoltxfr = |
| 474 | in_be32(&p_tx_fw_statistics_pram->latecoltxfr); |
| 475 | tx_firmware_statistics->frabortduecol = |
| 476 | in_be32(&p_tx_fw_statistics_pram->frabortduecol); |
| 477 | tx_firmware_statistics->frlostinmactxer = |
| 478 | in_be32(&p_tx_fw_statistics_pram->frlostinmactxer); |
| 479 | tx_firmware_statistics->carriersenseertx = |
| 480 | in_be32(&p_tx_fw_statistics_pram->carriersenseertx); |
| 481 | tx_firmware_statistics->frtxok = |
| 482 | in_be32(&p_tx_fw_statistics_pram->frtxok); |
| 483 | tx_firmware_statistics->txfrexcessivedefer = |
| 484 | in_be32(&p_tx_fw_statistics_pram->txfrexcessivedefer); |
| 485 | tx_firmware_statistics->txpkts256 = |
| 486 | in_be32(&p_tx_fw_statistics_pram->txpkts256); |
| 487 | tx_firmware_statistics->txpkts512 = |
| 488 | in_be32(&p_tx_fw_statistics_pram->txpkts512); |
| 489 | tx_firmware_statistics->txpkts1024 = |
| 490 | in_be32(&p_tx_fw_statistics_pram->txpkts1024); |
| 491 | tx_firmware_statistics->txpktsjumbo = |
| 492 | in_be32(&p_tx_fw_statistics_pram->txpktsjumbo); |
| 493 | } |
| 494 | |
| 495 | /* Rx firmware only if user handed pointer and driver actually |
| 496 | * gathers Rx firmware statistics */ |
| 497 | if (rx_firmware_statistics && p_rx_fw_statistics_pram) { |
| 498 | int i; |
| 499 | rx_firmware_statistics->frrxfcser = |
| 500 | in_be32(&p_rx_fw_statistics_pram->frrxfcser); |
| 501 | rx_firmware_statistics->fraligner = |
| 502 | in_be32(&p_rx_fw_statistics_pram->fraligner); |
| 503 | rx_firmware_statistics->inrangelenrxer = |
| 504 | in_be32(&p_rx_fw_statistics_pram->inrangelenrxer); |
| 505 | rx_firmware_statistics->outrangelenrxer = |
| 506 | in_be32(&p_rx_fw_statistics_pram->outrangelenrxer); |
| 507 | rx_firmware_statistics->frtoolong = |
| 508 | in_be32(&p_rx_fw_statistics_pram->frtoolong); |
| 509 | rx_firmware_statistics->runt = |
| 510 | in_be32(&p_rx_fw_statistics_pram->runt); |
| 511 | rx_firmware_statistics->verylongevent = |
| 512 | in_be32(&p_rx_fw_statistics_pram->verylongevent); |
| 513 | rx_firmware_statistics->symbolerror = |
| 514 | in_be32(&p_rx_fw_statistics_pram->symbolerror); |
| 515 | rx_firmware_statistics->dropbsy = |
| 516 | in_be32(&p_rx_fw_statistics_pram->dropbsy); |
| 517 | for (i = 0; i < 0x8; i++) |
| 518 | rx_firmware_statistics->res0[i] = |
| 519 | p_rx_fw_statistics_pram->res0[i]; |
| 520 | rx_firmware_statistics->mismatchdrop = |
| 521 | in_be32(&p_rx_fw_statistics_pram->mismatchdrop); |
| 522 | rx_firmware_statistics->underpkts = |
| 523 | in_be32(&p_rx_fw_statistics_pram->underpkts); |
| 524 | rx_firmware_statistics->pkts256 = |
| 525 | in_be32(&p_rx_fw_statistics_pram->pkts256); |
| 526 | rx_firmware_statistics->pkts512 = |
| 527 | in_be32(&p_rx_fw_statistics_pram->pkts512); |
| 528 | rx_firmware_statistics->pkts1024 = |
| 529 | in_be32(&p_rx_fw_statistics_pram->pkts1024); |
| 530 | rx_firmware_statistics->pktsjumbo = |
| 531 | in_be32(&p_rx_fw_statistics_pram->pktsjumbo); |
| 532 | rx_firmware_statistics->frlossinmacer = |
| 533 | in_be32(&p_rx_fw_statistics_pram->frlossinmacer); |
| 534 | rx_firmware_statistics->pausefr = |
| 535 | in_be32(&p_rx_fw_statistics_pram->pausefr); |
| 536 | for (i = 0; i < 0x4; i++) |
| 537 | rx_firmware_statistics->res1[i] = |
| 538 | p_rx_fw_statistics_pram->res1[i]; |
| 539 | rx_firmware_statistics->removevlan = |
| 540 | in_be32(&p_rx_fw_statistics_pram->removevlan); |
| 541 | rx_firmware_statistics->replacevlan = |
| 542 | in_be32(&p_rx_fw_statistics_pram->replacevlan); |
| 543 | rx_firmware_statistics->insertvlan = |
| 544 | in_be32(&p_rx_fw_statistics_pram->insertvlan); |
| 545 | } |
| 546 | |
| 547 | /* Hardware only if user handed pointer and driver actually |
| 548 | gathers hardware statistics */ |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 549 | if (hardware_statistics && |
| 550 | (in_be32(&uf_regs->upsmr) & UCC_GETH_UPSMR_HSE)) { |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 551 | hardware_statistics->tx64 = in_be32(&ug_regs->tx64); |
| 552 | hardware_statistics->tx127 = in_be32(&ug_regs->tx127); |
| 553 | hardware_statistics->tx255 = in_be32(&ug_regs->tx255); |
| 554 | hardware_statistics->rx64 = in_be32(&ug_regs->rx64); |
| 555 | hardware_statistics->rx127 = in_be32(&ug_regs->rx127); |
| 556 | hardware_statistics->rx255 = in_be32(&ug_regs->rx255); |
| 557 | hardware_statistics->txok = in_be32(&ug_regs->txok); |
| 558 | hardware_statistics->txcf = in_be16(&ug_regs->txcf); |
| 559 | hardware_statistics->tmca = in_be32(&ug_regs->tmca); |
| 560 | hardware_statistics->tbca = in_be32(&ug_regs->tbca); |
| 561 | hardware_statistics->rxfok = in_be32(&ug_regs->rxfok); |
| 562 | hardware_statistics->rxbok = in_be32(&ug_regs->rxbok); |
| 563 | hardware_statistics->rbyt = in_be32(&ug_regs->rbyt); |
| 564 | hardware_statistics->rmca = in_be32(&ug_regs->rmca); |
| 565 | hardware_statistics->rbca = in_be32(&ug_regs->rbca); |
| 566 | } |
| 567 | } |
| 568 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 569 | static void dump_bds(struct ucc_geth_private *ugeth) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 570 | { |
| 571 | int i; |
| 572 | int length; |
| 573 | |
| 574 | for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) { |
| 575 | if (ugeth->p_tx_bd_ring[i]) { |
| 576 | length = |
| 577 | (ugeth->ug_info->bdRingLenTx[i] * |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 578 | sizeof(struct qe_bd)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 579 | ugeth_info("TX BDs[%d]", i); |
| 580 | mem_disp(ugeth->p_tx_bd_ring[i], length); |
| 581 | } |
| 582 | } |
| 583 | for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) { |
| 584 | if (ugeth->p_rx_bd_ring[i]) { |
| 585 | length = |
| 586 | (ugeth->ug_info->bdRingLenRx[i] * |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 587 | sizeof(struct qe_bd)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 588 | ugeth_info("RX BDs[%d]", i); |
| 589 | mem_disp(ugeth->p_rx_bd_ring[i], length); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 594 | static void dump_regs(struct ucc_geth_private *ugeth) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 595 | { |
| 596 | int i; |
| 597 | |
Sergey Matyukevich | 3ac3774 | 2010-07-28 08:05:21 +0000 | [diff] [blame] | 598 | ugeth_info("UCC%d Geth registers:", ugeth->ug_info->uf_info.ucc_num + 1); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 599 | ugeth_info("Base address: 0x%08x", (u32) ugeth->ug_regs); |
| 600 | |
| 601 | ugeth_info("maccfg1 : addr - 0x%08x, val - 0x%08x", |
| 602 | (u32) & ugeth->ug_regs->maccfg1, |
| 603 | in_be32(&ugeth->ug_regs->maccfg1)); |
| 604 | ugeth_info("maccfg2 : addr - 0x%08x, val - 0x%08x", |
| 605 | (u32) & ugeth->ug_regs->maccfg2, |
| 606 | in_be32(&ugeth->ug_regs->maccfg2)); |
| 607 | ugeth_info("ipgifg : addr - 0x%08x, val - 0x%08x", |
| 608 | (u32) & ugeth->ug_regs->ipgifg, |
| 609 | in_be32(&ugeth->ug_regs->ipgifg)); |
| 610 | ugeth_info("hafdup : addr - 0x%08x, val - 0x%08x", |
| 611 | (u32) & ugeth->ug_regs->hafdup, |
| 612 | in_be32(&ugeth->ug_regs->hafdup)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 613 | ugeth_info("ifctl : addr - 0x%08x, val - 0x%08x", |
| 614 | (u32) & ugeth->ug_regs->ifctl, |
| 615 | in_be32(&ugeth->ug_regs->ifctl)); |
| 616 | ugeth_info("ifstat : addr - 0x%08x, val - 0x%08x", |
| 617 | (u32) & ugeth->ug_regs->ifstat, |
| 618 | in_be32(&ugeth->ug_regs->ifstat)); |
| 619 | ugeth_info("macstnaddr1: addr - 0x%08x, val - 0x%08x", |
| 620 | (u32) & ugeth->ug_regs->macstnaddr1, |
| 621 | in_be32(&ugeth->ug_regs->macstnaddr1)); |
| 622 | ugeth_info("macstnaddr2: addr - 0x%08x, val - 0x%08x", |
| 623 | (u32) & ugeth->ug_regs->macstnaddr2, |
| 624 | in_be32(&ugeth->ug_regs->macstnaddr2)); |
| 625 | ugeth_info("uempr : addr - 0x%08x, val - 0x%08x", |
| 626 | (u32) & ugeth->ug_regs->uempr, |
| 627 | in_be32(&ugeth->ug_regs->uempr)); |
| 628 | ugeth_info("utbipar : addr - 0x%08x, val - 0x%08x", |
| 629 | (u32) & ugeth->ug_regs->utbipar, |
| 630 | in_be32(&ugeth->ug_regs->utbipar)); |
| 631 | ugeth_info("uescr : addr - 0x%08x, val - 0x%04x", |
| 632 | (u32) & ugeth->ug_regs->uescr, |
| 633 | in_be16(&ugeth->ug_regs->uescr)); |
| 634 | ugeth_info("tx64 : addr - 0x%08x, val - 0x%08x", |
| 635 | (u32) & ugeth->ug_regs->tx64, |
| 636 | in_be32(&ugeth->ug_regs->tx64)); |
| 637 | ugeth_info("tx127 : addr - 0x%08x, val - 0x%08x", |
| 638 | (u32) & ugeth->ug_regs->tx127, |
| 639 | in_be32(&ugeth->ug_regs->tx127)); |
| 640 | ugeth_info("tx255 : addr - 0x%08x, val - 0x%08x", |
| 641 | (u32) & ugeth->ug_regs->tx255, |
| 642 | in_be32(&ugeth->ug_regs->tx255)); |
| 643 | ugeth_info("rx64 : addr - 0x%08x, val - 0x%08x", |
| 644 | (u32) & ugeth->ug_regs->rx64, |
| 645 | in_be32(&ugeth->ug_regs->rx64)); |
| 646 | ugeth_info("rx127 : addr - 0x%08x, val - 0x%08x", |
| 647 | (u32) & ugeth->ug_regs->rx127, |
| 648 | in_be32(&ugeth->ug_regs->rx127)); |
| 649 | ugeth_info("rx255 : addr - 0x%08x, val - 0x%08x", |
| 650 | (u32) & ugeth->ug_regs->rx255, |
| 651 | in_be32(&ugeth->ug_regs->rx255)); |
| 652 | ugeth_info("txok : addr - 0x%08x, val - 0x%08x", |
| 653 | (u32) & ugeth->ug_regs->txok, |
| 654 | in_be32(&ugeth->ug_regs->txok)); |
| 655 | ugeth_info("txcf : addr - 0x%08x, val - 0x%04x", |
| 656 | (u32) & ugeth->ug_regs->txcf, |
| 657 | in_be16(&ugeth->ug_regs->txcf)); |
| 658 | ugeth_info("tmca : addr - 0x%08x, val - 0x%08x", |
| 659 | (u32) & ugeth->ug_regs->tmca, |
| 660 | in_be32(&ugeth->ug_regs->tmca)); |
| 661 | ugeth_info("tbca : addr - 0x%08x, val - 0x%08x", |
| 662 | (u32) & ugeth->ug_regs->tbca, |
| 663 | in_be32(&ugeth->ug_regs->tbca)); |
| 664 | ugeth_info("rxfok : addr - 0x%08x, val - 0x%08x", |
| 665 | (u32) & ugeth->ug_regs->rxfok, |
| 666 | in_be32(&ugeth->ug_regs->rxfok)); |
| 667 | ugeth_info("rxbok : addr - 0x%08x, val - 0x%08x", |
| 668 | (u32) & ugeth->ug_regs->rxbok, |
| 669 | in_be32(&ugeth->ug_regs->rxbok)); |
| 670 | ugeth_info("rbyt : addr - 0x%08x, val - 0x%08x", |
| 671 | (u32) & ugeth->ug_regs->rbyt, |
| 672 | in_be32(&ugeth->ug_regs->rbyt)); |
| 673 | ugeth_info("rmca : addr - 0x%08x, val - 0x%08x", |
| 674 | (u32) & ugeth->ug_regs->rmca, |
| 675 | in_be32(&ugeth->ug_regs->rmca)); |
| 676 | ugeth_info("rbca : addr - 0x%08x, val - 0x%08x", |
| 677 | (u32) & ugeth->ug_regs->rbca, |
| 678 | in_be32(&ugeth->ug_regs->rbca)); |
| 679 | ugeth_info("scar : addr - 0x%08x, val - 0x%08x", |
| 680 | (u32) & ugeth->ug_regs->scar, |
| 681 | in_be32(&ugeth->ug_regs->scar)); |
| 682 | ugeth_info("scam : addr - 0x%08x, val - 0x%08x", |
| 683 | (u32) & ugeth->ug_regs->scam, |
| 684 | in_be32(&ugeth->ug_regs->scam)); |
| 685 | |
| 686 | if (ugeth->p_thread_data_tx) { |
| 687 | int numThreadsTxNumerical; |
| 688 | switch (ugeth->ug_info->numThreadsTx) { |
| 689 | case UCC_GETH_NUM_OF_THREADS_1: |
| 690 | numThreadsTxNumerical = 1; |
| 691 | break; |
| 692 | case UCC_GETH_NUM_OF_THREADS_2: |
| 693 | numThreadsTxNumerical = 2; |
| 694 | break; |
| 695 | case UCC_GETH_NUM_OF_THREADS_4: |
| 696 | numThreadsTxNumerical = 4; |
| 697 | break; |
| 698 | case UCC_GETH_NUM_OF_THREADS_6: |
| 699 | numThreadsTxNumerical = 6; |
| 700 | break; |
| 701 | case UCC_GETH_NUM_OF_THREADS_8: |
| 702 | numThreadsTxNumerical = 8; |
| 703 | break; |
| 704 | default: |
| 705 | numThreadsTxNumerical = 0; |
| 706 | break; |
| 707 | } |
| 708 | |
| 709 | ugeth_info("Thread data TXs:"); |
| 710 | ugeth_info("Base address: 0x%08x", |
| 711 | (u32) ugeth->p_thread_data_tx); |
| 712 | for (i = 0; i < numThreadsTxNumerical; i++) { |
| 713 | ugeth_info("Thread data TX[%d]:", i); |
| 714 | ugeth_info("Base address: 0x%08x", |
| 715 | (u32) & ugeth->p_thread_data_tx[i]); |
| 716 | mem_disp((u8 *) & ugeth->p_thread_data_tx[i], |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 717 | sizeof(struct ucc_geth_thread_data_tx)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | if (ugeth->p_thread_data_rx) { |
| 721 | int numThreadsRxNumerical; |
| 722 | switch (ugeth->ug_info->numThreadsRx) { |
| 723 | case UCC_GETH_NUM_OF_THREADS_1: |
| 724 | numThreadsRxNumerical = 1; |
| 725 | break; |
| 726 | case UCC_GETH_NUM_OF_THREADS_2: |
| 727 | numThreadsRxNumerical = 2; |
| 728 | break; |
| 729 | case UCC_GETH_NUM_OF_THREADS_4: |
| 730 | numThreadsRxNumerical = 4; |
| 731 | break; |
| 732 | case UCC_GETH_NUM_OF_THREADS_6: |
| 733 | numThreadsRxNumerical = 6; |
| 734 | break; |
| 735 | case UCC_GETH_NUM_OF_THREADS_8: |
| 736 | numThreadsRxNumerical = 8; |
| 737 | break; |
| 738 | default: |
| 739 | numThreadsRxNumerical = 0; |
| 740 | break; |
| 741 | } |
| 742 | |
| 743 | ugeth_info("Thread data RX:"); |
| 744 | ugeth_info("Base address: 0x%08x", |
| 745 | (u32) ugeth->p_thread_data_rx); |
| 746 | for (i = 0; i < numThreadsRxNumerical; i++) { |
| 747 | ugeth_info("Thread data RX[%d]:", i); |
| 748 | ugeth_info("Base address: 0x%08x", |
| 749 | (u32) & ugeth->p_thread_data_rx[i]); |
| 750 | mem_disp((u8 *) & ugeth->p_thread_data_rx[i], |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 751 | sizeof(struct ucc_geth_thread_data_rx)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | if (ugeth->p_exf_glbl_param) { |
| 755 | ugeth_info("EXF global param:"); |
| 756 | ugeth_info("Base address: 0x%08x", |
| 757 | (u32) ugeth->p_exf_glbl_param); |
| 758 | mem_disp((u8 *) ugeth->p_exf_glbl_param, |
| 759 | sizeof(*ugeth->p_exf_glbl_param)); |
| 760 | } |
| 761 | if (ugeth->p_tx_glbl_pram) { |
| 762 | ugeth_info("TX global param:"); |
| 763 | ugeth_info("Base address: 0x%08x", (u32) ugeth->p_tx_glbl_pram); |
| 764 | ugeth_info("temoder : addr - 0x%08x, val - 0x%04x", |
| 765 | (u32) & ugeth->p_tx_glbl_pram->temoder, |
| 766 | in_be16(&ugeth->p_tx_glbl_pram->temoder)); |
| 767 | ugeth_info("sqptr : addr - 0x%08x, val - 0x%08x", |
| 768 | (u32) & ugeth->p_tx_glbl_pram->sqptr, |
| 769 | in_be32(&ugeth->p_tx_glbl_pram->sqptr)); |
| 770 | ugeth_info("schedulerbasepointer: addr - 0x%08x, val - 0x%08x", |
| 771 | (u32) & ugeth->p_tx_glbl_pram->schedulerbasepointer, |
| 772 | in_be32(&ugeth->p_tx_glbl_pram-> |
| 773 | schedulerbasepointer)); |
| 774 | ugeth_info("txrmonbaseptr: addr - 0x%08x, val - 0x%08x", |
| 775 | (u32) & ugeth->p_tx_glbl_pram->txrmonbaseptr, |
| 776 | in_be32(&ugeth->p_tx_glbl_pram->txrmonbaseptr)); |
| 777 | ugeth_info("tstate : addr - 0x%08x, val - 0x%08x", |
| 778 | (u32) & ugeth->p_tx_glbl_pram->tstate, |
| 779 | in_be32(&ugeth->p_tx_glbl_pram->tstate)); |
| 780 | ugeth_info("iphoffset[0] : addr - 0x%08x, val - 0x%02x", |
| 781 | (u32) & ugeth->p_tx_glbl_pram->iphoffset[0], |
| 782 | ugeth->p_tx_glbl_pram->iphoffset[0]); |
| 783 | ugeth_info("iphoffset[1] : addr - 0x%08x, val - 0x%02x", |
| 784 | (u32) & ugeth->p_tx_glbl_pram->iphoffset[1], |
| 785 | ugeth->p_tx_glbl_pram->iphoffset[1]); |
| 786 | ugeth_info("iphoffset[2] : addr - 0x%08x, val - 0x%02x", |
| 787 | (u32) & ugeth->p_tx_glbl_pram->iphoffset[2], |
| 788 | ugeth->p_tx_glbl_pram->iphoffset[2]); |
| 789 | ugeth_info("iphoffset[3] : addr - 0x%08x, val - 0x%02x", |
| 790 | (u32) & ugeth->p_tx_glbl_pram->iphoffset[3], |
| 791 | ugeth->p_tx_glbl_pram->iphoffset[3]); |
| 792 | ugeth_info("iphoffset[4] : addr - 0x%08x, val - 0x%02x", |
| 793 | (u32) & ugeth->p_tx_glbl_pram->iphoffset[4], |
| 794 | ugeth->p_tx_glbl_pram->iphoffset[4]); |
| 795 | ugeth_info("iphoffset[5] : addr - 0x%08x, val - 0x%02x", |
| 796 | (u32) & ugeth->p_tx_glbl_pram->iphoffset[5], |
| 797 | ugeth->p_tx_glbl_pram->iphoffset[5]); |
| 798 | ugeth_info("iphoffset[6] : addr - 0x%08x, val - 0x%02x", |
| 799 | (u32) & ugeth->p_tx_glbl_pram->iphoffset[6], |
| 800 | ugeth->p_tx_glbl_pram->iphoffset[6]); |
| 801 | ugeth_info("iphoffset[7] : addr - 0x%08x, val - 0x%02x", |
| 802 | (u32) & ugeth->p_tx_glbl_pram->iphoffset[7], |
| 803 | ugeth->p_tx_glbl_pram->iphoffset[7]); |
| 804 | ugeth_info("vtagtable[0] : addr - 0x%08x, val - 0x%08x", |
| 805 | (u32) & ugeth->p_tx_glbl_pram->vtagtable[0], |
| 806 | in_be32(&ugeth->p_tx_glbl_pram->vtagtable[0])); |
| 807 | ugeth_info("vtagtable[1] : addr - 0x%08x, val - 0x%08x", |
| 808 | (u32) & ugeth->p_tx_glbl_pram->vtagtable[1], |
| 809 | in_be32(&ugeth->p_tx_glbl_pram->vtagtable[1])); |
| 810 | ugeth_info("vtagtable[2] : addr - 0x%08x, val - 0x%08x", |
| 811 | (u32) & ugeth->p_tx_glbl_pram->vtagtable[2], |
| 812 | in_be32(&ugeth->p_tx_glbl_pram->vtagtable[2])); |
| 813 | ugeth_info("vtagtable[3] : addr - 0x%08x, val - 0x%08x", |
| 814 | (u32) & ugeth->p_tx_glbl_pram->vtagtable[3], |
| 815 | in_be32(&ugeth->p_tx_glbl_pram->vtagtable[3])); |
| 816 | ugeth_info("vtagtable[4] : addr - 0x%08x, val - 0x%08x", |
| 817 | (u32) & ugeth->p_tx_glbl_pram->vtagtable[4], |
| 818 | in_be32(&ugeth->p_tx_glbl_pram->vtagtable[4])); |
| 819 | ugeth_info("vtagtable[5] : addr - 0x%08x, val - 0x%08x", |
| 820 | (u32) & ugeth->p_tx_glbl_pram->vtagtable[5], |
| 821 | in_be32(&ugeth->p_tx_glbl_pram->vtagtable[5])); |
| 822 | ugeth_info("vtagtable[6] : addr - 0x%08x, val - 0x%08x", |
| 823 | (u32) & ugeth->p_tx_glbl_pram->vtagtable[6], |
| 824 | in_be32(&ugeth->p_tx_glbl_pram->vtagtable[6])); |
| 825 | ugeth_info("vtagtable[7] : addr - 0x%08x, val - 0x%08x", |
| 826 | (u32) & ugeth->p_tx_glbl_pram->vtagtable[7], |
| 827 | in_be32(&ugeth->p_tx_glbl_pram->vtagtable[7])); |
| 828 | ugeth_info("tqptr : addr - 0x%08x, val - 0x%08x", |
| 829 | (u32) & ugeth->p_tx_glbl_pram->tqptr, |
| 830 | in_be32(&ugeth->p_tx_glbl_pram->tqptr)); |
| 831 | } |
| 832 | if (ugeth->p_rx_glbl_pram) { |
| 833 | ugeth_info("RX global param:"); |
| 834 | ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_glbl_pram); |
| 835 | ugeth_info("remoder : addr - 0x%08x, val - 0x%08x", |
| 836 | (u32) & ugeth->p_rx_glbl_pram->remoder, |
| 837 | in_be32(&ugeth->p_rx_glbl_pram->remoder)); |
| 838 | ugeth_info("rqptr : addr - 0x%08x, val - 0x%08x", |
| 839 | (u32) & ugeth->p_rx_glbl_pram->rqptr, |
| 840 | in_be32(&ugeth->p_rx_glbl_pram->rqptr)); |
| 841 | ugeth_info("typeorlen : addr - 0x%08x, val - 0x%04x", |
| 842 | (u32) & ugeth->p_rx_glbl_pram->typeorlen, |
| 843 | in_be16(&ugeth->p_rx_glbl_pram->typeorlen)); |
| 844 | ugeth_info("rxgstpack : addr - 0x%08x, val - 0x%02x", |
| 845 | (u32) & ugeth->p_rx_glbl_pram->rxgstpack, |
| 846 | ugeth->p_rx_glbl_pram->rxgstpack); |
| 847 | ugeth_info("rxrmonbaseptr : addr - 0x%08x, val - 0x%08x", |
| 848 | (u32) & ugeth->p_rx_glbl_pram->rxrmonbaseptr, |
| 849 | in_be32(&ugeth->p_rx_glbl_pram->rxrmonbaseptr)); |
| 850 | ugeth_info("intcoalescingptr: addr - 0x%08x, val - 0x%08x", |
| 851 | (u32) & ugeth->p_rx_glbl_pram->intcoalescingptr, |
| 852 | in_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr)); |
| 853 | ugeth_info("rstate : addr - 0x%08x, val - 0x%02x", |
| 854 | (u32) & ugeth->p_rx_glbl_pram->rstate, |
| 855 | ugeth->p_rx_glbl_pram->rstate); |
| 856 | ugeth_info("mrblr : addr - 0x%08x, val - 0x%04x", |
| 857 | (u32) & ugeth->p_rx_glbl_pram->mrblr, |
| 858 | in_be16(&ugeth->p_rx_glbl_pram->mrblr)); |
| 859 | ugeth_info("rbdqptr : addr - 0x%08x, val - 0x%08x", |
| 860 | (u32) & ugeth->p_rx_glbl_pram->rbdqptr, |
| 861 | in_be32(&ugeth->p_rx_glbl_pram->rbdqptr)); |
| 862 | ugeth_info("mflr : addr - 0x%08x, val - 0x%04x", |
| 863 | (u32) & ugeth->p_rx_glbl_pram->mflr, |
| 864 | in_be16(&ugeth->p_rx_glbl_pram->mflr)); |
| 865 | ugeth_info("minflr : addr - 0x%08x, val - 0x%04x", |
| 866 | (u32) & ugeth->p_rx_glbl_pram->minflr, |
| 867 | in_be16(&ugeth->p_rx_glbl_pram->minflr)); |
| 868 | ugeth_info("maxd1 : addr - 0x%08x, val - 0x%04x", |
| 869 | (u32) & ugeth->p_rx_glbl_pram->maxd1, |
| 870 | in_be16(&ugeth->p_rx_glbl_pram->maxd1)); |
| 871 | ugeth_info("maxd2 : addr - 0x%08x, val - 0x%04x", |
| 872 | (u32) & ugeth->p_rx_glbl_pram->maxd2, |
| 873 | in_be16(&ugeth->p_rx_glbl_pram->maxd2)); |
| 874 | ugeth_info("ecamptr : addr - 0x%08x, val - 0x%08x", |
| 875 | (u32) & ugeth->p_rx_glbl_pram->ecamptr, |
| 876 | in_be32(&ugeth->p_rx_glbl_pram->ecamptr)); |
| 877 | ugeth_info("l2qt : addr - 0x%08x, val - 0x%08x", |
| 878 | (u32) & ugeth->p_rx_glbl_pram->l2qt, |
| 879 | in_be32(&ugeth->p_rx_glbl_pram->l2qt)); |
| 880 | ugeth_info("l3qt[0] : addr - 0x%08x, val - 0x%08x", |
| 881 | (u32) & ugeth->p_rx_glbl_pram->l3qt[0], |
| 882 | in_be32(&ugeth->p_rx_glbl_pram->l3qt[0])); |
| 883 | ugeth_info("l3qt[1] : addr - 0x%08x, val - 0x%08x", |
| 884 | (u32) & ugeth->p_rx_glbl_pram->l3qt[1], |
| 885 | in_be32(&ugeth->p_rx_glbl_pram->l3qt[1])); |
| 886 | ugeth_info("l3qt[2] : addr - 0x%08x, val - 0x%08x", |
| 887 | (u32) & ugeth->p_rx_glbl_pram->l3qt[2], |
| 888 | in_be32(&ugeth->p_rx_glbl_pram->l3qt[2])); |
| 889 | ugeth_info("l3qt[3] : addr - 0x%08x, val - 0x%08x", |
| 890 | (u32) & ugeth->p_rx_glbl_pram->l3qt[3], |
| 891 | in_be32(&ugeth->p_rx_glbl_pram->l3qt[3])); |
| 892 | ugeth_info("l3qt[4] : addr - 0x%08x, val - 0x%08x", |
| 893 | (u32) & ugeth->p_rx_glbl_pram->l3qt[4], |
| 894 | in_be32(&ugeth->p_rx_glbl_pram->l3qt[4])); |
| 895 | ugeth_info("l3qt[5] : addr - 0x%08x, val - 0x%08x", |
| 896 | (u32) & ugeth->p_rx_glbl_pram->l3qt[5], |
| 897 | in_be32(&ugeth->p_rx_glbl_pram->l3qt[5])); |
| 898 | ugeth_info("l3qt[6] : addr - 0x%08x, val - 0x%08x", |
| 899 | (u32) & ugeth->p_rx_glbl_pram->l3qt[6], |
| 900 | in_be32(&ugeth->p_rx_glbl_pram->l3qt[6])); |
| 901 | ugeth_info("l3qt[7] : addr - 0x%08x, val - 0x%08x", |
| 902 | (u32) & ugeth->p_rx_glbl_pram->l3qt[7], |
| 903 | in_be32(&ugeth->p_rx_glbl_pram->l3qt[7])); |
| 904 | ugeth_info("vlantype : addr - 0x%08x, val - 0x%04x", |
| 905 | (u32) & ugeth->p_rx_glbl_pram->vlantype, |
| 906 | in_be16(&ugeth->p_rx_glbl_pram->vlantype)); |
| 907 | ugeth_info("vlantci : addr - 0x%08x, val - 0x%04x", |
| 908 | (u32) & ugeth->p_rx_glbl_pram->vlantci, |
| 909 | in_be16(&ugeth->p_rx_glbl_pram->vlantci)); |
| 910 | for (i = 0; i < 64; i++) |
| 911 | ugeth_info |
| 912 | ("addressfiltering[%d]: addr - 0x%08x, val - 0x%02x", |
| 913 | i, |
| 914 | (u32) & ugeth->p_rx_glbl_pram->addressfiltering[i], |
| 915 | ugeth->p_rx_glbl_pram->addressfiltering[i]); |
| 916 | ugeth_info("exfGlobalParam : addr - 0x%08x, val - 0x%08x", |
| 917 | (u32) & ugeth->p_rx_glbl_pram->exfGlobalParam, |
| 918 | in_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam)); |
| 919 | } |
| 920 | if (ugeth->p_send_q_mem_reg) { |
| 921 | ugeth_info("Send Q memory registers:"); |
| 922 | ugeth_info("Base address: 0x%08x", |
| 923 | (u32) ugeth->p_send_q_mem_reg); |
| 924 | for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) { |
| 925 | ugeth_info("SQQD[%d]:", i); |
| 926 | ugeth_info("Base address: 0x%08x", |
| 927 | (u32) & ugeth->p_send_q_mem_reg->sqqd[i]); |
| 928 | mem_disp((u8 *) & ugeth->p_send_q_mem_reg->sqqd[i], |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 929 | sizeof(struct ucc_geth_send_queue_qd)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | if (ugeth->p_scheduler) { |
| 933 | ugeth_info("Scheduler:"); |
| 934 | ugeth_info("Base address: 0x%08x", (u32) ugeth->p_scheduler); |
| 935 | mem_disp((u8 *) ugeth->p_scheduler, |
| 936 | sizeof(*ugeth->p_scheduler)); |
| 937 | } |
| 938 | if (ugeth->p_tx_fw_statistics_pram) { |
| 939 | ugeth_info("TX FW statistics pram:"); |
| 940 | ugeth_info("Base address: 0x%08x", |
| 941 | (u32) ugeth->p_tx_fw_statistics_pram); |
| 942 | mem_disp((u8 *) ugeth->p_tx_fw_statistics_pram, |
| 943 | sizeof(*ugeth->p_tx_fw_statistics_pram)); |
| 944 | } |
| 945 | if (ugeth->p_rx_fw_statistics_pram) { |
| 946 | ugeth_info("RX FW statistics pram:"); |
| 947 | ugeth_info("Base address: 0x%08x", |
| 948 | (u32) ugeth->p_rx_fw_statistics_pram); |
| 949 | mem_disp((u8 *) ugeth->p_rx_fw_statistics_pram, |
| 950 | sizeof(*ugeth->p_rx_fw_statistics_pram)); |
| 951 | } |
| 952 | if (ugeth->p_rx_irq_coalescing_tbl) { |
| 953 | ugeth_info("RX IRQ coalescing tables:"); |
| 954 | ugeth_info("Base address: 0x%08x", |
| 955 | (u32) ugeth->p_rx_irq_coalescing_tbl); |
| 956 | for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) { |
| 957 | ugeth_info("RX IRQ coalescing table entry[%d]:", i); |
| 958 | ugeth_info("Base address: 0x%08x", |
| 959 | (u32) & ugeth->p_rx_irq_coalescing_tbl-> |
| 960 | coalescingentry[i]); |
| 961 | ugeth_info |
| 962 | ("interruptcoalescingmaxvalue: addr - 0x%08x, val - 0x%08x", |
| 963 | (u32) & ugeth->p_rx_irq_coalescing_tbl-> |
| 964 | coalescingentry[i].interruptcoalescingmaxvalue, |
| 965 | in_be32(&ugeth->p_rx_irq_coalescing_tbl-> |
| 966 | coalescingentry[i]. |
| 967 | interruptcoalescingmaxvalue)); |
| 968 | ugeth_info |
| 969 | ("interruptcoalescingcounter : addr - 0x%08x, val - 0x%08x", |
| 970 | (u32) & ugeth->p_rx_irq_coalescing_tbl-> |
| 971 | coalescingentry[i].interruptcoalescingcounter, |
| 972 | in_be32(&ugeth->p_rx_irq_coalescing_tbl-> |
| 973 | coalescingentry[i]. |
| 974 | interruptcoalescingcounter)); |
| 975 | } |
| 976 | } |
| 977 | if (ugeth->p_rx_bd_qs_tbl) { |
| 978 | ugeth_info("RX BD QS tables:"); |
| 979 | ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_bd_qs_tbl); |
| 980 | for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) { |
| 981 | ugeth_info("RX BD QS table[%d]:", i); |
| 982 | ugeth_info("Base address: 0x%08x", |
| 983 | (u32) & ugeth->p_rx_bd_qs_tbl[i]); |
| 984 | ugeth_info |
| 985 | ("bdbaseptr : addr - 0x%08x, val - 0x%08x", |
| 986 | (u32) & ugeth->p_rx_bd_qs_tbl[i].bdbaseptr, |
| 987 | in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdbaseptr)); |
| 988 | ugeth_info |
| 989 | ("bdptr : addr - 0x%08x, val - 0x%08x", |
| 990 | (u32) & ugeth->p_rx_bd_qs_tbl[i].bdptr, |
| 991 | in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdptr)); |
| 992 | ugeth_info |
| 993 | ("externalbdbaseptr: addr - 0x%08x, val - 0x%08x", |
| 994 | (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr, |
| 995 | in_be32(&ugeth->p_rx_bd_qs_tbl[i]. |
| 996 | externalbdbaseptr)); |
| 997 | ugeth_info |
| 998 | ("externalbdptr : addr - 0x%08x, val - 0x%08x", |
| 999 | (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdptr, |
| 1000 | in_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdptr)); |
| 1001 | ugeth_info("ucode RX Prefetched BDs:"); |
| 1002 | ugeth_info("Base address: 0x%08x", |
| 1003 | (u32) |
| 1004 | qe_muram_addr(in_be32 |
| 1005 | (&ugeth->p_rx_bd_qs_tbl[i]. |
| 1006 | bdbaseptr))); |
| 1007 | mem_disp((u8 *) |
| 1008 | qe_muram_addr(in_be32 |
| 1009 | (&ugeth->p_rx_bd_qs_tbl[i]. |
| 1010 | bdbaseptr)), |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1011 | sizeof(struct ucc_geth_rx_prefetched_bds)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | if (ugeth->p_init_enet_param_shadow) { |
| 1015 | int size; |
| 1016 | ugeth_info("Init enet param shadow:"); |
| 1017 | ugeth_info("Base address: 0x%08x", |
| 1018 | (u32) ugeth->p_init_enet_param_shadow); |
| 1019 | mem_disp((u8 *) ugeth->p_init_enet_param_shadow, |
| 1020 | sizeof(*ugeth->p_init_enet_param_shadow)); |
| 1021 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1022 | size = sizeof(struct ucc_geth_thread_rx_pram); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1023 | if (ugeth->ug_info->rxExtendedFiltering) { |
| 1024 | size += |
| 1025 | THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING; |
| 1026 | if (ugeth->ug_info->largestexternallookupkeysize == |
| 1027 | QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES) |
| 1028 | size += |
| 1029 | THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8; |
| 1030 | if (ugeth->ug_info->largestexternallookupkeysize == |
| 1031 | QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES) |
| 1032 | size += |
| 1033 | THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16; |
| 1034 | } |
| 1035 | |
| 1036 | dump_init_enet_entries(ugeth, |
| 1037 | &(ugeth->p_init_enet_param_shadow-> |
| 1038 | txthread[0]), |
| 1039 | ENET_INIT_PARAM_MAX_ENTRIES_TX, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1040 | sizeof(struct ucc_geth_thread_tx_pram), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1041 | ugeth->ug_info->riscTx, 0); |
| 1042 | dump_init_enet_entries(ugeth, |
| 1043 | &(ugeth->p_init_enet_param_shadow-> |
| 1044 | rxthread[0]), |
| 1045 | ENET_INIT_PARAM_MAX_ENTRIES_RX, size, |
| 1046 | ugeth->ug_info->riscRx, 1); |
| 1047 | } |
| 1048 | } |
| 1049 | #endif /* DEBUG */ |
| 1050 | |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1051 | static void init_default_reg_vals(u32 __iomem *upsmr_register, |
| 1052 | u32 __iomem *maccfg1_register, |
| 1053 | u32 __iomem *maccfg2_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1054 | { |
| 1055 | out_be32(upsmr_register, UCC_GETH_UPSMR_INIT); |
| 1056 | out_be32(maccfg1_register, UCC_GETH_MACCFG1_INIT); |
| 1057 | out_be32(maccfg2_register, UCC_GETH_MACCFG2_INIT); |
| 1058 | } |
| 1059 | |
| 1060 | static int init_half_duplex_params(int alt_beb, |
| 1061 | int back_pressure_no_backoff, |
| 1062 | int no_backoff, |
| 1063 | int excess_defer, |
| 1064 | u8 alt_beb_truncation, |
| 1065 | u8 max_retransmissions, |
| 1066 | u8 collision_window, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1067 | u32 __iomem *hafdup_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1068 | { |
| 1069 | u32 value = 0; |
| 1070 | |
| 1071 | if ((alt_beb_truncation > HALFDUP_ALT_BEB_TRUNCATION_MAX) || |
| 1072 | (max_retransmissions > HALFDUP_MAX_RETRANSMISSION_MAX) || |
| 1073 | (collision_window > HALFDUP_COLLISION_WINDOW_MAX)) |
| 1074 | return -EINVAL; |
| 1075 | |
| 1076 | value = (u32) (alt_beb_truncation << HALFDUP_ALT_BEB_TRUNCATION_SHIFT); |
| 1077 | |
| 1078 | if (alt_beb) |
| 1079 | value |= HALFDUP_ALT_BEB; |
| 1080 | if (back_pressure_no_backoff) |
| 1081 | value |= HALFDUP_BACK_PRESSURE_NO_BACKOFF; |
| 1082 | if (no_backoff) |
| 1083 | value |= HALFDUP_NO_BACKOFF; |
| 1084 | if (excess_defer) |
| 1085 | value |= HALFDUP_EXCESSIVE_DEFER; |
| 1086 | |
| 1087 | value |= (max_retransmissions << HALFDUP_MAX_RETRANSMISSION_SHIFT); |
| 1088 | |
| 1089 | value |= collision_window; |
| 1090 | |
| 1091 | out_be32(hafdup_register, value); |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | static int init_inter_frame_gap_params(u8 non_btb_cs_ipg, |
| 1096 | u8 non_btb_ipg, |
| 1097 | u8 min_ifg, |
| 1098 | u8 btb_ipg, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1099 | u32 __iomem *ipgifg_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1100 | { |
| 1101 | u32 value = 0; |
| 1102 | |
| 1103 | /* Non-Back-to-back IPG part 1 should be <= Non-Back-to-back |
| 1104 | IPG part 2 */ |
| 1105 | if (non_btb_cs_ipg > non_btb_ipg) |
| 1106 | return -EINVAL; |
| 1107 | |
| 1108 | if ((non_btb_cs_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART1_MAX) || |
| 1109 | (non_btb_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART2_MAX) || |
| 1110 | /*(min_ifg > IPGIFG_MINIMUM_IFG_ENFORCEMENT_MAX) || */ |
| 1111 | (btb_ipg > IPGIFG_BACK_TO_BACK_IFG_MAX)) |
| 1112 | return -EINVAL; |
| 1113 | |
| 1114 | value |= |
| 1115 | ((non_btb_cs_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART1_SHIFT) & |
| 1116 | IPGIFG_NBTB_CS_IPG_MASK); |
| 1117 | value |= |
| 1118 | ((non_btb_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART2_SHIFT) & |
| 1119 | IPGIFG_NBTB_IPG_MASK); |
| 1120 | value |= |
| 1121 | ((min_ifg << IPGIFG_MINIMUM_IFG_ENFORCEMENT_SHIFT) & |
| 1122 | IPGIFG_MIN_IFG_MASK); |
| 1123 | value |= (btb_ipg & IPGIFG_BTB_IPG_MASK); |
| 1124 | |
| 1125 | out_be32(ipgifg_register, value); |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 1129 | int init_flow_control_params(u32 automatic_flow_control_mode, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1130 | int rx_flow_control_enable, |
| 1131 | int tx_flow_control_enable, |
| 1132 | u16 pause_period, |
| 1133 | u16 extension_field, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1134 | u32 __iomem *upsmr_register, |
| 1135 | u32 __iomem *uempr_register, |
| 1136 | u32 __iomem *maccfg1_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1137 | { |
| 1138 | u32 value = 0; |
| 1139 | |
| 1140 | /* Set UEMPR register */ |
| 1141 | value = (u32) pause_period << UEMPR_PAUSE_TIME_VALUE_SHIFT; |
| 1142 | value |= (u32) extension_field << UEMPR_EXTENDED_PAUSE_TIME_VALUE_SHIFT; |
| 1143 | out_be32(uempr_register, value); |
| 1144 | |
| 1145 | /* Set UPSMR register */ |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1146 | setbits32(upsmr_register, automatic_flow_control_mode); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1147 | |
| 1148 | value = in_be32(maccfg1_register); |
| 1149 | if (rx_flow_control_enable) |
| 1150 | value |= MACCFG1_FLOW_RX; |
| 1151 | if (tx_flow_control_enable) |
| 1152 | value |= MACCFG1_FLOW_TX; |
| 1153 | out_be32(maccfg1_register, value); |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | static int init_hw_statistics_gathering_mode(int enable_hardware_statistics, |
| 1159 | int auto_zero_hardware_statistics, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1160 | u32 __iomem *upsmr_register, |
| 1161 | u16 __iomem *uescr_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1162 | { |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1163 | u16 uescr_value = 0; |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1164 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1165 | /* Enable hardware statistics gathering if requested */ |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1166 | if (enable_hardware_statistics) |
| 1167 | setbits32(upsmr_register, UCC_GETH_UPSMR_HSE); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1168 | |
| 1169 | /* Clear hardware statistics counters */ |
| 1170 | uescr_value = in_be16(uescr_register); |
| 1171 | uescr_value |= UESCR_CLRCNT; |
| 1172 | /* Automatically zero hardware statistics counters on read, |
| 1173 | if requested */ |
| 1174 | if (auto_zero_hardware_statistics) |
| 1175 | uescr_value |= UESCR_AUTOZ; |
| 1176 | out_be16(uescr_register, uescr_value); |
| 1177 | |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | static int init_firmware_statistics_gathering_mode(int |
| 1182 | enable_tx_firmware_statistics, |
| 1183 | int enable_rx_firmware_statistics, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1184 | u32 __iomem *tx_rmon_base_ptr, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1185 | u32 tx_firmware_statistics_structure_address, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1186 | u32 __iomem *rx_rmon_base_ptr, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1187 | u32 rx_firmware_statistics_structure_address, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1188 | u16 __iomem *temoder_register, |
| 1189 | u32 __iomem *remoder_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1190 | { |
| 1191 | /* Note: this function does not check if */ |
| 1192 | /* the parameters it receives are NULL */ |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1193 | |
| 1194 | if (enable_tx_firmware_statistics) { |
| 1195 | out_be32(tx_rmon_base_ptr, |
| 1196 | tx_firmware_statistics_structure_address); |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1197 | setbits16(temoder_register, TEMODER_TX_RMON_STATISTICS_ENABLE); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | if (enable_rx_firmware_statistics) { |
| 1201 | out_be32(rx_rmon_base_ptr, |
| 1202 | rx_firmware_statistics_structure_address); |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1203 | setbits32(remoder_register, REMODER_RX_RMON_STATISTICS_ENABLE); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | return 0; |
| 1207 | } |
| 1208 | |
| 1209 | static int init_mac_station_addr_regs(u8 address_byte_0, |
| 1210 | u8 address_byte_1, |
| 1211 | u8 address_byte_2, |
| 1212 | u8 address_byte_3, |
| 1213 | u8 address_byte_4, |
| 1214 | u8 address_byte_5, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1215 | u32 __iomem *macstnaddr1_register, |
| 1216 | u32 __iomem *macstnaddr2_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1217 | { |
| 1218 | u32 value = 0; |
| 1219 | |
| 1220 | /* Example: for a station address of 0x12345678ABCD, */ |
| 1221 | /* 0x12 is byte 0, 0x34 is byte 1 and so on and 0xCD is byte 5 */ |
| 1222 | |
| 1223 | /* MACSTNADDR1 Register: */ |
| 1224 | |
| 1225 | /* 0 7 8 15 */ |
| 1226 | /* station address byte 5 station address byte 4 */ |
| 1227 | /* 16 23 24 31 */ |
| 1228 | /* station address byte 3 station address byte 2 */ |
| 1229 | value |= (u32) ((address_byte_2 << 0) & 0x000000FF); |
| 1230 | value |= (u32) ((address_byte_3 << 8) & 0x0000FF00); |
| 1231 | value |= (u32) ((address_byte_4 << 16) & 0x00FF0000); |
| 1232 | value |= (u32) ((address_byte_5 << 24) & 0xFF000000); |
| 1233 | |
| 1234 | out_be32(macstnaddr1_register, value); |
| 1235 | |
| 1236 | /* MACSTNADDR2 Register: */ |
| 1237 | |
| 1238 | /* 0 7 8 15 */ |
| 1239 | /* station address byte 1 station address byte 0 */ |
| 1240 | /* 16 23 24 31 */ |
| 1241 | /* reserved reserved */ |
| 1242 | value = 0; |
| 1243 | value |= (u32) ((address_byte_0 << 16) & 0x00FF0000); |
| 1244 | value |= (u32) ((address_byte_1 << 24) & 0xFF000000); |
| 1245 | |
| 1246 | out_be32(macstnaddr2_register, value); |
| 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1251 | static int init_check_frame_length_mode(int length_check, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1252 | u32 __iomem *maccfg2_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1253 | { |
| 1254 | u32 value = 0; |
| 1255 | |
| 1256 | value = in_be32(maccfg2_register); |
| 1257 | |
| 1258 | if (length_check) |
| 1259 | value |= MACCFG2_LC; |
| 1260 | else |
| 1261 | value &= ~MACCFG2_LC; |
| 1262 | |
| 1263 | out_be32(maccfg2_register, value); |
| 1264 | return 0; |
| 1265 | } |
| 1266 | |
| 1267 | static int init_preamble_length(u8 preamble_length, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1268 | u32 __iomem *maccfg2_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1269 | { |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1270 | if ((preamble_length < 3) || (preamble_length > 7)) |
| 1271 | return -EINVAL; |
| 1272 | |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1273 | clrsetbits_be32(maccfg2_register, MACCFG2_PREL_MASK, |
| 1274 | preamble_length << MACCFG2_PREL_SHIFT); |
| 1275 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1276 | return 0; |
| 1277 | } |
| 1278 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1279 | static int init_rx_parameters(int reject_broadcast, |
| 1280 | int receive_short_frames, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1281 | int promiscuous, u32 __iomem *upsmr_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1282 | { |
| 1283 | u32 value = 0; |
| 1284 | |
| 1285 | value = in_be32(upsmr_register); |
| 1286 | |
| 1287 | if (reject_broadcast) |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1288 | value |= UCC_GETH_UPSMR_BRO; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1289 | else |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1290 | value &= ~UCC_GETH_UPSMR_BRO; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1291 | |
| 1292 | if (receive_short_frames) |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1293 | value |= UCC_GETH_UPSMR_RSH; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1294 | else |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1295 | value &= ~UCC_GETH_UPSMR_RSH; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1296 | |
| 1297 | if (promiscuous) |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1298 | value |= UCC_GETH_UPSMR_PRO; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1299 | else |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1300 | value &= ~UCC_GETH_UPSMR_PRO; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1301 | |
| 1302 | out_be32(upsmr_register, value); |
| 1303 | |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
| 1307 | static int init_max_rx_buff_len(u16 max_rx_buf_len, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1308 | u16 __iomem *mrblr_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1309 | { |
| 1310 | /* max_rx_buf_len value must be a multiple of 128 */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1311 | if ((max_rx_buf_len == 0) || |
| 1312 | (max_rx_buf_len % UCC_GETH_MRBLR_ALIGNMENT)) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1313 | return -EINVAL; |
| 1314 | |
| 1315 | out_be16(mrblr_register, max_rx_buf_len); |
| 1316 | return 0; |
| 1317 | } |
| 1318 | |
| 1319 | static int init_min_frame_len(u16 min_frame_length, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1320 | u16 __iomem *minflr_register, |
| 1321 | u16 __iomem *mrblr_register) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1322 | { |
| 1323 | u16 mrblr_value = 0; |
| 1324 | |
| 1325 | mrblr_value = in_be16(mrblr_register); |
| 1326 | if (min_frame_length >= (mrblr_value - 4)) |
| 1327 | return -EINVAL; |
| 1328 | |
| 1329 | out_be16(minflr_register, min_frame_length); |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1333 | static int adjust_enet_interface(struct ucc_geth_private *ugeth) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1334 | { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1335 | struct ucc_geth_info *ug_info; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1336 | struct ucc_geth __iomem *ug_regs; |
| 1337 | struct ucc_fast __iomem *uf_regs; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1338 | int ret_val; |
Liu Yu-B13201 | 81abb43 | 2010-01-13 22:13:18 +0000 | [diff] [blame] | 1339 | u32 upsmr, maccfg2; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1340 | u16 value; |
| 1341 | |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 1342 | ugeth_vdbg("%s: IN", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1343 | |
| 1344 | ug_info = ugeth->ug_info; |
| 1345 | ug_regs = ugeth->ug_regs; |
| 1346 | uf_regs = ugeth->uccf->uf_regs; |
| 1347 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1348 | /* Set MACCFG2 */ |
| 1349 | maccfg2 = in_be32(&ug_regs->maccfg2); |
| 1350 | maccfg2 &= ~MACCFG2_INTERFACE_MODE_MASK; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1351 | if ((ugeth->max_speed == SPEED_10) || |
| 1352 | (ugeth->max_speed == SPEED_100)) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1353 | maccfg2 |= MACCFG2_INTERFACE_MODE_NIBBLE; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1354 | else if (ugeth->max_speed == SPEED_1000) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1355 | maccfg2 |= MACCFG2_INTERFACE_MODE_BYTE; |
| 1356 | maccfg2 |= ug_info->padAndCrc; |
| 1357 | out_be32(&ug_regs->maccfg2, maccfg2); |
| 1358 | |
| 1359 | /* Set UPSMR */ |
| 1360 | upsmr = in_be32(&uf_regs->upsmr); |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1361 | upsmr &= ~(UCC_GETH_UPSMR_RPM | UCC_GETH_UPSMR_R10M | |
| 1362 | UCC_GETH_UPSMR_TBIM | UCC_GETH_UPSMR_RMM); |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1363 | if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) || |
| 1364 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) || |
| 1365 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) || |
Kim Phillips | bd0ceaa | 2007-11-26 16:17:58 -0600 | [diff] [blame] | 1366 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) || |
| 1367 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) || |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1368 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) { |
Heiko Schocher | cef309c | 2009-04-20 22:36:43 +0000 | [diff] [blame] | 1369 | if (ugeth->phy_interface != PHY_INTERFACE_MODE_RMII) |
| 1370 | upsmr |= UCC_GETH_UPSMR_RPM; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1371 | switch (ugeth->max_speed) { |
| 1372 | case SPEED_10: |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1373 | upsmr |= UCC_GETH_UPSMR_R10M; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1374 | /* FALLTHROUGH */ |
| 1375 | case SPEED_100: |
| 1376 | if (ugeth->phy_interface != PHY_INTERFACE_MODE_RTBI) |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1377 | upsmr |= UCC_GETH_UPSMR_RMM; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1378 | } |
| 1379 | } |
| 1380 | if ((ugeth->phy_interface == PHY_INTERFACE_MODE_TBI) || |
| 1381 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) { |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1382 | upsmr |= UCC_GETH_UPSMR_TBIM; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1383 | } |
Haiying Wang | 047584c | 2009-06-02 04:04:15 +0000 | [diff] [blame] | 1384 | if ((ugeth->phy_interface == PHY_INTERFACE_MODE_SGMII)) |
| 1385 | upsmr |= UCC_GETH_UPSMR_SGMM; |
| 1386 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1387 | out_be32(&uf_regs->upsmr, upsmr); |
| 1388 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1389 | /* Disable autonegotiation in tbi mode, because by default it |
| 1390 | comes up in autonegotiation mode. */ |
| 1391 | /* Note that this depends on proper setting in utbipar register. */ |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1392 | if ((ugeth->phy_interface == PHY_INTERFACE_MODE_TBI) || |
| 1393 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) { |
Liu Yu-B13201 | 81abb43 | 2010-01-13 22:13:18 +0000 | [diff] [blame] | 1394 | struct ucc_geth_info *ug_info = ugeth->ug_info; |
| 1395 | struct phy_device *tbiphy; |
| 1396 | |
| 1397 | if (!ug_info->tbi_node) |
| 1398 | ugeth_warn("TBI mode requires that the device " |
| 1399 | "tree specify a tbi-handle\n"); |
| 1400 | |
| 1401 | tbiphy = of_phy_find_device(ug_info->tbi_node); |
| 1402 | if (!tbiphy) |
| 1403 | ugeth_warn("Could not get TBI device\n"); |
| 1404 | |
| 1405 | value = phy_read(tbiphy, ENET_TBI_MII_CR); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1406 | value &= ~0x1000; /* Turn off autonegotiation */ |
Liu Yu-B13201 | 81abb43 | 2010-01-13 22:13:18 +0000 | [diff] [blame] | 1407 | phy_write(tbiphy, ENET_TBI_MII_CR, value); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | init_check_frame_length_mode(ug_info->lengthCheckRx, &ug_regs->maccfg2); |
| 1411 | |
| 1412 | ret_val = init_preamble_length(ug_info->prel, &ug_regs->maccfg2); |
| 1413 | if (ret_val != 0) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 1414 | if (netif_msg_probe(ugeth)) |
| 1415 | ugeth_err("%s: Preamble length must be between 3 and 7 inclusive.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 1416 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1417 | return ret_val; |
| 1418 | } |
| 1419 | |
| 1420 | return 0; |
| 1421 | } |
| 1422 | |
Anton Vorontsov | 7de8ee7 | 2009-09-09 16:01:40 +0000 | [diff] [blame] | 1423 | static int ugeth_graceful_stop_tx(struct ucc_geth_private *ugeth) |
| 1424 | { |
| 1425 | struct ucc_fast_private *uccf; |
| 1426 | u32 cecr_subblock; |
| 1427 | u32 temp; |
| 1428 | int i = 10; |
| 1429 | |
| 1430 | uccf = ugeth->uccf; |
| 1431 | |
| 1432 | /* Mask GRACEFUL STOP TX interrupt bit and clear it */ |
| 1433 | clrbits32(uccf->p_uccm, UCC_GETH_UCCE_GRA); |
| 1434 | out_be32(uccf->p_ucce, UCC_GETH_UCCE_GRA); /* clear by writing 1 */ |
| 1435 | |
| 1436 | /* Issue host command */ |
| 1437 | cecr_subblock = |
| 1438 | ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num); |
| 1439 | qe_issue_cmd(QE_GRACEFUL_STOP_TX, cecr_subblock, |
| 1440 | QE_CR_PROTOCOL_ETHERNET, 0); |
| 1441 | |
| 1442 | /* Wait for command to complete */ |
| 1443 | do { |
| 1444 | msleep(10); |
| 1445 | temp = in_be32(uccf->p_ucce); |
| 1446 | } while (!(temp & UCC_GETH_UCCE_GRA) && --i); |
| 1447 | |
| 1448 | uccf->stopped_tx = 1; |
| 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | static int ugeth_graceful_stop_rx(struct ucc_geth_private *ugeth) |
| 1454 | { |
| 1455 | struct ucc_fast_private *uccf; |
| 1456 | u32 cecr_subblock; |
| 1457 | u8 temp; |
| 1458 | int i = 10; |
| 1459 | |
| 1460 | uccf = ugeth->uccf; |
| 1461 | |
| 1462 | /* Clear acknowledge bit */ |
| 1463 | temp = in_8(&ugeth->p_rx_glbl_pram->rxgstpack); |
| 1464 | temp &= ~GRACEFUL_STOP_ACKNOWLEDGE_RX; |
| 1465 | out_8(&ugeth->p_rx_glbl_pram->rxgstpack, temp); |
| 1466 | |
| 1467 | /* Keep issuing command and checking acknowledge bit until |
| 1468 | it is asserted, according to spec */ |
| 1469 | do { |
| 1470 | /* Issue host command */ |
| 1471 | cecr_subblock = |
| 1472 | ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info. |
| 1473 | ucc_num); |
| 1474 | qe_issue_cmd(QE_GRACEFUL_STOP_RX, cecr_subblock, |
| 1475 | QE_CR_PROTOCOL_ETHERNET, 0); |
| 1476 | msleep(10); |
| 1477 | temp = in_8(&ugeth->p_rx_glbl_pram->rxgstpack); |
| 1478 | } while (!(temp & GRACEFUL_STOP_ACKNOWLEDGE_RX) && --i); |
| 1479 | |
| 1480 | uccf->stopped_rx = 1; |
| 1481 | |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
| 1485 | static int ugeth_restart_tx(struct ucc_geth_private *ugeth) |
| 1486 | { |
| 1487 | struct ucc_fast_private *uccf; |
| 1488 | u32 cecr_subblock; |
| 1489 | |
| 1490 | uccf = ugeth->uccf; |
| 1491 | |
| 1492 | cecr_subblock = |
| 1493 | ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num); |
| 1494 | qe_issue_cmd(QE_RESTART_TX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET, 0); |
| 1495 | uccf->stopped_tx = 0; |
| 1496 | |
| 1497 | return 0; |
| 1498 | } |
| 1499 | |
| 1500 | static int ugeth_restart_rx(struct ucc_geth_private *ugeth) |
| 1501 | { |
| 1502 | struct ucc_fast_private *uccf; |
| 1503 | u32 cecr_subblock; |
| 1504 | |
| 1505 | uccf = ugeth->uccf; |
| 1506 | |
| 1507 | cecr_subblock = |
| 1508 | ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num); |
| 1509 | qe_issue_cmd(QE_RESTART_RX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET, |
| 1510 | 0); |
| 1511 | uccf->stopped_rx = 0; |
| 1512 | |
| 1513 | return 0; |
| 1514 | } |
| 1515 | |
| 1516 | static int ugeth_enable(struct ucc_geth_private *ugeth, enum comm_dir mode) |
| 1517 | { |
| 1518 | struct ucc_fast_private *uccf; |
| 1519 | int enabled_tx, enabled_rx; |
| 1520 | |
| 1521 | uccf = ugeth->uccf; |
| 1522 | |
| 1523 | /* check if the UCC number is in range. */ |
| 1524 | if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) { |
| 1525 | if (netif_msg_probe(ugeth)) |
| 1526 | ugeth_err("%s: ucc_num out of range.", __func__); |
| 1527 | return -EINVAL; |
| 1528 | } |
| 1529 | |
| 1530 | enabled_tx = uccf->enabled_tx; |
| 1531 | enabled_rx = uccf->enabled_rx; |
| 1532 | |
| 1533 | /* Get Tx and Rx going again, in case this channel was actively |
| 1534 | disabled. */ |
| 1535 | if ((mode & COMM_DIR_TX) && (!enabled_tx) && uccf->stopped_tx) |
| 1536 | ugeth_restart_tx(ugeth); |
| 1537 | if ((mode & COMM_DIR_RX) && (!enabled_rx) && uccf->stopped_rx) |
| 1538 | ugeth_restart_rx(ugeth); |
| 1539 | |
| 1540 | ucc_fast_enable(uccf, mode); /* OK to do even if not disabled */ |
| 1541 | |
| 1542 | return 0; |
| 1543 | |
| 1544 | } |
| 1545 | |
| 1546 | static int ugeth_disable(struct ucc_geth_private *ugeth, enum comm_dir mode) |
| 1547 | { |
| 1548 | struct ucc_fast_private *uccf; |
| 1549 | |
| 1550 | uccf = ugeth->uccf; |
| 1551 | |
| 1552 | /* check if the UCC number is in range. */ |
| 1553 | if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) { |
| 1554 | if (netif_msg_probe(ugeth)) |
| 1555 | ugeth_err("%s: ucc_num out of range.", __func__); |
| 1556 | return -EINVAL; |
| 1557 | } |
| 1558 | |
| 1559 | /* Stop any transmissions */ |
| 1560 | if ((mode & COMM_DIR_TX) && uccf->enabled_tx && !uccf->stopped_tx) |
| 1561 | ugeth_graceful_stop_tx(ugeth); |
| 1562 | |
| 1563 | /* Stop any receptions */ |
| 1564 | if ((mode & COMM_DIR_RX) && uccf->enabled_rx && !uccf->stopped_rx) |
| 1565 | ugeth_graceful_stop_rx(ugeth); |
| 1566 | |
| 1567 | ucc_fast_disable(ugeth->uccf, mode); /* OK to do even if not enabled */ |
| 1568 | |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
Anton Vorontsov | 864fdf8 | 2009-09-10 11:48:12 +0000 | [diff] [blame] | 1572 | static void ugeth_quiesce(struct ucc_geth_private *ugeth) |
| 1573 | { |
Anton Vorontsov | 08b5e1c | 2009-12-24 05:31:05 +0000 | [diff] [blame] | 1574 | /* Prevent any further xmits, plus detach the device. */ |
| 1575 | netif_device_detach(ugeth->ndev); |
| 1576 | |
| 1577 | /* Wait for any current xmits to finish. */ |
Anton Vorontsov | 864fdf8 | 2009-09-10 11:48:12 +0000 | [diff] [blame] | 1578 | netif_tx_disable(ugeth->ndev); |
| 1579 | |
| 1580 | /* Disable the interrupt to avoid NAPI rescheduling. */ |
| 1581 | disable_irq(ugeth->ug_info->uf_info.irq); |
| 1582 | |
| 1583 | /* Stop NAPI, and possibly wait for its completion. */ |
| 1584 | napi_disable(&ugeth->napi); |
| 1585 | } |
| 1586 | |
| 1587 | static void ugeth_activate(struct ucc_geth_private *ugeth) |
| 1588 | { |
| 1589 | napi_enable(&ugeth->napi); |
| 1590 | enable_irq(ugeth->ug_info->uf_info.irq); |
Anton Vorontsov | 08b5e1c | 2009-12-24 05:31:05 +0000 | [diff] [blame] | 1591 | netif_device_attach(ugeth->ndev); |
Anton Vorontsov | 864fdf8 | 2009-09-10 11:48:12 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1594 | /* Called every time the controller might need to be made |
| 1595 | * aware of new link state. The PHY code conveys this |
| 1596 | * information through variables in the ugeth structure, and this |
| 1597 | * function converts those variables into the appropriate |
| 1598 | * register values, and can bring down the device if needed. |
| 1599 | */ |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1600 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1601 | static void adjust_link(struct net_device *dev) |
| 1602 | { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1603 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1604 | struct ucc_geth __iomem *ug_regs; |
| 1605 | struct ucc_fast __iomem *uf_regs; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1606 | struct phy_device *phydev = ugeth->phydev; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1607 | int new_state = 0; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1608 | |
| 1609 | ug_regs = ugeth->ug_regs; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1610 | uf_regs = ugeth->uccf->uf_regs; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1611 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1612 | if (phydev->link) { |
| 1613 | u32 tempval = in_be32(&ug_regs->maccfg2); |
| 1614 | u32 upsmr = in_be32(&uf_regs->upsmr); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1615 | /* Now we make sure that we can be in full duplex mode. |
| 1616 | * If not, we operate in half-duplex mode. */ |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1617 | if (phydev->duplex != ugeth->oldduplex) { |
| 1618 | new_state = 1; |
| 1619 | if (!(phydev->duplex)) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1620 | tempval &= ~(MACCFG2_FDX); |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1621 | else |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1622 | tempval |= MACCFG2_FDX; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1623 | ugeth->oldduplex = phydev->duplex; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1626 | if (phydev->speed != ugeth->oldspeed) { |
| 1627 | new_state = 1; |
| 1628 | switch (phydev->speed) { |
| 1629 | case SPEED_1000: |
| 1630 | tempval = ((tempval & |
| 1631 | ~(MACCFG2_INTERFACE_MODE_MASK)) | |
| 1632 | MACCFG2_INTERFACE_MODE_BYTE); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1633 | break; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1634 | case SPEED_100: |
| 1635 | case SPEED_10: |
| 1636 | tempval = ((tempval & |
| 1637 | ~(MACCFG2_INTERFACE_MODE_MASK)) | |
| 1638 | MACCFG2_INTERFACE_MODE_NIBBLE); |
| 1639 | /* if reduced mode, re-set UPSMR.R10M */ |
| 1640 | if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) || |
| 1641 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) || |
| 1642 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) || |
Kim Phillips | bd0ceaa | 2007-11-26 16:17:58 -0600 | [diff] [blame] | 1643 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) || |
| 1644 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) || |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1645 | (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) { |
| 1646 | if (phydev->speed == SPEED_10) |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1647 | upsmr |= UCC_GETH_UPSMR_R10M; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1648 | else |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 1649 | upsmr &= ~UCC_GETH_UPSMR_R10M; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1650 | } |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1651 | break; |
| 1652 | default: |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1653 | if (netif_msg_link(ugeth)) |
| 1654 | ugeth_warn( |
| 1655 | "%s: Ack! Speed (%d) is not 10/100/1000!", |
| 1656 | dev->name, phydev->speed); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1657 | break; |
| 1658 | } |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1659 | ugeth->oldspeed = phydev->speed; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | if (!ugeth->oldlink) { |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1663 | new_state = 1; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1664 | ugeth->oldlink = 1; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1665 | } |
Anton Vorontsov | 08fafd8 | 2009-12-24 05:31:20 +0000 | [diff] [blame] | 1666 | |
| 1667 | if (new_state) { |
| 1668 | /* |
| 1669 | * To change the MAC configuration we need to disable |
| 1670 | * the controller. To do so, we have to either grab |
| 1671 | * ugeth->lock, which is a bad idea since 'graceful |
| 1672 | * stop' commands might take quite a while, or we can |
| 1673 | * quiesce driver's activity. |
| 1674 | */ |
| 1675 | ugeth_quiesce(ugeth); |
| 1676 | ugeth_disable(ugeth, COMM_DIR_RX_AND_TX); |
| 1677 | |
| 1678 | out_be32(&ug_regs->maccfg2, tempval); |
| 1679 | out_be32(&uf_regs->upsmr, upsmr); |
| 1680 | |
| 1681 | ugeth_enable(ugeth, COMM_DIR_RX_AND_TX); |
| 1682 | ugeth_activate(ugeth); |
| 1683 | } |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1684 | } else if (ugeth->oldlink) { |
| 1685 | new_state = 1; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1686 | ugeth->oldlink = 0; |
| 1687 | ugeth->oldspeed = 0; |
| 1688 | ugeth->oldduplex = -1; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1689 | } |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1690 | |
| 1691 | if (new_state && netif_msg_link(ugeth)) |
| 1692 | phy_print_status(phydev); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
Haiying Wang | fb1001f | 2009-06-17 13:16:10 +0000 | [diff] [blame] | 1695 | /* Initialize TBI PHY interface for communicating with the |
| 1696 | * SERDES lynx PHY on the chip. We communicate with this PHY |
| 1697 | * through the MDIO bus on each controller, treating it as a |
| 1698 | * "normal" PHY at the address found in the UTBIPA register. We assume |
| 1699 | * that the UTBIPA register is valid. Either the MDIO bus code will set |
| 1700 | * it to a value that doesn't conflict with other PHYs on the bus, or the |
| 1701 | * value doesn't matter, as there are no other PHYs on the bus. |
| 1702 | */ |
| 1703 | static void uec_configure_serdes(struct net_device *dev) |
| 1704 | { |
| 1705 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
| 1706 | struct ucc_geth_info *ug_info = ugeth->ug_info; |
| 1707 | struct phy_device *tbiphy; |
| 1708 | |
| 1709 | if (!ug_info->tbi_node) { |
| 1710 | dev_warn(&dev->dev, "SGMII mode requires that the device " |
| 1711 | "tree specify a tbi-handle\n"); |
| 1712 | return; |
| 1713 | } |
| 1714 | |
| 1715 | tbiphy = of_phy_find_device(ug_info->tbi_node); |
| 1716 | if (!tbiphy) { |
| 1717 | dev_err(&dev->dev, "error: Could not get TBI device\n"); |
| 1718 | return; |
| 1719 | } |
| 1720 | |
| 1721 | /* |
| 1722 | * If the link is already up, we must already be ok, and don't need to |
| 1723 | * configure and reset the TBI<->SerDes link. Maybe U-Boot configured |
| 1724 | * everything for us? Resetting it takes the link down and requires |
| 1725 | * several seconds for it to come back. |
| 1726 | */ |
| 1727 | if (phy_read(tbiphy, ENET_TBI_MII_SR) & TBISR_LSTATUS) |
| 1728 | return; |
| 1729 | |
| 1730 | /* Single clk mode, mii mode off(for serdes communication) */ |
| 1731 | phy_write(tbiphy, ENET_TBI_MII_ANA, TBIANA_SETTINGS); |
| 1732 | |
| 1733 | phy_write(tbiphy, ENET_TBI_MII_TBICON, TBICON_CLK_SELECT); |
| 1734 | |
| 1735 | phy_write(tbiphy, ENET_TBI_MII_CR, TBICR_SETTINGS); |
| 1736 | } |
| 1737 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1738 | /* Configure the PHY for dev. |
| 1739 | * returns 0 if success. -1 if failure |
| 1740 | */ |
| 1741 | static int init_phy(struct net_device *dev) |
| 1742 | { |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1743 | struct ucc_geth_private *priv = netdev_priv(dev); |
Anton Vorontsov | 61fa9dc | 2009-03-22 21:30:52 -0700 | [diff] [blame] | 1744 | struct ucc_geth_info *ug_info = priv->ug_info; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1745 | struct phy_device *phydev; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1746 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1747 | priv->oldlink = 0; |
| 1748 | priv->oldspeed = 0; |
| 1749 | priv->oldduplex = -1; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1750 | |
Grant Likely | 0b9da33 | 2009-04-25 12:53:23 +0000 | [diff] [blame] | 1751 | phydev = of_phy_connect(dev, ug_info->phy_node, &adjust_link, 0, |
| 1752 | priv->phy_interface); |
Anton Vorontsov | 3104a6f | 2009-07-16 21:31:47 +0000 | [diff] [blame] | 1753 | if (!phydev) |
| 1754 | phydev = of_phy_connect_fixed_link(dev, &adjust_link, |
| 1755 | priv->phy_interface); |
Grant Likely | 0b9da33 | 2009-04-25 12:53:23 +0000 | [diff] [blame] | 1756 | if (!phydev) { |
Anton Vorontsov | 3104a6f | 2009-07-16 21:31:47 +0000 | [diff] [blame] | 1757 | dev_err(&dev->dev, "Could not attach to PHY\n"); |
Grant Likely | 0b9da33 | 2009-04-25 12:53:23 +0000 | [diff] [blame] | 1758 | return -ENODEV; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
Haiying Wang | 047584c | 2009-06-02 04:04:15 +0000 | [diff] [blame] | 1761 | if (priv->phy_interface == PHY_INTERFACE_MODE_SGMII) |
| 1762 | uec_configure_serdes(dev); |
| 1763 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1764 | phydev->supported &= (ADVERTISED_10baseT_Half | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1765 | ADVERTISED_10baseT_Full | |
| 1766 | ADVERTISED_100baseT_Half | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1767 | ADVERTISED_100baseT_Full); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1768 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1769 | if (priv->max_speed == SPEED_1000) |
| 1770 | phydev->supported |= ADVERTISED_1000baseT_Full; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1771 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1772 | phydev->advertising = phydev->supported; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1773 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 1774 | priv->phydev = phydev; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1775 | |
| 1776 | return 0; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1779 | static void ugeth_dump_regs(struct ucc_geth_private *ugeth) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1780 | { |
| 1781 | #ifdef DEBUG |
| 1782 | ucc_fast_dump_regs(ugeth->uccf); |
| 1783 | dump_regs(ugeth); |
| 1784 | dump_bds(ugeth); |
| 1785 | #endif |
| 1786 | } |
| 1787 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1788 | static int ugeth_82xx_filtering_clear_all_addr_in_hash(struct ucc_geth_private * |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1789 | ugeth, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1790 | enum enet_addr_type |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1791 | enet_addr_type) |
| 1792 | { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1793 | struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt; |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1794 | struct ucc_fast_private *uccf; |
| 1795 | enum comm_dir comm_dir; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1796 | struct list_head *p_lh; |
| 1797 | u16 i, num; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1798 | u32 __iomem *addr_h; |
| 1799 | u32 __iomem *addr_l; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1800 | u8 *p_counter; |
| 1801 | |
| 1802 | uccf = ugeth->uccf; |
| 1803 | |
| 1804 | p_82xx_addr_filt = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1805 | (struct ucc_geth_82xx_address_filtering_pram __iomem *) |
| 1806 | ugeth->p_rx_glbl_pram->addressfiltering; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1807 | |
| 1808 | if (enet_addr_type == ENET_ADDR_TYPE_GROUP) { |
| 1809 | addr_h = &(p_82xx_addr_filt->gaddr_h); |
| 1810 | addr_l = &(p_82xx_addr_filt->gaddr_l); |
| 1811 | p_lh = &ugeth->group_hash_q; |
| 1812 | p_counter = &(ugeth->numGroupAddrInHash); |
| 1813 | } else if (enet_addr_type == ENET_ADDR_TYPE_INDIVIDUAL) { |
| 1814 | addr_h = &(p_82xx_addr_filt->iaddr_h); |
| 1815 | addr_l = &(p_82xx_addr_filt->iaddr_l); |
| 1816 | p_lh = &ugeth->ind_hash_q; |
| 1817 | p_counter = &(ugeth->numIndAddrInHash); |
| 1818 | } else |
| 1819 | return -EINVAL; |
| 1820 | |
| 1821 | comm_dir = 0; |
| 1822 | if (uccf->enabled_tx) |
| 1823 | comm_dir |= COMM_DIR_TX; |
| 1824 | if (uccf->enabled_rx) |
| 1825 | comm_dir |= COMM_DIR_RX; |
| 1826 | if (comm_dir) |
| 1827 | ugeth_disable(ugeth, comm_dir); |
| 1828 | |
| 1829 | /* Clear the hash table. */ |
| 1830 | out_be32(addr_h, 0x00000000); |
| 1831 | out_be32(addr_l, 0x00000000); |
| 1832 | |
| 1833 | if (!p_lh) |
| 1834 | return 0; |
| 1835 | |
| 1836 | num = *p_counter; |
| 1837 | |
| 1838 | /* Delete all remaining CQ elements */ |
| 1839 | for (i = 0; i < num; i++) |
| 1840 | put_enet_addr_container(ENET_ADDR_CONT_ENTRY(dequeue(p_lh))); |
| 1841 | |
| 1842 | *p_counter = 0; |
| 1843 | |
| 1844 | if (comm_dir) |
| 1845 | ugeth_enable(ugeth, comm_dir); |
| 1846 | |
| 1847 | return 0; |
| 1848 | } |
| 1849 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1850 | static int ugeth_82xx_filtering_clear_addr_in_paddr(struct ucc_geth_private *ugeth, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1851 | u8 paddr_num) |
| 1852 | { |
| 1853 | ugeth->indAddrRegUsed[paddr_num] = 0; /* mark this paddr as not used */ |
| 1854 | return hw_clear_addr_in_paddr(ugeth, paddr_num);/* clear in hardware */ |
| 1855 | } |
| 1856 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1857 | static void ucc_geth_memclean(struct ucc_geth_private *ugeth) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1858 | { |
| 1859 | u16 i, j; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1860 | u8 __iomem *bd; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1861 | |
| 1862 | if (!ugeth) |
| 1863 | return; |
| 1864 | |
Anton Vorontsov | 80a9fad | 2008-02-01 16:22:48 +0300 | [diff] [blame] | 1865 | if (ugeth->uccf) { |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1866 | ucc_fast_free(ugeth->uccf); |
Anton Vorontsov | 80a9fad | 2008-02-01 16:22:48 +0300 | [diff] [blame] | 1867 | ugeth->uccf = NULL; |
| 1868 | } |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1869 | |
| 1870 | if (ugeth->p_thread_data_tx) { |
| 1871 | qe_muram_free(ugeth->thread_dat_tx_offset); |
| 1872 | ugeth->p_thread_data_tx = NULL; |
| 1873 | } |
| 1874 | if (ugeth->p_thread_data_rx) { |
| 1875 | qe_muram_free(ugeth->thread_dat_rx_offset); |
| 1876 | ugeth->p_thread_data_rx = NULL; |
| 1877 | } |
| 1878 | if (ugeth->p_exf_glbl_param) { |
| 1879 | qe_muram_free(ugeth->exf_glbl_param_offset); |
| 1880 | ugeth->p_exf_glbl_param = NULL; |
| 1881 | } |
| 1882 | if (ugeth->p_rx_glbl_pram) { |
| 1883 | qe_muram_free(ugeth->rx_glbl_pram_offset); |
| 1884 | ugeth->p_rx_glbl_pram = NULL; |
| 1885 | } |
| 1886 | if (ugeth->p_tx_glbl_pram) { |
| 1887 | qe_muram_free(ugeth->tx_glbl_pram_offset); |
| 1888 | ugeth->p_tx_glbl_pram = NULL; |
| 1889 | } |
| 1890 | if (ugeth->p_send_q_mem_reg) { |
| 1891 | qe_muram_free(ugeth->send_q_mem_reg_offset); |
| 1892 | ugeth->p_send_q_mem_reg = NULL; |
| 1893 | } |
| 1894 | if (ugeth->p_scheduler) { |
| 1895 | qe_muram_free(ugeth->scheduler_offset); |
| 1896 | ugeth->p_scheduler = NULL; |
| 1897 | } |
| 1898 | if (ugeth->p_tx_fw_statistics_pram) { |
| 1899 | qe_muram_free(ugeth->tx_fw_statistics_pram_offset); |
| 1900 | ugeth->p_tx_fw_statistics_pram = NULL; |
| 1901 | } |
| 1902 | if (ugeth->p_rx_fw_statistics_pram) { |
| 1903 | qe_muram_free(ugeth->rx_fw_statistics_pram_offset); |
| 1904 | ugeth->p_rx_fw_statistics_pram = NULL; |
| 1905 | } |
| 1906 | if (ugeth->p_rx_irq_coalescing_tbl) { |
| 1907 | qe_muram_free(ugeth->rx_irq_coalescing_tbl_offset); |
| 1908 | ugeth->p_rx_irq_coalescing_tbl = NULL; |
| 1909 | } |
| 1910 | if (ugeth->p_rx_bd_qs_tbl) { |
| 1911 | qe_muram_free(ugeth->rx_bd_qs_tbl_offset); |
| 1912 | ugeth->p_rx_bd_qs_tbl = NULL; |
| 1913 | } |
| 1914 | if (ugeth->p_init_enet_param_shadow) { |
| 1915 | return_init_enet_entries(ugeth, |
| 1916 | &(ugeth->p_init_enet_param_shadow-> |
| 1917 | rxthread[0]), |
| 1918 | ENET_INIT_PARAM_MAX_ENTRIES_RX, |
| 1919 | ugeth->ug_info->riscRx, 1); |
| 1920 | return_init_enet_entries(ugeth, |
| 1921 | &(ugeth->p_init_enet_param_shadow-> |
| 1922 | txthread[0]), |
| 1923 | ENET_INIT_PARAM_MAX_ENTRIES_TX, |
| 1924 | ugeth->ug_info->riscTx, 0); |
| 1925 | kfree(ugeth->p_init_enet_param_shadow); |
| 1926 | ugeth->p_init_enet_param_shadow = NULL; |
| 1927 | } |
| 1928 | for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) { |
| 1929 | bd = ugeth->p_tx_bd_ring[i]; |
Nicu Ioan Petru | 3a8205e | 2007-04-13 01:26:29 -0500 | [diff] [blame] | 1930 | if (!bd) |
| 1931 | continue; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1932 | for (j = 0; j < ugeth->ug_info->bdRingLenTx[i]; j++) { |
| 1933 | if (ugeth->tx_skbuff[i][j]) { |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 1934 | dma_unmap_single(ugeth->dev, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1935 | in_be32(&((struct qe_bd __iomem *)bd)->buf), |
| 1936 | (in_be32((u32 __iomem *)bd) & |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1937 | BD_LENGTH_MASK), |
| 1938 | DMA_TO_DEVICE); |
| 1939 | dev_kfree_skb_any(ugeth->tx_skbuff[i][j]); |
| 1940 | ugeth->tx_skbuff[i][j] = NULL; |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | kfree(ugeth->tx_skbuff[i]); |
| 1945 | |
| 1946 | if (ugeth->p_tx_bd_ring[i]) { |
| 1947 | if (ugeth->ug_info->uf_info.bd_mem_part == |
| 1948 | MEM_PART_SYSTEM) |
| 1949 | kfree((void *)ugeth->tx_bd_ring_offset[i]); |
| 1950 | else if (ugeth->ug_info->uf_info.bd_mem_part == |
| 1951 | MEM_PART_MURAM) |
| 1952 | qe_muram_free(ugeth->tx_bd_ring_offset[i]); |
| 1953 | ugeth->p_tx_bd_ring[i] = NULL; |
| 1954 | } |
| 1955 | } |
| 1956 | for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) { |
| 1957 | if (ugeth->p_rx_bd_ring[i]) { |
| 1958 | /* Return existing data buffers in ring */ |
| 1959 | bd = ugeth->p_rx_bd_ring[i]; |
| 1960 | for (j = 0; j < ugeth->ug_info->bdRingLenRx[i]; j++) { |
| 1961 | if (ugeth->rx_skbuff[i][j]) { |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 1962 | dma_unmap_single(ugeth->dev, |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 1963 | in_be32(&((struct qe_bd __iomem *)bd)->buf), |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1964 | ugeth->ug_info-> |
| 1965 | uf_info.max_rx_buf_length + |
| 1966 | UCC_GETH_RX_DATA_BUF_ALIGNMENT, |
| 1967 | DMA_FROM_DEVICE); |
| 1968 | dev_kfree_skb_any( |
| 1969 | ugeth->rx_skbuff[i][j]); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1970 | ugeth->rx_skbuff[i][j] = NULL; |
| 1971 | } |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 1972 | bd += sizeof(struct qe_bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | kfree(ugeth->rx_skbuff[i]); |
| 1976 | |
| 1977 | if (ugeth->ug_info->uf_info.bd_mem_part == |
| 1978 | MEM_PART_SYSTEM) |
| 1979 | kfree((void *)ugeth->rx_bd_ring_offset[i]); |
| 1980 | else if (ugeth->ug_info->uf_info.bd_mem_part == |
| 1981 | MEM_PART_MURAM) |
| 1982 | qe_muram_free(ugeth->rx_bd_ring_offset[i]); |
| 1983 | ugeth->p_rx_bd_ring[i] = NULL; |
| 1984 | } |
| 1985 | } |
| 1986 | while (!list_empty(&ugeth->group_hash_q)) |
| 1987 | put_enet_addr_container(ENET_ADDR_CONT_ENTRY |
| 1988 | (dequeue(&ugeth->group_hash_q))); |
| 1989 | while (!list_empty(&ugeth->ind_hash_q)) |
| 1990 | put_enet_addr_container(ENET_ADDR_CONT_ENTRY |
| 1991 | (dequeue(&ugeth->ind_hash_q))); |
Anton Vorontsov | 3e73fc9 | 2008-12-18 08:23:33 +0000 | [diff] [blame] | 1992 | if (ugeth->ug_regs) { |
| 1993 | iounmap(ugeth->ug_regs); |
| 1994 | ugeth->ug_regs = NULL; |
| 1995 | } |
Anton Vorontsov | 50f238f | 2009-07-07 08:38:42 +0000 | [diff] [blame] | 1996 | |
| 1997 | skb_queue_purge(&ugeth->rx_recycle); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | static void ucc_geth_set_multi(struct net_device *dev) |
| 2001 | { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2002 | struct ucc_geth_private *ugeth; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2003 | struct netdev_hw_addr *ha; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2004 | struct ucc_fast __iomem *uf_regs; |
| 2005 | struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2006 | |
| 2007 | ugeth = netdev_priv(dev); |
| 2008 | |
| 2009 | uf_regs = ugeth->uccf->uf_regs; |
| 2010 | |
| 2011 | if (dev->flags & IFF_PROMISC) { |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 2012 | setbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2013 | } else { |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 2014 | clrbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2015 | |
| 2016 | p_82xx_addr_filt = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2017 | (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2018 | p_rx_glbl_pram->addressfiltering; |
| 2019 | |
| 2020 | if (dev->flags & IFF_ALLMULTI) { |
| 2021 | /* Catch all multicast addresses, so set the |
| 2022 | * filter to all 1's. |
| 2023 | */ |
| 2024 | out_be32(&p_82xx_addr_filt->gaddr_h, 0xffffffff); |
| 2025 | out_be32(&p_82xx_addr_filt->gaddr_l, 0xffffffff); |
| 2026 | } else { |
| 2027 | /* Clear filter and add the addresses in the list. |
| 2028 | */ |
| 2029 | out_be32(&p_82xx_addr_filt->gaddr_h, 0x0); |
| 2030 | out_be32(&p_82xx_addr_filt->gaddr_l, 0x0); |
| 2031 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2032 | netdev_for_each_mc_addr(ha, dev) { |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2033 | /* Only support group multicast for now. |
| 2034 | */ |
Tobias Klauser | 6c64b0c | 2011-01-11 23:31:01 +0000 | [diff] [blame] | 2035 | if (!is_multicast_ether_addr(ha->addr)) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2036 | continue; |
| 2037 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2038 | /* Ask CPM to run CRC and set bit in |
| 2039 | * filter mask. |
| 2040 | */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2041 | hw_add_addr_in_hash(ugeth, ha->addr); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | } |
| 2046 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2047 | static void ucc_geth_stop(struct ucc_geth_private *ugeth) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2048 | { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2049 | struct ucc_geth __iomem *ug_regs = ugeth->ug_regs; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2050 | struct phy_device *phydev = ugeth->phydev; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2051 | |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2052 | ugeth_vdbg("%s: IN", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2053 | |
Joakim Tjernlund | 75e6047 | 2010-11-12 03:55:09 +0000 | [diff] [blame] | 2054 | /* |
| 2055 | * Tell the kernel the link is down. |
| 2056 | * Must be done before disabling the controller |
| 2057 | * or deadlock may happen. |
| 2058 | */ |
| 2059 | phy_stop(phydev); |
| 2060 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2061 | /* Disable the controller */ |
| 2062 | ugeth_disable(ugeth, COMM_DIR_RX_AND_TX); |
| 2063 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2064 | /* Mask all interrupts */ |
Timur Tabi | c6f5047 | 2007-07-10 07:51:11 -0500 | [diff] [blame] | 2065 | out_be32(ugeth->uccf->p_uccm, 0x00000000); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2066 | |
| 2067 | /* Clear all interrupts */ |
| 2068 | out_be32(ugeth->uccf->p_ucce, 0xffffffff); |
| 2069 | |
| 2070 | /* Disable Rx and Tx */ |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 2071 | clrbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2072 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2073 | ucc_geth_memclean(ugeth); |
| 2074 | } |
| 2075 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2076 | static int ucc_struct_init(struct ucc_geth_private *ugeth) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2077 | { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2078 | struct ucc_geth_info *ug_info; |
| 2079 | struct ucc_fast_info *uf_info; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2080 | int i; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2081 | |
| 2082 | ug_info = ugeth->ug_info; |
| 2083 | uf_info = &ug_info->uf_info; |
| 2084 | |
| 2085 | if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) || |
| 2086 | (uf_info->bd_mem_part == MEM_PART_MURAM))) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2087 | if (netif_msg_probe(ugeth)) |
| 2088 | ugeth_err("%s: Bad memory partition value.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2089 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2090 | return -EINVAL; |
| 2091 | } |
| 2092 | |
| 2093 | /* Rx BD lengths */ |
| 2094 | for (i = 0; i < ug_info->numQueuesRx; i++) { |
| 2095 | if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) || |
| 2096 | (ug_info->bdRingLenRx[i] % |
| 2097 | UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2098 | if (netif_msg_probe(ugeth)) |
| 2099 | ugeth_err |
| 2100 | ("%s: Rx BD ring length must be multiple of 4, no smaller than 8.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2101 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2102 | return -EINVAL; |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | /* Tx BD lengths */ |
| 2107 | for (i = 0; i < ug_info->numQueuesTx; i++) { |
| 2108 | if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2109 | if (netif_msg_probe(ugeth)) |
| 2110 | ugeth_err |
| 2111 | ("%s: Tx BD ring length must be no smaller than 2.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2112 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2113 | return -EINVAL; |
| 2114 | } |
| 2115 | } |
| 2116 | |
| 2117 | /* mrblr */ |
| 2118 | if ((uf_info->max_rx_buf_length == 0) || |
| 2119 | (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2120 | if (netif_msg_probe(ugeth)) |
| 2121 | ugeth_err |
| 2122 | ("%s: max_rx_buf_length must be non-zero multiple of 128.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2123 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2124 | return -EINVAL; |
| 2125 | } |
| 2126 | |
| 2127 | /* num Tx queues */ |
| 2128 | if (ug_info->numQueuesTx > NUM_TX_QUEUES) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2129 | if (netif_msg_probe(ugeth)) |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2130 | ugeth_err("%s: number of tx queues too large.", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2131 | return -EINVAL; |
| 2132 | } |
| 2133 | |
| 2134 | /* num Rx queues */ |
| 2135 | if (ug_info->numQueuesRx > NUM_RX_QUEUES) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2136 | if (netif_msg_probe(ugeth)) |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2137 | ugeth_err("%s: number of rx queues too large.", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2138 | return -EINVAL; |
| 2139 | } |
| 2140 | |
| 2141 | /* l2qt */ |
| 2142 | for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) { |
| 2143 | if (ug_info->l2qt[i] >= ug_info->numQueuesRx) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2144 | if (netif_msg_probe(ugeth)) |
| 2145 | ugeth_err |
| 2146 | ("%s: VLAN priority table entry must not be" |
| 2147 | " larger than number of Rx queues.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2148 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2149 | return -EINVAL; |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | /* l3qt */ |
| 2154 | for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) { |
| 2155 | if (ug_info->l3qt[i] >= ug_info->numQueuesRx) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2156 | if (netif_msg_probe(ugeth)) |
| 2157 | ugeth_err |
| 2158 | ("%s: IP priority table entry must not be" |
| 2159 | " larger than number of Rx queues.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2160 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2161 | return -EINVAL; |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | if (ug_info->cam && !ug_info->ecamptr) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2166 | if (netif_msg_probe(ugeth)) |
| 2167 | ugeth_err("%s: If cam mode is chosen, must supply cam ptr.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2168 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2169 | return -EINVAL; |
| 2170 | } |
| 2171 | |
| 2172 | if ((ug_info->numStationAddresses != |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 2173 | UCC_GETH_NUM_OF_STATION_ADDRESSES_1) && |
| 2174 | ug_info->rxExtendedFiltering) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2175 | if (netif_msg_probe(ugeth)) |
| 2176 | ugeth_err("%s: Number of station addresses greater than 1 " |
| 2177 | "not allowed in extended parsing mode.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2178 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2179 | return -EINVAL; |
| 2180 | } |
| 2181 | |
| 2182 | /* Generate uccm_mask for receive */ |
| 2183 | uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */ |
| 2184 | for (i = 0; i < ug_info->numQueuesRx; i++) |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 2185 | uf_info->uccm_mask |= (UCC_GETH_UCCE_RXF0 << i); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2186 | |
| 2187 | for (i = 0; i < ug_info->numQueuesTx; i++) |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 2188 | uf_info->uccm_mask |= (UCC_GETH_UCCE_TXB0 << i); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2189 | /* Initialize the general fast UCC block. */ |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2190 | if (ucc_fast_init(uf_info, &ugeth->uccf)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2191 | if (netif_msg_probe(ugeth)) |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2192 | ugeth_err("%s: Failed to init uccf.", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2193 | return -ENOMEM; |
| 2194 | } |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2195 | |
Haiying Wang | 345f842 | 2009-04-29 14:14:35 -0400 | [diff] [blame] | 2196 | /* read the number of risc engines, update the riscTx and riscRx |
| 2197 | * if there are 4 riscs in QE |
| 2198 | */ |
| 2199 | if (qe_get_num_of_risc() == 4) { |
| 2200 | ug_info->riscTx = QE_RISC_ALLOCATION_FOUR_RISCS; |
| 2201 | ug_info->riscRx = QE_RISC_ALLOCATION_FOUR_RISCS; |
| 2202 | } |
| 2203 | |
Anton Vorontsov | 3e73fc9 | 2008-12-18 08:23:33 +0000 | [diff] [blame] | 2204 | ugeth->ug_regs = ioremap(uf_info->regs, sizeof(*ugeth->ug_regs)); |
| 2205 | if (!ugeth->ug_regs) { |
| 2206 | if (netif_msg_probe(ugeth)) |
| 2207 | ugeth_err("%s: Failed to ioremap regs.", __func__); |
| 2208 | return -ENOMEM; |
| 2209 | } |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2210 | |
Anton Vorontsov | 50f238f | 2009-07-07 08:38:42 +0000 | [diff] [blame] | 2211 | skb_queue_head_init(&ugeth->rx_recycle); |
| 2212 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2213 | return 0; |
| 2214 | } |
| 2215 | |
| 2216 | static int ucc_geth_startup(struct ucc_geth_private *ugeth) |
| 2217 | { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2218 | struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt; |
| 2219 | struct ucc_geth_init_pram __iomem *p_init_enet_pram; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2220 | struct ucc_fast_private *uccf; |
| 2221 | struct ucc_geth_info *ug_info; |
| 2222 | struct ucc_fast_info *uf_info; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2223 | struct ucc_fast __iomem *uf_regs; |
| 2224 | struct ucc_geth __iomem *ug_regs; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2225 | int ret_val = -EINVAL; |
| 2226 | u32 remoder = UCC_GETH_REMODER_INIT; |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 2227 | u32 init_enet_pram_offset, cecr_subblock, command; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2228 | u32 ifstat, i, j, size, l2qt, l3qt, length; |
| 2229 | u16 temoder = UCC_GETH_TEMODER_INIT; |
| 2230 | u16 test; |
| 2231 | u8 function_code = 0; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2232 | u8 __iomem *bd; |
| 2233 | u8 __iomem *endOfRing; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2234 | u8 numThreadsRxNumerical, numThreadsTxNumerical; |
| 2235 | |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2236 | ugeth_vdbg("%s: IN", __func__); |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 2237 | uccf = ugeth->uccf; |
| 2238 | ug_info = ugeth->ug_info; |
| 2239 | uf_info = &ug_info->uf_info; |
| 2240 | uf_regs = uccf->uf_regs; |
| 2241 | ug_regs = ugeth->ug_regs; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2242 | |
| 2243 | switch (ug_info->numThreadsRx) { |
| 2244 | case UCC_GETH_NUM_OF_THREADS_1: |
| 2245 | numThreadsRxNumerical = 1; |
| 2246 | break; |
| 2247 | case UCC_GETH_NUM_OF_THREADS_2: |
| 2248 | numThreadsRxNumerical = 2; |
| 2249 | break; |
| 2250 | case UCC_GETH_NUM_OF_THREADS_4: |
| 2251 | numThreadsRxNumerical = 4; |
| 2252 | break; |
| 2253 | case UCC_GETH_NUM_OF_THREADS_6: |
| 2254 | numThreadsRxNumerical = 6; |
| 2255 | break; |
| 2256 | case UCC_GETH_NUM_OF_THREADS_8: |
| 2257 | numThreadsRxNumerical = 8; |
| 2258 | break; |
| 2259 | default: |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2260 | if (netif_msg_ifup(ugeth)) |
| 2261 | ugeth_err("%s: Bad number of Rx threads value.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2262 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2263 | return -EINVAL; |
| 2264 | break; |
| 2265 | } |
| 2266 | |
| 2267 | switch (ug_info->numThreadsTx) { |
| 2268 | case UCC_GETH_NUM_OF_THREADS_1: |
| 2269 | numThreadsTxNumerical = 1; |
| 2270 | break; |
| 2271 | case UCC_GETH_NUM_OF_THREADS_2: |
| 2272 | numThreadsTxNumerical = 2; |
| 2273 | break; |
| 2274 | case UCC_GETH_NUM_OF_THREADS_4: |
| 2275 | numThreadsTxNumerical = 4; |
| 2276 | break; |
| 2277 | case UCC_GETH_NUM_OF_THREADS_6: |
| 2278 | numThreadsTxNumerical = 6; |
| 2279 | break; |
| 2280 | case UCC_GETH_NUM_OF_THREADS_8: |
| 2281 | numThreadsTxNumerical = 8; |
| 2282 | break; |
| 2283 | default: |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2284 | if (netif_msg_ifup(ugeth)) |
| 2285 | ugeth_err("%s: Bad number of Tx threads value.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2286 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2287 | return -EINVAL; |
| 2288 | break; |
| 2289 | } |
| 2290 | |
| 2291 | /* Calculate rx_extended_features */ |
| 2292 | ugeth->rx_non_dynamic_extended_features = ug_info->ipCheckSumCheck || |
| 2293 | ug_info->ipAddressAlignment || |
| 2294 | (ug_info->numStationAddresses != |
| 2295 | UCC_GETH_NUM_OF_STATION_ADDRESSES_1); |
| 2296 | |
| 2297 | ugeth->rx_extended_features = ugeth->rx_non_dynamic_extended_features || |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 2298 | (ug_info->vlanOperationTagged != UCC_GETH_VLAN_OPERATION_TAGGED_NOP) || |
| 2299 | (ug_info->vlanOperationNonTagged != |
| 2300 | UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2301 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2302 | init_default_reg_vals(&uf_regs->upsmr, |
| 2303 | &ug_regs->maccfg1, &ug_regs->maccfg2); |
| 2304 | |
| 2305 | /* Set UPSMR */ |
| 2306 | /* For more details see the hardware spec. */ |
| 2307 | init_rx_parameters(ug_info->bro, |
| 2308 | ug_info->rsh, ug_info->pro, &uf_regs->upsmr); |
| 2309 | |
| 2310 | /* We're going to ignore other registers for now, */ |
| 2311 | /* except as needed to get up and running */ |
| 2312 | |
| 2313 | /* Set MACCFG1 */ |
| 2314 | /* For more details see the hardware spec. */ |
| 2315 | init_flow_control_params(ug_info->aufc, |
| 2316 | ug_info->receiveFlowControl, |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 2317 | ug_info->transmitFlowControl, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2318 | ug_info->pausePeriod, |
| 2319 | ug_info->extensionField, |
| 2320 | &uf_regs->upsmr, |
| 2321 | &ug_regs->uempr, &ug_regs->maccfg1); |
| 2322 | |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 2323 | setbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2324 | |
| 2325 | /* Set IPGIFG */ |
| 2326 | /* For more details see the hardware spec. */ |
| 2327 | ret_val = init_inter_frame_gap_params(ug_info->nonBackToBackIfgPart1, |
| 2328 | ug_info->nonBackToBackIfgPart2, |
| 2329 | ug_info-> |
| 2330 | miminumInterFrameGapEnforcement, |
| 2331 | ug_info->backToBackInterFrameGap, |
| 2332 | &ug_regs->ipgifg); |
| 2333 | if (ret_val != 0) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2334 | if (netif_msg_ifup(ugeth)) |
| 2335 | ugeth_err("%s: IPGIFG initialization parameter too large.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2336 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2337 | return ret_val; |
| 2338 | } |
| 2339 | |
| 2340 | /* Set HAFDUP */ |
| 2341 | /* For more details see the hardware spec. */ |
| 2342 | ret_val = init_half_duplex_params(ug_info->altBeb, |
| 2343 | ug_info->backPressureNoBackoff, |
| 2344 | ug_info->noBackoff, |
| 2345 | ug_info->excessDefer, |
| 2346 | ug_info->altBebTruncation, |
| 2347 | ug_info->maxRetransmission, |
| 2348 | ug_info->collisionWindow, |
| 2349 | &ug_regs->hafdup); |
| 2350 | if (ret_val != 0) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2351 | if (netif_msg_ifup(ugeth)) |
| 2352 | ugeth_err("%s: Half Duplex initialization parameter too large.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2353 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2354 | return ret_val; |
| 2355 | } |
| 2356 | |
| 2357 | /* Set IFSTAT */ |
| 2358 | /* For more details see the hardware spec. */ |
| 2359 | /* Read only - resets upon read */ |
| 2360 | ifstat = in_be32(&ug_regs->ifstat); |
| 2361 | |
| 2362 | /* Clear UEMPR */ |
| 2363 | /* For more details see the hardware spec. */ |
| 2364 | out_be32(&ug_regs->uempr, 0); |
| 2365 | |
| 2366 | /* Set UESCR */ |
| 2367 | /* For more details see the hardware spec. */ |
| 2368 | init_hw_statistics_gathering_mode((ug_info->statisticsMode & |
| 2369 | UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE), |
| 2370 | 0, &uf_regs->upsmr, &ug_regs->uescr); |
| 2371 | |
| 2372 | /* Allocate Tx bds */ |
| 2373 | for (j = 0; j < ug_info->numQueuesTx; j++) { |
| 2374 | /* Allocate in multiple of |
| 2375 | UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT, |
| 2376 | according to spec */ |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2377 | length = ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2378 | / UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT) |
| 2379 | * UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT; |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2380 | if ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)) % |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2381 | UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT) |
| 2382 | length += UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT; |
| 2383 | if (uf_info->bd_mem_part == MEM_PART_SYSTEM) { |
| 2384 | u32 align = 4; |
| 2385 | if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4) |
| 2386 | align = UCC_GETH_TX_BD_RING_ALIGNMENT; |
| 2387 | ugeth->tx_bd_ring_offset[j] = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2388 | (u32) kmalloc((u32) (length + align), GFP_KERNEL); |
Ahmed S. Darwish | 04b588d | 2007-01-27 00:00:02 -0800 | [diff] [blame] | 2389 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2390 | if (ugeth->tx_bd_ring_offset[j] != 0) |
| 2391 | ugeth->p_tx_bd_ring[j] = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2392 | (u8 __iomem *)((ugeth->tx_bd_ring_offset[j] + |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2393 | align) & ~(align - 1)); |
| 2394 | } else if (uf_info->bd_mem_part == MEM_PART_MURAM) { |
| 2395 | ugeth->tx_bd_ring_offset[j] = |
| 2396 | qe_muram_alloc(length, |
| 2397 | UCC_GETH_TX_BD_RING_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2398 | if (!IS_ERR_VALUE(ugeth->tx_bd_ring_offset[j])) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2399 | ugeth->p_tx_bd_ring[j] = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2400 | (u8 __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2401 | tx_bd_ring_offset[j]); |
| 2402 | } |
| 2403 | if (!ugeth->p_tx_bd_ring[j]) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2404 | if (netif_msg_ifup(ugeth)) |
| 2405 | ugeth_err |
| 2406 | ("%s: Can not allocate memory for Tx bd rings.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2407 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2408 | return -ENOMEM; |
| 2409 | } |
| 2410 | /* Zero unused end of bd ring, according to spec */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2411 | memset_io((void __iomem *)(ugeth->p_tx_bd_ring[j] + |
| 2412 | ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)), 0, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2413 | length - ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | /* Allocate Rx bds */ |
| 2417 | for (j = 0; j < ug_info->numQueuesRx; j++) { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2418 | length = ug_info->bdRingLenRx[j] * sizeof(struct qe_bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2419 | if (uf_info->bd_mem_part == MEM_PART_SYSTEM) { |
| 2420 | u32 align = 4; |
| 2421 | if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4) |
| 2422 | align = UCC_GETH_RX_BD_RING_ALIGNMENT; |
| 2423 | ugeth->rx_bd_ring_offset[j] = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2424 | (u32) kmalloc((u32) (length + align), GFP_KERNEL); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2425 | if (ugeth->rx_bd_ring_offset[j] != 0) |
| 2426 | ugeth->p_rx_bd_ring[j] = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2427 | (u8 __iomem *)((ugeth->rx_bd_ring_offset[j] + |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2428 | align) & ~(align - 1)); |
| 2429 | } else if (uf_info->bd_mem_part == MEM_PART_MURAM) { |
| 2430 | ugeth->rx_bd_ring_offset[j] = |
| 2431 | qe_muram_alloc(length, |
| 2432 | UCC_GETH_RX_BD_RING_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2433 | if (!IS_ERR_VALUE(ugeth->rx_bd_ring_offset[j])) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2434 | ugeth->p_rx_bd_ring[j] = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2435 | (u8 __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2436 | rx_bd_ring_offset[j]); |
| 2437 | } |
| 2438 | if (!ugeth->p_rx_bd_ring[j]) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2439 | if (netif_msg_ifup(ugeth)) |
| 2440 | ugeth_err |
| 2441 | ("%s: Can not allocate memory for Rx bd rings.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2442 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2443 | return -ENOMEM; |
| 2444 | } |
| 2445 | } |
| 2446 | |
| 2447 | /* Init Tx bds */ |
| 2448 | for (j = 0; j < ug_info->numQueuesTx; j++) { |
| 2449 | /* Setup the skbuff rings */ |
Ahmed S. Darwish | 04b588d | 2007-01-27 00:00:02 -0800 | [diff] [blame] | 2450 | ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) * |
| 2451 | ugeth->ug_info->bdRingLenTx[j], |
| 2452 | GFP_KERNEL); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2453 | |
| 2454 | if (ugeth->tx_skbuff[j] == NULL) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2455 | if (netif_msg_ifup(ugeth)) |
| 2456 | ugeth_err("%s: Could not allocate tx_skbuff", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2457 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2458 | return -ENOMEM; |
| 2459 | } |
| 2460 | |
| 2461 | for (i = 0; i < ugeth->ug_info->bdRingLenTx[j]; i++) |
| 2462 | ugeth->tx_skbuff[j][i] = NULL; |
| 2463 | |
| 2464 | ugeth->skb_curtx[j] = ugeth->skb_dirtytx[j] = 0; |
| 2465 | bd = ugeth->confBd[j] = ugeth->txBd[j] = ugeth->p_tx_bd_ring[j]; |
| 2466 | for (i = 0; i < ug_info->bdRingLenTx[j]; i++) { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2467 | /* clear bd buffer */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2468 | out_be32(&((struct qe_bd __iomem *)bd)->buf, 0); |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2469 | /* set bd status and length */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2470 | out_be32((u32 __iomem *)bd, 0); |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2471 | bd += sizeof(struct qe_bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2472 | } |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2473 | bd -= sizeof(struct qe_bd); |
| 2474 | /* set bd status and length */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2475 | out_be32((u32 __iomem *)bd, T_W); /* for last BD set Wrap bit */ |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | /* Init Rx bds */ |
| 2479 | for (j = 0; j < ug_info->numQueuesRx; j++) { |
| 2480 | /* Setup the skbuff rings */ |
Ahmed S. Darwish | 04b588d | 2007-01-27 00:00:02 -0800 | [diff] [blame] | 2481 | ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) * |
| 2482 | ugeth->ug_info->bdRingLenRx[j], |
| 2483 | GFP_KERNEL); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2484 | |
| 2485 | if (ugeth->rx_skbuff[j] == NULL) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2486 | if (netif_msg_ifup(ugeth)) |
| 2487 | ugeth_err("%s: Could not allocate rx_skbuff", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2488 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2489 | return -ENOMEM; |
| 2490 | } |
| 2491 | |
| 2492 | for (i = 0; i < ugeth->ug_info->bdRingLenRx[j]; i++) |
| 2493 | ugeth->rx_skbuff[j][i] = NULL; |
| 2494 | |
| 2495 | ugeth->skb_currx[j] = 0; |
| 2496 | bd = ugeth->rxBd[j] = ugeth->p_rx_bd_ring[j]; |
| 2497 | for (i = 0; i < ug_info->bdRingLenRx[j]; i++) { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2498 | /* set bd status and length */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2499 | out_be32((u32 __iomem *)bd, R_I); |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2500 | /* clear bd buffer */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2501 | out_be32(&((struct qe_bd __iomem *)bd)->buf, 0); |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2502 | bd += sizeof(struct qe_bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2503 | } |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2504 | bd -= sizeof(struct qe_bd); |
| 2505 | /* set bd status and length */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2506 | out_be32((u32 __iomem *)bd, R_W); /* for last BD set Wrap bit */ |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | /* |
| 2510 | * Global PRAM |
| 2511 | */ |
| 2512 | /* Tx global PRAM */ |
| 2513 | /* Allocate global tx parameter RAM page */ |
| 2514 | ugeth->tx_glbl_pram_offset = |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2515 | qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2516 | UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2517 | if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2518 | if (netif_msg_ifup(ugeth)) |
| 2519 | ugeth_err |
| 2520 | ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2521 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2522 | return -ENOMEM; |
| 2523 | } |
| 2524 | ugeth->p_tx_glbl_pram = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2525 | (struct ucc_geth_tx_global_pram __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2526 | tx_glbl_pram_offset); |
| 2527 | /* Zero out p_tx_glbl_pram */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2528 | memset_io((void __iomem *)ugeth->p_tx_glbl_pram, 0, sizeof(struct ucc_geth_tx_global_pram)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2529 | |
| 2530 | /* Fill global PRAM */ |
| 2531 | |
| 2532 | /* TQPTR */ |
| 2533 | /* Size varies with number of Tx threads */ |
| 2534 | ugeth->thread_dat_tx_offset = |
| 2535 | qe_muram_alloc(numThreadsTxNumerical * |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2536 | sizeof(struct ucc_geth_thread_data_tx) + |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2537 | 32 * (numThreadsTxNumerical == 1), |
| 2538 | UCC_GETH_THREAD_DATA_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2539 | if (IS_ERR_VALUE(ugeth->thread_dat_tx_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2540 | if (netif_msg_ifup(ugeth)) |
| 2541 | ugeth_err |
| 2542 | ("%s: Can not allocate DPRAM memory for p_thread_data_tx.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2543 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2544 | return -ENOMEM; |
| 2545 | } |
| 2546 | |
| 2547 | ugeth->p_thread_data_tx = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2548 | (struct ucc_geth_thread_data_tx __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2549 | thread_dat_tx_offset); |
| 2550 | out_be32(&ugeth->p_tx_glbl_pram->tqptr, ugeth->thread_dat_tx_offset); |
| 2551 | |
| 2552 | /* vtagtable */ |
| 2553 | for (i = 0; i < UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX; i++) |
| 2554 | out_be32(&ugeth->p_tx_glbl_pram->vtagtable[i], |
| 2555 | ug_info->vtagtable[i]); |
| 2556 | |
| 2557 | /* iphoffset */ |
| 2558 | for (i = 0; i < TX_IP_OFFSET_ENTRY_MAX; i++) |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2559 | out_8(&ugeth->p_tx_glbl_pram->iphoffset[i], |
| 2560 | ug_info->iphoffset[i]); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2561 | |
| 2562 | /* SQPTR */ |
| 2563 | /* Size varies with number of Tx queues */ |
| 2564 | ugeth->send_q_mem_reg_offset = |
| 2565 | qe_muram_alloc(ug_info->numQueuesTx * |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2566 | sizeof(struct ucc_geth_send_queue_qd), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2567 | UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2568 | if (IS_ERR_VALUE(ugeth->send_q_mem_reg_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2569 | if (netif_msg_ifup(ugeth)) |
| 2570 | ugeth_err |
| 2571 | ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2572 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2573 | return -ENOMEM; |
| 2574 | } |
| 2575 | |
| 2576 | ugeth->p_send_q_mem_reg = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2577 | (struct ucc_geth_send_queue_mem_region __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2578 | send_q_mem_reg_offset); |
| 2579 | out_be32(&ugeth->p_tx_glbl_pram->sqptr, ugeth->send_q_mem_reg_offset); |
| 2580 | |
| 2581 | /* Setup the table */ |
| 2582 | /* Assume BD rings are already established */ |
| 2583 | for (i = 0; i < ug_info->numQueuesTx; i++) { |
| 2584 | endOfRing = |
| 2585 | ugeth->p_tx_bd_ring[i] + (ug_info->bdRingLenTx[i] - |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2586 | 1) * sizeof(struct qe_bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2587 | if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) { |
| 2588 | out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base, |
| 2589 | (u32) virt_to_phys(ugeth->p_tx_bd_ring[i])); |
| 2590 | out_be32(&ugeth->p_send_q_mem_reg->sqqd[i]. |
| 2591 | last_bd_completed_address, |
| 2592 | (u32) virt_to_phys(endOfRing)); |
| 2593 | } else if (ugeth->ug_info->uf_info.bd_mem_part == |
| 2594 | MEM_PART_MURAM) { |
| 2595 | out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base, |
| 2596 | (u32) immrbar_virt_to_phys(ugeth-> |
| 2597 | p_tx_bd_ring[i])); |
| 2598 | out_be32(&ugeth->p_send_q_mem_reg->sqqd[i]. |
| 2599 | last_bd_completed_address, |
| 2600 | (u32) immrbar_virt_to_phys(endOfRing)); |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | /* schedulerbasepointer */ |
| 2605 | |
| 2606 | if (ug_info->numQueuesTx > 1) { |
| 2607 | /* scheduler exists only if more than 1 tx queue */ |
| 2608 | ugeth->scheduler_offset = |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2609 | qe_muram_alloc(sizeof(struct ucc_geth_scheduler), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2610 | UCC_GETH_SCHEDULER_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2611 | if (IS_ERR_VALUE(ugeth->scheduler_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2612 | if (netif_msg_ifup(ugeth)) |
| 2613 | ugeth_err |
| 2614 | ("%s: Can not allocate DPRAM memory for p_scheduler.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2615 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2616 | return -ENOMEM; |
| 2617 | } |
| 2618 | |
| 2619 | ugeth->p_scheduler = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2620 | (struct ucc_geth_scheduler __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2621 | scheduler_offset); |
| 2622 | out_be32(&ugeth->p_tx_glbl_pram->schedulerbasepointer, |
| 2623 | ugeth->scheduler_offset); |
| 2624 | /* Zero out p_scheduler */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2625 | memset_io((void __iomem *)ugeth->p_scheduler, 0, sizeof(struct ucc_geth_scheduler)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2626 | |
| 2627 | /* Set values in scheduler */ |
| 2628 | out_be32(&ugeth->p_scheduler->mblinterval, |
| 2629 | ug_info->mblinterval); |
| 2630 | out_be16(&ugeth->p_scheduler->nortsrbytetime, |
| 2631 | ug_info->nortsrbytetime); |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2632 | out_8(&ugeth->p_scheduler->fracsiz, ug_info->fracsiz); |
| 2633 | out_8(&ugeth->p_scheduler->strictpriorityq, |
| 2634 | ug_info->strictpriorityq); |
| 2635 | out_8(&ugeth->p_scheduler->txasap, ug_info->txasap); |
| 2636 | out_8(&ugeth->p_scheduler->extrabw, ug_info->extrabw); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2637 | for (i = 0; i < NUM_TX_QUEUES; i++) |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2638 | out_8(&ugeth->p_scheduler->weightfactor[i], |
| 2639 | ug_info->weightfactor[i]); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2640 | |
| 2641 | /* Set pointers to cpucount registers in scheduler */ |
| 2642 | ugeth->p_cpucount[0] = &(ugeth->p_scheduler->cpucount0); |
| 2643 | ugeth->p_cpucount[1] = &(ugeth->p_scheduler->cpucount1); |
| 2644 | ugeth->p_cpucount[2] = &(ugeth->p_scheduler->cpucount2); |
| 2645 | ugeth->p_cpucount[3] = &(ugeth->p_scheduler->cpucount3); |
| 2646 | ugeth->p_cpucount[4] = &(ugeth->p_scheduler->cpucount4); |
| 2647 | ugeth->p_cpucount[5] = &(ugeth->p_scheduler->cpucount5); |
| 2648 | ugeth->p_cpucount[6] = &(ugeth->p_scheduler->cpucount6); |
| 2649 | ugeth->p_cpucount[7] = &(ugeth->p_scheduler->cpucount7); |
| 2650 | } |
| 2651 | |
| 2652 | /* schedulerbasepointer */ |
| 2653 | /* TxRMON_PTR (statistics) */ |
| 2654 | if (ug_info-> |
| 2655 | statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) { |
| 2656 | ugeth->tx_fw_statistics_pram_offset = |
| 2657 | qe_muram_alloc(sizeof |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2658 | (struct ucc_geth_tx_firmware_statistics_pram), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2659 | UCC_GETH_TX_STATISTICS_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2660 | if (IS_ERR_VALUE(ugeth->tx_fw_statistics_pram_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2661 | if (netif_msg_ifup(ugeth)) |
| 2662 | ugeth_err |
| 2663 | ("%s: Can not allocate DPRAM memory for" |
| 2664 | " p_tx_fw_statistics_pram.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2665 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2666 | return -ENOMEM; |
| 2667 | } |
| 2668 | ugeth->p_tx_fw_statistics_pram = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2669 | (struct ucc_geth_tx_firmware_statistics_pram __iomem *) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2670 | qe_muram_addr(ugeth->tx_fw_statistics_pram_offset); |
| 2671 | /* Zero out p_tx_fw_statistics_pram */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2672 | memset_io((void __iomem *)ugeth->p_tx_fw_statistics_pram, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2673 | 0, sizeof(struct ucc_geth_tx_firmware_statistics_pram)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | /* temoder */ |
| 2677 | /* Already has speed set */ |
| 2678 | |
| 2679 | if (ug_info->numQueuesTx > 1) |
| 2680 | temoder |= TEMODER_SCHEDULER_ENABLE; |
| 2681 | if (ug_info->ipCheckSumGenerate) |
| 2682 | temoder |= TEMODER_IP_CHECKSUM_GENERATE; |
| 2683 | temoder |= ((ug_info->numQueuesTx - 1) << TEMODER_NUM_OF_QUEUES_SHIFT); |
| 2684 | out_be16(&ugeth->p_tx_glbl_pram->temoder, temoder); |
| 2685 | |
| 2686 | test = in_be16(&ugeth->p_tx_glbl_pram->temoder); |
| 2687 | |
| 2688 | /* Function code register value to be used later */ |
Timur Tabi | 6b0b594 | 2007-10-03 11:34:59 -0500 | [diff] [blame] | 2689 | function_code = UCC_BMR_BO_BE | UCC_BMR_GBL; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2690 | /* Required for QE */ |
| 2691 | |
| 2692 | /* function code register */ |
| 2693 | out_be32(&ugeth->p_tx_glbl_pram->tstate, ((u32) function_code) << 24); |
| 2694 | |
| 2695 | /* Rx global PRAM */ |
| 2696 | /* Allocate global rx parameter RAM page */ |
| 2697 | ugeth->rx_glbl_pram_offset = |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2698 | qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2699 | UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2700 | if (IS_ERR_VALUE(ugeth->rx_glbl_pram_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2701 | if (netif_msg_ifup(ugeth)) |
| 2702 | ugeth_err |
| 2703 | ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2704 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2705 | return -ENOMEM; |
| 2706 | } |
| 2707 | ugeth->p_rx_glbl_pram = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2708 | (struct ucc_geth_rx_global_pram __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2709 | rx_glbl_pram_offset); |
| 2710 | /* Zero out p_rx_glbl_pram */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2711 | memset_io((void __iomem *)ugeth->p_rx_glbl_pram, 0, sizeof(struct ucc_geth_rx_global_pram)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2712 | |
| 2713 | /* Fill global PRAM */ |
| 2714 | |
| 2715 | /* RQPTR */ |
| 2716 | /* Size varies with number of Rx threads */ |
| 2717 | ugeth->thread_dat_rx_offset = |
| 2718 | qe_muram_alloc(numThreadsRxNumerical * |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2719 | sizeof(struct ucc_geth_thread_data_rx), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2720 | UCC_GETH_THREAD_DATA_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2721 | if (IS_ERR_VALUE(ugeth->thread_dat_rx_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2722 | if (netif_msg_ifup(ugeth)) |
| 2723 | ugeth_err |
| 2724 | ("%s: Can not allocate DPRAM memory for p_thread_data_rx.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2725 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2726 | return -ENOMEM; |
| 2727 | } |
| 2728 | |
| 2729 | ugeth->p_thread_data_rx = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2730 | (struct ucc_geth_thread_data_rx __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2731 | thread_dat_rx_offset); |
| 2732 | out_be32(&ugeth->p_rx_glbl_pram->rqptr, ugeth->thread_dat_rx_offset); |
| 2733 | |
| 2734 | /* typeorlen */ |
| 2735 | out_be16(&ugeth->p_rx_glbl_pram->typeorlen, ug_info->typeorlen); |
| 2736 | |
| 2737 | /* rxrmonbaseptr (statistics) */ |
| 2738 | if (ug_info-> |
| 2739 | statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) { |
| 2740 | ugeth->rx_fw_statistics_pram_offset = |
| 2741 | qe_muram_alloc(sizeof |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2742 | (struct ucc_geth_rx_firmware_statistics_pram), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2743 | UCC_GETH_RX_STATISTICS_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2744 | if (IS_ERR_VALUE(ugeth->rx_fw_statistics_pram_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2745 | if (netif_msg_ifup(ugeth)) |
| 2746 | ugeth_err |
| 2747 | ("%s: Can not allocate DPRAM memory for" |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2748 | " p_rx_fw_statistics_pram.", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2749 | return -ENOMEM; |
| 2750 | } |
| 2751 | ugeth->p_rx_fw_statistics_pram = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2752 | (struct ucc_geth_rx_firmware_statistics_pram __iomem *) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2753 | qe_muram_addr(ugeth->rx_fw_statistics_pram_offset); |
| 2754 | /* Zero out p_rx_fw_statistics_pram */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2755 | memset_io((void __iomem *)ugeth->p_rx_fw_statistics_pram, 0, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2756 | sizeof(struct ucc_geth_rx_firmware_statistics_pram)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | /* intCoalescingPtr */ |
| 2760 | |
| 2761 | /* Size varies with number of Rx queues */ |
| 2762 | ugeth->rx_irq_coalescing_tbl_offset = |
| 2763 | qe_muram_alloc(ug_info->numQueuesRx * |
Michael Barkowski | 7563907 | 2007-04-13 01:26:15 -0500 | [diff] [blame] | 2764 | sizeof(struct ucc_geth_rx_interrupt_coalescing_entry) |
| 2765 | + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2766 | if (IS_ERR_VALUE(ugeth->rx_irq_coalescing_tbl_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2767 | if (netif_msg_ifup(ugeth)) |
| 2768 | ugeth_err |
| 2769 | ("%s: Can not allocate DPRAM memory for" |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2770 | " p_rx_irq_coalescing_tbl.", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2771 | return -ENOMEM; |
| 2772 | } |
| 2773 | |
| 2774 | ugeth->p_rx_irq_coalescing_tbl = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2775 | (struct ucc_geth_rx_interrupt_coalescing_table __iomem *) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2776 | qe_muram_addr(ugeth->rx_irq_coalescing_tbl_offset); |
| 2777 | out_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr, |
| 2778 | ugeth->rx_irq_coalescing_tbl_offset); |
| 2779 | |
| 2780 | /* Fill interrupt coalescing table */ |
| 2781 | for (i = 0; i < ug_info->numQueuesRx; i++) { |
| 2782 | out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i]. |
| 2783 | interruptcoalescingmaxvalue, |
| 2784 | ug_info->interruptcoalescingmaxvalue[i]); |
| 2785 | out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i]. |
| 2786 | interruptcoalescingcounter, |
| 2787 | ug_info->interruptcoalescingmaxvalue[i]); |
| 2788 | } |
| 2789 | |
| 2790 | /* MRBLR */ |
| 2791 | init_max_rx_buff_len(uf_info->max_rx_buf_length, |
| 2792 | &ugeth->p_rx_glbl_pram->mrblr); |
| 2793 | /* MFLR */ |
| 2794 | out_be16(&ugeth->p_rx_glbl_pram->mflr, ug_info->maxFrameLength); |
| 2795 | /* MINFLR */ |
| 2796 | init_min_frame_len(ug_info->minFrameLength, |
| 2797 | &ugeth->p_rx_glbl_pram->minflr, |
| 2798 | &ugeth->p_rx_glbl_pram->mrblr); |
| 2799 | /* MAXD1 */ |
| 2800 | out_be16(&ugeth->p_rx_glbl_pram->maxd1, ug_info->maxD1Length); |
| 2801 | /* MAXD2 */ |
| 2802 | out_be16(&ugeth->p_rx_glbl_pram->maxd2, ug_info->maxD2Length); |
| 2803 | |
| 2804 | /* l2qt */ |
| 2805 | l2qt = 0; |
| 2806 | for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) |
| 2807 | l2qt |= (ug_info->l2qt[i] << (28 - 4 * i)); |
| 2808 | out_be32(&ugeth->p_rx_glbl_pram->l2qt, l2qt); |
| 2809 | |
| 2810 | /* l3qt */ |
| 2811 | for (j = 0; j < UCC_GETH_IP_PRIORITY_MAX; j += 8) { |
| 2812 | l3qt = 0; |
| 2813 | for (i = 0; i < 8; i++) |
| 2814 | l3qt |= (ug_info->l3qt[j + i] << (28 - 4 * i)); |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2815 | out_be32(&ugeth->p_rx_glbl_pram->l3qt[j/8], l3qt); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | /* vlantype */ |
| 2819 | out_be16(&ugeth->p_rx_glbl_pram->vlantype, ug_info->vlantype); |
| 2820 | |
| 2821 | /* vlantci */ |
| 2822 | out_be16(&ugeth->p_rx_glbl_pram->vlantci, ug_info->vlantci); |
| 2823 | |
| 2824 | /* ecamptr */ |
| 2825 | out_be32(&ugeth->p_rx_glbl_pram->ecamptr, ug_info->ecamptr); |
| 2826 | |
| 2827 | /* RBDQPTR */ |
| 2828 | /* Size varies with number of Rx queues */ |
| 2829 | ugeth->rx_bd_qs_tbl_offset = |
| 2830 | qe_muram_alloc(ug_info->numQueuesRx * |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2831 | (sizeof(struct ucc_geth_rx_bd_queues_entry) + |
| 2832 | sizeof(struct ucc_geth_rx_prefetched_bds)), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2833 | UCC_GETH_RX_BD_QUEUES_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2834 | if (IS_ERR_VALUE(ugeth->rx_bd_qs_tbl_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2835 | if (netif_msg_ifup(ugeth)) |
| 2836 | ugeth_err |
| 2837 | ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2838 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2839 | return -ENOMEM; |
| 2840 | } |
| 2841 | |
| 2842 | ugeth->p_rx_bd_qs_tbl = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2843 | (struct ucc_geth_rx_bd_queues_entry __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2844 | rx_bd_qs_tbl_offset); |
| 2845 | out_be32(&ugeth->p_rx_glbl_pram->rbdqptr, ugeth->rx_bd_qs_tbl_offset); |
| 2846 | /* Zero out p_rx_bd_qs_tbl */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2847 | memset_io((void __iomem *)ugeth->p_rx_bd_qs_tbl, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2848 | 0, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2849 | ug_info->numQueuesRx * (sizeof(struct ucc_geth_rx_bd_queues_entry) + |
| 2850 | sizeof(struct ucc_geth_rx_prefetched_bds))); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2851 | |
| 2852 | /* Setup the table */ |
| 2853 | /* Assume BD rings are already established */ |
| 2854 | for (i = 0; i < ug_info->numQueuesRx; i++) { |
| 2855 | if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) { |
| 2856 | out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr, |
| 2857 | (u32) virt_to_phys(ugeth->p_rx_bd_ring[i])); |
| 2858 | } else if (ugeth->ug_info->uf_info.bd_mem_part == |
| 2859 | MEM_PART_MURAM) { |
| 2860 | out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr, |
| 2861 | (u32) immrbar_virt_to_phys(ugeth-> |
| 2862 | p_rx_bd_ring[i])); |
| 2863 | } |
| 2864 | /* rest of fields handled by QE */ |
| 2865 | } |
| 2866 | |
| 2867 | /* remoder */ |
| 2868 | /* Already has speed set */ |
| 2869 | |
| 2870 | if (ugeth->rx_extended_features) |
| 2871 | remoder |= REMODER_RX_EXTENDED_FEATURES; |
| 2872 | if (ug_info->rxExtendedFiltering) |
| 2873 | remoder |= REMODER_RX_EXTENDED_FILTERING; |
| 2874 | if (ug_info->dynamicMaxFrameLength) |
| 2875 | remoder |= REMODER_DYNAMIC_MAX_FRAME_LENGTH; |
| 2876 | if (ug_info->dynamicMinFrameLength) |
| 2877 | remoder |= REMODER_DYNAMIC_MIN_FRAME_LENGTH; |
| 2878 | remoder |= |
| 2879 | ug_info->vlanOperationTagged << REMODER_VLAN_OPERATION_TAGGED_SHIFT; |
| 2880 | remoder |= |
| 2881 | ug_info-> |
| 2882 | vlanOperationNonTagged << REMODER_VLAN_OPERATION_NON_TAGGED_SHIFT; |
| 2883 | remoder |= ug_info->rxQoSMode << REMODER_RX_QOS_MODE_SHIFT; |
| 2884 | remoder |= ((ug_info->numQueuesRx - 1) << REMODER_NUM_OF_QUEUES_SHIFT); |
| 2885 | if (ug_info->ipCheckSumCheck) |
| 2886 | remoder |= REMODER_IP_CHECKSUM_CHECK; |
| 2887 | if (ug_info->ipAddressAlignment) |
| 2888 | remoder |= REMODER_IP_ADDRESS_ALIGNMENT; |
| 2889 | out_be32(&ugeth->p_rx_glbl_pram->remoder, remoder); |
| 2890 | |
| 2891 | /* Note that this function must be called */ |
| 2892 | /* ONLY AFTER p_tx_fw_statistics_pram */ |
| 2893 | /* andp_UccGethRxFirmwareStatisticsPram are allocated ! */ |
| 2894 | init_firmware_statistics_gathering_mode((ug_info-> |
| 2895 | statisticsMode & |
| 2896 | UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX), |
| 2897 | (ug_info->statisticsMode & |
| 2898 | UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX), |
| 2899 | &ugeth->p_tx_glbl_pram->txrmonbaseptr, |
| 2900 | ugeth->tx_fw_statistics_pram_offset, |
| 2901 | &ugeth->p_rx_glbl_pram->rxrmonbaseptr, |
| 2902 | ugeth->rx_fw_statistics_pram_offset, |
| 2903 | &ugeth->p_tx_glbl_pram->temoder, |
| 2904 | &ugeth->p_rx_glbl_pram->remoder); |
| 2905 | |
| 2906 | /* function code register */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2907 | out_8(&ugeth->p_rx_glbl_pram->rstate, function_code); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2908 | |
| 2909 | /* initialize extended filtering */ |
| 2910 | if (ug_info->rxExtendedFiltering) { |
| 2911 | if (!ug_info->extendedFilteringChainPointer) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2912 | if (netif_msg_ifup(ugeth)) |
| 2913 | ugeth_err("%s: Null Extended Filtering Chain Pointer.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2914 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2915 | return -EINVAL; |
| 2916 | } |
| 2917 | |
| 2918 | /* Allocate memory for extended filtering Mode Global |
| 2919 | Parameters */ |
| 2920 | ugeth->exf_glbl_param_offset = |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2921 | qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2922 | UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 2923 | if (IS_ERR_VALUE(ugeth->exf_glbl_param_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2924 | if (netif_msg_ifup(ugeth)) |
| 2925 | ugeth_err |
| 2926 | ("%s: Can not allocate DPRAM memory for" |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2927 | " p_exf_glbl_param.", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2928 | return -ENOMEM; |
| 2929 | } |
| 2930 | |
| 2931 | ugeth->p_exf_glbl_param = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2932 | (struct ucc_geth_exf_global_pram __iomem *) qe_muram_addr(ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2933 | exf_glbl_param_offset); |
| 2934 | out_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam, |
| 2935 | ugeth->exf_glbl_param_offset); |
| 2936 | out_be32(&ugeth->p_exf_glbl_param->l2pcdptr, |
| 2937 | (u32) ug_info->extendedFilteringChainPointer); |
| 2938 | |
| 2939 | } else { /* initialize 82xx style address filtering */ |
| 2940 | |
| 2941 | /* Init individual address recognition registers to disabled */ |
| 2942 | |
| 2943 | for (j = 0; j < NUM_OF_PADDRS; j++) |
| 2944 | ugeth_82xx_filtering_clear_addr_in_paddr(ugeth, (u8) j); |
| 2945 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2946 | p_82xx_addr_filt = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 2947 | (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth-> |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2948 | p_rx_glbl_pram->addressfiltering; |
| 2949 | |
| 2950 | ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth, |
| 2951 | ENET_ADDR_TYPE_GROUP); |
| 2952 | ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth, |
| 2953 | ENET_ADDR_TYPE_INDIVIDUAL); |
| 2954 | } |
| 2955 | |
| 2956 | /* |
| 2957 | * Initialize UCC at QE level |
| 2958 | */ |
| 2959 | |
| 2960 | command = QE_INIT_TX_RX; |
| 2961 | |
| 2962 | /* Allocate shadow InitEnet command parameter structure. |
| 2963 | * This is needed because after the InitEnet command is executed, |
| 2964 | * the structure in DPRAM is released, because DPRAM is a premium |
| 2965 | * resource. |
| 2966 | * This shadow structure keeps a copy of what was done so that the |
| 2967 | * allocated resources can be released when the channel is freed. |
| 2968 | */ |
| 2969 | if (!(ugeth->p_init_enet_param_shadow = |
Ahmed S. Darwish | 04b588d | 2007-01-27 00:00:02 -0800 | [diff] [blame] | 2970 | kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 2971 | if (netif_msg_ifup(ugeth)) |
| 2972 | ugeth_err |
| 2973 | ("%s: Can not allocate memory for" |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 2974 | " p_UccInitEnetParamShadows.", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2975 | return -ENOMEM; |
| 2976 | } |
| 2977 | /* Zero out *p_init_enet_param_shadow */ |
| 2978 | memset((char *)ugeth->p_init_enet_param_shadow, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 2979 | 0, sizeof(struct ucc_geth_init_pram)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 2980 | |
| 2981 | /* Fill shadow InitEnet command parameter structure */ |
| 2982 | |
| 2983 | ugeth->p_init_enet_param_shadow->resinit1 = |
| 2984 | ENET_INIT_PARAM_MAGIC_RES_INIT1; |
| 2985 | ugeth->p_init_enet_param_shadow->resinit2 = |
| 2986 | ENET_INIT_PARAM_MAGIC_RES_INIT2; |
| 2987 | ugeth->p_init_enet_param_shadow->resinit3 = |
| 2988 | ENET_INIT_PARAM_MAGIC_RES_INIT3; |
| 2989 | ugeth->p_init_enet_param_shadow->resinit4 = |
| 2990 | ENET_INIT_PARAM_MAGIC_RES_INIT4; |
| 2991 | ugeth->p_init_enet_param_shadow->resinit5 = |
| 2992 | ENET_INIT_PARAM_MAGIC_RES_INIT5; |
| 2993 | ugeth->p_init_enet_param_shadow->rgftgfrxglobal |= |
| 2994 | ((u32) ug_info->numThreadsRx) << ENET_INIT_PARAM_RGF_SHIFT; |
| 2995 | ugeth->p_init_enet_param_shadow->rgftgfrxglobal |= |
| 2996 | ((u32) ug_info->numThreadsTx) << ENET_INIT_PARAM_TGF_SHIFT; |
| 2997 | |
| 2998 | ugeth->p_init_enet_param_shadow->rgftgfrxglobal |= |
| 2999 | ugeth->rx_glbl_pram_offset | ug_info->riscRx; |
| 3000 | if ((ug_info->largestexternallookupkeysize != |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 3001 | QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE) && |
| 3002 | (ug_info->largestexternallookupkeysize != |
| 3003 | QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES) && |
| 3004 | (ug_info->largestexternallookupkeysize != |
| 3005 | QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3006 | if (netif_msg_ifup(ugeth)) |
| 3007 | ugeth_err("%s: Invalid largest External Lookup Key Size.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3008 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3009 | return -EINVAL; |
| 3010 | } |
| 3011 | ugeth->p_init_enet_param_shadow->largestexternallookupkeysize = |
| 3012 | ug_info->largestexternallookupkeysize; |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3013 | size = sizeof(struct ucc_geth_thread_rx_pram); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3014 | if (ug_info->rxExtendedFiltering) { |
| 3015 | size += THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING; |
| 3016 | if (ug_info->largestexternallookupkeysize == |
| 3017 | QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES) |
| 3018 | size += |
| 3019 | THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8; |
| 3020 | if (ug_info->largestexternallookupkeysize == |
| 3021 | QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES) |
| 3022 | size += |
| 3023 | THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16; |
| 3024 | } |
| 3025 | |
| 3026 | if ((ret_val = fill_init_enet_entries(ugeth, &(ugeth-> |
| 3027 | p_init_enet_param_shadow->rxthread[0]), |
| 3028 | (u8) (numThreadsRxNumerical + 1) |
| 3029 | /* Rx needs one extra for terminator */ |
| 3030 | , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT, |
| 3031 | ug_info->riscRx, 1)) != 0) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3032 | if (netif_msg_ifup(ugeth)) |
| 3033 | ugeth_err("%s: Can not fill p_init_enet_param_shadow.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3034 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3035 | return ret_val; |
| 3036 | } |
| 3037 | |
| 3038 | ugeth->p_init_enet_param_shadow->txglobal = |
| 3039 | ugeth->tx_glbl_pram_offset | ug_info->riscTx; |
| 3040 | if ((ret_val = |
| 3041 | fill_init_enet_entries(ugeth, |
| 3042 | &(ugeth->p_init_enet_param_shadow-> |
| 3043 | txthread[0]), numThreadsTxNumerical, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3044 | sizeof(struct ucc_geth_thread_tx_pram), |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3045 | UCC_GETH_THREAD_TX_PRAM_ALIGNMENT, |
| 3046 | ug_info->riscTx, 0)) != 0) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3047 | if (netif_msg_ifup(ugeth)) |
| 3048 | ugeth_err("%s: Can not fill p_init_enet_param_shadow.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3049 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3050 | return ret_val; |
| 3051 | } |
| 3052 | |
| 3053 | /* Load Rx bds with buffers */ |
| 3054 | for (i = 0; i < ug_info->numQueuesRx; i++) { |
| 3055 | if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3056 | if (netif_msg_ifup(ugeth)) |
| 3057 | ugeth_err("%s: Can not fill Rx bds with buffers.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3058 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3059 | return ret_val; |
| 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | /* Allocate InitEnet command parameter structure */ |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3064 | init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 3065 | if (IS_ERR_VALUE(init_enet_pram_offset)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3066 | if (netif_msg_ifup(ugeth)) |
| 3067 | ugeth_err |
| 3068 | ("%s: Can not allocate DPRAM memory for p_init_enet_pram.", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3069 | __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3070 | return -ENOMEM; |
| 3071 | } |
| 3072 | p_init_enet_pram = |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3073 | (struct ucc_geth_init_pram __iomem *) qe_muram_addr(init_enet_pram_offset); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3074 | |
| 3075 | /* Copy shadow InitEnet command parameter structure into PRAM */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3076 | out_8(&p_init_enet_pram->resinit1, |
| 3077 | ugeth->p_init_enet_param_shadow->resinit1); |
| 3078 | out_8(&p_init_enet_pram->resinit2, |
| 3079 | ugeth->p_init_enet_param_shadow->resinit2); |
| 3080 | out_8(&p_init_enet_pram->resinit3, |
| 3081 | ugeth->p_init_enet_param_shadow->resinit3); |
| 3082 | out_8(&p_init_enet_pram->resinit4, |
| 3083 | ugeth->p_init_enet_param_shadow->resinit4); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3084 | out_be16(&p_init_enet_pram->resinit5, |
| 3085 | ugeth->p_init_enet_param_shadow->resinit5); |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3086 | out_8(&p_init_enet_pram->largestexternallookupkeysize, |
| 3087 | ugeth->p_init_enet_param_shadow->largestexternallookupkeysize); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3088 | out_be32(&p_init_enet_pram->rgftgfrxglobal, |
| 3089 | ugeth->p_init_enet_param_shadow->rgftgfrxglobal); |
| 3090 | for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_RX; i++) |
| 3091 | out_be32(&p_init_enet_pram->rxthread[i], |
| 3092 | ugeth->p_init_enet_param_shadow->rxthread[i]); |
| 3093 | out_be32(&p_init_enet_pram->txglobal, |
| 3094 | ugeth->p_init_enet_param_shadow->txglobal); |
| 3095 | for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_TX; i++) |
| 3096 | out_be32(&p_init_enet_pram->txthread[i], |
| 3097 | ugeth->p_init_enet_param_shadow->txthread[i]); |
| 3098 | |
| 3099 | /* Issue QE command */ |
| 3100 | cecr_subblock = |
| 3101 | ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num); |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3102 | qe_issue_cmd(command, cecr_subblock, QE_CR_PROTOCOL_ETHERNET, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3103 | init_enet_pram_offset); |
| 3104 | |
| 3105 | /* Free InitEnet command parameter */ |
| 3106 | qe_muram_free(init_enet_pram_offset); |
| 3107 | |
| 3108 | return 0; |
| 3109 | } |
| 3110 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3111 | /* This is called by the kernel when a frame is ready for transmission. */ |
| 3112 | /* It is pointed to by the dev->hard_start_xmit function pointer */ |
| 3113 | static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 3114 | { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3115 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
Michael Reiss | d5b9049 | 2007-04-13 01:26:19 -0500 | [diff] [blame] | 3116 | #ifdef CONFIG_UGETH_TX_ON_DEMAND |
| 3117 | struct ucc_fast_private *uccf; |
| 3118 | #endif |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3119 | u8 __iomem *bd; /* BD pointer */ |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3120 | u32 bd_status; |
| 3121 | u8 txQ = 0; |
Dongdong Deng | 22580f8 | 2009-08-13 19:12:31 +0000 | [diff] [blame] | 3122 | unsigned long flags; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3123 | |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3124 | ugeth_vdbg("%s: IN", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3125 | |
Dongdong Deng | 22580f8 | 2009-08-13 19:12:31 +0000 | [diff] [blame] | 3126 | spin_lock_irqsave(&ugeth->lock, flags); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3127 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3128 | dev->stats.tx_bytes += skb->len; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3129 | |
| 3130 | /* Start from the next BD that should be filled */ |
| 3131 | bd = ugeth->txBd[txQ]; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3132 | bd_status = in_be32((u32 __iomem *)bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3133 | /* Save the skb pointer so we can free it later */ |
| 3134 | ugeth->tx_skbuff[txQ][ugeth->skb_curtx[txQ]] = skb; |
| 3135 | |
| 3136 | /* Update the current skb pointer (wrapping if this was the last) */ |
| 3137 | ugeth->skb_curtx[txQ] = |
| 3138 | (ugeth->skb_curtx[txQ] + |
| 3139 | 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]); |
| 3140 | |
| 3141 | /* set up the buffer descriptor */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3142 | out_be32(&((struct qe_bd __iomem *)bd)->buf, |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 3143 | dma_map_single(ugeth->dev, skb->data, |
Andy Fleming | 7f80202 | 2008-05-15 17:00:21 -0500 | [diff] [blame] | 3144 | skb->len, DMA_TO_DEVICE)); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3145 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3146 | /* printk(KERN_DEBUG"skb->data is 0x%x\n",skb->data); */ |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3147 | |
| 3148 | bd_status = (bd_status & T_W) | T_R | T_I | T_L | skb->len; |
| 3149 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3150 | /* set bd status and length */ |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3151 | out_be32((u32 __iomem *)bd, bd_status); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3152 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3153 | /* Move to next BD in the ring */ |
| 3154 | if (!(bd_status & T_W)) |
Li Yang | a394f01 | 2007-03-06 16:53:46 +0800 | [diff] [blame] | 3155 | bd += sizeof(struct qe_bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3156 | else |
Li Yang | a394f01 | 2007-03-06 16:53:46 +0800 | [diff] [blame] | 3157 | bd = ugeth->p_tx_bd_ring[txQ]; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3158 | |
| 3159 | /* If the next BD still needs to be cleaned up, then the bds |
| 3160 | are full. We need to tell the kernel to stop sending us stuff. */ |
| 3161 | if (bd == ugeth->confBd[txQ]) { |
| 3162 | if (!netif_queue_stopped(dev)) |
| 3163 | netif_stop_queue(dev); |
| 3164 | } |
| 3165 | |
Li Yang | a394f01 | 2007-03-06 16:53:46 +0800 | [diff] [blame] | 3166 | ugeth->txBd[txQ] = bd; |
| 3167 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3168 | if (ugeth->p_scheduler) { |
| 3169 | ugeth->cpucount[txQ]++; |
| 3170 | /* Indicate to QE that there are more Tx bds ready for |
| 3171 | transmission */ |
| 3172 | /* This is done by writing a running counter of the bd |
| 3173 | count to the scheduler PRAM. */ |
| 3174 | out_be16(ugeth->p_cpucount[txQ], ugeth->cpucount[txQ]); |
| 3175 | } |
| 3176 | |
Michael Reiss | d5b9049 | 2007-04-13 01:26:19 -0500 | [diff] [blame] | 3177 | #ifdef CONFIG_UGETH_TX_ON_DEMAND |
| 3178 | uccf = ugeth->uccf; |
| 3179 | out_be16(uccf->p_utodr, UCC_FAST_TOD); |
| 3180 | #endif |
Dongdong Deng | 22580f8 | 2009-08-13 19:12:31 +0000 | [diff] [blame] | 3181 | spin_unlock_irqrestore(&ugeth->lock, flags); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3182 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 3183 | return NETDEV_TX_OK; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3186 | static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3187 | { |
| 3188 | struct sk_buff *skb; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3189 | u8 __iomem *bd; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3190 | u16 length, howmany = 0; |
| 3191 | u32 bd_status; |
| 3192 | u8 *bdBuffer; |
Andrew Morton | 4b8fdef | 2007-12-13 16:02:55 -0800 | [diff] [blame] | 3193 | struct net_device *dev; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3194 | |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3195 | ugeth_vdbg("%s: IN", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3196 | |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 3197 | dev = ugeth->ndev; |
Emil Medve | 88a15f2 | 2007-10-15 08:43:50 -0500 | [diff] [blame] | 3198 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3199 | /* collect received buffers */ |
| 3200 | bd = ugeth->rxBd[rxQ]; |
| 3201 | |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3202 | bd_status = in_be32((u32 __iomem *)bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3203 | |
| 3204 | /* while there are received buffers and BD is full (~R_E) */ |
| 3205 | while (!((bd_status & (R_E)) || (--rx_work_limit < 0))) { |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3206 | bdBuffer = (u8 *) in_be32(&((struct qe_bd __iomem *)bd)->buf); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3207 | length = (u16) ((bd_status & BD_LENGTH_MASK) - 4); |
| 3208 | skb = ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]]; |
| 3209 | |
| 3210 | /* determine whether buffer is first, last, first and last |
| 3211 | (single buffer frame) or middle (not first and not last) */ |
| 3212 | if (!skb || |
| 3213 | (!(bd_status & (R_F | R_L))) || |
| 3214 | (bd_status & R_ERRORS_FATAL)) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3215 | if (netif_msg_rx_err(ugeth)) |
| 3216 | ugeth_err("%s, %d: ERROR!!! skb - 0x%08x", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3217 | __func__, __LINE__, (u32) skb); |
Anton Vorontsov | 50f238f | 2009-07-07 08:38:42 +0000 | [diff] [blame] | 3218 | if (skb) { |
| 3219 | skb->data = skb->head + NET_SKB_PAD; |
Sergey Matyukevich | db176ed | 2010-06-14 06:35:20 +0000 | [diff] [blame] | 3220 | skb->len = 0; |
| 3221 | skb_reset_tail_pointer(skb); |
Anton Vorontsov | 50f238f | 2009-07-07 08:38:42 +0000 | [diff] [blame] | 3222 | __skb_queue_head(&ugeth->rx_recycle, skb); |
| 3223 | } |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3224 | |
| 3225 | ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL; |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3226 | dev->stats.rx_dropped++; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3227 | } else { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3228 | dev->stats.rx_packets++; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3229 | howmany++; |
| 3230 | |
| 3231 | /* Prep the skb for the packet */ |
| 3232 | skb_put(skb, length); |
| 3233 | |
| 3234 | /* Tell the skb what kind of packet this is */ |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 3235 | skb->protocol = eth_type_trans(skb, ugeth->ndev); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3236 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3237 | dev->stats.rx_bytes += length; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3238 | /* Send the packet up the stack */ |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3239 | netif_receive_skb(skb); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3242 | skb = get_new_skb(ugeth, bd); |
| 3243 | if (!skb) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3244 | if (netif_msg_rx_err(ugeth)) |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3245 | ugeth_warn("%s: No Rx Data Buffer", __func__); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3246 | dev->stats.rx_dropped++; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3247 | break; |
| 3248 | } |
| 3249 | |
| 3250 | ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = skb; |
| 3251 | |
| 3252 | /* update to point at the next skb */ |
| 3253 | ugeth->skb_currx[rxQ] = |
| 3254 | (ugeth->skb_currx[rxQ] + |
| 3255 | 1) & RX_RING_MOD_MASK(ugeth->ug_info->bdRingLenRx[rxQ]); |
| 3256 | |
| 3257 | if (bd_status & R_W) |
| 3258 | bd = ugeth->p_rx_bd_ring[rxQ]; |
| 3259 | else |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3260 | bd += sizeof(struct qe_bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3261 | |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3262 | bd_status = in_be32((u32 __iomem *)bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | ugeth->rxBd[rxQ] = bd; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3266 | return howmany; |
| 3267 | } |
| 3268 | |
| 3269 | static int ucc_geth_tx(struct net_device *dev, u8 txQ) |
| 3270 | { |
| 3271 | /* Start from the next BD that should be filled */ |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3272 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3273 | u8 __iomem *bd; /* BD pointer */ |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3274 | u32 bd_status; |
| 3275 | |
| 3276 | bd = ugeth->confBd[txQ]; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3277 | bd_status = in_be32((u32 __iomem *)bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3278 | |
| 3279 | /* Normal processing. */ |
| 3280 | while ((bd_status & T_R) == 0) { |
Anton Vorontsov | 50f238f | 2009-07-07 08:38:42 +0000 | [diff] [blame] | 3281 | struct sk_buff *skb; |
| 3282 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3283 | /* BD contains already transmitted buffer. */ |
| 3284 | /* Handle the transmitted buffer and release */ |
| 3285 | /* the BD to be used with the current frame */ |
| 3286 | |
Jiajun Wu | 3469242 | 2010-01-18 05:47:50 +0000 | [diff] [blame] | 3287 | skb = ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]]; |
| 3288 | if (!skb) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3289 | break; |
| 3290 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3291 | dev->stats.tx_packets++; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3292 | |
Anton Vorontsov | 50f238f | 2009-07-07 08:38:42 +0000 | [diff] [blame] | 3293 | if (skb_queue_len(&ugeth->rx_recycle) < RX_BD_RING_LEN && |
| 3294 | skb_recycle_check(skb, |
| 3295 | ugeth->ug_info->uf_info.max_rx_buf_length + |
| 3296 | UCC_GETH_RX_DATA_BUF_ALIGNMENT)) |
| 3297 | __skb_queue_head(&ugeth->rx_recycle, skb); |
| 3298 | else |
| 3299 | dev_kfree_skb(skb); |
| 3300 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3301 | ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL; |
| 3302 | ugeth->skb_dirtytx[txQ] = |
| 3303 | (ugeth->skb_dirtytx[txQ] + |
| 3304 | 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]); |
| 3305 | |
| 3306 | /* We freed a buffer, so now we can restart transmission */ |
| 3307 | if (netif_queue_stopped(dev)) |
| 3308 | netif_wake_queue(dev); |
| 3309 | |
| 3310 | /* Advance the confirmation BD pointer */ |
| 3311 | if (!(bd_status & T_W)) |
Li Yang | a394f01 | 2007-03-06 16:53:46 +0800 | [diff] [blame] | 3312 | bd += sizeof(struct qe_bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3313 | else |
Li Yang | a394f01 | 2007-03-06 16:53:46 +0800 | [diff] [blame] | 3314 | bd = ugeth->p_tx_bd_ring[txQ]; |
Andy Fleming | 6fee40e | 2008-05-02 13:01:23 -0500 | [diff] [blame] | 3315 | bd_status = in_be32((u32 __iomem *)bd); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3316 | } |
Li Yang | a394f01 | 2007-03-06 16:53:46 +0800 | [diff] [blame] | 3317 | ugeth->confBd[txQ] = bd; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3318 | return 0; |
| 3319 | } |
| 3320 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3321 | static int ucc_geth_poll(struct napi_struct *napi, int budget) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3322 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3323 | struct ucc_geth_private *ugeth = container_of(napi, struct ucc_geth_private, napi); |
Michael Reiss | 702ff12 | 2007-04-13 01:26:11 -0500 | [diff] [blame] | 3324 | struct ucc_geth_info *ug_info; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3325 | int howmany, i; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3326 | |
Michael Reiss | 702ff12 | 2007-04-13 01:26:11 -0500 | [diff] [blame] | 3327 | ug_info = ugeth->ug_info; |
| 3328 | |
Joakim Tjernlund | 0cededf | 2009-04-17 12:03:48 +0000 | [diff] [blame] | 3329 | /* Tx event processing */ |
| 3330 | spin_lock(&ugeth->lock); |
| 3331 | for (i = 0; i < ug_info->numQueuesTx; i++) |
| 3332 | ucc_geth_tx(ugeth->ndev, i); |
| 3333 | spin_unlock(&ugeth->lock); |
| 3334 | |
Anton Vorontsov | 50f238f | 2009-07-07 08:38:42 +0000 | [diff] [blame] | 3335 | howmany = 0; |
| 3336 | for (i = 0; i < ug_info->numQueuesRx; i++) |
| 3337 | howmany += ucc_geth_rx(ugeth, i, budget - howmany); |
| 3338 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3339 | if (howmany < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3340 | napi_complete(napi); |
Joakim Tjernlund | 0cededf | 2009-04-17 12:03:48 +0000 | [diff] [blame] | 3341 | setbits32(ugeth->uccf->p_uccm, UCCE_RX_EVENTS | UCCE_TX_EVENTS); |
Michael Reiss | 702ff12 | 2007-04-13 01:26:11 -0500 | [diff] [blame] | 3342 | } |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3343 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3344 | return howmany; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3345 | } |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3346 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3347 | static irqreturn_t ucc_geth_irq_handler(int irq, void *info) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3348 | { |
Jeff Garzik | 06efcad | 2007-10-19 03:10:11 -0400 | [diff] [blame] | 3349 | struct net_device *dev = info; |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3350 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
| 3351 | struct ucc_fast_private *uccf; |
| 3352 | struct ucc_geth_info *ug_info; |
Michael Reiss | 702ff12 | 2007-04-13 01:26:11 -0500 | [diff] [blame] | 3353 | register u32 ucce; |
| 3354 | register u32 uccm; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3355 | |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3356 | ugeth_vdbg("%s: IN", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3357 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3358 | uccf = ugeth->uccf; |
| 3359 | ug_info = ugeth->ug_info; |
| 3360 | |
Michael Reiss | 702ff12 | 2007-04-13 01:26:11 -0500 | [diff] [blame] | 3361 | /* read and clear events */ |
| 3362 | ucce = (u32) in_be32(uccf->p_ucce); |
| 3363 | uccm = (u32) in_be32(uccf->p_uccm); |
| 3364 | ucce &= uccm; |
| 3365 | out_be32(uccf->p_ucce, ucce); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3366 | |
Michael Reiss | 702ff12 | 2007-04-13 01:26:11 -0500 | [diff] [blame] | 3367 | /* check for receive events that require processing */ |
Joakim Tjernlund | 0cededf | 2009-04-17 12:03:48 +0000 | [diff] [blame] | 3368 | if (ucce & (UCCE_RX_EVENTS | UCCE_TX_EVENTS)) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3369 | if (napi_schedule_prep(&ugeth->napi)) { |
Joakim Tjernlund | 0cededf | 2009-04-17 12:03:48 +0000 | [diff] [blame] | 3370 | uccm &= ~(UCCE_RX_EVENTS | UCCE_TX_EVENTS); |
Michael Reiss | 702ff12 | 2007-04-13 01:26:11 -0500 | [diff] [blame] | 3371 | out_be32(uccf->p_uccm, uccm); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3372 | __napi_schedule(&ugeth->napi); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3373 | } |
Michael Reiss | 702ff12 | 2007-04-13 01:26:11 -0500 | [diff] [blame] | 3374 | } |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3375 | |
Michael Reiss | 702ff12 | 2007-04-13 01:26:11 -0500 | [diff] [blame] | 3376 | /* Errors and other events */ |
| 3377 | if (ucce & UCCE_OTHER) { |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 3378 | if (ucce & UCC_GETH_UCCE_BSY) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3379 | dev->stats.rx_errors++; |
Timur Tabi | 3bc5342 | 2009-01-11 00:25:21 -0800 | [diff] [blame] | 3380 | if (ucce & UCC_GETH_UCCE_TXE) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3381 | dev->stats.tx_errors++; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3382 | } |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3383 | |
| 3384 | return IRQ_HANDLED; |
| 3385 | } |
| 3386 | |
Anton Vorontsov | 26d29ea | 2008-02-01 16:22:54 +0300 | [diff] [blame] | 3387 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3388 | /* |
| 3389 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 3390 | * without having to re-enable interrupts. It's not called while |
| 3391 | * the interrupt routine is executing. |
| 3392 | */ |
| 3393 | static void ucc_netpoll(struct net_device *dev) |
| 3394 | { |
| 3395 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
| 3396 | int irq = ugeth->ug_info->uf_info.irq; |
| 3397 | |
| 3398 | disable_irq(irq); |
| 3399 | ucc_geth_irq_handler(irq, dev); |
| 3400 | enable_irq(irq); |
| 3401 | } |
| 3402 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 3403 | |
Kevin Hao | 3d6593e | 2009-05-26 20:49:03 -0700 | [diff] [blame] | 3404 | static int ucc_geth_set_mac_addr(struct net_device *dev, void *p) |
| 3405 | { |
| 3406 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
| 3407 | struct sockaddr *addr = p; |
| 3408 | |
| 3409 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3410 | return -EADDRNOTAVAIL; |
| 3411 | |
| 3412 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 3413 | |
| 3414 | /* |
| 3415 | * If device is not running, we will set mac addr register |
| 3416 | * when opening the device. |
| 3417 | */ |
| 3418 | if (!netif_running(dev)) |
| 3419 | return 0; |
| 3420 | |
| 3421 | spin_lock_irq(&ugeth->lock); |
| 3422 | init_mac_station_addr_regs(dev->dev_addr[0], |
| 3423 | dev->dev_addr[1], |
| 3424 | dev->dev_addr[2], |
| 3425 | dev->dev_addr[3], |
| 3426 | dev->dev_addr[4], |
| 3427 | dev->dev_addr[5], |
| 3428 | &ugeth->ug_regs->macstnaddr1, |
| 3429 | &ugeth->ug_regs->macstnaddr2); |
| 3430 | spin_unlock_irq(&ugeth->lock); |
| 3431 | |
| 3432 | return 0; |
| 3433 | } |
| 3434 | |
Anton Vorontsov | 54b1598 | 2009-08-27 07:35:54 +0000 | [diff] [blame] | 3435 | static int ucc_geth_init_mac(struct ucc_geth_private *ugeth) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3436 | { |
Anton Vorontsov | 54b1598 | 2009-08-27 07:35:54 +0000 | [diff] [blame] | 3437 | struct net_device *dev = ugeth->ndev; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3438 | int err; |
| 3439 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3440 | err = ucc_struct_init(ugeth); |
| 3441 | if (err) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3442 | if (netif_msg_ifup(ugeth)) |
Anton Vorontsov | 54b1598 | 2009-08-27 07:35:54 +0000 | [diff] [blame] | 3443 | ugeth_err("%s: Cannot configure internal struct, " |
| 3444 | "aborting.", dev->name); |
| 3445 | goto err; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3446 | } |
| 3447 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3448 | err = ucc_geth_startup(ugeth); |
| 3449 | if (err) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3450 | if (netif_msg_ifup(ugeth)) |
| 3451 | ugeth_err("%s: Cannot configure net device, aborting.", |
| 3452 | dev->name); |
Anton Vorontsov | 54b1598 | 2009-08-27 07:35:54 +0000 | [diff] [blame] | 3453 | goto err; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | err = adjust_enet_interface(ugeth); |
| 3457 | if (err) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3458 | if (netif_msg_ifup(ugeth)) |
| 3459 | ugeth_err("%s: Cannot configure net device, aborting.", |
| 3460 | dev->name); |
Anton Vorontsov | 54b1598 | 2009-08-27 07:35:54 +0000 | [diff] [blame] | 3461 | goto err; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | /* Set MACSTNADDR1, MACSTNADDR2 */ |
| 3465 | /* For more details see the hardware spec. */ |
| 3466 | init_mac_station_addr_regs(dev->dev_addr[0], |
| 3467 | dev->dev_addr[1], |
| 3468 | dev->dev_addr[2], |
| 3469 | dev->dev_addr[3], |
| 3470 | dev->dev_addr[4], |
| 3471 | dev->dev_addr[5], |
| 3472 | &ugeth->ug_regs->macstnaddr1, |
| 3473 | &ugeth->ug_regs->macstnaddr2); |
| 3474 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3475 | err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX); |
| 3476 | if (err) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3477 | if (netif_msg_ifup(ugeth)) |
| 3478 | ugeth_err("%s: Cannot enable net device, aborting.", dev->name); |
Anton Vorontsov | 54b1598 | 2009-08-27 07:35:54 +0000 | [diff] [blame] | 3479 | goto err; |
| 3480 | } |
| 3481 | |
| 3482 | return 0; |
| 3483 | err: |
| 3484 | ucc_geth_stop(ugeth); |
| 3485 | return err; |
| 3486 | } |
| 3487 | |
| 3488 | /* Called when something needs to use the ethernet device */ |
| 3489 | /* Returns 0 for success. */ |
| 3490 | static int ucc_geth_open(struct net_device *dev) |
| 3491 | { |
| 3492 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
| 3493 | int err; |
| 3494 | |
| 3495 | ugeth_vdbg("%s: IN", __func__); |
| 3496 | |
| 3497 | /* Test station address */ |
| 3498 | if (dev->dev_addr[0] & ENET_GROUP_ADDR) { |
| 3499 | if (netif_msg_ifup(ugeth)) |
| 3500 | ugeth_err("%s: Multicast address used for station " |
| 3501 | "address - is this what you wanted?", |
| 3502 | __func__); |
| 3503 | return -EINVAL; |
| 3504 | } |
| 3505 | |
| 3506 | err = init_phy(dev); |
| 3507 | if (err) { |
| 3508 | if (netif_msg_ifup(ugeth)) |
| 3509 | ugeth_err("%s: Cannot initialize PHY, aborting.", |
| 3510 | dev->name); |
| 3511 | return err; |
| 3512 | } |
| 3513 | |
| 3514 | err = ucc_geth_init_mac(ugeth); |
| 3515 | if (err) { |
| 3516 | if (netif_msg_ifup(ugeth)) |
| 3517 | ugeth_err("%s: Cannot initialize MAC, aborting.", |
| 3518 | dev->name); |
| 3519 | goto err; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
Anton Vorontsov | 67c2fb8 | 2008-12-18 08:23:29 +0000 | [diff] [blame] | 3522 | err = request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler, |
| 3523 | 0, "UCC Geth", dev); |
| 3524 | if (err) { |
| 3525 | if (netif_msg_ifup(ugeth)) |
| 3526 | ugeth_err("%s: Cannot get IRQ for net device, aborting.", |
| 3527 | dev->name); |
Anton Vorontsov | 54b1598 | 2009-08-27 07:35:54 +0000 | [diff] [blame] | 3528 | goto err; |
Anton Vorontsov | 67c2fb8 | 2008-12-18 08:23:29 +0000 | [diff] [blame] | 3529 | } |
| 3530 | |
Anton Vorontsov | 54b1598 | 2009-08-27 07:35:54 +0000 | [diff] [blame] | 3531 | phy_start(ugeth->phydev); |
| 3532 | napi_enable(&ugeth->napi); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3533 | netif_start_queue(dev); |
| 3534 | |
Anton Vorontsov | 2394905 | 2009-08-27 07:35:57 +0000 | [diff] [blame] | 3535 | device_set_wakeup_capable(&dev->dev, |
| 3536 | qe_alive_during_sleep() || ugeth->phydev->irq); |
| 3537 | device_set_wakeup_enable(&dev->dev, ugeth->wol_en); |
| 3538 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3539 | return err; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3540 | |
Anton Vorontsov | 54b1598 | 2009-08-27 07:35:54 +0000 | [diff] [blame] | 3541 | err: |
Anton Vorontsov | ba57469 | 2008-12-18 08:23:31 +0000 | [diff] [blame] | 3542 | ucc_geth_stop(ugeth); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3543 | return err; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | /* Stops the kernel queue, and halts the controller */ |
| 3547 | static int ucc_geth_close(struct net_device *dev) |
| 3548 | { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3549 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3550 | |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3551 | ugeth_vdbg("%s: IN", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3552 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3553 | napi_disable(&ugeth->napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3554 | |
Joakim Tjernlund | 2040bd5 | 2010-11-12 03:55:08 +0000 | [diff] [blame] | 3555 | cancel_work_sync(&ugeth->timeout_work); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3556 | ucc_geth_stop(ugeth); |
Joakim Tjernlund | 2040bd5 | 2010-11-12 03:55:08 +0000 | [diff] [blame] | 3557 | phy_disconnect(ugeth->phydev); |
| 3558 | ugeth->phydev = NULL; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3559 | |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 3560 | free_irq(ugeth->ug_info->uf_info.irq, ugeth->ndev); |
Anton Vorontsov | 67c2fb8 | 2008-12-18 08:23:29 +0000 | [diff] [blame] | 3561 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3562 | netif_stop_queue(dev); |
| 3563 | |
| 3564 | return 0; |
| 3565 | } |
| 3566 | |
Anton Vorontsov | fdb614c | 2008-12-23 06:59:25 +0000 | [diff] [blame] | 3567 | /* Reopen device. This will reset the MAC and PHY. */ |
| 3568 | static void ucc_geth_timeout_work(struct work_struct *work) |
| 3569 | { |
| 3570 | struct ucc_geth_private *ugeth; |
| 3571 | struct net_device *dev; |
| 3572 | |
| 3573 | ugeth = container_of(work, struct ucc_geth_private, timeout_work); |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 3574 | dev = ugeth->ndev; |
Anton Vorontsov | fdb614c | 2008-12-23 06:59:25 +0000 | [diff] [blame] | 3575 | |
| 3576 | ugeth_vdbg("%s: IN", __func__); |
| 3577 | |
| 3578 | dev->stats.tx_errors++; |
| 3579 | |
| 3580 | ugeth_dump_regs(ugeth); |
| 3581 | |
| 3582 | if (dev->flags & IFF_UP) { |
| 3583 | /* |
| 3584 | * Must reset MAC *and* PHY. This is done by reopening |
| 3585 | * the device. |
| 3586 | */ |
Joakim Tjernlund | 2040bd5 | 2010-11-12 03:55:08 +0000 | [diff] [blame] | 3587 | netif_tx_stop_all_queues(dev); |
| 3588 | ucc_geth_stop(ugeth); |
| 3589 | ucc_geth_init_mac(ugeth); |
| 3590 | /* Must start PHY here */ |
| 3591 | phy_start(ugeth->phydev); |
| 3592 | netif_tx_start_all_queues(dev); |
Anton Vorontsov | fdb614c | 2008-12-23 06:59:25 +0000 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | netif_tx_schedule_all(dev); |
| 3596 | } |
| 3597 | |
| 3598 | /* |
| 3599 | * ucc_geth_timeout gets called when a packet has not been |
| 3600 | * transmitted after a set amount of time. |
| 3601 | */ |
| 3602 | static void ucc_geth_timeout(struct net_device *dev) |
| 3603 | { |
| 3604 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
| 3605 | |
Anton Vorontsov | fdb614c | 2008-12-23 06:59:25 +0000 | [diff] [blame] | 3606 | schedule_work(&ugeth->timeout_work); |
| 3607 | } |
| 3608 | |
Anton Vorontsov | 2394905 | 2009-08-27 07:35:57 +0000 | [diff] [blame] | 3609 | |
| 3610 | #ifdef CONFIG_PM |
| 3611 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 3612 | static int ucc_geth_suspend(struct platform_device *ofdev, pm_message_t state) |
Anton Vorontsov | 2394905 | 2009-08-27 07:35:57 +0000 | [diff] [blame] | 3613 | { |
| 3614 | struct net_device *ndev = dev_get_drvdata(&ofdev->dev); |
| 3615 | struct ucc_geth_private *ugeth = netdev_priv(ndev); |
| 3616 | |
| 3617 | if (!netif_running(ndev)) |
| 3618 | return 0; |
| 3619 | |
Anton Vorontsov | 29fb00e | 2009-12-30 08:23:32 +0000 | [diff] [blame] | 3620 | netif_device_detach(ndev); |
Anton Vorontsov | 2394905 | 2009-08-27 07:35:57 +0000 | [diff] [blame] | 3621 | napi_disable(&ugeth->napi); |
| 3622 | |
| 3623 | /* |
| 3624 | * Disable the controller, otherwise we'll wakeup on any network |
| 3625 | * activity. |
| 3626 | */ |
| 3627 | ugeth_disable(ugeth, COMM_DIR_RX_AND_TX); |
| 3628 | |
| 3629 | if (ugeth->wol_en & WAKE_MAGIC) { |
| 3630 | setbits32(ugeth->uccf->p_uccm, UCC_GETH_UCCE_MPD); |
| 3631 | setbits32(&ugeth->ug_regs->maccfg2, MACCFG2_MPE); |
| 3632 | ucc_fast_enable(ugeth->uccf, COMM_DIR_RX_AND_TX); |
| 3633 | } else if (!(ugeth->wol_en & WAKE_PHY)) { |
| 3634 | phy_stop(ugeth->phydev); |
| 3635 | } |
| 3636 | |
| 3637 | return 0; |
| 3638 | } |
| 3639 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 3640 | static int ucc_geth_resume(struct platform_device *ofdev) |
Anton Vorontsov | 2394905 | 2009-08-27 07:35:57 +0000 | [diff] [blame] | 3641 | { |
| 3642 | struct net_device *ndev = dev_get_drvdata(&ofdev->dev); |
| 3643 | struct ucc_geth_private *ugeth = netdev_priv(ndev); |
| 3644 | int err; |
| 3645 | |
| 3646 | if (!netif_running(ndev)) |
| 3647 | return 0; |
| 3648 | |
| 3649 | if (qe_alive_during_sleep()) { |
| 3650 | if (ugeth->wol_en & WAKE_MAGIC) { |
| 3651 | ucc_fast_disable(ugeth->uccf, COMM_DIR_RX_AND_TX); |
| 3652 | clrbits32(&ugeth->ug_regs->maccfg2, MACCFG2_MPE); |
| 3653 | clrbits32(ugeth->uccf->p_uccm, UCC_GETH_UCCE_MPD); |
| 3654 | } |
| 3655 | ugeth_enable(ugeth, COMM_DIR_RX_AND_TX); |
| 3656 | } else { |
| 3657 | /* |
| 3658 | * Full reinitialization is required if QE shuts down |
| 3659 | * during sleep. |
| 3660 | */ |
| 3661 | ucc_geth_memclean(ugeth); |
| 3662 | |
| 3663 | err = ucc_geth_init_mac(ugeth); |
| 3664 | if (err) { |
| 3665 | ugeth_err("%s: Cannot initialize MAC, aborting.", |
| 3666 | ndev->name); |
| 3667 | return err; |
| 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | ugeth->oldlink = 0; |
| 3672 | ugeth->oldspeed = 0; |
| 3673 | ugeth->oldduplex = -1; |
| 3674 | |
| 3675 | phy_stop(ugeth->phydev); |
| 3676 | phy_start(ugeth->phydev); |
| 3677 | |
| 3678 | napi_enable(&ugeth->napi); |
Anton Vorontsov | 29fb00e | 2009-12-30 08:23:32 +0000 | [diff] [blame] | 3679 | netif_device_attach(ndev); |
Anton Vorontsov | 2394905 | 2009-08-27 07:35:57 +0000 | [diff] [blame] | 3680 | |
| 3681 | return 0; |
| 3682 | } |
| 3683 | |
| 3684 | #else |
| 3685 | #define ucc_geth_suspend NULL |
| 3686 | #define ucc_geth_resume NULL |
| 3687 | #endif |
| 3688 | |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3689 | static phy_interface_t to_phy_interface(const char *phy_connection_type) |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3690 | { |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3691 | if (strcasecmp(phy_connection_type, "mii") == 0) |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3692 | return PHY_INTERFACE_MODE_MII; |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3693 | if (strcasecmp(phy_connection_type, "gmii") == 0) |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3694 | return PHY_INTERFACE_MODE_GMII; |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3695 | if (strcasecmp(phy_connection_type, "tbi") == 0) |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3696 | return PHY_INTERFACE_MODE_TBI; |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3697 | if (strcasecmp(phy_connection_type, "rmii") == 0) |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3698 | return PHY_INTERFACE_MODE_RMII; |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3699 | if (strcasecmp(phy_connection_type, "rgmii") == 0) |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3700 | return PHY_INTERFACE_MODE_RGMII; |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3701 | if (strcasecmp(phy_connection_type, "rgmii-id") == 0) |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3702 | return PHY_INTERFACE_MODE_RGMII_ID; |
Kim Phillips | bd0ceaa | 2007-11-26 16:17:58 -0600 | [diff] [blame] | 3703 | if (strcasecmp(phy_connection_type, "rgmii-txid") == 0) |
| 3704 | return PHY_INTERFACE_MODE_RGMII_TXID; |
| 3705 | if (strcasecmp(phy_connection_type, "rgmii-rxid") == 0) |
| 3706 | return PHY_INTERFACE_MODE_RGMII_RXID; |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3707 | if (strcasecmp(phy_connection_type, "rtbi") == 0) |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3708 | return PHY_INTERFACE_MODE_RTBI; |
Haiying Wang | 047584c | 2009-06-02 04:04:15 +0000 | [diff] [blame] | 3709 | if (strcasecmp(phy_connection_type, "sgmii") == 0) |
| 3710 | return PHY_INTERFACE_MODE_SGMII; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3711 | |
| 3712 | return PHY_INTERFACE_MODE_MII; |
| 3713 | } |
| 3714 | |
Sergey Matyukevich | d19b514 | 2010-06-07 08:38:13 +0000 | [diff] [blame] | 3715 | static int ucc_geth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 3716 | { |
| 3717 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
| 3718 | |
| 3719 | if (!netif_running(dev)) |
| 3720 | return -EINVAL; |
| 3721 | |
| 3722 | if (!ugeth->phydev) |
| 3723 | return -ENODEV; |
| 3724 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 3725 | return phy_mii_ioctl(ugeth->phydev, rq, cmd); |
Sergey Matyukevich | d19b514 | 2010-06-07 08:38:13 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
Joakim Tjernlund | a9dbae7 | 2009-03-20 21:09:14 +0100 | [diff] [blame] | 3728 | static const struct net_device_ops ucc_geth_netdev_ops = { |
| 3729 | .ndo_open = ucc_geth_open, |
| 3730 | .ndo_stop = ucc_geth_close, |
| 3731 | .ndo_start_xmit = ucc_geth_start_xmit, |
| 3732 | .ndo_validate_addr = eth_validate_addr, |
Kevin Hao | 3d6593e | 2009-05-26 20:49:03 -0700 | [diff] [blame] | 3733 | .ndo_set_mac_address = ucc_geth_set_mac_addr, |
Joakim Tjernlund | a9dbae7 | 2009-03-20 21:09:14 +0100 | [diff] [blame] | 3734 | .ndo_change_mtu = eth_change_mtu, |
| 3735 | .ndo_set_multicast_list = ucc_geth_set_multi, |
| 3736 | .ndo_tx_timeout = ucc_geth_timeout, |
Sergey Matyukevich | d19b514 | 2010-06-07 08:38:13 +0000 | [diff] [blame] | 3737 | .ndo_do_ioctl = ucc_geth_ioctl, |
Joakim Tjernlund | a9dbae7 | 2009-03-20 21:09:14 +0100 | [diff] [blame] | 3738 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3739 | .ndo_poll_controller = ucc_netpoll, |
| 3740 | #endif |
| 3741 | }; |
| 3742 | |
Grant Likely | 7488876 | 2011-02-22 21:05:51 -0700 | [diff] [blame] | 3743 | static int ucc_geth_probe(struct platform_device* ofdev) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3744 | { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3745 | struct device *device = &ofdev->dev; |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 3746 | struct device_node *np = ofdev->dev.of_node; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3747 | struct net_device *dev = NULL; |
| 3748 | struct ucc_geth_private *ugeth = NULL; |
| 3749 | struct ucc_geth_info *ug_info; |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3750 | struct resource res; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3751 | int err, ucc_num, max_speed = 0; |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3752 | const unsigned int *prop; |
Timur Tabi | 9fb1e35 | 2007-12-03 15:17:59 -0600 | [diff] [blame] | 3753 | const char *sprop; |
Li Yang | 9b4c7a4 | 2007-02-08 17:35:54 +0800 | [diff] [blame] | 3754 | const void *mac_addr; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3755 | phy_interface_t phy_interface; |
| 3756 | static const int enet_to_speed[] = { |
| 3757 | SPEED_10, SPEED_10, SPEED_10, |
| 3758 | SPEED_100, SPEED_100, SPEED_100, |
| 3759 | SPEED_1000, SPEED_1000, SPEED_1000, SPEED_1000, |
| 3760 | }; |
| 3761 | static const phy_interface_t enet_to_phy_interface[] = { |
| 3762 | PHY_INTERFACE_MODE_MII, PHY_INTERFACE_MODE_RMII, |
| 3763 | PHY_INTERFACE_MODE_RGMII, PHY_INTERFACE_MODE_MII, |
| 3764 | PHY_INTERFACE_MODE_RMII, PHY_INTERFACE_MODE_RGMII, |
| 3765 | PHY_INTERFACE_MODE_GMII, PHY_INTERFACE_MODE_RGMII, |
| 3766 | PHY_INTERFACE_MODE_TBI, PHY_INTERFACE_MODE_RTBI, |
Haiying Wang | 047584c | 2009-06-02 04:04:15 +0000 | [diff] [blame] | 3767 | PHY_INTERFACE_MODE_SGMII, |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3768 | }; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3769 | |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3770 | ugeth_vdbg("%s: IN", __func__); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3771 | |
Anton Vorontsov | 56626f3 | 2008-04-11 20:06:54 +0400 | [diff] [blame] | 3772 | prop = of_get_property(np, "cell-index", NULL); |
| 3773 | if (!prop) { |
| 3774 | prop = of_get_property(np, "device-id", NULL); |
| 3775 | if (!prop) |
| 3776 | return -ENODEV; |
| 3777 | } |
| 3778 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3779 | ucc_num = *prop - 1; |
| 3780 | if ((ucc_num < 0) || (ucc_num > 7)) |
| 3781 | return -ENODEV; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3782 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3783 | ug_info = &ugeth_info[ucc_num]; |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3784 | if (ug_info == NULL) { |
| 3785 | if (netif_msg_probe(&debug)) |
| 3786 | ugeth_err("%s: [%d] Missing additional data!", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 3787 | __func__, ucc_num); |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3788 | return -ENODEV; |
| 3789 | } |
| 3790 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3791 | ug_info->uf_info.ucc_num = ucc_num; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3792 | |
Timur Tabi | 9fb1e35 | 2007-12-03 15:17:59 -0600 | [diff] [blame] | 3793 | sprop = of_get_property(np, "rx-clock-name", NULL); |
| 3794 | if (sprop) { |
| 3795 | ug_info->uf_info.rx_clock = qe_clock_source(sprop); |
| 3796 | if ((ug_info->uf_info.rx_clock < QE_CLK_NONE) || |
| 3797 | (ug_info->uf_info.rx_clock > QE_CLK24)) { |
| 3798 | printk(KERN_ERR |
| 3799 | "ucc_geth: invalid rx-clock-name property\n"); |
| 3800 | return -EINVAL; |
| 3801 | } |
| 3802 | } else { |
| 3803 | prop = of_get_property(np, "rx-clock", NULL); |
| 3804 | if (!prop) { |
| 3805 | /* If both rx-clock-name and rx-clock are missing, |
| 3806 | we want to tell people to use rx-clock-name. */ |
| 3807 | printk(KERN_ERR |
| 3808 | "ucc_geth: missing rx-clock-name property\n"); |
| 3809 | return -EINVAL; |
| 3810 | } |
| 3811 | if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) { |
| 3812 | printk(KERN_ERR |
| 3813 | "ucc_geth: invalid rx-clock propperty\n"); |
| 3814 | return -EINVAL; |
| 3815 | } |
| 3816 | ug_info->uf_info.rx_clock = *prop; |
| 3817 | } |
| 3818 | |
| 3819 | sprop = of_get_property(np, "tx-clock-name", NULL); |
| 3820 | if (sprop) { |
| 3821 | ug_info->uf_info.tx_clock = qe_clock_source(sprop); |
| 3822 | if ((ug_info->uf_info.tx_clock < QE_CLK_NONE) || |
| 3823 | (ug_info->uf_info.tx_clock > QE_CLK24)) { |
| 3824 | printk(KERN_ERR |
| 3825 | "ucc_geth: invalid tx-clock-name property\n"); |
| 3826 | return -EINVAL; |
| 3827 | } |
| 3828 | } else { |
Joakim Tjernlund | e410553 | 2008-04-29 13:03:57 +0200 | [diff] [blame] | 3829 | prop = of_get_property(np, "tx-clock", NULL); |
Timur Tabi | 9fb1e35 | 2007-12-03 15:17:59 -0600 | [diff] [blame] | 3830 | if (!prop) { |
| 3831 | printk(KERN_ERR |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 3832 | "ucc_geth: missing tx-clock-name property\n"); |
Timur Tabi | 9fb1e35 | 2007-12-03 15:17:59 -0600 | [diff] [blame] | 3833 | return -EINVAL; |
| 3834 | } |
| 3835 | if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) { |
| 3836 | printk(KERN_ERR |
| 3837 | "ucc_geth: invalid tx-clock property\n"); |
| 3838 | return -EINVAL; |
| 3839 | } |
| 3840 | ug_info->uf_info.tx_clock = *prop; |
| 3841 | } |
| 3842 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3843 | err = of_address_to_resource(np, 0, &res); |
| 3844 | if (err) |
| 3845 | return -EINVAL; |
| 3846 | |
| 3847 | ug_info->uf_info.regs = res.start; |
| 3848 | ug_info->uf_info.irq = irq_of_parse_and_map(np, 0); |
Anton Vorontsov | 3104a6f | 2009-07-16 21:31:47 +0000 | [diff] [blame] | 3849 | |
| 3850 | ug_info->phy_node = of_parse_phandle(np, "phy-handle", 0); |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3851 | |
Haiying Wang | fb1001f | 2009-06-17 13:16:10 +0000 | [diff] [blame] | 3852 | /* Find the TBI PHY node. If it's not there, we don't support SGMII */ |
| 3853 | ug_info->tbi_node = of_parse_phandle(np, "tbi-handle", 0); |
| 3854 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3855 | /* get the phy interface type, or default to MII */ |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3856 | prop = of_get_property(np, "phy-connection-type", NULL); |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3857 | if (!prop) { |
| 3858 | /* handle interface property present in old trees */ |
Anton Vorontsov | 3104a6f | 2009-07-16 21:31:47 +0000 | [diff] [blame] | 3859 | prop = of_get_property(ug_info->phy_node, "interface", NULL); |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3860 | if (prop != NULL) { |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3861 | phy_interface = enet_to_phy_interface[*prop]; |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3862 | max_speed = enet_to_speed[*prop]; |
| 3863 | } else |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3864 | phy_interface = PHY_INTERFACE_MODE_MII; |
| 3865 | } else { |
| 3866 | phy_interface = to_phy_interface((const char *)prop); |
| 3867 | } |
| 3868 | |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3869 | /* get speed, or derive from PHY interface */ |
| 3870 | if (max_speed == 0) |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3871 | switch (phy_interface) { |
| 3872 | case PHY_INTERFACE_MODE_GMII: |
| 3873 | case PHY_INTERFACE_MODE_RGMII: |
| 3874 | case PHY_INTERFACE_MODE_RGMII_ID: |
Kim Phillips | bd0ceaa | 2007-11-26 16:17:58 -0600 | [diff] [blame] | 3875 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 3876 | case PHY_INTERFACE_MODE_RGMII_TXID: |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3877 | case PHY_INTERFACE_MODE_TBI: |
| 3878 | case PHY_INTERFACE_MODE_RTBI: |
Haiying Wang | 047584c | 2009-06-02 04:04:15 +0000 | [diff] [blame] | 3879 | case PHY_INTERFACE_MODE_SGMII: |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3880 | max_speed = SPEED_1000; |
| 3881 | break; |
| 3882 | default: |
| 3883 | max_speed = SPEED_100; |
| 3884 | break; |
| 3885 | } |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3886 | |
| 3887 | if (max_speed == SPEED_1000) { |
Kim Phillips | 4e19b5c | 2007-05-11 18:25:07 -0500 | [diff] [blame] | 3888 | /* configure muram FIFOs for gigabit operation */ |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3889 | ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT; |
| 3890 | ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT; |
| 3891 | ug_info->uf_info.urfset = UCC_GETH_URFSET_GIGA_INIT; |
| 3892 | ug_info->uf_info.utfs = UCC_GETH_UTFS_GIGA_INIT; |
| 3893 | ug_info->uf_info.utfet = UCC_GETH_UTFET_GIGA_INIT; |
| 3894 | ug_info->uf_info.utftt = UCC_GETH_UTFTT_GIGA_INIT; |
Joakim Tjernlund | ffea31e | 2008-03-06 18:48:46 +0800 | [diff] [blame] | 3895 | ug_info->numThreadsTx = UCC_GETH_NUM_OF_THREADS_4; |
Haiying Wang | 674e4f9 | 2009-05-01 15:40:49 -0400 | [diff] [blame] | 3896 | |
| 3897 | /* If QE's snum number is 46 which means we need to support |
| 3898 | * 4 UECs at 1000Base-T simultaneously, we need to allocate |
| 3899 | * more Threads to Rx. |
| 3900 | */ |
| 3901 | if (qe_get_num_of_snums() == 46) |
| 3902 | ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_6; |
| 3903 | else |
| 3904 | ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_4; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3905 | } |
| 3906 | |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3907 | if (netif_msg_probe(&debug)) |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 3908 | printk(KERN_INFO "ucc_geth: UCC%1d at 0x%8x (irq = %d)\n", |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3909 | ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs, |
| 3910 | ug_info->uf_info.irq); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3911 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3912 | /* Create an ethernet device instance */ |
| 3913 | dev = alloc_etherdev(sizeof(*ugeth)); |
| 3914 | |
| 3915 | if (dev == NULL) |
| 3916 | return -ENOMEM; |
| 3917 | |
| 3918 | ugeth = netdev_priv(dev); |
| 3919 | spin_lock_init(&ugeth->lock); |
| 3920 | |
Anton Vorontsov | 80a9fad | 2008-02-01 16:22:48 +0300 | [diff] [blame] | 3921 | /* Create CQs for hash tables */ |
| 3922 | INIT_LIST_HEAD(&ugeth->group_hash_q); |
| 3923 | INIT_LIST_HEAD(&ugeth->ind_hash_q); |
| 3924 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3925 | dev_set_drvdata(device, dev); |
| 3926 | |
| 3927 | /* Set the dev->base_addr to the gfar reg region */ |
| 3928 | dev->base_addr = (unsigned long)(ug_info->uf_info.regs); |
| 3929 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3930 | SET_NETDEV_DEV(dev, device); |
| 3931 | |
| 3932 | /* Fill in the dev structure */ |
Li Yang | ac42185 | 2007-07-19 11:47:47 +0800 | [diff] [blame] | 3933 | uec_set_ethtool_ops(dev); |
Joakim Tjernlund | a9dbae7 | 2009-03-20 21:09:14 +0100 | [diff] [blame] | 3934 | dev->netdev_ops = &ucc_geth_netdev_ops; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3935 | dev->watchdog_timeo = TX_TIMEOUT; |
Anton Vorontsov | 1762a29 | 2008-12-18 08:23:26 +0000 | [diff] [blame] | 3936 | INIT_WORK(&ugeth->timeout_work, ucc_geth_timeout_work); |
Joakim Tjernlund | 0cededf | 2009-04-17 12:03:48 +0000 | [diff] [blame] | 3937 | netif_napi_add(dev, &ugeth->napi, ucc_geth_poll, 64); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3938 | dev->mtu = 1500; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3939 | |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3940 | ugeth->msg_enable = netif_msg_init(debug.msg_enable, UGETH_MSG_DEFAULT); |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3941 | ugeth->phy_interface = phy_interface; |
| 3942 | ugeth->max_speed = max_speed; |
| 3943 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3944 | err = register_netdev(dev); |
| 3945 | if (err) { |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 3946 | if (netif_msg_probe(ugeth)) |
| 3947 | ugeth_err("%s: Cannot register net device, aborting.", |
| 3948 | dev->name); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3949 | free_netdev(dev); |
| 3950 | return err; |
| 3951 | } |
| 3952 | |
Timur Tabi | e9eb70c | 2007-02-21 14:40:12 -0600 | [diff] [blame] | 3953 | mac_addr = of_get_mac_address(np); |
Li Yang | 9b4c7a4 | 2007-02-08 17:35:54 +0800 | [diff] [blame] | 3954 | if (mac_addr) |
| 3955 | memcpy(dev->dev_addr, mac_addr, 6); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3956 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3957 | ugeth->ug_info = ug_info; |
Anton Vorontsov | da1aa63 | 2009-04-02 01:26:07 -0700 | [diff] [blame] | 3958 | ugeth->dev = device; |
| 3959 | ugeth->ndev = dev; |
Haiying Wang | b1c4a9dd | 2009-01-29 17:28:04 -0800 | [diff] [blame] | 3960 | ugeth->node = np; |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 3961 | |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3962 | return 0; |
| 3963 | } |
| 3964 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 3965 | static int ucc_geth_remove(struct platform_device* ofdev) |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3966 | { |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3967 | struct device *device = &ofdev->dev; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3968 | struct net_device *dev = dev_get_drvdata(device); |
| 3969 | struct ucc_geth_private *ugeth = netdev_priv(dev); |
| 3970 | |
Anton Vorontsov | 80a9fad | 2008-02-01 16:22:48 +0300 | [diff] [blame] | 3971 | unregister_netdev(dev); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3972 | free_netdev(dev); |
Anton Vorontsov | 80a9fad | 2008-02-01 16:22:48 +0300 | [diff] [blame] | 3973 | ucc_geth_memclean(ugeth); |
| 3974 | dev_set_drvdata(device, NULL); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3975 | |
| 3976 | return 0; |
| 3977 | } |
| 3978 | |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3979 | static struct of_device_id ucc_geth_match[] = { |
| 3980 | { |
| 3981 | .type = "network", |
| 3982 | .compatible = "ucc_geth", |
| 3983 | }, |
| 3984 | {}, |
| 3985 | }; |
| 3986 | |
| 3987 | MODULE_DEVICE_TABLE(of, ucc_geth_match); |
| 3988 | |
Grant Likely | 7488876 | 2011-02-22 21:05:51 -0700 | [diff] [blame] | 3989 | static struct platform_driver ucc_geth_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 3990 | .driver = { |
| 3991 | .name = DRV_NAME, |
| 3992 | .owner = THIS_MODULE, |
| 3993 | .of_match_table = ucc_geth_match, |
| 3994 | }, |
Li Yang | 18a8e86 | 2006-10-19 21:07:34 -0500 | [diff] [blame] | 3995 | .probe = ucc_geth_probe, |
| 3996 | .remove = ucc_geth_remove, |
Anton Vorontsov | 2394905 | 2009-08-27 07:35:57 +0000 | [diff] [blame] | 3997 | .suspend = ucc_geth_suspend, |
| 3998 | .resume = ucc_geth_resume, |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 3999 | }; |
| 4000 | |
| 4001 | static int __init ucc_geth_init(void) |
| 4002 | { |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 4003 | int i, ret; |
| 4004 | |
Li Yang | 890de95 | 2007-07-19 11:48:29 +0800 | [diff] [blame] | 4005 | if (netif_msg_drv(&debug)) |
| 4006 | printk(KERN_INFO "ucc_geth: " DRV_DESC "\n"); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 4007 | for (i = 0; i < 8; i++) |
| 4008 | memcpy(&(ugeth_info[i]), &ugeth_primary_info, |
| 4009 | sizeof(ugeth_primary_info)); |
| 4010 | |
Grant Likely | 7488876 | 2011-02-22 21:05:51 -0700 | [diff] [blame] | 4011 | ret = platform_driver_register(&ucc_geth_driver); |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 4012 | |
Kim Phillips | 728de4c9 | 2007-04-13 01:26:03 -0500 | [diff] [blame] | 4013 | return ret; |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | static void __exit ucc_geth_exit(void) |
| 4017 | { |
Grant Likely | 7488876 | 2011-02-22 21:05:51 -0700 | [diff] [blame] | 4018 | platform_driver_unregister(&ucc_geth_driver); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | module_init(ucc_geth_init); |
| 4022 | module_exit(ucc_geth_exit); |
| 4023 | |
| 4024 | MODULE_AUTHOR("Freescale Semiconductor, Inc"); |
| 4025 | MODULE_DESCRIPTION(DRV_DESC); |
Kim Phillips | c2bcf00 | 2007-04-13 01:26:36 -0500 | [diff] [blame] | 4026 | MODULE_VERSION(DRV_VERSION); |
Li Yang | ce973b1 | 2006-08-14 23:00:11 -0700 | [diff] [blame] | 4027 | MODULE_LICENSE("GPL"); |