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