blob: a110326dce6f8682d24206fec681a03a0084ab59 [file] [log] [blame]
Li Yangce973b12006-08-14 23:00:11 -07001/*
Kim Phillips4e19b5c2007-05-11 18:25:07 -05002 * Copyright (C) 2006-2007 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>
27#include <linux/fsl_devices.h>
Li Yangce973b12006-08-14 23:00:11 -070028#include <linux/mii.h>
Kim Phillips728de4c92007-04-13 01:26:03 -050029#include <linux/phy.h>
Timur Tabidf19b6b2007-01-09 12:31:38 -060030#include <linux/workqueue.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
212 skb = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length +
213 UCC_GETH_RX_DATA_BUF_ALIGNMENT);
214
215 if (skb == NULL)
216 return NULL;
217
218 /* We need the data buffer to be aligned properly. We will reserve
219 * as many bytes as needed to align the data properly
220 */
221 skb_reserve(skb,
222 UCC_GETH_RX_DATA_BUF_ALIGNMENT -
223 (((unsigned)skb->data) & (UCC_GETH_RX_DATA_BUF_ALIGNMENT -
224 1)));
225
226 skb->dev = ugeth->dev;
227
Andy Fleming6fee40e2008-05-02 13:01:23 -0500228 out_be32(&((struct qe_bd __iomem *)bd)->buf,
Andy Fleming7f802022008-05-15 17:00:21 -0500229 dma_map_single(&ugeth->dev->dev,
Li Yangce973b12006-08-14 23:00:11 -0700230 skb->data,
231 ugeth->ug_info->uf_info.max_rx_buf_length +
232 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
233 DMA_FROM_DEVICE));
234
Andy Fleming6fee40e2008-05-02 13:01:23 -0500235 out_be32((u32 __iomem *)bd,
236 (R_E | R_I | (in_be32((u32 __iomem*)bd) & R_W)));
Li Yangce973b12006-08-14 23:00:11 -0700237
238 return skb;
239}
240
Li Yang18a8e862006-10-19 21:07:34 -0500241static int rx_bd_buffer_set(struct ucc_geth_private *ugeth, u8 rxQ)
Li Yangce973b12006-08-14 23:00:11 -0700242{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500243 u8 __iomem *bd;
Li Yangce973b12006-08-14 23:00:11 -0700244 u32 bd_status;
245 struct sk_buff *skb;
246 int i;
247
248 bd = ugeth->p_rx_bd_ring[rxQ];
249 i = 0;
250
251 do {
Andy Fleming6fee40e2008-05-02 13:01:23 -0500252 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -0700253 skb = get_new_skb(ugeth, bd);
254
255 if (!skb) /* If can not allocate data buffer,
256 abort. Cleanup will be elsewhere */
257 return -ENOMEM;
258
259 ugeth->rx_skbuff[rxQ][i] = skb;
260
261 /* advance the BD pointer */
Li Yang18a8e862006-10-19 21:07:34 -0500262 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -0700263 i++;
264 } while (!(bd_status & R_W));
265
266 return 0;
267}
268
Li Yang18a8e862006-10-19 21:07:34 -0500269static int fill_init_enet_entries(struct ucc_geth_private *ugeth,
Andy Fleming6fee40e2008-05-02 13:01:23 -0500270 u32 *p_start,
Li Yangce973b12006-08-14 23:00:11 -0700271 u8 num_entries,
272 u32 thread_size,
273 u32 thread_alignment,
Li Yang18a8e862006-10-19 21:07:34 -0500274 enum qe_risc_allocation risc,
Li Yangce973b12006-08-14 23:00:11 -0700275 int skip_page_for_first_entry)
276{
277 u32 init_enet_offset;
278 u8 i;
279 int snum;
280
281 for (i = 0; i < num_entries; i++) {
282 if ((snum = qe_get_snum()) < 0) {
Li Yang890de952007-07-19 11:48:29 +0800283 if (netif_msg_ifup(ugeth))
284 ugeth_err("fill_init_enet_entries: Can not get SNUM.");
Li Yangce973b12006-08-14 23:00:11 -0700285 return snum;
286 }
287 if ((i == 0) && skip_page_for_first_entry)
288 /* First entry of Rx does not have page */
289 init_enet_offset = 0;
290 else {
291 init_enet_offset =
292 qe_muram_alloc(thread_size, thread_alignment);
Timur Tabi4c356302007-05-08 14:46:36 -0500293 if (IS_ERR_VALUE(init_enet_offset)) {
Li Yang890de952007-07-19 11:48:29 +0800294 if (netif_msg_ifup(ugeth))
295 ugeth_err("fill_init_enet_entries: Can not allocate DPRAM memory.");
Li Yangce973b12006-08-14 23:00:11 -0700296 qe_put_snum((u8) snum);
297 return -ENOMEM;
298 }
299 }
300 *(p_start++) =
301 ((u8) snum << ENET_INIT_PARAM_SNUM_SHIFT) | init_enet_offset
302 | risc;
303 }
304
305 return 0;
306}
307
Li Yang18a8e862006-10-19 21:07:34 -0500308static int return_init_enet_entries(struct ucc_geth_private *ugeth,
Andy Fleming6fee40e2008-05-02 13:01:23 -0500309 u32 *p_start,
Li Yangce973b12006-08-14 23:00:11 -0700310 u8 num_entries,
Li Yang18a8e862006-10-19 21:07:34 -0500311 enum qe_risc_allocation risc,
Li Yangce973b12006-08-14 23:00:11 -0700312 int skip_page_for_first_entry)
313{
314 u32 init_enet_offset;
315 u8 i;
316 int snum;
317
318 for (i = 0; i < num_entries; i++) {
Andy Fleming6fee40e2008-05-02 13:01:23 -0500319 u32 val = *p_start;
320
Li Yangce973b12006-08-14 23:00:11 -0700321 /* Check that this entry was actually valid --
322 needed in case failed in allocations */
Andy Fleming6fee40e2008-05-02 13:01:23 -0500323 if ((val & ENET_INIT_PARAM_RISC_MASK) == risc) {
Li Yangce973b12006-08-14 23:00:11 -0700324 snum =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500325 (u32) (val & ENET_INIT_PARAM_SNUM_MASK) >>
Li Yangce973b12006-08-14 23:00:11 -0700326 ENET_INIT_PARAM_SNUM_SHIFT;
327 qe_put_snum((u8) snum);
328 if (!((i == 0) && skip_page_for_first_entry)) {
329 /* First entry of Rx does not have page */
330 init_enet_offset =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500331 (val & ENET_INIT_PARAM_PTR_MASK);
Li Yangce973b12006-08-14 23:00:11 -0700332 qe_muram_free(init_enet_offset);
333 }
Andy Fleming6fee40e2008-05-02 13:01:23 -0500334 *p_start++ = 0;
Li Yangce973b12006-08-14 23:00:11 -0700335 }
336 }
337
338 return 0;
339}
340
341#ifdef DEBUG
Li Yang18a8e862006-10-19 21:07:34 -0500342static int dump_init_enet_entries(struct ucc_geth_private *ugeth,
Andy Fleming6fee40e2008-05-02 13:01:23 -0500343 u32 __iomem *p_start,
Li Yangce973b12006-08-14 23:00:11 -0700344 u8 num_entries,
345 u32 thread_size,
Li Yang18a8e862006-10-19 21:07:34 -0500346 enum qe_risc_allocation risc,
Li Yangce973b12006-08-14 23:00:11 -0700347 int skip_page_for_first_entry)
348{
349 u32 init_enet_offset;
350 u8 i;
351 int snum;
352
353 for (i = 0; i < num_entries; i++) {
Andy Fleming6fee40e2008-05-02 13:01:23 -0500354 u32 val = in_be32(p_start);
355
Li Yangce973b12006-08-14 23:00:11 -0700356 /* Check that this entry was actually valid --
357 needed in case failed in allocations */
Andy Fleming6fee40e2008-05-02 13:01:23 -0500358 if ((val & ENET_INIT_PARAM_RISC_MASK) == risc) {
Li Yangce973b12006-08-14 23:00:11 -0700359 snum =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500360 (u32) (val & ENET_INIT_PARAM_SNUM_MASK) >>
Li Yangce973b12006-08-14 23:00:11 -0700361 ENET_INIT_PARAM_SNUM_SHIFT;
362 qe_put_snum((u8) snum);
363 if (!((i == 0) && skip_page_for_first_entry)) {
364 /* First entry of Rx does not have page */
365 init_enet_offset =
366 (in_be32(p_start) &
367 ENET_INIT_PARAM_PTR_MASK);
368 ugeth_info("Init enet entry %d:", i);
369 ugeth_info("Base address: 0x%08x",
370 (u32)
371 qe_muram_addr(init_enet_offset));
372 mem_disp(qe_muram_addr(init_enet_offset),
373 thread_size);
374 }
375 p_start++;
376 }
377 }
378
379 return 0;
380}
381#endif
382
Li Yang18a8e862006-10-19 21:07:34 -0500383static void put_enet_addr_container(struct enet_addr_container *enet_addr_cont)
Li Yangce973b12006-08-14 23:00:11 -0700384{
385 kfree(enet_addr_cont);
386}
387
Timur Tabidf19b6b2007-01-09 12:31:38 -0600388static void set_mac_addr(__be16 __iomem *reg, u8 *mac)
Li Yangce973b12006-08-14 23:00:11 -0700389{
Li Yang18a8e862006-10-19 21:07:34 -0500390 out_be16(&reg[0], ((u16)mac[5] << 8) | mac[4]);
391 out_be16(&reg[1], ((u16)mac[3] << 8) | mac[2]);
392 out_be16(&reg[2], ((u16)mac[1] << 8) | mac[0]);
393}
394
Li Yang18a8e862006-10-19 21:07:34 -0500395static int hw_clear_addr_in_paddr(struct ucc_geth_private *ugeth, u8 paddr_num)
Li Yangce973b12006-08-14 23:00:11 -0700396{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500397 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Li Yangce973b12006-08-14 23:00:11 -0700398
399 if (!(paddr_num < NUM_OF_PADDRS)) {
Harvey Harrisonb39d66a2008-08-20 16:52:04 -0700400 ugeth_warn("%s: Illagel paddr_num.", __func__);
Li Yangce973b12006-08-14 23:00:11 -0700401 return -EINVAL;
402 }
403
404 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500405 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->p_rx_glbl_pram->
Li Yangce973b12006-08-14 23:00:11 -0700406 addressfiltering;
407
408 /* Writing address ff.ff.ff.ff.ff.ff disables address
409 recognition for this register */
410 out_be16(&p_82xx_addr_filt->paddr[paddr_num].h, 0xffff);
411 out_be16(&p_82xx_addr_filt->paddr[paddr_num].m, 0xffff);
412 out_be16(&p_82xx_addr_filt->paddr[paddr_num].l, 0xffff);
413
414 return 0;
415}
416
Li Yang18a8e862006-10-19 21:07:34 -0500417static void hw_add_addr_in_hash(struct ucc_geth_private *ugeth,
418 u8 *p_enet_addr)
Li Yangce973b12006-08-14 23:00:11 -0700419{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500420 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Li Yangce973b12006-08-14 23:00:11 -0700421 u32 cecr_subblock;
422
423 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500424 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->p_rx_glbl_pram->
Li Yangce973b12006-08-14 23:00:11 -0700425 addressfiltering;
426
427 cecr_subblock =
428 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
429
430 /* Ethernet frames are defined in Little Endian mode,
431 therefor to insert */
432 /* the address to the hash (Big Endian mode), we reverse the bytes.*/
Li Yang18a8e862006-10-19 21:07:34 -0500433
434 set_mac_addr(&p_82xx_addr_filt->taddr.h, p_enet_addr);
Li Yangce973b12006-08-14 23:00:11 -0700435
436 qe_issue_cmd(QE_SET_GROUP_ADDRESS, cecr_subblock,
Li Yang18a8e862006-10-19 21:07:34 -0500437 QE_CR_PROTOCOL_ETHERNET, 0);
Li Yangce973b12006-08-14 23:00:11 -0700438}
439
440#ifdef CONFIG_UGETH_MAGIC_PACKET
Li Yang18a8e862006-10-19 21:07:34 -0500441static void magic_packet_detection_enable(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700442{
Li Yang18a8e862006-10-19 21:07:34 -0500443 struct ucc_fast_private *uccf;
Andy Fleming6fee40e2008-05-02 13:01:23 -0500444 struct ucc_geth __iomem *ug_regs;
Li Yangce973b12006-08-14 23:00:11 -0700445
446 uccf = ugeth->uccf;
447 ug_regs = ugeth->ug_regs;
448
449 /* Enable interrupts for magic packet detection */
Timur Tabi3bc53422009-01-11 00:25:21 -0800450 setbits32(uccf->p_uccm, UCC_GETH_UCCE_MPD);
Li Yangce973b12006-08-14 23:00:11 -0700451
452 /* Enable magic packet detection */
Timur Tabi3bc53422009-01-11 00:25:21 -0800453 setbits32(&ug_regs->maccfg2, MACCFG2_MPE);
Li Yangce973b12006-08-14 23:00:11 -0700454}
455
Li Yang18a8e862006-10-19 21:07:34 -0500456static void magic_packet_detection_disable(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700457{
Li Yang18a8e862006-10-19 21:07:34 -0500458 struct ucc_fast_private *uccf;
Andy Fleming6fee40e2008-05-02 13:01:23 -0500459 struct ucc_geth __iomem *ug_regs;
Li Yangce973b12006-08-14 23:00:11 -0700460
461 uccf = ugeth->uccf;
462 ug_regs = ugeth->ug_regs;
463
464 /* Disable interrupts for magic packet detection */
Timur Tabi3bc53422009-01-11 00:25:21 -0800465 clrbits32(uccf->p_uccm, UCC_GETH_UCCE_MPD);
Li Yangce973b12006-08-14 23:00:11 -0700466
467 /* Disable magic packet detection */
Timur Tabi3bc53422009-01-11 00:25:21 -0800468 clrbits32(&ug_regs->maccfg2, MACCFG2_MPE);
Li Yangce973b12006-08-14 23:00:11 -0700469}
470#endif /* MAGIC_PACKET */
471
Li Yang18a8e862006-10-19 21:07:34 -0500472static inline int compare_addr(u8 **addr1, u8 **addr2)
Li Yangce973b12006-08-14 23:00:11 -0700473{
474 return memcmp(addr1, addr2, ENET_NUM_OCTETS_PER_ADDRESS);
475}
476
477#ifdef DEBUG
Li Yang18a8e862006-10-19 21:07:34 -0500478static void get_statistics(struct ucc_geth_private *ugeth,
479 struct ucc_geth_tx_firmware_statistics *
Li Yangce973b12006-08-14 23:00:11 -0700480 tx_firmware_statistics,
Li Yang18a8e862006-10-19 21:07:34 -0500481 struct ucc_geth_rx_firmware_statistics *
Li Yangce973b12006-08-14 23:00:11 -0700482 rx_firmware_statistics,
Li Yang18a8e862006-10-19 21:07:34 -0500483 struct ucc_geth_hardware_statistics *hardware_statistics)
Li Yangce973b12006-08-14 23:00:11 -0700484{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500485 struct ucc_fast __iomem *uf_regs;
486 struct ucc_geth __iomem *ug_regs;
Li Yang18a8e862006-10-19 21:07:34 -0500487 struct ucc_geth_tx_firmware_statistics_pram *p_tx_fw_statistics_pram;
488 struct ucc_geth_rx_firmware_statistics_pram *p_rx_fw_statistics_pram;
Li Yangce973b12006-08-14 23:00:11 -0700489
490 ug_regs = ugeth->ug_regs;
Andy Fleming6fee40e2008-05-02 13:01:23 -0500491 uf_regs = (struct ucc_fast __iomem *) ug_regs;
Li Yangce973b12006-08-14 23:00:11 -0700492 p_tx_fw_statistics_pram = ugeth->p_tx_fw_statistics_pram;
493 p_rx_fw_statistics_pram = ugeth->p_rx_fw_statistics_pram;
494
495 /* Tx firmware only if user handed pointer and driver actually
496 gathers Tx firmware statistics */
497 if (tx_firmware_statistics && p_tx_fw_statistics_pram) {
498 tx_firmware_statistics->sicoltx =
499 in_be32(&p_tx_fw_statistics_pram->sicoltx);
500 tx_firmware_statistics->mulcoltx =
501 in_be32(&p_tx_fw_statistics_pram->mulcoltx);
502 tx_firmware_statistics->latecoltxfr =
503 in_be32(&p_tx_fw_statistics_pram->latecoltxfr);
504 tx_firmware_statistics->frabortduecol =
505 in_be32(&p_tx_fw_statistics_pram->frabortduecol);
506 tx_firmware_statistics->frlostinmactxer =
507 in_be32(&p_tx_fw_statistics_pram->frlostinmactxer);
508 tx_firmware_statistics->carriersenseertx =
509 in_be32(&p_tx_fw_statistics_pram->carriersenseertx);
510 tx_firmware_statistics->frtxok =
511 in_be32(&p_tx_fw_statistics_pram->frtxok);
512 tx_firmware_statistics->txfrexcessivedefer =
513 in_be32(&p_tx_fw_statistics_pram->txfrexcessivedefer);
514 tx_firmware_statistics->txpkts256 =
515 in_be32(&p_tx_fw_statistics_pram->txpkts256);
516 tx_firmware_statistics->txpkts512 =
517 in_be32(&p_tx_fw_statistics_pram->txpkts512);
518 tx_firmware_statistics->txpkts1024 =
519 in_be32(&p_tx_fw_statistics_pram->txpkts1024);
520 tx_firmware_statistics->txpktsjumbo =
521 in_be32(&p_tx_fw_statistics_pram->txpktsjumbo);
522 }
523
524 /* Rx firmware only if user handed pointer and driver actually
525 * gathers Rx firmware statistics */
526 if (rx_firmware_statistics && p_rx_fw_statistics_pram) {
527 int i;
528 rx_firmware_statistics->frrxfcser =
529 in_be32(&p_rx_fw_statistics_pram->frrxfcser);
530 rx_firmware_statistics->fraligner =
531 in_be32(&p_rx_fw_statistics_pram->fraligner);
532 rx_firmware_statistics->inrangelenrxer =
533 in_be32(&p_rx_fw_statistics_pram->inrangelenrxer);
534 rx_firmware_statistics->outrangelenrxer =
535 in_be32(&p_rx_fw_statistics_pram->outrangelenrxer);
536 rx_firmware_statistics->frtoolong =
537 in_be32(&p_rx_fw_statistics_pram->frtoolong);
538 rx_firmware_statistics->runt =
539 in_be32(&p_rx_fw_statistics_pram->runt);
540 rx_firmware_statistics->verylongevent =
541 in_be32(&p_rx_fw_statistics_pram->verylongevent);
542 rx_firmware_statistics->symbolerror =
543 in_be32(&p_rx_fw_statistics_pram->symbolerror);
544 rx_firmware_statistics->dropbsy =
545 in_be32(&p_rx_fw_statistics_pram->dropbsy);
546 for (i = 0; i < 0x8; i++)
547 rx_firmware_statistics->res0[i] =
548 p_rx_fw_statistics_pram->res0[i];
549 rx_firmware_statistics->mismatchdrop =
550 in_be32(&p_rx_fw_statistics_pram->mismatchdrop);
551 rx_firmware_statistics->underpkts =
552 in_be32(&p_rx_fw_statistics_pram->underpkts);
553 rx_firmware_statistics->pkts256 =
554 in_be32(&p_rx_fw_statistics_pram->pkts256);
555 rx_firmware_statistics->pkts512 =
556 in_be32(&p_rx_fw_statistics_pram->pkts512);
557 rx_firmware_statistics->pkts1024 =
558 in_be32(&p_rx_fw_statistics_pram->pkts1024);
559 rx_firmware_statistics->pktsjumbo =
560 in_be32(&p_rx_fw_statistics_pram->pktsjumbo);
561 rx_firmware_statistics->frlossinmacer =
562 in_be32(&p_rx_fw_statistics_pram->frlossinmacer);
563 rx_firmware_statistics->pausefr =
564 in_be32(&p_rx_fw_statistics_pram->pausefr);
565 for (i = 0; i < 0x4; i++)
566 rx_firmware_statistics->res1[i] =
567 p_rx_fw_statistics_pram->res1[i];
568 rx_firmware_statistics->removevlan =
569 in_be32(&p_rx_fw_statistics_pram->removevlan);
570 rx_firmware_statistics->replacevlan =
571 in_be32(&p_rx_fw_statistics_pram->replacevlan);
572 rx_firmware_statistics->insertvlan =
573 in_be32(&p_rx_fw_statistics_pram->insertvlan);
574 }
575
576 /* Hardware only if user handed pointer and driver actually
577 gathers hardware statistics */
Timur Tabi3bc53422009-01-11 00:25:21 -0800578 if (hardware_statistics &&
579 (in_be32(&uf_regs->upsmr) & UCC_GETH_UPSMR_HSE)) {
Li Yangce973b12006-08-14 23:00:11 -0700580 hardware_statistics->tx64 = in_be32(&ug_regs->tx64);
581 hardware_statistics->tx127 = in_be32(&ug_regs->tx127);
582 hardware_statistics->tx255 = in_be32(&ug_regs->tx255);
583 hardware_statistics->rx64 = in_be32(&ug_regs->rx64);
584 hardware_statistics->rx127 = in_be32(&ug_regs->rx127);
585 hardware_statistics->rx255 = in_be32(&ug_regs->rx255);
586 hardware_statistics->txok = in_be32(&ug_regs->txok);
587 hardware_statistics->txcf = in_be16(&ug_regs->txcf);
588 hardware_statistics->tmca = in_be32(&ug_regs->tmca);
589 hardware_statistics->tbca = in_be32(&ug_regs->tbca);
590 hardware_statistics->rxfok = in_be32(&ug_regs->rxfok);
591 hardware_statistics->rxbok = in_be32(&ug_regs->rxbok);
592 hardware_statistics->rbyt = in_be32(&ug_regs->rbyt);
593 hardware_statistics->rmca = in_be32(&ug_regs->rmca);
594 hardware_statistics->rbca = in_be32(&ug_regs->rbca);
595 }
596}
597
Li Yang18a8e862006-10-19 21:07:34 -0500598static void dump_bds(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700599{
600 int i;
601 int length;
602
603 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
604 if (ugeth->p_tx_bd_ring[i]) {
605 length =
606 (ugeth->ug_info->bdRingLenTx[i] *
Li Yang18a8e862006-10-19 21:07:34 -0500607 sizeof(struct qe_bd));
Li Yangce973b12006-08-14 23:00:11 -0700608 ugeth_info("TX BDs[%d]", i);
609 mem_disp(ugeth->p_tx_bd_ring[i], length);
610 }
611 }
612 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
613 if (ugeth->p_rx_bd_ring[i]) {
614 length =
615 (ugeth->ug_info->bdRingLenRx[i] *
Li Yang18a8e862006-10-19 21:07:34 -0500616 sizeof(struct qe_bd));
Li Yangce973b12006-08-14 23:00:11 -0700617 ugeth_info("RX BDs[%d]", i);
618 mem_disp(ugeth->p_rx_bd_ring[i], length);
619 }
620 }
621}
622
Li Yang18a8e862006-10-19 21:07:34 -0500623static void dump_regs(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700624{
625 int i;
626
627 ugeth_info("UCC%d Geth registers:", ugeth->ug_info->uf_info.ucc_num);
628 ugeth_info("Base address: 0x%08x", (u32) ugeth->ug_regs);
629
630 ugeth_info("maccfg1 : addr - 0x%08x, val - 0x%08x",
631 (u32) & ugeth->ug_regs->maccfg1,
632 in_be32(&ugeth->ug_regs->maccfg1));
633 ugeth_info("maccfg2 : addr - 0x%08x, val - 0x%08x",
634 (u32) & ugeth->ug_regs->maccfg2,
635 in_be32(&ugeth->ug_regs->maccfg2));
636 ugeth_info("ipgifg : addr - 0x%08x, val - 0x%08x",
637 (u32) & ugeth->ug_regs->ipgifg,
638 in_be32(&ugeth->ug_regs->ipgifg));
639 ugeth_info("hafdup : addr - 0x%08x, val - 0x%08x",
640 (u32) & ugeth->ug_regs->hafdup,
641 in_be32(&ugeth->ug_regs->hafdup));
Li Yangce973b12006-08-14 23:00:11 -0700642 ugeth_info("ifctl : addr - 0x%08x, val - 0x%08x",
643 (u32) & ugeth->ug_regs->ifctl,
644 in_be32(&ugeth->ug_regs->ifctl));
645 ugeth_info("ifstat : addr - 0x%08x, val - 0x%08x",
646 (u32) & ugeth->ug_regs->ifstat,
647 in_be32(&ugeth->ug_regs->ifstat));
648 ugeth_info("macstnaddr1: addr - 0x%08x, val - 0x%08x",
649 (u32) & ugeth->ug_regs->macstnaddr1,
650 in_be32(&ugeth->ug_regs->macstnaddr1));
651 ugeth_info("macstnaddr2: addr - 0x%08x, val - 0x%08x",
652 (u32) & ugeth->ug_regs->macstnaddr2,
653 in_be32(&ugeth->ug_regs->macstnaddr2));
654 ugeth_info("uempr : addr - 0x%08x, val - 0x%08x",
655 (u32) & ugeth->ug_regs->uempr,
656 in_be32(&ugeth->ug_regs->uempr));
657 ugeth_info("utbipar : addr - 0x%08x, val - 0x%08x",
658 (u32) & ugeth->ug_regs->utbipar,
659 in_be32(&ugeth->ug_regs->utbipar));
660 ugeth_info("uescr : addr - 0x%08x, val - 0x%04x",
661 (u32) & ugeth->ug_regs->uescr,
662 in_be16(&ugeth->ug_regs->uescr));
663 ugeth_info("tx64 : addr - 0x%08x, val - 0x%08x",
664 (u32) & ugeth->ug_regs->tx64,
665 in_be32(&ugeth->ug_regs->tx64));
666 ugeth_info("tx127 : addr - 0x%08x, val - 0x%08x",
667 (u32) & ugeth->ug_regs->tx127,
668 in_be32(&ugeth->ug_regs->tx127));
669 ugeth_info("tx255 : addr - 0x%08x, val - 0x%08x",
670 (u32) & ugeth->ug_regs->tx255,
671 in_be32(&ugeth->ug_regs->tx255));
672 ugeth_info("rx64 : addr - 0x%08x, val - 0x%08x",
673 (u32) & ugeth->ug_regs->rx64,
674 in_be32(&ugeth->ug_regs->rx64));
675 ugeth_info("rx127 : addr - 0x%08x, val - 0x%08x",
676 (u32) & ugeth->ug_regs->rx127,
677 in_be32(&ugeth->ug_regs->rx127));
678 ugeth_info("rx255 : addr - 0x%08x, val - 0x%08x",
679 (u32) & ugeth->ug_regs->rx255,
680 in_be32(&ugeth->ug_regs->rx255));
681 ugeth_info("txok : addr - 0x%08x, val - 0x%08x",
682 (u32) & ugeth->ug_regs->txok,
683 in_be32(&ugeth->ug_regs->txok));
684 ugeth_info("txcf : addr - 0x%08x, val - 0x%04x",
685 (u32) & ugeth->ug_regs->txcf,
686 in_be16(&ugeth->ug_regs->txcf));
687 ugeth_info("tmca : addr - 0x%08x, val - 0x%08x",
688 (u32) & ugeth->ug_regs->tmca,
689 in_be32(&ugeth->ug_regs->tmca));
690 ugeth_info("tbca : addr - 0x%08x, val - 0x%08x",
691 (u32) & ugeth->ug_regs->tbca,
692 in_be32(&ugeth->ug_regs->tbca));
693 ugeth_info("rxfok : addr - 0x%08x, val - 0x%08x",
694 (u32) & ugeth->ug_regs->rxfok,
695 in_be32(&ugeth->ug_regs->rxfok));
696 ugeth_info("rxbok : addr - 0x%08x, val - 0x%08x",
697 (u32) & ugeth->ug_regs->rxbok,
698 in_be32(&ugeth->ug_regs->rxbok));
699 ugeth_info("rbyt : addr - 0x%08x, val - 0x%08x",
700 (u32) & ugeth->ug_regs->rbyt,
701 in_be32(&ugeth->ug_regs->rbyt));
702 ugeth_info("rmca : addr - 0x%08x, val - 0x%08x",
703 (u32) & ugeth->ug_regs->rmca,
704 in_be32(&ugeth->ug_regs->rmca));
705 ugeth_info("rbca : addr - 0x%08x, val - 0x%08x",
706 (u32) & ugeth->ug_regs->rbca,
707 in_be32(&ugeth->ug_regs->rbca));
708 ugeth_info("scar : addr - 0x%08x, val - 0x%08x",
709 (u32) & ugeth->ug_regs->scar,
710 in_be32(&ugeth->ug_regs->scar));
711 ugeth_info("scam : addr - 0x%08x, val - 0x%08x",
712 (u32) & ugeth->ug_regs->scam,
713 in_be32(&ugeth->ug_regs->scam));
714
715 if (ugeth->p_thread_data_tx) {
716 int numThreadsTxNumerical;
717 switch (ugeth->ug_info->numThreadsTx) {
718 case UCC_GETH_NUM_OF_THREADS_1:
719 numThreadsTxNumerical = 1;
720 break;
721 case UCC_GETH_NUM_OF_THREADS_2:
722 numThreadsTxNumerical = 2;
723 break;
724 case UCC_GETH_NUM_OF_THREADS_4:
725 numThreadsTxNumerical = 4;
726 break;
727 case UCC_GETH_NUM_OF_THREADS_6:
728 numThreadsTxNumerical = 6;
729 break;
730 case UCC_GETH_NUM_OF_THREADS_8:
731 numThreadsTxNumerical = 8;
732 break;
733 default:
734 numThreadsTxNumerical = 0;
735 break;
736 }
737
738 ugeth_info("Thread data TXs:");
739 ugeth_info("Base address: 0x%08x",
740 (u32) ugeth->p_thread_data_tx);
741 for (i = 0; i < numThreadsTxNumerical; i++) {
742 ugeth_info("Thread data TX[%d]:", i);
743 ugeth_info("Base address: 0x%08x",
744 (u32) & ugeth->p_thread_data_tx[i]);
745 mem_disp((u8 *) & ugeth->p_thread_data_tx[i],
Li Yang18a8e862006-10-19 21:07:34 -0500746 sizeof(struct ucc_geth_thread_data_tx));
Li Yangce973b12006-08-14 23:00:11 -0700747 }
748 }
749 if (ugeth->p_thread_data_rx) {
750 int numThreadsRxNumerical;
751 switch (ugeth->ug_info->numThreadsRx) {
752 case UCC_GETH_NUM_OF_THREADS_1:
753 numThreadsRxNumerical = 1;
754 break;
755 case UCC_GETH_NUM_OF_THREADS_2:
756 numThreadsRxNumerical = 2;
757 break;
758 case UCC_GETH_NUM_OF_THREADS_4:
759 numThreadsRxNumerical = 4;
760 break;
761 case UCC_GETH_NUM_OF_THREADS_6:
762 numThreadsRxNumerical = 6;
763 break;
764 case UCC_GETH_NUM_OF_THREADS_8:
765 numThreadsRxNumerical = 8;
766 break;
767 default:
768 numThreadsRxNumerical = 0;
769 break;
770 }
771
772 ugeth_info("Thread data RX:");
773 ugeth_info("Base address: 0x%08x",
774 (u32) ugeth->p_thread_data_rx);
775 for (i = 0; i < numThreadsRxNumerical; i++) {
776 ugeth_info("Thread data RX[%d]:", i);
777 ugeth_info("Base address: 0x%08x",
778 (u32) & ugeth->p_thread_data_rx[i]);
779 mem_disp((u8 *) & ugeth->p_thread_data_rx[i],
Li Yang18a8e862006-10-19 21:07:34 -0500780 sizeof(struct ucc_geth_thread_data_rx));
Li Yangce973b12006-08-14 23:00:11 -0700781 }
782 }
783 if (ugeth->p_exf_glbl_param) {
784 ugeth_info("EXF global param:");
785 ugeth_info("Base address: 0x%08x",
786 (u32) ugeth->p_exf_glbl_param);
787 mem_disp((u8 *) ugeth->p_exf_glbl_param,
788 sizeof(*ugeth->p_exf_glbl_param));
789 }
790 if (ugeth->p_tx_glbl_pram) {
791 ugeth_info("TX global param:");
792 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_tx_glbl_pram);
793 ugeth_info("temoder : addr - 0x%08x, val - 0x%04x",
794 (u32) & ugeth->p_tx_glbl_pram->temoder,
795 in_be16(&ugeth->p_tx_glbl_pram->temoder));
796 ugeth_info("sqptr : addr - 0x%08x, val - 0x%08x",
797 (u32) & ugeth->p_tx_glbl_pram->sqptr,
798 in_be32(&ugeth->p_tx_glbl_pram->sqptr));
799 ugeth_info("schedulerbasepointer: addr - 0x%08x, val - 0x%08x",
800 (u32) & ugeth->p_tx_glbl_pram->schedulerbasepointer,
801 in_be32(&ugeth->p_tx_glbl_pram->
802 schedulerbasepointer));
803 ugeth_info("txrmonbaseptr: addr - 0x%08x, val - 0x%08x",
804 (u32) & ugeth->p_tx_glbl_pram->txrmonbaseptr,
805 in_be32(&ugeth->p_tx_glbl_pram->txrmonbaseptr));
806 ugeth_info("tstate : addr - 0x%08x, val - 0x%08x",
807 (u32) & ugeth->p_tx_glbl_pram->tstate,
808 in_be32(&ugeth->p_tx_glbl_pram->tstate));
809 ugeth_info("iphoffset[0] : addr - 0x%08x, val - 0x%02x",
810 (u32) & ugeth->p_tx_glbl_pram->iphoffset[0],
811 ugeth->p_tx_glbl_pram->iphoffset[0]);
812 ugeth_info("iphoffset[1] : addr - 0x%08x, val - 0x%02x",
813 (u32) & ugeth->p_tx_glbl_pram->iphoffset[1],
814 ugeth->p_tx_glbl_pram->iphoffset[1]);
815 ugeth_info("iphoffset[2] : addr - 0x%08x, val - 0x%02x",
816 (u32) & ugeth->p_tx_glbl_pram->iphoffset[2],
817 ugeth->p_tx_glbl_pram->iphoffset[2]);
818 ugeth_info("iphoffset[3] : addr - 0x%08x, val - 0x%02x",
819 (u32) & ugeth->p_tx_glbl_pram->iphoffset[3],
820 ugeth->p_tx_glbl_pram->iphoffset[3]);
821 ugeth_info("iphoffset[4] : addr - 0x%08x, val - 0x%02x",
822 (u32) & ugeth->p_tx_glbl_pram->iphoffset[4],
823 ugeth->p_tx_glbl_pram->iphoffset[4]);
824 ugeth_info("iphoffset[5] : addr - 0x%08x, val - 0x%02x",
825 (u32) & ugeth->p_tx_glbl_pram->iphoffset[5],
826 ugeth->p_tx_glbl_pram->iphoffset[5]);
827 ugeth_info("iphoffset[6] : addr - 0x%08x, val - 0x%02x",
828 (u32) & ugeth->p_tx_glbl_pram->iphoffset[6],
829 ugeth->p_tx_glbl_pram->iphoffset[6]);
830 ugeth_info("iphoffset[7] : addr - 0x%08x, val - 0x%02x",
831 (u32) & ugeth->p_tx_glbl_pram->iphoffset[7],
832 ugeth->p_tx_glbl_pram->iphoffset[7]);
833 ugeth_info("vtagtable[0] : addr - 0x%08x, val - 0x%08x",
834 (u32) & ugeth->p_tx_glbl_pram->vtagtable[0],
835 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[0]));
836 ugeth_info("vtagtable[1] : addr - 0x%08x, val - 0x%08x",
837 (u32) & ugeth->p_tx_glbl_pram->vtagtable[1],
838 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[1]));
839 ugeth_info("vtagtable[2] : addr - 0x%08x, val - 0x%08x",
840 (u32) & ugeth->p_tx_glbl_pram->vtagtable[2],
841 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[2]));
842 ugeth_info("vtagtable[3] : addr - 0x%08x, val - 0x%08x",
843 (u32) & ugeth->p_tx_glbl_pram->vtagtable[3],
844 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[3]));
845 ugeth_info("vtagtable[4] : addr - 0x%08x, val - 0x%08x",
846 (u32) & ugeth->p_tx_glbl_pram->vtagtable[4],
847 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[4]));
848 ugeth_info("vtagtable[5] : addr - 0x%08x, val - 0x%08x",
849 (u32) & ugeth->p_tx_glbl_pram->vtagtable[5],
850 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[5]));
851 ugeth_info("vtagtable[6] : addr - 0x%08x, val - 0x%08x",
852 (u32) & ugeth->p_tx_glbl_pram->vtagtable[6],
853 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[6]));
854 ugeth_info("vtagtable[7] : addr - 0x%08x, val - 0x%08x",
855 (u32) & ugeth->p_tx_glbl_pram->vtagtable[7],
856 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[7]));
857 ugeth_info("tqptr : addr - 0x%08x, val - 0x%08x",
858 (u32) & ugeth->p_tx_glbl_pram->tqptr,
859 in_be32(&ugeth->p_tx_glbl_pram->tqptr));
860 }
861 if (ugeth->p_rx_glbl_pram) {
862 ugeth_info("RX global param:");
863 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_glbl_pram);
864 ugeth_info("remoder : addr - 0x%08x, val - 0x%08x",
865 (u32) & ugeth->p_rx_glbl_pram->remoder,
866 in_be32(&ugeth->p_rx_glbl_pram->remoder));
867 ugeth_info("rqptr : addr - 0x%08x, val - 0x%08x",
868 (u32) & ugeth->p_rx_glbl_pram->rqptr,
869 in_be32(&ugeth->p_rx_glbl_pram->rqptr));
870 ugeth_info("typeorlen : addr - 0x%08x, val - 0x%04x",
871 (u32) & ugeth->p_rx_glbl_pram->typeorlen,
872 in_be16(&ugeth->p_rx_glbl_pram->typeorlen));
873 ugeth_info("rxgstpack : addr - 0x%08x, val - 0x%02x",
874 (u32) & ugeth->p_rx_glbl_pram->rxgstpack,
875 ugeth->p_rx_glbl_pram->rxgstpack);
876 ugeth_info("rxrmonbaseptr : addr - 0x%08x, val - 0x%08x",
877 (u32) & ugeth->p_rx_glbl_pram->rxrmonbaseptr,
878 in_be32(&ugeth->p_rx_glbl_pram->rxrmonbaseptr));
879 ugeth_info("intcoalescingptr: addr - 0x%08x, val - 0x%08x",
880 (u32) & ugeth->p_rx_glbl_pram->intcoalescingptr,
881 in_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr));
882 ugeth_info("rstate : addr - 0x%08x, val - 0x%02x",
883 (u32) & ugeth->p_rx_glbl_pram->rstate,
884 ugeth->p_rx_glbl_pram->rstate);
885 ugeth_info("mrblr : addr - 0x%08x, val - 0x%04x",
886 (u32) & ugeth->p_rx_glbl_pram->mrblr,
887 in_be16(&ugeth->p_rx_glbl_pram->mrblr));
888 ugeth_info("rbdqptr : addr - 0x%08x, val - 0x%08x",
889 (u32) & ugeth->p_rx_glbl_pram->rbdqptr,
890 in_be32(&ugeth->p_rx_glbl_pram->rbdqptr));
891 ugeth_info("mflr : addr - 0x%08x, val - 0x%04x",
892 (u32) & ugeth->p_rx_glbl_pram->mflr,
893 in_be16(&ugeth->p_rx_glbl_pram->mflr));
894 ugeth_info("minflr : addr - 0x%08x, val - 0x%04x",
895 (u32) & ugeth->p_rx_glbl_pram->minflr,
896 in_be16(&ugeth->p_rx_glbl_pram->minflr));
897 ugeth_info("maxd1 : addr - 0x%08x, val - 0x%04x",
898 (u32) & ugeth->p_rx_glbl_pram->maxd1,
899 in_be16(&ugeth->p_rx_glbl_pram->maxd1));
900 ugeth_info("maxd2 : addr - 0x%08x, val - 0x%04x",
901 (u32) & ugeth->p_rx_glbl_pram->maxd2,
902 in_be16(&ugeth->p_rx_glbl_pram->maxd2));
903 ugeth_info("ecamptr : addr - 0x%08x, val - 0x%08x",
904 (u32) & ugeth->p_rx_glbl_pram->ecamptr,
905 in_be32(&ugeth->p_rx_glbl_pram->ecamptr));
906 ugeth_info("l2qt : addr - 0x%08x, val - 0x%08x",
907 (u32) & ugeth->p_rx_glbl_pram->l2qt,
908 in_be32(&ugeth->p_rx_glbl_pram->l2qt));
909 ugeth_info("l3qt[0] : addr - 0x%08x, val - 0x%08x",
910 (u32) & ugeth->p_rx_glbl_pram->l3qt[0],
911 in_be32(&ugeth->p_rx_glbl_pram->l3qt[0]));
912 ugeth_info("l3qt[1] : addr - 0x%08x, val - 0x%08x",
913 (u32) & ugeth->p_rx_glbl_pram->l3qt[1],
914 in_be32(&ugeth->p_rx_glbl_pram->l3qt[1]));
915 ugeth_info("l3qt[2] : addr - 0x%08x, val - 0x%08x",
916 (u32) & ugeth->p_rx_glbl_pram->l3qt[2],
917 in_be32(&ugeth->p_rx_glbl_pram->l3qt[2]));
918 ugeth_info("l3qt[3] : addr - 0x%08x, val - 0x%08x",
919 (u32) & ugeth->p_rx_glbl_pram->l3qt[3],
920 in_be32(&ugeth->p_rx_glbl_pram->l3qt[3]));
921 ugeth_info("l3qt[4] : addr - 0x%08x, val - 0x%08x",
922 (u32) & ugeth->p_rx_glbl_pram->l3qt[4],
923 in_be32(&ugeth->p_rx_glbl_pram->l3qt[4]));
924 ugeth_info("l3qt[5] : addr - 0x%08x, val - 0x%08x",
925 (u32) & ugeth->p_rx_glbl_pram->l3qt[5],
926 in_be32(&ugeth->p_rx_glbl_pram->l3qt[5]));
927 ugeth_info("l3qt[6] : addr - 0x%08x, val - 0x%08x",
928 (u32) & ugeth->p_rx_glbl_pram->l3qt[6],
929 in_be32(&ugeth->p_rx_glbl_pram->l3qt[6]));
930 ugeth_info("l3qt[7] : addr - 0x%08x, val - 0x%08x",
931 (u32) & ugeth->p_rx_glbl_pram->l3qt[7],
932 in_be32(&ugeth->p_rx_glbl_pram->l3qt[7]));
933 ugeth_info("vlantype : addr - 0x%08x, val - 0x%04x",
934 (u32) & ugeth->p_rx_glbl_pram->vlantype,
935 in_be16(&ugeth->p_rx_glbl_pram->vlantype));
936 ugeth_info("vlantci : addr - 0x%08x, val - 0x%04x",
937 (u32) & ugeth->p_rx_glbl_pram->vlantci,
938 in_be16(&ugeth->p_rx_glbl_pram->vlantci));
939 for (i = 0; i < 64; i++)
940 ugeth_info
941 ("addressfiltering[%d]: addr - 0x%08x, val - 0x%02x",
942 i,
943 (u32) & ugeth->p_rx_glbl_pram->addressfiltering[i],
944 ugeth->p_rx_glbl_pram->addressfiltering[i]);
945 ugeth_info("exfGlobalParam : addr - 0x%08x, val - 0x%08x",
946 (u32) & ugeth->p_rx_glbl_pram->exfGlobalParam,
947 in_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam));
948 }
949 if (ugeth->p_send_q_mem_reg) {
950 ugeth_info("Send Q memory registers:");
951 ugeth_info("Base address: 0x%08x",
952 (u32) ugeth->p_send_q_mem_reg);
953 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
954 ugeth_info("SQQD[%d]:", i);
955 ugeth_info("Base address: 0x%08x",
956 (u32) & ugeth->p_send_q_mem_reg->sqqd[i]);
957 mem_disp((u8 *) & ugeth->p_send_q_mem_reg->sqqd[i],
Li Yang18a8e862006-10-19 21:07:34 -0500958 sizeof(struct ucc_geth_send_queue_qd));
Li Yangce973b12006-08-14 23:00:11 -0700959 }
960 }
961 if (ugeth->p_scheduler) {
962 ugeth_info("Scheduler:");
963 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_scheduler);
964 mem_disp((u8 *) ugeth->p_scheduler,
965 sizeof(*ugeth->p_scheduler));
966 }
967 if (ugeth->p_tx_fw_statistics_pram) {
968 ugeth_info("TX FW statistics pram:");
969 ugeth_info("Base address: 0x%08x",
970 (u32) ugeth->p_tx_fw_statistics_pram);
971 mem_disp((u8 *) ugeth->p_tx_fw_statistics_pram,
972 sizeof(*ugeth->p_tx_fw_statistics_pram));
973 }
974 if (ugeth->p_rx_fw_statistics_pram) {
975 ugeth_info("RX FW statistics pram:");
976 ugeth_info("Base address: 0x%08x",
977 (u32) ugeth->p_rx_fw_statistics_pram);
978 mem_disp((u8 *) ugeth->p_rx_fw_statistics_pram,
979 sizeof(*ugeth->p_rx_fw_statistics_pram));
980 }
981 if (ugeth->p_rx_irq_coalescing_tbl) {
982 ugeth_info("RX IRQ coalescing tables:");
983 ugeth_info("Base address: 0x%08x",
984 (u32) ugeth->p_rx_irq_coalescing_tbl);
985 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
986 ugeth_info("RX IRQ coalescing table entry[%d]:", i);
987 ugeth_info("Base address: 0x%08x",
988 (u32) & ugeth->p_rx_irq_coalescing_tbl->
989 coalescingentry[i]);
990 ugeth_info
991 ("interruptcoalescingmaxvalue: addr - 0x%08x, val - 0x%08x",
992 (u32) & ugeth->p_rx_irq_coalescing_tbl->
993 coalescingentry[i].interruptcoalescingmaxvalue,
994 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
995 coalescingentry[i].
996 interruptcoalescingmaxvalue));
997 ugeth_info
998 ("interruptcoalescingcounter : addr - 0x%08x, val - 0x%08x",
999 (u32) & ugeth->p_rx_irq_coalescing_tbl->
1000 coalescingentry[i].interruptcoalescingcounter,
1001 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
1002 coalescingentry[i].
1003 interruptcoalescingcounter));
1004 }
1005 }
1006 if (ugeth->p_rx_bd_qs_tbl) {
1007 ugeth_info("RX BD QS tables:");
1008 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_bd_qs_tbl);
1009 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
1010 ugeth_info("RX BD QS table[%d]:", i);
1011 ugeth_info("Base address: 0x%08x",
1012 (u32) & ugeth->p_rx_bd_qs_tbl[i]);
1013 ugeth_info
1014 ("bdbaseptr : addr - 0x%08x, val - 0x%08x",
1015 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdbaseptr,
1016 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdbaseptr));
1017 ugeth_info
1018 ("bdptr : addr - 0x%08x, val - 0x%08x",
1019 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdptr,
1020 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdptr));
1021 ugeth_info
1022 ("externalbdbaseptr: addr - 0x%08x, val - 0x%08x",
1023 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
1024 in_be32(&ugeth->p_rx_bd_qs_tbl[i].
1025 externalbdbaseptr));
1026 ugeth_info
1027 ("externalbdptr : addr - 0x%08x, val - 0x%08x",
1028 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdptr,
1029 in_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdptr));
1030 ugeth_info("ucode RX Prefetched BDs:");
1031 ugeth_info("Base address: 0x%08x",
1032 (u32)
1033 qe_muram_addr(in_be32
1034 (&ugeth->p_rx_bd_qs_tbl[i].
1035 bdbaseptr)));
1036 mem_disp((u8 *)
1037 qe_muram_addr(in_be32
1038 (&ugeth->p_rx_bd_qs_tbl[i].
1039 bdbaseptr)),
Li Yang18a8e862006-10-19 21:07:34 -05001040 sizeof(struct ucc_geth_rx_prefetched_bds));
Li Yangce973b12006-08-14 23:00:11 -07001041 }
1042 }
1043 if (ugeth->p_init_enet_param_shadow) {
1044 int size;
1045 ugeth_info("Init enet param shadow:");
1046 ugeth_info("Base address: 0x%08x",
1047 (u32) ugeth->p_init_enet_param_shadow);
1048 mem_disp((u8 *) ugeth->p_init_enet_param_shadow,
1049 sizeof(*ugeth->p_init_enet_param_shadow));
1050
Li Yang18a8e862006-10-19 21:07:34 -05001051 size = sizeof(struct ucc_geth_thread_rx_pram);
Li Yangce973b12006-08-14 23:00:11 -07001052 if (ugeth->ug_info->rxExtendedFiltering) {
1053 size +=
1054 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
1055 if (ugeth->ug_info->largestexternallookupkeysize ==
1056 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
1057 size +=
1058 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
1059 if (ugeth->ug_info->largestexternallookupkeysize ==
1060 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
1061 size +=
1062 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
1063 }
1064
1065 dump_init_enet_entries(ugeth,
1066 &(ugeth->p_init_enet_param_shadow->
1067 txthread[0]),
1068 ENET_INIT_PARAM_MAX_ENTRIES_TX,
Li Yang18a8e862006-10-19 21:07:34 -05001069 sizeof(struct ucc_geth_thread_tx_pram),
Li Yangce973b12006-08-14 23:00:11 -07001070 ugeth->ug_info->riscTx, 0);
1071 dump_init_enet_entries(ugeth,
1072 &(ugeth->p_init_enet_param_shadow->
1073 rxthread[0]),
1074 ENET_INIT_PARAM_MAX_ENTRIES_RX, size,
1075 ugeth->ug_info->riscRx, 1);
1076 }
1077}
1078#endif /* DEBUG */
1079
Andy Fleming6fee40e2008-05-02 13:01:23 -05001080static void init_default_reg_vals(u32 __iomem *upsmr_register,
1081 u32 __iomem *maccfg1_register,
1082 u32 __iomem *maccfg2_register)
Li Yangce973b12006-08-14 23:00:11 -07001083{
1084 out_be32(upsmr_register, UCC_GETH_UPSMR_INIT);
1085 out_be32(maccfg1_register, UCC_GETH_MACCFG1_INIT);
1086 out_be32(maccfg2_register, UCC_GETH_MACCFG2_INIT);
1087}
1088
1089static int init_half_duplex_params(int alt_beb,
1090 int back_pressure_no_backoff,
1091 int no_backoff,
1092 int excess_defer,
1093 u8 alt_beb_truncation,
1094 u8 max_retransmissions,
1095 u8 collision_window,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001096 u32 __iomem *hafdup_register)
Li Yangce973b12006-08-14 23:00:11 -07001097{
1098 u32 value = 0;
1099
1100 if ((alt_beb_truncation > HALFDUP_ALT_BEB_TRUNCATION_MAX) ||
1101 (max_retransmissions > HALFDUP_MAX_RETRANSMISSION_MAX) ||
1102 (collision_window > HALFDUP_COLLISION_WINDOW_MAX))
1103 return -EINVAL;
1104
1105 value = (u32) (alt_beb_truncation << HALFDUP_ALT_BEB_TRUNCATION_SHIFT);
1106
1107 if (alt_beb)
1108 value |= HALFDUP_ALT_BEB;
1109 if (back_pressure_no_backoff)
1110 value |= HALFDUP_BACK_PRESSURE_NO_BACKOFF;
1111 if (no_backoff)
1112 value |= HALFDUP_NO_BACKOFF;
1113 if (excess_defer)
1114 value |= HALFDUP_EXCESSIVE_DEFER;
1115
1116 value |= (max_retransmissions << HALFDUP_MAX_RETRANSMISSION_SHIFT);
1117
1118 value |= collision_window;
1119
1120 out_be32(hafdup_register, value);
1121 return 0;
1122}
1123
1124static int init_inter_frame_gap_params(u8 non_btb_cs_ipg,
1125 u8 non_btb_ipg,
1126 u8 min_ifg,
1127 u8 btb_ipg,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001128 u32 __iomem *ipgifg_register)
Li Yangce973b12006-08-14 23:00:11 -07001129{
1130 u32 value = 0;
1131
1132 /* Non-Back-to-back IPG part 1 should be <= Non-Back-to-back
1133 IPG part 2 */
1134 if (non_btb_cs_ipg > non_btb_ipg)
1135 return -EINVAL;
1136
1137 if ((non_btb_cs_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART1_MAX) ||
1138 (non_btb_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART2_MAX) ||
1139 /*(min_ifg > IPGIFG_MINIMUM_IFG_ENFORCEMENT_MAX) || */
1140 (btb_ipg > IPGIFG_BACK_TO_BACK_IFG_MAX))
1141 return -EINVAL;
1142
1143 value |=
1144 ((non_btb_cs_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART1_SHIFT) &
1145 IPGIFG_NBTB_CS_IPG_MASK);
1146 value |=
1147 ((non_btb_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART2_SHIFT) &
1148 IPGIFG_NBTB_IPG_MASK);
1149 value |=
1150 ((min_ifg << IPGIFG_MINIMUM_IFG_ENFORCEMENT_SHIFT) &
1151 IPGIFG_MIN_IFG_MASK);
1152 value |= (btb_ipg & IPGIFG_BTB_IPG_MASK);
1153
1154 out_be32(ipgifg_register, value);
1155 return 0;
1156}
1157
Li Yangac421852007-07-19 11:47:47 +08001158int init_flow_control_params(u32 automatic_flow_control_mode,
Li Yangce973b12006-08-14 23:00:11 -07001159 int rx_flow_control_enable,
1160 int tx_flow_control_enable,
1161 u16 pause_period,
1162 u16 extension_field,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001163 u32 __iomem *upsmr_register,
1164 u32 __iomem *uempr_register,
1165 u32 __iomem *maccfg1_register)
Li Yangce973b12006-08-14 23:00:11 -07001166{
1167 u32 value = 0;
1168
1169 /* Set UEMPR register */
1170 value = (u32) pause_period << UEMPR_PAUSE_TIME_VALUE_SHIFT;
1171 value |= (u32) extension_field << UEMPR_EXTENDED_PAUSE_TIME_VALUE_SHIFT;
1172 out_be32(uempr_register, value);
1173
1174 /* Set UPSMR register */
Timur Tabi3bc53422009-01-11 00:25:21 -08001175 setbits32(upsmr_register, automatic_flow_control_mode);
Li Yangce973b12006-08-14 23:00:11 -07001176
1177 value = in_be32(maccfg1_register);
1178 if (rx_flow_control_enable)
1179 value |= MACCFG1_FLOW_RX;
1180 if (tx_flow_control_enable)
1181 value |= MACCFG1_FLOW_TX;
1182 out_be32(maccfg1_register, value);
1183
1184 return 0;
1185}
1186
1187static int init_hw_statistics_gathering_mode(int enable_hardware_statistics,
1188 int auto_zero_hardware_statistics,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001189 u32 __iomem *upsmr_register,
1190 u16 __iomem *uescr_register)
Li Yangce973b12006-08-14 23:00:11 -07001191{
Li Yangce973b12006-08-14 23:00:11 -07001192 u16 uescr_value = 0;
Timur Tabi3bc53422009-01-11 00:25:21 -08001193
Li Yangce973b12006-08-14 23:00:11 -07001194 /* Enable hardware statistics gathering if requested */
Timur Tabi3bc53422009-01-11 00:25:21 -08001195 if (enable_hardware_statistics)
1196 setbits32(upsmr_register, UCC_GETH_UPSMR_HSE);
Li Yangce973b12006-08-14 23:00:11 -07001197
1198 /* Clear hardware statistics counters */
1199 uescr_value = in_be16(uescr_register);
1200 uescr_value |= UESCR_CLRCNT;
1201 /* Automatically zero hardware statistics counters on read,
1202 if requested */
1203 if (auto_zero_hardware_statistics)
1204 uescr_value |= UESCR_AUTOZ;
1205 out_be16(uescr_register, uescr_value);
1206
1207 return 0;
1208}
1209
1210static int init_firmware_statistics_gathering_mode(int
1211 enable_tx_firmware_statistics,
1212 int enable_rx_firmware_statistics,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001213 u32 __iomem *tx_rmon_base_ptr,
Li Yangce973b12006-08-14 23:00:11 -07001214 u32 tx_firmware_statistics_structure_address,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001215 u32 __iomem *rx_rmon_base_ptr,
Li Yangce973b12006-08-14 23:00:11 -07001216 u32 rx_firmware_statistics_structure_address,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001217 u16 __iomem *temoder_register,
1218 u32 __iomem *remoder_register)
Li Yangce973b12006-08-14 23:00:11 -07001219{
1220 /* Note: this function does not check if */
1221 /* the parameters it receives are NULL */
Li Yangce973b12006-08-14 23:00:11 -07001222
1223 if (enable_tx_firmware_statistics) {
1224 out_be32(tx_rmon_base_ptr,
1225 tx_firmware_statistics_structure_address);
Timur Tabi3bc53422009-01-11 00:25:21 -08001226 setbits16(temoder_register, TEMODER_TX_RMON_STATISTICS_ENABLE);
Li Yangce973b12006-08-14 23:00:11 -07001227 }
1228
1229 if (enable_rx_firmware_statistics) {
1230 out_be32(rx_rmon_base_ptr,
1231 rx_firmware_statistics_structure_address);
Timur Tabi3bc53422009-01-11 00:25:21 -08001232 setbits32(remoder_register, REMODER_RX_RMON_STATISTICS_ENABLE);
Li Yangce973b12006-08-14 23:00:11 -07001233 }
1234
1235 return 0;
1236}
1237
1238static int init_mac_station_addr_regs(u8 address_byte_0,
1239 u8 address_byte_1,
1240 u8 address_byte_2,
1241 u8 address_byte_3,
1242 u8 address_byte_4,
1243 u8 address_byte_5,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001244 u32 __iomem *macstnaddr1_register,
1245 u32 __iomem *macstnaddr2_register)
Li Yangce973b12006-08-14 23:00:11 -07001246{
1247 u32 value = 0;
1248
1249 /* Example: for a station address of 0x12345678ABCD, */
1250 /* 0x12 is byte 0, 0x34 is byte 1 and so on and 0xCD is byte 5 */
1251
1252 /* MACSTNADDR1 Register: */
1253
1254 /* 0 7 8 15 */
1255 /* station address byte 5 station address byte 4 */
1256 /* 16 23 24 31 */
1257 /* station address byte 3 station address byte 2 */
1258 value |= (u32) ((address_byte_2 << 0) & 0x000000FF);
1259 value |= (u32) ((address_byte_3 << 8) & 0x0000FF00);
1260 value |= (u32) ((address_byte_4 << 16) & 0x00FF0000);
1261 value |= (u32) ((address_byte_5 << 24) & 0xFF000000);
1262
1263 out_be32(macstnaddr1_register, value);
1264
1265 /* MACSTNADDR2 Register: */
1266
1267 /* 0 7 8 15 */
1268 /* station address byte 1 station address byte 0 */
1269 /* 16 23 24 31 */
1270 /* reserved reserved */
1271 value = 0;
1272 value |= (u32) ((address_byte_0 << 16) & 0x00FF0000);
1273 value |= (u32) ((address_byte_1 << 24) & 0xFF000000);
1274
1275 out_be32(macstnaddr2_register, value);
1276
1277 return 0;
1278}
1279
Li Yangce973b12006-08-14 23:00:11 -07001280static int init_check_frame_length_mode(int length_check,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001281 u32 __iomem *maccfg2_register)
Li Yangce973b12006-08-14 23:00:11 -07001282{
1283 u32 value = 0;
1284
1285 value = in_be32(maccfg2_register);
1286
1287 if (length_check)
1288 value |= MACCFG2_LC;
1289 else
1290 value &= ~MACCFG2_LC;
1291
1292 out_be32(maccfg2_register, value);
1293 return 0;
1294}
1295
1296static int init_preamble_length(u8 preamble_length,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001297 u32 __iomem *maccfg2_register)
Li Yangce973b12006-08-14 23:00:11 -07001298{
Li Yangce973b12006-08-14 23:00:11 -07001299 if ((preamble_length < 3) || (preamble_length > 7))
1300 return -EINVAL;
1301
Timur Tabi3bc53422009-01-11 00:25:21 -08001302 clrsetbits_be32(maccfg2_register, MACCFG2_PREL_MASK,
1303 preamble_length << MACCFG2_PREL_SHIFT);
1304
Li Yangce973b12006-08-14 23:00:11 -07001305 return 0;
1306}
1307
Li Yangce973b12006-08-14 23:00:11 -07001308static int init_rx_parameters(int reject_broadcast,
1309 int receive_short_frames,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001310 int promiscuous, u32 __iomem *upsmr_register)
Li Yangce973b12006-08-14 23:00:11 -07001311{
1312 u32 value = 0;
1313
1314 value = in_be32(upsmr_register);
1315
1316 if (reject_broadcast)
Timur Tabi3bc53422009-01-11 00:25:21 -08001317 value |= UCC_GETH_UPSMR_BRO;
Li Yangce973b12006-08-14 23:00:11 -07001318 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001319 value &= ~UCC_GETH_UPSMR_BRO;
Li Yangce973b12006-08-14 23:00:11 -07001320
1321 if (receive_short_frames)
Timur Tabi3bc53422009-01-11 00:25:21 -08001322 value |= UCC_GETH_UPSMR_RSH;
Li Yangce973b12006-08-14 23:00:11 -07001323 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001324 value &= ~UCC_GETH_UPSMR_RSH;
Li Yangce973b12006-08-14 23:00:11 -07001325
1326 if (promiscuous)
Timur Tabi3bc53422009-01-11 00:25:21 -08001327 value |= UCC_GETH_UPSMR_PRO;
Li Yangce973b12006-08-14 23:00:11 -07001328 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001329 value &= ~UCC_GETH_UPSMR_PRO;
Li Yangce973b12006-08-14 23:00:11 -07001330
1331 out_be32(upsmr_register, value);
1332
1333 return 0;
1334}
1335
1336static int init_max_rx_buff_len(u16 max_rx_buf_len,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001337 u16 __iomem *mrblr_register)
Li Yangce973b12006-08-14 23:00:11 -07001338{
1339 /* max_rx_buf_len value must be a multiple of 128 */
1340 if ((max_rx_buf_len == 0)
1341 || (max_rx_buf_len % UCC_GETH_MRBLR_ALIGNMENT))
1342 return -EINVAL;
1343
1344 out_be16(mrblr_register, max_rx_buf_len);
1345 return 0;
1346}
1347
1348static int init_min_frame_len(u16 min_frame_length,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001349 u16 __iomem *minflr_register,
1350 u16 __iomem *mrblr_register)
Li Yangce973b12006-08-14 23:00:11 -07001351{
1352 u16 mrblr_value = 0;
1353
1354 mrblr_value = in_be16(mrblr_register);
1355 if (min_frame_length >= (mrblr_value - 4))
1356 return -EINVAL;
1357
1358 out_be16(minflr_register, min_frame_length);
1359 return 0;
1360}
1361
Li Yang18a8e862006-10-19 21:07:34 -05001362static int adjust_enet_interface(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001363{
Li Yang18a8e862006-10-19 21:07:34 -05001364 struct ucc_geth_info *ug_info;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001365 struct ucc_geth __iomem *ug_regs;
1366 struct ucc_fast __iomem *uf_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001367 int ret_val;
1368 u32 upsmr, maccfg2, tbiBaseAddress;
Li Yangce973b12006-08-14 23:00:11 -07001369 u16 value;
1370
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001371 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07001372
1373 ug_info = ugeth->ug_info;
1374 ug_regs = ugeth->ug_regs;
1375 uf_regs = ugeth->uccf->uf_regs;
1376
Li Yangce973b12006-08-14 23:00:11 -07001377 /* Set MACCFG2 */
1378 maccfg2 = in_be32(&ug_regs->maccfg2);
1379 maccfg2 &= ~MACCFG2_INTERFACE_MODE_MASK;
Kim Phillips728de4c92007-04-13 01:26:03 -05001380 if ((ugeth->max_speed == SPEED_10) ||
1381 (ugeth->max_speed == SPEED_100))
Li Yangce973b12006-08-14 23:00:11 -07001382 maccfg2 |= MACCFG2_INTERFACE_MODE_NIBBLE;
Kim Phillips728de4c92007-04-13 01:26:03 -05001383 else if (ugeth->max_speed == SPEED_1000)
Li Yangce973b12006-08-14 23:00:11 -07001384 maccfg2 |= MACCFG2_INTERFACE_MODE_BYTE;
1385 maccfg2 |= ug_info->padAndCrc;
1386 out_be32(&ug_regs->maccfg2, maccfg2);
1387
1388 /* Set UPSMR */
1389 upsmr = in_be32(&uf_regs->upsmr);
Timur Tabi3bc53422009-01-11 00:25:21 -08001390 upsmr &= ~(UCC_GETH_UPSMR_RPM | UCC_GETH_UPSMR_R10M |
1391 UCC_GETH_UPSMR_TBIM | UCC_GETH_UPSMR_RMM);
Kim Phillips728de4c92007-04-13 01:26:03 -05001392 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
1393 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
1394 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06001395 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
1396 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
Kim Phillips728de4c92007-04-13 01:26:03 -05001397 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
Timur Tabi3bc53422009-01-11 00:25:21 -08001398 upsmr |= UCC_GETH_UPSMR_RPM;
Kim Phillips728de4c92007-04-13 01:26:03 -05001399 switch (ugeth->max_speed) {
1400 case SPEED_10:
Timur Tabi3bc53422009-01-11 00:25:21 -08001401 upsmr |= UCC_GETH_UPSMR_R10M;
Kim Phillips728de4c92007-04-13 01:26:03 -05001402 /* FALLTHROUGH */
1403 case SPEED_100:
1404 if (ugeth->phy_interface != PHY_INTERFACE_MODE_RTBI)
Timur Tabi3bc53422009-01-11 00:25:21 -08001405 upsmr |= UCC_GETH_UPSMR_RMM;
Kim Phillips728de4c92007-04-13 01:26:03 -05001406 }
1407 }
1408 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_TBI) ||
1409 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
Timur Tabi3bc53422009-01-11 00:25:21 -08001410 upsmr |= UCC_GETH_UPSMR_TBIM;
Kim Phillips728de4c92007-04-13 01:26:03 -05001411 }
Li Yangce973b12006-08-14 23:00:11 -07001412 out_be32(&uf_regs->upsmr, upsmr);
1413
Li Yangce973b12006-08-14 23:00:11 -07001414 /* Disable autonegotiation in tbi mode, because by default it
1415 comes up in autonegotiation mode. */
1416 /* Note that this depends on proper setting in utbipar register. */
Kim Phillips728de4c92007-04-13 01:26:03 -05001417 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_TBI) ||
1418 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
Li Yangce973b12006-08-14 23:00:11 -07001419 tbiBaseAddress = in_be32(&ug_regs->utbipar);
1420 tbiBaseAddress &= UTBIPAR_PHY_ADDRESS_MASK;
1421 tbiBaseAddress >>= UTBIPAR_PHY_ADDRESS_SHIFT;
Kim Phillips728de4c92007-04-13 01:26:03 -05001422 value = ugeth->phydev->bus->read(ugeth->phydev->bus,
1423 (u8) tbiBaseAddress, ENET_TBI_MII_CR);
Li Yangce973b12006-08-14 23:00:11 -07001424 value &= ~0x1000; /* Turn off autonegotiation */
Kim Phillips728de4c92007-04-13 01:26:03 -05001425 ugeth->phydev->bus->write(ugeth->phydev->bus,
1426 (u8) tbiBaseAddress, ENET_TBI_MII_CR, value);
Li Yangce973b12006-08-14 23:00:11 -07001427 }
1428
1429 init_check_frame_length_mode(ug_info->lengthCheckRx, &ug_regs->maccfg2);
1430
1431 ret_val = init_preamble_length(ug_info->prel, &ug_regs->maccfg2);
1432 if (ret_val != 0) {
Li Yang890de952007-07-19 11:48:29 +08001433 if (netif_msg_probe(ugeth))
1434 ugeth_err("%s: Preamble length must be between 3 and 7 inclusive.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001435 __func__);
Li Yangce973b12006-08-14 23:00:11 -07001436 return ret_val;
1437 }
1438
1439 return 0;
1440}
1441
1442/* Called every time the controller might need to be made
1443 * aware of new link state. The PHY code conveys this
1444 * information through variables in the ugeth structure, and this
1445 * function converts those variables into the appropriate
1446 * register values, and can bring down the device if needed.
1447 */
Kim Phillips728de4c92007-04-13 01:26:03 -05001448
Li Yangce973b12006-08-14 23:00:11 -07001449static void adjust_link(struct net_device *dev)
1450{
Li Yang18a8e862006-10-19 21:07:34 -05001451 struct ucc_geth_private *ugeth = netdev_priv(dev);
Andy Fleming6fee40e2008-05-02 13:01:23 -05001452 struct ucc_geth __iomem *ug_regs;
1453 struct ucc_fast __iomem *uf_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001454 struct phy_device *phydev = ugeth->phydev;
1455 unsigned long flags;
1456 int new_state = 0;
Li Yangce973b12006-08-14 23:00:11 -07001457
1458 ug_regs = ugeth->ug_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001459 uf_regs = ugeth->uccf->uf_regs;
Li Yangce973b12006-08-14 23:00:11 -07001460
Kim Phillips728de4c92007-04-13 01:26:03 -05001461 spin_lock_irqsave(&ugeth->lock, flags);
1462
1463 if (phydev->link) {
1464 u32 tempval = in_be32(&ug_regs->maccfg2);
1465 u32 upsmr = in_be32(&uf_regs->upsmr);
Li Yangce973b12006-08-14 23:00:11 -07001466 /* Now we make sure that we can be in full duplex mode.
1467 * If not, we operate in half-duplex mode. */
Kim Phillips728de4c92007-04-13 01:26:03 -05001468 if (phydev->duplex != ugeth->oldduplex) {
1469 new_state = 1;
1470 if (!(phydev->duplex))
Li Yangce973b12006-08-14 23:00:11 -07001471 tempval &= ~(MACCFG2_FDX);
Kim Phillips728de4c92007-04-13 01:26:03 -05001472 else
Li Yangce973b12006-08-14 23:00:11 -07001473 tempval |= MACCFG2_FDX;
Kim Phillips728de4c92007-04-13 01:26:03 -05001474 ugeth->oldduplex = phydev->duplex;
Li Yangce973b12006-08-14 23:00:11 -07001475 }
1476
Kim Phillips728de4c92007-04-13 01:26:03 -05001477 if (phydev->speed != ugeth->oldspeed) {
1478 new_state = 1;
1479 switch (phydev->speed) {
1480 case SPEED_1000:
1481 tempval = ((tempval &
1482 ~(MACCFG2_INTERFACE_MODE_MASK)) |
1483 MACCFG2_INTERFACE_MODE_BYTE);
Li Yangce973b12006-08-14 23:00:11 -07001484 break;
Kim Phillips728de4c92007-04-13 01:26:03 -05001485 case SPEED_100:
1486 case SPEED_10:
1487 tempval = ((tempval &
1488 ~(MACCFG2_INTERFACE_MODE_MASK)) |
1489 MACCFG2_INTERFACE_MODE_NIBBLE);
1490 /* if reduced mode, re-set UPSMR.R10M */
1491 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
1492 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
1493 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06001494 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
1495 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
Kim Phillips728de4c92007-04-13 01:26:03 -05001496 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
1497 if (phydev->speed == SPEED_10)
Timur Tabi3bc53422009-01-11 00:25:21 -08001498 upsmr |= UCC_GETH_UPSMR_R10M;
Kim Phillips728de4c92007-04-13 01:26:03 -05001499 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001500 upsmr &= ~UCC_GETH_UPSMR_R10M;
Kim Phillips728de4c92007-04-13 01:26:03 -05001501 }
Li Yangce973b12006-08-14 23:00:11 -07001502 break;
1503 default:
Kim Phillips728de4c92007-04-13 01:26:03 -05001504 if (netif_msg_link(ugeth))
1505 ugeth_warn(
1506 "%s: Ack! Speed (%d) is not 10/100/1000!",
1507 dev->name, phydev->speed);
Li Yangce973b12006-08-14 23:00:11 -07001508 break;
1509 }
Kim Phillips728de4c92007-04-13 01:26:03 -05001510 ugeth->oldspeed = phydev->speed;
Li Yangce973b12006-08-14 23:00:11 -07001511 }
1512
Kim Phillips728de4c92007-04-13 01:26:03 -05001513 out_be32(&ug_regs->maccfg2, tempval);
1514 out_be32(&uf_regs->upsmr, upsmr);
1515
Li Yangce973b12006-08-14 23:00:11 -07001516 if (!ugeth->oldlink) {
Kim Phillips728de4c92007-04-13 01:26:03 -05001517 new_state = 1;
Li Yangce973b12006-08-14 23:00:11 -07001518 ugeth->oldlink = 1;
Li Yangce973b12006-08-14 23:00:11 -07001519 }
Kim Phillips728de4c92007-04-13 01:26:03 -05001520 } else if (ugeth->oldlink) {
1521 new_state = 1;
Li Yangce973b12006-08-14 23:00:11 -07001522 ugeth->oldlink = 0;
1523 ugeth->oldspeed = 0;
1524 ugeth->oldduplex = -1;
Li Yangce973b12006-08-14 23:00:11 -07001525 }
Kim Phillips728de4c92007-04-13 01:26:03 -05001526
1527 if (new_state && netif_msg_link(ugeth))
1528 phy_print_status(phydev);
1529
1530 spin_unlock_irqrestore(&ugeth->lock, flags);
Li Yangce973b12006-08-14 23:00:11 -07001531}
1532
1533/* Configure the PHY for dev.
1534 * returns 0 if success. -1 if failure
1535 */
1536static int init_phy(struct net_device *dev)
1537{
Kim Phillips728de4c92007-04-13 01:26:03 -05001538 struct ucc_geth_private *priv = netdev_priv(dev);
Anton Vorontsov61fa9dc2009-03-22 21:30:52 -07001539 struct ucc_geth_info *ug_info = priv->ug_info;
Kim Phillips728de4c92007-04-13 01:26:03 -05001540 struct phy_device *phydev;
Li Yangce973b12006-08-14 23:00:11 -07001541
Kim Phillips728de4c92007-04-13 01:26:03 -05001542 priv->oldlink = 0;
1543 priv->oldspeed = 0;
1544 priv->oldduplex = -1;
Li Yangce973b12006-08-14 23:00:11 -07001545
Anton Vorontsov61fa9dc2009-03-22 21:30:52 -07001546 phydev = phy_connect(dev, ug_info->phy_bus_id, &adjust_link, 0,
1547 priv->phy_interface);
Li Yangce973b12006-08-14 23:00:11 -07001548
Kim Phillips728de4c92007-04-13 01:26:03 -05001549 if (IS_ERR(phydev)) {
1550 printk("%s: Could not attach to PHY\n", dev->name);
1551 return PTR_ERR(phydev);
Li Yangce973b12006-08-14 23:00:11 -07001552 }
1553
Kim Phillips728de4c92007-04-13 01:26:03 -05001554 phydev->supported &= (ADVERTISED_10baseT_Half |
Li Yangce973b12006-08-14 23:00:11 -07001555 ADVERTISED_10baseT_Full |
1556 ADVERTISED_100baseT_Half |
Kim Phillips728de4c92007-04-13 01:26:03 -05001557 ADVERTISED_100baseT_Full);
Li Yangce973b12006-08-14 23:00:11 -07001558
Kim Phillips728de4c92007-04-13 01:26:03 -05001559 if (priv->max_speed == SPEED_1000)
1560 phydev->supported |= ADVERTISED_1000baseT_Full;
Li Yangce973b12006-08-14 23:00:11 -07001561
Kim Phillips728de4c92007-04-13 01:26:03 -05001562 phydev->advertising = phydev->supported;
Li Yangce973b12006-08-14 23:00:11 -07001563
Kim Phillips728de4c92007-04-13 01:26:03 -05001564 priv->phydev = phydev;
Li Yangce973b12006-08-14 23:00:11 -07001565
1566 return 0;
Li Yangce973b12006-08-14 23:00:11 -07001567}
1568
Kim Phillips728de4c92007-04-13 01:26:03 -05001569
Li Yangce973b12006-08-14 23:00:11 -07001570
Li Yang18a8e862006-10-19 21:07:34 -05001571static int ugeth_graceful_stop_tx(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001572{
Li Yang18a8e862006-10-19 21:07:34 -05001573 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001574 u32 cecr_subblock;
1575 u32 temp;
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001576 int i = 10;
Li Yangce973b12006-08-14 23:00:11 -07001577
1578 uccf = ugeth->uccf;
1579
1580 /* Mask GRACEFUL STOP TX interrupt bit and clear it */
Timur Tabi3bc53422009-01-11 00:25:21 -08001581 clrbits32(uccf->p_uccm, UCC_GETH_UCCE_GRA);
1582 out_be32(uccf->p_ucce, UCC_GETH_UCCE_GRA); /* clear by writing 1 */
Li Yangce973b12006-08-14 23:00:11 -07001583
1584 /* Issue host command */
1585 cecr_subblock =
1586 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1587 qe_issue_cmd(QE_GRACEFUL_STOP_TX, cecr_subblock,
Li Yang18a8e862006-10-19 21:07:34 -05001588 QE_CR_PROTOCOL_ETHERNET, 0);
Li Yangce973b12006-08-14 23:00:11 -07001589
1590 /* Wait for command to complete */
1591 do {
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001592 msleep(10);
Li Yangce973b12006-08-14 23:00:11 -07001593 temp = in_be32(uccf->p_ucce);
Timur Tabi3bc53422009-01-11 00:25:21 -08001594 } while (!(temp & UCC_GETH_UCCE_GRA) && --i);
Li Yangce973b12006-08-14 23:00:11 -07001595
1596 uccf->stopped_tx = 1;
1597
1598 return 0;
1599}
1600
Li Yang18a8e862006-10-19 21:07:34 -05001601static int ugeth_graceful_stop_rx(struct ucc_geth_private * ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001602{
Li Yang18a8e862006-10-19 21:07:34 -05001603 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001604 u32 cecr_subblock;
1605 u8 temp;
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001606 int i = 10;
Li Yangce973b12006-08-14 23:00:11 -07001607
1608 uccf = ugeth->uccf;
1609
1610 /* Clear acknowledge bit */
Andy Fleming6fee40e2008-05-02 13:01:23 -05001611 temp = in_8(&ugeth->p_rx_glbl_pram->rxgstpack);
Li Yangce973b12006-08-14 23:00:11 -07001612 temp &= ~GRACEFUL_STOP_ACKNOWLEDGE_RX;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001613 out_8(&ugeth->p_rx_glbl_pram->rxgstpack, temp);
Li Yangce973b12006-08-14 23:00:11 -07001614
1615 /* Keep issuing command and checking acknowledge bit until
1616 it is asserted, according to spec */
1617 do {
1618 /* Issue host command */
1619 cecr_subblock =
1620 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.
1621 ucc_num);
1622 qe_issue_cmd(QE_GRACEFUL_STOP_RX, cecr_subblock,
Li Yang18a8e862006-10-19 21:07:34 -05001623 QE_CR_PROTOCOL_ETHERNET, 0);
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001624 msleep(10);
Andy Fleming6fee40e2008-05-02 13:01:23 -05001625 temp = in_8(&ugeth->p_rx_glbl_pram->rxgstpack);
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001626 } while (!(temp & GRACEFUL_STOP_ACKNOWLEDGE_RX) && --i);
Li Yangce973b12006-08-14 23:00:11 -07001627
1628 uccf->stopped_rx = 1;
1629
1630 return 0;
1631}
1632
Li Yang18a8e862006-10-19 21:07:34 -05001633static int ugeth_restart_tx(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001634{
Li Yang18a8e862006-10-19 21:07:34 -05001635 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001636 u32 cecr_subblock;
1637
1638 uccf = ugeth->uccf;
1639
1640 cecr_subblock =
1641 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
Li Yang18a8e862006-10-19 21:07:34 -05001642 qe_issue_cmd(QE_RESTART_TX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET, 0);
Li Yangce973b12006-08-14 23:00:11 -07001643 uccf->stopped_tx = 0;
1644
1645 return 0;
1646}
1647
Li Yang18a8e862006-10-19 21:07:34 -05001648static int ugeth_restart_rx(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001649{
Li Yang18a8e862006-10-19 21:07:34 -05001650 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001651 u32 cecr_subblock;
1652
1653 uccf = ugeth->uccf;
1654
1655 cecr_subblock =
1656 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
Li Yang18a8e862006-10-19 21:07:34 -05001657 qe_issue_cmd(QE_RESTART_RX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
Li Yangce973b12006-08-14 23:00:11 -07001658 0);
1659 uccf->stopped_rx = 0;
1660
1661 return 0;
1662}
1663
Li Yang18a8e862006-10-19 21:07:34 -05001664static int ugeth_enable(struct ucc_geth_private *ugeth, enum comm_dir mode)
Li Yangce973b12006-08-14 23:00:11 -07001665{
Li Yang18a8e862006-10-19 21:07:34 -05001666 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001667 int enabled_tx, enabled_rx;
1668
1669 uccf = ugeth->uccf;
1670
1671 /* check if the UCC number is in range. */
1672 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
Li Yang890de952007-07-19 11:48:29 +08001673 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001674 ugeth_err("%s: ucc_num out of range.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07001675 return -EINVAL;
1676 }
1677
1678 enabled_tx = uccf->enabled_tx;
1679 enabled_rx = uccf->enabled_rx;
1680
1681 /* Get Tx and Rx going again, in case this channel was actively
1682 disabled. */
1683 if ((mode & COMM_DIR_TX) && (!enabled_tx) && uccf->stopped_tx)
1684 ugeth_restart_tx(ugeth);
1685 if ((mode & COMM_DIR_RX) && (!enabled_rx) && uccf->stopped_rx)
1686 ugeth_restart_rx(ugeth);
1687
1688 ucc_fast_enable(uccf, mode); /* OK to do even if not disabled */
1689
1690 return 0;
1691
1692}
1693
Li Yang18a8e862006-10-19 21:07:34 -05001694static int ugeth_disable(struct ucc_geth_private * ugeth, enum comm_dir mode)
Li Yangce973b12006-08-14 23:00:11 -07001695{
Li Yang18a8e862006-10-19 21:07:34 -05001696 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001697
1698 uccf = ugeth->uccf;
1699
1700 /* check if the UCC number is in range. */
1701 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
Li Yang890de952007-07-19 11:48:29 +08001702 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001703 ugeth_err("%s: ucc_num out of range.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07001704 return -EINVAL;
1705 }
1706
1707 /* Stop any transmissions */
1708 if ((mode & COMM_DIR_TX) && uccf->enabled_tx && !uccf->stopped_tx)
1709 ugeth_graceful_stop_tx(ugeth);
1710
1711 /* Stop any receptions */
1712 if ((mode & COMM_DIR_RX) && uccf->enabled_rx && !uccf->stopped_rx)
1713 ugeth_graceful_stop_rx(ugeth);
1714
1715 ucc_fast_disable(ugeth->uccf, mode); /* OK to do even if not enabled */
1716
1717 return 0;
1718}
1719
Li Yang18a8e862006-10-19 21:07:34 -05001720static void ugeth_dump_regs(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001721{
1722#ifdef DEBUG
1723 ucc_fast_dump_regs(ugeth->uccf);
1724 dump_regs(ugeth);
1725 dump_bds(ugeth);
1726#endif
1727}
1728
Li Yang18a8e862006-10-19 21:07:34 -05001729static int ugeth_82xx_filtering_clear_all_addr_in_hash(struct ucc_geth_private *
Li Yangce973b12006-08-14 23:00:11 -07001730 ugeth,
Li Yang18a8e862006-10-19 21:07:34 -05001731 enum enet_addr_type
Li Yangce973b12006-08-14 23:00:11 -07001732 enet_addr_type)
1733{
Andy Fleming6fee40e2008-05-02 13:01:23 -05001734 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Li Yang18a8e862006-10-19 21:07:34 -05001735 struct ucc_fast_private *uccf;
1736 enum comm_dir comm_dir;
Li Yangce973b12006-08-14 23:00:11 -07001737 struct list_head *p_lh;
1738 u16 i, num;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001739 u32 __iomem *addr_h;
1740 u32 __iomem *addr_l;
Li Yangce973b12006-08-14 23:00:11 -07001741 u8 *p_counter;
1742
1743 uccf = ugeth->uccf;
1744
1745 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -05001746 (struct ucc_geth_82xx_address_filtering_pram __iomem *)
1747 ugeth->p_rx_glbl_pram->addressfiltering;
Li Yangce973b12006-08-14 23:00:11 -07001748
1749 if (enet_addr_type == ENET_ADDR_TYPE_GROUP) {
1750 addr_h = &(p_82xx_addr_filt->gaddr_h);
1751 addr_l = &(p_82xx_addr_filt->gaddr_l);
1752 p_lh = &ugeth->group_hash_q;
1753 p_counter = &(ugeth->numGroupAddrInHash);
1754 } else if (enet_addr_type == ENET_ADDR_TYPE_INDIVIDUAL) {
1755 addr_h = &(p_82xx_addr_filt->iaddr_h);
1756 addr_l = &(p_82xx_addr_filt->iaddr_l);
1757 p_lh = &ugeth->ind_hash_q;
1758 p_counter = &(ugeth->numIndAddrInHash);
1759 } else
1760 return -EINVAL;
1761
1762 comm_dir = 0;
1763 if (uccf->enabled_tx)
1764 comm_dir |= COMM_DIR_TX;
1765 if (uccf->enabled_rx)
1766 comm_dir |= COMM_DIR_RX;
1767 if (comm_dir)
1768 ugeth_disable(ugeth, comm_dir);
1769
1770 /* Clear the hash table. */
1771 out_be32(addr_h, 0x00000000);
1772 out_be32(addr_l, 0x00000000);
1773
1774 if (!p_lh)
1775 return 0;
1776
1777 num = *p_counter;
1778
1779 /* Delete all remaining CQ elements */
1780 for (i = 0; i < num; i++)
1781 put_enet_addr_container(ENET_ADDR_CONT_ENTRY(dequeue(p_lh)));
1782
1783 *p_counter = 0;
1784
1785 if (comm_dir)
1786 ugeth_enable(ugeth, comm_dir);
1787
1788 return 0;
1789}
1790
Li Yang18a8e862006-10-19 21:07:34 -05001791static int ugeth_82xx_filtering_clear_addr_in_paddr(struct ucc_geth_private *ugeth,
Li Yangce973b12006-08-14 23:00:11 -07001792 u8 paddr_num)
1793{
1794 ugeth->indAddrRegUsed[paddr_num] = 0; /* mark this paddr as not used */
1795 return hw_clear_addr_in_paddr(ugeth, paddr_num);/* clear in hardware */
1796}
1797
Li Yang18a8e862006-10-19 21:07:34 -05001798static void ucc_geth_memclean(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001799{
1800 u16 i, j;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001801 u8 __iomem *bd;
Li Yangce973b12006-08-14 23:00:11 -07001802
1803 if (!ugeth)
1804 return;
1805
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03001806 if (ugeth->uccf) {
Li Yangce973b12006-08-14 23:00:11 -07001807 ucc_fast_free(ugeth->uccf);
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03001808 ugeth->uccf = NULL;
1809 }
Li Yangce973b12006-08-14 23:00:11 -07001810
1811 if (ugeth->p_thread_data_tx) {
1812 qe_muram_free(ugeth->thread_dat_tx_offset);
1813 ugeth->p_thread_data_tx = NULL;
1814 }
1815 if (ugeth->p_thread_data_rx) {
1816 qe_muram_free(ugeth->thread_dat_rx_offset);
1817 ugeth->p_thread_data_rx = NULL;
1818 }
1819 if (ugeth->p_exf_glbl_param) {
1820 qe_muram_free(ugeth->exf_glbl_param_offset);
1821 ugeth->p_exf_glbl_param = NULL;
1822 }
1823 if (ugeth->p_rx_glbl_pram) {
1824 qe_muram_free(ugeth->rx_glbl_pram_offset);
1825 ugeth->p_rx_glbl_pram = NULL;
1826 }
1827 if (ugeth->p_tx_glbl_pram) {
1828 qe_muram_free(ugeth->tx_glbl_pram_offset);
1829 ugeth->p_tx_glbl_pram = NULL;
1830 }
1831 if (ugeth->p_send_q_mem_reg) {
1832 qe_muram_free(ugeth->send_q_mem_reg_offset);
1833 ugeth->p_send_q_mem_reg = NULL;
1834 }
1835 if (ugeth->p_scheduler) {
1836 qe_muram_free(ugeth->scheduler_offset);
1837 ugeth->p_scheduler = NULL;
1838 }
1839 if (ugeth->p_tx_fw_statistics_pram) {
1840 qe_muram_free(ugeth->tx_fw_statistics_pram_offset);
1841 ugeth->p_tx_fw_statistics_pram = NULL;
1842 }
1843 if (ugeth->p_rx_fw_statistics_pram) {
1844 qe_muram_free(ugeth->rx_fw_statistics_pram_offset);
1845 ugeth->p_rx_fw_statistics_pram = NULL;
1846 }
1847 if (ugeth->p_rx_irq_coalescing_tbl) {
1848 qe_muram_free(ugeth->rx_irq_coalescing_tbl_offset);
1849 ugeth->p_rx_irq_coalescing_tbl = NULL;
1850 }
1851 if (ugeth->p_rx_bd_qs_tbl) {
1852 qe_muram_free(ugeth->rx_bd_qs_tbl_offset);
1853 ugeth->p_rx_bd_qs_tbl = NULL;
1854 }
1855 if (ugeth->p_init_enet_param_shadow) {
1856 return_init_enet_entries(ugeth,
1857 &(ugeth->p_init_enet_param_shadow->
1858 rxthread[0]),
1859 ENET_INIT_PARAM_MAX_ENTRIES_RX,
1860 ugeth->ug_info->riscRx, 1);
1861 return_init_enet_entries(ugeth,
1862 &(ugeth->p_init_enet_param_shadow->
1863 txthread[0]),
1864 ENET_INIT_PARAM_MAX_ENTRIES_TX,
1865 ugeth->ug_info->riscTx, 0);
1866 kfree(ugeth->p_init_enet_param_shadow);
1867 ugeth->p_init_enet_param_shadow = NULL;
1868 }
1869 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
1870 bd = ugeth->p_tx_bd_ring[i];
Nicu Ioan Petru3a8205e2007-04-13 01:26:29 -05001871 if (!bd)
1872 continue;
Li Yangce973b12006-08-14 23:00:11 -07001873 for (j = 0; j < ugeth->ug_info->bdRingLenTx[i]; j++) {
1874 if (ugeth->tx_skbuff[i][j]) {
Andy Fleming7f802022008-05-15 17:00:21 -05001875 dma_unmap_single(&ugeth->dev->dev,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001876 in_be32(&((struct qe_bd __iomem *)bd)->buf),
1877 (in_be32((u32 __iomem *)bd) &
Li Yangce973b12006-08-14 23:00:11 -07001878 BD_LENGTH_MASK),
1879 DMA_TO_DEVICE);
1880 dev_kfree_skb_any(ugeth->tx_skbuff[i][j]);
1881 ugeth->tx_skbuff[i][j] = NULL;
1882 }
1883 }
1884
1885 kfree(ugeth->tx_skbuff[i]);
1886
1887 if (ugeth->p_tx_bd_ring[i]) {
1888 if (ugeth->ug_info->uf_info.bd_mem_part ==
1889 MEM_PART_SYSTEM)
1890 kfree((void *)ugeth->tx_bd_ring_offset[i]);
1891 else if (ugeth->ug_info->uf_info.bd_mem_part ==
1892 MEM_PART_MURAM)
1893 qe_muram_free(ugeth->tx_bd_ring_offset[i]);
1894 ugeth->p_tx_bd_ring[i] = NULL;
1895 }
1896 }
1897 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
1898 if (ugeth->p_rx_bd_ring[i]) {
1899 /* Return existing data buffers in ring */
1900 bd = ugeth->p_rx_bd_ring[i];
1901 for (j = 0; j < ugeth->ug_info->bdRingLenRx[i]; j++) {
1902 if (ugeth->rx_skbuff[i][j]) {
Andy Fleming7f802022008-05-15 17:00:21 -05001903 dma_unmap_single(&ugeth->dev->dev,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001904 in_be32(&((struct qe_bd __iomem *)bd)->buf),
Li Yang18a8e862006-10-19 21:07:34 -05001905 ugeth->ug_info->
1906 uf_info.max_rx_buf_length +
1907 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
1908 DMA_FROM_DEVICE);
1909 dev_kfree_skb_any(
1910 ugeth->rx_skbuff[i][j]);
Li Yangce973b12006-08-14 23:00:11 -07001911 ugeth->rx_skbuff[i][j] = NULL;
1912 }
Li Yang18a8e862006-10-19 21:07:34 -05001913 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07001914 }
1915
1916 kfree(ugeth->rx_skbuff[i]);
1917
1918 if (ugeth->ug_info->uf_info.bd_mem_part ==
1919 MEM_PART_SYSTEM)
1920 kfree((void *)ugeth->rx_bd_ring_offset[i]);
1921 else if (ugeth->ug_info->uf_info.bd_mem_part ==
1922 MEM_PART_MURAM)
1923 qe_muram_free(ugeth->rx_bd_ring_offset[i]);
1924 ugeth->p_rx_bd_ring[i] = NULL;
1925 }
1926 }
1927 while (!list_empty(&ugeth->group_hash_q))
1928 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
1929 (dequeue(&ugeth->group_hash_q)));
1930 while (!list_empty(&ugeth->ind_hash_q))
1931 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
1932 (dequeue(&ugeth->ind_hash_q)));
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00001933 if (ugeth->ug_regs) {
1934 iounmap(ugeth->ug_regs);
1935 ugeth->ug_regs = NULL;
1936 }
Li Yangce973b12006-08-14 23:00:11 -07001937}
1938
1939static void ucc_geth_set_multi(struct net_device *dev)
1940{
Li Yang18a8e862006-10-19 21:07:34 -05001941 struct ucc_geth_private *ugeth;
Li Yangce973b12006-08-14 23:00:11 -07001942 struct dev_mc_list *dmi;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001943 struct ucc_fast __iomem *uf_regs;
1944 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Joakim Tjernlund9030b3d2007-10-17 11:05:41 +02001945 int i;
Li Yangce973b12006-08-14 23:00:11 -07001946
1947 ugeth = netdev_priv(dev);
1948
1949 uf_regs = ugeth->uccf->uf_regs;
1950
1951 if (dev->flags & IFF_PROMISC) {
Timur Tabi3bc53422009-01-11 00:25:21 -08001952 setbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
Li Yangce973b12006-08-14 23:00:11 -07001953 } else {
Timur Tabi3bc53422009-01-11 00:25:21 -08001954 clrbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
Li Yangce973b12006-08-14 23:00:11 -07001955
1956 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -05001957 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
Li Yangce973b12006-08-14 23:00:11 -07001958 p_rx_glbl_pram->addressfiltering;
1959
1960 if (dev->flags & IFF_ALLMULTI) {
1961 /* Catch all multicast addresses, so set the
1962 * filter to all 1's.
1963 */
1964 out_be32(&p_82xx_addr_filt->gaddr_h, 0xffffffff);
1965 out_be32(&p_82xx_addr_filt->gaddr_l, 0xffffffff);
1966 } else {
1967 /* Clear filter and add the addresses in the list.
1968 */
1969 out_be32(&p_82xx_addr_filt->gaddr_h, 0x0);
1970 out_be32(&p_82xx_addr_filt->gaddr_l, 0x0);
1971
1972 dmi = dev->mc_list;
1973
1974 for (i = 0; i < dev->mc_count; i++, dmi = dmi->next) {
1975
1976 /* Only support group multicast for now.
1977 */
1978 if (!(dmi->dmi_addr[0] & 1))
1979 continue;
1980
Li Yangce973b12006-08-14 23:00:11 -07001981 /* Ask CPM to run CRC and set bit in
1982 * filter mask.
1983 */
Joakim Tjernlund9030b3d2007-10-17 11:05:41 +02001984 hw_add_addr_in_hash(ugeth, dmi->dmi_addr);
Li Yangce973b12006-08-14 23:00:11 -07001985 }
1986 }
1987 }
1988}
1989
Li Yang18a8e862006-10-19 21:07:34 -05001990static void ucc_geth_stop(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001991{
Andy Fleming6fee40e2008-05-02 13:01:23 -05001992 struct ucc_geth __iomem *ug_regs = ugeth->ug_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001993 struct phy_device *phydev = ugeth->phydev;
Li Yangce973b12006-08-14 23:00:11 -07001994
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001995 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07001996
1997 /* Disable the controller */
1998 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
1999
2000 /* Tell the kernel the link is down */
Kim Phillips728de4c92007-04-13 01:26:03 -05002001 phy_stop(phydev);
Li Yangce973b12006-08-14 23:00:11 -07002002
2003 /* Mask all interrupts */
Timur Tabic6f50472007-07-10 07:51:11 -05002004 out_be32(ugeth->uccf->p_uccm, 0x00000000);
Li Yangce973b12006-08-14 23:00:11 -07002005
2006 /* Clear all interrupts */
2007 out_be32(ugeth->uccf->p_ucce, 0xffffffff);
2008
2009 /* Disable Rx and Tx */
Timur Tabi3bc53422009-01-11 00:25:21 -08002010 clrbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
Li Yangce973b12006-08-14 23:00:11 -07002011
Li Yangce973b12006-08-14 23:00:11 -07002012 ucc_geth_memclean(ugeth);
2013}
2014
Kim Phillips728de4c92007-04-13 01:26:03 -05002015static int ucc_struct_init(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07002016{
Li Yang18a8e862006-10-19 21:07:34 -05002017 struct ucc_geth_info *ug_info;
2018 struct ucc_fast_info *uf_info;
Kim Phillips728de4c92007-04-13 01:26:03 -05002019 int i;
Li Yangce973b12006-08-14 23:00:11 -07002020
2021 ug_info = ugeth->ug_info;
2022 uf_info = &ug_info->uf_info;
2023
2024 if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
2025 (uf_info->bd_mem_part == MEM_PART_MURAM))) {
Li Yang890de952007-07-19 11:48:29 +08002026 if (netif_msg_probe(ugeth))
2027 ugeth_err("%s: Bad memory partition value.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002028 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002029 return -EINVAL;
2030 }
2031
2032 /* Rx BD lengths */
2033 for (i = 0; i < ug_info->numQueuesRx; i++) {
2034 if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) ||
2035 (ug_info->bdRingLenRx[i] %
2036 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) {
Li Yang890de952007-07-19 11:48:29 +08002037 if (netif_msg_probe(ugeth))
2038 ugeth_err
2039 ("%s: Rx BD ring length must be multiple of 4, no smaller than 8.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002040 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002041 return -EINVAL;
2042 }
2043 }
2044
2045 /* Tx BD lengths */
2046 for (i = 0; i < ug_info->numQueuesTx; i++) {
2047 if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) {
Li Yang890de952007-07-19 11:48:29 +08002048 if (netif_msg_probe(ugeth))
2049 ugeth_err
2050 ("%s: Tx BD ring length must be no smaller than 2.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002051 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002052 return -EINVAL;
2053 }
2054 }
2055
2056 /* mrblr */
2057 if ((uf_info->max_rx_buf_length == 0) ||
2058 (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) {
Li Yang890de952007-07-19 11:48:29 +08002059 if (netif_msg_probe(ugeth))
2060 ugeth_err
2061 ("%s: max_rx_buf_length must be non-zero multiple of 128.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002062 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002063 return -EINVAL;
2064 }
2065
2066 /* num Tx queues */
2067 if (ug_info->numQueuesTx > NUM_TX_QUEUES) {
Li Yang890de952007-07-19 11:48:29 +08002068 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002069 ugeth_err("%s: number of tx queues too large.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002070 return -EINVAL;
2071 }
2072
2073 /* num Rx queues */
2074 if (ug_info->numQueuesRx > NUM_RX_QUEUES) {
Li Yang890de952007-07-19 11:48:29 +08002075 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002076 ugeth_err("%s: number of rx queues too large.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002077 return -EINVAL;
2078 }
2079
2080 /* l2qt */
2081 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) {
2082 if (ug_info->l2qt[i] >= ug_info->numQueuesRx) {
Li Yang890de952007-07-19 11:48:29 +08002083 if (netif_msg_probe(ugeth))
2084 ugeth_err
2085 ("%s: VLAN priority table entry must not be"
2086 " larger than number of Rx queues.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002087 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002088 return -EINVAL;
2089 }
2090 }
2091
2092 /* l3qt */
2093 for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) {
2094 if (ug_info->l3qt[i] >= ug_info->numQueuesRx) {
Li Yang890de952007-07-19 11:48:29 +08002095 if (netif_msg_probe(ugeth))
2096 ugeth_err
2097 ("%s: IP priority table entry must not be"
2098 " larger than number of Rx queues.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002099 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002100 return -EINVAL;
2101 }
2102 }
2103
2104 if (ug_info->cam && !ug_info->ecamptr) {
Li Yang890de952007-07-19 11:48:29 +08002105 if (netif_msg_probe(ugeth))
2106 ugeth_err("%s: If cam mode is chosen, must supply cam ptr.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002107 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002108 return -EINVAL;
2109 }
2110
2111 if ((ug_info->numStationAddresses !=
2112 UCC_GETH_NUM_OF_STATION_ADDRESSES_1)
2113 && ug_info->rxExtendedFiltering) {
Li Yang890de952007-07-19 11:48:29 +08002114 if (netif_msg_probe(ugeth))
2115 ugeth_err("%s: Number of station addresses greater than 1 "
2116 "not allowed in extended parsing mode.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002117 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002118 return -EINVAL;
2119 }
2120
2121 /* Generate uccm_mask for receive */
2122 uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */
2123 for (i = 0; i < ug_info->numQueuesRx; i++)
Timur Tabi3bc53422009-01-11 00:25:21 -08002124 uf_info->uccm_mask |= (UCC_GETH_UCCE_RXF0 << i);
Li Yangce973b12006-08-14 23:00:11 -07002125
2126 for (i = 0; i < ug_info->numQueuesTx; i++)
Timur Tabi3bc53422009-01-11 00:25:21 -08002127 uf_info->uccm_mask |= (UCC_GETH_UCCE_TXB0 << i);
Li Yangce973b12006-08-14 23:00:11 -07002128 /* Initialize the general fast UCC block. */
Kim Phillips728de4c92007-04-13 01:26:03 -05002129 if (ucc_fast_init(uf_info, &ugeth->uccf)) {
Li Yang890de952007-07-19 11:48:29 +08002130 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002131 ugeth_err("%s: Failed to init uccf.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002132 return -ENOMEM;
2133 }
Kim Phillips728de4c92007-04-13 01:26:03 -05002134
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00002135 ugeth->ug_regs = ioremap(uf_info->regs, sizeof(*ugeth->ug_regs));
2136 if (!ugeth->ug_regs) {
2137 if (netif_msg_probe(ugeth))
2138 ugeth_err("%s: Failed to ioremap regs.", __func__);
2139 return -ENOMEM;
2140 }
Kim Phillips728de4c92007-04-13 01:26:03 -05002141
2142 return 0;
2143}
2144
2145static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2146{
Andy Fleming6fee40e2008-05-02 13:01:23 -05002147 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
2148 struct ucc_geth_init_pram __iomem *p_init_enet_pram;
Kim Phillips728de4c92007-04-13 01:26:03 -05002149 struct ucc_fast_private *uccf;
2150 struct ucc_geth_info *ug_info;
2151 struct ucc_fast_info *uf_info;
Andy Fleming6fee40e2008-05-02 13:01:23 -05002152 struct ucc_fast __iomem *uf_regs;
2153 struct ucc_geth __iomem *ug_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05002154 int ret_val = -EINVAL;
2155 u32 remoder = UCC_GETH_REMODER_INIT;
Timur Tabi3bc53422009-01-11 00:25:21 -08002156 u32 init_enet_pram_offset, cecr_subblock, command;
Kim Phillips728de4c92007-04-13 01:26:03 -05002157 u32 ifstat, i, j, size, l2qt, l3qt, length;
2158 u16 temoder = UCC_GETH_TEMODER_INIT;
2159 u16 test;
2160 u8 function_code = 0;
Andy Fleming6fee40e2008-05-02 13:01:23 -05002161 u8 __iomem *bd;
2162 u8 __iomem *endOfRing;
Kim Phillips728de4c92007-04-13 01:26:03 -05002163 u8 numThreadsRxNumerical, numThreadsTxNumerical;
2164
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002165 ugeth_vdbg("%s: IN", __func__);
Kim Phillips728de4c92007-04-13 01:26:03 -05002166 uccf = ugeth->uccf;
2167 ug_info = ugeth->ug_info;
2168 uf_info = &ug_info->uf_info;
2169 uf_regs = uccf->uf_regs;
2170 ug_regs = ugeth->ug_regs;
Li Yangce973b12006-08-14 23:00:11 -07002171
2172 switch (ug_info->numThreadsRx) {
2173 case UCC_GETH_NUM_OF_THREADS_1:
2174 numThreadsRxNumerical = 1;
2175 break;
2176 case UCC_GETH_NUM_OF_THREADS_2:
2177 numThreadsRxNumerical = 2;
2178 break;
2179 case UCC_GETH_NUM_OF_THREADS_4:
2180 numThreadsRxNumerical = 4;
2181 break;
2182 case UCC_GETH_NUM_OF_THREADS_6:
2183 numThreadsRxNumerical = 6;
2184 break;
2185 case UCC_GETH_NUM_OF_THREADS_8:
2186 numThreadsRxNumerical = 8;
2187 break;
2188 default:
Li Yang890de952007-07-19 11:48:29 +08002189 if (netif_msg_ifup(ugeth))
2190 ugeth_err("%s: Bad number of Rx threads value.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002191 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002192 return -EINVAL;
2193 break;
2194 }
2195
2196 switch (ug_info->numThreadsTx) {
2197 case UCC_GETH_NUM_OF_THREADS_1:
2198 numThreadsTxNumerical = 1;
2199 break;
2200 case UCC_GETH_NUM_OF_THREADS_2:
2201 numThreadsTxNumerical = 2;
2202 break;
2203 case UCC_GETH_NUM_OF_THREADS_4:
2204 numThreadsTxNumerical = 4;
2205 break;
2206 case UCC_GETH_NUM_OF_THREADS_6:
2207 numThreadsTxNumerical = 6;
2208 break;
2209 case UCC_GETH_NUM_OF_THREADS_8:
2210 numThreadsTxNumerical = 8;
2211 break;
2212 default:
Li Yang890de952007-07-19 11:48:29 +08002213 if (netif_msg_ifup(ugeth))
2214 ugeth_err("%s: Bad number of Tx threads value.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002215 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002216 return -EINVAL;
2217 break;
2218 }
2219
2220 /* Calculate rx_extended_features */
2221 ugeth->rx_non_dynamic_extended_features = ug_info->ipCheckSumCheck ||
2222 ug_info->ipAddressAlignment ||
2223 (ug_info->numStationAddresses !=
2224 UCC_GETH_NUM_OF_STATION_ADDRESSES_1);
2225
2226 ugeth->rx_extended_features = ugeth->rx_non_dynamic_extended_features ||
2227 (ug_info->vlanOperationTagged != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
2228 || (ug_info->vlanOperationNonTagged !=
2229 UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP);
2230
Li Yangce973b12006-08-14 23:00:11 -07002231 init_default_reg_vals(&uf_regs->upsmr,
2232 &ug_regs->maccfg1, &ug_regs->maccfg2);
2233
2234 /* Set UPSMR */
2235 /* For more details see the hardware spec. */
2236 init_rx_parameters(ug_info->bro,
2237 ug_info->rsh, ug_info->pro, &uf_regs->upsmr);
2238
2239 /* We're going to ignore other registers for now, */
2240 /* except as needed to get up and running */
2241
2242 /* Set MACCFG1 */
2243 /* For more details see the hardware spec. */
2244 init_flow_control_params(ug_info->aufc,
2245 ug_info->receiveFlowControl,
Li Yangac421852007-07-19 11:47:47 +08002246 ug_info->transmitFlowControl,
Li Yangce973b12006-08-14 23:00:11 -07002247 ug_info->pausePeriod,
2248 ug_info->extensionField,
2249 &uf_regs->upsmr,
2250 &ug_regs->uempr, &ug_regs->maccfg1);
2251
Timur Tabi3bc53422009-01-11 00:25:21 -08002252 setbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
Li Yangce973b12006-08-14 23:00:11 -07002253
2254 /* Set IPGIFG */
2255 /* For more details see the hardware spec. */
2256 ret_val = init_inter_frame_gap_params(ug_info->nonBackToBackIfgPart1,
2257 ug_info->nonBackToBackIfgPart2,
2258 ug_info->
2259 miminumInterFrameGapEnforcement,
2260 ug_info->backToBackInterFrameGap,
2261 &ug_regs->ipgifg);
2262 if (ret_val != 0) {
Li Yang890de952007-07-19 11:48:29 +08002263 if (netif_msg_ifup(ugeth))
2264 ugeth_err("%s: IPGIFG initialization parameter too large.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002265 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002266 return ret_val;
2267 }
2268
2269 /* Set HAFDUP */
2270 /* For more details see the hardware spec. */
2271 ret_val = init_half_duplex_params(ug_info->altBeb,
2272 ug_info->backPressureNoBackoff,
2273 ug_info->noBackoff,
2274 ug_info->excessDefer,
2275 ug_info->altBebTruncation,
2276 ug_info->maxRetransmission,
2277 ug_info->collisionWindow,
2278 &ug_regs->hafdup);
2279 if (ret_val != 0) {
Li Yang890de952007-07-19 11:48:29 +08002280 if (netif_msg_ifup(ugeth))
2281 ugeth_err("%s: Half Duplex initialization parameter too large.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002282 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002283 return ret_val;
2284 }
2285
2286 /* Set IFSTAT */
2287 /* For more details see the hardware spec. */
2288 /* Read only - resets upon read */
2289 ifstat = in_be32(&ug_regs->ifstat);
2290
2291 /* Clear UEMPR */
2292 /* For more details see the hardware spec. */
2293 out_be32(&ug_regs->uempr, 0);
2294
2295 /* Set UESCR */
2296 /* For more details see the hardware spec. */
2297 init_hw_statistics_gathering_mode((ug_info->statisticsMode &
2298 UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE),
2299 0, &uf_regs->upsmr, &ug_regs->uescr);
2300
2301 /* Allocate Tx bds */
2302 for (j = 0; j < ug_info->numQueuesTx; j++) {
2303 /* Allocate in multiple of
2304 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT,
2305 according to spec */
Li Yang18a8e862006-10-19 21:07:34 -05002306 length = ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd))
Li Yangce973b12006-08-14 23:00:11 -07002307 / UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2308 * UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
Li Yang18a8e862006-10-19 21:07:34 -05002309 if ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)) %
Li Yangce973b12006-08-14 23:00:11 -07002310 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2311 length += UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
2312 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2313 u32 align = 4;
2314 if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
2315 align = UCC_GETH_TX_BD_RING_ALIGNMENT;
2316 ugeth->tx_bd_ring_offset[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002317 (u32) kmalloc((u32) (length + align), GFP_KERNEL);
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002318
Li Yangce973b12006-08-14 23:00:11 -07002319 if (ugeth->tx_bd_ring_offset[j] != 0)
2320 ugeth->p_tx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002321 (u8 __iomem *)((ugeth->tx_bd_ring_offset[j] +
Li Yangce973b12006-08-14 23:00:11 -07002322 align) & ~(align - 1));
2323 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2324 ugeth->tx_bd_ring_offset[j] =
2325 qe_muram_alloc(length,
2326 UCC_GETH_TX_BD_RING_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002327 if (!IS_ERR_VALUE(ugeth->tx_bd_ring_offset[j]))
Li Yangce973b12006-08-14 23:00:11 -07002328 ugeth->p_tx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002329 (u8 __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002330 tx_bd_ring_offset[j]);
2331 }
2332 if (!ugeth->p_tx_bd_ring[j]) {
Li Yang890de952007-07-19 11:48:29 +08002333 if (netif_msg_ifup(ugeth))
2334 ugeth_err
2335 ("%s: Can not allocate memory for Tx bd rings.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002336 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002337 return -ENOMEM;
2338 }
2339 /* Zero unused end of bd ring, according to spec */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002340 memset_io((void __iomem *)(ugeth->p_tx_bd_ring[j] +
2341 ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)), 0,
Li Yang18a8e862006-10-19 21:07:34 -05002342 length - ug_info->bdRingLenTx[j] * sizeof(struct qe_bd));
Li Yangce973b12006-08-14 23:00:11 -07002343 }
2344
2345 /* Allocate Rx bds */
2346 for (j = 0; j < ug_info->numQueuesRx; j++) {
Li Yang18a8e862006-10-19 21:07:34 -05002347 length = ug_info->bdRingLenRx[j] * sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002348 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2349 u32 align = 4;
2350 if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
2351 align = UCC_GETH_RX_BD_RING_ALIGNMENT;
2352 ugeth->rx_bd_ring_offset[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002353 (u32) kmalloc((u32) (length + align), GFP_KERNEL);
Li Yangce973b12006-08-14 23:00:11 -07002354 if (ugeth->rx_bd_ring_offset[j] != 0)
2355 ugeth->p_rx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002356 (u8 __iomem *)((ugeth->rx_bd_ring_offset[j] +
Li Yangce973b12006-08-14 23:00:11 -07002357 align) & ~(align - 1));
2358 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2359 ugeth->rx_bd_ring_offset[j] =
2360 qe_muram_alloc(length,
2361 UCC_GETH_RX_BD_RING_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002362 if (!IS_ERR_VALUE(ugeth->rx_bd_ring_offset[j]))
Li Yangce973b12006-08-14 23:00:11 -07002363 ugeth->p_rx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002364 (u8 __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002365 rx_bd_ring_offset[j]);
2366 }
2367 if (!ugeth->p_rx_bd_ring[j]) {
Li Yang890de952007-07-19 11:48:29 +08002368 if (netif_msg_ifup(ugeth))
2369 ugeth_err
2370 ("%s: Can not allocate memory for Rx bd rings.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002371 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002372 return -ENOMEM;
2373 }
2374 }
2375
2376 /* Init Tx bds */
2377 for (j = 0; j < ug_info->numQueuesTx; j++) {
2378 /* Setup the skbuff rings */
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002379 ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
2380 ugeth->ug_info->bdRingLenTx[j],
2381 GFP_KERNEL);
Li Yangce973b12006-08-14 23:00:11 -07002382
2383 if (ugeth->tx_skbuff[j] == NULL) {
Li Yang890de952007-07-19 11:48:29 +08002384 if (netif_msg_ifup(ugeth))
2385 ugeth_err("%s: Could not allocate tx_skbuff",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002386 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002387 return -ENOMEM;
2388 }
2389
2390 for (i = 0; i < ugeth->ug_info->bdRingLenTx[j]; i++)
2391 ugeth->tx_skbuff[j][i] = NULL;
2392
2393 ugeth->skb_curtx[j] = ugeth->skb_dirtytx[j] = 0;
2394 bd = ugeth->confBd[j] = ugeth->txBd[j] = ugeth->p_tx_bd_ring[j];
2395 for (i = 0; i < ug_info->bdRingLenTx[j]; i++) {
Li Yang18a8e862006-10-19 21:07:34 -05002396 /* clear bd buffer */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002397 out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
Li Yang18a8e862006-10-19 21:07:34 -05002398 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002399 out_be32((u32 __iomem *)bd, 0);
Li Yang18a8e862006-10-19 21:07:34 -05002400 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002401 }
Li Yang18a8e862006-10-19 21:07:34 -05002402 bd -= sizeof(struct qe_bd);
2403 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002404 out_be32((u32 __iomem *)bd, T_W); /* for last BD set Wrap bit */
Li Yangce973b12006-08-14 23:00:11 -07002405 }
2406
2407 /* Init Rx bds */
2408 for (j = 0; j < ug_info->numQueuesRx; j++) {
2409 /* Setup the skbuff rings */
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002410 ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
2411 ugeth->ug_info->bdRingLenRx[j],
2412 GFP_KERNEL);
Li Yangce973b12006-08-14 23:00:11 -07002413
2414 if (ugeth->rx_skbuff[j] == NULL) {
Li Yang890de952007-07-19 11:48:29 +08002415 if (netif_msg_ifup(ugeth))
2416 ugeth_err("%s: Could not allocate rx_skbuff",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002417 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002418 return -ENOMEM;
2419 }
2420
2421 for (i = 0; i < ugeth->ug_info->bdRingLenRx[j]; i++)
2422 ugeth->rx_skbuff[j][i] = NULL;
2423
2424 ugeth->skb_currx[j] = 0;
2425 bd = ugeth->rxBd[j] = ugeth->p_rx_bd_ring[j];
2426 for (i = 0; i < ug_info->bdRingLenRx[j]; i++) {
Li Yang18a8e862006-10-19 21:07:34 -05002427 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002428 out_be32((u32 __iomem *)bd, R_I);
Li Yang18a8e862006-10-19 21:07:34 -05002429 /* clear bd buffer */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002430 out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
Li Yang18a8e862006-10-19 21:07:34 -05002431 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002432 }
Li Yang18a8e862006-10-19 21:07:34 -05002433 bd -= sizeof(struct qe_bd);
2434 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002435 out_be32((u32 __iomem *)bd, R_W); /* for last BD set Wrap bit */
Li Yangce973b12006-08-14 23:00:11 -07002436 }
2437
2438 /*
2439 * Global PRAM
2440 */
2441 /* Tx global PRAM */
2442 /* Allocate global tx parameter RAM page */
2443 ugeth->tx_glbl_pram_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002444 qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram),
Li Yangce973b12006-08-14 23:00:11 -07002445 UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002446 if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002447 if (netif_msg_ifup(ugeth))
2448 ugeth_err
2449 ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002450 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002451 return -ENOMEM;
2452 }
2453 ugeth->p_tx_glbl_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002454 (struct ucc_geth_tx_global_pram __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002455 tx_glbl_pram_offset);
2456 /* Zero out p_tx_glbl_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002457 memset_io((void __iomem *)ugeth->p_tx_glbl_pram, 0, sizeof(struct ucc_geth_tx_global_pram));
Li Yangce973b12006-08-14 23:00:11 -07002458
2459 /* Fill global PRAM */
2460
2461 /* TQPTR */
2462 /* Size varies with number of Tx threads */
2463 ugeth->thread_dat_tx_offset =
2464 qe_muram_alloc(numThreadsTxNumerical *
Li Yang18a8e862006-10-19 21:07:34 -05002465 sizeof(struct ucc_geth_thread_data_tx) +
Li Yangce973b12006-08-14 23:00:11 -07002466 32 * (numThreadsTxNumerical == 1),
2467 UCC_GETH_THREAD_DATA_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002468 if (IS_ERR_VALUE(ugeth->thread_dat_tx_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002469 if (netif_msg_ifup(ugeth))
2470 ugeth_err
2471 ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002472 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002473 return -ENOMEM;
2474 }
2475
2476 ugeth->p_thread_data_tx =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002477 (struct ucc_geth_thread_data_tx __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002478 thread_dat_tx_offset);
2479 out_be32(&ugeth->p_tx_glbl_pram->tqptr, ugeth->thread_dat_tx_offset);
2480
2481 /* vtagtable */
2482 for (i = 0; i < UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX; i++)
2483 out_be32(&ugeth->p_tx_glbl_pram->vtagtable[i],
2484 ug_info->vtagtable[i]);
2485
2486 /* iphoffset */
2487 for (i = 0; i < TX_IP_OFFSET_ENTRY_MAX; i++)
Andy Fleming6fee40e2008-05-02 13:01:23 -05002488 out_8(&ugeth->p_tx_glbl_pram->iphoffset[i],
2489 ug_info->iphoffset[i]);
Li Yangce973b12006-08-14 23:00:11 -07002490
2491 /* SQPTR */
2492 /* Size varies with number of Tx queues */
2493 ugeth->send_q_mem_reg_offset =
2494 qe_muram_alloc(ug_info->numQueuesTx *
Li Yang18a8e862006-10-19 21:07:34 -05002495 sizeof(struct ucc_geth_send_queue_qd),
Li Yangce973b12006-08-14 23:00:11 -07002496 UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002497 if (IS_ERR_VALUE(ugeth->send_q_mem_reg_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002498 if (netif_msg_ifup(ugeth))
2499 ugeth_err
2500 ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002501 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002502 return -ENOMEM;
2503 }
2504
2505 ugeth->p_send_q_mem_reg =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002506 (struct ucc_geth_send_queue_mem_region __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002507 send_q_mem_reg_offset);
2508 out_be32(&ugeth->p_tx_glbl_pram->sqptr, ugeth->send_q_mem_reg_offset);
2509
2510 /* Setup the table */
2511 /* Assume BD rings are already established */
2512 for (i = 0; i < ug_info->numQueuesTx; i++) {
2513 endOfRing =
2514 ugeth->p_tx_bd_ring[i] + (ug_info->bdRingLenTx[i] -
Li Yang18a8e862006-10-19 21:07:34 -05002515 1) * sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002516 if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
2517 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
2518 (u32) virt_to_phys(ugeth->p_tx_bd_ring[i]));
2519 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
2520 last_bd_completed_address,
2521 (u32) virt_to_phys(endOfRing));
2522 } else if (ugeth->ug_info->uf_info.bd_mem_part ==
2523 MEM_PART_MURAM) {
2524 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
2525 (u32) immrbar_virt_to_phys(ugeth->
2526 p_tx_bd_ring[i]));
2527 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
2528 last_bd_completed_address,
2529 (u32) immrbar_virt_to_phys(endOfRing));
2530 }
2531 }
2532
2533 /* schedulerbasepointer */
2534
2535 if (ug_info->numQueuesTx > 1) {
2536 /* scheduler exists only if more than 1 tx queue */
2537 ugeth->scheduler_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002538 qe_muram_alloc(sizeof(struct ucc_geth_scheduler),
Li Yangce973b12006-08-14 23:00:11 -07002539 UCC_GETH_SCHEDULER_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002540 if (IS_ERR_VALUE(ugeth->scheduler_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002541 if (netif_msg_ifup(ugeth))
2542 ugeth_err
2543 ("%s: Can not allocate DPRAM memory for p_scheduler.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002544 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002545 return -ENOMEM;
2546 }
2547
2548 ugeth->p_scheduler =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002549 (struct ucc_geth_scheduler __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002550 scheduler_offset);
2551 out_be32(&ugeth->p_tx_glbl_pram->schedulerbasepointer,
2552 ugeth->scheduler_offset);
2553 /* Zero out p_scheduler */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002554 memset_io((void __iomem *)ugeth->p_scheduler, 0, sizeof(struct ucc_geth_scheduler));
Li Yangce973b12006-08-14 23:00:11 -07002555
2556 /* Set values in scheduler */
2557 out_be32(&ugeth->p_scheduler->mblinterval,
2558 ug_info->mblinterval);
2559 out_be16(&ugeth->p_scheduler->nortsrbytetime,
2560 ug_info->nortsrbytetime);
Andy Fleming6fee40e2008-05-02 13:01:23 -05002561 out_8(&ugeth->p_scheduler->fracsiz, ug_info->fracsiz);
2562 out_8(&ugeth->p_scheduler->strictpriorityq,
2563 ug_info->strictpriorityq);
2564 out_8(&ugeth->p_scheduler->txasap, ug_info->txasap);
2565 out_8(&ugeth->p_scheduler->extrabw, ug_info->extrabw);
Li Yangce973b12006-08-14 23:00:11 -07002566 for (i = 0; i < NUM_TX_QUEUES; i++)
Andy Fleming6fee40e2008-05-02 13:01:23 -05002567 out_8(&ugeth->p_scheduler->weightfactor[i],
2568 ug_info->weightfactor[i]);
Li Yangce973b12006-08-14 23:00:11 -07002569
2570 /* Set pointers to cpucount registers in scheduler */
2571 ugeth->p_cpucount[0] = &(ugeth->p_scheduler->cpucount0);
2572 ugeth->p_cpucount[1] = &(ugeth->p_scheduler->cpucount1);
2573 ugeth->p_cpucount[2] = &(ugeth->p_scheduler->cpucount2);
2574 ugeth->p_cpucount[3] = &(ugeth->p_scheduler->cpucount3);
2575 ugeth->p_cpucount[4] = &(ugeth->p_scheduler->cpucount4);
2576 ugeth->p_cpucount[5] = &(ugeth->p_scheduler->cpucount5);
2577 ugeth->p_cpucount[6] = &(ugeth->p_scheduler->cpucount6);
2578 ugeth->p_cpucount[7] = &(ugeth->p_scheduler->cpucount7);
2579 }
2580
2581 /* schedulerbasepointer */
2582 /* TxRMON_PTR (statistics) */
2583 if (ug_info->
2584 statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
2585 ugeth->tx_fw_statistics_pram_offset =
2586 qe_muram_alloc(sizeof
Li Yang18a8e862006-10-19 21:07:34 -05002587 (struct ucc_geth_tx_firmware_statistics_pram),
Li Yangce973b12006-08-14 23:00:11 -07002588 UCC_GETH_TX_STATISTICS_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002589 if (IS_ERR_VALUE(ugeth->tx_fw_statistics_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002590 if (netif_msg_ifup(ugeth))
2591 ugeth_err
2592 ("%s: Can not allocate DPRAM memory for"
2593 " p_tx_fw_statistics_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002594 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002595 return -ENOMEM;
2596 }
2597 ugeth->p_tx_fw_statistics_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002598 (struct ucc_geth_tx_firmware_statistics_pram __iomem *)
Li Yangce973b12006-08-14 23:00:11 -07002599 qe_muram_addr(ugeth->tx_fw_statistics_pram_offset);
2600 /* Zero out p_tx_fw_statistics_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002601 memset_io((void __iomem *)ugeth->p_tx_fw_statistics_pram,
Li Yang18a8e862006-10-19 21:07:34 -05002602 0, sizeof(struct ucc_geth_tx_firmware_statistics_pram));
Li Yangce973b12006-08-14 23:00:11 -07002603 }
2604
2605 /* temoder */
2606 /* Already has speed set */
2607
2608 if (ug_info->numQueuesTx > 1)
2609 temoder |= TEMODER_SCHEDULER_ENABLE;
2610 if (ug_info->ipCheckSumGenerate)
2611 temoder |= TEMODER_IP_CHECKSUM_GENERATE;
2612 temoder |= ((ug_info->numQueuesTx - 1) << TEMODER_NUM_OF_QUEUES_SHIFT);
2613 out_be16(&ugeth->p_tx_glbl_pram->temoder, temoder);
2614
2615 test = in_be16(&ugeth->p_tx_glbl_pram->temoder);
2616
2617 /* Function code register value to be used later */
Timur Tabi6b0b5942007-10-03 11:34:59 -05002618 function_code = UCC_BMR_BO_BE | UCC_BMR_GBL;
Li Yangce973b12006-08-14 23:00:11 -07002619 /* Required for QE */
2620
2621 /* function code register */
2622 out_be32(&ugeth->p_tx_glbl_pram->tstate, ((u32) function_code) << 24);
2623
2624 /* Rx global PRAM */
2625 /* Allocate global rx parameter RAM page */
2626 ugeth->rx_glbl_pram_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002627 qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram),
Li Yangce973b12006-08-14 23:00:11 -07002628 UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002629 if (IS_ERR_VALUE(ugeth->rx_glbl_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002630 if (netif_msg_ifup(ugeth))
2631 ugeth_err
2632 ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002633 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002634 return -ENOMEM;
2635 }
2636 ugeth->p_rx_glbl_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002637 (struct ucc_geth_rx_global_pram __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002638 rx_glbl_pram_offset);
2639 /* Zero out p_rx_glbl_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002640 memset_io((void __iomem *)ugeth->p_rx_glbl_pram, 0, sizeof(struct ucc_geth_rx_global_pram));
Li Yangce973b12006-08-14 23:00:11 -07002641
2642 /* Fill global PRAM */
2643
2644 /* RQPTR */
2645 /* Size varies with number of Rx threads */
2646 ugeth->thread_dat_rx_offset =
2647 qe_muram_alloc(numThreadsRxNumerical *
Li Yang18a8e862006-10-19 21:07:34 -05002648 sizeof(struct ucc_geth_thread_data_rx),
Li Yangce973b12006-08-14 23:00:11 -07002649 UCC_GETH_THREAD_DATA_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002650 if (IS_ERR_VALUE(ugeth->thread_dat_rx_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002651 if (netif_msg_ifup(ugeth))
2652 ugeth_err
2653 ("%s: Can not allocate DPRAM memory for p_thread_data_rx.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002654 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002655 return -ENOMEM;
2656 }
2657
2658 ugeth->p_thread_data_rx =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002659 (struct ucc_geth_thread_data_rx __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002660 thread_dat_rx_offset);
2661 out_be32(&ugeth->p_rx_glbl_pram->rqptr, ugeth->thread_dat_rx_offset);
2662
2663 /* typeorlen */
2664 out_be16(&ugeth->p_rx_glbl_pram->typeorlen, ug_info->typeorlen);
2665
2666 /* rxrmonbaseptr (statistics) */
2667 if (ug_info->
2668 statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
2669 ugeth->rx_fw_statistics_pram_offset =
2670 qe_muram_alloc(sizeof
Li Yang18a8e862006-10-19 21:07:34 -05002671 (struct ucc_geth_rx_firmware_statistics_pram),
Li Yangce973b12006-08-14 23:00:11 -07002672 UCC_GETH_RX_STATISTICS_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002673 if (IS_ERR_VALUE(ugeth->rx_fw_statistics_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002674 if (netif_msg_ifup(ugeth))
2675 ugeth_err
2676 ("%s: Can not allocate DPRAM memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002677 " p_rx_fw_statistics_pram.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002678 return -ENOMEM;
2679 }
2680 ugeth->p_rx_fw_statistics_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002681 (struct ucc_geth_rx_firmware_statistics_pram __iomem *)
Li Yangce973b12006-08-14 23:00:11 -07002682 qe_muram_addr(ugeth->rx_fw_statistics_pram_offset);
2683 /* Zero out p_rx_fw_statistics_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002684 memset_io((void __iomem *)ugeth->p_rx_fw_statistics_pram, 0,
Li Yang18a8e862006-10-19 21:07:34 -05002685 sizeof(struct ucc_geth_rx_firmware_statistics_pram));
Li Yangce973b12006-08-14 23:00:11 -07002686 }
2687
2688 /* intCoalescingPtr */
2689
2690 /* Size varies with number of Rx queues */
2691 ugeth->rx_irq_coalescing_tbl_offset =
2692 qe_muram_alloc(ug_info->numQueuesRx *
Michael Barkowski75639072007-04-13 01:26:15 -05002693 sizeof(struct ucc_geth_rx_interrupt_coalescing_entry)
2694 + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002695 if (IS_ERR_VALUE(ugeth->rx_irq_coalescing_tbl_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002696 if (netif_msg_ifup(ugeth))
2697 ugeth_err
2698 ("%s: Can not allocate DPRAM memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002699 " p_rx_irq_coalescing_tbl.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002700 return -ENOMEM;
2701 }
2702
2703 ugeth->p_rx_irq_coalescing_tbl =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002704 (struct ucc_geth_rx_interrupt_coalescing_table __iomem *)
Li Yangce973b12006-08-14 23:00:11 -07002705 qe_muram_addr(ugeth->rx_irq_coalescing_tbl_offset);
2706 out_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr,
2707 ugeth->rx_irq_coalescing_tbl_offset);
2708
2709 /* Fill interrupt coalescing table */
2710 for (i = 0; i < ug_info->numQueuesRx; i++) {
2711 out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
2712 interruptcoalescingmaxvalue,
2713 ug_info->interruptcoalescingmaxvalue[i]);
2714 out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
2715 interruptcoalescingcounter,
2716 ug_info->interruptcoalescingmaxvalue[i]);
2717 }
2718
2719 /* MRBLR */
2720 init_max_rx_buff_len(uf_info->max_rx_buf_length,
2721 &ugeth->p_rx_glbl_pram->mrblr);
2722 /* MFLR */
2723 out_be16(&ugeth->p_rx_glbl_pram->mflr, ug_info->maxFrameLength);
2724 /* MINFLR */
2725 init_min_frame_len(ug_info->minFrameLength,
2726 &ugeth->p_rx_glbl_pram->minflr,
2727 &ugeth->p_rx_glbl_pram->mrblr);
2728 /* MAXD1 */
2729 out_be16(&ugeth->p_rx_glbl_pram->maxd1, ug_info->maxD1Length);
2730 /* MAXD2 */
2731 out_be16(&ugeth->p_rx_glbl_pram->maxd2, ug_info->maxD2Length);
2732
2733 /* l2qt */
2734 l2qt = 0;
2735 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++)
2736 l2qt |= (ug_info->l2qt[i] << (28 - 4 * i));
2737 out_be32(&ugeth->p_rx_glbl_pram->l2qt, l2qt);
2738
2739 /* l3qt */
2740 for (j = 0; j < UCC_GETH_IP_PRIORITY_MAX; j += 8) {
2741 l3qt = 0;
2742 for (i = 0; i < 8; i++)
2743 l3qt |= (ug_info->l3qt[j + i] << (28 - 4 * i));
Li Yang18a8e862006-10-19 21:07:34 -05002744 out_be32(&ugeth->p_rx_glbl_pram->l3qt[j/8], l3qt);
Li Yangce973b12006-08-14 23:00:11 -07002745 }
2746
2747 /* vlantype */
2748 out_be16(&ugeth->p_rx_glbl_pram->vlantype, ug_info->vlantype);
2749
2750 /* vlantci */
2751 out_be16(&ugeth->p_rx_glbl_pram->vlantci, ug_info->vlantci);
2752
2753 /* ecamptr */
2754 out_be32(&ugeth->p_rx_glbl_pram->ecamptr, ug_info->ecamptr);
2755
2756 /* RBDQPTR */
2757 /* Size varies with number of Rx queues */
2758 ugeth->rx_bd_qs_tbl_offset =
2759 qe_muram_alloc(ug_info->numQueuesRx *
Li Yang18a8e862006-10-19 21:07:34 -05002760 (sizeof(struct ucc_geth_rx_bd_queues_entry) +
2761 sizeof(struct ucc_geth_rx_prefetched_bds)),
Li Yangce973b12006-08-14 23:00:11 -07002762 UCC_GETH_RX_BD_QUEUES_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002763 if (IS_ERR_VALUE(ugeth->rx_bd_qs_tbl_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002764 if (netif_msg_ifup(ugeth))
2765 ugeth_err
2766 ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002767 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002768 return -ENOMEM;
2769 }
2770
2771 ugeth->p_rx_bd_qs_tbl =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002772 (struct ucc_geth_rx_bd_queues_entry __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002773 rx_bd_qs_tbl_offset);
2774 out_be32(&ugeth->p_rx_glbl_pram->rbdqptr, ugeth->rx_bd_qs_tbl_offset);
2775 /* Zero out p_rx_bd_qs_tbl */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002776 memset_io((void __iomem *)ugeth->p_rx_bd_qs_tbl,
Li Yangce973b12006-08-14 23:00:11 -07002777 0,
Li Yang18a8e862006-10-19 21:07:34 -05002778 ug_info->numQueuesRx * (sizeof(struct ucc_geth_rx_bd_queues_entry) +
2779 sizeof(struct ucc_geth_rx_prefetched_bds)));
Li Yangce973b12006-08-14 23:00:11 -07002780
2781 /* Setup the table */
2782 /* Assume BD rings are already established */
2783 for (i = 0; i < ug_info->numQueuesRx; i++) {
2784 if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
2785 out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
2786 (u32) virt_to_phys(ugeth->p_rx_bd_ring[i]));
2787 } else if (ugeth->ug_info->uf_info.bd_mem_part ==
2788 MEM_PART_MURAM) {
2789 out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
2790 (u32) immrbar_virt_to_phys(ugeth->
2791 p_rx_bd_ring[i]));
2792 }
2793 /* rest of fields handled by QE */
2794 }
2795
2796 /* remoder */
2797 /* Already has speed set */
2798
2799 if (ugeth->rx_extended_features)
2800 remoder |= REMODER_RX_EXTENDED_FEATURES;
2801 if (ug_info->rxExtendedFiltering)
2802 remoder |= REMODER_RX_EXTENDED_FILTERING;
2803 if (ug_info->dynamicMaxFrameLength)
2804 remoder |= REMODER_DYNAMIC_MAX_FRAME_LENGTH;
2805 if (ug_info->dynamicMinFrameLength)
2806 remoder |= REMODER_DYNAMIC_MIN_FRAME_LENGTH;
2807 remoder |=
2808 ug_info->vlanOperationTagged << REMODER_VLAN_OPERATION_TAGGED_SHIFT;
2809 remoder |=
2810 ug_info->
2811 vlanOperationNonTagged << REMODER_VLAN_OPERATION_NON_TAGGED_SHIFT;
2812 remoder |= ug_info->rxQoSMode << REMODER_RX_QOS_MODE_SHIFT;
2813 remoder |= ((ug_info->numQueuesRx - 1) << REMODER_NUM_OF_QUEUES_SHIFT);
2814 if (ug_info->ipCheckSumCheck)
2815 remoder |= REMODER_IP_CHECKSUM_CHECK;
2816 if (ug_info->ipAddressAlignment)
2817 remoder |= REMODER_IP_ADDRESS_ALIGNMENT;
2818 out_be32(&ugeth->p_rx_glbl_pram->remoder, remoder);
2819
2820 /* Note that this function must be called */
2821 /* ONLY AFTER p_tx_fw_statistics_pram */
2822 /* andp_UccGethRxFirmwareStatisticsPram are allocated ! */
2823 init_firmware_statistics_gathering_mode((ug_info->
2824 statisticsMode &
2825 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX),
2826 (ug_info->statisticsMode &
2827 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX),
2828 &ugeth->p_tx_glbl_pram->txrmonbaseptr,
2829 ugeth->tx_fw_statistics_pram_offset,
2830 &ugeth->p_rx_glbl_pram->rxrmonbaseptr,
2831 ugeth->rx_fw_statistics_pram_offset,
2832 &ugeth->p_tx_glbl_pram->temoder,
2833 &ugeth->p_rx_glbl_pram->remoder);
2834
2835 /* function code register */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002836 out_8(&ugeth->p_rx_glbl_pram->rstate, function_code);
Li Yangce973b12006-08-14 23:00:11 -07002837
2838 /* initialize extended filtering */
2839 if (ug_info->rxExtendedFiltering) {
2840 if (!ug_info->extendedFilteringChainPointer) {
Li Yang890de952007-07-19 11:48:29 +08002841 if (netif_msg_ifup(ugeth))
2842 ugeth_err("%s: Null Extended Filtering Chain Pointer.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002843 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002844 return -EINVAL;
2845 }
2846
2847 /* Allocate memory for extended filtering Mode Global
2848 Parameters */
2849 ugeth->exf_glbl_param_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002850 qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram),
Li Yangce973b12006-08-14 23:00:11 -07002851 UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002852 if (IS_ERR_VALUE(ugeth->exf_glbl_param_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002853 if (netif_msg_ifup(ugeth))
2854 ugeth_err
2855 ("%s: Can not allocate DPRAM memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002856 " p_exf_glbl_param.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002857 return -ENOMEM;
2858 }
2859
2860 ugeth->p_exf_glbl_param =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002861 (struct ucc_geth_exf_global_pram __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002862 exf_glbl_param_offset);
2863 out_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam,
2864 ugeth->exf_glbl_param_offset);
2865 out_be32(&ugeth->p_exf_glbl_param->l2pcdptr,
2866 (u32) ug_info->extendedFilteringChainPointer);
2867
2868 } else { /* initialize 82xx style address filtering */
2869
2870 /* Init individual address recognition registers to disabled */
2871
2872 for (j = 0; j < NUM_OF_PADDRS; j++)
2873 ugeth_82xx_filtering_clear_addr_in_paddr(ugeth, (u8) j);
2874
Li Yangce973b12006-08-14 23:00:11 -07002875 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002876 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002877 p_rx_glbl_pram->addressfiltering;
2878
2879 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
2880 ENET_ADDR_TYPE_GROUP);
2881 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
2882 ENET_ADDR_TYPE_INDIVIDUAL);
2883 }
2884
2885 /*
2886 * Initialize UCC at QE level
2887 */
2888
2889 command = QE_INIT_TX_RX;
2890
2891 /* Allocate shadow InitEnet command parameter structure.
2892 * This is needed because after the InitEnet command is executed,
2893 * the structure in DPRAM is released, because DPRAM is a premium
2894 * resource.
2895 * This shadow structure keeps a copy of what was done so that the
2896 * allocated resources can be released when the channel is freed.
2897 */
2898 if (!(ugeth->p_init_enet_param_shadow =
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002899 kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
Li Yang890de952007-07-19 11:48:29 +08002900 if (netif_msg_ifup(ugeth))
2901 ugeth_err
2902 ("%s: Can not allocate memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002903 " p_UccInitEnetParamShadows.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002904 return -ENOMEM;
2905 }
2906 /* Zero out *p_init_enet_param_shadow */
2907 memset((char *)ugeth->p_init_enet_param_shadow,
Li Yang18a8e862006-10-19 21:07:34 -05002908 0, sizeof(struct ucc_geth_init_pram));
Li Yangce973b12006-08-14 23:00:11 -07002909
2910 /* Fill shadow InitEnet command parameter structure */
2911
2912 ugeth->p_init_enet_param_shadow->resinit1 =
2913 ENET_INIT_PARAM_MAGIC_RES_INIT1;
2914 ugeth->p_init_enet_param_shadow->resinit2 =
2915 ENET_INIT_PARAM_MAGIC_RES_INIT2;
2916 ugeth->p_init_enet_param_shadow->resinit3 =
2917 ENET_INIT_PARAM_MAGIC_RES_INIT3;
2918 ugeth->p_init_enet_param_shadow->resinit4 =
2919 ENET_INIT_PARAM_MAGIC_RES_INIT4;
2920 ugeth->p_init_enet_param_shadow->resinit5 =
2921 ENET_INIT_PARAM_MAGIC_RES_INIT5;
2922 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
2923 ((u32) ug_info->numThreadsRx) << ENET_INIT_PARAM_RGF_SHIFT;
2924 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
2925 ((u32) ug_info->numThreadsTx) << ENET_INIT_PARAM_TGF_SHIFT;
2926
2927 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
2928 ugeth->rx_glbl_pram_offset | ug_info->riscRx;
2929 if ((ug_info->largestexternallookupkeysize !=
2930 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE)
2931 && (ug_info->largestexternallookupkeysize !=
2932 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
2933 && (ug_info->largestexternallookupkeysize !=
2934 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) {
Li Yang890de952007-07-19 11:48:29 +08002935 if (netif_msg_ifup(ugeth))
2936 ugeth_err("%s: Invalid largest External Lookup Key Size.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002937 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002938 return -EINVAL;
2939 }
2940 ugeth->p_init_enet_param_shadow->largestexternallookupkeysize =
2941 ug_info->largestexternallookupkeysize;
Li Yang18a8e862006-10-19 21:07:34 -05002942 size = sizeof(struct ucc_geth_thread_rx_pram);
Li Yangce973b12006-08-14 23:00:11 -07002943 if (ug_info->rxExtendedFiltering) {
2944 size += THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
2945 if (ug_info->largestexternallookupkeysize ==
2946 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
2947 size +=
2948 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
2949 if (ug_info->largestexternallookupkeysize ==
2950 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
2951 size +=
2952 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
2953 }
2954
2955 if ((ret_val = fill_init_enet_entries(ugeth, &(ugeth->
2956 p_init_enet_param_shadow->rxthread[0]),
2957 (u8) (numThreadsRxNumerical + 1)
2958 /* Rx needs one extra for terminator */
2959 , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT,
2960 ug_info->riscRx, 1)) != 0) {
Li Yang890de952007-07-19 11:48:29 +08002961 if (netif_msg_ifup(ugeth))
2962 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002963 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002964 return ret_val;
2965 }
2966
2967 ugeth->p_init_enet_param_shadow->txglobal =
2968 ugeth->tx_glbl_pram_offset | ug_info->riscTx;
2969 if ((ret_val =
2970 fill_init_enet_entries(ugeth,
2971 &(ugeth->p_init_enet_param_shadow->
2972 txthread[0]), numThreadsTxNumerical,
Li Yang18a8e862006-10-19 21:07:34 -05002973 sizeof(struct ucc_geth_thread_tx_pram),
Li Yangce973b12006-08-14 23:00:11 -07002974 UCC_GETH_THREAD_TX_PRAM_ALIGNMENT,
2975 ug_info->riscTx, 0)) != 0) {
Li Yang890de952007-07-19 11:48:29 +08002976 if (netif_msg_ifup(ugeth))
2977 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002978 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002979 return ret_val;
2980 }
2981
2982 /* Load Rx bds with buffers */
2983 for (i = 0; i < ug_info->numQueuesRx; i++) {
2984 if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) {
Li Yang890de952007-07-19 11:48:29 +08002985 if (netif_msg_ifup(ugeth))
2986 ugeth_err("%s: Can not fill Rx bds with buffers.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002987 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002988 return ret_val;
2989 }
2990 }
2991
2992 /* Allocate InitEnet command parameter structure */
Li Yang18a8e862006-10-19 21:07:34 -05002993 init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4);
Timur Tabi4c356302007-05-08 14:46:36 -05002994 if (IS_ERR_VALUE(init_enet_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002995 if (netif_msg_ifup(ugeth))
2996 ugeth_err
2997 ("%s: Can not allocate DPRAM memory for p_init_enet_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002998 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002999 return -ENOMEM;
3000 }
3001 p_init_enet_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05003002 (struct ucc_geth_init_pram __iomem *) qe_muram_addr(init_enet_pram_offset);
Li Yangce973b12006-08-14 23:00:11 -07003003
3004 /* Copy shadow InitEnet command parameter structure into PRAM */
Andy Fleming6fee40e2008-05-02 13:01:23 -05003005 out_8(&p_init_enet_pram->resinit1,
3006 ugeth->p_init_enet_param_shadow->resinit1);
3007 out_8(&p_init_enet_pram->resinit2,
3008 ugeth->p_init_enet_param_shadow->resinit2);
3009 out_8(&p_init_enet_pram->resinit3,
3010 ugeth->p_init_enet_param_shadow->resinit3);
3011 out_8(&p_init_enet_pram->resinit4,
3012 ugeth->p_init_enet_param_shadow->resinit4);
Li Yangce973b12006-08-14 23:00:11 -07003013 out_be16(&p_init_enet_pram->resinit5,
3014 ugeth->p_init_enet_param_shadow->resinit5);
Andy Fleming6fee40e2008-05-02 13:01:23 -05003015 out_8(&p_init_enet_pram->largestexternallookupkeysize,
3016 ugeth->p_init_enet_param_shadow->largestexternallookupkeysize);
Li Yangce973b12006-08-14 23:00:11 -07003017 out_be32(&p_init_enet_pram->rgftgfrxglobal,
3018 ugeth->p_init_enet_param_shadow->rgftgfrxglobal);
3019 for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_RX; i++)
3020 out_be32(&p_init_enet_pram->rxthread[i],
3021 ugeth->p_init_enet_param_shadow->rxthread[i]);
3022 out_be32(&p_init_enet_pram->txglobal,
3023 ugeth->p_init_enet_param_shadow->txglobal);
3024 for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_TX; i++)
3025 out_be32(&p_init_enet_pram->txthread[i],
3026 ugeth->p_init_enet_param_shadow->txthread[i]);
3027
3028 /* Issue QE command */
3029 cecr_subblock =
3030 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
Li Yang18a8e862006-10-19 21:07:34 -05003031 qe_issue_cmd(command, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
Li Yangce973b12006-08-14 23:00:11 -07003032 init_enet_pram_offset);
3033
3034 /* Free InitEnet command parameter */
3035 qe_muram_free(init_enet_pram_offset);
3036
3037 return 0;
3038}
3039
Li Yangce973b12006-08-14 23:00:11 -07003040/* This is called by the kernel when a frame is ready for transmission. */
3041/* It is pointed to by the dev->hard_start_xmit function pointer */
3042static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
3043{
Li Yang18a8e862006-10-19 21:07:34 -05003044 struct ucc_geth_private *ugeth = netdev_priv(dev);
Michael Reissd5b90492007-04-13 01:26:19 -05003045#ifdef CONFIG_UGETH_TX_ON_DEMAND
3046 struct ucc_fast_private *uccf;
3047#endif
Andy Fleming6fee40e2008-05-02 13:01:23 -05003048 u8 __iomem *bd; /* BD pointer */
Li Yangce973b12006-08-14 23:00:11 -07003049 u32 bd_status;
3050 u8 txQ = 0;
3051
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003052 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003053
3054 spin_lock_irq(&ugeth->lock);
3055
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003056 dev->stats.tx_bytes += skb->len;
Li Yangce973b12006-08-14 23:00:11 -07003057
3058 /* Start from the next BD that should be filled */
3059 bd = ugeth->txBd[txQ];
Andy Fleming6fee40e2008-05-02 13:01:23 -05003060 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003061 /* Save the skb pointer so we can free it later */
3062 ugeth->tx_skbuff[txQ][ugeth->skb_curtx[txQ]] = skb;
3063
3064 /* Update the current skb pointer (wrapping if this was the last) */
3065 ugeth->skb_curtx[txQ] =
3066 (ugeth->skb_curtx[txQ] +
3067 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
3068
3069 /* set up the buffer descriptor */
Andy Fleming6fee40e2008-05-02 13:01:23 -05003070 out_be32(&((struct qe_bd __iomem *)bd)->buf,
Andy Fleming7f802022008-05-15 17:00:21 -05003071 dma_map_single(&ugeth->dev->dev, skb->data,
3072 skb->len, DMA_TO_DEVICE));
Li Yangce973b12006-08-14 23:00:11 -07003073
Li Yang18a8e862006-10-19 21:07:34 -05003074 /* printk(KERN_DEBUG"skb->data is 0x%x\n",skb->data); */
Li Yangce973b12006-08-14 23:00:11 -07003075
3076 bd_status = (bd_status & T_W) | T_R | T_I | T_L | skb->len;
3077
Li Yang18a8e862006-10-19 21:07:34 -05003078 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05003079 out_be32((u32 __iomem *)bd, bd_status);
Li Yangce973b12006-08-14 23:00:11 -07003080
3081 dev->trans_start = jiffies;
3082
3083 /* Move to next BD in the ring */
3084 if (!(bd_status & T_W))
Li Yanga394f012007-03-06 16:53:46 +08003085 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07003086 else
Li Yanga394f012007-03-06 16:53:46 +08003087 bd = ugeth->p_tx_bd_ring[txQ];
Li Yangce973b12006-08-14 23:00:11 -07003088
3089 /* If the next BD still needs to be cleaned up, then the bds
3090 are full. We need to tell the kernel to stop sending us stuff. */
3091 if (bd == ugeth->confBd[txQ]) {
3092 if (!netif_queue_stopped(dev))
3093 netif_stop_queue(dev);
3094 }
3095
Li Yanga394f012007-03-06 16:53:46 +08003096 ugeth->txBd[txQ] = bd;
3097
Li Yangce973b12006-08-14 23:00:11 -07003098 if (ugeth->p_scheduler) {
3099 ugeth->cpucount[txQ]++;
3100 /* Indicate to QE that there are more Tx bds ready for
3101 transmission */
3102 /* This is done by writing a running counter of the bd
3103 count to the scheduler PRAM. */
3104 out_be16(ugeth->p_cpucount[txQ], ugeth->cpucount[txQ]);
3105 }
3106
Michael Reissd5b90492007-04-13 01:26:19 -05003107#ifdef CONFIG_UGETH_TX_ON_DEMAND
3108 uccf = ugeth->uccf;
3109 out_be16(uccf->p_utodr, UCC_FAST_TOD);
3110#endif
Li Yangce973b12006-08-14 23:00:11 -07003111 spin_unlock_irq(&ugeth->lock);
3112
Li Yang6f6881b2007-03-19 11:58:02 +08003113 return 0;
Li Yangce973b12006-08-14 23:00:11 -07003114}
3115
Li Yang18a8e862006-10-19 21:07:34 -05003116static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit)
Li Yangce973b12006-08-14 23:00:11 -07003117{
3118 struct sk_buff *skb;
Andy Fleming6fee40e2008-05-02 13:01:23 -05003119 u8 __iomem *bd;
Li Yangce973b12006-08-14 23:00:11 -07003120 u16 length, howmany = 0;
3121 u32 bd_status;
3122 u8 *bdBuffer;
Andrew Morton4b8fdef2007-12-13 16:02:55 -08003123 struct net_device *dev;
Li Yangce973b12006-08-14 23:00:11 -07003124
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003125 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003126
Emil Medve88a15f22007-10-15 08:43:50 -05003127 dev = ugeth->dev;
3128
Li Yangce973b12006-08-14 23:00:11 -07003129 /* collect received buffers */
3130 bd = ugeth->rxBd[rxQ];
3131
Andy Fleming6fee40e2008-05-02 13:01:23 -05003132 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003133
3134 /* while there are received buffers and BD is full (~R_E) */
3135 while (!((bd_status & (R_E)) || (--rx_work_limit < 0))) {
Andy Fleming6fee40e2008-05-02 13:01:23 -05003136 bdBuffer = (u8 *) in_be32(&((struct qe_bd __iomem *)bd)->buf);
Li Yangce973b12006-08-14 23:00:11 -07003137 length = (u16) ((bd_status & BD_LENGTH_MASK) - 4);
3138 skb = ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]];
3139
3140 /* determine whether buffer is first, last, first and last
3141 (single buffer frame) or middle (not first and not last) */
3142 if (!skb ||
3143 (!(bd_status & (R_F | R_L))) ||
3144 (bd_status & R_ERRORS_FATAL)) {
Li Yang890de952007-07-19 11:48:29 +08003145 if (netif_msg_rx_err(ugeth))
3146 ugeth_err("%s, %d: ERROR!!! skb - 0x%08x",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003147 __func__, __LINE__, (u32) skb);
Li Yangce973b12006-08-14 23:00:11 -07003148 if (skb)
3149 dev_kfree_skb_any(skb);
3150
3151 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL;
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003152 dev->stats.rx_dropped++;
Li Yangce973b12006-08-14 23:00:11 -07003153 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003154 dev->stats.rx_packets++;
Li Yangce973b12006-08-14 23:00:11 -07003155 howmany++;
3156
3157 /* Prep the skb for the packet */
3158 skb_put(skb, length);
3159
3160 /* Tell the skb what kind of packet this is */
3161 skb->protocol = eth_type_trans(skb, ugeth->dev);
3162
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003163 dev->stats.rx_bytes += length;
Li Yangce973b12006-08-14 23:00:11 -07003164 /* Send the packet up the stack */
Li Yangce973b12006-08-14 23:00:11 -07003165 netif_receive_skb(skb);
Li Yangce973b12006-08-14 23:00:11 -07003166 }
3167
Li Yangce973b12006-08-14 23:00:11 -07003168 skb = get_new_skb(ugeth, bd);
3169 if (!skb) {
Li Yang890de952007-07-19 11:48:29 +08003170 if (netif_msg_rx_err(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003171 ugeth_warn("%s: No Rx Data Buffer", __func__);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003172 dev->stats.rx_dropped++;
Li Yangce973b12006-08-14 23:00:11 -07003173 break;
3174 }
3175
3176 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = skb;
3177
3178 /* update to point at the next skb */
3179 ugeth->skb_currx[rxQ] =
3180 (ugeth->skb_currx[rxQ] +
3181 1) & RX_RING_MOD_MASK(ugeth->ug_info->bdRingLenRx[rxQ]);
3182
3183 if (bd_status & R_W)
3184 bd = ugeth->p_rx_bd_ring[rxQ];
3185 else
Li Yang18a8e862006-10-19 21:07:34 -05003186 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07003187
Andy Fleming6fee40e2008-05-02 13:01:23 -05003188 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003189 }
3190
3191 ugeth->rxBd[rxQ] = bd;
Li Yangce973b12006-08-14 23:00:11 -07003192 return howmany;
3193}
3194
3195static int ucc_geth_tx(struct net_device *dev, u8 txQ)
3196{
3197 /* Start from the next BD that should be filled */
Li Yang18a8e862006-10-19 21:07:34 -05003198 struct ucc_geth_private *ugeth = netdev_priv(dev);
Andy Fleming6fee40e2008-05-02 13:01:23 -05003199 u8 __iomem *bd; /* BD pointer */
Li Yangce973b12006-08-14 23:00:11 -07003200 u32 bd_status;
3201
3202 bd = ugeth->confBd[txQ];
Andy Fleming6fee40e2008-05-02 13:01:23 -05003203 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003204
3205 /* Normal processing. */
3206 while ((bd_status & T_R) == 0) {
3207 /* BD contains already transmitted buffer. */
3208 /* Handle the transmitted buffer and release */
3209 /* the BD to be used with the current frame */
3210
Li Yanga394f012007-03-06 16:53:46 +08003211 if ((bd == ugeth->txBd[txQ]) && (netif_queue_stopped(dev) == 0))
Li Yangce973b12006-08-14 23:00:11 -07003212 break;
3213
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003214 dev->stats.tx_packets++;
Li Yangce973b12006-08-14 23:00:11 -07003215
3216 /* Free the sk buffer associated with this TxBD */
3217 dev_kfree_skb_irq(ugeth->
3218 tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]]);
3219 ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL;
3220 ugeth->skb_dirtytx[txQ] =
3221 (ugeth->skb_dirtytx[txQ] +
3222 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
3223
3224 /* We freed a buffer, so now we can restart transmission */
3225 if (netif_queue_stopped(dev))
3226 netif_wake_queue(dev);
3227
3228 /* Advance the confirmation BD pointer */
3229 if (!(bd_status & T_W))
Li Yanga394f012007-03-06 16:53:46 +08003230 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07003231 else
Li Yanga394f012007-03-06 16:53:46 +08003232 bd = ugeth->p_tx_bd_ring[txQ];
Andy Fleming6fee40e2008-05-02 13:01:23 -05003233 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003234 }
Li Yanga394f012007-03-06 16:53:46 +08003235 ugeth->confBd[txQ] = bd;
Li Yangce973b12006-08-14 23:00:11 -07003236 return 0;
3237}
3238
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003239static int ucc_geth_poll(struct napi_struct *napi, int budget)
Li Yangce973b12006-08-14 23:00:11 -07003240{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003241 struct ucc_geth_private *ugeth = container_of(napi, struct ucc_geth_private, napi);
Michael Reiss702ff122007-04-13 01:26:11 -05003242 struct ucc_geth_info *ug_info;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003243 int howmany, i;
Li Yangce973b12006-08-14 23:00:11 -07003244
Michael Reiss702ff122007-04-13 01:26:11 -05003245 ug_info = ugeth->ug_info;
3246
Michael Reiss702ff122007-04-13 01:26:11 -05003247 howmany = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003248 for (i = 0; i < ug_info->numQueuesRx; i++)
3249 howmany += ucc_geth_rx(ugeth, i, budget - howmany);
Michael Reiss702ff122007-04-13 01:26:11 -05003250
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003251 if (howmany < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08003252 napi_complete(napi);
Timur Tabi3bc53422009-01-11 00:25:21 -08003253 setbits32(ugeth->uccf->p_uccm, UCCE_RX_EVENTS);
Michael Reiss702ff122007-04-13 01:26:11 -05003254 }
Li Yangce973b12006-08-14 23:00:11 -07003255
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003256 return howmany;
Li Yangce973b12006-08-14 23:00:11 -07003257}
Li Yangce973b12006-08-14 23:00:11 -07003258
David Howells7d12e782006-10-05 14:55:46 +01003259static irqreturn_t ucc_geth_irq_handler(int irq, void *info)
Li Yangce973b12006-08-14 23:00:11 -07003260{
Jeff Garzik06efcad2007-10-19 03:10:11 -04003261 struct net_device *dev = info;
Li Yang18a8e862006-10-19 21:07:34 -05003262 struct ucc_geth_private *ugeth = netdev_priv(dev);
3263 struct ucc_fast_private *uccf;
3264 struct ucc_geth_info *ug_info;
Michael Reiss702ff122007-04-13 01:26:11 -05003265 register u32 ucce;
3266 register u32 uccm;
Michael Reiss702ff122007-04-13 01:26:11 -05003267 register u32 tx_mask;
3268 u8 i;
Li Yangce973b12006-08-14 23:00:11 -07003269
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003270 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003271
Li Yangce973b12006-08-14 23:00:11 -07003272 uccf = ugeth->uccf;
3273 ug_info = ugeth->ug_info;
3274
Michael Reiss702ff122007-04-13 01:26:11 -05003275 /* read and clear events */
3276 ucce = (u32) in_be32(uccf->p_ucce);
3277 uccm = (u32) in_be32(uccf->p_uccm);
3278 ucce &= uccm;
3279 out_be32(uccf->p_ucce, ucce);
Li Yangce973b12006-08-14 23:00:11 -07003280
Michael Reiss702ff122007-04-13 01:26:11 -05003281 /* check for receive events that require processing */
3282 if (ucce & UCCE_RX_EVENTS) {
Ben Hutchings288379f2009-01-19 16:43:59 -08003283 if (napi_schedule_prep(&ugeth->napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003284 uccm &= ~UCCE_RX_EVENTS;
Michael Reiss702ff122007-04-13 01:26:11 -05003285 out_be32(uccf->p_uccm, uccm);
Ben Hutchings288379f2009-01-19 16:43:59 -08003286 __napi_schedule(&ugeth->napi);
Li Yangce973b12006-08-14 23:00:11 -07003287 }
Michael Reiss702ff122007-04-13 01:26:11 -05003288 }
Li Yangce973b12006-08-14 23:00:11 -07003289
Michael Reiss702ff122007-04-13 01:26:11 -05003290 /* Tx event processing */
3291 if (ucce & UCCE_TX_EVENTS) {
3292 spin_lock(&ugeth->lock);
Timur Tabi3bc53422009-01-11 00:25:21 -08003293 tx_mask = UCC_GETH_UCCE_TXB0;
Li Yangce973b12006-08-14 23:00:11 -07003294 for (i = 0; i < ug_info->numQueuesTx; i++) {
3295 if (ucce & tx_mask)
3296 ucc_geth_tx(dev, i);
3297 ucce &= ~tx_mask;
3298 tx_mask <<= 1;
3299 }
Michael Reiss702ff122007-04-13 01:26:11 -05003300 spin_unlock(&ugeth->lock);
3301 }
Li Yangce973b12006-08-14 23:00:11 -07003302
Michael Reiss702ff122007-04-13 01:26:11 -05003303 /* Errors and other events */
3304 if (ucce & UCCE_OTHER) {
Timur Tabi3bc53422009-01-11 00:25:21 -08003305 if (ucce & UCC_GETH_UCCE_BSY)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003306 dev->stats.rx_errors++;
Timur Tabi3bc53422009-01-11 00:25:21 -08003307 if (ucce & UCC_GETH_UCCE_TXE)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003308 dev->stats.tx_errors++;
Li Yangce973b12006-08-14 23:00:11 -07003309 }
Li Yangce973b12006-08-14 23:00:11 -07003310
3311 return IRQ_HANDLED;
3312}
3313
Anton Vorontsov26d29ea2008-02-01 16:22:54 +03003314#ifdef CONFIG_NET_POLL_CONTROLLER
3315/*
3316 * Polling 'interrupt' - used by things like netconsole to send skbs
3317 * without having to re-enable interrupts. It's not called while
3318 * the interrupt routine is executing.
3319 */
3320static void ucc_netpoll(struct net_device *dev)
3321{
3322 struct ucc_geth_private *ugeth = netdev_priv(dev);
3323 int irq = ugeth->ug_info->uf_info.irq;
3324
3325 disable_irq(irq);
3326 ucc_geth_irq_handler(irq, dev);
3327 enable_irq(irq);
3328}
3329#endif /* CONFIG_NET_POLL_CONTROLLER */
3330
Li Yangce973b12006-08-14 23:00:11 -07003331/* Called when something needs to use the ethernet device */
3332/* Returns 0 for success. */
3333static int ucc_geth_open(struct net_device *dev)
3334{
Li Yang18a8e862006-10-19 21:07:34 -05003335 struct ucc_geth_private *ugeth = netdev_priv(dev);
Li Yangce973b12006-08-14 23:00:11 -07003336 int err;
3337
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003338 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003339
3340 /* Test station address */
3341 if (dev->dev_addr[0] & ENET_GROUP_ADDR) {
Li Yang890de952007-07-19 11:48:29 +08003342 if (netif_msg_ifup(ugeth))
3343 ugeth_err("%s: Multicast address used for station address"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003344 " - is this what you wanted?", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003345 return -EINVAL;
3346 }
3347
Kim Phillips728de4c92007-04-13 01:26:03 -05003348 err = ucc_struct_init(ugeth);
3349 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003350 if (netif_msg_ifup(ugeth))
3351 ugeth_err("%s: Cannot configure internal struct, aborting.", dev->name);
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00003352 goto out_err_stop;
Kim Phillips728de4c92007-04-13 01:26:03 -05003353 }
3354
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003355 napi_enable(&ugeth->napi);
Francois Romieu1a342d22008-07-11 00:34:40 +02003356
Li Yangce973b12006-08-14 23:00:11 -07003357 err = ucc_geth_startup(ugeth);
3358 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003359 if (netif_msg_ifup(ugeth))
3360 ugeth_err("%s: Cannot configure net device, aborting.",
3361 dev->name);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003362 goto out_err;
Li Yangce973b12006-08-14 23:00:11 -07003363 }
3364
3365 err = adjust_enet_interface(ugeth);
3366 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003367 if (netif_msg_ifup(ugeth))
3368 ugeth_err("%s: Cannot configure net device, aborting.",
3369 dev->name);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003370 goto out_err;
Li Yangce973b12006-08-14 23:00:11 -07003371 }
3372
3373 /* Set MACSTNADDR1, MACSTNADDR2 */
3374 /* For more details see the hardware spec. */
3375 init_mac_station_addr_regs(dev->dev_addr[0],
3376 dev->dev_addr[1],
3377 dev->dev_addr[2],
3378 dev->dev_addr[3],
3379 dev->dev_addr[4],
3380 dev->dev_addr[5],
3381 &ugeth->ug_regs->macstnaddr1,
3382 &ugeth->ug_regs->macstnaddr2);
3383
3384 err = init_phy(dev);
3385 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003386 if (netif_msg_ifup(ugeth))
3387 ugeth_err("%s: Cannot initialize PHY, aborting.", dev->name);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003388 goto out_err;
Li Yangce973b12006-08-14 23:00:11 -07003389 }
Kim Phillips728de4c92007-04-13 01:26:03 -05003390
3391 phy_start(ugeth->phydev);
3392
Li Yangce973b12006-08-14 23:00:11 -07003393 err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
3394 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003395 if (netif_msg_ifup(ugeth))
3396 ugeth_err("%s: Cannot enable net device, aborting.", dev->name);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003397 goto out_err;
Li Yangce973b12006-08-14 23:00:11 -07003398 }
3399
Anton Vorontsov67c2fb82008-12-18 08:23:29 +00003400 err = request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler,
3401 0, "UCC Geth", dev);
3402 if (err) {
3403 if (netif_msg_ifup(ugeth))
3404 ugeth_err("%s: Cannot get IRQ for net device, aborting.",
3405 dev->name);
Anton Vorontsov67c2fb82008-12-18 08:23:29 +00003406 goto out_err;
3407 }
3408
Li Yangce973b12006-08-14 23:00:11 -07003409 netif_start_queue(dev);
3410
3411 return err;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003412
3413out_err:
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003414 napi_disable(&ugeth->napi);
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00003415out_err_stop:
Anton Vorontsovba574692008-12-18 08:23:31 +00003416 ucc_geth_stop(ugeth);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003417 return err;
Li Yangce973b12006-08-14 23:00:11 -07003418}
3419
3420/* Stops the kernel queue, and halts the controller */
3421static int ucc_geth_close(struct net_device *dev)
3422{
Li Yang18a8e862006-10-19 21:07:34 -05003423 struct ucc_geth_private *ugeth = netdev_priv(dev);
Li Yangce973b12006-08-14 23:00:11 -07003424
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003425 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003426
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003427 napi_disable(&ugeth->napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003428
Li Yangce973b12006-08-14 23:00:11 -07003429 ucc_geth_stop(ugeth);
3430
Anton Vorontsov67c2fb82008-12-18 08:23:29 +00003431 free_irq(ugeth->ug_info->uf_info.irq, ugeth->dev);
3432
Kim Phillips728de4c92007-04-13 01:26:03 -05003433 phy_disconnect(ugeth->phydev);
3434 ugeth->phydev = NULL;
Li Yangce973b12006-08-14 23:00:11 -07003435
3436 netif_stop_queue(dev);
3437
3438 return 0;
3439}
3440
Anton Vorontsovfdb614c2008-12-23 06:59:25 +00003441/* Reopen device. This will reset the MAC and PHY. */
3442static void ucc_geth_timeout_work(struct work_struct *work)
3443{
3444 struct ucc_geth_private *ugeth;
3445 struct net_device *dev;
3446
3447 ugeth = container_of(work, struct ucc_geth_private, timeout_work);
3448 dev = ugeth->dev;
3449
3450 ugeth_vdbg("%s: IN", __func__);
3451
3452 dev->stats.tx_errors++;
3453
3454 ugeth_dump_regs(ugeth);
3455
3456 if (dev->flags & IFF_UP) {
3457 /*
3458 * Must reset MAC *and* PHY. This is done by reopening
3459 * the device.
3460 */
3461 ucc_geth_close(dev);
3462 ucc_geth_open(dev);
3463 }
3464
3465 netif_tx_schedule_all(dev);
3466}
3467
3468/*
3469 * ucc_geth_timeout gets called when a packet has not been
3470 * transmitted after a set amount of time.
3471 */
3472static void ucc_geth_timeout(struct net_device *dev)
3473{
3474 struct ucc_geth_private *ugeth = netdev_priv(dev);
3475
3476 netif_carrier_off(dev);
3477 schedule_work(&ugeth->timeout_work);
3478}
3479
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003480static phy_interface_t to_phy_interface(const char *phy_connection_type)
Kim Phillips728de4c92007-04-13 01:26:03 -05003481{
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003482 if (strcasecmp(phy_connection_type, "mii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003483 return PHY_INTERFACE_MODE_MII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003484 if (strcasecmp(phy_connection_type, "gmii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003485 return PHY_INTERFACE_MODE_GMII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003486 if (strcasecmp(phy_connection_type, "tbi") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003487 return PHY_INTERFACE_MODE_TBI;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003488 if (strcasecmp(phy_connection_type, "rmii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003489 return PHY_INTERFACE_MODE_RMII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003490 if (strcasecmp(phy_connection_type, "rgmii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003491 return PHY_INTERFACE_MODE_RGMII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003492 if (strcasecmp(phy_connection_type, "rgmii-id") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003493 return PHY_INTERFACE_MODE_RGMII_ID;
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06003494 if (strcasecmp(phy_connection_type, "rgmii-txid") == 0)
3495 return PHY_INTERFACE_MODE_RGMII_TXID;
3496 if (strcasecmp(phy_connection_type, "rgmii-rxid") == 0)
3497 return PHY_INTERFACE_MODE_RGMII_RXID;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003498 if (strcasecmp(phy_connection_type, "rtbi") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003499 return PHY_INTERFACE_MODE_RTBI;
3500
3501 return PHY_INTERFACE_MODE_MII;
3502}
3503
Joakim Tjernlunda9dbae72009-03-20 21:09:14 +01003504static const struct net_device_ops ucc_geth_netdev_ops = {
3505 .ndo_open = ucc_geth_open,
3506 .ndo_stop = ucc_geth_close,
3507 .ndo_start_xmit = ucc_geth_start_xmit,
3508 .ndo_validate_addr = eth_validate_addr,
3509 .ndo_set_mac_address = eth_mac_addr,
3510 .ndo_change_mtu = eth_change_mtu,
3511 .ndo_set_multicast_list = ucc_geth_set_multi,
3512 .ndo_tx_timeout = ucc_geth_timeout,
3513#ifdef CONFIG_NET_POLL_CONTROLLER
3514 .ndo_poll_controller = ucc_netpoll,
3515#endif
3516};
3517
Li Yang18a8e862006-10-19 21:07:34 -05003518static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *match)
Li Yangce973b12006-08-14 23:00:11 -07003519{
Li Yang18a8e862006-10-19 21:07:34 -05003520 struct device *device = &ofdev->dev;
3521 struct device_node *np = ofdev->node;
Kim Phillips728de4c92007-04-13 01:26:03 -05003522 struct device_node *mdio;
Li Yangce973b12006-08-14 23:00:11 -07003523 struct net_device *dev = NULL;
3524 struct ucc_geth_private *ugeth = NULL;
3525 struct ucc_geth_info *ug_info;
Li Yang18a8e862006-10-19 21:07:34 -05003526 struct resource res;
3527 struct device_node *phy;
Kim Phillips728de4c92007-04-13 01:26:03 -05003528 int err, ucc_num, max_speed = 0;
Li Yang18a8e862006-10-19 21:07:34 -05003529 const phandle *ph;
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003530 const u32 *fixed_link;
Li Yang18a8e862006-10-19 21:07:34 -05003531 const unsigned int *prop;
Timur Tabi9fb1e352007-12-03 15:17:59 -06003532 const char *sprop;
Li Yang9b4c7a42007-02-08 17:35:54 +08003533 const void *mac_addr;
Kim Phillips728de4c92007-04-13 01:26:03 -05003534 phy_interface_t phy_interface;
3535 static const int enet_to_speed[] = {
3536 SPEED_10, SPEED_10, SPEED_10,
3537 SPEED_100, SPEED_100, SPEED_100,
3538 SPEED_1000, SPEED_1000, SPEED_1000, SPEED_1000,
3539 };
3540 static const phy_interface_t enet_to_phy_interface[] = {
3541 PHY_INTERFACE_MODE_MII, PHY_INTERFACE_MODE_RMII,
3542 PHY_INTERFACE_MODE_RGMII, PHY_INTERFACE_MODE_MII,
3543 PHY_INTERFACE_MODE_RMII, PHY_INTERFACE_MODE_RGMII,
3544 PHY_INTERFACE_MODE_GMII, PHY_INTERFACE_MODE_RGMII,
3545 PHY_INTERFACE_MODE_TBI, PHY_INTERFACE_MODE_RTBI,
3546 };
Li Yangce973b12006-08-14 23:00:11 -07003547
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003548 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003549
Anton Vorontsov56626f32008-04-11 20:06:54 +04003550 prop = of_get_property(np, "cell-index", NULL);
3551 if (!prop) {
3552 prop = of_get_property(np, "device-id", NULL);
3553 if (!prop)
3554 return -ENODEV;
3555 }
3556
Li Yang18a8e862006-10-19 21:07:34 -05003557 ucc_num = *prop - 1;
3558 if ((ucc_num < 0) || (ucc_num > 7))
3559 return -ENODEV;
Li Yangce973b12006-08-14 23:00:11 -07003560
Li Yang18a8e862006-10-19 21:07:34 -05003561 ug_info = &ugeth_info[ucc_num];
Li Yang890de952007-07-19 11:48:29 +08003562 if (ug_info == NULL) {
3563 if (netif_msg_probe(&debug))
3564 ugeth_err("%s: [%d] Missing additional data!",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003565 __func__, ucc_num);
Li Yang890de952007-07-19 11:48:29 +08003566 return -ENODEV;
3567 }
3568
Li Yang18a8e862006-10-19 21:07:34 -05003569 ug_info->uf_info.ucc_num = ucc_num;
Kim Phillips728de4c92007-04-13 01:26:03 -05003570
Timur Tabi9fb1e352007-12-03 15:17:59 -06003571 sprop = of_get_property(np, "rx-clock-name", NULL);
3572 if (sprop) {
3573 ug_info->uf_info.rx_clock = qe_clock_source(sprop);
3574 if ((ug_info->uf_info.rx_clock < QE_CLK_NONE) ||
3575 (ug_info->uf_info.rx_clock > QE_CLK24)) {
3576 printk(KERN_ERR
3577 "ucc_geth: invalid rx-clock-name property\n");
3578 return -EINVAL;
3579 }
3580 } else {
3581 prop = of_get_property(np, "rx-clock", NULL);
3582 if (!prop) {
3583 /* If both rx-clock-name and rx-clock are missing,
3584 we want to tell people to use rx-clock-name. */
3585 printk(KERN_ERR
3586 "ucc_geth: missing rx-clock-name property\n");
3587 return -EINVAL;
3588 }
3589 if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
3590 printk(KERN_ERR
3591 "ucc_geth: invalid rx-clock propperty\n");
3592 return -EINVAL;
3593 }
3594 ug_info->uf_info.rx_clock = *prop;
3595 }
3596
3597 sprop = of_get_property(np, "tx-clock-name", NULL);
3598 if (sprop) {
3599 ug_info->uf_info.tx_clock = qe_clock_source(sprop);
3600 if ((ug_info->uf_info.tx_clock < QE_CLK_NONE) ||
3601 (ug_info->uf_info.tx_clock > QE_CLK24)) {
3602 printk(KERN_ERR
3603 "ucc_geth: invalid tx-clock-name property\n");
3604 return -EINVAL;
3605 }
3606 } else {
Joakim Tjernlunde4105532008-04-29 13:03:57 +02003607 prop = of_get_property(np, "tx-clock", NULL);
Timur Tabi9fb1e352007-12-03 15:17:59 -06003608 if (!prop) {
3609 printk(KERN_ERR
3610 "ucc_geth: mising tx-clock-name property\n");
3611 return -EINVAL;
3612 }
3613 if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
3614 printk(KERN_ERR
3615 "ucc_geth: invalid tx-clock property\n");
3616 return -EINVAL;
3617 }
3618 ug_info->uf_info.tx_clock = *prop;
3619 }
3620
Li Yang18a8e862006-10-19 21:07:34 -05003621 err = of_address_to_resource(np, 0, &res);
3622 if (err)
3623 return -EINVAL;
3624
3625 ug_info->uf_info.regs = res.start;
3626 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003627 fixed_link = of_get_property(np, "fixed-link", NULL);
3628 if (fixed_link) {
Anton Vorontsov61fa9dc2009-03-22 21:30:52 -07003629 snprintf(ug_info->phy_bus_id, sizeof(ug_info->phy_bus_id),
3630 PHY_ID_FMT, "0", fixed_link[0]);
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003631 phy = NULL;
3632 } else {
Anton Vorontsov61fa9dc2009-03-22 21:30:52 -07003633 char bus_name[MII_BUS_ID_SIZE];
3634
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003635 ph = of_get_property(np, "phy-handle", NULL);
3636 phy = of_find_node_by_phandle(*ph);
Li Yang18a8e862006-10-19 21:07:34 -05003637
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003638 if (phy == NULL)
3639 return -ENODEV;
Li Yang18a8e862006-10-19 21:07:34 -05003640
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003641 /* set the PHY address */
3642 prop = of_get_property(phy, "reg", NULL);
3643 if (prop == NULL)
3644 return -1;
Li Yang18a8e862006-10-19 21:07:34 -05003645
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003646 /* Set the bus id */
3647 mdio = of_get_parent(phy);
3648
3649 if (mdio == NULL)
3650 return -1;
3651
3652 err = of_address_to_resource(mdio, 0, &res);
3653 of_node_put(mdio);
3654
3655 if (err)
3656 return -1;
3657
Anton Vorontsovbb4f92b2009-03-24 12:06:46 -07003658 fsl_pq_mdio_bus_name(bus_name, mdio);
Anton Vorontsov61fa9dc2009-03-22 21:30:52 -07003659 snprintf(ug_info->phy_bus_id, sizeof(ug_info->phy_bus_id),
3660 "%s:%02x", bus_name, *prop);
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003661 }
Kim Phillips728de4c92007-04-13 01:26:03 -05003662
3663 /* get the phy interface type, or default to MII */
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003664 prop = of_get_property(np, "phy-connection-type", NULL);
Kim Phillips728de4c92007-04-13 01:26:03 -05003665 if (!prop) {
3666 /* handle interface property present in old trees */
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003667 prop = of_get_property(phy, "interface", NULL);
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003668 if (prop != NULL) {
Kim Phillips728de4c92007-04-13 01:26:03 -05003669 phy_interface = enet_to_phy_interface[*prop];
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003670 max_speed = enet_to_speed[*prop];
3671 } else
Kim Phillips728de4c92007-04-13 01:26:03 -05003672 phy_interface = PHY_INTERFACE_MODE_MII;
3673 } else {
3674 phy_interface = to_phy_interface((const char *)prop);
3675 }
3676
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003677 /* get speed, or derive from PHY interface */
3678 if (max_speed == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003679 switch (phy_interface) {
3680 case PHY_INTERFACE_MODE_GMII:
3681 case PHY_INTERFACE_MODE_RGMII:
3682 case PHY_INTERFACE_MODE_RGMII_ID:
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06003683 case PHY_INTERFACE_MODE_RGMII_RXID:
3684 case PHY_INTERFACE_MODE_RGMII_TXID:
Kim Phillips728de4c92007-04-13 01:26:03 -05003685 case PHY_INTERFACE_MODE_TBI:
3686 case PHY_INTERFACE_MODE_RTBI:
3687 max_speed = SPEED_1000;
3688 break;
3689 default:
3690 max_speed = SPEED_100;
3691 break;
3692 }
Kim Phillips728de4c92007-04-13 01:26:03 -05003693
3694 if (max_speed == SPEED_1000) {
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003695 /* configure muram FIFOs for gigabit operation */
Kim Phillips728de4c92007-04-13 01:26:03 -05003696 ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT;
3697 ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT;
3698 ug_info->uf_info.urfset = UCC_GETH_URFSET_GIGA_INIT;
3699 ug_info->uf_info.utfs = UCC_GETH_UTFS_GIGA_INIT;
3700 ug_info->uf_info.utfet = UCC_GETH_UTFET_GIGA_INIT;
3701 ug_info->uf_info.utftt = UCC_GETH_UTFTT_GIGA_INIT;
Joakim Tjernlundffea31e2008-03-06 18:48:46 +08003702 ug_info->numThreadsTx = UCC_GETH_NUM_OF_THREADS_4;
3703 ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_4;
Kim Phillips728de4c92007-04-13 01:26:03 -05003704 }
3705
Li Yang890de952007-07-19 11:48:29 +08003706 if (netif_msg_probe(&debug))
3707 printk(KERN_INFO "ucc_geth: UCC%1d at 0x%8x (irq = %d) \n",
3708 ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs,
3709 ug_info->uf_info.irq);
Li Yangce973b12006-08-14 23:00:11 -07003710
Li Yangce973b12006-08-14 23:00:11 -07003711 /* Create an ethernet device instance */
3712 dev = alloc_etherdev(sizeof(*ugeth));
3713
3714 if (dev == NULL)
3715 return -ENOMEM;
3716
3717 ugeth = netdev_priv(dev);
3718 spin_lock_init(&ugeth->lock);
3719
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03003720 /* Create CQs for hash tables */
3721 INIT_LIST_HEAD(&ugeth->group_hash_q);
3722 INIT_LIST_HEAD(&ugeth->ind_hash_q);
3723
Li Yangce973b12006-08-14 23:00:11 -07003724 dev_set_drvdata(device, dev);
3725
3726 /* Set the dev->base_addr to the gfar reg region */
3727 dev->base_addr = (unsigned long)(ug_info->uf_info.regs);
3728
Li Yangce973b12006-08-14 23:00:11 -07003729 SET_NETDEV_DEV(dev, device);
3730
3731 /* Fill in the dev structure */
Li Yangac421852007-07-19 11:47:47 +08003732 uec_set_ethtool_ops(dev);
Joakim Tjernlunda9dbae72009-03-20 21:09:14 +01003733 dev->netdev_ops = &ucc_geth_netdev_ops;
Li Yangce973b12006-08-14 23:00:11 -07003734 dev->watchdog_timeo = TX_TIMEOUT;
Anton Vorontsov1762a292008-12-18 08:23:26 +00003735 INIT_WORK(&ugeth->timeout_work, ucc_geth_timeout_work);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003736 netif_napi_add(dev, &ugeth->napi, ucc_geth_poll, UCC_GETH_DEV_WEIGHT);
Li Yangce973b12006-08-14 23:00:11 -07003737 dev->mtu = 1500;
Li Yangce973b12006-08-14 23:00:11 -07003738
Li Yang890de952007-07-19 11:48:29 +08003739 ugeth->msg_enable = netif_msg_init(debug.msg_enable, UGETH_MSG_DEFAULT);
Kim Phillips728de4c92007-04-13 01:26:03 -05003740 ugeth->phy_interface = phy_interface;
3741 ugeth->max_speed = max_speed;
3742
Li Yangce973b12006-08-14 23:00:11 -07003743 err = register_netdev(dev);
3744 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003745 if (netif_msg_probe(ugeth))
3746 ugeth_err("%s: Cannot register net device, aborting.",
3747 dev->name);
Li Yangce973b12006-08-14 23:00:11 -07003748 free_netdev(dev);
3749 return err;
3750 }
3751
Timur Tabie9eb70c2007-02-21 14:40:12 -06003752 mac_addr = of_get_mac_address(np);
Li Yang9b4c7a42007-02-08 17:35:54 +08003753 if (mac_addr)
3754 memcpy(dev->dev_addr, mac_addr, 6);
Li Yangce973b12006-08-14 23:00:11 -07003755
Kim Phillips728de4c92007-04-13 01:26:03 -05003756 ugeth->ug_info = ug_info;
3757 ugeth->dev = dev;
Haiying Wangb1c4a9dd2009-01-29 17:28:04 -08003758 ugeth->node = np;
Kim Phillips728de4c92007-04-13 01:26:03 -05003759
Li Yangce973b12006-08-14 23:00:11 -07003760 return 0;
3761}
3762
Li Yang18a8e862006-10-19 21:07:34 -05003763static int ucc_geth_remove(struct of_device* ofdev)
Li Yangce973b12006-08-14 23:00:11 -07003764{
Li Yang18a8e862006-10-19 21:07:34 -05003765 struct device *device = &ofdev->dev;
Li Yangce973b12006-08-14 23:00:11 -07003766 struct net_device *dev = dev_get_drvdata(device);
3767 struct ucc_geth_private *ugeth = netdev_priv(dev);
3768
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03003769 unregister_netdev(dev);
Li Yangce973b12006-08-14 23:00:11 -07003770 free_netdev(dev);
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03003771 ucc_geth_memclean(ugeth);
3772 dev_set_drvdata(device, NULL);
Li Yangce973b12006-08-14 23:00:11 -07003773
3774 return 0;
3775}
3776
Li Yang18a8e862006-10-19 21:07:34 -05003777static struct of_device_id ucc_geth_match[] = {
3778 {
3779 .type = "network",
3780 .compatible = "ucc_geth",
3781 },
3782 {},
3783};
3784
3785MODULE_DEVICE_TABLE(of, ucc_geth_match);
3786
3787static struct of_platform_driver ucc_geth_driver = {
3788 .name = DRV_NAME,
3789 .match_table = ucc_geth_match,
3790 .probe = ucc_geth_probe,
3791 .remove = ucc_geth_remove,
Li Yangce973b12006-08-14 23:00:11 -07003792};
3793
3794static int __init ucc_geth_init(void)
3795{
Kim Phillips728de4c92007-04-13 01:26:03 -05003796 int i, ret;
3797
Li Yang890de952007-07-19 11:48:29 +08003798 if (netif_msg_drv(&debug))
3799 printk(KERN_INFO "ucc_geth: " DRV_DESC "\n");
Li Yangce973b12006-08-14 23:00:11 -07003800 for (i = 0; i < 8; i++)
3801 memcpy(&(ugeth_info[i]), &ugeth_primary_info,
3802 sizeof(ugeth_primary_info));
3803
Kim Phillips728de4c92007-04-13 01:26:03 -05003804 ret = of_register_platform_driver(&ucc_geth_driver);
3805
Kim Phillips728de4c92007-04-13 01:26:03 -05003806 return ret;
Li Yangce973b12006-08-14 23:00:11 -07003807}
3808
3809static void __exit ucc_geth_exit(void)
3810{
Kim Phillipsa4f0c2c2006-11-15 12:29:35 -06003811 of_unregister_platform_driver(&ucc_geth_driver);
Li Yangce973b12006-08-14 23:00:11 -07003812}
3813
3814module_init(ucc_geth_init);
3815module_exit(ucc_geth_exit);
3816
3817MODULE_AUTHOR("Freescale Semiconductor, Inc");
3818MODULE_DESCRIPTION(DRV_DESC);
Kim Phillipsc2bcf002007-04-13 01:26:36 -05003819MODULE_VERSION(DRV_VERSION);
Li Yangce973b12006-08-14 23:00:11 -07003820MODULE_LICENSE("GPL");