blob: a39368a46352a99cf73f633c99a28bbb728d2e0d [file] [log] [blame]
Li Yangce973b12006-08-14 23:00:11 -07001/*
Haiying Wang047584c2009-06-02 04:04:15 +00002 * Copyright (C) 2006-2009 Freescale Semicondutor, Inc. All rights reserved.
Li Yangce973b12006-08-14 23:00:11 -07003 *
4 * Author: Shlomi Gridish <gridish@freescale.com>
Li Yang18a8e862006-10-19 21:07:34 -05005 * Li Yang <leoli@freescale.com>
Li Yangce973b12006-08-14 23:00:11 -07006 *
7 * Description:
8 * QE UCC Gigabit Ethernet Driver
9 *
Li Yangce973b12006-08-14 23:00:11 -070010 * 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 Yangce973b12006-08-14 23:00:11 -070026#include <linux/dma-mapping.h>
Li Yangce973b12006-08-14 23:00:11 -070027#include <linux/mii.h>
Kim Phillips728de4c92007-04-13 01:26:03 -050028#include <linux/phy.h>
Timur Tabidf19b6b2007-01-09 12:31:38 -060029#include <linux/workqueue.h>
Grant Likely0b9da332009-04-25 12:53:23 +000030#include <linux/of_mdio.h>
Stephen Rothwell55b6c8e2008-05-23 16:28:54 +100031#include <linux/of_platform.h>
Li Yangce973b12006-08-14 23:00:11 -070032
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 Fleming1577ece2009-02-04 16:42:12 -080042#include "fsl_pq_mdio.h"
Li Yangce973b12006-08-14 23:00:11 -070043
44#undef DEBUG
45
Li Yangce973b12006-08-14 23:00:11 -070046#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 Yang890de952007-07-19 11:48:29 +080063#define UGETH_MSG_DEFAULT (NETIF_MSG_IFUP << 1 ) - 1
Li Yangce973b12006-08-14 23:00:11 -070064
Emil Medve88a15f22007-10-15 08:43:50 -050065
Li Yangce973b12006-08-14 23:00:11 -070066static DEFINE_SPINLOCK(ugeth_lock);
67
Li Yang890de952007-07-19 11:48:29 +080068static struct {
69 u32 msg_enable;
70} debug = { -1 };
71
72module_param_named(debug, debug.msg_enable, int, 0);
73MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 0xffff=all)");
74
Li Yang18a8e862006-10-19 21:07:34 -050075static struct ucc_geth_info ugeth_primary_info = {
Li Yangce973b12006-08-14 23:00:11 -070076 .uf_info = {
77 .bd_mem_part = MEM_PART_SYSTEM,
78 .rtsm = UCC_FAST_SEND_IDLES_BETWEEN_FRAMES,
79 .max_rx_buf_length = 1536,
Kim Phillips728de4c92007-04-13 01:26:03 -050080 /* adjusted at startup if max-speed 1000 */
Li Yangce973b12006-08-14 23:00:11 -070081 .urfs = UCC_GETH_URFS_INIT,
82 .urfet = UCC_GETH_URFET_INIT,
83 .urfset = UCC_GETH_URFSET_INIT,
84 .utfs = UCC_GETH_UTFS_INIT,
85 .utfet = UCC_GETH_UTFET_INIT,
86 .utftt = UCC_GETH_UTFTT_INIT,
Li Yangce973b12006-08-14 23:00:11 -070087 .ufpt = 256,
88 .mode = UCC_FAST_PROTOCOL_MODE_ETHERNET,
89 .ttx_trx = UCC_FAST_GUMR_TRANSPARENT_TTX_TRX_NORMAL,
90 .tenc = UCC_FAST_TX_ENCODING_NRZ,
91 .renc = UCC_FAST_RX_ENCODING_NRZ,
92 .tcrc = UCC_FAST_16_BIT_CRC,
93 .synl = UCC_FAST_SYNC_LEN_NOT_USED,
94 },
95 .numQueuesTx = 1,
96 .numQueuesRx = 1,
97 .extendedFilteringChainPointer = ((uint32_t) NULL),
98 .typeorlen = 3072 /*1536 */ ,
99 .nonBackToBackIfgPart1 = 0x40,
100 .nonBackToBackIfgPart2 = 0x60,
101 .miminumInterFrameGapEnforcement = 0x50,
102 .backToBackInterFrameGap = 0x60,
103 .mblinterval = 128,
104 .nortsrbytetime = 5,
105 .fracsiz = 1,
106 .strictpriorityq = 0xff,
107 .altBebTruncation = 0xa,
108 .excessDefer = 1,
109 .maxRetransmission = 0xf,
110 .collisionWindow = 0x37,
111 .receiveFlowControl = 1,
Li Yangac421852007-07-19 11:47:47 +0800112 .transmitFlowControl = 1,
Li Yangce973b12006-08-14 23:00:11 -0700113 .maxGroupAddrInHash = 4,
114 .maxIndAddrInHash = 4,
115 .prel = 7,
116 .maxFrameLength = 1518,
117 .minFrameLength = 64,
118 .maxD1Length = 1520,
119 .maxD2Length = 1520,
120 .vlantype = 0x8100,
121 .ecamptr = ((uint32_t) NULL),
122 .eventRegMask = UCCE_OTHER,
123 .pausePeriod = 0xf000,
124 .interruptcoalescingmaxvalue = {1, 1, 1, 1, 1, 1, 1, 1},
125 .bdRingLenTx = {
126 TX_BD_RING_LEN,
127 TX_BD_RING_LEN,
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
135 .bdRingLenRx = {
136 RX_BD_RING_LEN,
137 RX_BD_RING_LEN,
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
145 .numStationAddresses = UCC_GETH_NUM_OF_STATION_ADDRESSES_1,
146 .largestexternallookupkeysize =
147 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE,
Li Yangac421852007-07-19 11:47:47 +0800148 .statisticsMode = UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE |
149 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX |
150 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX,
Li Yangce973b12006-08-14 23:00:11 -0700151 .vlanOperationTagged = UCC_GETH_VLAN_OPERATION_TAGGED_NOP,
152 .vlanOperationNonTagged = UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP,
153 .rxQoSMode = UCC_GETH_QOS_MODE_DEFAULT,
154 .aufc = UPSMR_AUTOMATIC_FLOW_CONTROL_MODE_NONE,
155 .padAndCrc = MACCFG2_PAD_AND_CRC_MODE_PAD_AND_CRC,
Joakim Tjernlundffea31e2008-03-06 18:48:46 +0800156 .numThreadsTx = UCC_GETH_NUM_OF_THREADS_1,
157 .numThreadsRx = UCC_GETH_NUM_OF_THREADS_1,
Li Yangce973b12006-08-14 23:00:11 -0700158 .riscTx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
159 .riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
160};
161
Li Yang18a8e862006-10-19 21:07:34 -0500162static struct ucc_geth_info ugeth_info[8];
Li Yangce973b12006-08-14 23:00:11 -0700163
164#ifdef DEBUG
165static void mem_disp(u8 *addr, int size)
166{
167 u8 *i;
168 int size16Aling = (size >> 4) << 4;
169 int size4Aling = (size >> 2) << 2;
170 int notAlign = 0;
171 if (size % 16)
172 notAlign = 1;
173
174 for (i = addr; (u32) i < (u32) addr + size16Aling; i += 16)
175 printk("0x%08x: %08x %08x %08x %08x\r\n",
176 (u32) i,
177 *((u32 *) (i)),
178 *((u32 *) (i + 4)),
179 *((u32 *) (i + 8)), *((u32 *) (i + 12)));
180 if (notAlign == 1)
181 printk("0x%08x: ", (u32) i);
182 for (; (u32) i < (u32) addr + size4Aling; i += 4)
183 printk("%08x ", *((u32 *) (i)));
184 for (; (u32) i < (u32) addr + size; i++)
185 printk("%02x", *((u8 *) (i)));
186 if (notAlign == 1)
187 printk("\r\n");
188}
189#endif /* DEBUG */
190
Li Yangce973b12006-08-14 23:00:11 -0700191static struct list_head *dequeue(struct list_head *lh)
192{
193 unsigned long flags;
194
Scott Wood1083cfe2006-12-07 13:31:07 -0600195 spin_lock_irqsave(&ugeth_lock, flags);
Li Yangce973b12006-08-14 23:00:11 -0700196 if (!list_empty(lh)) {
197 struct list_head *node = lh->next;
198 list_del(node);
Scott Wood1083cfe2006-12-07 13:31:07 -0600199 spin_unlock_irqrestore(&ugeth_lock, flags);
Li Yangce973b12006-08-14 23:00:11 -0700200 return node;
201 } else {
Scott Wood1083cfe2006-12-07 13:31:07 -0600202 spin_unlock_irqrestore(&ugeth_lock, flags);
Li Yangce973b12006-08-14 23:00:11 -0700203 return NULL;
204 }
205}
206
Andy Fleming6fee40e2008-05-02 13:01:23 -0500207static struct sk_buff *get_new_skb(struct ucc_geth_private *ugeth,
208 u8 __iomem *bd)
Li Yangce973b12006-08-14 23:00:11 -0700209{
210 struct sk_buff *skb = NULL;
211
Anton Vorontsov50f238f2009-07-07 08:38:42 +0000212 skb = __skb_dequeue(&ugeth->rx_recycle);
213 if (!skb)
214 skb = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length +
215 UCC_GETH_RX_DATA_BUF_ALIGNMENT);
Li Yangce973b12006-08-14 23:00:11 -0700216 if (skb == NULL)
217 return NULL;
218
219 /* We need the data buffer to be aligned properly. We will reserve
220 * as many bytes as needed to align the data properly
221 */
222 skb_reserve(skb,
223 UCC_GETH_RX_DATA_BUF_ALIGNMENT -
224 (((unsigned)skb->data) & (UCC_GETH_RX_DATA_BUF_ALIGNMENT -
225 1)));
226
Anton Vorontsovda1aa632009-04-02 01:26:07 -0700227 skb->dev = ugeth->ndev;
Li Yangce973b12006-08-14 23:00:11 -0700228
Andy Fleming6fee40e2008-05-02 13:01:23 -0500229 out_be32(&((struct qe_bd __iomem *)bd)->buf,
Anton Vorontsovda1aa632009-04-02 01:26:07 -0700230 dma_map_single(ugeth->dev,
Li Yangce973b12006-08-14 23:00:11 -0700231 skb->data,
232 ugeth->ug_info->uf_info.max_rx_buf_length +
233 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
234 DMA_FROM_DEVICE));
235
Andy Fleming6fee40e2008-05-02 13:01:23 -0500236 out_be32((u32 __iomem *)bd,
237 (R_E | R_I | (in_be32((u32 __iomem*)bd) & R_W)));
Li Yangce973b12006-08-14 23:00:11 -0700238
239 return skb;
240}
241
Li Yang18a8e862006-10-19 21:07:34 -0500242static int rx_bd_buffer_set(struct ucc_geth_private *ugeth, u8 rxQ)
Li Yangce973b12006-08-14 23:00:11 -0700243{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500244 u8 __iomem *bd;
Li Yangce973b12006-08-14 23:00:11 -0700245 u32 bd_status;
246 struct sk_buff *skb;
247 int i;
248
249 bd = ugeth->p_rx_bd_ring[rxQ];
250 i = 0;
251
252 do {
Andy Fleming6fee40e2008-05-02 13:01:23 -0500253 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -0700254 skb = get_new_skb(ugeth, bd);
255
256 if (!skb) /* If can not allocate data buffer,
257 abort. Cleanup will be elsewhere */
258 return -ENOMEM;
259
260 ugeth->rx_skbuff[rxQ][i] = skb;
261
262 /* advance the BD pointer */
Li Yang18a8e862006-10-19 21:07:34 -0500263 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -0700264 i++;
265 } while (!(bd_status & R_W));
266
267 return 0;
268}
269
Li Yang18a8e862006-10-19 21:07:34 -0500270static int fill_init_enet_entries(struct ucc_geth_private *ugeth,
Andy Fleming6fee40e2008-05-02 13:01:23 -0500271 u32 *p_start,
Li Yangce973b12006-08-14 23:00:11 -0700272 u8 num_entries,
273 u32 thread_size,
274 u32 thread_alignment,
Haiying Wang345f8422009-04-29 14:14:35 -0400275 unsigned int risc,
Li Yangce973b12006-08-14 23:00:11 -0700276 int skip_page_for_first_entry)
277{
278 u32 init_enet_offset;
279 u8 i;
280 int snum;
281
282 for (i = 0; i < num_entries; i++) {
283 if ((snum = qe_get_snum()) < 0) {
Li Yang890de952007-07-19 11:48:29 +0800284 if (netif_msg_ifup(ugeth))
285 ugeth_err("fill_init_enet_entries: Can not get SNUM.");
Li Yangce973b12006-08-14 23:00:11 -0700286 return snum;
287 }
288 if ((i == 0) && skip_page_for_first_entry)
289 /* First entry of Rx does not have page */
290 init_enet_offset = 0;
291 else {
292 init_enet_offset =
293 qe_muram_alloc(thread_size, thread_alignment);
Timur Tabi4c356302007-05-08 14:46:36 -0500294 if (IS_ERR_VALUE(init_enet_offset)) {
Li Yang890de952007-07-19 11:48:29 +0800295 if (netif_msg_ifup(ugeth))
296 ugeth_err("fill_init_enet_entries: Can not allocate DPRAM memory.");
Li Yangce973b12006-08-14 23:00:11 -0700297 qe_put_snum((u8) snum);
298 return -ENOMEM;
299 }
300 }
301 *(p_start++) =
302 ((u8) snum << ENET_INIT_PARAM_SNUM_SHIFT) | init_enet_offset
303 | risc;
304 }
305
306 return 0;
307}
308
Li Yang18a8e862006-10-19 21:07:34 -0500309static int return_init_enet_entries(struct ucc_geth_private *ugeth,
Andy Fleming6fee40e2008-05-02 13:01:23 -0500310 u32 *p_start,
Li Yangce973b12006-08-14 23:00:11 -0700311 u8 num_entries,
Haiying Wang345f8422009-04-29 14:14:35 -0400312 unsigned int risc,
Li Yangce973b12006-08-14 23:00:11 -0700313 int skip_page_for_first_entry)
314{
315 u32 init_enet_offset;
316 u8 i;
317 int snum;
318
319 for (i = 0; i < num_entries; i++) {
Andy Fleming6fee40e2008-05-02 13:01:23 -0500320 u32 val = *p_start;
321
Li Yangce973b12006-08-14 23:00:11 -0700322 /* Check that this entry was actually valid --
323 needed in case failed in allocations */
Andy Fleming6fee40e2008-05-02 13:01:23 -0500324 if ((val & ENET_INIT_PARAM_RISC_MASK) == risc) {
Li Yangce973b12006-08-14 23:00:11 -0700325 snum =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500326 (u32) (val & ENET_INIT_PARAM_SNUM_MASK) >>
Li Yangce973b12006-08-14 23:00:11 -0700327 ENET_INIT_PARAM_SNUM_SHIFT;
328 qe_put_snum((u8) snum);
329 if (!((i == 0) && skip_page_for_first_entry)) {
330 /* First entry of Rx does not have page */
331 init_enet_offset =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500332 (val & ENET_INIT_PARAM_PTR_MASK);
Li Yangce973b12006-08-14 23:00:11 -0700333 qe_muram_free(init_enet_offset);
334 }
Andy Fleming6fee40e2008-05-02 13:01:23 -0500335 *p_start++ = 0;
Li Yangce973b12006-08-14 23:00:11 -0700336 }
337 }
338
339 return 0;
340}
341
342#ifdef DEBUG
Li Yang18a8e862006-10-19 21:07:34 -0500343static int dump_init_enet_entries(struct ucc_geth_private *ugeth,
Andy Fleming6fee40e2008-05-02 13:01:23 -0500344 u32 __iomem *p_start,
Li Yangce973b12006-08-14 23:00:11 -0700345 u8 num_entries,
346 u32 thread_size,
Haiying Wang345f8422009-04-29 14:14:35 -0400347 unsigned int risc,
Li Yangce973b12006-08-14 23:00:11 -0700348 int skip_page_for_first_entry)
349{
350 u32 init_enet_offset;
351 u8 i;
352 int snum;
353
354 for (i = 0; i < num_entries; i++) {
Andy Fleming6fee40e2008-05-02 13:01:23 -0500355 u32 val = in_be32(p_start);
356
Li Yangce973b12006-08-14 23:00:11 -0700357 /* Check that this entry was actually valid --
358 needed in case failed in allocations */
Andy Fleming6fee40e2008-05-02 13:01:23 -0500359 if ((val & ENET_INIT_PARAM_RISC_MASK) == risc) {
Li Yangce973b12006-08-14 23:00:11 -0700360 snum =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500361 (u32) (val & ENET_INIT_PARAM_SNUM_MASK) >>
Li Yangce973b12006-08-14 23:00:11 -0700362 ENET_INIT_PARAM_SNUM_SHIFT;
363 qe_put_snum((u8) snum);
364 if (!((i == 0) && skip_page_for_first_entry)) {
365 /* First entry of Rx does not have page */
366 init_enet_offset =
367 (in_be32(p_start) &
368 ENET_INIT_PARAM_PTR_MASK);
369 ugeth_info("Init enet entry %d:", i);
370 ugeth_info("Base address: 0x%08x",
371 (u32)
372 qe_muram_addr(init_enet_offset));
373 mem_disp(qe_muram_addr(init_enet_offset),
374 thread_size);
375 }
376 p_start++;
377 }
378 }
379
380 return 0;
381}
382#endif
383
Li Yang18a8e862006-10-19 21:07:34 -0500384static void put_enet_addr_container(struct enet_addr_container *enet_addr_cont)
Li Yangce973b12006-08-14 23:00:11 -0700385{
386 kfree(enet_addr_cont);
387}
388
Timur Tabidf19b6b2007-01-09 12:31:38 -0600389static void set_mac_addr(__be16 __iomem *reg, u8 *mac)
Li Yangce973b12006-08-14 23:00:11 -0700390{
Li Yang18a8e862006-10-19 21:07:34 -0500391 out_be16(&reg[0], ((u16)mac[5] << 8) | mac[4]);
392 out_be16(&reg[1], ((u16)mac[3] << 8) | mac[2]);
393 out_be16(&reg[2], ((u16)mac[1] << 8) | mac[0]);
394}
395
Li Yang18a8e862006-10-19 21:07:34 -0500396static int hw_clear_addr_in_paddr(struct ucc_geth_private *ugeth, u8 paddr_num)
Li Yangce973b12006-08-14 23:00:11 -0700397{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500398 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Li Yangce973b12006-08-14 23:00:11 -0700399
400 if (!(paddr_num < NUM_OF_PADDRS)) {
Harvey Harrisonb39d66a2008-08-20 16:52:04 -0700401 ugeth_warn("%s: Illagel paddr_num.", __func__);
Li Yangce973b12006-08-14 23:00:11 -0700402 return -EINVAL;
403 }
404
405 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500406 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->p_rx_glbl_pram->
Li Yangce973b12006-08-14 23:00:11 -0700407 addressfiltering;
408
409 /* Writing address ff.ff.ff.ff.ff.ff disables address
410 recognition for this register */
411 out_be16(&p_82xx_addr_filt->paddr[paddr_num].h, 0xffff);
412 out_be16(&p_82xx_addr_filt->paddr[paddr_num].m, 0xffff);
413 out_be16(&p_82xx_addr_filt->paddr[paddr_num].l, 0xffff);
414
415 return 0;
416}
417
Li Yang18a8e862006-10-19 21:07:34 -0500418static void hw_add_addr_in_hash(struct ucc_geth_private *ugeth,
419 u8 *p_enet_addr)
Li Yangce973b12006-08-14 23:00:11 -0700420{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500421 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Li Yangce973b12006-08-14 23:00:11 -0700422 u32 cecr_subblock;
423
424 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500425 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->p_rx_glbl_pram->
Li Yangce973b12006-08-14 23:00:11 -0700426 addressfiltering;
427
428 cecr_subblock =
429 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
430
431 /* Ethernet frames are defined in Little Endian mode,
432 therefor to insert */
433 /* the address to the hash (Big Endian mode), we reverse the bytes.*/
Li Yang18a8e862006-10-19 21:07:34 -0500434
435 set_mac_addr(&p_82xx_addr_filt->taddr.h, p_enet_addr);
Li Yangce973b12006-08-14 23:00:11 -0700436
437 qe_issue_cmd(QE_SET_GROUP_ADDRESS, cecr_subblock,
Li Yang18a8e862006-10-19 21:07:34 -0500438 QE_CR_PROTOCOL_ETHERNET, 0);
Li Yangce973b12006-08-14 23:00:11 -0700439}
440
Li Yang18a8e862006-10-19 21:07:34 -0500441static inline int compare_addr(u8 **addr1, u8 **addr2)
Li Yangce973b12006-08-14 23:00:11 -0700442{
443 return memcmp(addr1, addr2, ENET_NUM_OCTETS_PER_ADDRESS);
444}
445
446#ifdef DEBUG
Li Yang18a8e862006-10-19 21:07:34 -0500447static void get_statistics(struct ucc_geth_private *ugeth,
448 struct ucc_geth_tx_firmware_statistics *
Li Yangce973b12006-08-14 23:00:11 -0700449 tx_firmware_statistics,
Li Yang18a8e862006-10-19 21:07:34 -0500450 struct ucc_geth_rx_firmware_statistics *
Li Yangce973b12006-08-14 23:00:11 -0700451 rx_firmware_statistics,
Li Yang18a8e862006-10-19 21:07:34 -0500452 struct ucc_geth_hardware_statistics *hardware_statistics)
Li Yangce973b12006-08-14 23:00:11 -0700453{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500454 struct ucc_fast __iomem *uf_regs;
455 struct ucc_geth __iomem *ug_regs;
Li Yang18a8e862006-10-19 21:07:34 -0500456 struct ucc_geth_tx_firmware_statistics_pram *p_tx_fw_statistics_pram;
457 struct ucc_geth_rx_firmware_statistics_pram *p_rx_fw_statistics_pram;
Li Yangce973b12006-08-14 23:00:11 -0700458
459 ug_regs = ugeth->ug_regs;
Andy Fleming6fee40e2008-05-02 13:01:23 -0500460 uf_regs = (struct ucc_fast __iomem *) ug_regs;
Li Yangce973b12006-08-14 23:00:11 -0700461 p_tx_fw_statistics_pram = ugeth->p_tx_fw_statistics_pram;
462 p_rx_fw_statistics_pram = ugeth->p_rx_fw_statistics_pram;
463
464 /* Tx firmware only if user handed pointer and driver actually
465 gathers Tx firmware statistics */
466 if (tx_firmware_statistics && p_tx_fw_statistics_pram) {
467 tx_firmware_statistics->sicoltx =
468 in_be32(&p_tx_fw_statistics_pram->sicoltx);
469 tx_firmware_statistics->mulcoltx =
470 in_be32(&p_tx_fw_statistics_pram->mulcoltx);
471 tx_firmware_statistics->latecoltxfr =
472 in_be32(&p_tx_fw_statistics_pram->latecoltxfr);
473 tx_firmware_statistics->frabortduecol =
474 in_be32(&p_tx_fw_statistics_pram->frabortduecol);
475 tx_firmware_statistics->frlostinmactxer =
476 in_be32(&p_tx_fw_statistics_pram->frlostinmactxer);
477 tx_firmware_statistics->carriersenseertx =
478 in_be32(&p_tx_fw_statistics_pram->carriersenseertx);
479 tx_firmware_statistics->frtxok =
480 in_be32(&p_tx_fw_statistics_pram->frtxok);
481 tx_firmware_statistics->txfrexcessivedefer =
482 in_be32(&p_tx_fw_statistics_pram->txfrexcessivedefer);
483 tx_firmware_statistics->txpkts256 =
484 in_be32(&p_tx_fw_statistics_pram->txpkts256);
485 tx_firmware_statistics->txpkts512 =
486 in_be32(&p_tx_fw_statistics_pram->txpkts512);
487 tx_firmware_statistics->txpkts1024 =
488 in_be32(&p_tx_fw_statistics_pram->txpkts1024);
489 tx_firmware_statistics->txpktsjumbo =
490 in_be32(&p_tx_fw_statistics_pram->txpktsjumbo);
491 }
492
493 /* Rx firmware only if user handed pointer and driver actually
494 * gathers Rx firmware statistics */
495 if (rx_firmware_statistics && p_rx_fw_statistics_pram) {
496 int i;
497 rx_firmware_statistics->frrxfcser =
498 in_be32(&p_rx_fw_statistics_pram->frrxfcser);
499 rx_firmware_statistics->fraligner =
500 in_be32(&p_rx_fw_statistics_pram->fraligner);
501 rx_firmware_statistics->inrangelenrxer =
502 in_be32(&p_rx_fw_statistics_pram->inrangelenrxer);
503 rx_firmware_statistics->outrangelenrxer =
504 in_be32(&p_rx_fw_statistics_pram->outrangelenrxer);
505 rx_firmware_statistics->frtoolong =
506 in_be32(&p_rx_fw_statistics_pram->frtoolong);
507 rx_firmware_statistics->runt =
508 in_be32(&p_rx_fw_statistics_pram->runt);
509 rx_firmware_statistics->verylongevent =
510 in_be32(&p_rx_fw_statistics_pram->verylongevent);
511 rx_firmware_statistics->symbolerror =
512 in_be32(&p_rx_fw_statistics_pram->symbolerror);
513 rx_firmware_statistics->dropbsy =
514 in_be32(&p_rx_fw_statistics_pram->dropbsy);
515 for (i = 0; i < 0x8; i++)
516 rx_firmware_statistics->res0[i] =
517 p_rx_fw_statistics_pram->res0[i];
518 rx_firmware_statistics->mismatchdrop =
519 in_be32(&p_rx_fw_statistics_pram->mismatchdrop);
520 rx_firmware_statistics->underpkts =
521 in_be32(&p_rx_fw_statistics_pram->underpkts);
522 rx_firmware_statistics->pkts256 =
523 in_be32(&p_rx_fw_statistics_pram->pkts256);
524 rx_firmware_statistics->pkts512 =
525 in_be32(&p_rx_fw_statistics_pram->pkts512);
526 rx_firmware_statistics->pkts1024 =
527 in_be32(&p_rx_fw_statistics_pram->pkts1024);
528 rx_firmware_statistics->pktsjumbo =
529 in_be32(&p_rx_fw_statistics_pram->pktsjumbo);
530 rx_firmware_statistics->frlossinmacer =
531 in_be32(&p_rx_fw_statistics_pram->frlossinmacer);
532 rx_firmware_statistics->pausefr =
533 in_be32(&p_rx_fw_statistics_pram->pausefr);
534 for (i = 0; i < 0x4; i++)
535 rx_firmware_statistics->res1[i] =
536 p_rx_fw_statistics_pram->res1[i];
537 rx_firmware_statistics->removevlan =
538 in_be32(&p_rx_fw_statistics_pram->removevlan);
539 rx_firmware_statistics->replacevlan =
540 in_be32(&p_rx_fw_statistics_pram->replacevlan);
541 rx_firmware_statistics->insertvlan =
542 in_be32(&p_rx_fw_statistics_pram->insertvlan);
543 }
544
545 /* Hardware only if user handed pointer and driver actually
546 gathers hardware statistics */
Timur Tabi3bc53422009-01-11 00:25:21 -0800547 if (hardware_statistics &&
548 (in_be32(&uf_regs->upsmr) & UCC_GETH_UPSMR_HSE)) {
Li Yangce973b12006-08-14 23:00:11 -0700549 hardware_statistics->tx64 = in_be32(&ug_regs->tx64);
550 hardware_statistics->tx127 = in_be32(&ug_regs->tx127);
551 hardware_statistics->tx255 = in_be32(&ug_regs->tx255);
552 hardware_statistics->rx64 = in_be32(&ug_regs->rx64);
553 hardware_statistics->rx127 = in_be32(&ug_regs->rx127);
554 hardware_statistics->rx255 = in_be32(&ug_regs->rx255);
555 hardware_statistics->txok = in_be32(&ug_regs->txok);
556 hardware_statistics->txcf = in_be16(&ug_regs->txcf);
557 hardware_statistics->tmca = in_be32(&ug_regs->tmca);
558 hardware_statistics->tbca = in_be32(&ug_regs->tbca);
559 hardware_statistics->rxfok = in_be32(&ug_regs->rxfok);
560 hardware_statistics->rxbok = in_be32(&ug_regs->rxbok);
561 hardware_statistics->rbyt = in_be32(&ug_regs->rbyt);
562 hardware_statistics->rmca = in_be32(&ug_regs->rmca);
563 hardware_statistics->rbca = in_be32(&ug_regs->rbca);
564 }
565}
566
Li Yang18a8e862006-10-19 21:07:34 -0500567static void dump_bds(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700568{
569 int i;
570 int length;
571
572 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
573 if (ugeth->p_tx_bd_ring[i]) {
574 length =
575 (ugeth->ug_info->bdRingLenTx[i] *
Li Yang18a8e862006-10-19 21:07:34 -0500576 sizeof(struct qe_bd));
Li Yangce973b12006-08-14 23:00:11 -0700577 ugeth_info("TX BDs[%d]", i);
578 mem_disp(ugeth->p_tx_bd_ring[i], length);
579 }
580 }
581 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
582 if (ugeth->p_rx_bd_ring[i]) {
583 length =
584 (ugeth->ug_info->bdRingLenRx[i] *
Li Yang18a8e862006-10-19 21:07:34 -0500585 sizeof(struct qe_bd));
Li Yangce973b12006-08-14 23:00:11 -0700586 ugeth_info("RX BDs[%d]", i);
587 mem_disp(ugeth->p_rx_bd_ring[i], length);
588 }
589 }
590}
591
Li Yang18a8e862006-10-19 21:07:34 -0500592static void dump_regs(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700593{
594 int i;
595
596 ugeth_info("UCC%d Geth registers:", ugeth->ug_info->uf_info.ucc_num);
597 ugeth_info("Base address: 0x%08x", (u32) ugeth->ug_regs);
598
599 ugeth_info("maccfg1 : addr - 0x%08x, val - 0x%08x",
600 (u32) & ugeth->ug_regs->maccfg1,
601 in_be32(&ugeth->ug_regs->maccfg1));
602 ugeth_info("maccfg2 : addr - 0x%08x, val - 0x%08x",
603 (u32) & ugeth->ug_regs->maccfg2,
604 in_be32(&ugeth->ug_regs->maccfg2));
605 ugeth_info("ipgifg : addr - 0x%08x, val - 0x%08x",
606 (u32) & ugeth->ug_regs->ipgifg,
607 in_be32(&ugeth->ug_regs->ipgifg));
608 ugeth_info("hafdup : addr - 0x%08x, val - 0x%08x",
609 (u32) & ugeth->ug_regs->hafdup,
610 in_be32(&ugeth->ug_regs->hafdup));
Li Yangce973b12006-08-14 23:00:11 -0700611 ugeth_info("ifctl : addr - 0x%08x, val - 0x%08x",
612 (u32) & ugeth->ug_regs->ifctl,
613 in_be32(&ugeth->ug_regs->ifctl));
614 ugeth_info("ifstat : addr - 0x%08x, val - 0x%08x",
615 (u32) & ugeth->ug_regs->ifstat,
616 in_be32(&ugeth->ug_regs->ifstat));
617 ugeth_info("macstnaddr1: addr - 0x%08x, val - 0x%08x",
618 (u32) & ugeth->ug_regs->macstnaddr1,
619 in_be32(&ugeth->ug_regs->macstnaddr1));
620 ugeth_info("macstnaddr2: addr - 0x%08x, val - 0x%08x",
621 (u32) & ugeth->ug_regs->macstnaddr2,
622 in_be32(&ugeth->ug_regs->macstnaddr2));
623 ugeth_info("uempr : addr - 0x%08x, val - 0x%08x",
624 (u32) & ugeth->ug_regs->uempr,
625 in_be32(&ugeth->ug_regs->uempr));
626 ugeth_info("utbipar : addr - 0x%08x, val - 0x%08x",
627 (u32) & ugeth->ug_regs->utbipar,
628 in_be32(&ugeth->ug_regs->utbipar));
629 ugeth_info("uescr : addr - 0x%08x, val - 0x%04x",
630 (u32) & ugeth->ug_regs->uescr,
631 in_be16(&ugeth->ug_regs->uescr));
632 ugeth_info("tx64 : addr - 0x%08x, val - 0x%08x",
633 (u32) & ugeth->ug_regs->tx64,
634 in_be32(&ugeth->ug_regs->tx64));
635 ugeth_info("tx127 : addr - 0x%08x, val - 0x%08x",
636 (u32) & ugeth->ug_regs->tx127,
637 in_be32(&ugeth->ug_regs->tx127));
638 ugeth_info("tx255 : addr - 0x%08x, val - 0x%08x",
639 (u32) & ugeth->ug_regs->tx255,
640 in_be32(&ugeth->ug_regs->tx255));
641 ugeth_info("rx64 : addr - 0x%08x, val - 0x%08x",
642 (u32) & ugeth->ug_regs->rx64,
643 in_be32(&ugeth->ug_regs->rx64));
644 ugeth_info("rx127 : addr - 0x%08x, val - 0x%08x",
645 (u32) & ugeth->ug_regs->rx127,
646 in_be32(&ugeth->ug_regs->rx127));
647 ugeth_info("rx255 : addr - 0x%08x, val - 0x%08x",
648 (u32) & ugeth->ug_regs->rx255,
649 in_be32(&ugeth->ug_regs->rx255));
650 ugeth_info("txok : addr - 0x%08x, val - 0x%08x",
651 (u32) & ugeth->ug_regs->txok,
652 in_be32(&ugeth->ug_regs->txok));
653 ugeth_info("txcf : addr - 0x%08x, val - 0x%04x",
654 (u32) & ugeth->ug_regs->txcf,
655 in_be16(&ugeth->ug_regs->txcf));
656 ugeth_info("tmca : addr - 0x%08x, val - 0x%08x",
657 (u32) & ugeth->ug_regs->tmca,
658 in_be32(&ugeth->ug_regs->tmca));
659 ugeth_info("tbca : addr - 0x%08x, val - 0x%08x",
660 (u32) & ugeth->ug_regs->tbca,
661 in_be32(&ugeth->ug_regs->tbca));
662 ugeth_info("rxfok : addr - 0x%08x, val - 0x%08x",
663 (u32) & ugeth->ug_regs->rxfok,
664 in_be32(&ugeth->ug_regs->rxfok));
665 ugeth_info("rxbok : addr - 0x%08x, val - 0x%08x",
666 (u32) & ugeth->ug_regs->rxbok,
667 in_be32(&ugeth->ug_regs->rxbok));
668 ugeth_info("rbyt : addr - 0x%08x, val - 0x%08x",
669 (u32) & ugeth->ug_regs->rbyt,
670 in_be32(&ugeth->ug_regs->rbyt));
671 ugeth_info("rmca : addr - 0x%08x, val - 0x%08x",
672 (u32) & ugeth->ug_regs->rmca,
673 in_be32(&ugeth->ug_regs->rmca));
674 ugeth_info("rbca : addr - 0x%08x, val - 0x%08x",
675 (u32) & ugeth->ug_regs->rbca,
676 in_be32(&ugeth->ug_regs->rbca));
677 ugeth_info("scar : addr - 0x%08x, val - 0x%08x",
678 (u32) & ugeth->ug_regs->scar,
679 in_be32(&ugeth->ug_regs->scar));
680 ugeth_info("scam : addr - 0x%08x, val - 0x%08x",
681 (u32) & ugeth->ug_regs->scam,
682 in_be32(&ugeth->ug_regs->scam));
683
684 if (ugeth->p_thread_data_tx) {
685 int numThreadsTxNumerical;
686 switch (ugeth->ug_info->numThreadsTx) {
687 case UCC_GETH_NUM_OF_THREADS_1:
688 numThreadsTxNumerical = 1;
689 break;
690 case UCC_GETH_NUM_OF_THREADS_2:
691 numThreadsTxNumerical = 2;
692 break;
693 case UCC_GETH_NUM_OF_THREADS_4:
694 numThreadsTxNumerical = 4;
695 break;
696 case UCC_GETH_NUM_OF_THREADS_6:
697 numThreadsTxNumerical = 6;
698 break;
699 case UCC_GETH_NUM_OF_THREADS_8:
700 numThreadsTxNumerical = 8;
701 break;
702 default:
703 numThreadsTxNumerical = 0;
704 break;
705 }
706
707 ugeth_info("Thread data TXs:");
708 ugeth_info("Base address: 0x%08x",
709 (u32) ugeth->p_thread_data_tx);
710 for (i = 0; i < numThreadsTxNumerical; i++) {
711 ugeth_info("Thread data TX[%d]:", i);
712 ugeth_info("Base address: 0x%08x",
713 (u32) & ugeth->p_thread_data_tx[i]);
714 mem_disp((u8 *) & ugeth->p_thread_data_tx[i],
Li Yang18a8e862006-10-19 21:07:34 -0500715 sizeof(struct ucc_geth_thread_data_tx));
Li Yangce973b12006-08-14 23:00:11 -0700716 }
717 }
718 if (ugeth->p_thread_data_rx) {
719 int numThreadsRxNumerical;
720 switch (ugeth->ug_info->numThreadsRx) {
721 case UCC_GETH_NUM_OF_THREADS_1:
722 numThreadsRxNumerical = 1;
723 break;
724 case UCC_GETH_NUM_OF_THREADS_2:
725 numThreadsRxNumerical = 2;
726 break;
727 case UCC_GETH_NUM_OF_THREADS_4:
728 numThreadsRxNumerical = 4;
729 break;
730 case UCC_GETH_NUM_OF_THREADS_6:
731 numThreadsRxNumerical = 6;
732 break;
733 case UCC_GETH_NUM_OF_THREADS_8:
734 numThreadsRxNumerical = 8;
735 break;
736 default:
737 numThreadsRxNumerical = 0;
738 break;
739 }
740
741 ugeth_info("Thread data RX:");
742 ugeth_info("Base address: 0x%08x",
743 (u32) ugeth->p_thread_data_rx);
744 for (i = 0; i < numThreadsRxNumerical; i++) {
745 ugeth_info("Thread data RX[%d]:", i);
746 ugeth_info("Base address: 0x%08x",
747 (u32) & ugeth->p_thread_data_rx[i]);
748 mem_disp((u8 *) & ugeth->p_thread_data_rx[i],
Li Yang18a8e862006-10-19 21:07:34 -0500749 sizeof(struct ucc_geth_thread_data_rx));
Li Yangce973b12006-08-14 23:00:11 -0700750 }
751 }
752 if (ugeth->p_exf_glbl_param) {
753 ugeth_info("EXF global param:");
754 ugeth_info("Base address: 0x%08x",
755 (u32) ugeth->p_exf_glbl_param);
756 mem_disp((u8 *) ugeth->p_exf_glbl_param,
757 sizeof(*ugeth->p_exf_glbl_param));
758 }
759 if (ugeth->p_tx_glbl_pram) {
760 ugeth_info("TX global param:");
761 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_tx_glbl_pram);
762 ugeth_info("temoder : addr - 0x%08x, val - 0x%04x",
763 (u32) & ugeth->p_tx_glbl_pram->temoder,
764 in_be16(&ugeth->p_tx_glbl_pram->temoder));
765 ugeth_info("sqptr : addr - 0x%08x, val - 0x%08x",
766 (u32) & ugeth->p_tx_glbl_pram->sqptr,
767 in_be32(&ugeth->p_tx_glbl_pram->sqptr));
768 ugeth_info("schedulerbasepointer: addr - 0x%08x, val - 0x%08x",
769 (u32) & ugeth->p_tx_glbl_pram->schedulerbasepointer,
770 in_be32(&ugeth->p_tx_glbl_pram->
771 schedulerbasepointer));
772 ugeth_info("txrmonbaseptr: addr - 0x%08x, val - 0x%08x",
773 (u32) & ugeth->p_tx_glbl_pram->txrmonbaseptr,
774 in_be32(&ugeth->p_tx_glbl_pram->txrmonbaseptr));
775 ugeth_info("tstate : addr - 0x%08x, val - 0x%08x",
776 (u32) & ugeth->p_tx_glbl_pram->tstate,
777 in_be32(&ugeth->p_tx_glbl_pram->tstate));
778 ugeth_info("iphoffset[0] : addr - 0x%08x, val - 0x%02x",
779 (u32) & ugeth->p_tx_glbl_pram->iphoffset[0],
780 ugeth->p_tx_glbl_pram->iphoffset[0]);
781 ugeth_info("iphoffset[1] : addr - 0x%08x, val - 0x%02x",
782 (u32) & ugeth->p_tx_glbl_pram->iphoffset[1],
783 ugeth->p_tx_glbl_pram->iphoffset[1]);
784 ugeth_info("iphoffset[2] : addr - 0x%08x, val - 0x%02x",
785 (u32) & ugeth->p_tx_glbl_pram->iphoffset[2],
786 ugeth->p_tx_glbl_pram->iphoffset[2]);
787 ugeth_info("iphoffset[3] : addr - 0x%08x, val - 0x%02x",
788 (u32) & ugeth->p_tx_glbl_pram->iphoffset[3],
789 ugeth->p_tx_glbl_pram->iphoffset[3]);
790 ugeth_info("iphoffset[4] : addr - 0x%08x, val - 0x%02x",
791 (u32) & ugeth->p_tx_glbl_pram->iphoffset[4],
792 ugeth->p_tx_glbl_pram->iphoffset[4]);
793 ugeth_info("iphoffset[5] : addr - 0x%08x, val - 0x%02x",
794 (u32) & ugeth->p_tx_glbl_pram->iphoffset[5],
795 ugeth->p_tx_glbl_pram->iphoffset[5]);
796 ugeth_info("iphoffset[6] : addr - 0x%08x, val - 0x%02x",
797 (u32) & ugeth->p_tx_glbl_pram->iphoffset[6],
798 ugeth->p_tx_glbl_pram->iphoffset[6]);
799 ugeth_info("iphoffset[7] : addr - 0x%08x, val - 0x%02x",
800 (u32) & ugeth->p_tx_glbl_pram->iphoffset[7],
801 ugeth->p_tx_glbl_pram->iphoffset[7]);
802 ugeth_info("vtagtable[0] : addr - 0x%08x, val - 0x%08x",
803 (u32) & ugeth->p_tx_glbl_pram->vtagtable[0],
804 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[0]));
805 ugeth_info("vtagtable[1] : addr - 0x%08x, val - 0x%08x",
806 (u32) & ugeth->p_tx_glbl_pram->vtagtable[1],
807 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[1]));
808 ugeth_info("vtagtable[2] : addr - 0x%08x, val - 0x%08x",
809 (u32) & ugeth->p_tx_glbl_pram->vtagtable[2],
810 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[2]));
811 ugeth_info("vtagtable[3] : addr - 0x%08x, val - 0x%08x",
812 (u32) & ugeth->p_tx_glbl_pram->vtagtable[3],
813 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[3]));
814 ugeth_info("vtagtable[4] : addr - 0x%08x, val - 0x%08x",
815 (u32) & ugeth->p_tx_glbl_pram->vtagtable[4],
816 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[4]));
817 ugeth_info("vtagtable[5] : addr - 0x%08x, val - 0x%08x",
818 (u32) & ugeth->p_tx_glbl_pram->vtagtable[5],
819 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[5]));
820 ugeth_info("vtagtable[6] : addr - 0x%08x, val - 0x%08x",
821 (u32) & ugeth->p_tx_glbl_pram->vtagtable[6],
822 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[6]));
823 ugeth_info("vtagtable[7] : addr - 0x%08x, val - 0x%08x",
824 (u32) & ugeth->p_tx_glbl_pram->vtagtable[7],
825 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[7]));
826 ugeth_info("tqptr : addr - 0x%08x, val - 0x%08x",
827 (u32) & ugeth->p_tx_glbl_pram->tqptr,
828 in_be32(&ugeth->p_tx_glbl_pram->tqptr));
829 }
830 if (ugeth->p_rx_glbl_pram) {
831 ugeth_info("RX global param:");
832 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_glbl_pram);
833 ugeth_info("remoder : addr - 0x%08x, val - 0x%08x",
834 (u32) & ugeth->p_rx_glbl_pram->remoder,
835 in_be32(&ugeth->p_rx_glbl_pram->remoder));
836 ugeth_info("rqptr : addr - 0x%08x, val - 0x%08x",
837 (u32) & ugeth->p_rx_glbl_pram->rqptr,
838 in_be32(&ugeth->p_rx_glbl_pram->rqptr));
839 ugeth_info("typeorlen : addr - 0x%08x, val - 0x%04x",
840 (u32) & ugeth->p_rx_glbl_pram->typeorlen,
841 in_be16(&ugeth->p_rx_glbl_pram->typeorlen));
842 ugeth_info("rxgstpack : addr - 0x%08x, val - 0x%02x",
843 (u32) & ugeth->p_rx_glbl_pram->rxgstpack,
844 ugeth->p_rx_glbl_pram->rxgstpack);
845 ugeth_info("rxrmonbaseptr : addr - 0x%08x, val - 0x%08x",
846 (u32) & ugeth->p_rx_glbl_pram->rxrmonbaseptr,
847 in_be32(&ugeth->p_rx_glbl_pram->rxrmonbaseptr));
848 ugeth_info("intcoalescingptr: addr - 0x%08x, val - 0x%08x",
849 (u32) & ugeth->p_rx_glbl_pram->intcoalescingptr,
850 in_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr));
851 ugeth_info("rstate : addr - 0x%08x, val - 0x%02x",
852 (u32) & ugeth->p_rx_glbl_pram->rstate,
853 ugeth->p_rx_glbl_pram->rstate);
854 ugeth_info("mrblr : addr - 0x%08x, val - 0x%04x",
855 (u32) & ugeth->p_rx_glbl_pram->mrblr,
856 in_be16(&ugeth->p_rx_glbl_pram->mrblr));
857 ugeth_info("rbdqptr : addr - 0x%08x, val - 0x%08x",
858 (u32) & ugeth->p_rx_glbl_pram->rbdqptr,
859 in_be32(&ugeth->p_rx_glbl_pram->rbdqptr));
860 ugeth_info("mflr : addr - 0x%08x, val - 0x%04x",
861 (u32) & ugeth->p_rx_glbl_pram->mflr,
862 in_be16(&ugeth->p_rx_glbl_pram->mflr));
863 ugeth_info("minflr : addr - 0x%08x, val - 0x%04x",
864 (u32) & ugeth->p_rx_glbl_pram->minflr,
865 in_be16(&ugeth->p_rx_glbl_pram->minflr));
866 ugeth_info("maxd1 : addr - 0x%08x, val - 0x%04x",
867 (u32) & ugeth->p_rx_glbl_pram->maxd1,
868 in_be16(&ugeth->p_rx_glbl_pram->maxd1));
869 ugeth_info("maxd2 : addr - 0x%08x, val - 0x%04x",
870 (u32) & ugeth->p_rx_glbl_pram->maxd2,
871 in_be16(&ugeth->p_rx_glbl_pram->maxd2));
872 ugeth_info("ecamptr : addr - 0x%08x, val - 0x%08x",
873 (u32) & ugeth->p_rx_glbl_pram->ecamptr,
874 in_be32(&ugeth->p_rx_glbl_pram->ecamptr));
875 ugeth_info("l2qt : addr - 0x%08x, val - 0x%08x",
876 (u32) & ugeth->p_rx_glbl_pram->l2qt,
877 in_be32(&ugeth->p_rx_glbl_pram->l2qt));
878 ugeth_info("l3qt[0] : addr - 0x%08x, val - 0x%08x",
879 (u32) & ugeth->p_rx_glbl_pram->l3qt[0],
880 in_be32(&ugeth->p_rx_glbl_pram->l3qt[0]));
881 ugeth_info("l3qt[1] : addr - 0x%08x, val - 0x%08x",
882 (u32) & ugeth->p_rx_glbl_pram->l3qt[1],
883 in_be32(&ugeth->p_rx_glbl_pram->l3qt[1]));
884 ugeth_info("l3qt[2] : addr - 0x%08x, val - 0x%08x",
885 (u32) & ugeth->p_rx_glbl_pram->l3qt[2],
886 in_be32(&ugeth->p_rx_glbl_pram->l3qt[2]));
887 ugeth_info("l3qt[3] : addr - 0x%08x, val - 0x%08x",
888 (u32) & ugeth->p_rx_glbl_pram->l3qt[3],
889 in_be32(&ugeth->p_rx_glbl_pram->l3qt[3]));
890 ugeth_info("l3qt[4] : addr - 0x%08x, val - 0x%08x",
891 (u32) & ugeth->p_rx_glbl_pram->l3qt[4],
892 in_be32(&ugeth->p_rx_glbl_pram->l3qt[4]));
893 ugeth_info("l3qt[5] : addr - 0x%08x, val - 0x%08x",
894 (u32) & ugeth->p_rx_glbl_pram->l3qt[5],
895 in_be32(&ugeth->p_rx_glbl_pram->l3qt[5]));
896 ugeth_info("l3qt[6] : addr - 0x%08x, val - 0x%08x",
897 (u32) & ugeth->p_rx_glbl_pram->l3qt[6],
898 in_be32(&ugeth->p_rx_glbl_pram->l3qt[6]));
899 ugeth_info("l3qt[7] : addr - 0x%08x, val - 0x%08x",
900 (u32) & ugeth->p_rx_glbl_pram->l3qt[7],
901 in_be32(&ugeth->p_rx_glbl_pram->l3qt[7]));
902 ugeth_info("vlantype : addr - 0x%08x, val - 0x%04x",
903 (u32) & ugeth->p_rx_glbl_pram->vlantype,
904 in_be16(&ugeth->p_rx_glbl_pram->vlantype));
905 ugeth_info("vlantci : addr - 0x%08x, val - 0x%04x",
906 (u32) & ugeth->p_rx_glbl_pram->vlantci,
907 in_be16(&ugeth->p_rx_glbl_pram->vlantci));
908 for (i = 0; i < 64; i++)
909 ugeth_info
910 ("addressfiltering[%d]: addr - 0x%08x, val - 0x%02x",
911 i,
912 (u32) & ugeth->p_rx_glbl_pram->addressfiltering[i],
913 ugeth->p_rx_glbl_pram->addressfiltering[i]);
914 ugeth_info("exfGlobalParam : addr - 0x%08x, val - 0x%08x",
915 (u32) & ugeth->p_rx_glbl_pram->exfGlobalParam,
916 in_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam));
917 }
918 if (ugeth->p_send_q_mem_reg) {
919 ugeth_info("Send Q memory registers:");
920 ugeth_info("Base address: 0x%08x",
921 (u32) ugeth->p_send_q_mem_reg);
922 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
923 ugeth_info("SQQD[%d]:", i);
924 ugeth_info("Base address: 0x%08x",
925 (u32) & ugeth->p_send_q_mem_reg->sqqd[i]);
926 mem_disp((u8 *) & ugeth->p_send_q_mem_reg->sqqd[i],
Li Yang18a8e862006-10-19 21:07:34 -0500927 sizeof(struct ucc_geth_send_queue_qd));
Li Yangce973b12006-08-14 23:00:11 -0700928 }
929 }
930 if (ugeth->p_scheduler) {
931 ugeth_info("Scheduler:");
932 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_scheduler);
933 mem_disp((u8 *) ugeth->p_scheduler,
934 sizeof(*ugeth->p_scheduler));
935 }
936 if (ugeth->p_tx_fw_statistics_pram) {
937 ugeth_info("TX FW statistics pram:");
938 ugeth_info("Base address: 0x%08x",
939 (u32) ugeth->p_tx_fw_statistics_pram);
940 mem_disp((u8 *) ugeth->p_tx_fw_statistics_pram,
941 sizeof(*ugeth->p_tx_fw_statistics_pram));
942 }
943 if (ugeth->p_rx_fw_statistics_pram) {
944 ugeth_info("RX FW statistics pram:");
945 ugeth_info("Base address: 0x%08x",
946 (u32) ugeth->p_rx_fw_statistics_pram);
947 mem_disp((u8 *) ugeth->p_rx_fw_statistics_pram,
948 sizeof(*ugeth->p_rx_fw_statistics_pram));
949 }
950 if (ugeth->p_rx_irq_coalescing_tbl) {
951 ugeth_info("RX IRQ coalescing tables:");
952 ugeth_info("Base address: 0x%08x",
953 (u32) ugeth->p_rx_irq_coalescing_tbl);
954 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
955 ugeth_info("RX IRQ coalescing table entry[%d]:", i);
956 ugeth_info("Base address: 0x%08x",
957 (u32) & ugeth->p_rx_irq_coalescing_tbl->
958 coalescingentry[i]);
959 ugeth_info
960 ("interruptcoalescingmaxvalue: addr - 0x%08x, val - 0x%08x",
961 (u32) & ugeth->p_rx_irq_coalescing_tbl->
962 coalescingentry[i].interruptcoalescingmaxvalue,
963 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
964 coalescingentry[i].
965 interruptcoalescingmaxvalue));
966 ugeth_info
967 ("interruptcoalescingcounter : addr - 0x%08x, val - 0x%08x",
968 (u32) & ugeth->p_rx_irq_coalescing_tbl->
969 coalescingentry[i].interruptcoalescingcounter,
970 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
971 coalescingentry[i].
972 interruptcoalescingcounter));
973 }
974 }
975 if (ugeth->p_rx_bd_qs_tbl) {
976 ugeth_info("RX BD QS tables:");
977 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_bd_qs_tbl);
978 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
979 ugeth_info("RX BD QS table[%d]:", i);
980 ugeth_info("Base address: 0x%08x",
981 (u32) & ugeth->p_rx_bd_qs_tbl[i]);
982 ugeth_info
983 ("bdbaseptr : addr - 0x%08x, val - 0x%08x",
984 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdbaseptr,
985 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdbaseptr));
986 ugeth_info
987 ("bdptr : addr - 0x%08x, val - 0x%08x",
988 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdptr,
989 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdptr));
990 ugeth_info
991 ("externalbdbaseptr: addr - 0x%08x, val - 0x%08x",
992 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
993 in_be32(&ugeth->p_rx_bd_qs_tbl[i].
994 externalbdbaseptr));
995 ugeth_info
996 ("externalbdptr : addr - 0x%08x, val - 0x%08x",
997 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdptr,
998 in_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdptr));
999 ugeth_info("ucode RX Prefetched BDs:");
1000 ugeth_info("Base address: 0x%08x",
1001 (u32)
1002 qe_muram_addr(in_be32
1003 (&ugeth->p_rx_bd_qs_tbl[i].
1004 bdbaseptr)));
1005 mem_disp((u8 *)
1006 qe_muram_addr(in_be32
1007 (&ugeth->p_rx_bd_qs_tbl[i].
1008 bdbaseptr)),
Li Yang18a8e862006-10-19 21:07:34 -05001009 sizeof(struct ucc_geth_rx_prefetched_bds));
Li Yangce973b12006-08-14 23:00:11 -07001010 }
1011 }
1012 if (ugeth->p_init_enet_param_shadow) {
1013 int size;
1014 ugeth_info("Init enet param shadow:");
1015 ugeth_info("Base address: 0x%08x",
1016 (u32) ugeth->p_init_enet_param_shadow);
1017 mem_disp((u8 *) ugeth->p_init_enet_param_shadow,
1018 sizeof(*ugeth->p_init_enet_param_shadow));
1019
Li Yang18a8e862006-10-19 21:07:34 -05001020 size = sizeof(struct ucc_geth_thread_rx_pram);
Li Yangce973b12006-08-14 23:00:11 -07001021 if (ugeth->ug_info->rxExtendedFiltering) {
1022 size +=
1023 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
1024 if (ugeth->ug_info->largestexternallookupkeysize ==
1025 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
1026 size +=
1027 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
1028 if (ugeth->ug_info->largestexternallookupkeysize ==
1029 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
1030 size +=
1031 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
1032 }
1033
1034 dump_init_enet_entries(ugeth,
1035 &(ugeth->p_init_enet_param_shadow->
1036 txthread[0]),
1037 ENET_INIT_PARAM_MAX_ENTRIES_TX,
Li Yang18a8e862006-10-19 21:07:34 -05001038 sizeof(struct ucc_geth_thread_tx_pram),
Li Yangce973b12006-08-14 23:00:11 -07001039 ugeth->ug_info->riscTx, 0);
1040 dump_init_enet_entries(ugeth,
1041 &(ugeth->p_init_enet_param_shadow->
1042 rxthread[0]),
1043 ENET_INIT_PARAM_MAX_ENTRIES_RX, size,
1044 ugeth->ug_info->riscRx, 1);
1045 }
1046}
1047#endif /* DEBUG */
1048
Andy Fleming6fee40e2008-05-02 13:01:23 -05001049static void init_default_reg_vals(u32 __iomem *upsmr_register,
1050 u32 __iomem *maccfg1_register,
1051 u32 __iomem *maccfg2_register)
Li Yangce973b12006-08-14 23:00:11 -07001052{
1053 out_be32(upsmr_register, UCC_GETH_UPSMR_INIT);
1054 out_be32(maccfg1_register, UCC_GETH_MACCFG1_INIT);
1055 out_be32(maccfg2_register, UCC_GETH_MACCFG2_INIT);
1056}
1057
1058static int init_half_duplex_params(int alt_beb,
1059 int back_pressure_no_backoff,
1060 int no_backoff,
1061 int excess_defer,
1062 u8 alt_beb_truncation,
1063 u8 max_retransmissions,
1064 u8 collision_window,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001065 u32 __iomem *hafdup_register)
Li Yangce973b12006-08-14 23:00:11 -07001066{
1067 u32 value = 0;
1068
1069 if ((alt_beb_truncation > HALFDUP_ALT_BEB_TRUNCATION_MAX) ||
1070 (max_retransmissions > HALFDUP_MAX_RETRANSMISSION_MAX) ||
1071 (collision_window > HALFDUP_COLLISION_WINDOW_MAX))
1072 return -EINVAL;
1073
1074 value = (u32) (alt_beb_truncation << HALFDUP_ALT_BEB_TRUNCATION_SHIFT);
1075
1076 if (alt_beb)
1077 value |= HALFDUP_ALT_BEB;
1078 if (back_pressure_no_backoff)
1079 value |= HALFDUP_BACK_PRESSURE_NO_BACKOFF;
1080 if (no_backoff)
1081 value |= HALFDUP_NO_BACKOFF;
1082 if (excess_defer)
1083 value |= HALFDUP_EXCESSIVE_DEFER;
1084
1085 value |= (max_retransmissions << HALFDUP_MAX_RETRANSMISSION_SHIFT);
1086
1087 value |= collision_window;
1088
1089 out_be32(hafdup_register, value);
1090 return 0;
1091}
1092
1093static int init_inter_frame_gap_params(u8 non_btb_cs_ipg,
1094 u8 non_btb_ipg,
1095 u8 min_ifg,
1096 u8 btb_ipg,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001097 u32 __iomem *ipgifg_register)
Li Yangce973b12006-08-14 23:00:11 -07001098{
1099 u32 value = 0;
1100
1101 /* Non-Back-to-back IPG part 1 should be <= Non-Back-to-back
1102 IPG part 2 */
1103 if (non_btb_cs_ipg > non_btb_ipg)
1104 return -EINVAL;
1105
1106 if ((non_btb_cs_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART1_MAX) ||
1107 (non_btb_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART2_MAX) ||
1108 /*(min_ifg > IPGIFG_MINIMUM_IFG_ENFORCEMENT_MAX) || */
1109 (btb_ipg > IPGIFG_BACK_TO_BACK_IFG_MAX))
1110 return -EINVAL;
1111
1112 value |=
1113 ((non_btb_cs_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART1_SHIFT) &
1114 IPGIFG_NBTB_CS_IPG_MASK);
1115 value |=
1116 ((non_btb_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART2_SHIFT) &
1117 IPGIFG_NBTB_IPG_MASK);
1118 value |=
1119 ((min_ifg << IPGIFG_MINIMUM_IFG_ENFORCEMENT_SHIFT) &
1120 IPGIFG_MIN_IFG_MASK);
1121 value |= (btb_ipg & IPGIFG_BTB_IPG_MASK);
1122
1123 out_be32(ipgifg_register, value);
1124 return 0;
1125}
1126
Li Yangac421852007-07-19 11:47:47 +08001127int init_flow_control_params(u32 automatic_flow_control_mode,
Li Yangce973b12006-08-14 23:00:11 -07001128 int rx_flow_control_enable,
1129 int tx_flow_control_enable,
1130 u16 pause_period,
1131 u16 extension_field,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001132 u32 __iomem *upsmr_register,
1133 u32 __iomem *uempr_register,
1134 u32 __iomem *maccfg1_register)
Li Yangce973b12006-08-14 23:00:11 -07001135{
1136 u32 value = 0;
1137
1138 /* Set UEMPR register */
1139 value = (u32) pause_period << UEMPR_PAUSE_TIME_VALUE_SHIFT;
1140 value |= (u32) extension_field << UEMPR_EXTENDED_PAUSE_TIME_VALUE_SHIFT;
1141 out_be32(uempr_register, value);
1142
1143 /* Set UPSMR register */
Timur Tabi3bc53422009-01-11 00:25:21 -08001144 setbits32(upsmr_register, automatic_flow_control_mode);
Li Yangce973b12006-08-14 23:00:11 -07001145
1146 value = in_be32(maccfg1_register);
1147 if (rx_flow_control_enable)
1148 value |= MACCFG1_FLOW_RX;
1149 if (tx_flow_control_enable)
1150 value |= MACCFG1_FLOW_TX;
1151 out_be32(maccfg1_register, value);
1152
1153 return 0;
1154}
1155
1156static int init_hw_statistics_gathering_mode(int enable_hardware_statistics,
1157 int auto_zero_hardware_statistics,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001158 u32 __iomem *upsmr_register,
1159 u16 __iomem *uescr_register)
Li Yangce973b12006-08-14 23:00:11 -07001160{
Li Yangce973b12006-08-14 23:00:11 -07001161 u16 uescr_value = 0;
Timur Tabi3bc53422009-01-11 00:25:21 -08001162
Li Yangce973b12006-08-14 23:00:11 -07001163 /* Enable hardware statistics gathering if requested */
Timur Tabi3bc53422009-01-11 00:25:21 -08001164 if (enable_hardware_statistics)
1165 setbits32(upsmr_register, UCC_GETH_UPSMR_HSE);
Li Yangce973b12006-08-14 23:00:11 -07001166
1167 /* Clear hardware statistics counters */
1168 uescr_value = in_be16(uescr_register);
1169 uescr_value |= UESCR_CLRCNT;
1170 /* Automatically zero hardware statistics counters on read,
1171 if requested */
1172 if (auto_zero_hardware_statistics)
1173 uescr_value |= UESCR_AUTOZ;
1174 out_be16(uescr_register, uescr_value);
1175
1176 return 0;
1177}
1178
1179static int init_firmware_statistics_gathering_mode(int
1180 enable_tx_firmware_statistics,
1181 int enable_rx_firmware_statistics,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001182 u32 __iomem *tx_rmon_base_ptr,
Li Yangce973b12006-08-14 23:00:11 -07001183 u32 tx_firmware_statistics_structure_address,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001184 u32 __iomem *rx_rmon_base_ptr,
Li Yangce973b12006-08-14 23:00:11 -07001185 u32 rx_firmware_statistics_structure_address,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001186 u16 __iomem *temoder_register,
1187 u32 __iomem *remoder_register)
Li Yangce973b12006-08-14 23:00:11 -07001188{
1189 /* Note: this function does not check if */
1190 /* the parameters it receives are NULL */
Li Yangce973b12006-08-14 23:00:11 -07001191
1192 if (enable_tx_firmware_statistics) {
1193 out_be32(tx_rmon_base_ptr,
1194 tx_firmware_statistics_structure_address);
Timur Tabi3bc53422009-01-11 00:25:21 -08001195 setbits16(temoder_register, TEMODER_TX_RMON_STATISTICS_ENABLE);
Li Yangce973b12006-08-14 23:00:11 -07001196 }
1197
1198 if (enable_rx_firmware_statistics) {
1199 out_be32(rx_rmon_base_ptr,
1200 rx_firmware_statistics_structure_address);
Timur Tabi3bc53422009-01-11 00:25:21 -08001201 setbits32(remoder_register, REMODER_RX_RMON_STATISTICS_ENABLE);
Li Yangce973b12006-08-14 23:00:11 -07001202 }
1203
1204 return 0;
1205}
1206
1207static int init_mac_station_addr_regs(u8 address_byte_0,
1208 u8 address_byte_1,
1209 u8 address_byte_2,
1210 u8 address_byte_3,
1211 u8 address_byte_4,
1212 u8 address_byte_5,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001213 u32 __iomem *macstnaddr1_register,
1214 u32 __iomem *macstnaddr2_register)
Li Yangce973b12006-08-14 23:00:11 -07001215{
1216 u32 value = 0;
1217
1218 /* Example: for a station address of 0x12345678ABCD, */
1219 /* 0x12 is byte 0, 0x34 is byte 1 and so on and 0xCD is byte 5 */
1220
1221 /* MACSTNADDR1 Register: */
1222
1223 /* 0 7 8 15 */
1224 /* station address byte 5 station address byte 4 */
1225 /* 16 23 24 31 */
1226 /* station address byte 3 station address byte 2 */
1227 value |= (u32) ((address_byte_2 << 0) & 0x000000FF);
1228 value |= (u32) ((address_byte_3 << 8) & 0x0000FF00);
1229 value |= (u32) ((address_byte_4 << 16) & 0x00FF0000);
1230 value |= (u32) ((address_byte_5 << 24) & 0xFF000000);
1231
1232 out_be32(macstnaddr1_register, value);
1233
1234 /* MACSTNADDR2 Register: */
1235
1236 /* 0 7 8 15 */
1237 /* station address byte 1 station address byte 0 */
1238 /* 16 23 24 31 */
1239 /* reserved reserved */
1240 value = 0;
1241 value |= (u32) ((address_byte_0 << 16) & 0x00FF0000);
1242 value |= (u32) ((address_byte_1 << 24) & 0xFF000000);
1243
1244 out_be32(macstnaddr2_register, value);
1245
1246 return 0;
1247}
1248
Li Yangce973b12006-08-14 23:00:11 -07001249static int init_check_frame_length_mode(int length_check,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001250 u32 __iomem *maccfg2_register)
Li Yangce973b12006-08-14 23:00:11 -07001251{
1252 u32 value = 0;
1253
1254 value = in_be32(maccfg2_register);
1255
1256 if (length_check)
1257 value |= MACCFG2_LC;
1258 else
1259 value &= ~MACCFG2_LC;
1260
1261 out_be32(maccfg2_register, value);
1262 return 0;
1263}
1264
1265static int init_preamble_length(u8 preamble_length,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001266 u32 __iomem *maccfg2_register)
Li Yangce973b12006-08-14 23:00:11 -07001267{
Li Yangce973b12006-08-14 23:00:11 -07001268 if ((preamble_length < 3) || (preamble_length > 7))
1269 return -EINVAL;
1270
Timur Tabi3bc53422009-01-11 00:25:21 -08001271 clrsetbits_be32(maccfg2_register, MACCFG2_PREL_MASK,
1272 preamble_length << MACCFG2_PREL_SHIFT);
1273
Li Yangce973b12006-08-14 23:00:11 -07001274 return 0;
1275}
1276
Li Yangce973b12006-08-14 23:00:11 -07001277static int init_rx_parameters(int reject_broadcast,
1278 int receive_short_frames,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001279 int promiscuous, u32 __iomem *upsmr_register)
Li Yangce973b12006-08-14 23:00:11 -07001280{
1281 u32 value = 0;
1282
1283 value = in_be32(upsmr_register);
1284
1285 if (reject_broadcast)
Timur Tabi3bc53422009-01-11 00:25:21 -08001286 value |= UCC_GETH_UPSMR_BRO;
Li Yangce973b12006-08-14 23:00:11 -07001287 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001288 value &= ~UCC_GETH_UPSMR_BRO;
Li Yangce973b12006-08-14 23:00:11 -07001289
1290 if (receive_short_frames)
Timur Tabi3bc53422009-01-11 00:25:21 -08001291 value |= UCC_GETH_UPSMR_RSH;
Li Yangce973b12006-08-14 23:00:11 -07001292 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001293 value &= ~UCC_GETH_UPSMR_RSH;
Li Yangce973b12006-08-14 23:00:11 -07001294
1295 if (promiscuous)
Timur Tabi3bc53422009-01-11 00:25:21 -08001296 value |= UCC_GETH_UPSMR_PRO;
Li Yangce973b12006-08-14 23:00:11 -07001297 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001298 value &= ~UCC_GETH_UPSMR_PRO;
Li Yangce973b12006-08-14 23:00:11 -07001299
1300 out_be32(upsmr_register, value);
1301
1302 return 0;
1303}
1304
1305static int init_max_rx_buff_len(u16 max_rx_buf_len,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001306 u16 __iomem *mrblr_register)
Li Yangce973b12006-08-14 23:00:11 -07001307{
1308 /* max_rx_buf_len value must be a multiple of 128 */
1309 if ((max_rx_buf_len == 0)
1310 || (max_rx_buf_len % UCC_GETH_MRBLR_ALIGNMENT))
1311 return -EINVAL;
1312
1313 out_be16(mrblr_register, max_rx_buf_len);
1314 return 0;
1315}
1316
1317static int init_min_frame_len(u16 min_frame_length,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001318 u16 __iomem *minflr_register,
1319 u16 __iomem *mrblr_register)
Li Yangce973b12006-08-14 23:00:11 -07001320{
1321 u16 mrblr_value = 0;
1322
1323 mrblr_value = in_be16(mrblr_register);
1324 if (min_frame_length >= (mrblr_value - 4))
1325 return -EINVAL;
1326
1327 out_be16(minflr_register, min_frame_length);
1328 return 0;
1329}
1330
Li Yang18a8e862006-10-19 21:07:34 -05001331static int adjust_enet_interface(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001332{
Li Yang18a8e862006-10-19 21:07:34 -05001333 struct ucc_geth_info *ug_info;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001334 struct ucc_geth __iomem *ug_regs;
1335 struct ucc_fast __iomem *uf_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001336 int ret_val;
1337 u32 upsmr, maccfg2, tbiBaseAddress;
Li Yangce973b12006-08-14 23:00:11 -07001338 u16 value;
1339
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001340 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07001341
1342 ug_info = ugeth->ug_info;
1343 ug_regs = ugeth->ug_regs;
1344 uf_regs = ugeth->uccf->uf_regs;
1345
Li Yangce973b12006-08-14 23:00:11 -07001346 /* Set MACCFG2 */
1347 maccfg2 = in_be32(&ug_regs->maccfg2);
1348 maccfg2 &= ~MACCFG2_INTERFACE_MODE_MASK;
Kim Phillips728de4c92007-04-13 01:26:03 -05001349 if ((ugeth->max_speed == SPEED_10) ||
1350 (ugeth->max_speed == SPEED_100))
Li Yangce973b12006-08-14 23:00:11 -07001351 maccfg2 |= MACCFG2_INTERFACE_MODE_NIBBLE;
Kim Phillips728de4c92007-04-13 01:26:03 -05001352 else if (ugeth->max_speed == SPEED_1000)
Li Yangce973b12006-08-14 23:00:11 -07001353 maccfg2 |= MACCFG2_INTERFACE_MODE_BYTE;
1354 maccfg2 |= ug_info->padAndCrc;
1355 out_be32(&ug_regs->maccfg2, maccfg2);
1356
1357 /* Set UPSMR */
1358 upsmr = in_be32(&uf_regs->upsmr);
Timur Tabi3bc53422009-01-11 00:25:21 -08001359 upsmr &= ~(UCC_GETH_UPSMR_RPM | UCC_GETH_UPSMR_R10M |
1360 UCC_GETH_UPSMR_TBIM | UCC_GETH_UPSMR_RMM);
Kim Phillips728de4c92007-04-13 01:26:03 -05001361 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
1362 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
1363 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06001364 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
1365 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
Kim Phillips728de4c92007-04-13 01:26:03 -05001366 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
Heiko Schochercef309c2009-04-20 22:36:43 +00001367 if (ugeth->phy_interface != PHY_INTERFACE_MODE_RMII)
1368 upsmr |= UCC_GETH_UPSMR_RPM;
Kim Phillips728de4c92007-04-13 01:26:03 -05001369 switch (ugeth->max_speed) {
1370 case SPEED_10:
Timur Tabi3bc53422009-01-11 00:25:21 -08001371 upsmr |= UCC_GETH_UPSMR_R10M;
Kim Phillips728de4c92007-04-13 01:26:03 -05001372 /* FALLTHROUGH */
1373 case SPEED_100:
1374 if (ugeth->phy_interface != PHY_INTERFACE_MODE_RTBI)
Timur Tabi3bc53422009-01-11 00:25:21 -08001375 upsmr |= UCC_GETH_UPSMR_RMM;
Kim Phillips728de4c92007-04-13 01:26:03 -05001376 }
1377 }
1378 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_TBI) ||
1379 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
Timur Tabi3bc53422009-01-11 00:25:21 -08001380 upsmr |= UCC_GETH_UPSMR_TBIM;
Kim Phillips728de4c92007-04-13 01:26:03 -05001381 }
Haiying Wang047584c2009-06-02 04:04:15 +00001382 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_SGMII))
1383 upsmr |= UCC_GETH_UPSMR_SGMM;
1384
Li Yangce973b12006-08-14 23:00:11 -07001385 out_be32(&uf_regs->upsmr, upsmr);
1386
Li Yangce973b12006-08-14 23:00:11 -07001387 /* Disable autonegotiation in tbi mode, because by default it
1388 comes up in autonegotiation mode. */
1389 /* Note that this depends on proper setting in utbipar register. */
Kim Phillips728de4c92007-04-13 01:26:03 -05001390 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_TBI) ||
1391 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
Li Yangce973b12006-08-14 23:00:11 -07001392 tbiBaseAddress = in_be32(&ug_regs->utbipar);
1393 tbiBaseAddress &= UTBIPAR_PHY_ADDRESS_MASK;
1394 tbiBaseAddress >>= UTBIPAR_PHY_ADDRESS_SHIFT;
Kim Phillips728de4c92007-04-13 01:26:03 -05001395 value = ugeth->phydev->bus->read(ugeth->phydev->bus,
1396 (u8) tbiBaseAddress, ENET_TBI_MII_CR);
Li Yangce973b12006-08-14 23:00:11 -07001397 value &= ~0x1000; /* Turn off autonegotiation */
Kim Phillips728de4c92007-04-13 01:26:03 -05001398 ugeth->phydev->bus->write(ugeth->phydev->bus,
1399 (u8) tbiBaseAddress, ENET_TBI_MII_CR, value);
Li Yangce973b12006-08-14 23:00:11 -07001400 }
1401
1402 init_check_frame_length_mode(ug_info->lengthCheckRx, &ug_regs->maccfg2);
1403
1404 ret_val = init_preamble_length(ug_info->prel, &ug_regs->maccfg2);
1405 if (ret_val != 0) {
Li Yang890de952007-07-19 11:48:29 +08001406 if (netif_msg_probe(ugeth))
1407 ugeth_err("%s: Preamble length must be between 3 and 7 inclusive.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001408 __func__);
Li Yangce973b12006-08-14 23:00:11 -07001409 return ret_val;
1410 }
1411
1412 return 0;
1413}
1414
Anton Vorontsov7de8ee72009-09-09 16:01:40 +00001415static int ugeth_graceful_stop_tx(struct ucc_geth_private *ugeth)
1416{
1417 struct ucc_fast_private *uccf;
1418 u32 cecr_subblock;
1419 u32 temp;
1420 int i = 10;
1421
1422 uccf = ugeth->uccf;
1423
1424 /* Mask GRACEFUL STOP TX interrupt bit and clear it */
1425 clrbits32(uccf->p_uccm, UCC_GETH_UCCE_GRA);
1426 out_be32(uccf->p_ucce, UCC_GETH_UCCE_GRA); /* clear by writing 1 */
1427
1428 /* Issue host command */
1429 cecr_subblock =
1430 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1431 qe_issue_cmd(QE_GRACEFUL_STOP_TX, cecr_subblock,
1432 QE_CR_PROTOCOL_ETHERNET, 0);
1433
1434 /* Wait for command to complete */
1435 do {
1436 msleep(10);
1437 temp = in_be32(uccf->p_ucce);
1438 } while (!(temp & UCC_GETH_UCCE_GRA) && --i);
1439
1440 uccf->stopped_tx = 1;
1441
1442 return 0;
1443}
1444
1445static int ugeth_graceful_stop_rx(struct ucc_geth_private *ugeth)
1446{
1447 struct ucc_fast_private *uccf;
1448 u32 cecr_subblock;
1449 u8 temp;
1450 int i = 10;
1451
1452 uccf = ugeth->uccf;
1453
1454 /* Clear acknowledge bit */
1455 temp = in_8(&ugeth->p_rx_glbl_pram->rxgstpack);
1456 temp &= ~GRACEFUL_STOP_ACKNOWLEDGE_RX;
1457 out_8(&ugeth->p_rx_glbl_pram->rxgstpack, temp);
1458
1459 /* Keep issuing command and checking acknowledge bit until
1460 it is asserted, according to spec */
1461 do {
1462 /* Issue host command */
1463 cecr_subblock =
1464 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.
1465 ucc_num);
1466 qe_issue_cmd(QE_GRACEFUL_STOP_RX, cecr_subblock,
1467 QE_CR_PROTOCOL_ETHERNET, 0);
1468 msleep(10);
1469 temp = in_8(&ugeth->p_rx_glbl_pram->rxgstpack);
1470 } while (!(temp & GRACEFUL_STOP_ACKNOWLEDGE_RX) && --i);
1471
1472 uccf->stopped_rx = 1;
1473
1474 return 0;
1475}
1476
1477static int ugeth_restart_tx(struct ucc_geth_private *ugeth)
1478{
1479 struct ucc_fast_private *uccf;
1480 u32 cecr_subblock;
1481
1482 uccf = ugeth->uccf;
1483
1484 cecr_subblock =
1485 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1486 qe_issue_cmd(QE_RESTART_TX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET, 0);
1487 uccf->stopped_tx = 0;
1488
1489 return 0;
1490}
1491
1492static int ugeth_restart_rx(struct ucc_geth_private *ugeth)
1493{
1494 struct ucc_fast_private *uccf;
1495 u32 cecr_subblock;
1496
1497 uccf = ugeth->uccf;
1498
1499 cecr_subblock =
1500 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1501 qe_issue_cmd(QE_RESTART_RX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
1502 0);
1503 uccf->stopped_rx = 0;
1504
1505 return 0;
1506}
1507
1508static int ugeth_enable(struct ucc_geth_private *ugeth, enum comm_dir mode)
1509{
1510 struct ucc_fast_private *uccf;
1511 int enabled_tx, enabled_rx;
1512
1513 uccf = ugeth->uccf;
1514
1515 /* check if the UCC number is in range. */
1516 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
1517 if (netif_msg_probe(ugeth))
1518 ugeth_err("%s: ucc_num out of range.", __func__);
1519 return -EINVAL;
1520 }
1521
1522 enabled_tx = uccf->enabled_tx;
1523 enabled_rx = uccf->enabled_rx;
1524
1525 /* Get Tx and Rx going again, in case this channel was actively
1526 disabled. */
1527 if ((mode & COMM_DIR_TX) && (!enabled_tx) && uccf->stopped_tx)
1528 ugeth_restart_tx(ugeth);
1529 if ((mode & COMM_DIR_RX) && (!enabled_rx) && uccf->stopped_rx)
1530 ugeth_restart_rx(ugeth);
1531
1532 ucc_fast_enable(uccf, mode); /* OK to do even if not disabled */
1533
1534 return 0;
1535
1536}
1537
1538static int ugeth_disable(struct ucc_geth_private *ugeth, enum comm_dir mode)
1539{
1540 struct ucc_fast_private *uccf;
1541
1542 uccf = ugeth->uccf;
1543
1544 /* check if the UCC number is in range. */
1545 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
1546 if (netif_msg_probe(ugeth))
1547 ugeth_err("%s: ucc_num out of range.", __func__);
1548 return -EINVAL;
1549 }
1550
1551 /* Stop any transmissions */
1552 if ((mode & COMM_DIR_TX) && uccf->enabled_tx && !uccf->stopped_tx)
1553 ugeth_graceful_stop_tx(ugeth);
1554
1555 /* Stop any receptions */
1556 if ((mode & COMM_DIR_RX) && uccf->enabled_rx && !uccf->stopped_rx)
1557 ugeth_graceful_stop_rx(ugeth);
1558
1559 ucc_fast_disable(ugeth->uccf, mode); /* OK to do even if not enabled */
1560
1561 return 0;
1562}
1563
Li Yangce973b12006-08-14 23:00:11 -07001564/* Called every time the controller might need to be made
1565 * aware of new link state. The PHY code conveys this
1566 * information through variables in the ugeth structure, and this
1567 * function converts those variables into the appropriate
1568 * register values, and can bring down the device if needed.
1569 */
Kim Phillips728de4c92007-04-13 01:26:03 -05001570
Li Yangce973b12006-08-14 23:00:11 -07001571static void adjust_link(struct net_device *dev)
1572{
Li Yang18a8e862006-10-19 21:07:34 -05001573 struct ucc_geth_private *ugeth = netdev_priv(dev);
Andy Fleming6fee40e2008-05-02 13:01:23 -05001574 struct ucc_geth __iomem *ug_regs;
1575 struct ucc_fast __iomem *uf_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001576 struct phy_device *phydev = ugeth->phydev;
1577 unsigned long flags;
1578 int new_state = 0;
Li Yangce973b12006-08-14 23:00:11 -07001579
1580 ug_regs = ugeth->ug_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001581 uf_regs = ugeth->uccf->uf_regs;
Li Yangce973b12006-08-14 23:00:11 -07001582
Kim Phillips728de4c92007-04-13 01:26:03 -05001583 spin_lock_irqsave(&ugeth->lock, flags);
1584
1585 if (phydev->link) {
1586 u32 tempval = in_be32(&ug_regs->maccfg2);
1587 u32 upsmr = in_be32(&uf_regs->upsmr);
Li Yangce973b12006-08-14 23:00:11 -07001588 /* Now we make sure that we can be in full duplex mode.
1589 * If not, we operate in half-duplex mode. */
Kim Phillips728de4c92007-04-13 01:26:03 -05001590 if (phydev->duplex != ugeth->oldduplex) {
1591 new_state = 1;
1592 if (!(phydev->duplex))
Li Yangce973b12006-08-14 23:00:11 -07001593 tempval &= ~(MACCFG2_FDX);
Kim Phillips728de4c92007-04-13 01:26:03 -05001594 else
Li Yangce973b12006-08-14 23:00:11 -07001595 tempval |= MACCFG2_FDX;
Kim Phillips728de4c92007-04-13 01:26:03 -05001596 ugeth->oldduplex = phydev->duplex;
Li Yangce973b12006-08-14 23:00:11 -07001597 }
1598
Kim Phillips728de4c92007-04-13 01:26:03 -05001599 if (phydev->speed != ugeth->oldspeed) {
1600 new_state = 1;
1601 switch (phydev->speed) {
1602 case SPEED_1000:
1603 tempval = ((tempval &
1604 ~(MACCFG2_INTERFACE_MODE_MASK)) |
1605 MACCFG2_INTERFACE_MODE_BYTE);
Li Yangce973b12006-08-14 23:00:11 -07001606 break;
Kim Phillips728de4c92007-04-13 01:26:03 -05001607 case SPEED_100:
1608 case SPEED_10:
1609 tempval = ((tempval &
1610 ~(MACCFG2_INTERFACE_MODE_MASK)) |
1611 MACCFG2_INTERFACE_MODE_NIBBLE);
1612 /* if reduced mode, re-set UPSMR.R10M */
1613 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
1614 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
1615 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06001616 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
1617 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
Kim Phillips728de4c92007-04-13 01:26:03 -05001618 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
1619 if (phydev->speed == SPEED_10)
Timur Tabi3bc53422009-01-11 00:25:21 -08001620 upsmr |= UCC_GETH_UPSMR_R10M;
Kim Phillips728de4c92007-04-13 01:26:03 -05001621 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001622 upsmr &= ~UCC_GETH_UPSMR_R10M;
Kim Phillips728de4c92007-04-13 01:26:03 -05001623 }
Li Yangce973b12006-08-14 23:00:11 -07001624 break;
1625 default:
Kim Phillips728de4c92007-04-13 01:26:03 -05001626 if (netif_msg_link(ugeth))
1627 ugeth_warn(
1628 "%s: Ack! Speed (%d) is not 10/100/1000!",
1629 dev->name, phydev->speed);
Li Yangce973b12006-08-14 23:00:11 -07001630 break;
1631 }
Kim Phillips728de4c92007-04-13 01:26:03 -05001632 ugeth->oldspeed = phydev->speed;
Li Yangce973b12006-08-14 23:00:11 -07001633 }
1634
Kim Phillips728de4c92007-04-13 01:26:03 -05001635 out_be32(&ug_regs->maccfg2, tempval);
1636 out_be32(&uf_regs->upsmr, upsmr);
1637
Li Yangce973b12006-08-14 23:00:11 -07001638 if (!ugeth->oldlink) {
Kim Phillips728de4c92007-04-13 01:26:03 -05001639 new_state = 1;
Li Yangce973b12006-08-14 23:00:11 -07001640 ugeth->oldlink = 1;
Li Yangce973b12006-08-14 23:00:11 -07001641 }
Kim Phillips728de4c92007-04-13 01:26:03 -05001642 } else if (ugeth->oldlink) {
1643 new_state = 1;
Li Yangce973b12006-08-14 23:00:11 -07001644 ugeth->oldlink = 0;
1645 ugeth->oldspeed = 0;
1646 ugeth->oldduplex = -1;
Li Yangce973b12006-08-14 23:00:11 -07001647 }
Kim Phillips728de4c92007-04-13 01:26:03 -05001648
1649 if (new_state && netif_msg_link(ugeth))
1650 phy_print_status(phydev);
1651
1652 spin_unlock_irqrestore(&ugeth->lock, flags);
Li Yangce973b12006-08-14 23:00:11 -07001653}
1654
Haiying Wangfb1001f2009-06-17 13:16:10 +00001655/* Initialize TBI PHY interface for communicating with the
1656 * SERDES lynx PHY on the chip. We communicate with this PHY
1657 * through the MDIO bus on each controller, treating it as a
1658 * "normal" PHY at the address found in the UTBIPA register. We assume
1659 * that the UTBIPA register is valid. Either the MDIO bus code will set
1660 * it to a value that doesn't conflict with other PHYs on the bus, or the
1661 * value doesn't matter, as there are no other PHYs on the bus.
1662 */
1663static void uec_configure_serdes(struct net_device *dev)
1664{
1665 struct ucc_geth_private *ugeth = netdev_priv(dev);
1666 struct ucc_geth_info *ug_info = ugeth->ug_info;
1667 struct phy_device *tbiphy;
1668
1669 if (!ug_info->tbi_node) {
1670 dev_warn(&dev->dev, "SGMII mode requires that the device "
1671 "tree specify a tbi-handle\n");
1672 return;
1673 }
1674
1675 tbiphy = of_phy_find_device(ug_info->tbi_node);
1676 if (!tbiphy) {
1677 dev_err(&dev->dev, "error: Could not get TBI device\n");
1678 return;
1679 }
1680
1681 /*
1682 * If the link is already up, we must already be ok, and don't need to
1683 * configure and reset the TBI<->SerDes link. Maybe U-Boot configured
1684 * everything for us? Resetting it takes the link down and requires
1685 * several seconds for it to come back.
1686 */
1687 if (phy_read(tbiphy, ENET_TBI_MII_SR) & TBISR_LSTATUS)
1688 return;
1689
1690 /* Single clk mode, mii mode off(for serdes communication) */
1691 phy_write(tbiphy, ENET_TBI_MII_ANA, TBIANA_SETTINGS);
1692
1693 phy_write(tbiphy, ENET_TBI_MII_TBICON, TBICON_CLK_SELECT);
1694
1695 phy_write(tbiphy, ENET_TBI_MII_CR, TBICR_SETTINGS);
1696}
1697
Li Yangce973b12006-08-14 23:00:11 -07001698/* Configure the PHY for dev.
1699 * returns 0 if success. -1 if failure
1700 */
1701static int init_phy(struct net_device *dev)
1702{
Kim Phillips728de4c92007-04-13 01:26:03 -05001703 struct ucc_geth_private *priv = netdev_priv(dev);
Anton Vorontsov61fa9dc2009-03-22 21:30:52 -07001704 struct ucc_geth_info *ug_info = priv->ug_info;
Kim Phillips728de4c92007-04-13 01:26:03 -05001705 struct phy_device *phydev;
Li Yangce973b12006-08-14 23:00:11 -07001706
Kim Phillips728de4c92007-04-13 01:26:03 -05001707 priv->oldlink = 0;
1708 priv->oldspeed = 0;
1709 priv->oldduplex = -1;
Li Yangce973b12006-08-14 23:00:11 -07001710
Grant Likely0b9da332009-04-25 12:53:23 +00001711 phydev = of_phy_connect(dev, ug_info->phy_node, &adjust_link, 0,
1712 priv->phy_interface);
Anton Vorontsov3104a6f2009-07-16 21:31:47 +00001713 if (!phydev)
1714 phydev = of_phy_connect_fixed_link(dev, &adjust_link,
1715 priv->phy_interface);
Grant Likely0b9da332009-04-25 12:53:23 +00001716 if (!phydev) {
Anton Vorontsov3104a6f2009-07-16 21:31:47 +00001717 dev_err(&dev->dev, "Could not attach to PHY\n");
Grant Likely0b9da332009-04-25 12:53:23 +00001718 return -ENODEV;
Li Yangce973b12006-08-14 23:00:11 -07001719 }
1720
Haiying Wang047584c2009-06-02 04:04:15 +00001721 if (priv->phy_interface == PHY_INTERFACE_MODE_SGMII)
1722 uec_configure_serdes(dev);
1723
Kim Phillips728de4c92007-04-13 01:26:03 -05001724 phydev->supported &= (ADVERTISED_10baseT_Half |
Li Yangce973b12006-08-14 23:00:11 -07001725 ADVERTISED_10baseT_Full |
1726 ADVERTISED_100baseT_Half |
Kim Phillips728de4c92007-04-13 01:26:03 -05001727 ADVERTISED_100baseT_Full);
Li Yangce973b12006-08-14 23:00:11 -07001728
Kim Phillips728de4c92007-04-13 01:26:03 -05001729 if (priv->max_speed == SPEED_1000)
1730 phydev->supported |= ADVERTISED_1000baseT_Full;
Li Yangce973b12006-08-14 23:00:11 -07001731
Kim Phillips728de4c92007-04-13 01:26:03 -05001732 phydev->advertising = phydev->supported;
Li Yangce973b12006-08-14 23:00:11 -07001733
Kim Phillips728de4c92007-04-13 01:26:03 -05001734 priv->phydev = phydev;
Li Yangce973b12006-08-14 23:00:11 -07001735
1736 return 0;
Li Yangce973b12006-08-14 23:00:11 -07001737}
1738
Li Yang18a8e862006-10-19 21:07:34 -05001739static void ugeth_dump_regs(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001740{
1741#ifdef DEBUG
1742 ucc_fast_dump_regs(ugeth->uccf);
1743 dump_regs(ugeth);
1744 dump_bds(ugeth);
1745#endif
1746}
1747
Li Yang18a8e862006-10-19 21:07:34 -05001748static int ugeth_82xx_filtering_clear_all_addr_in_hash(struct ucc_geth_private *
Li Yangce973b12006-08-14 23:00:11 -07001749 ugeth,
Li Yang18a8e862006-10-19 21:07:34 -05001750 enum enet_addr_type
Li Yangce973b12006-08-14 23:00:11 -07001751 enet_addr_type)
1752{
Andy Fleming6fee40e2008-05-02 13:01:23 -05001753 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Li Yang18a8e862006-10-19 21:07:34 -05001754 struct ucc_fast_private *uccf;
1755 enum comm_dir comm_dir;
Li Yangce973b12006-08-14 23:00:11 -07001756 struct list_head *p_lh;
1757 u16 i, num;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001758 u32 __iomem *addr_h;
1759 u32 __iomem *addr_l;
Li Yangce973b12006-08-14 23:00:11 -07001760 u8 *p_counter;
1761
1762 uccf = ugeth->uccf;
1763
1764 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -05001765 (struct ucc_geth_82xx_address_filtering_pram __iomem *)
1766 ugeth->p_rx_glbl_pram->addressfiltering;
Li Yangce973b12006-08-14 23:00:11 -07001767
1768 if (enet_addr_type == ENET_ADDR_TYPE_GROUP) {
1769 addr_h = &(p_82xx_addr_filt->gaddr_h);
1770 addr_l = &(p_82xx_addr_filt->gaddr_l);
1771 p_lh = &ugeth->group_hash_q;
1772 p_counter = &(ugeth->numGroupAddrInHash);
1773 } else if (enet_addr_type == ENET_ADDR_TYPE_INDIVIDUAL) {
1774 addr_h = &(p_82xx_addr_filt->iaddr_h);
1775 addr_l = &(p_82xx_addr_filt->iaddr_l);
1776 p_lh = &ugeth->ind_hash_q;
1777 p_counter = &(ugeth->numIndAddrInHash);
1778 } else
1779 return -EINVAL;
1780
1781 comm_dir = 0;
1782 if (uccf->enabled_tx)
1783 comm_dir |= COMM_DIR_TX;
1784 if (uccf->enabled_rx)
1785 comm_dir |= COMM_DIR_RX;
1786 if (comm_dir)
1787 ugeth_disable(ugeth, comm_dir);
1788
1789 /* Clear the hash table. */
1790 out_be32(addr_h, 0x00000000);
1791 out_be32(addr_l, 0x00000000);
1792
1793 if (!p_lh)
1794 return 0;
1795
1796 num = *p_counter;
1797
1798 /* Delete all remaining CQ elements */
1799 for (i = 0; i < num; i++)
1800 put_enet_addr_container(ENET_ADDR_CONT_ENTRY(dequeue(p_lh)));
1801
1802 *p_counter = 0;
1803
1804 if (comm_dir)
1805 ugeth_enable(ugeth, comm_dir);
1806
1807 return 0;
1808}
1809
Li Yang18a8e862006-10-19 21:07:34 -05001810static int ugeth_82xx_filtering_clear_addr_in_paddr(struct ucc_geth_private *ugeth,
Li Yangce973b12006-08-14 23:00:11 -07001811 u8 paddr_num)
1812{
1813 ugeth->indAddrRegUsed[paddr_num] = 0; /* mark this paddr as not used */
1814 return hw_clear_addr_in_paddr(ugeth, paddr_num);/* clear in hardware */
1815}
1816
Li Yang18a8e862006-10-19 21:07:34 -05001817static void ucc_geth_memclean(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001818{
1819 u16 i, j;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001820 u8 __iomem *bd;
Li Yangce973b12006-08-14 23:00:11 -07001821
1822 if (!ugeth)
1823 return;
1824
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03001825 if (ugeth->uccf) {
Li Yangce973b12006-08-14 23:00:11 -07001826 ucc_fast_free(ugeth->uccf);
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03001827 ugeth->uccf = NULL;
1828 }
Li Yangce973b12006-08-14 23:00:11 -07001829
1830 if (ugeth->p_thread_data_tx) {
1831 qe_muram_free(ugeth->thread_dat_tx_offset);
1832 ugeth->p_thread_data_tx = NULL;
1833 }
1834 if (ugeth->p_thread_data_rx) {
1835 qe_muram_free(ugeth->thread_dat_rx_offset);
1836 ugeth->p_thread_data_rx = NULL;
1837 }
1838 if (ugeth->p_exf_glbl_param) {
1839 qe_muram_free(ugeth->exf_glbl_param_offset);
1840 ugeth->p_exf_glbl_param = NULL;
1841 }
1842 if (ugeth->p_rx_glbl_pram) {
1843 qe_muram_free(ugeth->rx_glbl_pram_offset);
1844 ugeth->p_rx_glbl_pram = NULL;
1845 }
1846 if (ugeth->p_tx_glbl_pram) {
1847 qe_muram_free(ugeth->tx_glbl_pram_offset);
1848 ugeth->p_tx_glbl_pram = NULL;
1849 }
1850 if (ugeth->p_send_q_mem_reg) {
1851 qe_muram_free(ugeth->send_q_mem_reg_offset);
1852 ugeth->p_send_q_mem_reg = NULL;
1853 }
1854 if (ugeth->p_scheduler) {
1855 qe_muram_free(ugeth->scheduler_offset);
1856 ugeth->p_scheduler = NULL;
1857 }
1858 if (ugeth->p_tx_fw_statistics_pram) {
1859 qe_muram_free(ugeth->tx_fw_statistics_pram_offset);
1860 ugeth->p_tx_fw_statistics_pram = NULL;
1861 }
1862 if (ugeth->p_rx_fw_statistics_pram) {
1863 qe_muram_free(ugeth->rx_fw_statistics_pram_offset);
1864 ugeth->p_rx_fw_statistics_pram = NULL;
1865 }
1866 if (ugeth->p_rx_irq_coalescing_tbl) {
1867 qe_muram_free(ugeth->rx_irq_coalescing_tbl_offset);
1868 ugeth->p_rx_irq_coalescing_tbl = NULL;
1869 }
1870 if (ugeth->p_rx_bd_qs_tbl) {
1871 qe_muram_free(ugeth->rx_bd_qs_tbl_offset);
1872 ugeth->p_rx_bd_qs_tbl = NULL;
1873 }
1874 if (ugeth->p_init_enet_param_shadow) {
1875 return_init_enet_entries(ugeth,
1876 &(ugeth->p_init_enet_param_shadow->
1877 rxthread[0]),
1878 ENET_INIT_PARAM_MAX_ENTRIES_RX,
1879 ugeth->ug_info->riscRx, 1);
1880 return_init_enet_entries(ugeth,
1881 &(ugeth->p_init_enet_param_shadow->
1882 txthread[0]),
1883 ENET_INIT_PARAM_MAX_ENTRIES_TX,
1884 ugeth->ug_info->riscTx, 0);
1885 kfree(ugeth->p_init_enet_param_shadow);
1886 ugeth->p_init_enet_param_shadow = NULL;
1887 }
1888 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
1889 bd = ugeth->p_tx_bd_ring[i];
Nicu Ioan Petru3a8205e2007-04-13 01:26:29 -05001890 if (!bd)
1891 continue;
Li Yangce973b12006-08-14 23:00:11 -07001892 for (j = 0; j < ugeth->ug_info->bdRingLenTx[i]; j++) {
1893 if (ugeth->tx_skbuff[i][j]) {
Anton Vorontsovda1aa632009-04-02 01:26:07 -07001894 dma_unmap_single(ugeth->dev,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001895 in_be32(&((struct qe_bd __iomem *)bd)->buf),
1896 (in_be32((u32 __iomem *)bd) &
Li Yangce973b12006-08-14 23:00:11 -07001897 BD_LENGTH_MASK),
1898 DMA_TO_DEVICE);
1899 dev_kfree_skb_any(ugeth->tx_skbuff[i][j]);
1900 ugeth->tx_skbuff[i][j] = NULL;
1901 }
1902 }
1903
1904 kfree(ugeth->tx_skbuff[i]);
1905
1906 if (ugeth->p_tx_bd_ring[i]) {
1907 if (ugeth->ug_info->uf_info.bd_mem_part ==
1908 MEM_PART_SYSTEM)
1909 kfree((void *)ugeth->tx_bd_ring_offset[i]);
1910 else if (ugeth->ug_info->uf_info.bd_mem_part ==
1911 MEM_PART_MURAM)
1912 qe_muram_free(ugeth->tx_bd_ring_offset[i]);
1913 ugeth->p_tx_bd_ring[i] = NULL;
1914 }
1915 }
1916 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
1917 if (ugeth->p_rx_bd_ring[i]) {
1918 /* Return existing data buffers in ring */
1919 bd = ugeth->p_rx_bd_ring[i];
1920 for (j = 0; j < ugeth->ug_info->bdRingLenRx[i]; j++) {
1921 if (ugeth->rx_skbuff[i][j]) {
Anton Vorontsovda1aa632009-04-02 01:26:07 -07001922 dma_unmap_single(ugeth->dev,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001923 in_be32(&((struct qe_bd __iomem *)bd)->buf),
Li Yang18a8e862006-10-19 21:07:34 -05001924 ugeth->ug_info->
1925 uf_info.max_rx_buf_length +
1926 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
1927 DMA_FROM_DEVICE);
1928 dev_kfree_skb_any(
1929 ugeth->rx_skbuff[i][j]);
Li Yangce973b12006-08-14 23:00:11 -07001930 ugeth->rx_skbuff[i][j] = NULL;
1931 }
Li Yang18a8e862006-10-19 21:07:34 -05001932 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07001933 }
1934
1935 kfree(ugeth->rx_skbuff[i]);
1936
1937 if (ugeth->ug_info->uf_info.bd_mem_part ==
1938 MEM_PART_SYSTEM)
1939 kfree((void *)ugeth->rx_bd_ring_offset[i]);
1940 else if (ugeth->ug_info->uf_info.bd_mem_part ==
1941 MEM_PART_MURAM)
1942 qe_muram_free(ugeth->rx_bd_ring_offset[i]);
1943 ugeth->p_rx_bd_ring[i] = NULL;
1944 }
1945 }
1946 while (!list_empty(&ugeth->group_hash_q))
1947 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
1948 (dequeue(&ugeth->group_hash_q)));
1949 while (!list_empty(&ugeth->ind_hash_q))
1950 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
1951 (dequeue(&ugeth->ind_hash_q)));
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00001952 if (ugeth->ug_regs) {
1953 iounmap(ugeth->ug_regs);
1954 ugeth->ug_regs = NULL;
1955 }
Anton Vorontsov50f238f2009-07-07 08:38:42 +00001956
1957 skb_queue_purge(&ugeth->rx_recycle);
Li Yangce973b12006-08-14 23:00:11 -07001958}
1959
1960static void ucc_geth_set_multi(struct net_device *dev)
1961{
Li Yang18a8e862006-10-19 21:07:34 -05001962 struct ucc_geth_private *ugeth;
Li Yangce973b12006-08-14 23:00:11 -07001963 struct dev_mc_list *dmi;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001964 struct ucc_fast __iomem *uf_regs;
1965 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Joakim Tjernlund9030b3d2007-10-17 11:05:41 +02001966 int i;
Li Yangce973b12006-08-14 23:00:11 -07001967
1968 ugeth = netdev_priv(dev);
1969
1970 uf_regs = ugeth->uccf->uf_regs;
1971
1972 if (dev->flags & IFF_PROMISC) {
Timur Tabi3bc53422009-01-11 00:25:21 -08001973 setbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
Li Yangce973b12006-08-14 23:00:11 -07001974 } else {
Timur Tabi3bc53422009-01-11 00:25:21 -08001975 clrbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
Li Yangce973b12006-08-14 23:00:11 -07001976
1977 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -05001978 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
Li Yangce973b12006-08-14 23:00:11 -07001979 p_rx_glbl_pram->addressfiltering;
1980
1981 if (dev->flags & IFF_ALLMULTI) {
1982 /* Catch all multicast addresses, so set the
1983 * filter to all 1's.
1984 */
1985 out_be32(&p_82xx_addr_filt->gaddr_h, 0xffffffff);
1986 out_be32(&p_82xx_addr_filt->gaddr_l, 0xffffffff);
1987 } else {
1988 /* Clear filter and add the addresses in the list.
1989 */
1990 out_be32(&p_82xx_addr_filt->gaddr_h, 0x0);
1991 out_be32(&p_82xx_addr_filt->gaddr_l, 0x0);
1992
1993 dmi = dev->mc_list;
1994
1995 for (i = 0; i < dev->mc_count; i++, dmi = dmi->next) {
1996
1997 /* Only support group multicast for now.
1998 */
1999 if (!(dmi->dmi_addr[0] & 1))
2000 continue;
2001
Li Yangce973b12006-08-14 23:00:11 -07002002 /* Ask CPM to run CRC and set bit in
2003 * filter mask.
2004 */
Joakim Tjernlund9030b3d2007-10-17 11:05:41 +02002005 hw_add_addr_in_hash(ugeth, dmi->dmi_addr);
Li Yangce973b12006-08-14 23:00:11 -07002006 }
2007 }
2008 }
2009}
2010
Li Yang18a8e862006-10-19 21:07:34 -05002011static void ucc_geth_stop(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07002012{
Andy Fleming6fee40e2008-05-02 13:01:23 -05002013 struct ucc_geth __iomem *ug_regs = ugeth->ug_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05002014 struct phy_device *phydev = ugeth->phydev;
Li Yangce973b12006-08-14 23:00:11 -07002015
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002016 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002017
2018 /* Disable the controller */
2019 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
2020
2021 /* Tell the kernel the link is down */
Kim Phillips728de4c92007-04-13 01:26:03 -05002022 phy_stop(phydev);
Li Yangce973b12006-08-14 23:00:11 -07002023
2024 /* Mask all interrupts */
Timur Tabic6f50472007-07-10 07:51:11 -05002025 out_be32(ugeth->uccf->p_uccm, 0x00000000);
Li Yangce973b12006-08-14 23:00:11 -07002026
2027 /* Clear all interrupts */
2028 out_be32(ugeth->uccf->p_ucce, 0xffffffff);
2029
2030 /* Disable Rx and Tx */
Timur Tabi3bc53422009-01-11 00:25:21 -08002031 clrbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
Li Yangce973b12006-08-14 23:00:11 -07002032
Anton Vorontsov79675902009-03-27 16:00:03 -07002033 phy_disconnect(ugeth->phydev);
2034 ugeth->phydev = NULL;
2035
Li Yangce973b12006-08-14 23:00:11 -07002036 ucc_geth_memclean(ugeth);
2037}
2038
Kim Phillips728de4c92007-04-13 01:26:03 -05002039static int ucc_struct_init(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07002040{
Li Yang18a8e862006-10-19 21:07:34 -05002041 struct ucc_geth_info *ug_info;
2042 struct ucc_fast_info *uf_info;
Kim Phillips728de4c92007-04-13 01:26:03 -05002043 int i;
Li Yangce973b12006-08-14 23:00:11 -07002044
2045 ug_info = ugeth->ug_info;
2046 uf_info = &ug_info->uf_info;
2047
2048 if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
2049 (uf_info->bd_mem_part == MEM_PART_MURAM))) {
Li Yang890de952007-07-19 11:48:29 +08002050 if (netif_msg_probe(ugeth))
2051 ugeth_err("%s: Bad memory partition value.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002052 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002053 return -EINVAL;
2054 }
2055
2056 /* Rx BD lengths */
2057 for (i = 0; i < ug_info->numQueuesRx; i++) {
2058 if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) ||
2059 (ug_info->bdRingLenRx[i] %
2060 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) {
Li Yang890de952007-07-19 11:48:29 +08002061 if (netif_msg_probe(ugeth))
2062 ugeth_err
2063 ("%s: Rx BD ring length must be multiple of 4, no smaller than 8.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002064 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002065 return -EINVAL;
2066 }
2067 }
2068
2069 /* Tx BD lengths */
2070 for (i = 0; i < ug_info->numQueuesTx; i++) {
2071 if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) {
Li Yang890de952007-07-19 11:48:29 +08002072 if (netif_msg_probe(ugeth))
2073 ugeth_err
2074 ("%s: Tx BD ring length must be no smaller than 2.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002075 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002076 return -EINVAL;
2077 }
2078 }
2079
2080 /* mrblr */
2081 if ((uf_info->max_rx_buf_length == 0) ||
2082 (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) {
Li Yang890de952007-07-19 11:48:29 +08002083 if (netif_msg_probe(ugeth))
2084 ugeth_err
2085 ("%s: max_rx_buf_length must be non-zero multiple of 128.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002086 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002087 return -EINVAL;
2088 }
2089
2090 /* num Tx queues */
2091 if (ug_info->numQueuesTx > NUM_TX_QUEUES) {
Li Yang890de952007-07-19 11:48:29 +08002092 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002093 ugeth_err("%s: number of tx queues too large.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002094 return -EINVAL;
2095 }
2096
2097 /* num Rx queues */
2098 if (ug_info->numQueuesRx > NUM_RX_QUEUES) {
Li Yang890de952007-07-19 11:48:29 +08002099 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002100 ugeth_err("%s: number of rx queues too large.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002101 return -EINVAL;
2102 }
2103
2104 /* l2qt */
2105 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) {
2106 if (ug_info->l2qt[i] >= ug_info->numQueuesRx) {
Li Yang890de952007-07-19 11:48:29 +08002107 if (netif_msg_probe(ugeth))
2108 ugeth_err
2109 ("%s: VLAN priority table entry must not be"
2110 " larger than number of Rx queues.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002111 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002112 return -EINVAL;
2113 }
2114 }
2115
2116 /* l3qt */
2117 for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) {
2118 if (ug_info->l3qt[i] >= ug_info->numQueuesRx) {
Li Yang890de952007-07-19 11:48:29 +08002119 if (netif_msg_probe(ugeth))
2120 ugeth_err
2121 ("%s: IP priority table entry must not be"
2122 " larger than number of Rx queues.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002123 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002124 return -EINVAL;
2125 }
2126 }
2127
2128 if (ug_info->cam && !ug_info->ecamptr) {
Li Yang890de952007-07-19 11:48:29 +08002129 if (netif_msg_probe(ugeth))
2130 ugeth_err("%s: If cam mode is chosen, must supply cam ptr.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002131 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002132 return -EINVAL;
2133 }
2134
2135 if ((ug_info->numStationAddresses !=
2136 UCC_GETH_NUM_OF_STATION_ADDRESSES_1)
2137 && ug_info->rxExtendedFiltering) {
Li Yang890de952007-07-19 11:48:29 +08002138 if (netif_msg_probe(ugeth))
2139 ugeth_err("%s: Number of station addresses greater than 1 "
2140 "not allowed in extended parsing mode.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002141 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002142 return -EINVAL;
2143 }
2144
2145 /* Generate uccm_mask for receive */
2146 uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */
2147 for (i = 0; i < ug_info->numQueuesRx; i++)
Timur Tabi3bc53422009-01-11 00:25:21 -08002148 uf_info->uccm_mask |= (UCC_GETH_UCCE_RXF0 << i);
Li Yangce973b12006-08-14 23:00:11 -07002149
2150 for (i = 0; i < ug_info->numQueuesTx; i++)
Timur Tabi3bc53422009-01-11 00:25:21 -08002151 uf_info->uccm_mask |= (UCC_GETH_UCCE_TXB0 << i);
Li Yangce973b12006-08-14 23:00:11 -07002152 /* Initialize the general fast UCC block. */
Kim Phillips728de4c92007-04-13 01:26:03 -05002153 if (ucc_fast_init(uf_info, &ugeth->uccf)) {
Li Yang890de952007-07-19 11:48:29 +08002154 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002155 ugeth_err("%s: Failed to init uccf.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002156 return -ENOMEM;
2157 }
Kim Phillips728de4c92007-04-13 01:26:03 -05002158
Haiying Wang345f8422009-04-29 14:14:35 -04002159 /* read the number of risc engines, update the riscTx and riscRx
2160 * if there are 4 riscs in QE
2161 */
2162 if (qe_get_num_of_risc() == 4) {
2163 ug_info->riscTx = QE_RISC_ALLOCATION_FOUR_RISCS;
2164 ug_info->riscRx = QE_RISC_ALLOCATION_FOUR_RISCS;
2165 }
2166
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00002167 ugeth->ug_regs = ioremap(uf_info->regs, sizeof(*ugeth->ug_regs));
2168 if (!ugeth->ug_regs) {
2169 if (netif_msg_probe(ugeth))
2170 ugeth_err("%s: Failed to ioremap regs.", __func__);
2171 return -ENOMEM;
2172 }
Kim Phillips728de4c92007-04-13 01:26:03 -05002173
Anton Vorontsov50f238f2009-07-07 08:38:42 +00002174 skb_queue_head_init(&ugeth->rx_recycle);
2175
Kim Phillips728de4c92007-04-13 01:26:03 -05002176 return 0;
2177}
2178
2179static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2180{
Andy Fleming6fee40e2008-05-02 13:01:23 -05002181 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
2182 struct ucc_geth_init_pram __iomem *p_init_enet_pram;
Kim Phillips728de4c92007-04-13 01:26:03 -05002183 struct ucc_fast_private *uccf;
2184 struct ucc_geth_info *ug_info;
2185 struct ucc_fast_info *uf_info;
Andy Fleming6fee40e2008-05-02 13:01:23 -05002186 struct ucc_fast __iomem *uf_regs;
2187 struct ucc_geth __iomem *ug_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05002188 int ret_val = -EINVAL;
2189 u32 remoder = UCC_GETH_REMODER_INIT;
Timur Tabi3bc53422009-01-11 00:25:21 -08002190 u32 init_enet_pram_offset, cecr_subblock, command;
Kim Phillips728de4c92007-04-13 01:26:03 -05002191 u32 ifstat, i, j, size, l2qt, l3qt, length;
2192 u16 temoder = UCC_GETH_TEMODER_INIT;
2193 u16 test;
2194 u8 function_code = 0;
Andy Fleming6fee40e2008-05-02 13:01:23 -05002195 u8 __iomem *bd;
2196 u8 __iomem *endOfRing;
Kim Phillips728de4c92007-04-13 01:26:03 -05002197 u8 numThreadsRxNumerical, numThreadsTxNumerical;
2198
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002199 ugeth_vdbg("%s: IN", __func__);
Kim Phillips728de4c92007-04-13 01:26:03 -05002200 uccf = ugeth->uccf;
2201 ug_info = ugeth->ug_info;
2202 uf_info = &ug_info->uf_info;
2203 uf_regs = uccf->uf_regs;
2204 ug_regs = ugeth->ug_regs;
Li Yangce973b12006-08-14 23:00:11 -07002205
2206 switch (ug_info->numThreadsRx) {
2207 case UCC_GETH_NUM_OF_THREADS_1:
2208 numThreadsRxNumerical = 1;
2209 break;
2210 case UCC_GETH_NUM_OF_THREADS_2:
2211 numThreadsRxNumerical = 2;
2212 break;
2213 case UCC_GETH_NUM_OF_THREADS_4:
2214 numThreadsRxNumerical = 4;
2215 break;
2216 case UCC_GETH_NUM_OF_THREADS_6:
2217 numThreadsRxNumerical = 6;
2218 break;
2219 case UCC_GETH_NUM_OF_THREADS_8:
2220 numThreadsRxNumerical = 8;
2221 break;
2222 default:
Li Yang890de952007-07-19 11:48:29 +08002223 if (netif_msg_ifup(ugeth))
2224 ugeth_err("%s: Bad number of Rx threads value.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002225 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002226 return -EINVAL;
2227 break;
2228 }
2229
2230 switch (ug_info->numThreadsTx) {
2231 case UCC_GETH_NUM_OF_THREADS_1:
2232 numThreadsTxNumerical = 1;
2233 break;
2234 case UCC_GETH_NUM_OF_THREADS_2:
2235 numThreadsTxNumerical = 2;
2236 break;
2237 case UCC_GETH_NUM_OF_THREADS_4:
2238 numThreadsTxNumerical = 4;
2239 break;
2240 case UCC_GETH_NUM_OF_THREADS_6:
2241 numThreadsTxNumerical = 6;
2242 break;
2243 case UCC_GETH_NUM_OF_THREADS_8:
2244 numThreadsTxNumerical = 8;
2245 break;
2246 default:
Li Yang890de952007-07-19 11:48:29 +08002247 if (netif_msg_ifup(ugeth))
2248 ugeth_err("%s: Bad number of Tx threads value.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002249 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002250 return -EINVAL;
2251 break;
2252 }
2253
2254 /* Calculate rx_extended_features */
2255 ugeth->rx_non_dynamic_extended_features = ug_info->ipCheckSumCheck ||
2256 ug_info->ipAddressAlignment ||
2257 (ug_info->numStationAddresses !=
2258 UCC_GETH_NUM_OF_STATION_ADDRESSES_1);
2259
2260 ugeth->rx_extended_features = ugeth->rx_non_dynamic_extended_features ||
2261 (ug_info->vlanOperationTagged != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
2262 || (ug_info->vlanOperationNonTagged !=
2263 UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP);
2264
Li Yangce973b12006-08-14 23:00:11 -07002265 init_default_reg_vals(&uf_regs->upsmr,
2266 &ug_regs->maccfg1, &ug_regs->maccfg2);
2267
2268 /* Set UPSMR */
2269 /* For more details see the hardware spec. */
2270 init_rx_parameters(ug_info->bro,
2271 ug_info->rsh, ug_info->pro, &uf_regs->upsmr);
2272
2273 /* We're going to ignore other registers for now, */
2274 /* except as needed to get up and running */
2275
2276 /* Set MACCFG1 */
2277 /* For more details see the hardware spec. */
2278 init_flow_control_params(ug_info->aufc,
2279 ug_info->receiveFlowControl,
Li Yangac421852007-07-19 11:47:47 +08002280 ug_info->transmitFlowControl,
Li Yangce973b12006-08-14 23:00:11 -07002281 ug_info->pausePeriod,
2282 ug_info->extensionField,
2283 &uf_regs->upsmr,
2284 &ug_regs->uempr, &ug_regs->maccfg1);
2285
Timur Tabi3bc53422009-01-11 00:25:21 -08002286 setbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
Li Yangce973b12006-08-14 23:00:11 -07002287
2288 /* Set IPGIFG */
2289 /* For more details see the hardware spec. */
2290 ret_val = init_inter_frame_gap_params(ug_info->nonBackToBackIfgPart1,
2291 ug_info->nonBackToBackIfgPart2,
2292 ug_info->
2293 miminumInterFrameGapEnforcement,
2294 ug_info->backToBackInterFrameGap,
2295 &ug_regs->ipgifg);
2296 if (ret_val != 0) {
Li Yang890de952007-07-19 11:48:29 +08002297 if (netif_msg_ifup(ugeth))
2298 ugeth_err("%s: IPGIFG initialization parameter too large.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002299 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002300 return ret_val;
2301 }
2302
2303 /* Set HAFDUP */
2304 /* For more details see the hardware spec. */
2305 ret_val = init_half_duplex_params(ug_info->altBeb,
2306 ug_info->backPressureNoBackoff,
2307 ug_info->noBackoff,
2308 ug_info->excessDefer,
2309 ug_info->altBebTruncation,
2310 ug_info->maxRetransmission,
2311 ug_info->collisionWindow,
2312 &ug_regs->hafdup);
2313 if (ret_val != 0) {
Li Yang890de952007-07-19 11:48:29 +08002314 if (netif_msg_ifup(ugeth))
2315 ugeth_err("%s: Half Duplex initialization parameter too large.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002316 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002317 return ret_val;
2318 }
2319
2320 /* Set IFSTAT */
2321 /* For more details see the hardware spec. */
2322 /* Read only - resets upon read */
2323 ifstat = in_be32(&ug_regs->ifstat);
2324
2325 /* Clear UEMPR */
2326 /* For more details see the hardware spec. */
2327 out_be32(&ug_regs->uempr, 0);
2328
2329 /* Set UESCR */
2330 /* For more details see the hardware spec. */
2331 init_hw_statistics_gathering_mode((ug_info->statisticsMode &
2332 UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE),
2333 0, &uf_regs->upsmr, &ug_regs->uescr);
2334
2335 /* Allocate Tx bds */
2336 for (j = 0; j < ug_info->numQueuesTx; j++) {
2337 /* Allocate in multiple of
2338 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT,
2339 according to spec */
Li Yang18a8e862006-10-19 21:07:34 -05002340 length = ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd))
Li Yangce973b12006-08-14 23:00:11 -07002341 / UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2342 * UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
Li Yang18a8e862006-10-19 21:07:34 -05002343 if ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)) %
Li Yangce973b12006-08-14 23:00:11 -07002344 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2345 length += UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
2346 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2347 u32 align = 4;
2348 if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
2349 align = UCC_GETH_TX_BD_RING_ALIGNMENT;
2350 ugeth->tx_bd_ring_offset[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002351 (u32) kmalloc((u32) (length + align), GFP_KERNEL);
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002352
Li Yangce973b12006-08-14 23:00:11 -07002353 if (ugeth->tx_bd_ring_offset[j] != 0)
2354 ugeth->p_tx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002355 (u8 __iomem *)((ugeth->tx_bd_ring_offset[j] +
Li Yangce973b12006-08-14 23:00:11 -07002356 align) & ~(align - 1));
2357 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2358 ugeth->tx_bd_ring_offset[j] =
2359 qe_muram_alloc(length,
2360 UCC_GETH_TX_BD_RING_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002361 if (!IS_ERR_VALUE(ugeth->tx_bd_ring_offset[j]))
Li Yangce973b12006-08-14 23:00:11 -07002362 ugeth->p_tx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002363 (u8 __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002364 tx_bd_ring_offset[j]);
2365 }
2366 if (!ugeth->p_tx_bd_ring[j]) {
Li Yang890de952007-07-19 11:48:29 +08002367 if (netif_msg_ifup(ugeth))
2368 ugeth_err
2369 ("%s: Can not allocate memory for Tx bd rings.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002370 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002371 return -ENOMEM;
2372 }
2373 /* Zero unused end of bd ring, according to spec */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002374 memset_io((void __iomem *)(ugeth->p_tx_bd_ring[j] +
2375 ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)), 0,
Li Yang18a8e862006-10-19 21:07:34 -05002376 length - ug_info->bdRingLenTx[j] * sizeof(struct qe_bd));
Li Yangce973b12006-08-14 23:00:11 -07002377 }
2378
2379 /* Allocate Rx bds */
2380 for (j = 0; j < ug_info->numQueuesRx; j++) {
Li Yang18a8e862006-10-19 21:07:34 -05002381 length = ug_info->bdRingLenRx[j] * sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002382 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2383 u32 align = 4;
2384 if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
2385 align = UCC_GETH_RX_BD_RING_ALIGNMENT;
2386 ugeth->rx_bd_ring_offset[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002387 (u32) kmalloc((u32) (length + align), GFP_KERNEL);
Li Yangce973b12006-08-14 23:00:11 -07002388 if (ugeth->rx_bd_ring_offset[j] != 0)
2389 ugeth->p_rx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002390 (u8 __iomem *)((ugeth->rx_bd_ring_offset[j] +
Li Yangce973b12006-08-14 23:00:11 -07002391 align) & ~(align - 1));
2392 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2393 ugeth->rx_bd_ring_offset[j] =
2394 qe_muram_alloc(length,
2395 UCC_GETH_RX_BD_RING_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002396 if (!IS_ERR_VALUE(ugeth->rx_bd_ring_offset[j]))
Li Yangce973b12006-08-14 23:00:11 -07002397 ugeth->p_rx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002398 (u8 __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002399 rx_bd_ring_offset[j]);
2400 }
2401 if (!ugeth->p_rx_bd_ring[j]) {
Li Yang890de952007-07-19 11:48:29 +08002402 if (netif_msg_ifup(ugeth))
2403 ugeth_err
2404 ("%s: Can not allocate memory for Rx bd rings.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002405 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002406 return -ENOMEM;
2407 }
2408 }
2409
2410 /* Init Tx bds */
2411 for (j = 0; j < ug_info->numQueuesTx; j++) {
2412 /* Setup the skbuff rings */
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002413 ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
2414 ugeth->ug_info->bdRingLenTx[j],
2415 GFP_KERNEL);
Li Yangce973b12006-08-14 23:00:11 -07002416
2417 if (ugeth->tx_skbuff[j] == NULL) {
Li Yang890de952007-07-19 11:48:29 +08002418 if (netif_msg_ifup(ugeth))
2419 ugeth_err("%s: Could not allocate tx_skbuff",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002420 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002421 return -ENOMEM;
2422 }
2423
2424 for (i = 0; i < ugeth->ug_info->bdRingLenTx[j]; i++)
2425 ugeth->tx_skbuff[j][i] = NULL;
2426
2427 ugeth->skb_curtx[j] = ugeth->skb_dirtytx[j] = 0;
2428 bd = ugeth->confBd[j] = ugeth->txBd[j] = ugeth->p_tx_bd_ring[j];
2429 for (i = 0; i < ug_info->bdRingLenTx[j]; i++) {
Li Yang18a8e862006-10-19 21:07:34 -05002430 /* clear bd buffer */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002431 out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
Li Yang18a8e862006-10-19 21:07:34 -05002432 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002433 out_be32((u32 __iomem *)bd, 0);
Li Yang18a8e862006-10-19 21:07:34 -05002434 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002435 }
Li Yang18a8e862006-10-19 21:07:34 -05002436 bd -= sizeof(struct qe_bd);
2437 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002438 out_be32((u32 __iomem *)bd, T_W); /* for last BD set Wrap bit */
Li Yangce973b12006-08-14 23:00:11 -07002439 }
2440
2441 /* Init Rx bds */
2442 for (j = 0; j < ug_info->numQueuesRx; j++) {
2443 /* Setup the skbuff rings */
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002444 ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
2445 ugeth->ug_info->bdRingLenRx[j],
2446 GFP_KERNEL);
Li Yangce973b12006-08-14 23:00:11 -07002447
2448 if (ugeth->rx_skbuff[j] == NULL) {
Li Yang890de952007-07-19 11:48:29 +08002449 if (netif_msg_ifup(ugeth))
2450 ugeth_err("%s: Could not allocate rx_skbuff",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002451 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002452 return -ENOMEM;
2453 }
2454
2455 for (i = 0; i < ugeth->ug_info->bdRingLenRx[j]; i++)
2456 ugeth->rx_skbuff[j][i] = NULL;
2457
2458 ugeth->skb_currx[j] = 0;
2459 bd = ugeth->rxBd[j] = ugeth->p_rx_bd_ring[j];
2460 for (i = 0; i < ug_info->bdRingLenRx[j]; i++) {
Li Yang18a8e862006-10-19 21:07:34 -05002461 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002462 out_be32((u32 __iomem *)bd, R_I);
Li Yang18a8e862006-10-19 21:07:34 -05002463 /* clear bd buffer */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002464 out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
Li Yang18a8e862006-10-19 21:07:34 -05002465 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002466 }
Li Yang18a8e862006-10-19 21:07:34 -05002467 bd -= sizeof(struct qe_bd);
2468 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002469 out_be32((u32 __iomem *)bd, R_W); /* for last BD set Wrap bit */
Li Yangce973b12006-08-14 23:00:11 -07002470 }
2471
2472 /*
2473 * Global PRAM
2474 */
2475 /* Tx global PRAM */
2476 /* Allocate global tx parameter RAM page */
2477 ugeth->tx_glbl_pram_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002478 qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram),
Li Yangce973b12006-08-14 23:00:11 -07002479 UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002480 if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002481 if (netif_msg_ifup(ugeth))
2482 ugeth_err
2483 ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002484 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002485 return -ENOMEM;
2486 }
2487 ugeth->p_tx_glbl_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002488 (struct ucc_geth_tx_global_pram __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002489 tx_glbl_pram_offset);
2490 /* Zero out p_tx_glbl_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002491 memset_io((void __iomem *)ugeth->p_tx_glbl_pram, 0, sizeof(struct ucc_geth_tx_global_pram));
Li Yangce973b12006-08-14 23:00:11 -07002492
2493 /* Fill global PRAM */
2494
2495 /* TQPTR */
2496 /* Size varies with number of Tx threads */
2497 ugeth->thread_dat_tx_offset =
2498 qe_muram_alloc(numThreadsTxNumerical *
Li Yang18a8e862006-10-19 21:07:34 -05002499 sizeof(struct ucc_geth_thread_data_tx) +
Li Yangce973b12006-08-14 23:00:11 -07002500 32 * (numThreadsTxNumerical == 1),
2501 UCC_GETH_THREAD_DATA_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002502 if (IS_ERR_VALUE(ugeth->thread_dat_tx_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002503 if (netif_msg_ifup(ugeth))
2504 ugeth_err
2505 ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002506 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002507 return -ENOMEM;
2508 }
2509
2510 ugeth->p_thread_data_tx =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002511 (struct ucc_geth_thread_data_tx __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002512 thread_dat_tx_offset);
2513 out_be32(&ugeth->p_tx_glbl_pram->tqptr, ugeth->thread_dat_tx_offset);
2514
2515 /* vtagtable */
2516 for (i = 0; i < UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX; i++)
2517 out_be32(&ugeth->p_tx_glbl_pram->vtagtable[i],
2518 ug_info->vtagtable[i]);
2519
2520 /* iphoffset */
2521 for (i = 0; i < TX_IP_OFFSET_ENTRY_MAX; i++)
Andy Fleming6fee40e2008-05-02 13:01:23 -05002522 out_8(&ugeth->p_tx_glbl_pram->iphoffset[i],
2523 ug_info->iphoffset[i]);
Li Yangce973b12006-08-14 23:00:11 -07002524
2525 /* SQPTR */
2526 /* Size varies with number of Tx queues */
2527 ugeth->send_q_mem_reg_offset =
2528 qe_muram_alloc(ug_info->numQueuesTx *
Li Yang18a8e862006-10-19 21:07:34 -05002529 sizeof(struct ucc_geth_send_queue_qd),
Li Yangce973b12006-08-14 23:00:11 -07002530 UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002531 if (IS_ERR_VALUE(ugeth->send_q_mem_reg_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002532 if (netif_msg_ifup(ugeth))
2533 ugeth_err
2534 ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002535 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002536 return -ENOMEM;
2537 }
2538
2539 ugeth->p_send_q_mem_reg =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002540 (struct ucc_geth_send_queue_mem_region __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002541 send_q_mem_reg_offset);
2542 out_be32(&ugeth->p_tx_glbl_pram->sqptr, ugeth->send_q_mem_reg_offset);
2543
2544 /* Setup the table */
2545 /* Assume BD rings are already established */
2546 for (i = 0; i < ug_info->numQueuesTx; i++) {
2547 endOfRing =
2548 ugeth->p_tx_bd_ring[i] + (ug_info->bdRingLenTx[i] -
Li Yang18a8e862006-10-19 21:07:34 -05002549 1) * sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002550 if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
2551 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
2552 (u32) virt_to_phys(ugeth->p_tx_bd_ring[i]));
2553 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
2554 last_bd_completed_address,
2555 (u32) virt_to_phys(endOfRing));
2556 } else if (ugeth->ug_info->uf_info.bd_mem_part ==
2557 MEM_PART_MURAM) {
2558 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
2559 (u32) immrbar_virt_to_phys(ugeth->
2560 p_tx_bd_ring[i]));
2561 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
2562 last_bd_completed_address,
2563 (u32) immrbar_virt_to_phys(endOfRing));
2564 }
2565 }
2566
2567 /* schedulerbasepointer */
2568
2569 if (ug_info->numQueuesTx > 1) {
2570 /* scheduler exists only if more than 1 tx queue */
2571 ugeth->scheduler_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002572 qe_muram_alloc(sizeof(struct ucc_geth_scheduler),
Li Yangce973b12006-08-14 23:00:11 -07002573 UCC_GETH_SCHEDULER_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002574 if (IS_ERR_VALUE(ugeth->scheduler_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002575 if (netif_msg_ifup(ugeth))
2576 ugeth_err
2577 ("%s: Can not allocate DPRAM memory for p_scheduler.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002578 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002579 return -ENOMEM;
2580 }
2581
2582 ugeth->p_scheduler =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002583 (struct ucc_geth_scheduler __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002584 scheduler_offset);
2585 out_be32(&ugeth->p_tx_glbl_pram->schedulerbasepointer,
2586 ugeth->scheduler_offset);
2587 /* Zero out p_scheduler */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002588 memset_io((void __iomem *)ugeth->p_scheduler, 0, sizeof(struct ucc_geth_scheduler));
Li Yangce973b12006-08-14 23:00:11 -07002589
2590 /* Set values in scheduler */
2591 out_be32(&ugeth->p_scheduler->mblinterval,
2592 ug_info->mblinterval);
2593 out_be16(&ugeth->p_scheduler->nortsrbytetime,
2594 ug_info->nortsrbytetime);
Andy Fleming6fee40e2008-05-02 13:01:23 -05002595 out_8(&ugeth->p_scheduler->fracsiz, ug_info->fracsiz);
2596 out_8(&ugeth->p_scheduler->strictpriorityq,
2597 ug_info->strictpriorityq);
2598 out_8(&ugeth->p_scheduler->txasap, ug_info->txasap);
2599 out_8(&ugeth->p_scheduler->extrabw, ug_info->extrabw);
Li Yangce973b12006-08-14 23:00:11 -07002600 for (i = 0; i < NUM_TX_QUEUES; i++)
Andy Fleming6fee40e2008-05-02 13:01:23 -05002601 out_8(&ugeth->p_scheduler->weightfactor[i],
2602 ug_info->weightfactor[i]);
Li Yangce973b12006-08-14 23:00:11 -07002603
2604 /* Set pointers to cpucount registers in scheduler */
2605 ugeth->p_cpucount[0] = &(ugeth->p_scheduler->cpucount0);
2606 ugeth->p_cpucount[1] = &(ugeth->p_scheduler->cpucount1);
2607 ugeth->p_cpucount[2] = &(ugeth->p_scheduler->cpucount2);
2608 ugeth->p_cpucount[3] = &(ugeth->p_scheduler->cpucount3);
2609 ugeth->p_cpucount[4] = &(ugeth->p_scheduler->cpucount4);
2610 ugeth->p_cpucount[5] = &(ugeth->p_scheduler->cpucount5);
2611 ugeth->p_cpucount[6] = &(ugeth->p_scheduler->cpucount6);
2612 ugeth->p_cpucount[7] = &(ugeth->p_scheduler->cpucount7);
2613 }
2614
2615 /* schedulerbasepointer */
2616 /* TxRMON_PTR (statistics) */
2617 if (ug_info->
2618 statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
2619 ugeth->tx_fw_statistics_pram_offset =
2620 qe_muram_alloc(sizeof
Li Yang18a8e862006-10-19 21:07:34 -05002621 (struct ucc_geth_tx_firmware_statistics_pram),
Li Yangce973b12006-08-14 23:00:11 -07002622 UCC_GETH_TX_STATISTICS_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002623 if (IS_ERR_VALUE(ugeth->tx_fw_statistics_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002624 if (netif_msg_ifup(ugeth))
2625 ugeth_err
2626 ("%s: Can not allocate DPRAM memory for"
2627 " p_tx_fw_statistics_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002628 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002629 return -ENOMEM;
2630 }
2631 ugeth->p_tx_fw_statistics_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002632 (struct ucc_geth_tx_firmware_statistics_pram __iomem *)
Li Yangce973b12006-08-14 23:00:11 -07002633 qe_muram_addr(ugeth->tx_fw_statistics_pram_offset);
2634 /* Zero out p_tx_fw_statistics_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002635 memset_io((void __iomem *)ugeth->p_tx_fw_statistics_pram,
Li Yang18a8e862006-10-19 21:07:34 -05002636 0, sizeof(struct ucc_geth_tx_firmware_statistics_pram));
Li Yangce973b12006-08-14 23:00:11 -07002637 }
2638
2639 /* temoder */
2640 /* Already has speed set */
2641
2642 if (ug_info->numQueuesTx > 1)
2643 temoder |= TEMODER_SCHEDULER_ENABLE;
2644 if (ug_info->ipCheckSumGenerate)
2645 temoder |= TEMODER_IP_CHECKSUM_GENERATE;
2646 temoder |= ((ug_info->numQueuesTx - 1) << TEMODER_NUM_OF_QUEUES_SHIFT);
2647 out_be16(&ugeth->p_tx_glbl_pram->temoder, temoder);
2648
2649 test = in_be16(&ugeth->p_tx_glbl_pram->temoder);
2650
2651 /* Function code register value to be used later */
Timur Tabi6b0b5942007-10-03 11:34:59 -05002652 function_code = UCC_BMR_BO_BE | UCC_BMR_GBL;
Li Yangce973b12006-08-14 23:00:11 -07002653 /* Required for QE */
2654
2655 /* function code register */
2656 out_be32(&ugeth->p_tx_glbl_pram->tstate, ((u32) function_code) << 24);
2657
2658 /* Rx global PRAM */
2659 /* Allocate global rx parameter RAM page */
2660 ugeth->rx_glbl_pram_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002661 qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram),
Li Yangce973b12006-08-14 23:00:11 -07002662 UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002663 if (IS_ERR_VALUE(ugeth->rx_glbl_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002664 if (netif_msg_ifup(ugeth))
2665 ugeth_err
2666 ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002667 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002668 return -ENOMEM;
2669 }
2670 ugeth->p_rx_glbl_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002671 (struct ucc_geth_rx_global_pram __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002672 rx_glbl_pram_offset);
2673 /* Zero out p_rx_glbl_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002674 memset_io((void __iomem *)ugeth->p_rx_glbl_pram, 0, sizeof(struct ucc_geth_rx_global_pram));
Li Yangce973b12006-08-14 23:00:11 -07002675
2676 /* Fill global PRAM */
2677
2678 /* RQPTR */
2679 /* Size varies with number of Rx threads */
2680 ugeth->thread_dat_rx_offset =
2681 qe_muram_alloc(numThreadsRxNumerical *
Li Yang18a8e862006-10-19 21:07:34 -05002682 sizeof(struct ucc_geth_thread_data_rx),
Li Yangce973b12006-08-14 23:00:11 -07002683 UCC_GETH_THREAD_DATA_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002684 if (IS_ERR_VALUE(ugeth->thread_dat_rx_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002685 if (netif_msg_ifup(ugeth))
2686 ugeth_err
2687 ("%s: Can not allocate DPRAM memory for p_thread_data_rx.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002688 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002689 return -ENOMEM;
2690 }
2691
2692 ugeth->p_thread_data_rx =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002693 (struct ucc_geth_thread_data_rx __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002694 thread_dat_rx_offset);
2695 out_be32(&ugeth->p_rx_glbl_pram->rqptr, ugeth->thread_dat_rx_offset);
2696
2697 /* typeorlen */
2698 out_be16(&ugeth->p_rx_glbl_pram->typeorlen, ug_info->typeorlen);
2699
2700 /* rxrmonbaseptr (statistics) */
2701 if (ug_info->
2702 statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
2703 ugeth->rx_fw_statistics_pram_offset =
2704 qe_muram_alloc(sizeof
Li Yang18a8e862006-10-19 21:07:34 -05002705 (struct ucc_geth_rx_firmware_statistics_pram),
Li Yangce973b12006-08-14 23:00:11 -07002706 UCC_GETH_RX_STATISTICS_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002707 if (IS_ERR_VALUE(ugeth->rx_fw_statistics_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002708 if (netif_msg_ifup(ugeth))
2709 ugeth_err
2710 ("%s: Can not allocate DPRAM memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002711 " p_rx_fw_statistics_pram.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002712 return -ENOMEM;
2713 }
2714 ugeth->p_rx_fw_statistics_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002715 (struct ucc_geth_rx_firmware_statistics_pram __iomem *)
Li Yangce973b12006-08-14 23:00:11 -07002716 qe_muram_addr(ugeth->rx_fw_statistics_pram_offset);
2717 /* Zero out p_rx_fw_statistics_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002718 memset_io((void __iomem *)ugeth->p_rx_fw_statistics_pram, 0,
Li Yang18a8e862006-10-19 21:07:34 -05002719 sizeof(struct ucc_geth_rx_firmware_statistics_pram));
Li Yangce973b12006-08-14 23:00:11 -07002720 }
2721
2722 /* intCoalescingPtr */
2723
2724 /* Size varies with number of Rx queues */
2725 ugeth->rx_irq_coalescing_tbl_offset =
2726 qe_muram_alloc(ug_info->numQueuesRx *
Michael Barkowski75639072007-04-13 01:26:15 -05002727 sizeof(struct ucc_geth_rx_interrupt_coalescing_entry)
2728 + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002729 if (IS_ERR_VALUE(ugeth->rx_irq_coalescing_tbl_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002730 if (netif_msg_ifup(ugeth))
2731 ugeth_err
2732 ("%s: Can not allocate DPRAM memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002733 " p_rx_irq_coalescing_tbl.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002734 return -ENOMEM;
2735 }
2736
2737 ugeth->p_rx_irq_coalescing_tbl =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002738 (struct ucc_geth_rx_interrupt_coalescing_table __iomem *)
Li Yangce973b12006-08-14 23:00:11 -07002739 qe_muram_addr(ugeth->rx_irq_coalescing_tbl_offset);
2740 out_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr,
2741 ugeth->rx_irq_coalescing_tbl_offset);
2742
2743 /* Fill interrupt coalescing table */
2744 for (i = 0; i < ug_info->numQueuesRx; i++) {
2745 out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
2746 interruptcoalescingmaxvalue,
2747 ug_info->interruptcoalescingmaxvalue[i]);
2748 out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
2749 interruptcoalescingcounter,
2750 ug_info->interruptcoalescingmaxvalue[i]);
2751 }
2752
2753 /* MRBLR */
2754 init_max_rx_buff_len(uf_info->max_rx_buf_length,
2755 &ugeth->p_rx_glbl_pram->mrblr);
2756 /* MFLR */
2757 out_be16(&ugeth->p_rx_glbl_pram->mflr, ug_info->maxFrameLength);
2758 /* MINFLR */
2759 init_min_frame_len(ug_info->minFrameLength,
2760 &ugeth->p_rx_glbl_pram->minflr,
2761 &ugeth->p_rx_glbl_pram->mrblr);
2762 /* MAXD1 */
2763 out_be16(&ugeth->p_rx_glbl_pram->maxd1, ug_info->maxD1Length);
2764 /* MAXD2 */
2765 out_be16(&ugeth->p_rx_glbl_pram->maxd2, ug_info->maxD2Length);
2766
2767 /* l2qt */
2768 l2qt = 0;
2769 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++)
2770 l2qt |= (ug_info->l2qt[i] << (28 - 4 * i));
2771 out_be32(&ugeth->p_rx_glbl_pram->l2qt, l2qt);
2772
2773 /* l3qt */
2774 for (j = 0; j < UCC_GETH_IP_PRIORITY_MAX; j += 8) {
2775 l3qt = 0;
2776 for (i = 0; i < 8; i++)
2777 l3qt |= (ug_info->l3qt[j + i] << (28 - 4 * i));
Li Yang18a8e862006-10-19 21:07:34 -05002778 out_be32(&ugeth->p_rx_glbl_pram->l3qt[j/8], l3qt);
Li Yangce973b12006-08-14 23:00:11 -07002779 }
2780
2781 /* vlantype */
2782 out_be16(&ugeth->p_rx_glbl_pram->vlantype, ug_info->vlantype);
2783
2784 /* vlantci */
2785 out_be16(&ugeth->p_rx_glbl_pram->vlantci, ug_info->vlantci);
2786
2787 /* ecamptr */
2788 out_be32(&ugeth->p_rx_glbl_pram->ecamptr, ug_info->ecamptr);
2789
2790 /* RBDQPTR */
2791 /* Size varies with number of Rx queues */
2792 ugeth->rx_bd_qs_tbl_offset =
2793 qe_muram_alloc(ug_info->numQueuesRx *
Li Yang18a8e862006-10-19 21:07:34 -05002794 (sizeof(struct ucc_geth_rx_bd_queues_entry) +
2795 sizeof(struct ucc_geth_rx_prefetched_bds)),
Li Yangce973b12006-08-14 23:00:11 -07002796 UCC_GETH_RX_BD_QUEUES_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002797 if (IS_ERR_VALUE(ugeth->rx_bd_qs_tbl_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002798 if (netif_msg_ifup(ugeth))
2799 ugeth_err
2800 ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002801 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002802 return -ENOMEM;
2803 }
2804
2805 ugeth->p_rx_bd_qs_tbl =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002806 (struct ucc_geth_rx_bd_queues_entry __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002807 rx_bd_qs_tbl_offset);
2808 out_be32(&ugeth->p_rx_glbl_pram->rbdqptr, ugeth->rx_bd_qs_tbl_offset);
2809 /* Zero out p_rx_bd_qs_tbl */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002810 memset_io((void __iomem *)ugeth->p_rx_bd_qs_tbl,
Li Yangce973b12006-08-14 23:00:11 -07002811 0,
Li Yang18a8e862006-10-19 21:07:34 -05002812 ug_info->numQueuesRx * (sizeof(struct ucc_geth_rx_bd_queues_entry) +
2813 sizeof(struct ucc_geth_rx_prefetched_bds)));
Li Yangce973b12006-08-14 23:00:11 -07002814
2815 /* Setup the table */
2816 /* Assume BD rings are already established */
2817 for (i = 0; i < ug_info->numQueuesRx; i++) {
2818 if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
2819 out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
2820 (u32) virt_to_phys(ugeth->p_rx_bd_ring[i]));
2821 } else if (ugeth->ug_info->uf_info.bd_mem_part ==
2822 MEM_PART_MURAM) {
2823 out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
2824 (u32) immrbar_virt_to_phys(ugeth->
2825 p_rx_bd_ring[i]));
2826 }
2827 /* rest of fields handled by QE */
2828 }
2829
2830 /* remoder */
2831 /* Already has speed set */
2832
2833 if (ugeth->rx_extended_features)
2834 remoder |= REMODER_RX_EXTENDED_FEATURES;
2835 if (ug_info->rxExtendedFiltering)
2836 remoder |= REMODER_RX_EXTENDED_FILTERING;
2837 if (ug_info->dynamicMaxFrameLength)
2838 remoder |= REMODER_DYNAMIC_MAX_FRAME_LENGTH;
2839 if (ug_info->dynamicMinFrameLength)
2840 remoder |= REMODER_DYNAMIC_MIN_FRAME_LENGTH;
2841 remoder |=
2842 ug_info->vlanOperationTagged << REMODER_VLAN_OPERATION_TAGGED_SHIFT;
2843 remoder |=
2844 ug_info->
2845 vlanOperationNonTagged << REMODER_VLAN_OPERATION_NON_TAGGED_SHIFT;
2846 remoder |= ug_info->rxQoSMode << REMODER_RX_QOS_MODE_SHIFT;
2847 remoder |= ((ug_info->numQueuesRx - 1) << REMODER_NUM_OF_QUEUES_SHIFT);
2848 if (ug_info->ipCheckSumCheck)
2849 remoder |= REMODER_IP_CHECKSUM_CHECK;
2850 if (ug_info->ipAddressAlignment)
2851 remoder |= REMODER_IP_ADDRESS_ALIGNMENT;
2852 out_be32(&ugeth->p_rx_glbl_pram->remoder, remoder);
2853
2854 /* Note that this function must be called */
2855 /* ONLY AFTER p_tx_fw_statistics_pram */
2856 /* andp_UccGethRxFirmwareStatisticsPram are allocated ! */
2857 init_firmware_statistics_gathering_mode((ug_info->
2858 statisticsMode &
2859 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX),
2860 (ug_info->statisticsMode &
2861 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX),
2862 &ugeth->p_tx_glbl_pram->txrmonbaseptr,
2863 ugeth->tx_fw_statistics_pram_offset,
2864 &ugeth->p_rx_glbl_pram->rxrmonbaseptr,
2865 ugeth->rx_fw_statistics_pram_offset,
2866 &ugeth->p_tx_glbl_pram->temoder,
2867 &ugeth->p_rx_glbl_pram->remoder);
2868
2869 /* function code register */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002870 out_8(&ugeth->p_rx_glbl_pram->rstate, function_code);
Li Yangce973b12006-08-14 23:00:11 -07002871
2872 /* initialize extended filtering */
2873 if (ug_info->rxExtendedFiltering) {
2874 if (!ug_info->extendedFilteringChainPointer) {
Li Yang890de952007-07-19 11:48:29 +08002875 if (netif_msg_ifup(ugeth))
2876 ugeth_err("%s: Null Extended Filtering Chain Pointer.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002877 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002878 return -EINVAL;
2879 }
2880
2881 /* Allocate memory for extended filtering Mode Global
2882 Parameters */
2883 ugeth->exf_glbl_param_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002884 qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram),
Li Yangce973b12006-08-14 23:00:11 -07002885 UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002886 if (IS_ERR_VALUE(ugeth->exf_glbl_param_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002887 if (netif_msg_ifup(ugeth))
2888 ugeth_err
2889 ("%s: Can not allocate DPRAM memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002890 " p_exf_glbl_param.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002891 return -ENOMEM;
2892 }
2893
2894 ugeth->p_exf_glbl_param =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002895 (struct ucc_geth_exf_global_pram __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002896 exf_glbl_param_offset);
2897 out_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam,
2898 ugeth->exf_glbl_param_offset);
2899 out_be32(&ugeth->p_exf_glbl_param->l2pcdptr,
2900 (u32) ug_info->extendedFilteringChainPointer);
2901
2902 } else { /* initialize 82xx style address filtering */
2903
2904 /* Init individual address recognition registers to disabled */
2905
2906 for (j = 0; j < NUM_OF_PADDRS; j++)
2907 ugeth_82xx_filtering_clear_addr_in_paddr(ugeth, (u8) j);
2908
Li Yangce973b12006-08-14 23:00:11 -07002909 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002910 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002911 p_rx_glbl_pram->addressfiltering;
2912
2913 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
2914 ENET_ADDR_TYPE_GROUP);
2915 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
2916 ENET_ADDR_TYPE_INDIVIDUAL);
2917 }
2918
2919 /*
2920 * Initialize UCC at QE level
2921 */
2922
2923 command = QE_INIT_TX_RX;
2924
2925 /* Allocate shadow InitEnet command parameter structure.
2926 * This is needed because after the InitEnet command is executed,
2927 * the structure in DPRAM is released, because DPRAM is a premium
2928 * resource.
2929 * This shadow structure keeps a copy of what was done so that the
2930 * allocated resources can be released when the channel is freed.
2931 */
2932 if (!(ugeth->p_init_enet_param_shadow =
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002933 kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
Li Yang890de952007-07-19 11:48:29 +08002934 if (netif_msg_ifup(ugeth))
2935 ugeth_err
2936 ("%s: Can not allocate memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002937 " p_UccInitEnetParamShadows.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002938 return -ENOMEM;
2939 }
2940 /* Zero out *p_init_enet_param_shadow */
2941 memset((char *)ugeth->p_init_enet_param_shadow,
Li Yang18a8e862006-10-19 21:07:34 -05002942 0, sizeof(struct ucc_geth_init_pram));
Li Yangce973b12006-08-14 23:00:11 -07002943
2944 /* Fill shadow InitEnet command parameter structure */
2945
2946 ugeth->p_init_enet_param_shadow->resinit1 =
2947 ENET_INIT_PARAM_MAGIC_RES_INIT1;
2948 ugeth->p_init_enet_param_shadow->resinit2 =
2949 ENET_INIT_PARAM_MAGIC_RES_INIT2;
2950 ugeth->p_init_enet_param_shadow->resinit3 =
2951 ENET_INIT_PARAM_MAGIC_RES_INIT3;
2952 ugeth->p_init_enet_param_shadow->resinit4 =
2953 ENET_INIT_PARAM_MAGIC_RES_INIT4;
2954 ugeth->p_init_enet_param_shadow->resinit5 =
2955 ENET_INIT_PARAM_MAGIC_RES_INIT5;
2956 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
2957 ((u32) ug_info->numThreadsRx) << ENET_INIT_PARAM_RGF_SHIFT;
2958 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
2959 ((u32) ug_info->numThreadsTx) << ENET_INIT_PARAM_TGF_SHIFT;
2960
2961 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
2962 ugeth->rx_glbl_pram_offset | ug_info->riscRx;
2963 if ((ug_info->largestexternallookupkeysize !=
2964 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE)
2965 && (ug_info->largestexternallookupkeysize !=
2966 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
2967 && (ug_info->largestexternallookupkeysize !=
2968 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) {
Li Yang890de952007-07-19 11:48:29 +08002969 if (netif_msg_ifup(ugeth))
2970 ugeth_err("%s: Invalid largest External Lookup Key Size.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002971 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002972 return -EINVAL;
2973 }
2974 ugeth->p_init_enet_param_shadow->largestexternallookupkeysize =
2975 ug_info->largestexternallookupkeysize;
Li Yang18a8e862006-10-19 21:07:34 -05002976 size = sizeof(struct ucc_geth_thread_rx_pram);
Li Yangce973b12006-08-14 23:00:11 -07002977 if (ug_info->rxExtendedFiltering) {
2978 size += THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
2979 if (ug_info->largestexternallookupkeysize ==
2980 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
2981 size +=
2982 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
2983 if (ug_info->largestexternallookupkeysize ==
2984 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
2985 size +=
2986 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
2987 }
2988
2989 if ((ret_val = fill_init_enet_entries(ugeth, &(ugeth->
2990 p_init_enet_param_shadow->rxthread[0]),
2991 (u8) (numThreadsRxNumerical + 1)
2992 /* Rx needs one extra for terminator */
2993 , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT,
2994 ug_info->riscRx, 1)) != 0) {
Li Yang890de952007-07-19 11:48:29 +08002995 if (netif_msg_ifup(ugeth))
2996 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002997 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002998 return ret_val;
2999 }
3000
3001 ugeth->p_init_enet_param_shadow->txglobal =
3002 ugeth->tx_glbl_pram_offset | ug_info->riscTx;
3003 if ((ret_val =
3004 fill_init_enet_entries(ugeth,
3005 &(ugeth->p_init_enet_param_shadow->
3006 txthread[0]), numThreadsTxNumerical,
Li Yang18a8e862006-10-19 21:07:34 -05003007 sizeof(struct ucc_geth_thread_tx_pram),
Li Yangce973b12006-08-14 23:00:11 -07003008 UCC_GETH_THREAD_TX_PRAM_ALIGNMENT,
3009 ug_info->riscTx, 0)) != 0) {
Li Yang890de952007-07-19 11:48:29 +08003010 if (netif_msg_ifup(ugeth))
3011 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003012 __func__);
Li Yangce973b12006-08-14 23:00:11 -07003013 return ret_val;
3014 }
3015
3016 /* Load Rx bds with buffers */
3017 for (i = 0; i < ug_info->numQueuesRx; i++) {
3018 if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) {
Li Yang890de952007-07-19 11:48:29 +08003019 if (netif_msg_ifup(ugeth))
3020 ugeth_err("%s: Can not fill Rx bds with buffers.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003021 __func__);
Li Yangce973b12006-08-14 23:00:11 -07003022 return ret_val;
3023 }
3024 }
3025
3026 /* Allocate InitEnet command parameter structure */
Li Yang18a8e862006-10-19 21:07:34 -05003027 init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4);
Timur Tabi4c356302007-05-08 14:46:36 -05003028 if (IS_ERR_VALUE(init_enet_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08003029 if (netif_msg_ifup(ugeth))
3030 ugeth_err
3031 ("%s: Can not allocate DPRAM memory for p_init_enet_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003032 __func__);
Li Yangce973b12006-08-14 23:00:11 -07003033 return -ENOMEM;
3034 }
3035 p_init_enet_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05003036 (struct ucc_geth_init_pram __iomem *) qe_muram_addr(init_enet_pram_offset);
Li Yangce973b12006-08-14 23:00:11 -07003037
3038 /* Copy shadow InitEnet command parameter structure into PRAM */
Andy Fleming6fee40e2008-05-02 13:01:23 -05003039 out_8(&p_init_enet_pram->resinit1,
3040 ugeth->p_init_enet_param_shadow->resinit1);
3041 out_8(&p_init_enet_pram->resinit2,
3042 ugeth->p_init_enet_param_shadow->resinit2);
3043 out_8(&p_init_enet_pram->resinit3,
3044 ugeth->p_init_enet_param_shadow->resinit3);
3045 out_8(&p_init_enet_pram->resinit4,
3046 ugeth->p_init_enet_param_shadow->resinit4);
Li Yangce973b12006-08-14 23:00:11 -07003047 out_be16(&p_init_enet_pram->resinit5,
3048 ugeth->p_init_enet_param_shadow->resinit5);
Andy Fleming6fee40e2008-05-02 13:01:23 -05003049 out_8(&p_init_enet_pram->largestexternallookupkeysize,
3050 ugeth->p_init_enet_param_shadow->largestexternallookupkeysize);
Li Yangce973b12006-08-14 23:00:11 -07003051 out_be32(&p_init_enet_pram->rgftgfrxglobal,
3052 ugeth->p_init_enet_param_shadow->rgftgfrxglobal);
3053 for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_RX; i++)
3054 out_be32(&p_init_enet_pram->rxthread[i],
3055 ugeth->p_init_enet_param_shadow->rxthread[i]);
3056 out_be32(&p_init_enet_pram->txglobal,
3057 ugeth->p_init_enet_param_shadow->txglobal);
3058 for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_TX; i++)
3059 out_be32(&p_init_enet_pram->txthread[i],
3060 ugeth->p_init_enet_param_shadow->txthread[i]);
3061
3062 /* Issue QE command */
3063 cecr_subblock =
3064 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
Li Yang18a8e862006-10-19 21:07:34 -05003065 qe_issue_cmd(command, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
Li Yangce973b12006-08-14 23:00:11 -07003066 init_enet_pram_offset);
3067
3068 /* Free InitEnet command parameter */
3069 qe_muram_free(init_enet_pram_offset);
3070
3071 return 0;
3072}
3073
Li Yangce973b12006-08-14 23:00:11 -07003074/* This is called by the kernel when a frame is ready for transmission. */
3075/* It is pointed to by the dev->hard_start_xmit function pointer */
3076static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
3077{
Li Yang18a8e862006-10-19 21:07:34 -05003078 struct ucc_geth_private *ugeth = netdev_priv(dev);
Michael Reissd5b90492007-04-13 01:26:19 -05003079#ifdef CONFIG_UGETH_TX_ON_DEMAND
3080 struct ucc_fast_private *uccf;
3081#endif
Andy Fleming6fee40e2008-05-02 13:01:23 -05003082 u8 __iomem *bd; /* BD pointer */
Li Yangce973b12006-08-14 23:00:11 -07003083 u32 bd_status;
3084 u8 txQ = 0;
Dongdong Deng22580f82009-08-13 19:12:31 +00003085 unsigned long flags;
Li Yangce973b12006-08-14 23:00:11 -07003086
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003087 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003088
Dongdong Deng22580f82009-08-13 19:12:31 +00003089 spin_lock_irqsave(&ugeth->lock, flags);
Li Yangce973b12006-08-14 23:00:11 -07003090
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003091 dev->stats.tx_bytes += skb->len;
Li Yangce973b12006-08-14 23:00:11 -07003092
3093 /* Start from the next BD that should be filled */
3094 bd = ugeth->txBd[txQ];
Andy Fleming6fee40e2008-05-02 13:01:23 -05003095 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003096 /* Save the skb pointer so we can free it later */
3097 ugeth->tx_skbuff[txQ][ugeth->skb_curtx[txQ]] = skb;
3098
3099 /* Update the current skb pointer (wrapping if this was the last) */
3100 ugeth->skb_curtx[txQ] =
3101 (ugeth->skb_curtx[txQ] +
3102 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
3103
3104 /* set up the buffer descriptor */
Andy Fleming6fee40e2008-05-02 13:01:23 -05003105 out_be32(&((struct qe_bd __iomem *)bd)->buf,
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003106 dma_map_single(ugeth->dev, skb->data,
Andy Fleming7f802022008-05-15 17:00:21 -05003107 skb->len, DMA_TO_DEVICE));
Li Yangce973b12006-08-14 23:00:11 -07003108
Li Yang18a8e862006-10-19 21:07:34 -05003109 /* printk(KERN_DEBUG"skb->data is 0x%x\n",skb->data); */
Li Yangce973b12006-08-14 23:00:11 -07003110
3111 bd_status = (bd_status & T_W) | T_R | T_I | T_L | skb->len;
3112
Li Yang18a8e862006-10-19 21:07:34 -05003113 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05003114 out_be32((u32 __iomem *)bd, bd_status);
Li Yangce973b12006-08-14 23:00:11 -07003115
3116 dev->trans_start = jiffies;
3117
3118 /* Move to next BD in the ring */
3119 if (!(bd_status & T_W))
Li Yanga394f012007-03-06 16:53:46 +08003120 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07003121 else
Li Yanga394f012007-03-06 16:53:46 +08003122 bd = ugeth->p_tx_bd_ring[txQ];
Li Yangce973b12006-08-14 23:00:11 -07003123
3124 /* If the next BD still needs to be cleaned up, then the bds
3125 are full. We need to tell the kernel to stop sending us stuff. */
3126 if (bd == ugeth->confBd[txQ]) {
3127 if (!netif_queue_stopped(dev))
3128 netif_stop_queue(dev);
3129 }
3130
Li Yanga394f012007-03-06 16:53:46 +08003131 ugeth->txBd[txQ] = bd;
3132
Li Yangce973b12006-08-14 23:00:11 -07003133 if (ugeth->p_scheduler) {
3134 ugeth->cpucount[txQ]++;
3135 /* Indicate to QE that there are more Tx bds ready for
3136 transmission */
3137 /* This is done by writing a running counter of the bd
3138 count to the scheduler PRAM. */
3139 out_be16(ugeth->p_cpucount[txQ], ugeth->cpucount[txQ]);
3140 }
3141
Michael Reissd5b90492007-04-13 01:26:19 -05003142#ifdef CONFIG_UGETH_TX_ON_DEMAND
3143 uccf = ugeth->uccf;
3144 out_be16(uccf->p_utodr, UCC_FAST_TOD);
3145#endif
Dongdong Deng22580f82009-08-13 19:12:31 +00003146 spin_unlock_irqrestore(&ugeth->lock, flags);
Li Yangce973b12006-08-14 23:00:11 -07003147
Patrick McHardy6ed10652009-06-23 06:03:08 +00003148 return NETDEV_TX_OK;
Li Yangce973b12006-08-14 23:00:11 -07003149}
3150
Li Yang18a8e862006-10-19 21:07:34 -05003151static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit)
Li Yangce973b12006-08-14 23:00:11 -07003152{
3153 struct sk_buff *skb;
Andy Fleming6fee40e2008-05-02 13:01:23 -05003154 u8 __iomem *bd;
Li Yangce973b12006-08-14 23:00:11 -07003155 u16 length, howmany = 0;
3156 u32 bd_status;
3157 u8 *bdBuffer;
Andrew Morton4b8fdef2007-12-13 16:02:55 -08003158 struct net_device *dev;
Li Yangce973b12006-08-14 23:00:11 -07003159
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003160 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003161
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003162 dev = ugeth->ndev;
Emil Medve88a15f22007-10-15 08:43:50 -05003163
Li Yangce973b12006-08-14 23:00:11 -07003164 /* collect received buffers */
3165 bd = ugeth->rxBd[rxQ];
3166
Andy Fleming6fee40e2008-05-02 13:01:23 -05003167 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003168
3169 /* while there are received buffers and BD is full (~R_E) */
3170 while (!((bd_status & (R_E)) || (--rx_work_limit < 0))) {
Andy Fleming6fee40e2008-05-02 13:01:23 -05003171 bdBuffer = (u8 *) in_be32(&((struct qe_bd __iomem *)bd)->buf);
Li Yangce973b12006-08-14 23:00:11 -07003172 length = (u16) ((bd_status & BD_LENGTH_MASK) - 4);
3173 skb = ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]];
3174
3175 /* determine whether buffer is first, last, first and last
3176 (single buffer frame) or middle (not first and not last) */
3177 if (!skb ||
3178 (!(bd_status & (R_F | R_L))) ||
3179 (bd_status & R_ERRORS_FATAL)) {
Li Yang890de952007-07-19 11:48:29 +08003180 if (netif_msg_rx_err(ugeth))
3181 ugeth_err("%s, %d: ERROR!!! skb - 0x%08x",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003182 __func__, __LINE__, (u32) skb);
Anton Vorontsov50f238f2009-07-07 08:38:42 +00003183 if (skb) {
3184 skb->data = skb->head + NET_SKB_PAD;
3185 __skb_queue_head(&ugeth->rx_recycle, skb);
3186 }
Li Yangce973b12006-08-14 23:00:11 -07003187
3188 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL;
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003189 dev->stats.rx_dropped++;
Li Yangce973b12006-08-14 23:00:11 -07003190 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003191 dev->stats.rx_packets++;
Li Yangce973b12006-08-14 23:00:11 -07003192 howmany++;
3193
3194 /* Prep the skb for the packet */
3195 skb_put(skb, length);
3196
3197 /* Tell the skb what kind of packet this is */
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003198 skb->protocol = eth_type_trans(skb, ugeth->ndev);
Li Yangce973b12006-08-14 23:00:11 -07003199
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003200 dev->stats.rx_bytes += length;
Li Yangce973b12006-08-14 23:00:11 -07003201 /* Send the packet up the stack */
Li Yangce973b12006-08-14 23:00:11 -07003202 netif_receive_skb(skb);
Li Yangce973b12006-08-14 23:00:11 -07003203 }
3204
Li Yangce973b12006-08-14 23:00:11 -07003205 skb = get_new_skb(ugeth, bd);
3206 if (!skb) {
Li Yang890de952007-07-19 11:48:29 +08003207 if (netif_msg_rx_err(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003208 ugeth_warn("%s: No Rx Data Buffer", __func__);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003209 dev->stats.rx_dropped++;
Li Yangce973b12006-08-14 23:00:11 -07003210 break;
3211 }
3212
3213 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = skb;
3214
3215 /* update to point at the next skb */
3216 ugeth->skb_currx[rxQ] =
3217 (ugeth->skb_currx[rxQ] +
3218 1) & RX_RING_MOD_MASK(ugeth->ug_info->bdRingLenRx[rxQ]);
3219
3220 if (bd_status & R_W)
3221 bd = ugeth->p_rx_bd_ring[rxQ];
3222 else
Li Yang18a8e862006-10-19 21:07:34 -05003223 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07003224
Andy Fleming6fee40e2008-05-02 13:01:23 -05003225 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003226 }
3227
3228 ugeth->rxBd[rxQ] = bd;
Li Yangce973b12006-08-14 23:00:11 -07003229 return howmany;
3230}
3231
3232static int ucc_geth_tx(struct net_device *dev, u8 txQ)
3233{
3234 /* Start from the next BD that should be filled */
Li Yang18a8e862006-10-19 21:07:34 -05003235 struct ucc_geth_private *ugeth = netdev_priv(dev);
Andy Fleming6fee40e2008-05-02 13:01:23 -05003236 u8 __iomem *bd; /* BD pointer */
Li Yangce973b12006-08-14 23:00:11 -07003237 u32 bd_status;
3238
3239 bd = ugeth->confBd[txQ];
Andy Fleming6fee40e2008-05-02 13:01:23 -05003240 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003241
3242 /* Normal processing. */
3243 while ((bd_status & T_R) == 0) {
Anton Vorontsov50f238f2009-07-07 08:38:42 +00003244 struct sk_buff *skb;
3245
Li Yangce973b12006-08-14 23:00:11 -07003246 /* BD contains already transmitted buffer. */
3247 /* Handle the transmitted buffer and release */
3248 /* the BD to be used with the current frame */
3249
Li Yanga394f012007-03-06 16:53:46 +08003250 if ((bd == ugeth->txBd[txQ]) && (netif_queue_stopped(dev) == 0))
Li Yangce973b12006-08-14 23:00:11 -07003251 break;
3252
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003253 dev->stats.tx_packets++;
Li Yangce973b12006-08-14 23:00:11 -07003254
Anton Vorontsov50f238f2009-07-07 08:38:42 +00003255 skb = ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]];
3256
3257 if (skb_queue_len(&ugeth->rx_recycle) < RX_BD_RING_LEN &&
3258 skb_recycle_check(skb,
3259 ugeth->ug_info->uf_info.max_rx_buf_length +
3260 UCC_GETH_RX_DATA_BUF_ALIGNMENT))
3261 __skb_queue_head(&ugeth->rx_recycle, skb);
3262 else
3263 dev_kfree_skb(skb);
3264
Li Yangce973b12006-08-14 23:00:11 -07003265 ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL;
3266 ugeth->skb_dirtytx[txQ] =
3267 (ugeth->skb_dirtytx[txQ] +
3268 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
3269
3270 /* We freed a buffer, so now we can restart transmission */
3271 if (netif_queue_stopped(dev))
3272 netif_wake_queue(dev);
3273
3274 /* Advance the confirmation BD pointer */
3275 if (!(bd_status & T_W))
Li Yanga394f012007-03-06 16:53:46 +08003276 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07003277 else
Li Yanga394f012007-03-06 16:53:46 +08003278 bd = ugeth->p_tx_bd_ring[txQ];
Andy Fleming6fee40e2008-05-02 13:01:23 -05003279 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003280 }
Li Yanga394f012007-03-06 16:53:46 +08003281 ugeth->confBd[txQ] = bd;
Li Yangce973b12006-08-14 23:00:11 -07003282 return 0;
3283}
3284
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003285static int ucc_geth_poll(struct napi_struct *napi, int budget)
Li Yangce973b12006-08-14 23:00:11 -07003286{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003287 struct ucc_geth_private *ugeth = container_of(napi, struct ucc_geth_private, napi);
Michael Reiss702ff122007-04-13 01:26:11 -05003288 struct ucc_geth_info *ug_info;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003289 int howmany, i;
Li Yangce973b12006-08-14 23:00:11 -07003290
Michael Reiss702ff122007-04-13 01:26:11 -05003291 ug_info = ugeth->ug_info;
3292
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003293 /* Tx event processing */
3294 spin_lock(&ugeth->lock);
3295 for (i = 0; i < ug_info->numQueuesTx; i++)
3296 ucc_geth_tx(ugeth->ndev, i);
3297 spin_unlock(&ugeth->lock);
3298
Anton Vorontsov50f238f2009-07-07 08:38:42 +00003299 howmany = 0;
3300 for (i = 0; i < ug_info->numQueuesRx; i++)
3301 howmany += ucc_geth_rx(ugeth, i, budget - howmany);
3302
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003303 if (howmany < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08003304 napi_complete(napi);
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003305 setbits32(ugeth->uccf->p_uccm, UCCE_RX_EVENTS | UCCE_TX_EVENTS);
Michael Reiss702ff122007-04-13 01:26:11 -05003306 }
Li Yangce973b12006-08-14 23:00:11 -07003307
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003308 return howmany;
Li Yangce973b12006-08-14 23:00:11 -07003309}
Li Yangce973b12006-08-14 23:00:11 -07003310
David Howells7d12e782006-10-05 14:55:46 +01003311static irqreturn_t ucc_geth_irq_handler(int irq, void *info)
Li Yangce973b12006-08-14 23:00:11 -07003312{
Jeff Garzik06efcad2007-10-19 03:10:11 -04003313 struct net_device *dev = info;
Li Yang18a8e862006-10-19 21:07:34 -05003314 struct ucc_geth_private *ugeth = netdev_priv(dev);
3315 struct ucc_fast_private *uccf;
3316 struct ucc_geth_info *ug_info;
Michael Reiss702ff122007-04-13 01:26:11 -05003317 register u32 ucce;
3318 register u32 uccm;
Li Yangce973b12006-08-14 23:00:11 -07003319
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003320 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003321
Li Yangce973b12006-08-14 23:00:11 -07003322 uccf = ugeth->uccf;
3323 ug_info = ugeth->ug_info;
3324
Michael Reiss702ff122007-04-13 01:26:11 -05003325 /* read and clear events */
3326 ucce = (u32) in_be32(uccf->p_ucce);
3327 uccm = (u32) in_be32(uccf->p_uccm);
3328 ucce &= uccm;
3329 out_be32(uccf->p_ucce, ucce);
Li Yangce973b12006-08-14 23:00:11 -07003330
Michael Reiss702ff122007-04-13 01:26:11 -05003331 /* check for receive events that require processing */
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003332 if (ucce & (UCCE_RX_EVENTS | UCCE_TX_EVENTS)) {
Ben Hutchings288379f2009-01-19 16:43:59 -08003333 if (napi_schedule_prep(&ugeth->napi)) {
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003334 uccm &= ~(UCCE_RX_EVENTS | UCCE_TX_EVENTS);
Michael Reiss702ff122007-04-13 01:26:11 -05003335 out_be32(uccf->p_uccm, uccm);
Ben Hutchings288379f2009-01-19 16:43:59 -08003336 __napi_schedule(&ugeth->napi);
Li Yangce973b12006-08-14 23:00:11 -07003337 }
Michael Reiss702ff122007-04-13 01:26:11 -05003338 }
Li Yangce973b12006-08-14 23:00:11 -07003339
Michael Reiss702ff122007-04-13 01:26:11 -05003340 /* Errors and other events */
3341 if (ucce & UCCE_OTHER) {
Timur Tabi3bc53422009-01-11 00:25:21 -08003342 if (ucce & UCC_GETH_UCCE_BSY)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003343 dev->stats.rx_errors++;
Timur Tabi3bc53422009-01-11 00:25:21 -08003344 if (ucce & UCC_GETH_UCCE_TXE)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003345 dev->stats.tx_errors++;
Li Yangce973b12006-08-14 23:00:11 -07003346 }
Li Yangce973b12006-08-14 23:00:11 -07003347
3348 return IRQ_HANDLED;
3349}
3350
Anton Vorontsov26d29ea2008-02-01 16:22:54 +03003351#ifdef CONFIG_NET_POLL_CONTROLLER
3352/*
3353 * Polling 'interrupt' - used by things like netconsole to send skbs
3354 * without having to re-enable interrupts. It's not called while
3355 * the interrupt routine is executing.
3356 */
3357static void ucc_netpoll(struct net_device *dev)
3358{
3359 struct ucc_geth_private *ugeth = netdev_priv(dev);
3360 int irq = ugeth->ug_info->uf_info.irq;
3361
3362 disable_irq(irq);
3363 ucc_geth_irq_handler(irq, dev);
3364 enable_irq(irq);
3365}
3366#endif /* CONFIG_NET_POLL_CONTROLLER */
3367
Kevin Hao3d6593e2009-05-26 20:49:03 -07003368static int ucc_geth_set_mac_addr(struct net_device *dev, void *p)
3369{
3370 struct ucc_geth_private *ugeth = netdev_priv(dev);
3371 struct sockaddr *addr = p;
3372
3373 if (!is_valid_ether_addr(addr->sa_data))
3374 return -EADDRNOTAVAIL;
3375
3376 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3377
3378 /*
3379 * If device is not running, we will set mac addr register
3380 * when opening the device.
3381 */
3382 if (!netif_running(dev))
3383 return 0;
3384
3385 spin_lock_irq(&ugeth->lock);
3386 init_mac_station_addr_regs(dev->dev_addr[0],
3387 dev->dev_addr[1],
3388 dev->dev_addr[2],
3389 dev->dev_addr[3],
3390 dev->dev_addr[4],
3391 dev->dev_addr[5],
3392 &ugeth->ug_regs->macstnaddr1,
3393 &ugeth->ug_regs->macstnaddr2);
3394 spin_unlock_irq(&ugeth->lock);
3395
3396 return 0;
3397}
3398
Anton Vorontsov54b15982009-08-27 07:35:54 +00003399static int ucc_geth_init_mac(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07003400{
Anton Vorontsov54b15982009-08-27 07:35:54 +00003401 struct net_device *dev = ugeth->ndev;
Li Yangce973b12006-08-14 23:00:11 -07003402 int err;
3403
Kim Phillips728de4c92007-04-13 01:26:03 -05003404 err = ucc_struct_init(ugeth);
3405 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003406 if (netif_msg_ifup(ugeth))
Anton Vorontsov54b15982009-08-27 07:35:54 +00003407 ugeth_err("%s: Cannot configure internal struct, "
3408 "aborting.", dev->name);
3409 goto err;
Kim Phillips728de4c92007-04-13 01:26:03 -05003410 }
3411
Li Yangce973b12006-08-14 23:00:11 -07003412 err = ucc_geth_startup(ugeth);
3413 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003414 if (netif_msg_ifup(ugeth))
3415 ugeth_err("%s: Cannot configure net device, aborting.",
3416 dev->name);
Anton Vorontsov54b15982009-08-27 07:35:54 +00003417 goto err;
Li Yangce973b12006-08-14 23:00:11 -07003418 }
3419
3420 err = adjust_enet_interface(ugeth);
3421 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003422 if (netif_msg_ifup(ugeth))
3423 ugeth_err("%s: Cannot configure net device, aborting.",
3424 dev->name);
Anton Vorontsov54b15982009-08-27 07:35:54 +00003425 goto err;
Li Yangce973b12006-08-14 23:00:11 -07003426 }
3427
3428 /* Set MACSTNADDR1, MACSTNADDR2 */
3429 /* For more details see the hardware spec. */
3430 init_mac_station_addr_regs(dev->dev_addr[0],
3431 dev->dev_addr[1],
3432 dev->dev_addr[2],
3433 dev->dev_addr[3],
3434 dev->dev_addr[4],
3435 dev->dev_addr[5],
3436 &ugeth->ug_regs->macstnaddr1,
3437 &ugeth->ug_regs->macstnaddr2);
3438
Li Yangce973b12006-08-14 23:00:11 -07003439 err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
3440 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003441 if (netif_msg_ifup(ugeth))
3442 ugeth_err("%s: Cannot enable net device, aborting.", dev->name);
Anton Vorontsov54b15982009-08-27 07:35:54 +00003443 goto err;
3444 }
3445
3446 return 0;
3447err:
3448 ucc_geth_stop(ugeth);
3449 return err;
3450}
3451
3452/* Called when something needs to use the ethernet device */
3453/* Returns 0 for success. */
3454static int ucc_geth_open(struct net_device *dev)
3455{
3456 struct ucc_geth_private *ugeth = netdev_priv(dev);
3457 int err;
3458
3459 ugeth_vdbg("%s: IN", __func__);
3460
3461 /* Test station address */
3462 if (dev->dev_addr[0] & ENET_GROUP_ADDR) {
3463 if (netif_msg_ifup(ugeth))
3464 ugeth_err("%s: Multicast address used for station "
3465 "address - is this what you wanted?",
3466 __func__);
3467 return -EINVAL;
3468 }
3469
3470 err = init_phy(dev);
3471 if (err) {
3472 if (netif_msg_ifup(ugeth))
3473 ugeth_err("%s: Cannot initialize PHY, aborting.",
3474 dev->name);
3475 return err;
3476 }
3477
3478 err = ucc_geth_init_mac(ugeth);
3479 if (err) {
3480 if (netif_msg_ifup(ugeth))
3481 ugeth_err("%s: Cannot initialize MAC, aborting.",
3482 dev->name);
3483 goto err;
Li Yangce973b12006-08-14 23:00:11 -07003484 }
3485
Anton Vorontsov67c2fb82008-12-18 08:23:29 +00003486 err = request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler,
3487 0, "UCC Geth", dev);
3488 if (err) {
3489 if (netif_msg_ifup(ugeth))
3490 ugeth_err("%s: Cannot get IRQ for net device, aborting.",
3491 dev->name);
Anton Vorontsov54b15982009-08-27 07:35:54 +00003492 goto err;
Anton Vorontsov67c2fb82008-12-18 08:23:29 +00003493 }
3494
Anton Vorontsov54b15982009-08-27 07:35:54 +00003495 phy_start(ugeth->phydev);
3496 napi_enable(&ugeth->napi);
Li Yangce973b12006-08-14 23:00:11 -07003497 netif_start_queue(dev);
3498
Anton Vorontsov23949052009-08-27 07:35:57 +00003499 device_set_wakeup_capable(&dev->dev,
3500 qe_alive_during_sleep() || ugeth->phydev->irq);
3501 device_set_wakeup_enable(&dev->dev, ugeth->wol_en);
3502
Li Yangce973b12006-08-14 23:00:11 -07003503 return err;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003504
Anton Vorontsov54b15982009-08-27 07:35:54 +00003505err:
Anton Vorontsovba574692008-12-18 08:23:31 +00003506 ucc_geth_stop(ugeth);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003507 return err;
Li Yangce973b12006-08-14 23:00:11 -07003508}
3509
3510/* Stops the kernel queue, and halts the controller */
3511static int ucc_geth_close(struct net_device *dev)
3512{
Li Yang18a8e862006-10-19 21:07:34 -05003513 struct ucc_geth_private *ugeth = netdev_priv(dev);
Li Yangce973b12006-08-14 23:00:11 -07003514
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003515 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003516
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003517 napi_disable(&ugeth->napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003518
Li Yangce973b12006-08-14 23:00:11 -07003519 ucc_geth_stop(ugeth);
3520
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003521 free_irq(ugeth->ug_info->uf_info.irq, ugeth->ndev);
Anton Vorontsov67c2fb82008-12-18 08:23:29 +00003522
Li Yangce973b12006-08-14 23:00:11 -07003523 netif_stop_queue(dev);
3524
3525 return 0;
3526}
3527
Anton Vorontsovfdb614c2008-12-23 06:59:25 +00003528/* Reopen device. This will reset the MAC and PHY. */
3529static void ucc_geth_timeout_work(struct work_struct *work)
3530{
3531 struct ucc_geth_private *ugeth;
3532 struct net_device *dev;
3533
3534 ugeth = container_of(work, struct ucc_geth_private, timeout_work);
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003535 dev = ugeth->ndev;
Anton Vorontsovfdb614c2008-12-23 06:59:25 +00003536
3537 ugeth_vdbg("%s: IN", __func__);
3538
3539 dev->stats.tx_errors++;
3540
3541 ugeth_dump_regs(ugeth);
3542
3543 if (dev->flags & IFF_UP) {
3544 /*
3545 * Must reset MAC *and* PHY. This is done by reopening
3546 * the device.
3547 */
3548 ucc_geth_close(dev);
3549 ucc_geth_open(dev);
3550 }
3551
3552 netif_tx_schedule_all(dev);
3553}
3554
3555/*
3556 * ucc_geth_timeout gets called when a packet has not been
3557 * transmitted after a set amount of time.
3558 */
3559static void ucc_geth_timeout(struct net_device *dev)
3560{
3561 struct ucc_geth_private *ugeth = netdev_priv(dev);
3562
3563 netif_carrier_off(dev);
3564 schedule_work(&ugeth->timeout_work);
3565}
3566
Anton Vorontsov23949052009-08-27 07:35:57 +00003567
3568#ifdef CONFIG_PM
3569
3570static int ucc_geth_suspend(struct of_device *ofdev, pm_message_t state)
3571{
3572 struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
3573 struct ucc_geth_private *ugeth = netdev_priv(ndev);
3574
3575 if (!netif_running(ndev))
3576 return 0;
3577
3578 napi_disable(&ugeth->napi);
3579
3580 /*
3581 * Disable the controller, otherwise we'll wakeup on any network
3582 * activity.
3583 */
3584 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
3585
3586 if (ugeth->wol_en & WAKE_MAGIC) {
3587 setbits32(ugeth->uccf->p_uccm, UCC_GETH_UCCE_MPD);
3588 setbits32(&ugeth->ug_regs->maccfg2, MACCFG2_MPE);
3589 ucc_fast_enable(ugeth->uccf, COMM_DIR_RX_AND_TX);
3590 } else if (!(ugeth->wol_en & WAKE_PHY)) {
3591 phy_stop(ugeth->phydev);
3592 }
3593
3594 return 0;
3595}
3596
3597static int ucc_geth_resume(struct of_device *ofdev)
3598{
3599 struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
3600 struct ucc_geth_private *ugeth = netdev_priv(ndev);
3601 int err;
3602
3603 if (!netif_running(ndev))
3604 return 0;
3605
3606 if (qe_alive_during_sleep()) {
3607 if (ugeth->wol_en & WAKE_MAGIC) {
3608 ucc_fast_disable(ugeth->uccf, COMM_DIR_RX_AND_TX);
3609 clrbits32(&ugeth->ug_regs->maccfg2, MACCFG2_MPE);
3610 clrbits32(ugeth->uccf->p_uccm, UCC_GETH_UCCE_MPD);
3611 }
3612 ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
3613 } else {
3614 /*
3615 * Full reinitialization is required if QE shuts down
3616 * during sleep.
3617 */
3618 ucc_geth_memclean(ugeth);
3619
3620 err = ucc_geth_init_mac(ugeth);
3621 if (err) {
3622 ugeth_err("%s: Cannot initialize MAC, aborting.",
3623 ndev->name);
3624 return err;
3625 }
3626 }
3627
3628 ugeth->oldlink = 0;
3629 ugeth->oldspeed = 0;
3630 ugeth->oldduplex = -1;
3631
3632 phy_stop(ugeth->phydev);
3633 phy_start(ugeth->phydev);
3634
3635 napi_enable(&ugeth->napi);
3636 netif_start_queue(ndev);
3637
3638 return 0;
3639}
3640
3641#else
3642#define ucc_geth_suspend NULL
3643#define ucc_geth_resume NULL
3644#endif
3645
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003646static phy_interface_t to_phy_interface(const char *phy_connection_type)
Kim Phillips728de4c92007-04-13 01:26:03 -05003647{
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003648 if (strcasecmp(phy_connection_type, "mii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003649 return PHY_INTERFACE_MODE_MII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003650 if (strcasecmp(phy_connection_type, "gmii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003651 return PHY_INTERFACE_MODE_GMII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003652 if (strcasecmp(phy_connection_type, "tbi") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003653 return PHY_INTERFACE_MODE_TBI;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003654 if (strcasecmp(phy_connection_type, "rmii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003655 return PHY_INTERFACE_MODE_RMII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003656 if (strcasecmp(phy_connection_type, "rgmii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003657 return PHY_INTERFACE_MODE_RGMII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003658 if (strcasecmp(phy_connection_type, "rgmii-id") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003659 return PHY_INTERFACE_MODE_RGMII_ID;
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06003660 if (strcasecmp(phy_connection_type, "rgmii-txid") == 0)
3661 return PHY_INTERFACE_MODE_RGMII_TXID;
3662 if (strcasecmp(phy_connection_type, "rgmii-rxid") == 0)
3663 return PHY_INTERFACE_MODE_RGMII_RXID;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003664 if (strcasecmp(phy_connection_type, "rtbi") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003665 return PHY_INTERFACE_MODE_RTBI;
Haiying Wang047584c2009-06-02 04:04:15 +00003666 if (strcasecmp(phy_connection_type, "sgmii") == 0)
3667 return PHY_INTERFACE_MODE_SGMII;
Kim Phillips728de4c92007-04-13 01:26:03 -05003668
3669 return PHY_INTERFACE_MODE_MII;
3670}
3671
Joakim Tjernlunda9dbae72009-03-20 21:09:14 +01003672static const struct net_device_ops ucc_geth_netdev_ops = {
3673 .ndo_open = ucc_geth_open,
3674 .ndo_stop = ucc_geth_close,
3675 .ndo_start_xmit = ucc_geth_start_xmit,
3676 .ndo_validate_addr = eth_validate_addr,
Kevin Hao3d6593e2009-05-26 20:49:03 -07003677 .ndo_set_mac_address = ucc_geth_set_mac_addr,
Joakim Tjernlunda9dbae72009-03-20 21:09:14 +01003678 .ndo_change_mtu = eth_change_mtu,
3679 .ndo_set_multicast_list = ucc_geth_set_multi,
3680 .ndo_tx_timeout = ucc_geth_timeout,
3681#ifdef CONFIG_NET_POLL_CONTROLLER
3682 .ndo_poll_controller = ucc_netpoll,
3683#endif
3684};
3685
Li Yang18a8e862006-10-19 21:07:34 -05003686static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *match)
Li Yangce973b12006-08-14 23:00:11 -07003687{
Li Yang18a8e862006-10-19 21:07:34 -05003688 struct device *device = &ofdev->dev;
3689 struct device_node *np = ofdev->node;
Li Yangce973b12006-08-14 23:00:11 -07003690 struct net_device *dev = NULL;
3691 struct ucc_geth_private *ugeth = NULL;
3692 struct ucc_geth_info *ug_info;
Li Yang18a8e862006-10-19 21:07:34 -05003693 struct resource res;
Kim Phillips728de4c92007-04-13 01:26:03 -05003694 int err, ucc_num, max_speed = 0;
Li Yang18a8e862006-10-19 21:07:34 -05003695 const unsigned int *prop;
Timur Tabi9fb1e352007-12-03 15:17:59 -06003696 const char *sprop;
Li Yang9b4c7a42007-02-08 17:35:54 +08003697 const void *mac_addr;
Kim Phillips728de4c92007-04-13 01:26:03 -05003698 phy_interface_t phy_interface;
3699 static const int enet_to_speed[] = {
3700 SPEED_10, SPEED_10, SPEED_10,
3701 SPEED_100, SPEED_100, SPEED_100,
3702 SPEED_1000, SPEED_1000, SPEED_1000, SPEED_1000,
3703 };
3704 static const phy_interface_t enet_to_phy_interface[] = {
3705 PHY_INTERFACE_MODE_MII, PHY_INTERFACE_MODE_RMII,
3706 PHY_INTERFACE_MODE_RGMII, PHY_INTERFACE_MODE_MII,
3707 PHY_INTERFACE_MODE_RMII, PHY_INTERFACE_MODE_RGMII,
3708 PHY_INTERFACE_MODE_GMII, PHY_INTERFACE_MODE_RGMII,
3709 PHY_INTERFACE_MODE_TBI, PHY_INTERFACE_MODE_RTBI,
Haiying Wang047584c2009-06-02 04:04:15 +00003710 PHY_INTERFACE_MODE_SGMII,
Kim Phillips728de4c92007-04-13 01:26:03 -05003711 };
Li Yangce973b12006-08-14 23:00:11 -07003712
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003713 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003714
Anton Vorontsov56626f32008-04-11 20:06:54 +04003715 prop = of_get_property(np, "cell-index", NULL);
3716 if (!prop) {
3717 prop = of_get_property(np, "device-id", NULL);
3718 if (!prop)
3719 return -ENODEV;
3720 }
3721
Li Yang18a8e862006-10-19 21:07:34 -05003722 ucc_num = *prop - 1;
3723 if ((ucc_num < 0) || (ucc_num > 7))
3724 return -ENODEV;
Li Yangce973b12006-08-14 23:00:11 -07003725
Li Yang18a8e862006-10-19 21:07:34 -05003726 ug_info = &ugeth_info[ucc_num];
Li Yang890de952007-07-19 11:48:29 +08003727 if (ug_info == NULL) {
3728 if (netif_msg_probe(&debug))
3729 ugeth_err("%s: [%d] Missing additional data!",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003730 __func__, ucc_num);
Li Yang890de952007-07-19 11:48:29 +08003731 return -ENODEV;
3732 }
3733
Li Yang18a8e862006-10-19 21:07:34 -05003734 ug_info->uf_info.ucc_num = ucc_num;
Kim Phillips728de4c92007-04-13 01:26:03 -05003735
Timur Tabi9fb1e352007-12-03 15:17:59 -06003736 sprop = of_get_property(np, "rx-clock-name", NULL);
3737 if (sprop) {
3738 ug_info->uf_info.rx_clock = qe_clock_source(sprop);
3739 if ((ug_info->uf_info.rx_clock < QE_CLK_NONE) ||
3740 (ug_info->uf_info.rx_clock > QE_CLK24)) {
3741 printk(KERN_ERR
3742 "ucc_geth: invalid rx-clock-name property\n");
3743 return -EINVAL;
3744 }
3745 } else {
3746 prop = of_get_property(np, "rx-clock", NULL);
3747 if (!prop) {
3748 /* If both rx-clock-name and rx-clock are missing,
3749 we want to tell people to use rx-clock-name. */
3750 printk(KERN_ERR
3751 "ucc_geth: missing rx-clock-name property\n");
3752 return -EINVAL;
3753 }
3754 if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
3755 printk(KERN_ERR
3756 "ucc_geth: invalid rx-clock propperty\n");
3757 return -EINVAL;
3758 }
3759 ug_info->uf_info.rx_clock = *prop;
3760 }
3761
3762 sprop = of_get_property(np, "tx-clock-name", NULL);
3763 if (sprop) {
3764 ug_info->uf_info.tx_clock = qe_clock_source(sprop);
3765 if ((ug_info->uf_info.tx_clock < QE_CLK_NONE) ||
3766 (ug_info->uf_info.tx_clock > QE_CLK24)) {
3767 printk(KERN_ERR
3768 "ucc_geth: invalid tx-clock-name property\n");
3769 return -EINVAL;
3770 }
3771 } else {
Joakim Tjernlunde4105532008-04-29 13:03:57 +02003772 prop = of_get_property(np, "tx-clock", NULL);
Timur Tabi9fb1e352007-12-03 15:17:59 -06003773 if (!prop) {
3774 printk(KERN_ERR
3775 "ucc_geth: mising tx-clock-name property\n");
3776 return -EINVAL;
3777 }
3778 if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
3779 printk(KERN_ERR
3780 "ucc_geth: invalid tx-clock property\n");
3781 return -EINVAL;
3782 }
3783 ug_info->uf_info.tx_clock = *prop;
3784 }
3785
Li Yang18a8e862006-10-19 21:07:34 -05003786 err = of_address_to_resource(np, 0, &res);
3787 if (err)
3788 return -EINVAL;
3789
3790 ug_info->uf_info.regs = res.start;
3791 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
Anton Vorontsov3104a6f2009-07-16 21:31:47 +00003792
3793 ug_info->phy_node = of_parse_phandle(np, "phy-handle", 0);
Kim Phillips728de4c92007-04-13 01:26:03 -05003794
Haiying Wangfb1001f2009-06-17 13:16:10 +00003795 /* Find the TBI PHY node. If it's not there, we don't support SGMII */
3796 ug_info->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
3797
Kim Phillips728de4c92007-04-13 01:26:03 -05003798 /* get the phy interface type, or default to MII */
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003799 prop = of_get_property(np, "phy-connection-type", NULL);
Kim Phillips728de4c92007-04-13 01:26:03 -05003800 if (!prop) {
3801 /* handle interface property present in old trees */
Anton Vorontsov3104a6f2009-07-16 21:31:47 +00003802 prop = of_get_property(ug_info->phy_node, "interface", NULL);
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003803 if (prop != NULL) {
Kim Phillips728de4c92007-04-13 01:26:03 -05003804 phy_interface = enet_to_phy_interface[*prop];
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003805 max_speed = enet_to_speed[*prop];
3806 } else
Kim Phillips728de4c92007-04-13 01:26:03 -05003807 phy_interface = PHY_INTERFACE_MODE_MII;
3808 } else {
3809 phy_interface = to_phy_interface((const char *)prop);
3810 }
3811
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003812 /* get speed, or derive from PHY interface */
3813 if (max_speed == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003814 switch (phy_interface) {
3815 case PHY_INTERFACE_MODE_GMII:
3816 case PHY_INTERFACE_MODE_RGMII:
3817 case PHY_INTERFACE_MODE_RGMII_ID:
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06003818 case PHY_INTERFACE_MODE_RGMII_RXID:
3819 case PHY_INTERFACE_MODE_RGMII_TXID:
Kim Phillips728de4c92007-04-13 01:26:03 -05003820 case PHY_INTERFACE_MODE_TBI:
3821 case PHY_INTERFACE_MODE_RTBI:
Haiying Wang047584c2009-06-02 04:04:15 +00003822 case PHY_INTERFACE_MODE_SGMII:
Kim Phillips728de4c92007-04-13 01:26:03 -05003823 max_speed = SPEED_1000;
3824 break;
3825 default:
3826 max_speed = SPEED_100;
3827 break;
3828 }
Kim Phillips728de4c92007-04-13 01:26:03 -05003829
3830 if (max_speed == SPEED_1000) {
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003831 /* configure muram FIFOs for gigabit operation */
Kim Phillips728de4c92007-04-13 01:26:03 -05003832 ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT;
3833 ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT;
3834 ug_info->uf_info.urfset = UCC_GETH_URFSET_GIGA_INIT;
3835 ug_info->uf_info.utfs = UCC_GETH_UTFS_GIGA_INIT;
3836 ug_info->uf_info.utfet = UCC_GETH_UTFET_GIGA_INIT;
3837 ug_info->uf_info.utftt = UCC_GETH_UTFTT_GIGA_INIT;
Joakim Tjernlundffea31e2008-03-06 18:48:46 +08003838 ug_info->numThreadsTx = UCC_GETH_NUM_OF_THREADS_4;
Haiying Wang674e4f92009-05-01 15:40:49 -04003839
3840 /* If QE's snum number is 46 which means we need to support
3841 * 4 UECs at 1000Base-T simultaneously, we need to allocate
3842 * more Threads to Rx.
3843 */
3844 if (qe_get_num_of_snums() == 46)
3845 ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_6;
3846 else
3847 ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_4;
Kim Phillips728de4c92007-04-13 01:26:03 -05003848 }
3849
Li Yang890de952007-07-19 11:48:29 +08003850 if (netif_msg_probe(&debug))
3851 printk(KERN_INFO "ucc_geth: UCC%1d at 0x%8x (irq = %d) \n",
3852 ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs,
3853 ug_info->uf_info.irq);
Li Yangce973b12006-08-14 23:00:11 -07003854
Li Yangce973b12006-08-14 23:00:11 -07003855 /* Create an ethernet device instance */
3856 dev = alloc_etherdev(sizeof(*ugeth));
3857
3858 if (dev == NULL)
3859 return -ENOMEM;
3860
3861 ugeth = netdev_priv(dev);
3862 spin_lock_init(&ugeth->lock);
3863
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03003864 /* Create CQs for hash tables */
3865 INIT_LIST_HEAD(&ugeth->group_hash_q);
3866 INIT_LIST_HEAD(&ugeth->ind_hash_q);
3867
Li Yangce973b12006-08-14 23:00:11 -07003868 dev_set_drvdata(device, dev);
3869
3870 /* Set the dev->base_addr to the gfar reg region */
3871 dev->base_addr = (unsigned long)(ug_info->uf_info.regs);
3872
Li Yangce973b12006-08-14 23:00:11 -07003873 SET_NETDEV_DEV(dev, device);
3874
3875 /* Fill in the dev structure */
Li Yangac421852007-07-19 11:47:47 +08003876 uec_set_ethtool_ops(dev);
Joakim Tjernlunda9dbae72009-03-20 21:09:14 +01003877 dev->netdev_ops = &ucc_geth_netdev_ops;
Li Yangce973b12006-08-14 23:00:11 -07003878 dev->watchdog_timeo = TX_TIMEOUT;
Anton Vorontsov1762a292008-12-18 08:23:26 +00003879 INIT_WORK(&ugeth->timeout_work, ucc_geth_timeout_work);
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003880 netif_napi_add(dev, &ugeth->napi, ucc_geth_poll, 64);
Li Yangce973b12006-08-14 23:00:11 -07003881 dev->mtu = 1500;
Li Yangce973b12006-08-14 23:00:11 -07003882
Li Yang890de952007-07-19 11:48:29 +08003883 ugeth->msg_enable = netif_msg_init(debug.msg_enable, UGETH_MSG_DEFAULT);
Kim Phillips728de4c92007-04-13 01:26:03 -05003884 ugeth->phy_interface = phy_interface;
3885 ugeth->max_speed = max_speed;
3886
Li Yangce973b12006-08-14 23:00:11 -07003887 err = register_netdev(dev);
3888 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003889 if (netif_msg_probe(ugeth))
3890 ugeth_err("%s: Cannot register net device, aborting.",
3891 dev->name);
Li Yangce973b12006-08-14 23:00:11 -07003892 free_netdev(dev);
3893 return err;
3894 }
3895
Timur Tabie9eb70c2007-02-21 14:40:12 -06003896 mac_addr = of_get_mac_address(np);
Li Yang9b4c7a42007-02-08 17:35:54 +08003897 if (mac_addr)
3898 memcpy(dev->dev_addr, mac_addr, 6);
Li Yangce973b12006-08-14 23:00:11 -07003899
Kim Phillips728de4c92007-04-13 01:26:03 -05003900 ugeth->ug_info = ug_info;
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003901 ugeth->dev = device;
3902 ugeth->ndev = dev;
Haiying Wangb1c4a9dd2009-01-29 17:28:04 -08003903 ugeth->node = np;
Kim Phillips728de4c92007-04-13 01:26:03 -05003904
Li Yangce973b12006-08-14 23:00:11 -07003905 return 0;
3906}
3907
Li Yang18a8e862006-10-19 21:07:34 -05003908static int ucc_geth_remove(struct of_device* ofdev)
Li Yangce973b12006-08-14 23:00:11 -07003909{
Li Yang18a8e862006-10-19 21:07:34 -05003910 struct device *device = &ofdev->dev;
Li Yangce973b12006-08-14 23:00:11 -07003911 struct net_device *dev = dev_get_drvdata(device);
3912 struct ucc_geth_private *ugeth = netdev_priv(dev);
3913
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03003914 unregister_netdev(dev);
Li Yangce973b12006-08-14 23:00:11 -07003915 free_netdev(dev);
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03003916 ucc_geth_memclean(ugeth);
3917 dev_set_drvdata(device, NULL);
Li Yangce973b12006-08-14 23:00:11 -07003918
3919 return 0;
3920}
3921
Li Yang18a8e862006-10-19 21:07:34 -05003922static struct of_device_id ucc_geth_match[] = {
3923 {
3924 .type = "network",
3925 .compatible = "ucc_geth",
3926 },
3927 {},
3928};
3929
3930MODULE_DEVICE_TABLE(of, ucc_geth_match);
3931
3932static struct of_platform_driver ucc_geth_driver = {
3933 .name = DRV_NAME,
3934 .match_table = ucc_geth_match,
3935 .probe = ucc_geth_probe,
3936 .remove = ucc_geth_remove,
Anton Vorontsov23949052009-08-27 07:35:57 +00003937 .suspend = ucc_geth_suspend,
3938 .resume = ucc_geth_resume,
Li Yangce973b12006-08-14 23:00:11 -07003939};
3940
3941static int __init ucc_geth_init(void)
3942{
Kim Phillips728de4c92007-04-13 01:26:03 -05003943 int i, ret;
3944
Li Yang890de952007-07-19 11:48:29 +08003945 if (netif_msg_drv(&debug))
3946 printk(KERN_INFO "ucc_geth: " DRV_DESC "\n");
Li Yangce973b12006-08-14 23:00:11 -07003947 for (i = 0; i < 8; i++)
3948 memcpy(&(ugeth_info[i]), &ugeth_primary_info,
3949 sizeof(ugeth_primary_info));
3950
Kim Phillips728de4c92007-04-13 01:26:03 -05003951 ret = of_register_platform_driver(&ucc_geth_driver);
3952
Kim Phillips728de4c92007-04-13 01:26:03 -05003953 return ret;
Li Yangce973b12006-08-14 23:00:11 -07003954}
3955
3956static void __exit ucc_geth_exit(void)
3957{
Kim Phillipsa4f0c2c2006-11-15 12:29:35 -06003958 of_unregister_platform_driver(&ucc_geth_driver);
Li Yangce973b12006-08-14 23:00:11 -07003959}
3960
3961module_init(ucc_geth_init);
3962module_exit(ucc_geth_exit);
3963
3964MODULE_AUTHOR("Freescale Semiconductor, Inc");
3965MODULE_DESCRIPTION(DRV_DESC);
Kim Phillipsc2bcf002007-04-13 01:26:36 -05003966MODULE_VERSION(DRV_VERSION);
Li Yangce973b12006-08-14 23:00:11 -07003967MODULE_LICENSE("GPL");