blob: ca476a58087c565ae893557a7fd9f77ff5a8790a [file] [log] [blame]
Li Yangce973b12006-08-14 23:00:11 -07001/*
Haiying Wang047584c2009-06-02 04:04:15 +00002 * Copyright (C) 2006-2009 Freescale Semicondutor, Inc. All rights reserved.
Li Yangce973b12006-08-14 23:00:11 -07003 *
4 * Author: Shlomi Gridish <gridish@freescale.com>
Li Yang18a8e862006-10-19 21:07:34 -05005 * Li Yang <leoli@freescale.com>
Li Yangce973b12006-08-14 23:00:11 -07006 *
7 * Description:
8 * QE UCC Gigabit Ethernet Driver
9 *
Li Yangce973b12006-08-14 23:00:11 -070010 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 */
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/slab.h>
19#include <linux/stddef.h>
20#include <linux/interrupt.h>
21#include <linux/netdevice.h>
22#include <linux/etherdevice.h>
23#include <linux/skbuff.h>
24#include <linux/spinlock.h>
25#include <linux/mm.h>
Li Yangce973b12006-08-14 23:00:11 -070026#include <linux/dma-mapping.h>
Li Yangce973b12006-08-14 23:00:11 -070027#include <linux/mii.h>
Kim Phillips728de4c92007-04-13 01:26:03 -050028#include <linux/phy.h>
Timur Tabidf19b6b2007-01-09 12:31:38 -060029#include <linux/workqueue.h>
Grant Likely0b9da332009-04-25 12:53:23 +000030#include <linux/of_mdio.h>
Stephen Rothwell55b6c8e2008-05-23 16:28:54 +100031#include <linux/of_platform.h>
Li Yangce973b12006-08-14 23:00:11 -070032
33#include <asm/uaccess.h>
34#include <asm/irq.h>
35#include <asm/io.h>
36#include <asm/immap_qe.h>
37#include <asm/qe.h>
38#include <asm/ucc.h>
39#include <asm/ucc_fast.h>
40
41#include "ucc_geth.h"
Andy Fleming1577ece2009-02-04 16:42:12 -080042#include "fsl_pq_mdio.h"
Li Yangce973b12006-08-14 23:00:11 -070043
44#undef DEBUG
45
Li Yangce973b12006-08-14 23:00:11 -070046#define ugeth_printk(level, format, arg...) \
47 printk(level format "\n", ## arg)
48
49#define ugeth_dbg(format, arg...) \
50 ugeth_printk(KERN_DEBUG , format , ## arg)
51#define ugeth_err(format, arg...) \
52 ugeth_printk(KERN_ERR , format , ## arg)
53#define ugeth_info(format, arg...) \
54 ugeth_printk(KERN_INFO , format , ## arg)
55#define ugeth_warn(format, arg...) \
56 ugeth_printk(KERN_WARNING , format , ## arg)
57
58#ifdef UGETH_VERBOSE_DEBUG
59#define ugeth_vdbg ugeth_dbg
60#else
61#define ugeth_vdbg(fmt, args...) do { } while (0)
62#endif /* UGETH_VERBOSE_DEBUG */
Li Yang890de952007-07-19 11:48:29 +080063#define UGETH_MSG_DEFAULT (NETIF_MSG_IFUP << 1 ) - 1
Li Yangce973b12006-08-14 23:00:11 -070064
Emil Medve88a15f22007-10-15 08:43:50 -050065
Li Yangce973b12006-08-14 23:00:11 -070066static DEFINE_SPINLOCK(ugeth_lock);
67
Li Yang890de952007-07-19 11:48:29 +080068static struct {
69 u32 msg_enable;
70} debug = { -1 };
71
72module_param_named(debug, debug.msg_enable, int, 0);
73MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 0xffff=all)");
74
Li Yang18a8e862006-10-19 21:07:34 -050075static struct ucc_geth_info ugeth_primary_info = {
Li Yangce973b12006-08-14 23:00:11 -070076 .uf_info = {
77 .bd_mem_part = MEM_PART_SYSTEM,
78 .rtsm = UCC_FAST_SEND_IDLES_BETWEEN_FRAMES,
79 .max_rx_buf_length = 1536,
Kim Phillips728de4c92007-04-13 01:26:03 -050080 /* adjusted at startup if max-speed 1000 */
Li Yangce973b12006-08-14 23:00:11 -070081 .urfs = UCC_GETH_URFS_INIT,
82 .urfet = UCC_GETH_URFET_INIT,
83 .urfset = UCC_GETH_URFSET_INIT,
84 .utfs = UCC_GETH_UTFS_INIT,
85 .utfet = UCC_GETH_UTFET_INIT,
86 .utftt = UCC_GETH_UTFTT_INIT,
Li Yangce973b12006-08-14 23:00:11 -070087 .ufpt = 256,
88 .mode = UCC_FAST_PROTOCOL_MODE_ETHERNET,
89 .ttx_trx = UCC_FAST_GUMR_TRANSPARENT_TTX_TRX_NORMAL,
90 .tenc = UCC_FAST_TX_ENCODING_NRZ,
91 .renc = UCC_FAST_RX_ENCODING_NRZ,
92 .tcrc = UCC_FAST_16_BIT_CRC,
93 .synl = UCC_FAST_SYNC_LEN_NOT_USED,
94 },
95 .numQueuesTx = 1,
96 .numQueuesRx = 1,
97 .extendedFilteringChainPointer = ((uint32_t) NULL),
98 .typeorlen = 3072 /*1536 */ ,
99 .nonBackToBackIfgPart1 = 0x40,
100 .nonBackToBackIfgPart2 = 0x60,
101 .miminumInterFrameGapEnforcement = 0x50,
102 .backToBackInterFrameGap = 0x60,
103 .mblinterval = 128,
104 .nortsrbytetime = 5,
105 .fracsiz = 1,
106 .strictpriorityq = 0xff,
107 .altBebTruncation = 0xa,
108 .excessDefer = 1,
109 .maxRetransmission = 0xf,
110 .collisionWindow = 0x37,
111 .receiveFlowControl = 1,
Li Yangac421852007-07-19 11:47:47 +0800112 .transmitFlowControl = 1,
Li Yangce973b12006-08-14 23:00:11 -0700113 .maxGroupAddrInHash = 4,
114 .maxIndAddrInHash = 4,
115 .prel = 7,
116 .maxFrameLength = 1518,
117 .minFrameLength = 64,
118 .maxD1Length = 1520,
119 .maxD2Length = 1520,
120 .vlantype = 0x8100,
121 .ecamptr = ((uint32_t) NULL),
122 .eventRegMask = UCCE_OTHER,
123 .pausePeriod = 0xf000,
124 .interruptcoalescingmaxvalue = {1, 1, 1, 1, 1, 1, 1, 1},
125 .bdRingLenTx = {
126 TX_BD_RING_LEN,
127 TX_BD_RING_LEN,
128 TX_BD_RING_LEN,
129 TX_BD_RING_LEN,
130 TX_BD_RING_LEN,
131 TX_BD_RING_LEN,
132 TX_BD_RING_LEN,
133 TX_BD_RING_LEN},
134
135 .bdRingLenRx = {
136 RX_BD_RING_LEN,
137 RX_BD_RING_LEN,
138 RX_BD_RING_LEN,
139 RX_BD_RING_LEN,
140 RX_BD_RING_LEN,
141 RX_BD_RING_LEN,
142 RX_BD_RING_LEN,
143 RX_BD_RING_LEN},
144
145 .numStationAddresses = UCC_GETH_NUM_OF_STATION_ADDRESSES_1,
146 .largestexternallookupkeysize =
147 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE,
Li Yangac421852007-07-19 11:47:47 +0800148 .statisticsMode = UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE |
149 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX |
150 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX,
Li Yangce973b12006-08-14 23:00:11 -0700151 .vlanOperationTagged = UCC_GETH_VLAN_OPERATION_TAGGED_NOP,
152 .vlanOperationNonTagged = UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP,
153 .rxQoSMode = UCC_GETH_QOS_MODE_DEFAULT,
154 .aufc = UPSMR_AUTOMATIC_FLOW_CONTROL_MODE_NONE,
155 .padAndCrc = MACCFG2_PAD_AND_CRC_MODE_PAD_AND_CRC,
Joakim Tjernlundffea31e2008-03-06 18:48:46 +0800156 .numThreadsTx = UCC_GETH_NUM_OF_THREADS_1,
157 .numThreadsRx = UCC_GETH_NUM_OF_THREADS_1,
Li Yangce973b12006-08-14 23:00:11 -0700158 .riscTx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
159 .riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
160};
161
Li Yang18a8e862006-10-19 21:07:34 -0500162static struct ucc_geth_info ugeth_info[8];
Li Yangce973b12006-08-14 23:00:11 -0700163
164#ifdef DEBUG
165static void mem_disp(u8 *addr, int size)
166{
167 u8 *i;
168 int size16Aling = (size >> 4) << 4;
169 int size4Aling = (size >> 2) << 2;
170 int notAlign = 0;
171 if (size % 16)
172 notAlign = 1;
173
174 for (i = addr; (u32) i < (u32) addr + size16Aling; i += 16)
175 printk("0x%08x: %08x %08x %08x %08x\r\n",
176 (u32) i,
177 *((u32 *) (i)),
178 *((u32 *) (i + 4)),
179 *((u32 *) (i + 8)), *((u32 *) (i + 12)));
180 if (notAlign == 1)
181 printk("0x%08x: ", (u32) i);
182 for (; (u32) i < (u32) addr + size4Aling; i += 4)
183 printk("%08x ", *((u32 *) (i)));
184 for (; (u32) i < (u32) addr + size; i++)
185 printk("%02x", *((u8 *) (i)));
186 if (notAlign == 1)
187 printk("\r\n");
188}
189#endif /* DEBUG */
190
Li Yangce973b12006-08-14 23:00:11 -0700191static struct list_head *dequeue(struct list_head *lh)
192{
193 unsigned long flags;
194
Scott Wood1083cfe2006-12-07 13:31:07 -0600195 spin_lock_irqsave(&ugeth_lock, flags);
Li Yangce973b12006-08-14 23:00:11 -0700196 if (!list_empty(lh)) {
197 struct list_head *node = lh->next;
198 list_del(node);
Scott Wood1083cfe2006-12-07 13:31:07 -0600199 spin_unlock_irqrestore(&ugeth_lock, flags);
Li Yangce973b12006-08-14 23:00:11 -0700200 return node;
201 } else {
Scott Wood1083cfe2006-12-07 13:31:07 -0600202 spin_unlock_irqrestore(&ugeth_lock, flags);
Li Yangce973b12006-08-14 23:00:11 -0700203 return NULL;
204 }
205}
206
Andy Fleming6fee40e2008-05-02 13:01:23 -0500207static struct sk_buff *get_new_skb(struct ucc_geth_private *ugeth,
208 u8 __iomem *bd)
Li Yangce973b12006-08-14 23:00:11 -0700209{
210 struct sk_buff *skb = NULL;
211
Anton Vorontsov50f238f2009-07-07 08:38:42 +0000212 skb = __skb_dequeue(&ugeth->rx_recycle);
213 if (!skb)
214 skb = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length +
215 UCC_GETH_RX_DATA_BUF_ALIGNMENT);
Li Yangce973b12006-08-14 23:00:11 -0700216 if (skb == NULL)
217 return NULL;
218
219 /* We need the data buffer to be aligned properly. We will reserve
220 * as many bytes as needed to align the data properly
221 */
222 skb_reserve(skb,
223 UCC_GETH_RX_DATA_BUF_ALIGNMENT -
224 (((unsigned)skb->data) & (UCC_GETH_RX_DATA_BUF_ALIGNMENT -
225 1)));
226
Anton Vorontsovda1aa632009-04-02 01:26:07 -0700227 skb->dev = ugeth->ndev;
Li Yangce973b12006-08-14 23:00:11 -0700228
Andy Fleming6fee40e2008-05-02 13:01:23 -0500229 out_be32(&((struct qe_bd __iomem *)bd)->buf,
Anton Vorontsovda1aa632009-04-02 01:26:07 -0700230 dma_map_single(ugeth->dev,
Li Yangce973b12006-08-14 23:00:11 -0700231 skb->data,
232 ugeth->ug_info->uf_info.max_rx_buf_length +
233 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
234 DMA_FROM_DEVICE));
235
Andy Fleming6fee40e2008-05-02 13:01:23 -0500236 out_be32((u32 __iomem *)bd,
237 (R_E | R_I | (in_be32((u32 __iomem*)bd) & R_W)));
Li Yangce973b12006-08-14 23:00:11 -0700238
239 return skb;
240}
241
Li Yang18a8e862006-10-19 21:07:34 -0500242static int rx_bd_buffer_set(struct ucc_geth_private *ugeth, u8 rxQ)
Li Yangce973b12006-08-14 23:00:11 -0700243{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500244 u8 __iomem *bd;
Li Yangce973b12006-08-14 23:00:11 -0700245 u32 bd_status;
246 struct sk_buff *skb;
247 int i;
248
249 bd = ugeth->p_rx_bd_ring[rxQ];
250 i = 0;
251
252 do {
Andy Fleming6fee40e2008-05-02 13:01:23 -0500253 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -0700254 skb = get_new_skb(ugeth, bd);
255
256 if (!skb) /* If can not allocate data buffer,
257 abort. Cleanup will be elsewhere */
258 return -ENOMEM;
259
260 ugeth->rx_skbuff[rxQ][i] = skb;
261
262 /* advance the BD pointer */
Li Yang18a8e862006-10-19 21:07:34 -0500263 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -0700264 i++;
265 } while (!(bd_status & R_W));
266
267 return 0;
268}
269
Li Yang18a8e862006-10-19 21:07:34 -0500270static int fill_init_enet_entries(struct ucc_geth_private *ugeth,
Andy Fleming6fee40e2008-05-02 13:01:23 -0500271 u32 *p_start,
Li Yangce973b12006-08-14 23:00:11 -0700272 u8 num_entries,
273 u32 thread_size,
274 u32 thread_alignment,
Haiying Wang345f8422009-04-29 14:14:35 -0400275 unsigned int risc,
Li Yangce973b12006-08-14 23:00:11 -0700276 int skip_page_for_first_entry)
277{
278 u32 init_enet_offset;
279 u8 i;
280 int snum;
281
282 for (i = 0; i < num_entries; i++) {
283 if ((snum = qe_get_snum()) < 0) {
Li Yang890de952007-07-19 11:48:29 +0800284 if (netif_msg_ifup(ugeth))
285 ugeth_err("fill_init_enet_entries: Can not get SNUM.");
Li Yangce973b12006-08-14 23:00:11 -0700286 return snum;
287 }
288 if ((i == 0) && skip_page_for_first_entry)
289 /* First entry of Rx does not have page */
290 init_enet_offset = 0;
291 else {
292 init_enet_offset =
293 qe_muram_alloc(thread_size, thread_alignment);
Timur Tabi4c356302007-05-08 14:46:36 -0500294 if (IS_ERR_VALUE(init_enet_offset)) {
Li Yang890de952007-07-19 11:48:29 +0800295 if (netif_msg_ifup(ugeth))
296 ugeth_err("fill_init_enet_entries: Can not allocate DPRAM memory.");
Li Yangce973b12006-08-14 23:00:11 -0700297 qe_put_snum((u8) snum);
298 return -ENOMEM;
299 }
300 }
301 *(p_start++) =
302 ((u8) snum << ENET_INIT_PARAM_SNUM_SHIFT) | init_enet_offset
303 | risc;
304 }
305
306 return 0;
307}
308
Li Yang18a8e862006-10-19 21:07:34 -0500309static int return_init_enet_entries(struct ucc_geth_private *ugeth,
Andy Fleming6fee40e2008-05-02 13:01:23 -0500310 u32 *p_start,
Li Yangce973b12006-08-14 23:00:11 -0700311 u8 num_entries,
Haiying Wang345f8422009-04-29 14:14:35 -0400312 unsigned int risc,
Li Yangce973b12006-08-14 23:00:11 -0700313 int skip_page_for_first_entry)
314{
315 u32 init_enet_offset;
316 u8 i;
317 int snum;
318
319 for (i = 0; i < num_entries; i++) {
Andy Fleming6fee40e2008-05-02 13:01:23 -0500320 u32 val = *p_start;
321
Li Yangce973b12006-08-14 23:00:11 -0700322 /* Check that this entry was actually valid --
323 needed in case failed in allocations */
Andy Fleming6fee40e2008-05-02 13:01:23 -0500324 if ((val & ENET_INIT_PARAM_RISC_MASK) == risc) {
Li Yangce973b12006-08-14 23:00:11 -0700325 snum =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500326 (u32) (val & ENET_INIT_PARAM_SNUM_MASK) >>
Li Yangce973b12006-08-14 23:00:11 -0700327 ENET_INIT_PARAM_SNUM_SHIFT;
328 qe_put_snum((u8) snum);
329 if (!((i == 0) && skip_page_for_first_entry)) {
330 /* First entry of Rx does not have page */
331 init_enet_offset =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500332 (val & ENET_INIT_PARAM_PTR_MASK);
Li Yangce973b12006-08-14 23:00:11 -0700333 qe_muram_free(init_enet_offset);
334 }
Andy Fleming6fee40e2008-05-02 13:01:23 -0500335 *p_start++ = 0;
Li Yangce973b12006-08-14 23:00:11 -0700336 }
337 }
338
339 return 0;
340}
341
342#ifdef DEBUG
Li Yang18a8e862006-10-19 21:07:34 -0500343static int dump_init_enet_entries(struct ucc_geth_private *ugeth,
Andy Fleming6fee40e2008-05-02 13:01:23 -0500344 u32 __iomem *p_start,
Li Yangce973b12006-08-14 23:00:11 -0700345 u8 num_entries,
346 u32 thread_size,
Haiying Wang345f8422009-04-29 14:14:35 -0400347 unsigned int risc,
Li Yangce973b12006-08-14 23:00:11 -0700348 int skip_page_for_first_entry)
349{
350 u32 init_enet_offset;
351 u8 i;
352 int snum;
353
354 for (i = 0; i < num_entries; i++) {
Andy Fleming6fee40e2008-05-02 13:01:23 -0500355 u32 val = in_be32(p_start);
356
Li Yangce973b12006-08-14 23:00:11 -0700357 /* Check that this entry was actually valid --
358 needed in case failed in allocations */
Andy Fleming6fee40e2008-05-02 13:01:23 -0500359 if ((val & ENET_INIT_PARAM_RISC_MASK) == risc) {
Li Yangce973b12006-08-14 23:00:11 -0700360 snum =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500361 (u32) (val & ENET_INIT_PARAM_SNUM_MASK) >>
Li Yangce973b12006-08-14 23:00:11 -0700362 ENET_INIT_PARAM_SNUM_SHIFT;
363 qe_put_snum((u8) snum);
364 if (!((i == 0) && skip_page_for_first_entry)) {
365 /* First entry of Rx does not have page */
366 init_enet_offset =
367 (in_be32(p_start) &
368 ENET_INIT_PARAM_PTR_MASK);
369 ugeth_info("Init enet entry %d:", i);
370 ugeth_info("Base address: 0x%08x",
371 (u32)
372 qe_muram_addr(init_enet_offset));
373 mem_disp(qe_muram_addr(init_enet_offset),
374 thread_size);
375 }
376 p_start++;
377 }
378 }
379
380 return 0;
381}
382#endif
383
Li Yang18a8e862006-10-19 21:07:34 -0500384static void put_enet_addr_container(struct enet_addr_container *enet_addr_cont)
Li Yangce973b12006-08-14 23:00:11 -0700385{
386 kfree(enet_addr_cont);
387}
388
Timur Tabidf19b6b2007-01-09 12:31:38 -0600389static void set_mac_addr(__be16 __iomem *reg, u8 *mac)
Li Yangce973b12006-08-14 23:00:11 -0700390{
Li Yang18a8e862006-10-19 21:07:34 -0500391 out_be16(&reg[0], ((u16)mac[5] << 8) | mac[4]);
392 out_be16(&reg[1], ((u16)mac[3] << 8) | mac[2]);
393 out_be16(&reg[2], ((u16)mac[1] << 8) | mac[0]);
394}
395
Li Yang18a8e862006-10-19 21:07:34 -0500396static int hw_clear_addr_in_paddr(struct ucc_geth_private *ugeth, u8 paddr_num)
Li Yangce973b12006-08-14 23:00:11 -0700397{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500398 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Li Yangce973b12006-08-14 23:00:11 -0700399
400 if (!(paddr_num < NUM_OF_PADDRS)) {
Harvey Harrisonb39d66a2008-08-20 16:52:04 -0700401 ugeth_warn("%s: Illagel paddr_num.", __func__);
Li Yangce973b12006-08-14 23:00:11 -0700402 return -EINVAL;
403 }
404
405 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500406 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->p_rx_glbl_pram->
Li Yangce973b12006-08-14 23:00:11 -0700407 addressfiltering;
408
409 /* Writing address ff.ff.ff.ff.ff.ff disables address
410 recognition for this register */
411 out_be16(&p_82xx_addr_filt->paddr[paddr_num].h, 0xffff);
412 out_be16(&p_82xx_addr_filt->paddr[paddr_num].m, 0xffff);
413 out_be16(&p_82xx_addr_filt->paddr[paddr_num].l, 0xffff);
414
415 return 0;
416}
417
Li Yang18a8e862006-10-19 21:07:34 -0500418static void hw_add_addr_in_hash(struct ucc_geth_private *ugeth,
419 u8 *p_enet_addr)
Li Yangce973b12006-08-14 23:00:11 -0700420{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500421 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Li Yangce973b12006-08-14 23:00:11 -0700422 u32 cecr_subblock;
423
424 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -0500425 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->p_rx_glbl_pram->
Li Yangce973b12006-08-14 23:00:11 -0700426 addressfiltering;
427
428 cecr_subblock =
429 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
430
431 /* Ethernet frames are defined in Little Endian mode,
432 therefor to insert */
433 /* the address to the hash (Big Endian mode), we reverse the bytes.*/
Li Yang18a8e862006-10-19 21:07:34 -0500434
435 set_mac_addr(&p_82xx_addr_filt->taddr.h, p_enet_addr);
Li Yangce973b12006-08-14 23:00:11 -0700436
437 qe_issue_cmd(QE_SET_GROUP_ADDRESS, cecr_subblock,
Li Yang18a8e862006-10-19 21:07:34 -0500438 QE_CR_PROTOCOL_ETHERNET, 0);
Li Yangce973b12006-08-14 23:00:11 -0700439}
440
441#ifdef CONFIG_UGETH_MAGIC_PACKET
Li Yang18a8e862006-10-19 21:07:34 -0500442static void magic_packet_detection_enable(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700443{
Li Yang18a8e862006-10-19 21:07:34 -0500444 struct ucc_fast_private *uccf;
Andy Fleming6fee40e2008-05-02 13:01:23 -0500445 struct ucc_geth __iomem *ug_regs;
Li Yangce973b12006-08-14 23:00:11 -0700446
447 uccf = ugeth->uccf;
448 ug_regs = ugeth->ug_regs;
449
450 /* Enable interrupts for magic packet detection */
Timur Tabi3bc53422009-01-11 00:25:21 -0800451 setbits32(uccf->p_uccm, UCC_GETH_UCCE_MPD);
Li Yangce973b12006-08-14 23:00:11 -0700452
453 /* Enable magic packet detection */
Timur Tabi3bc53422009-01-11 00:25:21 -0800454 setbits32(&ug_regs->maccfg2, MACCFG2_MPE);
Li Yangce973b12006-08-14 23:00:11 -0700455}
456
Li Yang18a8e862006-10-19 21:07:34 -0500457static void magic_packet_detection_disable(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700458{
Li Yang18a8e862006-10-19 21:07:34 -0500459 struct ucc_fast_private *uccf;
Andy Fleming6fee40e2008-05-02 13:01:23 -0500460 struct ucc_geth __iomem *ug_regs;
Li Yangce973b12006-08-14 23:00:11 -0700461
462 uccf = ugeth->uccf;
463 ug_regs = ugeth->ug_regs;
464
465 /* Disable interrupts for magic packet detection */
Timur Tabi3bc53422009-01-11 00:25:21 -0800466 clrbits32(uccf->p_uccm, UCC_GETH_UCCE_MPD);
Li Yangce973b12006-08-14 23:00:11 -0700467
468 /* Disable magic packet detection */
Timur Tabi3bc53422009-01-11 00:25:21 -0800469 clrbits32(&ug_regs->maccfg2, MACCFG2_MPE);
Li Yangce973b12006-08-14 23:00:11 -0700470}
471#endif /* MAGIC_PACKET */
472
Li Yang18a8e862006-10-19 21:07:34 -0500473static inline int compare_addr(u8 **addr1, u8 **addr2)
Li Yangce973b12006-08-14 23:00:11 -0700474{
475 return memcmp(addr1, addr2, ENET_NUM_OCTETS_PER_ADDRESS);
476}
477
478#ifdef DEBUG
Li Yang18a8e862006-10-19 21:07:34 -0500479static void get_statistics(struct ucc_geth_private *ugeth,
480 struct ucc_geth_tx_firmware_statistics *
Li Yangce973b12006-08-14 23:00:11 -0700481 tx_firmware_statistics,
Li Yang18a8e862006-10-19 21:07:34 -0500482 struct ucc_geth_rx_firmware_statistics *
Li Yangce973b12006-08-14 23:00:11 -0700483 rx_firmware_statistics,
Li Yang18a8e862006-10-19 21:07:34 -0500484 struct ucc_geth_hardware_statistics *hardware_statistics)
Li Yangce973b12006-08-14 23:00:11 -0700485{
Andy Fleming6fee40e2008-05-02 13:01:23 -0500486 struct ucc_fast __iomem *uf_regs;
487 struct ucc_geth __iomem *ug_regs;
Li Yang18a8e862006-10-19 21:07:34 -0500488 struct ucc_geth_tx_firmware_statistics_pram *p_tx_fw_statistics_pram;
489 struct ucc_geth_rx_firmware_statistics_pram *p_rx_fw_statistics_pram;
Li Yangce973b12006-08-14 23:00:11 -0700490
491 ug_regs = ugeth->ug_regs;
Andy Fleming6fee40e2008-05-02 13:01:23 -0500492 uf_regs = (struct ucc_fast __iomem *) ug_regs;
Li Yangce973b12006-08-14 23:00:11 -0700493 p_tx_fw_statistics_pram = ugeth->p_tx_fw_statistics_pram;
494 p_rx_fw_statistics_pram = ugeth->p_rx_fw_statistics_pram;
495
496 /* Tx firmware only if user handed pointer and driver actually
497 gathers Tx firmware statistics */
498 if (tx_firmware_statistics && p_tx_fw_statistics_pram) {
499 tx_firmware_statistics->sicoltx =
500 in_be32(&p_tx_fw_statistics_pram->sicoltx);
501 tx_firmware_statistics->mulcoltx =
502 in_be32(&p_tx_fw_statistics_pram->mulcoltx);
503 tx_firmware_statistics->latecoltxfr =
504 in_be32(&p_tx_fw_statistics_pram->latecoltxfr);
505 tx_firmware_statistics->frabortduecol =
506 in_be32(&p_tx_fw_statistics_pram->frabortduecol);
507 tx_firmware_statistics->frlostinmactxer =
508 in_be32(&p_tx_fw_statistics_pram->frlostinmactxer);
509 tx_firmware_statistics->carriersenseertx =
510 in_be32(&p_tx_fw_statistics_pram->carriersenseertx);
511 tx_firmware_statistics->frtxok =
512 in_be32(&p_tx_fw_statistics_pram->frtxok);
513 tx_firmware_statistics->txfrexcessivedefer =
514 in_be32(&p_tx_fw_statistics_pram->txfrexcessivedefer);
515 tx_firmware_statistics->txpkts256 =
516 in_be32(&p_tx_fw_statistics_pram->txpkts256);
517 tx_firmware_statistics->txpkts512 =
518 in_be32(&p_tx_fw_statistics_pram->txpkts512);
519 tx_firmware_statistics->txpkts1024 =
520 in_be32(&p_tx_fw_statistics_pram->txpkts1024);
521 tx_firmware_statistics->txpktsjumbo =
522 in_be32(&p_tx_fw_statistics_pram->txpktsjumbo);
523 }
524
525 /* Rx firmware only if user handed pointer and driver actually
526 * gathers Rx firmware statistics */
527 if (rx_firmware_statistics && p_rx_fw_statistics_pram) {
528 int i;
529 rx_firmware_statistics->frrxfcser =
530 in_be32(&p_rx_fw_statistics_pram->frrxfcser);
531 rx_firmware_statistics->fraligner =
532 in_be32(&p_rx_fw_statistics_pram->fraligner);
533 rx_firmware_statistics->inrangelenrxer =
534 in_be32(&p_rx_fw_statistics_pram->inrangelenrxer);
535 rx_firmware_statistics->outrangelenrxer =
536 in_be32(&p_rx_fw_statistics_pram->outrangelenrxer);
537 rx_firmware_statistics->frtoolong =
538 in_be32(&p_rx_fw_statistics_pram->frtoolong);
539 rx_firmware_statistics->runt =
540 in_be32(&p_rx_fw_statistics_pram->runt);
541 rx_firmware_statistics->verylongevent =
542 in_be32(&p_rx_fw_statistics_pram->verylongevent);
543 rx_firmware_statistics->symbolerror =
544 in_be32(&p_rx_fw_statistics_pram->symbolerror);
545 rx_firmware_statistics->dropbsy =
546 in_be32(&p_rx_fw_statistics_pram->dropbsy);
547 for (i = 0; i < 0x8; i++)
548 rx_firmware_statistics->res0[i] =
549 p_rx_fw_statistics_pram->res0[i];
550 rx_firmware_statistics->mismatchdrop =
551 in_be32(&p_rx_fw_statistics_pram->mismatchdrop);
552 rx_firmware_statistics->underpkts =
553 in_be32(&p_rx_fw_statistics_pram->underpkts);
554 rx_firmware_statistics->pkts256 =
555 in_be32(&p_rx_fw_statistics_pram->pkts256);
556 rx_firmware_statistics->pkts512 =
557 in_be32(&p_rx_fw_statistics_pram->pkts512);
558 rx_firmware_statistics->pkts1024 =
559 in_be32(&p_rx_fw_statistics_pram->pkts1024);
560 rx_firmware_statistics->pktsjumbo =
561 in_be32(&p_rx_fw_statistics_pram->pktsjumbo);
562 rx_firmware_statistics->frlossinmacer =
563 in_be32(&p_rx_fw_statistics_pram->frlossinmacer);
564 rx_firmware_statistics->pausefr =
565 in_be32(&p_rx_fw_statistics_pram->pausefr);
566 for (i = 0; i < 0x4; i++)
567 rx_firmware_statistics->res1[i] =
568 p_rx_fw_statistics_pram->res1[i];
569 rx_firmware_statistics->removevlan =
570 in_be32(&p_rx_fw_statistics_pram->removevlan);
571 rx_firmware_statistics->replacevlan =
572 in_be32(&p_rx_fw_statistics_pram->replacevlan);
573 rx_firmware_statistics->insertvlan =
574 in_be32(&p_rx_fw_statistics_pram->insertvlan);
575 }
576
577 /* Hardware only if user handed pointer and driver actually
578 gathers hardware statistics */
Timur Tabi3bc53422009-01-11 00:25:21 -0800579 if (hardware_statistics &&
580 (in_be32(&uf_regs->upsmr) & UCC_GETH_UPSMR_HSE)) {
Li Yangce973b12006-08-14 23:00:11 -0700581 hardware_statistics->tx64 = in_be32(&ug_regs->tx64);
582 hardware_statistics->tx127 = in_be32(&ug_regs->tx127);
583 hardware_statistics->tx255 = in_be32(&ug_regs->tx255);
584 hardware_statistics->rx64 = in_be32(&ug_regs->rx64);
585 hardware_statistics->rx127 = in_be32(&ug_regs->rx127);
586 hardware_statistics->rx255 = in_be32(&ug_regs->rx255);
587 hardware_statistics->txok = in_be32(&ug_regs->txok);
588 hardware_statistics->txcf = in_be16(&ug_regs->txcf);
589 hardware_statistics->tmca = in_be32(&ug_regs->tmca);
590 hardware_statistics->tbca = in_be32(&ug_regs->tbca);
591 hardware_statistics->rxfok = in_be32(&ug_regs->rxfok);
592 hardware_statistics->rxbok = in_be32(&ug_regs->rxbok);
593 hardware_statistics->rbyt = in_be32(&ug_regs->rbyt);
594 hardware_statistics->rmca = in_be32(&ug_regs->rmca);
595 hardware_statistics->rbca = in_be32(&ug_regs->rbca);
596 }
597}
598
Li Yang18a8e862006-10-19 21:07:34 -0500599static void dump_bds(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700600{
601 int i;
602 int length;
603
604 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
605 if (ugeth->p_tx_bd_ring[i]) {
606 length =
607 (ugeth->ug_info->bdRingLenTx[i] *
Li Yang18a8e862006-10-19 21:07:34 -0500608 sizeof(struct qe_bd));
Li Yangce973b12006-08-14 23:00:11 -0700609 ugeth_info("TX BDs[%d]", i);
610 mem_disp(ugeth->p_tx_bd_ring[i], length);
611 }
612 }
613 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
614 if (ugeth->p_rx_bd_ring[i]) {
615 length =
616 (ugeth->ug_info->bdRingLenRx[i] *
Li Yang18a8e862006-10-19 21:07:34 -0500617 sizeof(struct qe_bd));
Li Yangce973b12006-08-14 23:00:11 -0700618 ugeth_info("RX BDs[%d]", i);
619 mem_disp(ugeth->p_rx_bd_ring[i], length);
620 }
621 }
622}
623
Li Yang18a8e862006-10-19 21:07:34 -0500624static void dump_regs(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -0700625{
626 int i;
627
628 ugeth_info("UCC%d Geth registers:", ugeth->ug_info->uf_info.ucc_num);
629 ugeth_info("Base address: 0x%08x", (u32) ugeth->ug_regs);
630
631 ugeth_info("maccfg1 : addr - 0x%08x, val - 0x%08x",
632 (u32) & ugeth->ug_regs->maccfg1,
633 in_be32(&ugeth->ug_regs->maccfg1));
634 ugeth_info("maccfg2 : addr - 0x%08x, val - 0x%08x",
635 (u32) & ugeth->ug_regs->maccfg2,
636 in_be32(&ugeth->ug_regs->maccfg2));
637 ugeth_info("ipgifg : addr - 0x%08x, val - 0x%08x",
638 (u32) & ugeth->ug_regs->ipgifg,
639 in_be32(&ugeth->ug_regs->ipgifg));
640 ugeth_info("hafdup : addr - 0x%08x, val - 0x%08x",
641 (u32) & ugeth->ug_regs->hafdup,
642 in_be32(&ugeth->ug_regs->hafdup));
Li Yangce973b12006-08-14 23:00:11 -0700643 ugeth_info("ifctl : addr - 0x%08x, val - 0x%08x",
644 (u32) & ugeth->ug_regs->ifctl,
645 in_be32(&ugeth->ug_regs->ifctl));
646 ugeth_info("ifstat : addr - 0x%08x, val - 0x%08x",
647 (u32) & ugeth->ug_regs->ifstat,
648 in_be32(&ugeth->ug_regs->ifstat));
649 ugeth_info("macstnaddr1: addr - 0x%08x, val - 0x%08x",
650 (u32) & ugeth->ug_regs->macstnaddr1,
651 in_be32(&ugeth->ug_regs->macstnaddr1));
652 ugeth_info("macstnaddr2: addr - 0x%08x, val - 0x%08x",
653 (u32) & ugeth->ug_regs->macstnaddr2,
654 in_be32(&ugeth->ug_regs->macstnaddr2));
655 ugeth_info("uempr : addr - 0x%08x, val - 0x%08x",
656 (u32) & ugeth->ug_regs->uempr,
657 in_be32(&ugeth->ug_regs->uempr));
658 ugeth_info("utbipar : addr - 0x%08x, val - 0x%08x",
659 (u32) & ugeth->ug_regs->utbipar,
660 in_be32(&ugeth->ug_regs->utbipar));
661 ugeth_info("uescr : addr - 0x%08x, val - 0x%04x",
662 (u32) & ugeth->ug_regs->uescr,
663 in_be16(&ugeth->ug_regs->uescr));
664 ugeth_info("tx64 : addr - 0x%08x, val - 0x%08x",
665 (u32) & ugeth->ug_regs->tx64,
666 in_be32(&ugeth->ug_regs->tx64));
667 ugeth_info("tx127 : addr - 0x%08x, val - 0x%08x",
668 (u32) & ugeth->ug_regs->tx127,
669 in_be32(&ugeth->ug_regs->tx127));
670 ugeth_info("tx255 : addr - 0x%08x, val - 0x%08x",
671 (u32) & ugeth->ug_regs->tx255,
672 in_be32(&ugeth->ug_regs->tx255));
673 ugeth_info("rx64 : addr - 0x%08x, val - 0x%08x",
674 (u32) & ugeth->ug_regs->rx64,
675 in_be32(&ugeth->ug_regs->rx64));
676 ugeth_info("rx127 : addr - 0x%08x, val - 0x%08x",
677 (u32) & ugeth->ug_regs->rx127,
678 in_be32(&ugeth->ug_regs->rx127));
679 ugeth_info("rx255 : addr - 0x%08x, val - 0x%08x",
680 (u32) & ugeth->ug_regs->rx255,
681 in_be32(&ugeth->ug_regs->rx255));
682 ugeth_info("txok : addr - 0x%08x, val - 0x%08x",
683 (u32) & ugeth->ug_regs->txok,
684 in_be32(&ugeth->ug_regs->txok));
685 ugeth_info("txcf : addr - 0x%08x, val - 0x%04x",
686 (u32) & ugeth->ug_regs->txcf,
687 in_be16(&ugeth->ug_regs->txcf));
688 ugeth_info("tmca : addr - 0x%08x, val - 0x%08x",
689 (u32) & ugeth->ug_regs->tmca,
690 in_be32(&ugeth->ug_regs->tmca));
691 ugeth_info("tbca : addr - 0x%08x, val - 0x%08x",
692 (u32) & ugeth->ug_regs->tbca,
693 in_be32(&ugeth->ug_regs->tbca));
694 ugeth_info("rxfok : addr - 0x%08x, val - 0x%08x",
695 (u32) & ugeth->ug_regs->rxfok,
696 in_be32(&ugeth->ug_regs->rxfok));
697 ugeth_info("rxbok : addr - 0x%08x, val - 0x%08x",
698 (u32) & ugeth->ug_regs->rxbok,
699 in_be32(&ugeth->ug_regs->rxbok));
700 ugeth_info("rbyt : addr - 0x%08x, val - 0x%08x",
701 (u32) & ugeth->ug_regs->rbyt,
702 in_be32(&ugeth->ug_regs->rbyt));
703 ugeth_info("rmca : addr - 0x%08x, val - 0x%08x",
704 (u32) & ugeth->ug_regs->rmca,
705 in_be32(&ugeth->ug_regs->rmca));
706 ugeth_info("rbca : addr - 0x%08x, val - 0x%08x",
707 (u32) & ugeth->ug_regs->rbca,
708 in_be32(&ugeth->ug_regs->rbca));
709 ugeth_info("scar : addr - 0x%08x, val - 0x%08x",
710 (u32) & ugeth->ug_regs->scar,
711 in_be32(&ugeth->ug_regs->scar));
712 ugeth_info("scam : addr - 0x%08x, val - 0x%08x",
713 (u32) & ugeth->ug_regs->scam,
714 in_be32(&ugeth->ug_regs->scam));
715
716 if (ugeth->p_thread_data_tx) {
717 int numThreadsTxNumerical;
718 switch (ugeth->ug_info->numThreadsTx) {
719 case UCC_GETH_NUM_OF_THREADS_1:
720 numThreadsTxNumerical = 1;
721 break;
722 case UCC_GETH_NUM_OF_THREADS_2:
723 numThreadsTxNumerical = 2;
724 break;
725 case UCC_GETH_NUM_OF_THREADS_4:
726 numThreadsTxNumerical = 4;
727 break;
728 case UCC_GETH_NUM_OF_THREADS_6:
729 numThreadsTxNumerical = 6;
730 break;
731 case UCC_GETH_NUM_OF_THREADS_8:
732 numThreadsTxNumerical = 8;
733 break;
734 default:
735 numThreadsTxNumerical = 0;
736 break;
737 }
738
739 ugeth_info("Thread data TXs:");
740 ugeth_info("Base address: 0x%08x",
741 (u32) ugeth->p_thread_data_tx);
742 for (i = 0; i < numThreadsTxNumerical; i++) {
743 ugeth_info("Thread data TX[%d]:", i);
744 ugeth_info("Base address: 0x%08x",
745 (u32) & ugeth->p_thread_data_tx[i]);
746 mem_disp((u8 *) & ugeth->p_thread_data_tx[i],
Li Yang18a8e862006-10-19 21:07:34 -0500747 sizeof(struct ucc_geth_thread_data_tx));
Li Yangce973b12006-08-14 23:00:11 -0700748 }
749 }
750 if (ugeth->p_thread_data_rx) {
751 int numThreadsRxNumerical;
752 switch (ugeth->ug_info->numThreadsRx) {
753 case UCC_GETH_NUM_OF_THREADS_1:
754 numThreadsRxNumerical = 1;
755 break;
756 case UCC_GETH_NUM_OF_THREADS_2:
757 numThreadsRxNumerical = 2;
758 break;
759 case UCC_GETH_NUM_OF_THREADS_4:
760 numThreadsRxNumerical = 4;
761 break;
762 case UCC_GETH_NUM_OF_THREADS_6:
763 numThreadsRxNumerical = 6;
764 break;
765 case UCC_GETH_NUM_OF_THREADS_8:
766 numThreadsRxNumerical = 8;
767 break;
768 default:
769 numThreadsRxNumerical = 0;
770 break;
771 }
772
773 ugeth_info("Thread data RX:");
774 ugeth_info("Base address: 0x%08x",
775 (u32) ugeth->p_thread_data_rx);
776 for (i = 0; i < numThreadsRxNumerical; i++) {
777 ugeth_info("Thread data RX[%d]:", i);
778 ugeth_info("Base address: 0x%08x",
779 (u32) & ugeth->p_thread_data_rx[i]);
780 mem_disp((u8 *) & ugeth->p_thread_data_rx[i],
Li Yang18a8e862006-10-19 21:07:34 -0500781 sizeof(struct ucc_geth_thread_data_rx));
Li Yangce973b12006-08-14 23:00:11 -0700782 }
783 }
784 if (ugeth->p_exf_glbl_param) {
785 ugeth_info("EXF global param:");
786 ugeth_info("Base address: 0x%08x",
787 (u32) ugeth->p_exf_glbl_param);
788 mem_disp((u8 *) ugeth->p_exf_glbl_param,
789 sizeof(*ugeth->p_exf_glbl_param));
790 }
791 if (ugeth->p_tx_glbl_pram) {
792 ugeth_info("TX global param:");
793 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_tx_glbl_pram);
794 ugeth_info("temoder : addr - 0x%08x, val - 0x%04x",
795 (u32) & ugeth->p_tx_glbl_pram->temoder,
796 in_be16(&ugeth->p_tx_glbl_pram->temoder));
797 ugeth_info("sqptr : addr - 0x%08x, val - 0x%08x",
798 (u32) & ugeth->p_tx_glbl_pram->sqptr,
799 in_be32(&ugeth->p_tx_glbl_pram->sqptr));
800 ugeth_info("schedulerbasepointer: addr - 0x%08x, val - 0x%08x",
801 (u32) & ugeth->p_tx_glbl_pram->schedulerbasepointer,
802 in_be32(&ugeth->p_tx_glbl_pram->
803 schedulerbasepointer));
804 ugeth_info("txrmonbaseptr: addr - 0x%08x, val - 0x%08x",
805 (u32) & ugeth->p_tx_glbl_pram->txrmonbaseptr,
806 in_be32(&ugeth->p_tx_glbl_pram->txrmonbaseptr));
807 ugeth_info("tstate : addr - 0x%08x, val - 0x%08x",
808 (u32) & ugeth->p_tx_glbl_pram->tstate,
809 in_be32(&ugeth->p_tx_glbl_pram->tstate));
810 ugeth_info("iphoffset[0] : addr - 0x%08x, val - 0x%02x",
811 (u32) & ugeth->p_tx_glbl_pram->iphoffset[0],
812 ugeth->p_tx_glbl_pram->iphoffset[0]);
813 ugeth_info("iphoffset[1] : addr - 0x%08x, val - 0x%02x",
814 (u32) & ugeth->p_tx_glbl_pram->iphoffset[1],
815 ugeth->p_tx_glbl_pram->iphoffset[1]);
816 ugeth_info("iphoffset[2] : addr - 0x%08x, val - 0x%02x",
817 (u32) & ugeth->p_tx_glbl_pram->iphoffset[2],
818 ugeth->p_tx_glbl_pram->iphoffset[2]);
819 ugeth_info("iphoffset[3] : addr - 0x%08x, val - 0x%02x",
820 (u32) & ugeth->p_tx_glbl_pram->iphoffset[3],
821 ugeth->p_tx_glbl_pram->iphoffset[3]);
822 ugeth_info("iphoffset[4] : addr - 0x%08x, val - 0x%02x",
823 (u32) & ugeth->p_tx_glbl_pram->iphoffset[4],
824 ugeth->p_tx_glbl_pram->iphoffset[4]);
825 ugeth_info("iphoffset[5] : addr - 0x%08x, val - 0x%02x",
826 (u32) & ugeth->p_tx_glbl_pram->iphoffset[5],
827 ugeth->p_tx_glbl_pram->iphoffset[5]);
828 ugeth_info("iphoffset[6] : addr - 0x%08x, val - 0x%02x",
829 (u32) & ugeth->p_tx_glbl_pram->iphoffset[6],
830 ugeth->p_tx_glbl_pram->iphoffset[6]);
831 ugeth_info("iphoffset[7] : addr - 0x%08x, val - 0x%02x",
832 (u32) & ugeth->p_tx_glbl_pram->iphoffset[7],
833 ugeth->p_tx_glbl_pram->iphoffset[7]);
834 ugeth_info("vtagtable[0] : addr - 0x%08x, val - 0x%08x",
835 (u32) & ugeth->p_tx_glbl_pram->vtagtable[0],
836 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[0]));
837 ugeth_info("vtagtable[1] : addr - 0x%08x, val - 0x%08x",
838 (u32) & ugeth->p_tx_glbl_pram->vtagtable[1],
839 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[1]));
840 ugeth_info("vtagtable[2] : addr - 0x%08x, val - 0x%08x",
841 (u32) & ugeth->p_tx_glbl_pram->vtagtable[2],
842 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[2]));
843 ugeth_info("vtagtable[3] : addr - 0x%08x, val - 0x%08x",
844 (u32) & ugeth->p_tx_glbl_pram->vtagtable[3],
845 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[3]));
846 ugeth_info("vtagtable[4] : addr - 0x%08x, val - 0x%08x",
847 (u32) & ugeth->p_tx_glbl_pram->vtagtable[4],
848 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[4]));
849 ugeth_info("vtagtable[5] : addr - 0x%08x, val - 0x%08x",
850 (u32) & ugeth->p_tx_glbl_pram->vtagtable[5],
851 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[5]));
852 ugeth_info("vtagtable[6] : addr - 0x%08x, val - 0x%08x",
853 (u32) & ugeth->p_tx_glbl_pram->vtagtable[6],
854 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[6]));
855 ugeth_info("vtagtable[7] : addr - 0x%08x, val - 0x%08x",
856 (u32) & ugeth->p_tx_glbl_pram->vtagtable[7],
857 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[7]));
858 ugeth_info("tqptr : addr - 0x%08x, val - 0x%08x",
859 (u32) & ugeth->p_tx_glbl_pram->tqptr,
860 in_be32(&ugeth->p_tx_glbl_pram->tqptr));
861 }
862 if (ugeth->p_rx_glbl_pram) {
863 ugeth_info("RX global param:");
864 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_glbl_pram);
865 ugeth_info("remoder : addr - 0x%08x, val - 0x%08x",
866 (u32) & ugeth->p_rx_glbl_pram->remoder,
867 in_be32(&ugeth->p_rx_glbl_pram->remoder));
868 ugeth_info("rqptr : addr - 0x%08x, val - 0x%08x",
869 (u32) & ugeth->p_rx_glbl_pram->rqptr,
870 in_be32(&ugeth->p_rx_glbl_pram->rqptr));
871 ugeth_info("typeorlen : addr - 0x%08x, val - 0x%04x",
872 (u32) & ugeth->p_rx_glbl_pram->typeorlen,
873 in_be16(&ugeth->p_rx_glbl_pram->typeorlen));
874 ugeth_info("rxgstpack : addr - 0x%08x, val - 0x%02x",
875 (u32) & ugeth->p_rx_glbl_pram->rxgstpack,
876 ugeth->p_rx_glbl_pram->rxgstpack);
877 ugeth_info("rxrmonbaseptr : addr - 0x%08x, val - 0x%08x",
878 (u32) & ugeth->p_rx_glbl_pram->rxrmonbaseptr,
879 in_be32(&ugeth->p_rx_glbl_pram->rxrmonbaseptr));
880 ugeth_info("intcoalescingptr: addr - 0x%08x, val - 0x%08x",
881 (u32) & ugeth->p_rx_glbl_pram->intcoalescingptr,
882 in_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr));
883 ugeth_info("rstate : addr - 0x%08x, val - 0x%02x",
884 (u32) & ugeth->p_rx_glbl_pram->rstate,
885 ugeth->p_rx_glbl_pram->rstate);
886 ugeth_info("mrblr : addr - 0x%08x, val - 0x%04x",
887 (u32) & ugeth->p_rx_glbl_pram->mrblr,
888 in_be16(&ugeth->p_rx_glbl_pram->mrblr));
889 ugeth_info("rbdqptr : addr - 0x%08x, val - 0x%08x",
890 (u32) & ugeth->p_rx_glbl_pram->rbdqptr,
891 in_be32(&ugeth->p_rx_glbl_pram->rbdqptr));
892 ugeth_info("mflr : addr - 0x%08x, val - 0x%04x",
893 (u32) & ugeth->p_rx_glbl_pram->mflr,
894 in_be16(&ugeth->p_rx_glbl_pram->mflr));
895 ugeth_info("minflr : addr - 0x%08x, val - 0x%04x",
896 (u32) & ugeth->p_rx_glbl_pram->minflr,
897 in_be16(&ugeth->p_rx_glbl_pram->minflr));
898 ugeth_info("maxd1 : addr - 0x%08x, val - 0x%04x",
899 (u32) & ugeth->p_rx_glbl_pram->maxd1,
900 in_be16(&ugeth->p_rx_glbl_pram->maxd1));
901 ugeth_info("maxd2 : addr - 0x%08x, val - 0x%04x",
902 (u32) & ugeth->p_rx_glbl_pram->maxd2,
903 in_be16(&ugeth->p_rx_glbl_pram->maxd2));
904 ugeth_info("ecamptr : addr - 0x%08x, val - 0x%08x",
905 (u32) & ugeth->p_rx_glbl_pram->ecamptr,
906 in_be32(&ugeth->p_rx_glbl_pram->ecamptr));
907 ugeth_info("l2qt : addr - 0x%08x, val - 0x%08x",
908 (u32) & ugeth->p_rx_glbl_pram->l2qt,
909 in_be32(&ugeth->p_rx_glbl_pram->l2qt));
910 ugeth_info("l3qt[0] : addr - 0x%08x, val - 0x%08x",
911 (u32) & ugeth->p_rx_glbl_pram->l3qt[0],
912 in_be32(&ugeth->p_rx_glbl_pram->l3qt[0]));
913 ugeth_info("l3qt[1] : addr - 0x%08x, val - 0x%08x",
914 (u32) & ugeth->p_rx_glbl_pram->l3qt[1],
915 in_be32(&ugeth->p_rx_glbl_pram->l3qt[1]));
916 ugeth_info("l3qt[2] : addr - 0x%08x, val - 0x%08x",
917 (u32) & ugeth->p_rx_glbl_pram->l3qt[2],
918 in_be32(&ugeth->p_rx_glbl_pram->l3qt[2]));
919 ugeth_info("l3qt[3] : addr - 0x%08x, val - 0x%08x",
920 (u32) & ugeth->p_rx_glbl_pram->l3qt[3],
921 in_be32(&ugeth->p_rx_glbl_pram->l3qt[3]));
922 ugeth_info("l3qt[4] : addr - 0x%08x, val - 0x%08x",
923 (u32) & ugeth->p_rx_glbl_pram->l3qt[4],
924 in_be32(&ugeth->p_rx_glbl_pram->l3qt[4]));
925 ugeth_info("l3qt[5] : addr - 0x%08x, val - 0x%08x",
926 (u32) & ugeth->p_rx_glbl_pram->l3qt[5],
927 in_be32(&ugeth->p_rx_glbl_pram->l3qt[5]));
928 ugeth_info("l3qt[6] : addr - 0x%08x, val - 0x%08x",
929 (u32) & ugeth->p_rx_glbl_pram->l3qt[6],
930 in_be32(&ugeth->p_rx_glbl_pram->l3qt[6]));
931 ugeth_info("l3qt[7] : addr - 0x%08x, val - 0x%08x",
932 (u32) & ugeth->p_rx_glbl_pram->l3qt[7],
933 in_be32(&ugeth->p_rx_glbl_pram->l3qt[7]));
934 ugeth_info("vlantype : addr - 0x%08x, val - 0x%04x",
935 (u32) & ugeth->p_rx_glbl_pram->vlantype,
936 in_be16(&ugeth->p_rx_glbl_pram->vlantype));
937 ugeth_info("vlantci : addr - 0x%08x, val - 0x%04x",
938 (u32) & ugeth->p_rx_glbl_pram->vlantci,
939 in_be16(&ugeth->p_rx_glbl_pram->vlantci));
940 for (i = 0; i < 64; i++)
941 ugeth_info
942 ("addressfiltering[%d]: addr - 0x%08x, val - 0x%02x",
943 i,
944 (u32) & ugeth->p_rx_glbl_pram->addressfiltering[i],
945 ugeth->p_rx_glbl_pram->addressfiltering[i]);
946 ugeth_info("exfGlobalParam : addr - 0x%08x, val - 0x%08x",
947 (u32) & ugeth->p_rx_glbl_pram->exfGlobalParam,
948 in_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam));
949 }
950 if (ugeth->p_send_q_mem_reg) {
951 ugeth_info("Send Q memory registers:");
952 ugeth_info("Base address: 0x%08x",
953 (u32) ugeth->p_send_q_mem_reg);
954 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
955 ugeth_info("SQQD[%d]:", i);
956 ugeth_info("Base address: 0x%08x",
957 (u32) & ugeth->p_send_q_mem_reg->sqqd[i]);
958 mem_disp((u8 *) & ugeth->p_send_q_mem_reg->sqqd[i],
Li Yang18a8e862006-10-19 21:07:34 -0500959 sizeof(struct ucc_geth_send_queue_qd));
Li Yangce973b12006-08-14 23:00:11 -0700960 }
961 }
962 if (ugeth->p_scheduler) {
963 ugeth_info("Scheduler:");
964 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_scheduler);
965 mem_disp((u8 *) ugeth->p_scheduler,
966 sizeof(*ugeth->p_scheduler));
967 }
968 if (ugeth->p_tx_fw_statistics_pram) {
969 ugeth_info("TX FW statistics pram:");
970 ugeth_info("Base address: 0x%08x",
971 (u32) ugeth->p_tx_fw_statistics_pram);
972 mem_disp((u8 *) ugeth->p_tx_fw_statistics_pram,
973 sizeof(*ugeth->p_tx_fw_statistics_pram));
974 }
975 if (ugeth->p_rx_fw_statistics_pram) {
976 ugeth_info("RX FW statistics pram:");
977 ugeth_info("Base address: 0x%08x",
978 (u32) ugeth->p_rx_fw_statistics_pram);
979 mem_disp((u8 *) ugeth->p_rx_fw_statistics_pram,
980 sizeof(*ugeth->p_rx_fw_statistics_pram));
981 }
982 if (ugeth->p_rx_irq_coalescing_tbl) {
983 ugeth_info("RX IRQ coalescing tables:");
984 ugeth_info("Base address: 0x%08x",
985 (u32) ugeth->p_rx_irq_coalescing_tbl);
986 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
987 ugeth_info("RX IRQ coalescing table entry[%d]:", i);
988 ugeth_info("Base address: 0x%08x",
989 (u32) & ugeth->p_rx_irq_coalescing_tbl->
990 coalescingentry[i]);
991 ugeth_info
992 ("interruptcoalescingmaxvalue: addr - 0x%08x, val - 0x%08x",
993 (u32) & ugeth->p_rx_irq_coalescing_tbl->
994 coalescingentry[i].interruptcoalescingmaxvalue,
995 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
996 coalescingentry[i].
997 interruptcoalescingmaxvalue));
998 ugeth_info
999 ("interruptcoalescingcounter : addr - 0x%08x, val - 0x%08x",
1000 (u32) & ugeth->p_rx_irq_coalescing_tbl->
1001 coalescingentry[i].interruptcoalescingcounter,
1002 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
1003 coalescingentry[i].
1004 interruptcoalescingcounter));
1005 }
1006 }
1007 if (ugeth->p_rx_bd_qs_tbl) {
1008 ugeth_info("RX BD QS tables:");
1009 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_bd_qs_tbl);
1010 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
1011 ugeth_info("RX BD QS table[%d]:", i);
1012 ugeth_info("Base address: 0x%08x",
1013 (u32) & ugeth->p_rx_bd_qs_tbl[i]);
1014 ugeth_info
1015 ("bdbaseptr : addr - 0x%08x, val - 0x%08x",
1016 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdbaseptr,
1017 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdbaseptr));
1018 ugeth_info
1019 ("bdptr : addr - 0x%08x, val - 0x%08x",
1020 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdptr,
1021 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdptr));
1022 ugeth_info
1023 ("externalbdbaseptr: addr - 0x%08x, val - 0x%08x",
1024 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
1025 in_be32(&ugeth->p_rx_bd_qs_tbl[i].
1026 externalbdbaseptr));
1027 ugeth_info
1028 ("externalbdptr : addr - 0x%08x, val - 0x%08x",
1029 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdptr,
1030 in_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdptr));
1031 ugeth_info("ucode RX Prefetched BDs:");
1032 ugeth_info("Base address: 0x%08x",
1033 (u32)
1034 qe_muram_addr(in_be32
1035 (&ugeth->p_rx_bd_qs_tbl[i].
1036 bdbaseptr)));
1037 mem_disp((u8 *)
1038 qe_muram_addr(in_be32
1039 (&ugeth->p_rx_bd_qs_tbl[i].
1040 bdbaseptr)),
Li Yang18a8e862006-10-19 21:07:34 -05001041 sizeof(struct ucc_geth_rx_prefetched_bds));
Li Yangce973b12006-08-14 23:00:11 -07001042 }
1043 }
1044 if (ugeth->p_init_enet_param_shadow) {
1045 int size;
1046 ugeth_info("Init enet param shadow:");
1047 ugeth_info("Base address: 0x%08x",
1048 (u32) ugeth->p_init_enet_param_shadow);
1049 mem_disp((u8 *) ugeth->p_init_enet_param_shadow,
1050 sizeof(*ugeth->p_init_enet_param_shadow));
1051
Li Yang18a8e862006-10-19 21:07:34 -05001052 size = sizeof(struct ucc_geth_thread_rx_pram);
Li Yangce973b12006-08-14 23:00:11 -07001053 if (ugeth->ug_info->rxExtendedFiltering) {
1054 size +=
1055 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
1056 if (ugeth->ug_info->largestexternallookupkeysize ==
1057 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
1058 size +=
1059 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
1060 if (ugeth->ug_info->largestexternallookupkeysize ==
1061 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
1062 size +=
1063 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
1064 }
1065
1066 dump_init_enet_entries(ugeth,
1067 &(ugeth->p_init_enet_param_shadow->
1068 txthread[0]),
1069 ENET_INIT_PARAM_MAX_ENTRIES_TX,
Li Yang18a8e862006-10-19 21:07:34 -05001070 sizeof(struct ucc_geth_thread_tx_pram),
Li Yangce973b12006-08-14 23:00:11 -07001071 ugeth->ug_info->riscTx, 0);
1072 dump_init_enet_entries(ugeth,
1073 &(ugeth->p_init_enet_param_shadow->
1074 rxthread[0]),
1075 ENET_INIT_PARAM_MAX_ENTRIES_RX, size,
1076 ugeth->ug_info->riscRx, 1);
1077 }
1078}
1079#endif /* DEBUG */
1080
Andy Fleming6fee40e2008-05-02 13:01:23 -05001081static void init_default_reg_vals(u32 __iomem *upsmr_register,
1082 u32 __iomem *maccfg1_register,
1083 u32 __iomem *maccfg2_register)
Li Yangce973b12006-08-14 23:00:11 -07001084{
1085 out_be32(upsmr_register, UCC_GETH_UPSMR_INIT);
1086 out_be32(maccfg1_register, UCC_GETH_MACCFG1_INIT);
1087 out_be32(maccfg2_register, UCC_GETH_MACCFG2_INIT);
1088}
1089
1090static int init_half_duplex_params(int alt_beb,
1091 int back_pressure_no_backoff,
1092 int no_backoff,
1093 int excess_defer,
1094 u8 alt_beb_truncation,
1095 u8 max_retransmissions,
1096 u8 collision_window,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001097 u32 __iomem *hafdup_register)
Li Yangce973b12006-08-14 23:00:11 -07001098{
1099 u32 value = 0;
1100
1101 if ((alt_beb_truncation > HALFDUP_ALT_BEB_TRUNCATION_MAX) ||
1102 (max_retransmissions > HALFDUP_MAX_RETRANSMISSION_MAX) ||
1103 (collision_window > HALFDUP_COLLISION_WINDOW_MAX))
1104 return -EINVAL;
1105
1106 value = (u32) (alt_beb_truncation << HALFDUP_ALT_BEB_TRUNCATION_SHIFT);
1107
1108 if (alt_beb)
1109 value |= HALFDUP_ALT_BEB;
1110 if (back_pressure_no_backoff)
1111 value |= HALFDUP_BACK_PRESSURE_NO_BACKOFF;
1112 if (no_backoff)
1113 value |= HALFDUP_NO_BACKOFF;
1114 if (excess_defer)
1115 value |= HALFDUP_EXCESSIVE_DEFER;
1116
1117 value |= (max_retransmissions << HALFDUP_MAX_RETRANSMISSION_SHIFT);
1118
1119 value |= collision_window;
1120
1121 out_be32(hafdup_register, value);
1122 return 0;
1123}
1124
1125static int init_inter_frame_gap_params(u8 non_btb_cs_ipg,
1126 u8 non_btb_ipg,
1127 u8 min_ifg,
1128 u8 btb_ipg,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001129 u32 __iomem *ipgifg_register)
Li Yangce973b12006-08-14 23:00:11 -07001130{
1131 u32 value = 0;
1132
1133 /* Non-Back-to-back IPG part 1 should be <= Non-Back-to-back
1134 IPG part 2 */
1135 if (non_btb_cs_ipg > non_btb_ipg)
1136 return -EINVAL;
1137
1138 if ((non_btb_cs_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART1_MAX) ||
1139 (non_btb_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART2_MAX) ||
1140 /*(min_ifg > IPGIFG_MINIMUM_IFG_ENFORCEMENT_MAX) || */
1141 (btb_ipg > IPGIFG_BACK_TO_BACK_IFG_MAX))
1142 return -EINVAL;
1143
1144 value |=
1145 ((non_btb_cs_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART1_SHIFT) &
1146 IPGIFG_NBTB_CS_IPG_MASK);
1147 value |=
1148 ((non_btb_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART2_SHIFT) &
1149 IPGIFG_NBTB_IPG_MASK);
1150 value |=
1151 ((min_ifg << IPGIFG_MINIMUM_IFG_ENFORCEMENT_SHIFT) &
1152 IPGIFG_MIN_IFG_MASK);
1153 value |= (btb_ipg & IPGIFG_BTB_IPG_MASK);
1154
1155 out_be32(ipgifg_register, value);
1156 return 0;
1157}
1158
Li Yangac421852007-07-19 11:47:47 +08001159int init_flow_control_params(u32 automatic_flow_control_mode,
Li Yangce973b12006-08-14 23:00:11 -07001160 int rx_flow_control_enable,
1161 int tx_flow_control_enable,
1162 u16 pause_period,
1163 u16 extension_field,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001164 u32 __iomem *upsmr_register,
1165 u32 __iomem *uempr_register,
1166 u32 __iomem *maccfg1_register)
Li Yangce973b12006-08-14 23:00:11 -07001167{
1168 u32 value = 0;
1169
1170 /* Set UEMPR register */
1171 value = (u32) pause_period << UEMPR_PAUSE_TIME_VALUE_SHIFT;
1172 value |= (u32) extension_field << UEMPR_EXTENDED_PAUSE_TIME_VALUE_SHIFT;
1173 out_be32(uempr_register, value);
1174
1175 /* Set UPSMR register */
Timur Tabi3bc53422009-01-11 00:25:21 -08001176 setbits32(upsmr_register, automatic_flow_control_mode);
Li Yangce973b12006-08-14 23:00:11 -07001177
1178 value = in_be32(maccfg1_register);
1179 if (rx_flow_control_enable)
1180 value |= MACCFG1_FLOW_RX;
1181 if (tx_flow_control_enable)
1182 value |= MACCFG1_FLOW_TX;
1183 out_be32(maccfg1_register, value);
1184
1185 return 0;
1186}
1187
1188static int init_hw_statistics_gathering_mode(int enable_hardware_statistics,
1189 int auto_zero_hardware_statistics,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001190 u32 __iomem *upsmr_register,
1191 u16 __iomem *uescr_register)
Li Yangce973b12006-08-14 23:00:11 -07001192{
Li Yangce973b12006-08-14 23:00:11 -07001193 u16 uescr_value = 0;
Timur Tabi3bc53422009-01-11 00:25:21 -08001194
Li Yangce973b12006-08-14 23:00:11 -07001195 /* Enable hardware statistics gathering if requested */
Timur Tabi3bc53422009-01-11 00:25:21 -08001196 if (enable_hardware_statistics)
1197 setbits32(upsmr_register, UCC_GETH_UPSMR_HSE);
Li Yangce973b12006-08-14 23:00:11 -07001198
1199 /* Clear hardware statistics counters */
1200 uescr_value = in_be16(uescr_register);
1201 uescr_value |= UESCR_CLRCNT;
1202 /* Automatically zero hardware statistics counters on read,
1203 if requested */
1204 if (auto_zero_hardware_statistics)
1205 uescr_value |= UESCR_AUTOZ;
1206 out_be16(uescr_register, uescr_value);
1207
1208 return 0;
1209}
1210
1211static int init_firmware_statistics_gathering_mode(int
1212 enable_tx_firmware_statistics,
1213 int enable_rx_firmware_statistics,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001214 u32 __iomem *tx_rmon_base_ptr,
Li Yangce973b12006-08-14 23:00:11 -07001215 u32 tx_firmware_statistics_structure_address,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001216 u32 __iomem *rx_rmon_base_ptr,
Li Yangce973b12006-08-14 23:00:11 -07001217 u32 rx_firmware_statistics_structure_address,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001218 u16 __iomem *temoder_register,
1219 u32 __iomem *remoder_register)
Li Yangce973b12006-08-14 23:00:11 -07001220{
1221 /* Note: this function does not check if */
1222 /* the parameters it receives are NULL */
Li Yangce973b12006-08-14 23:00:11 -07001223
1224 if (enable_tx_firmware_statistics) {
1225 out_be32(tx_rmon_base_ptr,
1226 tx_firmware_statistics_structure_address);
Timur Tabi3bc53422009-01-11 00:25:21 -08001227 setbits16(temoder_register, TEMODER_TX_RMON_STATISTICS_ENABLE);
Li Yangce973b12006-08-14 23:00:11 -07001228 }
1229
1230 if (enable_rx_firmware_statistics) {
1231 out_be32(rx_rmon_base_ptr,
1232 rx_firmware_statistics_structure_address);
Timur Tabi3bc53422009-01-11 00:25:21 -08001233 setbits32(remoder_register, REMODER_RX_RMON_STATISTICS_ENABLE);
Li Yangce973b12006-08-14 23:00:11 -07001234 }
1235
1236 return 0;
1237}
1238
1239static int init_mac_station_addr_regs(u8 address_byte_0,
1240 u8 address_byte_1,
1241 u8 address_byte_2,
1242 u8 address_byte_3,
1243 u8 address_byte_4,
1244 u8 address_byte_5,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001245 u32 __iomem *macstnaddr1_register,
1246 u32 __iomem *macstnaddr2_register)
Li Yangce973b12006-08-14 23:00:11 -07001247{
1248 u32 value = 0;
1249
1250 /* Example: for a station address of 0x12345678ABCD, */
1251 /* 0x12 is byte 0, 0x34 is byte 1 and so on and 0xCD is byte 5 */
1252
1253 /* MACSTNADDR1 Register: */
1254
1255 /* 0 7 8 15 */
1256 /* station address byte 5 station address byte 4 */
1257 /* 16 23 24 31 */
1258 /* station address byte 3 station address byte 2 */
1259 value |= (u32) ((address_byte_2 << 0) & 0x000000FF);
1260 value |= (u32) ((address_byte_3 << 8) & 0x0000FF00);
1261 value |= (u32) ((address_byte_4 << 16) & 0x00FF0000);
1262 value |= (u32) ((address_byte_5 << 24) & 0xFF000000);
1263
1264 out_be32(macstnaddr1_register, value);
1265
1266 /* MACSTNADDR2 Register: */
1267
1268 /* 0 7 8 15 */
1269 /* station address byte 1 station address byte 0 */
1270 /* 16 23 24 31 */
1271 /* reserved reserved */
1272 value = 0;
1273 value |= (u32) ((address_byte_0 << 16) & 0x00FF0000);
1274 value |= (u32) ((address_byte_1 << 24) & 0xFF000000);
1275
1276 out_be32(macstnaddr2_register, value);
1277
1278 return 0;
1279}
1280
Li Yangce973b12006-08-14 23:00:11 -07001281static int init_check_frame_length_mode(int length_check,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001282 u32 __iomem *maccfg2_register)
Li Yangce973b12006-08-14 23:00:11 -07001283{
1284 u32 value = 0;
1285
1286 value = in_be32(maccfg2_register);
1287
1288 if (length_check)
1289 value |= MACCFG2_LC;
1290 else
1291 value &= ~MACCFG2_LC;
1292
1293 out_be32(maccfg2_register, value);
1294 return 0;
1295}
1296
1297static int init_preamble_length(u8 preamble_length,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001298 u32 __iomem *maccfg2_register)
Li Yangce973b12006-08-14 23:00:11 -07001299{
Li Yangce973b12006-08-14 23:00:11 -07001300 if ((preamble_length < 3) || (preamble_length > 7))
1301 return -EINVAL;
1302
Timur Tabi3bc53422009-01-11 00:25:21 -08001303 clrsetbits_be32(maccfg2_register, MACCFG2_PREL_MASK,
1304 preamble_length << MACCFG2_PREL_SHIFT);
1305
Li Yangce973b12006-08-14 23:00:11 -07001306 return 0;
1307}
1308
Li Yangce973b12006-08-14 23:00:11 -07001309static int init_rx_parameters(int reject_broadcast,
1310 int receive_short_frames,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001311 int promiscuous, u32 __iomem *upsmr_register)
Li Yangce973b12006-08-14 23:00:11 -07001312{
1313 u32 value = 0;
1314
1315 value = in_be32(upsmr_register);
1316
1317 if (reject_broadcast)
Timur Tabi3bc53422009-01-11 00:25:21 -08001318 value |= UCC_GETH_UPSMR_BRO;
Li Yangce973b12006-08-14 23:00:11 -07001319 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001320 value &= ~UCC_GETH_UPSMR_BRO;
Li Yangce973b12006-08-14 23:00:11 -07001321
1322 if (receive_short_frames)
Timur Tabi3bc53422009-01-11 00:25:21 -08001323 value |= UCC_GETH_UPSMR_RSH;
Li Yangce973b12006-08-14 23:00:11 -07001324 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001325 value &= ~UCC_GETH_UPSMR_RSH;
Li Yangce973b12006-08-14 23:00:11 -07001326
1327 if (promiscuous)
Timur Tabi3bc53422009-01-11 00:25:21 -08001328 value |= UCC_GETH_UPSMR_PRO;
Li Yangce973b12006-08-14 23:00:11 -07001329 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001330 value &= ~UCC_GETH_UPSMR_PRO;
Li Yangce973b12006-08-14 23:00:11 -07001331
1332 out_be32(upsmr_register, value);
1333
1334 return 0;
1335}
1336
1337static int init_max_rx_buff_len(u16 max_rx_buf_len,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001338 u16 __iomem *mrblr_register)
Li Yangce973b12006-08-14 23:00:11 -07001339{
1340 /* max_rx_buf_len value must be a multiple of 128 */
1341 if ((max_rx_buf_len == 0)
1342 || (max_rx_buf_len % UCC_GETH_MRBLR_ALIGNMENT))
1343 return -EINVAL;
1344
1345 out_be16(mrblr_register, max_rx_buf_len);
1346 return 0;
1347}
1348
1349static int init_min_frame_len(u16 min_frame_length,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001350 u16 __iomem *minflr_register,
1351 u16 __iomem *mrblr_register)
Li Yangce973b12006-08-14 23:00:11 -07001352{
1353 u16 mrblr_value = 0;
1354
1355 mrblr_value = in_be16(mrblr_register);
1356 if (min_frame_length >= (mrblr_value - 4))
1357 return -EINVAL;
1358
1359 out_be16(minflr_register, min_frame_length);
1360 return 0;
1361}
1362
Li Yang18a8e862006-10-19 21:07:34 -05001363static int adjust_enet_interface(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001364{
Li Yang18a8e862006-10-19 21:07:34 -05001365 struct ucc_geth_info *ug_info;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001366 struct ucc_geth __iomem *ug_regs;
1367 struct ucc_fast __iomem *uf_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001368 int ret_val;
1369 u32 upsmr, maccfg2, tbiBaseAddress;
Li Yangce973b12006-08-14 23:00:11 -07001370 u16 value;
1371
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001372 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07001373
1374 ug_info = ugeth->ug_info;
1375 ug_regs = ugeth->ug_regs;
1376 uf_regs = ugeth->uccf->uf_regs;
1377
Li Yangce973b12006-08-14 23:00:11 -07001378 /* Set MACCFG2 */
1379 maccfg2 = in_be32(&ug_regs->maccfg2);
1380 maccfg2 &= ~MACCFG2_INTERFACE_MODE_MASK;
Kim Phillips728de4c92007-04-13 01:26:03 -05001381 if ((ugeth->max_speed == SPEED_10) ||
1382 (ugeth->max_speed == SPEED_100))
Li Yangce973b12006-08-14 23:00:11 -07001383 maccfg2 |= MACCFG2_INTERFACE_MODE_NIBBLE;
Kim Phillips728de4c92007-04-13 01:26:03 -05001384 else if (ugeth->max_speed == SPEED_1000)
Li Yangce973b12006-08-14 23:00:11 -07001385 maccfg2 |= MACCFG2_INTERFACE_MODE_BYTE;
1386 maccfg2 |= ug_info->padAndCrc;
1387 out_be32(&ug_regs->maccfg2, maccfg2);
1388
1389 /* Set UPSMR */
1390 upsmr = in_be32(&uf_regs->upsmr);
Timur Tabi3bc53422009-01-11 00:25:21 -08001391 upsmr &= ~(UCC_GETH_UPSMR_RPM | UCC_GETH_UPSMR_R10M |
1392 UCC_GETH_UPSMR_TBIM | UCC_GETH_UPSMR_RMM);
Kim Phillips728de4c92007-04-13 01:26:03 -05001393 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
1394 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
1395 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06001396 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
1397 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
Kim Phillips728de4c92007-04-13 01:26:03 -05001398 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
Heiko Schochercef309c2009-04-20 22:36:43 +00001399 if (ugeth->phy_interface != PHY_INTERFACE_MODE_RMII)
1400 upsmr |= UCC_GETH_UPSMR_RPM;
Kim Phillips728de4c92007-04-13 01:26:03 -05001401 switch (ugeth->max_speed) {
1402 case SPEED_10:
Timur Tabi3bc53422009-01-11 00:25:21 -08001403 upsmr |= UCC_GETH_UPSMR_R10M;
Kim Phillips728de4c92007-04-13 01:26:03 -05001404 /* FALLTHROUGH */
1405 case SPEED_100:
1406 if (ugeth->phy_interface != PHY_INTERFACE_MODE_RTBI)
Timur Tabi3bc53422009-01-11 00:25:21 -08001407 upsmr |= UCC_GETH_UPSMR_RMM;
Kim Phillips728de4c92007-04-13 01:26:03 -05001408 }
1409 }
1410 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_TBI) ||
1411 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
Timur Tabi3bc53422009-01-11 00:25:21 -08001412 upsmr |= UCC_GETH_UPSMR_TBIM;
Kim Phillips728de4c92007-04-13 01:26:03 -05001413 }
Haiying Wang047584c2009-06-02 04:04:15 +00001414 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_SGMII))
1415 upsmr |= UCC_GETH_UPSMR_SGMM;
1416
Li Yangce973b12006-08-14 23:00:11 -07001417 out_be32(&uf_regs->upsmr, upsmr);
1418
Li Yangce973b12006-08-14 23:00:11 -07001419 /* Disable autonegotiation in tbi mode, because by default it
1420 comes up in autonegotiation mode. */
1421 /* Note that this depends on proper setting in utbipar register. */
Kim Phillips728de4c92007-04-13 01:26:03 -05001422 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_TBI) ||
1423 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
Li Yangce973b12006-08-14 23:00:11 -07001424 tbiBaseAddress = in_be32(&ug_regs->utbipar);
1425 tbiBaseAddress &= UTBIPAR_PHY_ADDRESS_MASK;
1426 tbiBaseAddress >>= UTBIPAR_PHY_ADDRESS_SHIFT;
Kim Phillips728de4c92007-04-13 01:26:03 -05001427 value = ugeth->phydev->bus->read(ugeth->phydev->bus,
1428 (u8) tbiBaseAddress, ENET_TBI_MII_CR);
Li Yangce973b12006-08-14 23:00:11 -07001429 value &= ~0x1000; /* Turn off autonegotiation */
Kim Phillips728de4c92007-04-13 01:26:03 -05001430 ugeth->phydev->bus->write(ugeth->phydev->bus,
1431 (u8) tbiBaseAddress, ENET_TBI_MII_CR, value);
Li Yangce973b12006-08-14 23:00:11 -07001432 }
1433
1434 init_check_frame_length_mode(ug_info->lengthCheckRx, &ug_regs->maccfg2);
1435
1436 ret_val = init_preamble_length(ug_info->prel, &ug_regs->maccfg2);
1437 if (ret_val != 0) {
Li Yang890de952007-07-19 11:48:29 +08001438 if (netif_msg_probe(ugeth))
1439 ugeth_err("%s: Preamble length must be between 3 and 7 inclusive.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001440 __func__);
Li Yangce973b12006-08-14 23:00:11 -07001441 return ret_val;
1442 }
1443
1444 return 0;
1445}
1446
1447/* Called every time the controller might need to be made
1448 * aware of new link state. The PHY code conveys this
1449 * information through variables in the ugeth structure, and this
1450 * function converts those variables into the appropriate
1451 * register values, and can bring down the device if needed.
1452 */
Kim Phillips728de4c92007-04-13 01:26:03 -05001453
Li Yangce973b12006-08-14 23:00:11 -07001454static void adjust_link(struct net_device *dev)
1455{
Li Yang18a8e862006-10-19 21:07:34 -05001456 struct ucc_geth_private *ugeth = netdev_priv(dev);
Andy Fleming6fee40e2008-05-02 13:01:23 -05001457 struct ucc_geth __iomem *ug_regs;
1458 struct ucc_fast __iomem *uf_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001459 struct phy_device *phydev = ugeth->phydev;
1460 unsigned long flags;
1461 int new_state = 0;
Li Yangce973b12006-08-14 23:00:11 -07001462
1463 ug_regs = ugeth->ug_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05001464 uf_regs = ugeth->uccf->uf_regs;
Li Yangce973b12006-08-14 23:00:11 -07001465
Kim Phillips728de4c92007-04-13 01:26:03 -05001466 spin_lock_irqsave(&ugeth->lock, flags);
1467
1468 if (phydev->link) {
1469 u32 tempval = in_be32(&ug_regs->maccfg2);
1470 u32 upsmr = in_be32(&uf_regs->upsmr);
Li Yangce973b12006-08-14 23:00:11 -07001471 /* Now we make sure that we can be in full duplex mode.
1472 * If not, we operate in half-duplex mode. */
Kim Phillips728de4c92007-04-13 01:26:03 -05001473 if (phydev->duplex != ugeth->oldduplex) {
1474 new_state = 1;
1475 if (!(phydev->duplex))
Li Yangce973b12006-08-14 23:00:11 -07001476 tempval &= ~(MACCFG2_FDX);
Kim Phillips728de4c92007-04-13 01:26:03 -05001477 else
Li Yangce973b12006-08-14 23:00:11 -07001478 tempval |= MACCFG2_FDX;
Kim Phillips728de4c92007-04-13 01:26:03 -05001479 ugeth->oldduplex = phydev->duplex;
Li Yangce973b12006-08-14 23:00:11 -07001480 }
1481
Kim Phillips728de4c92007-04-13 01:26:03 -05001482 if (phydev->speed != ugeth->oldspeed) {
1483 new_state = 1;
1484 switch (phydev->speed) {
1485 case SPEED_1000:
1486 tempval = ((tempval &
1487 ~(MACCFG2_INTERFACE_MODE_MASK)) |
1488 MACCFG2_INTERFACE_MODE_BYTE);
Li Yangce973b12006-08-14 23:00:11 -07001489 break;
Kim Phillips728de4c92007-04-13 01:26:03 -05001490 case SPEED_100:
1491 case SPEED_10:
1492 tempval = ((tempval &
1493 ~(MACCFG2_INTERFACE_MODE_MASK)) |
1494 MACCFG2_INTERFACE_MODE_NIBBLE);
1495 /* if reduced mode, re-set UPSMR.R10M */
1496 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
1497 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
1498 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06001499 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
1500 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
Kim Phillips728de4c92007-04-13 01:26:03 -05001501 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
1502 if (phydev->speed == SPEED_10)
Timur Tabi3bc53422009-01-11 00:25:21 -08001503 upsmr |= UCC_GETH_UPSMR_R10M;
Kim Phillips728de4c92007-04-13 01:26:03 -05001504 else
Timur Tabi3bc53422009-01-11 00:25:21 -08001505 upsmr &= ~UCC_GETH_UPSMR_R10M;
Kim Phillips728de4c92007-04-13 01:26:03 -05001506 }
Li Yangce973b12006-08-14 23:00:11 -07001507 break;
1508 default:
Kim Phillips728de4c92007-04-13 01:26:03 -05001509 if (netif_msg_link(ugeth))
1510 ugeth_warn(
1511 "%s: Ack! Speed (%d) is not 10/100/1000!",
1512 dev->name, phydev->speed);
Li Yangce973b12006-08-14 23:00:11 -07001513 break;
1514 }
Kim Phillips728de4c92007-04-13 01:26:03 -05001515 ugeth->oldspeed = phydev->speed;
Li Yangce973b12006-08-14 23:00:11 -07001516 }
1517
Kim Phillips728de4c92007-04-13 01:26:03 -05001518 out_be32(&ug_regs->maccfg2, tempval);
1519 out_be32(&uf_regs->upsmr, upsmr);
1520
Li Yangce973b12006-08-14 23:00:11 -07001521 if (!ugeth->oldlink) {
Kim Phillips728de4c92007-04-13 01:26:03 -05001522 new_state = 1;
Li Yangce973b12006-08-14 23:00:11 -07001523 ugeth->oldlink = 1;
Li Yangce973b12006-08-14 23:00:11 -07001524 }
Kim Phillips728de4c92007-04-13 01:26:03 -05001525 } else if (ugeth->oldlink) {
1526 new_state = 1;
Li Yangce973b12006-08-14 23:00:11 -07001527 ugeth->oldlink = 0;
1528 ugeth->oldspeed = 0;
1529 ugeth->oldduplex = -1;
Li Yangce973b12006-08-14 23:00:11 -07001530 }
Kim Phillips728de4c92007-04-13 01:26:03 -05001531
1532 if (new_state && netif_msg_link(ugeth))
1533 phy_print_status(phydev);
1534
1535 spin_unlock_irqrestore(&ugeth->lock, flags);
Li Yangce973b12006-08-14 23:00:11 -07001536}
1537
Haiying Wangfb1001f2009-06-17 13:16:10 +00001538/* Initialize TBI PHY interface for communicating with the
1539 * SERDES lynx PHY on the chip. We communicate with this PHY
1540 * through the MDIO bus on each controller, treating it as a
1541 * "normal" PHY at the address found in the UTBIPA register. We assume
1542 * that the UTBIPA register is valid. Either the MDIO bus code will set
1543 * it to a value that doesn't conflict with other PHYs on the bus, or the
1544 * value doesn't matter, as there are no other PHYs on the bus.
1545 */
1546static void uec_configure_serdes(struct net_device *dev)
1547{
1548 struct ucc_geth_private *ugeth = netdev_priv(dev);
1549 struct ucc_geth_info *ug_info = ugeth->ug_info;
1550 struct phy_device *tbiphy;
1551
1552 if (!ug_info->tbi_node) {
1553 dev_warn(&dev->dev, "SGMII mode requires that the device "
1554 "tree specify a tbi-handle\n");
1555 return;
1556 }
1557
1558 tbiphy = of_phy_find_device(ug_info->tbi_node);
1559 if (!tbiphy) {
1560 dev_err(&dev->dev, "error: Could not get TBI device\n");
1561 return;
1562 }
1563
1564 /*
1565 * If the link is already up, we must already be ok, and don't need to
1566 * configure and reset the TBI<->SerDes link. Maybe U-Boot configured
1567 * everything for us? Resetting it takes the link down and requires
1568 * several seconds for it to come back.
1569 */
1570 if (phy_read(tbiphy, ENET_TBI_MII_SR) & TBISR_LSTATUS)
1571 return;
1572
1573 /* Single clk mode, mii mode off(for serdes communication) */
1574 phy_write(tbiphy, ENET_TBI_MII_ANA, TBIANA_SETTINGS);
1575
1576 phy_write(tbiphy, ENET_TBI_MII_TBICON, TBICON_CLK_SELECT);
1577
1578 phy_write(tbiphy, ENET_TBI_MII_CR, TBICR_SETTINGS);
1579}
1580
Li Yangce973b12006-08-14 23:00:11 -07001581/* Configure the PHY for dev.
1582 * returns 0 if success. -1 if failure
1583 */
1584static int init_phy(struct net_device *dev)
1585{
Kim Phillips728de4c92007-04-13 01:26:03 -05001586 struct ucc_geth_private *priv = netdev_priv(dev);
Anton Vorontsov61fa9dc2009-03-22 21:30:52 -07001587 struct ucc_geth_info *ug_info = priv->ug_info;
Kim Phillips728de4c92007-04-13 01:26:03 -05001588 struct phy_device *phydev;
Li Yangce973b12006-08-14 23:00:11 -07001589
Kim Phillips728de4c92007-04-13 01:26:03 -05001590 priv->oldlink = 0;
1591 priv->oldspeed = 0;
1592 priv->oldduplex = -1;
Li Yangce973b12006-08-14 23:00:11 -07001593
Grant Likely0b9da332009-04-25 12:53:23 +00001594 if (!ug_info->phy_node)
1595 return 0;
Li Yangce973b12006-08-14 23:00:11 -07001596
Grant Likely0b9da332009-04-25 12:53:23 +00001597 phydev = of_phy_connect(dev, ug_info->phy_node, &adjust_link, 0,
1598 priv->phy_interface);
1599 if (!phydev) {
Kim Phillips728de4c92007-04-13 01:26:03 -05001600 printk("%s: Could not attach to PHY\n", dev->name);
Grant Likely0b9da332009-04-25 12:53:23 +00001601 return -ENODEV;
Li Yangce973b12006-08-14 23:00:11 -07001602 }
1603
Haiying Wang047584c2009-06-02 04:04:15 +00001604 if (priv->phy_interface == PHY_INTERFACE_MODE_SGMII)
1605 uec_configure_serdes(dev);
1606
Kim Phillips728de4c92007-04-13 01:26:03 -05001607 phydev->supported &= (ADVERTISED_10baseT_Half |
Li Yangce973b12006-08-14 23:00:11 -07001608 ADVERTISED_10baseT_Full |
1609 ADVERTISED_100baseT_Half |
Kim Phillips728de4c92007-04-13 01:26:03 -05001610 ADVERTISED_100baseT_Full);
Li Yangce973b12006-08-14 23:00:11 -07001611
Kim Phillips728de4c92007-04-13 01:26:03 -05001612 if (priv->max_speed == SPEED_1000)
1613 phydev->supported |= ADVERTISED_1000baseT_Full;
Li Yangce973b12006-08-14 23:00:11 -07001614
Kim Phillips728de4c92007-04-13 01:26:03 -05001615 phydev->advertising = phydev->supported;
Li Yangce973b12006-08-14 23:00:11 -07001616
Kim Phillips728de4c92007-04-13 01:26:03 -05001617 priv->phydev = phydev;
Li Yangce973b12006-08-14 23:00:11 -07001618
1619 return 0;
Li Yangce973b12006-08-14 23:00:11 -07001620}
1621
Kim Phillips728de4c92007-04-13 01:26:03 -05001622
Li Yangce973b12006-08-14 23:00:11 -07001623
Li Yang18a8e862006-10-19 21:07:34 -05001624static int ugeth_graceful_stop_tx(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001625{
Li Yang18a8e862006-10-19 21:07:34 -05001626 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001627 u32 cecr_subblock;
1628 u32 temp;
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001629 int i = 10;
Li Yangce973b12006-08-14 23:00:11 -07001630
1631 uccf = ugeth->uccf;
1632
1633 /* Mask GRACEFUL STOP TX interrupt bit and clear it */
Timur Tabi3bc53422009-01-11 00:25:21 -08001634 clrbits32(uccf->p_uccm, UCC_GETH_UCCE_GRA);
1635 out_be32(uccf->p_ucce, UCC_GETH_UCCE_GRA); /* clear by writing 1 */
Li Yangce973b12006-08-14 23:00:11 -07001636
1637 /* Issue host command */
1638 cecr_subblock =
1639 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1640 qe_issue_cmd(QE_GRACEFUL_STOP_TX, cecr_subblock,
Li Yang18a8e862006-10-19 21:07:34 -05001641 QE_CR_PROTOCOL_ETHERNET, 0);
Li Yangce973b12006-08-14 23:00:11 -07001642
1643 /* Wait for command to complete */
1644 do {
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001645 msleep(10);
Li Yangce973b12006-08-14 23:00:11 -07001646 temp = in_be32(uccf->p_ucce);
Timur Tabi3bc53422009-01-11 00:25:21 -08001647 } while (!(temp & UCC_GETH_UCCE_GRA) && --i);
Li Yangce973b12006-08-14 23:00:11 -07001648
1649 uccf->stopped_tx = 1;
1650
1651 return 0;
1652}
1653
Li Yang18a8e862006-10-19 21:07:34 -05001654static int ugeth_graceful_stop_rx(struct ucc_geth_private * ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001655{
Li Yang18a8e862006-10-19 21:07:34 -05001656 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001657 u32 cecr_subblock;
1658 u8 temp;
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001659 int i = 10;
Li Yangce973b12006-08-14 23:00:11 -07001660
1661 uccf = ugeth->uccf;
1662
1663 /* Clear acknowledge bit */
Andy Fleming6fee40e2008-05-02 13:01:23 -05001664 temp = in_8(&ugeth->p_rx_glbl_pram->rxgstpack);
Li Yangce973b12006-08-14 23:00:11 -07001665 temp &= ~GRACEFUL_STOP_ACKNOWLEDGE_RX;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001666 out_8(&ugeth->p_rx_glbl_pram->rxgstpack, temp);
Li Yangce973b12006-08-14 23:00:11 -07001667
1668 /* Keep issuing command and checking acknowledge bit until
1669 it is asserted, according to spec */
1670 do {
1671 /* Issue host command */
1672 cecr_subblock =
1673 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.
1674 ucc_num);
1675 qe_issue_cmd(QE_GRACEFUL_STOP_RX, cecr_subblock,
Li Yang18a8e862006-10-19 21:07:34 -05001676 QE_CR_PROTOCOL_ETHERNET, 0);
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001677 msleep(10);
Andy Fleming6fee40e2008-05-02 13:01:23 -05001678 temp = in_8(&ugeth->p_rx_glbl_pram->rxgstpack);
Anton Vorontsovb3431c62008-12-18 08:23:22 +00001679 } while (!(temp & GRACEFUL_STOP_ACKNOWLEDGE_RX) && --i);
Li Yangce973b12006-08-14 23:00:11 -07001680
1681 uccf->stopped_rx = 1;
1682
1683 return 0;
1684}
1685
Li Yang18a8e862006-10-19 21:07:34 -05001686static int ugeth_restart_tx(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001687{
Li Yang18a8e862006-10-19 21:07:34 -05001688 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001689 u32 cecr_subblock;
1690
1691 uccf = ugeth->uccf;
1692
1693 cecr_subblock =
1694 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
Li Yang18a8e862006-10-19 21:07:34 -05001695 qe_issue_cmd(QE_RESTART_TX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET, 0);
Li Yangce973b12006-08-14 23:00:11 -07001696 uccf->stopped_tx = 0;
1697
1698 return 0;
1699}
1700
Li Yang18a8e862006-10-19 21:07:34 -05001701static int ugeth_restart_rx(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001702{
Li Yang18a8e862006-10-19 21:07:34 -05001703 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001704 u32 cecr_subblock;
1705
1706 uccf = ugeth->uccf;
1707
1708 cecr_subblock =
1709 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
Li Yang18a8e862006-10-19 21:07:34 -05001710 qe_issue_cmd(QE_RESTART_RX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
Li Yangce973b12006-08-14 23:00:11 -07001711 0);
1712 uccf->stopped_rx = 0;
1713
1714 return 0;
1715}
1716
Li Yang18a8e862006-10-19 21:07:34 -05001717static int ugeth_enable(struct ucc_geth_private *ugeth, enum comm_dir mode)
Li Yangce973b12006-08-14 23:00:11 -07001718{
Li Yang18a8e862006-10-19 21:07:34 -05001719 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001720 int enabled_tx, enabled_rx;
1721
1722 uccf = ugeth->uccf;
1723
1724 /* check if the UCC number is in range. */
1725 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
Li Yang890de952007-07-19 11:48:29 +08001726 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001727 ugeth_err("%s: ucc_num out of range.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07001728 return -EINVAL;
1729 }
1730
1731 enabled_tx = uccf->enabled_tx;
1732 enabled_rx = uccf->enabled_rx;
1733
1734 /* Get Tx and Rx going again, in case this channel was actively
1735 disabled. */
1736 if ((mode & COMM_DIR_TX) && (!enabled_tx) && uccf->stopped_tx)
1737 ugeth_restart_tx(ugeth);
1738 if ((mode & COMM_DIR_RX) && (!enabled_rx) && uccf->stopped_rx)
1739 ugeth_restart_rx(ugeth);
1740
1741 ucc_fast_enable(uccf, mode); /* OK to do even if not disabled */
1742
1743 return 0;
1744
1745}
1746
Li Yang18a8e862006-10-19 21:07:34 -05001747static int ugeth_disable(struct ucc_geth_private * ugeth, enum comm_dir mode)
Li Yangce973b12006-08-14 23:00:11 -07001748{
Li Yang18a8e862006-10-19 21:07:34 -05001749 struct ucc_fast_private *uccf;
Li Yangce973b12006-08-14 23:00:11 -07001750
1751 uccf = ugeth->uccf;
1752
1753 /* check if the UCC number is in range. */
1754 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
Li Yang890de952007-07-19 11:48:29 +08001755 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07001756 ugeth_err("%s: ucc_num out of range.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07001757 return -EINVAL;
1758 }
1759
1760 /* Stop any transmissions */
1761 if ((mode & COMM_DIR_TX) && uccf->enabled_tx && !uccf->stopped_tx)
1762 ugeth_graceful_stop_tx(ugeth);
1763
1764 /* Stop any receptions */
1765 if ((mode & COMM_DIR_RX) && uccf->enabled_rx && !uccf->stopped_rx)
1766 ugeth_graceful_stop_rx(ugeth);
1767
1768 ucc_fast_disable(ugeth->uccf, mode); /* OK to do even if not enabled */
1769
1770 return 0;
1771}
1772
Li Yang18a8e862006-10-19 21:07:34 -05001773static void ugeth_dump_regs(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001774{
1775#ifdef DEBUG
1776 ucc_fast_dump_regs(ugeth->uccf);
1777 dump_regs(ugeth);
1778 dump_bds(ugeth);
1779#endif
1780}
1781
Li Yang18a8e862006-10-19 21:07:34 -05001782static int ugeth_82xx_filtering_clear_all_addr_in_hash(struct ucc_geth_private *
Li Yangce973b12006-08-14 23:00:11 -07001783 ugeth,
Li Yang18a8e862006-10-19 21:07:34 -05001784 enum enet_addr_type
Li Yangce973b12006-08-14 23:00:11 -07001785 enet_addr_type)
1786{
Andy Fleming6fee40e2008-05-02 13:01:23 -05001787 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Li Yang18a8e862006-10-19 21:07:34 -05001788 struct ucc_fast_private *uccf;
1789 enum comm_dir comm_dir;
Li Yangce973b12006-08-14 23:00:11 -07001790 struct list_head *p_lh;
1791 u16 i, num;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001792 u32 __iomem *addr_h;
1793 u32 __iomem *addr_l;
Li Yangce973b12006-08-14 23:00:11 -07001794 u8 *p_counter;
1795
1796 uccf = ugeth->uccf;
1797
1798 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -05001799 (struct ucc_geth_82xx_address_filtering_pram __iomem *)
1800 ugeth->p_rx_glbl_pram->addressfiltering;
Li Yangce973b12006-08-14 23:00:11 -07001801
1802 if (enet_addr_type == ENET_ADDR_TYPE_GROUP) {
1803 addr_h = &(p_82xx_addr_filt->gaddr_h);
1804 addr_l = &(p_82xx_addr_filt->gaddr_l);
1805 p_lh = &ugeth->group_hash_q;
1806 p_counter = &(ugeth->numGroupAddrInHash);
1807 } else if (enet_addr_type == ENET_ADDR_TYPE_INDIVIDUAL) {
1808 addr_h = &(p_82xx_addr_filt->iaddr_h);
1809 addr_l = &(p_82xx_addr_filt->iaddr_l);
1810 p_lh = &ugeth->ind_hash_q;
1811 p_counter = &(ugeth->numIndAddrInHash);
1812 } else
1813 return -EINVAL;
1814
1815 comm_dir = 0;
1816 if (uccf->enabled_tx)
1817 comm_dir |= COMM_DIR_TX;
1818 if (uccf->enabled_rx)
1819 comm_dir |= COMM_DIR_RX;
1820 if (comm_dir)
1821 ugeth_disable(ugeth, comm_dir);
1822
1823 /* Clear the hash table. */
1824 out_be32(addr_h, 0x00000000);
1825 out_be32(addr_l, 0x00000000);
1826
1827 if (!p_lh)
1828 return 0;
1829
1830 num = *p_counter;
1831
1832 /* Delete all remaining CQ elements */
1833 for (i = 0; i < num; i++)
1834 put_enet_addr_container(ENET_ADDR_CONT_ENTRY(dequeue(p_lh)));
1835
1836 *p_counter = 0;
1837
1838 if (comm_dir)
1839 ugeth_enable(ugeth, comm_dir);
1840
1841 return 0;
1842}
1843
Li Yang18a8e862006-10-19 21:07:34 -05001844static int ugeth_82xx_filtering_clear_addr_in_paddr(struct ucc_geth_private *ugeth,
Li Yangce973b12006-08-14 23:00:11 -07001845 u8 paddr_num)
1846{
1847 ugeth->indAddrRegUsed[paddr_num] = 0; /* mark this paddr as not used */
1848 return hw_clear_addr_in_paddr(ugeth, paddr_num);/* clear in hardware */
1849}
1850
Li Yang18a8e862006-10-19 21:07:34 -05001851static void ucc_geth_memclean(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07001852{
1853 u16 i, j;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001854 u8 __iomem *bd;
Li Yangce973b12006-08-14 23:00:11 -07001855
1856 if (!ugeth)
1857 return;
1858
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03001859 if (ugeth->uccf) {
Li Yangce973b12006-08-14 23:00:11 -07001860 ucc_fast_free(ugeth->uccf);
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03001861 ugeth->uccf = NULL;
1862 }
Li Yangce973b12006-08-14 23:00:11 -07001863
1864 if (ugeth->p_thread_data_tx) {
1865 qe_muram_free(ugeth->thread_dat_tx_offset);
1866 ugeth->p_thread_data_tx = NULL;
1867 }
1868 if (ugeth->p_thread_data_rx) {
1869 qe_muram_free(ugeth->thread_dat_rx_offset);
1870 ugeth->p_thread_data_rx = NULL;
1871 }
1872 if (ugeth->p_exf_glbl_param) {
1873 qe_muram_free(ugeth->exf_glbl_param_offset);
1874 ugeth->p_exf_glbl_param = NULL;
1875 }
1876 if (ugeth->p_rx_glbl_pram) {
1877 qe_muram_free(ugeth->rx_glbl_pram_offset);
1878 ugeth->p_rx_glbl_pram = NULL;
1879 }
1880 if (ugeth->p_tx_glbl_pram) {
1881 qe_muram_free(ugeth->tx_glbl_pram_offset);
1882 ugeth->p_tx_glbl_pram = NULL;
1883 }
1884 if (ugeth->p_send_q_mem_reg) {
1885 qe_muram_free(ugeth->send_q_mem_reg_offset);
1886 ugeth->p_send_q_mem_reg = NULL;
1887 }
1888 if (ugeth->p_scheduler) {
1889 qe_muram_free(ugeth->scheduler_offset);
1890 ugeth->p_scheduler = NULL;
1891 }
1892 if (ugeth->p_tx_fw_statistics_pram) {
1893 qe_muram_free(ugeth->tx_fw_statistics_pram_offset);
1894 ugeth->p_tx_fw_statistics_pram = NULL;
1895 }
1896 if (ugeth->p_rx_fw_statistics_pram) {
1897 qe_muram_free(ugeth->rx_fw_statistics_pram_offset);
1898 ugeth->p_rx_fw_statistics_pram = NULL;
1899 }
1900 if (ugeth->p_rx_irq_coalescing_tbl) {
1901 qe_muram_free(ugeth->rx_irq_coalescing_tbl_offset);
1902 ugeth->p_rx_irq_coalescing_tbl = NULL;
1903 }
1904 if (ugeth->p_rx_bd_qs_tbl) {
1905 qe_muram_free(ugeth->rx_bd_qs_tbl_offset);
1906 ugeth->p_rx_bd_qs_tbl = NULL;
1907 }
1908 if (ugeth->p_init_enet_param_shadow) {
1909 return_init_enet_entries(ugeth,
1910 &(ugeth->p_init_enet_param_shadow->
1911 rxthread[0]),
1912 ENET_INIT_PARAM_MAX_ENTRIES_RX,
1913 ugeth->ug_info->riscRx, 1);
1914 return_init_enet_entries(ugeth,
1915 &(ugeth->p_init_enet_param_shadow->
1916 txthread[0]),
1917 ENET_INIT_PARAM_MAX_ENTRIES_TX,
1918 ugeth->ug_info->riscTx, 0);
1919 kfree(ugeth->p_init_enet_param_shadow);
1920 ugeth->p_init_enet_param_shadow = NULL;
1921 }
1922 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
1923 bd = ugeth->p_tx_bd_ring[i];
Nicu Ioan Petru3a8205e2007-04-13 01:26:29 -05001924 if (!bd)
1925 continue;
Li Yangce973b12006-08-14 23:00:11 -07001926 for (j = 0; j < ugeth->ug_info->bdRingLenTx[i]; j++) {
1927 if (ugeth->tx_skbuff[i][j]) {
Anton Vorontsovda1aa632009-04-02 01:26:07 -07001928 dma_unmap_single(ugeth->dev,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001929 in_be32(&((struct qe_bd __iomem *)bd)->buf),
1930 (in_be32((u32 __iomem *)bd) &
Li Yangce973b12006-08-14 23:00:11 -07001931 BD_LENGTH_MASK),
1932 DMA_TO_DEVICE);
1933 dev_kfree_skb_any(ugeth->tx_skbuff[i][j]);
1934 ugeth->tx_skbuff[i][j] = NULL;
1935 }
1936 }
1937
1938 kfree(ugeth->tx_skbuff[i]);
1939
1940 if (ugeth->p_tx_bd_ring[i]) {
1941 if (ugeth->ug_info->uf_info.bd_mem_part ==
1942 MEM_PART_SYSTEM)
1943 kfree((void *)ugeth->tx_bd_ring_offset[i]);
1944 else if (ugeth->ug_info->uf_info.bd_mem_part ==
1945 MEM_PART_MURAM)
1946 qe_muram_free(ugeth->tx_bd_ring_offset[i]);
1947 ugeth->p_tx_bd_ring[i] = NULL;
1948 }
1949 }
1950 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
1951 if (ugeth->p_rx_bd_ring[i]) {
1952 /* Return existing data buffers in ring */
1953 bd = ugeth->p_rx_bd_ring[i];
1954 for (j = 0; j < ugeth->ug_info->bdRingLenRx[i]; j++) {
1955 if (ugeth->rx_skbuff[i][j]) {
Anton Vorontsovda1aa632009-04-02 01:26:07 -07001956 dma_unmap_single(ugeth->dev,
Andy Fleming6fee40e2008-05-02 13:01:23 -05001957 in_be32(&((struct qe_bd __iomem *)bd)->buf),
Li Yang18a8e862006-10-19 21:07:34 -05001958 ugeth->ug_info->
1959 uf_info.max_rx_buf_length +
1960 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
1961 DMA_FROM_DEVICE);
1962 dev_kfree_skb_any(
1963 ugeth->rx_skbuff[i][j]);
Li Yangce973b12006-08-14 23:00:11 -07001964 ugeth->rx_skbuff[i][j] = NULL;
1965 }
Li Yang18a8e862006-10-19 21:07:34 -05001966 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07001967 }
1968
1969 kfree(ugeth->rx_skbuff[i]);
1970
1971 if (ugeth->ug_info->uf_info.bd_mem_part ==
1972 MEM_PART_SYSTEM)
1973 kfree((void *)ugeth->rx_bd_ring_offset[i]);
1974 else if (ugeth->ug_info->uf_info.bd_mem_part ==
1975 MEM_PART_MURAM)
1976 qe_muram_free(ugeth->rx_bd_ring_offset[i]);
1977 ugeth->p_rx_bd_ring[i] = NULL;
1978 }
1979 }
1980 while (!list_empty(&ugeth->group_hash_q))
1981 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
1982 (dequeue(&ugeth->group_hash_q)));
1983 while (!list_empty(&ugeth->ind_hash_q))
1984 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
1985 (dequeue(&ugeth->ind_hash_q)));
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00001986 if (ugeth->ug_regs) {
1987 iounmap(ugeth->ug_regs);
1988 ugeth->ug_regs = NULL;
1989 }
Anton Vorontsov50f238f2009-07-07 08:38:42 +00001990
1991 skb_queue_purge(&ugeth->rx_recycle);
Li Yangce973b12006-08-14 23:00:11 -07001992}
1993
1994static void ucc_geth_set_multi(struct net_device *dev)
1995{
Li Yang18a8e862006-10-19 21:07:34 -05001996 struct ucc_geth_private *ugeth;
Li Yangce973b12006-08-14 23:00:11 -07001997 struct dev_mc_list *dmi;
Andy Fleming6fee40e2008-05-02 13:01:23 -05001998 struct ucc_fast __iomem *uf_regs;
1999 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
Joakim Tjernlund9030b3d2007-10-17 11:05:41 +02002000 int i;
Li Yangce973b12006-08-14 23:00:11 -07002001
2002 ugeth = netdev_priv(dev);
2003
2004 uf_regs = ugeth->uccf->uf_regs;
2005
2006 if (dev->flags & IFF_PROMISC) {
Timur Tabi3bc53422009-01-11 00:25:21 -08002007 setbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
Li Yangce973b12006-08-14 23:00:11 -07002008 } else {
Timur Tabi3bc53422009-01-11 00:25:21 -08002009 clrbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
Li Yangce973b12006-08-14 23:00:11 -07002010
2011 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002012 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002013 p_rx_glbl_pram->addressfiltering;
2014
2015 if (dev->flags & IFF_ALLMULTI) {
2016 /* Catch all multicast addresses, so set the
2017 * filter to all 1's.
2018 */
2019 out_be32(&p_82xx_addr_filt->gaddr_h, 0xffffffff);
2020 out_be32(&p_82xx_addr_filt->gaddr_l, 0xffffffff);
2021 } else {
2022 /* Clear filter and add the addresses in the list.
2023 */
2024 out_be32(&p_82xx_addr_filt->gaddr_h, 0x0);
2025 out_be32(&p_82xx_addr_filt->gaddr_l, 0x0);
2026
2027 dmi = dev->mc_list;
2028
2029 for (i = 0; i < dev->mc_count; i++, dmi = dmi->next) {
2030
2031 /* Only support group multicast for now.
2032 */
2033 if (!(dmi->dmi_addr[0] & 1))
2034 continue;
2035
Li Yangce973b12006-08-14 23:00:11 -07002036 /* Ask CPM to run CRC and set bit in
2037 * filter mask.
2038 */
Joakim Tjernlund9030b3d2007-10-17 11:05:41 +02002039 hw_add_addr_in_hash(ugeth, dmi->dmi_addr);
Li Yangce973b12006-08-14 23:00:11 -07002040 }
2041 }
2042 }
2043}
2044
Li Yang18a8e862006-10-19 21:07:34 -05002045static void ucc_geth_stop(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07002046{
Andy Fleming6fee40e2008-05-02 13:01:23 -05002047 struct ucc_geth __iomem *ug_regs = ugeth->ug_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05002048 struct phy_device *phydev = ugeth->phydev;
Li Yangce973b12006-08-14 23:00:11 -07002049
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002050 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002051
2052 /* Disable the controller */
2053 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
2054
2055 /* Tell the kernel the link is down */
Kim Phillips728de4c92007-04-13 01:26:03 -05002056 phy_stop(phydev);
Li Yangce973b12006-08-14 23:00:11 -07002057
2058 /* Mask all interrupts */
Timur Tabic6f50472007-07-10 07:51:11 -05002059 out_be32(ugeth->uccf->p_uccm, 0x00000000);
Li Yangce973b12006-08-14 23:00:11 -07002060
2061 /* Clear all interrupts */
2062 out_be32(ugeth->uccf->p_ucce, 0xffffffff);
2063
2064 /* Disable Rx and Tx */
Timur Tabi3bc53422009-01-11 00:25:21 -08002065 clrbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
Li Yangce973b12006-08-14 23:00:11 -07002066
Anton Vorontsov79675902009-03-27 16:00:03 -07002067 phy_disconnect(ugeth->phydev);
2068 ugeth->phydev = NULL;
2069
Li Yangce973b12006-08-14 23:00:11 -07002070 ucc_geth_memclean(ugeth);
2071}
2072
Kim Phillips728de4c92007-04-13 01:26:03 -05002073static int ucc_struct_init(struct ucc_geth_private *ugeth)
Li Yangce973b12006-08-14 23:00:11 -07002074{
Li Yang18a8e862006-10-19 21:07:34 -05002075 struct ucc_geth_info *ug_info;
2076 struct ucc_fast_info *uf_info;
Kim Phillips728de4c92007-04-13 01:26:03 -05002077 int i;
Li Yangce973b12006-08-14 23:00:11 -07002078
2079 ug_info = ugeth->ug_info;
2080 uf_info = &ug_info->uf_info;
2081
2082 if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
2083 (uf_info->bd_mem_part == MEM_PART_MURAM))) {
Li Yang890de952007-07-19 11:48:29 +08002084 if (netif_msg_probe(ugeth))
2085 ugeth_err("%s: Bad memory partition value.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002086 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002087 return -EINVAL;
2088 }
2089
2090 /* Rx BD lengths */
2091 for (i = 0; i < ug_info->numQueuesRx; i++) {
2092 if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) ||
2093 (ug_info->bdRingLenRx[i] %
2094 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) {
Li Yang890de952007-07-19 11:48:29 +08002095 if (netif_msg_probe(ugeth))
2096 ugeth_err
2097 ("%s: Rx BD ring length must be multiple of 4, no smaller than 8.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002098 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002099 return -EINVAL;
2100 }
2101 }
2102
2103 /* Tx BD lengths */
2104 for (i = 0; i < ug_info->numQueuesTx; i++) {
2105 if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) {
Li Yang890de952007-07-19 11:48:29 +08002106 if (netif_msg_probe(ugeth))
2107 ugeth_err
2108 ("%s: Tx BD ring length must be no smaller than 2.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002109 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002110 return -EINVAL;
2111 }
2112 }
2113
2114 /* mrblr */
2115 if ((uf_info->max_rx_buf_length == 0) ||
2116 (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) {
Li Yang890de952007-07-19 11:48:29 +08002117 if (netif_msg_probe(ugeth))
2118 ugeth_err
2119 ("%s: max_rx_buf_length must be non-zero multiple of 128.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002120 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002121 return -EINVAL;
2122 }
2123
2124 /* num Tx queues */
2125 if (ug_info->numQueuesTx > NUM_TX_QUEUES) {
Li Yang890de952007-07-19 11:48:29 +08002126 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002127 ugeth_err("%s: number of tx queues too large.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002128 return -EINVAL;
2129 }
2130
2131 /* num Rx queues */
2132 if (ug_info->numQueuesRx > NUM_RX_QUEUES) {
Li Yang890de952007-07-19 11:48:29 +08002133 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002134 ugeth_err("%s: number of rx queues too large.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002135 return -EINVAL;
2136 }
2137
2138 /* l2qt */
2139 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) {
2140 if (ug_info->l2qt[i] >= ug_info->numQueuesRx) {
Li Yang890de952007-07-19 11:48:29 +08002141 if (netif_msg_probe(ugeth))
2142 ugeth_err
2143 ("%s: VLAN priority table entry must not be"
2144 " larger than number of Rx queues.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002145 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002146 return -EINVAL;
2147 }
2148 }
2149
2150 /* l3qt */
2151 for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) {
2152 if (ug_info->l3qt[i] >= ug_info->numQueuesRx) {
Li Yang890de952007-07-19 11:48:29 +08002153 if (netif_msg_probe(ugeth))
2154 ugeth_err
2155 ("%s: IP priority table entry must not be"
2156 " larger than number of Rx queues.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002157 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002158 return -EINVAL;
2159 }
2160 }
2161
2162 if (ug_info->cam && !ug_info->ecamptr) {
Li Yang890de952007-07-19 11:48:29 +08002163 if (netif_msg_probe(ugeth))
2164 ugeth_err("%s: If cam mode is chosen, must supply cam ptr.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002165 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002166 return -EINVAL;
2167 }
2168
2169 if ((ug_info->numStationAddresses !=
2170 UCC_GETH_NUM_OF_STATION_ADDRESSES_1)
2171 && ug_info->rxExtendedFiltering) {
Li Yang890de952007-07-19 11:48:29 +08002172 if (netif_msg_probe(ugeth))
2173 ugeth_err("%s: Number of station addresses greater than 1 "
2174 "not allowed in extended parsing mode.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002175 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002176 return -EINVAL;
2177 }
2178
2179 /* Generate uccm_mask for receive */
2180 uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */
2181 for (i = 0; i < ug_info->numQueuesRx; i++)
Timur Tabi3bc53422009-01-11 00:25:21 -08002182 uf_info->uccm_mask |= (UCC_GETH_UCCE_RXF0 << i);
Li Yangce973b12006-08-14 23:00:11 -07002183
2184 for (i = 0; i < ug_info->numQueuesTx; i++)
Timur Tabi3bc53422009-01-11 00:25:21 -08002185 uf_info->uccm_mask |= (UCC_GETH_UCCE_TXB0 << i);
Li Yangce973b12006-08-14 23:00:11 -07002186 /* Initialize the general fast UCC block. */
Kim Phillips728de4c92007-04-13 01:26:03 -05002187 if (ucc_fast_init(uf_info, &ugeth->uccf)) {
Li Yang890de952007-07-19 11:48:29 +08002188 if (netif_msg_probe(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002189 ugeth_err("%s: Failed to init uccf.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002190 return -ENOMEM;
2191 }
Kim Phillips728de4c92007-04-13 01:26:03 -05002192
Haiying Wang345f8422009-04-29 14:14:35 -04002193 /* read the number of risc engines, update the riscTx and riscRx
2194 * if there are 4 riscs in QE
2195 */
2196 if (qe_get_num_of_risc() == 4) {
2197 ug_info->riscTx = QE_RISC_ALLOCATION_FOUR_RISCS;
2198 ug_info->riscRx = QE_RISC_ALLOCATION_FOUR_RISCS;
2199 }
2200
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00002201 ugeth->ug_regs = ioremap(uf_info->regs, sizeof(*ugeth->ug_regs));
2202 if (!ugeth->ug_regs) {
2203 if (netif_msg_probe(ugeth))
2204 ugeth_err("%s: Failed to ioremap regs.", __func__);
2205 return -ENOMEM;
2206 }
Kim Phillips728de4c92007-04-13 01:26:03 -05002207
Anton Vorontsov50f238f2009-07-07 08:38:42 +00002208 skb_queue_head_init(&ugeth->rx_recycle);
2209
Kim Phillips728de4c92007-04-13 01:26:03 -05002210 return 0;
2211}
2212
2213static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2214{
Andy Fleming6fee40e2008-05-02 13:01:23 -05002215 struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
2216 struct ucc_geth_init_pram __iomem *p_init_enet_pram;
Kim Phillips728de4c92007-04-13 01:26:03 -05002217 struct ucc_fast_private *uccf;
2218 struct ucc_geth_info *ug_info;
2219 struct ucc_fast_info *uf_info;
Andy Fleming6fee40e2008-05-02 13:01:23 -05002220 struct ucc_fast __iomem *uf_regs;
2221 struct ucc_geth __iomem *ug_regs;
Kim Phillips728de4c92007-04-13 01:26:03 -05002222 int ret_val = -EINVAL;
2223 u32 remoder = UCC_GETH_REMODER_INIT;
Timur Tabi3bc53422009-01-11 00:25:21 -08002224 u32 init_enet_pram_offset, cecr_subblock, command;
Kim Phillips728de4c92007-04-13 01:26:03 -05002225 u32 ifstat, i, j, size, l2qt, l3qt, length;
2226 u16 temoder = UCC_GETH_TEMODER_INIT;
2227 u16 test;
2228 u8 function_code = 0;
Andy Fleming6fee40e2008-05-02 13:01:23 -05002229 u8 __iomem *bd;
2230 u8 __iomem *endOfRing;
Kim Phillips728de4c92007-04-13 01:26:03 -05002231 u8 numThreadsRxNumerical, numThreadsTxNumerical;
2232
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002233 ugeth_vdbg("%s: IN", __func__);
Kim Phillips728de4c92007-04-13 01:26:03 -05002234 uccf = ugeth->uccf;
2235 ug_info = ugeth->ug_info;
2236 uf_info = &ug_info->uf_info;
2237 uf_regs = uccf->uf_regs;
2238 ug_regs = ugeth->ug_regs;
Li Yangce973b12006-08-14 23:00:11 -07002239
2240 switch (ug_info->numThreadsRx) {
2241 case UCC_GETH_NUM_OF_THREADS_1:
2242 numThreadsRxNumerical = 1;
2243 break;
2244 case UCC_GETH_NUM_OF_THREADS_2:
2245 numThreadsRxNumerical = 2;
2246 break;
2247 case UCC_GETH_NUM_OF_THREADS_4:
2248 numThreadsRxNumerical = 4;
2249 break;
2250 case UCC_GETH_NUM_OF_THREADS_6:
2251 numThreadsRxNumerical = 6;
2252 break;
2253 case UCC_GETH_NUM_OF_THREADS_8:
2254 numThreadsRxNumerical = 8;
2255 break;
2256 default:
Li Yang890de952007-07-19 11:48:29 +08002257 if (netif_msg_ifup(ugeth))
2258 ugeth_err("%s: Bad number of Rx threads value.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002259 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002260 return -EINVAL;
2261 break;
2262 }
2263
2264 switch (ug_info->numThreadsTx) {
2265 case UCC_GETH_NUM_OF_THREADS_1:
2266 numThreadsTxNumerical = 1;
2267 break;
2268 case UCC_GETH_NUM_OF_THREADS_2:
2269 numThreadsTxNumerical = 2;
2270 break;
2271 case UCC_GETH_NUM_OF_THREADS_4:
2272 numThreadsTxNumerical = 4;
2273 break;
2274 case UCC_GETH_NUM_OF_THREADS_6:
2275 numThreadsTxNumerical = 6;
2276 break;
2277 case UCC_GETH_NUM_OF_THREADS_8:
2278 numThreadsTxNumerical = 8;
2279 break;
2280 default:
Li Yang890de952007-07-19 11:48:29 +08002281 if (netif_msg_ifup(ugeth))
2282 ugeth_err("%s: Bad number of Tx threads value.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002283 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002284 return -EINVAL;
2285 break;
2286 }
2287
2288 /* Calculate rx_extended_features */
2289 ugeth->rx_non_dynamic_extended_features = ug_info->ipCheckSumCheck ||
2290 ug_info->ipAddressAlignment ||
2291 (ug_info->numStationAddresses !=
2292 UCC_GETH_NUM_OF_STATION_ADDRESSES_1);
2293
2294 ugeth->rx_extended_features = ugeth->rx_non_dynamic_extended_features ||
2295 (ug_info->vlanOperationTagged != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
2296 || (ug_info->vlanOperationNonTagged !=
2297 UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP);
2298
Li Yangce973b12006-08-14 23:00:11 -07002299 init_default_reg_vals(&uf_regs->upsmr,
2300 &ug_regs->maccfg1, &ug_regs->maccfg2);
2301
2302 /* Set UPSMR */
2303 /* For more details see the hardware spec. */
2304 init_rx_parameters(ug_info->bro,
2305 ug_info->rsh, ug_info->pro, &uf_regs->upsmr);
2306
2307 /* We're going to ignore other registers for now, */
2308 /* except as needed to get up and running */
2309
2310 /* Set MACCFG1 */
2311 /* For more details see the hardware spec. */
2312 init_flow_control_params(ug_info->aufc,
2313 ug_info->receiveFlowControl,
Li Yangac421852007-07-19 11:47:47 +08002314 ug_info->transmitFlowControl,
Li Yangce973b12006-08-14 23:00:11 -07002315 ug_info->pausePeriod,
2316 ug_info->extensionField,
2317 &uf_regs->upsmr,
2318 &ug_regs->uempr, &ug_regs->maccfg1);
2319
Timur Tabi3bc53422009-01-11 00:25:21 -08002320 setbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
Li Yangce973b12006-08-14 23:00:11 -07002321
2322 /* Set IPGIFG */
2323 /* For more details see the hardware spec. */
2324 ret_val = init_inter_frame_gap_params(ug_info->nonBackToBackIfgPart1,
2325 ug_info->nonBackToBackIfgPart2,
2326 ug_info->
2327 miminumInterFrameGapEnforcement,
2328 ug_info->backToBackInterFrameGap,
2329 &ug_regs->ipgifg);
2330 if (ret_val != 0) {
Li Yang890de952007-07-19 11:48:29 +08002331 if (netif_msg_ifup(ugeth))
2332 ugeth_err("%s: IPGIFG initialization parameter too large.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002333 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002334 return ret_val;
2335 }
2336
2337 /* Set HAFDUP */
2338 /* For more details see the hardware spec. */
2339 ret_val = init_half_duplex_params(ug_info->altBeb,
2340 ug_info->backPressureNoBackoff,
2341 ug_info->noBackoff,
2342 ug_info->excessDefer,
2343 ug_info->altBebTruncation,
2344 ug_info->maxRetransmission,
2345 ug_info->collisionWindow,
2346 &ug_regs->hafdup);
2347 if (ret_val != 0) {
Li Yang890de952007-07-19 11:48:29 +08002348 if (netif_msg_ifup(ugeth))
2349 ugeth_err("%s: Half Duplex initialization parameter too large.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002350 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002351 return ret_val;
2352 }
2353
2354 /* Set IFSTAT */
2355 /* For more details see the hardware spec. */
2356 /* Read only - resets upon read */
2357 ifstat = in_be32(&ug_regs->ifstat);
2358
2359 /* Clear UEMPR */
2360 /* For more details see the hardware spec. */
2361 out_be32(&ug_regs->uempr, 0);
2362
2363 /* Set UESCR */
2364 /* For more details see the hardware spec. */
2365 init_hw_statistics_gathering_mode((ug_info->statisticsMode &
2366 UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE),
2367 0, &uf_regs->upsmr, &ug_regs->uescr);
2368
2369 /* Allocate Tx bds */
2370 for (j = 0; j < ug_info->numQueuesTx; j++) {
2371 /* Allocate in multiple of
2372 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT,
2373 according to spec */
Li Yang18a8e862006-10-19 21:07:34 -05002374 length = ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd))
Li Yangce973b12006-08-14 23:00:11 -07002375 / UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2376 * UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
Li Yang18a8e862006-10-19 21:07:34 -05002377 if ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)) %
Li Yangce973b12006-08-14 23:00:11 -07002378 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2379 length += UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
2380 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2381 u32 align = 4;
2382 if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
2383 align = UCC_GETH_TX_BD_RING_ALIGNMENT;
2384 ugeth->tx_bd_ring_offset[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002385 (u32) kmalloc((u32) (length + align), GFP_KERNEL);
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002386
Li Yangce973b12006-08-14 23:00:11 -07002387 if (ugeth->tx_bd_ring_offset[j] != 0)
2388 ugeth->p_tx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002389 (u8 __iomem *)((ugeth->tx_bd_ring_offset[j] +
Li Yangce973b12006-08-14 23:00:11 -07002390 align) & ~(align - 1));
2391 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2392 ugeth->tx_bd_ring_offset[j] =
2393 qe_muram_alloc(length,
2394 UCC_GETH_TX_BD_RING_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002395 if (!IS_ERR_VALUE(ugeth->tx_bd_ring_offset[j]))
Li Yangce973b12006-08-14 23:00:11 -07002396 ugeth->p_tx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002397 (u8 __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002398 tx_bd_ring_offset[j]);
2399 }
2400 if (!ugeth->p_tx_bd_ring[j]) {
Li Yang890de952007-07-19 11:48:29 +08002401 if (netif_msg_ifup(ugeth))
2402 ugeth_err
2403 ("%s: Can not allocate memory for Tx bd rings.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002404 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002405 return -ENOMEM;
2406 }
2407 /* Zero unused end of bd ring, according to spec */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002408 memset_io((void __iomem *)(ugeth->p_tx_bd_ring[j] +
2409 ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)), 0,
Li Yang18a8e862006-10-19 21:07:34 -05002410 length - ug_info->bdRingLenTx[j] * sizeof(struct qe_bd));
Li Yangce973b12006-08-14 23:00:11 -07002411 }
2412
2413 /* Allocate Rx bds */
2414 for (j = 0; j < ug_info->numQueuesRx; j++) {
Li Yang18a8e862006-10-19 21:07:34 -05002415 length = ug_info->bdRingLenRx[j] * sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002416 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2417 u32 align = 4;
2418 if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
2419 align = UCC_GETH_RX_BD_RING_ALIGNMENT;
2420 ugeth->rx_bd_ring_offset[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002421 (u32) kmalloc((u32) (length + align), GFP_KERNEL);
Li Yangce973b12006-08-14 23:00:11 -07002422 if (ugeth->rx_bd_ring_offset[j] != 0)
2423 ugeth->p_rx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002424 (u8 __iomem *)((ugeth->rx_bd_ring_offset[j] +
Li Yangce973b12006-08-14 23:00:11 -07002425 align) & ~(align - 1));
2426 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2427 ugeth->rx_bd_ring_offset[j] =
2428 qe_muram_alloc(length,
2429 UCC_GETH_RX_BD_RING_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002430 if (!IS_ERR_VALUE(ugeth->rx_bd_ring_offset[j]))
Li Yangce973b12006-08-14 23:00:11 -07002431 ugeth->p_rx_bd_ring[j] =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002432 (u8 __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002433 rx_bd_ring_offset[j]);
2434 }
2435 if (!ugeth->p_rx_bd_ring[j]) {
Li Yang890de952007-07-19 11:48:29 +08002436 if (netif_msg_ifup(ugeth))
2437 ugeth_err
2438 ("%s: Can not allocate memory for Rx bd rings.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002439 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002440 return -ENOMEM;
2441 }
2442 }
2443
2444 /* Init Tx bds */
2445 for (j = 0; j < ug_info->numQueuesTx; j++) {
2446 /* Setup the skbuff rings */
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002447 ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
2448 ugeth->ug_info->bdRingLenTx[j],
2449 GFP_KERNEL);
Li Yangce973b12006-08-14 23:00:11 -07002450
2451 if (ugeth->tx_skbuff[j] == NULL) {
Li Yang890de952007-07-19 11:48:29 +08002452 if (netif_msg_ifup(ugeth))
2453 ugeth_err("%s: Could not allocate tx_skbuff",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002454 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002455 return -ENOMEM;
2456 }
2457
2458 for (i = 0; i < ugeth->ug_info->bdRingLenTx[j]; i++)
2459 ugeth->tx_skbuff[j][i] = NULL;
2460
2461 ugeth->skb_curtx[j] = ugeth->skb_dirtytx[j] = 0;
2462 bd = ugeth->confBd[j] = ugeth->txBd[j] = ugeth->p_tx_bd_ring[j];
2463 for (i = 0; i < ug_info->bdRingLenTx[j]; i++) {
Li Yang18a8e862006-10-19 21:07:34 -05002464 /* clear bd buffer */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002465 out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
Li Yang18a8e862006-10-19 21:07:34 -05002466 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002467 out_be32((u32 __iomem *)bd, 0);
Li Yang18a8e862006-10-19 21:07:34 -05002468 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002469 }
Li Yang18a8e862006-10-19 21:07:34 -05002470 bd -= sizeof(struct qe_bd);
2471 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002472 out_be32((u32 __iomem *)bd, T_W); /* for last BD set Wrap bit */
Li Yangce973b12006-08-14 23:00:11 -07002473 }
2474
2475 /* Init Rx bds */
2476 for (j = 0; j < ug_info->numQueuesRx; j++) {
2477 /* Setup the skbuff rings */
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002478 ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
2479 ugeth->ug_info->bdRingLenRx[j],
2480 GFP_KERNEL);
Li Yangce973b12006-08-14 23:00:11 -07002481
2482 if (ugeth->rx_skbuff[j] == NULL) {
Li Yang890de952007-07-19 11:48:29 +08002483 if (netif_msg_ifup(ugeth))
2484 ugeth_err("%s: Could not allocate rx_skbuff",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002485 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002486 return -ENOMEM;
2487 }
2488
2489 for (i = 0; i < ugeth->ug_info->bdRingLenRx[j]; i++)
2490 ugeth->rx_skbuff[j][i] = NULL;
2491
2492 ugeth->skb_currx[j] = 0;
2493 bd = ugeth->rxBd[j] = ugeth->p_rx_bd_ring[j];
2494 for (i = 0; i < ug_info->bdRingLenRx[j]; i++) {
Li Yang18a8e862006-10-19 21:07:34 -05002495 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002496 out_be32((u32 __iomem *)bd, R_I);
Li Yang18a8e862006-10-19 21:07:34 -05002497 /* clear bd buffer */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002498 out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
Li Yang18a8e862006-10-19 21:07:34 -05002499 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002500 }
Li Yang18a8e862006-10-19 21:07:34 -05002501 bd -= sizeof(struct qe_bd);
2502 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002503 out_be32((u32 __iomem *)bd, R_W); /* for last BD set Wrap bit */
Li Yangce973b12006-08-14 23:00:11 -07002504 }
2505
2506 /*
2507 * Global PRAM
2508 */
2509 /* Tx global PRAM */
2510 /* Allocate global tx parameter RAM page */
2511 ugeth->tx_glbl_pram_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002512 qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram),
Li Yangce973b12006-08-14 23:00:11 -07002513 UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002514 if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002515 if (netif_msg_ifup(ugeth))
2516 ugeth_err
2517 ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002518 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002519 return -ENOMEM;
2520 }
2521 ugeth->p_tx_glbl_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002522 (struct ucc_geth_tx_global_pram __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002523 tx_glbl_pram_offset);
2524 /* Zero out p_tx_glbl_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002525 memset_io((void __iomem *)ugeth->p_tx_glbl_pram, 0, sizeof(struct ucc_geth_tx_global_pram));
Li Yangce973b12006-08-14 23:00:11 -07002526
2527 /* Fill global PRAM */
2528
2529 /* TQPTR */
2530 /* Size varies with number of Tx threads */
2531 ugeth->thread_dat_tx_offset =
2532 qe_muram_alloc(numThreadsTxNumerical *
Li Yang18a8e862006-10-19 21:07:34 -05002533 sizeof(struct ucc_geth_thread_data_tx) +
Li Yangce973b12006-08-14 23:00:11 -07002534 32 * (numThreadsTxNumerical == 1),
2535 UCC_GETH_THREAD_DATA_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002536 if (IS_ERR_VALUE(ugeth->thread_dat_tx_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002537 if (netif_msg_ifup(ugeth))
2538 ugeth_err
2539 ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002540 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002541 return -ENOMEM;
2542 }
2543
2544 ugeth->p_thread_data_tx =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002545 (struct ucc_geth_thread_data_tx __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002546 thread_dat_tx_offset);
2547 out_be32(&ugeth->p_tx_glbl_pram->tqptr, ugeth->thread_dat_tx_offset);
2548
2549 /* vtagtable */
2550 for (i = 0; i < UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX; i++)
2551 out_be32(&ugeth->p_tx_glbl_pram->vtagtable[i],
2552 ug_info->vtagtable[i]);
2553
2554 /* iphoffset */
2555 for (i = 0; i < TX_IP_OFFSET_ENTRY_MAX; i++)
Andy Fleming6fee40e2008-05-02 13:01:23 -05002556 out_8(&ugeth->p_tx_glbl_pram->iphoffset[i],
2557 ug_info->iphoffset[i]);
Li Yangce973b12006-08-14 23:00:11 -07002558
2559 /* SQPTR */
2560 /* Size varies with number of Tx queues */
2561 ugeth->send_q_mem_reg_offset =
2562 qe_muram_alloc(ug_info->numQueuesTx *
Li Yang18a8e862006-10-19 21:07:34 -05002563 sizeof(struct ucc_geth_send_queue_qd),
Li Yangce973b12006-08-14 23:00:11 -07002564 UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002565 if (IS_ERR_VALUE(ugeth->send_q_mem_reg_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002566 if (netif_msg_ifup(ugeth))
2567 ugeth_err
2568 ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002569 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002570 return -ENOMEM;
2571 }
2572
2573 ugeth->p_send_q_mem_reg =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002574 (struct ucc_geth_send_queue_mem_region __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002575 send_q_mem_reg_offset);
2576 out_be32(&ugeth->p_tx_glbl_pram->sqptr, ugeth->send_q_mem_reg_offset);
2577
2578 /* Setup the table */
2579 /* Assume BD rings are already established */
2580 for (i = 0; i < ug_info->numQueuesTx; i++) {
2581 endOfRing =
2582 ugeth->p_tx_bd_ring[i] + (ug_info->bdRingLenTx[i] -
Li Yang18a8e862006-10-19 21:07:34 -05002583 1) * sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07002584 if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
2585 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
2586 (u32) virt_to_phys(ugeth->p_tx_bd_ring[i]));
2587 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
2588 last_bd_completed_address,
2589 (u32) virt_to_phys(endOfRing));
2590 } else if (ugeth->ug_info->uf_info.bd_mem_part ==
2591 MEM_PART_MURAM) {
2592 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
2593 (u32) immrbar_virt_to_phys(ugeth->
2594 p_tx_bd_ring[i]));
2595 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
2596 last_bd_completed_address,
2597 (u32) immrbar_virt_to_phys(endOfRing));
2598 }
2599 }
2600
2601 /* schedulerbasepointer */
2602
2603 if (ug_info->numQueuesTx > 1) {
2604 /* scheduler exists only if more than 1 tx queue */
2605 ugeth->scheduler_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002606 qe_muram_alloc(sizeof(struct ucc_geth_scheduler),
Li Yangce973b12006-08-14 23:00:11 -07002607 UCC_GETH_SCHEDULER_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002608 if (IS_ERR_VALUE(ugeth->scheduler_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002609 if (netif_msg_ifup(ugeth))
2610 ugeth_err
2611 ("%s: Can not allocate DPRAM memory for p_scheduler.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002612 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002613 return -ENOMEM;
2614 }
2615
2616 ugeth->p_scheduler =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002617 (struct ucc_geth_scheduler __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002618 scheduler_offset);
2619 out_be32(&ugeth->p_tx_glbl_pram->schedulerbasepointer,
2620 ugeth->scheduler_offset);
2621 /* Zero out p_scheduler */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002622 memset_io((void __iomem *)ugeth->p_scheduler, 0, sizeof(struct ucc_geth_scheduler));
Li Yangce973b12006-08-14 23:00:11 -07002623
2624 /* Set values in scheduler */
2625 out_be32(&ugeth->p_scheduler->mblinterval,
2626 ug_info->mblinterval);
2627 out_be16(&ugeth->p_scheduler->nortsrbytetime,
2628 ug_info->nortsrbytetime);
Andy Fleming6fee40e2008-05-02 13:01:23 -05002629 out_8(&ugeth->p_scheduler->fracsiz, ug_info->fracsiz);
2630 out_8(&ugeth->p_scheduler->strictpriorityq,
2631 ug_info->strictpriorityq);
2632 out_8(&ugeth->p_scheduler->txasap, ug_info->txasap);
2633 out_8(&ugeth->p_scheduler->extrabw, ug_info->extrabw);
Li Yangce973b12006-08-14 23:00:11 -07002634 for (i = 0; i < NUM_TX_QUEUES; i++)
Andy Fleming6fee40e2008-05-02 13:01:23 -05002635 out_8(&ugeth->p_scheduler->weightfactor[i],
2636 ug_info->weightfactor[i]);
Li Yangce973b12006-08-14 23:00:11 -07002637
2638 /* Set pointers to cpucount registers in scheduler */
2639 ugeth->p_cpucount[0] = &(ugeth->p_scheduler->cpucount0);
2640 ugeth->p_cpucount[1] = &(ugeth->p_scheduler->cpucount1);
2641 ugeth->p_cpucount[2] = &(ugeth->p_scheduler->cpucount2);
2642 ugeth->p_cpucount[3] = &(ugeth->p_scheduler->cpucount3);
2643 ugeth->p_cpucount[4] = &(ugeth->p_scheduler->cpucount4);
2644 ugeth->p_cpucount[5] = &(ugeth->p_scheduler->cpucount5);
2645 ugeth->p_cpucount[6] = &(ugeth->p_scheduler->cpucount6);
2646 ugeth->p_cpucount[7] = &(ugeth->p_scheduler->cpucount7);
2647 }
2648
2649 /* schedulerbasepointer */
2650 /* TxRMON_PTR (statistics) */
2651 if (ug_info->
2652 statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
2653 ugeth->tx_fw_statistics_pram_offset =
2654 qe_muram_alloc(sizeof
Li Yang18a8e862006-10-19 21:07:34 -05002655 (struct ucc_geth_tx_firmware_statistics_pram),
Li Yangce973b12006-08-14 23:00:11 -07002656 UCC_GETH_TX_STATISTICS_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002657 if (IS_ERR_VALUE(ugeth->tx_fw_statistics_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002658 if (netif_msg_ifup(ugeth))
2659 ugeth_err
2660 ("%s: Can not allocate DPRAM memory for"
2661 " p_tx_fw_statistics_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002662 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002663 return -ENOMEM;
2664 }
2665 ugeth->p_tx_fw_statistics_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002666 (struct ucc_geth_tx_firmware_statistics_pram __iomem *)
Li Yangce973b12006-08-14 23:00:11 -07002667 qe_muram_addr(ugeth->tx_fw_statistics_pram_offset);
2668 /* Zero out p_tx_fw_statistics_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002669 memset_io((void __iomem *)ugeth->p_tx_fw_statistics_pram,
Li Yang18a8e862006-10-19 21:07:34 -05002670 0, sizeof(struct ucc_geth_tx_firmware_statistics_pram));
Li Yangce973b12006-08-14 23:00:11 -07002671 }
2672
2673 /* temoder */
2674 /* Already has speed set */
2675
2676 if (ug_info->numQueuesTx > 1)
2677 temoder |= TEMODER_SCHEDULER_ENABLE;
2678 if (ug_info->ipCheckSumGenerate)
2679 temoder |= TEMODER_IP_CHECKSUM_GENERATE;
2680 temoder |= ((ug_info->numQueuesTx - 1) << TEMODER_NUM_OF_QUEUES_SHIFT);
2681 out_be16(&ugeth->p_tx_glbl_pram->temoder, temoder);
2682
2683 test = in_be16(&ugeth->p_tx_glbl_pram->temoder);
2684
2685 /* Function code register value to be used later */
Timur Tabi6b0b5942007-10-03 11:34:59 -05002686 function_code = UCC_BMR_BO_BE | UCC_BMR_GBL;
Li Yangce973b12006-08-14 23:00:11 -07002687 /* Required for QE */
2688
2689 /* function code register */
2690 out_be32(&ugeth->p_tx_glbl_pram->tstate, ((u32) function_code) << 24);
2691
2692 /* Rx global PRAM */
2693 /* Allocate global rx parameter RAM page */
2694 ugeth->rx_glbl_pram_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002695 qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram),
Li Yangce973b12006-08-14 23:00:11 -07002696 UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002697 if (IS_ERR_VALUE(ugeth->rx_glbl_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002698 if (netif_msg_ifup(ugeth))
2699 ugeth_err
2700 ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002701 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002702 return -ENOMEM;
2703 }
2704 ugeth->p_rx_glbl_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002705 (struct ucc_geth_rx_global_pram __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002706 rx_glbl_pram_offset);
2707 /* Zero out p_rx_glbl_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002708 memset_io((void __iomem *)ugeth->p_rx_glbl_pram, 0, sizeof(struct ucc_geth_rx_global_pram));
Li Yangce973b12006-08-14 23:00:11 -07002709
2710 /* Fill global PRAM */
2711
2712 /* RQPTR */
2713 /* Size varies with number of Rx threads */
2714 ugeth->thread_dat_rx_offset =
2715 qe_muram_alloc(numThreadsRxNumerical *
Li Yang18a8e862006-10-19 21:07:34 -05002716 sizeof(struct ucc_geth_thread_data_rx),
Li Yangce973b12006-08-14 23:00:11 -07002717 UCC_GETH_THREAD_DATA_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002718 if (IS_ERR_VALUE(ugeth->thread_dat_rx_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002719 if (netif_msg_ifup(ugeth))
2720 ugeth_err
2721 ("%s: Can not allocate DPRAM memory for p_thread_data_rx.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002722 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002723 return -ENOMEM;
2724 }
2725
2726 ugeth->p_thread_data_rx =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002727 (struct ucc_geth_thread_data_rx __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002728 thread_dat_rx_offset);
2729 out_be32(&ugeth->p_rx_glbl_pram->rqptr, ugeth->thread_dat_rx_offset);
2730
2731 /* typeorlen */
2732 out_be16(&ugeth->p_rx_glbl_pram->typeorlen, ug_info->typeorlen);
2733
2734 /* rxrmonbaseptr (statistics) */
2735 if (ug_info->
2736 statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
2737 ugeth->rx_fw_statistics_pram_offset =
2738 qe_muram_alloc(sizeof
Li Yang18a8e862006-10-19 21:07:34 -05002739 (struct ucc_geth_rx_firmware_statistics_pram),
Li Yangce973b12006-08-14 23:00:11 -07002740 UCC_GETH_RX_STATISTICS_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002741 if (IS_ERR_VALUE(ugeth->rx_fw_statistics_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002742 if (netif_msg_ifup(ugeth))
2743 ugeth_err
2744 ("%s: Can not allocate DPRAM memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002745 " p_rx_fw_statistics_pram.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002746 return -ENOMEM;
2747 }
2748 ugeth->p_rx_fw_statistics_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002749 (struct ucc_geth_rx_firmware_statistics_pram __iomem *)
Li Yangce973b12006-08-14 23:00:11 -07002750 qe_muram_addr(ugeth->rx_fw_statistics_pram_offset);
2751 /* Zero out p_rx_fw_statistics_pram */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002752 memset_io((void __iomem *)ugeth->p_rx_fw_statistics_pram, 0,
Li Yang18a8e862006-10-19 21:07:34 -05002753 sizeof(struct ucc_geth_rx_firmware_statistics_pram));
Li Yangce973b12006-08-14 23:00:11 -07002754 }
2755
2756 /* intCoalescingPtr */
2757
2758 /* Size varies with number of Rx queues */
2759 ugeth->rx_irq_coalescing_tbl_offset =
2760 qe_muram_alloc(ug_info->numQueuesRx *
Michael Barkowski75639072007-04-13 01:26:15 -05002761 sizeof(struct ucc_geth_rx_interrupt_coalescing_entry)
2762 + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002763 if (IS_ERR_VALUE(ugeth->rx_irq_coalescing_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"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002767 " p_rx_irq_coalescing_tbl.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002768 return -ENOMEM;
2769 }
2770
2771 ugeth->p_rx_irq_coalescing_tbl =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002772 (struct ucc_geth_rx_interrupt_coalescing_table __iomem *)
Li Yangce973b12006-08-14 23:00:11 -07002773 qe_muram_addr(ugeth->rx_irq_coalescing_tbl_offset);
2774 out_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr,
2775 ugeth->rx_irq_coalescing_tbl_offset);
2776
2777 /* Fill interrupt coalescing table */
2778 for (i = 0; i < ug_info->numQueuesRx; i++) {
2779 out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
2780 interruptcoalescingmaxvalue,
2781 ug_info->interruptcoalescingmaxvalue[i]);
2782 out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
2783 interruptcoalescingcounter,
2784 ug_info->interruptcoalescingmaxvalue[i]);
2785 }
2786
2787 /* MRBLR */
2788 init_max_rx_buff_len(uf_info->max_rx_buf_length,
2789 &ugeth->p_rx_glbl_pram->mrblr);
2790 /* MFLR */
2791 out_be16(&ugeth->p_rx_glbl_pram->mflr, ug_info->maxFrameLength);
2792 /* MINFLR */
2793 init_min_frame_len(ug_info->minFrameLength,
2794 &ugeth->p_rx_glbl_pram->minflr,
2795 &ugeth->p_rx_glbl_pram->mrblr);
2796 /* MAXD1 */
2797 out_be16(&ugeth->p_rx_glbl_pram->maxd1, ug_info->maxD1Length);
2798 /* MAXD2 */
2799 out_be16(&ugeth->p_rx_glbl_pram->maxd2, ug_info->maxD2Length);
2800
2801 /* l2qt */
2802 l2qt = 0;
2803 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++)
2804 l2qt |= (ug_info->l2qt[i] << (28 - 4 * i));
2805 out_be32(&ugeth->p_rx_glbl_pram->l2qt, l2qt);
2806
2807 /* l3qt */
2808 for (j = 0; j < UCC_GETH_IP_PRIORITY_MAX; j += 8) {
2809 l3qt = 0;
2810 for (i = 0; i < 8; i++)
2811 l3qt |= (ug_info->l3qt[j + i] << (28 - 4 * i));
Li Yang18a8e862006-10-19 21:07:34 -05002812 out_be32(&ugeth->p_rx_glbl_pram->l3qt[j/8], l3qt);
Li Yangce973b12006-08-14 23:00:11 -07002813 }
2814
2815 /* vlantype */
2816 out_be16(&ugeth->p_rx_glbl_pram->vlantype, ug_info->vlantype);
2817
2818 /* vlantci */
2819 out_be16(&ugeth->p_rx_glbl_pram->vlantci, ug_info->vlantci);
2820
2821 /* ecamptr */
2822 out_be32(&ugeth->p_rx_glbl_pram->ecamptr, ug_info->ecamptr);
2823
2824 /* RBDQPTR */
2825 /* Size varies with number of Rx queues */
2826 ugeth->rx_bd_qs_tbl_offset =
2827 qe_muram_alloc(ug_info->numQueuesRx *
Li Yang18a8e862006-10-19 21:07:34 -05002828 (sizeof(struct ucc_geth_rx_bd_queues_entry) +
2829 sizeof(struct ucc_geth_rx_prefetched_bds)),
Li Yangce973b12006-08-14 23:00:11 -07002830 UCC_GETH_RX_BD_QUEUES_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002831 if (IS_ERR_VALUE(ugeth->rx_bd_qs_tbl_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002832 if (netif_msg_ifup(ugeth))
2833 ugeth_err
2834 ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002835 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002836 return -ENOMEM;
2837 }
2838
2839 ugeth->p_rx_bd_qs_tbl =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002840 (struct ucc_geth_rx_bd_queues_entry __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002841 rx_bd_qs_tbl_offset);
2842 out_be32(&ugeth->p_rx_glbl_pram->rbdqptr, ugeth->rx_bd_qs_tbl_offset);
2843 /* Zero out p_rx_bd_qs_tbl */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002844 memset_io((void __iomem *)ugeth->p_rx_bd_qs_tbl,
Li Yangce973b12006-08-14 23:00:11 -07002845 0,
Li Yang18a8e862006-10-19 21:07:34 -05002846 ug_info->numQueuesRx * (sizeof(struct ucc_geth_rx_bd_queues_entry) +
2847 sizeof(struct ucc_geth_rx_prefetched_bds)));
Li Yangce973b12006-08-14 23:00:11 -07002848
2849 /* Setup the table */
2850 /* Assume BD rings are already established */
2851 for (i = 0; i < ug_info->numQueuesRx; i++) {
2852 if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
2853 out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
2854 (u32) virt_to_phys(ugeth->p_rx_bd_ring[i]));
2855 } else if (ugeth->ug_info->uf_info.bd_mem_part ==
2856 MEM_PART_MURAM) {
2857 out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
2858 (u32) immrbar_virt_to_phys(ugeth->
2859 p_rx_bd_ring[i]));
2860 }
2861 /* rest of fields handled by QE */
2862 }
2863
2864 /* remoder */
2865 /* Already has speed set */
2866
2867 if (ugeth->rx_extended_features)
2868 remoder |= REMODER_RX_EXTENDED_FEATURES;
2869 if (ug_info->rxExtendedFiltering)
2870 remoder |= REMODER_RX_EXTENDED_FILTERING;
2871 if (ug_info->dynamicMaxFrameLength)
2872 remoder |= REMODER_DYNAMIC_MAX_FRAME_LENGTH;
2873 if (ug_info->dynamicMinFrameLength)
2874 remoder |= REMODER_DYNAMIC_MIN_FRAME_LENGTH;
2875 remoder |=
2876 ug_info->vlanOperationTagged << REMODER_VLAN_OPERATION_TAGGED_SHIFT;
2877 remoder |=
2878 ug_info->
2879 vlanOperationNonTagged << REMODER_VLAN_OPERATION_NON_TAGGED_SHIFT;
2880 remoder |= ug_info->rxQoSMode << REMODER_RX_QOS_MODE_SHIFT;
2881 remoder |= ((ug_info->numQueuesRx - 1) << REMODER_NUM_OF_QUEUES_SHIFT);
2882 if (ug_info->ipCheckSumCheck)
2883 remoder |= REMODER_IP_CHECKSUM_CHECK;
2884 if (ug_info->ipAddressAlignment)
2885 remoder |= REMODER_IP_ADDRESS_ALIGNMENT;
2886 out_be32(&ugeth->p_rx_glbl_pram->remoder, remoder);
2887
2888 /* Note that this function must be called */
2889 /* ONLY AFTER p_tx_fw_statistics_pram */
2890 /* andp_UccGethRxFirmwareStatisticsPram are allocated ! */
2891 init_firmware_statistics_gathering_mode((ug_info->
2892 statisticsMode &
2893 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX),
2894 (ug_info->statisticsMode &
2895 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX),
2896 &ugeth->p_tx_glbl_pram->txrmonbaseptr,
2897 ugeth->tx_fw_statistics_pram_offset,
2898 &ugeth->p_rx_glbl_pram->rxrmonbaseptr,
2899 ugeth->rx_fw_statistics_pram_offset,
2900 &ugeth->p_tx_glbl_pram->temoder,
2901 &ugeth->p_rx_glbl_pram->remoder);
2902
2903 /* function code register */
Andy Fleming6fee40e2008-05-02 13:01:23 -05002904 out_8(&ugeth->p_rx_glbl_pram->rstate, function_code);
Li Yangce973b12006-08-14 23:00:11 -07002905
2906 /* initialize extended filtering */
2907 if (ug_info->rxExtendedFiltering) {
2908 if (!ug_info->extendedFilteringChainPointer) {
Li Yang890de952007-07-19 11:48:29 +08002909 if (netif_msg_ifup(ugeth))
2910 ugeth_err("%s: Null Extended Filtering Chain Pointer.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002911 __func__);
Li Yangce973b12006-08-14 23:00:11 -07002912 return -EINVAL;
2913 }
2914
2915 /* Allocate memory for extended filtering Mode Global
2916 Parameters */
2917 ugeth->exf_glbl_param_offset =
Li Yang18a8e862006-10-19 21:07:34 -05002918 qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram),
Li Yangce973b12006-08-14 23:00:11 -07002919 UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT);
Timur Tabi4c356302007-05-08 14:46:36 -05002920 if (IS_ERR_VALUE(ugeth->exf_glbl_param_offset)) {
Li Yang890de952007-07-19 11:48:29 +08002921 if (netif_msg_ifup(ugeth))
2922 ugeth_err
2923 ("%s: Can not allocate DPRAM memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002924 " p_exf_glbl_param.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002925 return -ENOMEM;
2926 }
2927
2928 ugeth->p_exf_glbl_param =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002929 (struct ucc_geth_exf_global_pram __iomem *) qe_muram_addr(ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002930 exf_glbl_param_offset);
2931 out_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam,
2932 ugeth->exf_glbl_param_offset);
2933 out_be32(&ugeth->p_exf_glbl_param->l2pcdptr,
2934 (u32) ug_info->extendedFilteringChainPointer);
2935
2936 } else { /* initialize 82xx style address filtering */
2937
2938 /* Init individual address recognition registers to disabled */
2939
2940 for (j = 0; j < NUM_OF_PADDRS; j++)
2941 ugeth_82xx_filtering_clear_addr_in_paddr(ugeth, (u8) j);
2942
Li Yangce973b12006-08-14 23:00:11 -07002943 p_82xx_addr_filt =
Andy Fleming6fee40e2008-05-02 13:01:23 -05002944 (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
Li Yangce973b12006-08-14 23:00:11 -07002945 p_rx_glbl_pram->addressfiltering;
2946
2947 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
2948 ENET_ADDR_TYPE_GROUP);
2949 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
2950 ENET_ADDR_TYPE_INDIVIDUAL);
2951 }
2952
2953 /*
2954 * Initialize UCC at QE level
2955 */
2956
2957 command = QE_INIT_TX_RX;
2958
2959 /* Allocate shadow InitEnet command parameter structure.
2960 * This is needed because after the InitEnet command is executed,
2961 * the structure in DPRAM is released, because DPRAM is a premium
2962 * resource.
2963 * This shadow structure keeps a copy of what was done so that the
2964 * allocated resources can be released when the channel is freed.
2965 */
2966 if (!(ugeth->p_init_enet_param_shadow =
Ahmed S. Darwish04b588d2007-01-27 00:00:02 -08002967 kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
Li Yang890de952007-07-19 11:48:29 +08002968 if (netif_msg_ifup(ugeth))
2969 ugeth_err
2970 ("%s: Can not allocate memory for"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07002971 " p_UccInitEnetParamShadows.", __func__);
Li Yangce973b12006-08-14 23:00:11 -07002972 return -ENOMEM;
2973 }
2974 /* Zero out *p_init_enet_param_shadow */
2975 memset((char *)ugeth->p_init_enet_param_shadow,
Li Yang18a8e862006-10-19 21:07:34 -05002976 0, sizeof(struct ucc_geth_init_pram));
Li Yangce973b12006-08-14 23:00:11 -07002977
2978 /* Fill shadow InitEnet command parameter structure */
2979
2980 ugeth->p_init_enet_param_shadow->resinit1 =
2981 ENET_INIT_PARAM_MAGIC_RES_INIT1;
2982 ugeth->p_init_enet_param_shadow->resinit2 =
2983 ENET_INIT_PARAM_MAGIC_RES_INIT2;
2984 ugeth->p_init_enet_param_shadow->resinit3 =
2985 ENET_INIT_PARAM_MAGIC_RES_INIT3;
2986 ugeth->p_init_enet_param_shadow->resinit4 =
2987 ENET_INIT_PARAM_MAGIC_RES_INIT4;
2988 ugeth->p_init_enet_param_shadow->resinit5 =
2989 ENET_INIT_PARAM_MAGIC_RES_INIT5;
2990 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
2991 ((u32) ug_info->numThreadsRx) << ENET_INIT_PARAM_RGF_SHIFT;
2992 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
2993 ((u32) ug_info->numThreadsTx) << ENET_INIT_PARAM_TGF_SHIFT;
2994
2995 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
2996 ugeth->rx_glbl_pram_offset | ug_info->riscRx;
2997 if ((ug_info->largestexternallookupkeysize !=
2998 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE)
2999 && (ug_info->largestexternallookupkeysize !=
3000 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
3001 && (ug_info->largestexternallookupkeysize !=
3002 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) {
Li Yang890de952007-07-19 11:48:29 +08003003 if (netif_msg_ifup(ugeth))
3004 ugeth_err("%s: Invalid largest External Lookup Key Size.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003005 __func__);
Li Yangce973b12006-08-14 23:00:11 -07003006 return -EINVAL;
3007 }
3008 ugeth->p_init_enet_param_shadow->largestexternallookupkeysize =
3009 ug_info->largestexternallookupkeysize;
Li Yang18a8e862006-10-19 21:07:34 -05003010 size = sizeof(struct ucc_geth_thread_rx_pram);
Li Yangce973b12006-08-14 23:00:11 -07003011 if (ug_info->rxExtendedFiltering) {
3012 size += THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
3013 if (ug_info->largestexternallookupkeysize ==
3014 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
3015 size +=
3016 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
3017 if (ug_info->largestexternallookupkeysize ==
3018 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
3019 size +=
3020 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
3021 }
3022
3023 if ((ret_val = fill_init_enet_entries(ugeth, &(ugeth->
3024 p_init_enet_param_shadow->rxthread[0]),
3025 (u8) (numThreadsRxNumerical + 1)
3026 /* Rx needs one extra for terminator */
3027 , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT,
3028 ug_info->riscRx, 1)) != 0) {
Li Yang890de952007-07-19 11:48:29 +08003029 if (netif_msg_ifup(ugeth))
3030 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003031 __func__);
Li Yangce973b12006-08-14 23:00:11 -07003032 return ret_val;
3033 }
3034
3035 ugeth->p_init_enet_param_shadow->txglobal =
3036 ugeth->tx_glbl_pram_offset | ug_info->riscTx;
3037 if ((ret_val =
3038 fill_init_enet_entries(ugeth,
3039 &(ugeth->p_init_enet_param_shadow->
3040 txthread[0]), numThreadsTxNumerical,
Li Yang18a8e862006-10-19 21:07:34 -05003041 sizeof(struct ucc_geth_thread_tx_pram),
Li Yangce973b12006-08-14 23:00:11 -07003042 UCC_GETH_THREAD_TX_PRAM_ALIGNMENT,
3043 ug_info->riscTx, 0)) != 0) {
Li Yang890de952007-07-19 11:48:29 +08003044 if (netif_msg_ifup(ugeth))
3045 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003046 __func__);
Li Yangce973b12006-08-14 23:00:11 -07003047 return ret_val;
3048 }
3049
3050 /* Load Rx bds with buffers */
3051 for (i = 0; i < ug_info->numQueuesRx; i++) {
3052 if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) {
Li Yang890de952007-07-19 11:48:29 +08003053 if (netif_msg_ifup(ugeth))
3054 ugeth_err("%s: Can not fill Rx bds with buffers.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003055 __func__);
Li Yangce973b12006-08-14 23:00:11 -07003056 return ret_val;
3057 }
3058 }
3059
3060 /* Allocate InitEnet command parameter structure */
Li Yang18a8e862006-10-19 21:07:34 -05003061 init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4);
Timur Tabi4c356302007-05-08 14:46:36 -05003062 if (IS_ERR_VALUE(init_enet_pram_offset)) {
Li Yang890de952007-07-19 11:48:29 +08003063 if (netif_msg_ifup(ugeth))
3064 ugeth_err
3065 ("%s: Can not allocate DPRAM memory for p_init_enet_pram.",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003066 __func__);
Li Yangce973b12006-08-14 23:00:11 -07003067 return -ENOMEM;
3068 }
3069 p_init_enet_pram =
Andy Fleming6fee40e2008-05-02 13:01:23 -05003070 (struct ucc_geth_init_pram __iomem *) qe_muram_addr(init_enet_pram_offset);
Li Yangce973b12006-08-14 23:00:11 -07003071
3072 /* Copy shadow InitEnet command parameter structure into PRAM */
Andy Fleming6fee40e2008-05-02 13:01:23 -05003073 out_8(&p_init_enet_pram->resinit1,
3074 ugeth->p_init_enet_param_shadow->resinit1);
3075 out_8(&p_init_enet_pram->resinit2,
3076 ugeth->p_init_enet_param_shadow->resinit2);
3077 out_8(&p_init_enet_pram->resinit3,
3078 ugeth->p_init_enet_param_shadow->resinit3);
3079 out_8(&p_init_enet_pram->resinit4,
3080 ugeth->p_init_enet_param_shadow->resinit4);
Li Yangce973b12006-08-14 23:00:11 -07003081 out_be16(&p_init_enet_pram->resinit5,
3082 ugeth->p_init_enet_param_shadow->resinit5);
Andy Fleming6fee40e2008-05-02 13:01:23 -05003083 out_8(&p_init_enet_pram->largestexternallookupkeysize,
3084 ugeth->p_init_enet_param_shadow->largestexternallookupkeysize);
Li Yangce973b12006-08-14 23:00:11 -07003085 out_be32(&p_init_enet_pram->rgftgfrxglobal,
3086 ugeth->p_init_enet_param_shadow->rgftgfrxglobal);
3087 for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_RX; i++)
3088 out_be32(&p_init_enet_pram->rxthread[i],
3089 ugeth->p_init_enet_param_shadow->rxthread[i]);
3090 out_be32(&p_init_enet_pram->txglobal,
3091 ugeth->p_init_enet_param_shadow->txglobal);
3092 for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_TX; i++)
3093 out_be32(&p_init_enet_pram->txthread[i],
3094 ugeth->p_init_enet_param_shadow->txthread[i]);
3095
3096 /* Issue QE command */
3097 cecr_subblock =
3098 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
Li Yang18a8e862006-10-19 21:07:34 -05003099 qe_issue_cmd(command, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
Li Yangce973b12006-08-14 23:00:11 -07003100 init_enet_pram_offset);
3101
3102 /* Free InitEnet command parameter */
3103 qe_muram_free(init_enet_pram_offset);
3104
3105 return 0;
3106}
3107
Li Yangce973b12006-08-14 23:00:11 -07003108/* This is called by the kernel when a frame is ready for transmission. */
3109/* It is pointed to by the dev->hard_start_xmit function pointer */
3110static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
3111{
Li Yang18a8e862006-10-19 21:07:34 -05003112 struct ucc_geth_private *ugeth = netdev_priv(dev);
Michael Reissd5b90492007-04-13 01:26:19 -05003113#ifdef CONFIG_UGETH_TX_ON_DEMAND
3114 struct ucc_fast_private *uccf;
3115#endif
Andy Fleming6fee40e2008-05-02 13:01:23 -05003116 u8 __iomem *bd; /* BD pointer */
Li Yangce973b12006-08-14 23:00:11 -07003117 u32 bd_status;
3118 u8 txQ = 0;
3119
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003120 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003121
3122 spin_lock_irq(&ugeth->lock);
3123
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003124 dev->stats.tx_bytes += skb->len;
Li Yangce973b12006-08-14 23:00:11 -07003125
3126 /* Start from the next BD that should be filled */
3127 bd = ugeth->txBd[txQ];
Andy Fleming6fee40e2008-05-02 13:01:23 -05003128 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003129 /* Save the skb pointer so we can free it later */
3130 ugeth->tx_skbuff[txQ][ugeth->skb_curtx[txQ]] = skb;
3131
3132 /* Update the current skb pointer (wrapping if this was the last) */
3133 ugeth->skb_curtx[txQ] =
3134 (ugeth->skb_curtx[txQ] +
3135 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
3136
3137 /* set up the buffer descriptor */
Andy Fleming6fee40e2008-05-02 13:01:23 -05003138 out_be32(&((struct qe_bd __iomem *)bd)->buf,
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003139 dma_map_single(ugeth->dev, skb->data,
Andy Fleming7f802022008-05-15 17:00:21 -05003140 skb->len, DMA_TO_DEVICE));
Li Yangce973b12006-08-14 23:00:11 -07003141
Li Yang18a8e862006-10-19 21:07:34 -05003142 /* printk(KERN_DEBUG"skb->data is 0x%x\n",skb->data); */
Li Yangce973b12006-08-14 23:00:11 -07003143
3144 bd_status = (bd_status & T_W) | T_R | T_I | T_L | skb->len;
3145
Li Yang18a8e862006-10-19 21:07:34 -05003146 /* set bd status and length */
Andy Fleming6fee40e2008-05-02 13:01:23 -05003147 out_be32((u32 __iomem *)bd, bd_status);
Li Yangce973b12006-08-14 23:00:11 -07003148
3149 dev->trans_start = jiffies;
3150
3151 /* Move to next BD in the ring */
3152 if (!(bd_status & T_W))
Li Yanga394f012007-03-06 16:53:46 +08003153 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07003154 else
Li Yanga394f012007-03-06 16:53:46 +08003155 bd = ugeth->p_tx_bd_ring[txQ];
Li Yangce973b12006-08-14 23:00:11 -07003156
3157 /* If the next BD still needs to be cleaned up, then the bds
3158 are full. We need to tell the kernel to stop sending us stuff. */
3159 if (bd == ugeth->confBd[txQ]) {
3160 if (!netif_queue_stopped(dev))
3161 netif_stop_queue(dev);
3162 }
3163
Li Yanga394f012007-03-06 16:53:46 +08003164 ugeth->txBd[txQ] = bd;
3165
Li Yangce973b12006-08-14 23:00:11 -07003166 if (ugeth->p_scheduler) {
3167 ugeth->cpucount[txQ]++;
3168 /* Indicate to QE that there are more Tx bds ready for
3169 transmission */
3170 /* This is done by writing a running counter of the bd
3171 count to the scheduler PRAM. */
3172 out_be16(ugeth->p_cpucount[txQ], ugeth->cpucount[txQ]);
3173 }
3174
Michael Reissd5b90492007-04-13 01:26:19 -05003175#ifdef CONFIG_UGETH_TX_ON_DEMAND
3176 uccf = ugeth->uccf;
3177 out_be16(uccf->p_utodr, UCC_FAST_TOD);
3178#endif
Li Yangce973b12006-08-14 23:00:11 -07003179 spin_unlock_irq(&ugeth->lock);
3180
Patrick McHardy6ed10652009-06-23 06:03:08 +00003181 return NETDEV_TX_OK;
Li Yangce973b12006-08-14 23:00:11 -07003182}
3183
Li Yang18a8e862006-10-19 21:07:34 -05003184static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit)
Li Yangce973b12006-08-14 23:00:11 -07003185{
3186 struct sk_buff *skb;
Andy Fleming6fee40e2008-05-02 13:01:23 -05003187 u8 __iomem *bd;
Li Yangce973b12006-08-14 23:00:11 -07003188 u16 length, howmany = 0;
3189 u32 bd_status;
3190 u8 *bdBuffer;
Andrew Morton4b8fdef2007-12-13 16:02:55 -08003191 struct net_device *dev;
Li Yangce973b12006-08-14 23:00:11 -07003192
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003193 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003194
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003195 dev = ugeth->ndev;
Emil Medve88a15f22007-10-15 08:43:50 -05003196
Li Yangce973b12006-08-14 23:00:11 -07003197 /* collect received buffers */
3198 bd = ugeth->rxBd[rxQ];
3199
Andy Fleming6fee40e2008-05-02 13:01:23 -05003200 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003201
3202 /* while there are received buffers and BD is full (~R_E) */
3203 while (!((bd_status & (R_E)) || (--rx_work_limit < 0))) {
Andy Fleming6fee40e2008-05-02 13:01:23 -05003204 bdBuffer = (u8 *) in_be32(&((struct qe_bd __iomem *)bd)->buf);
Li Yangce973b12006-08-14 23:00:11 -07003205 length = (u16) ((bd_status & BD_LENGTH_MASK) - 4);
3206 skb = ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]];
3207
3208 /* determine whether buffer is first, last, first and last
3209 (single buffer frame) or middle (not first and not last) */
3210 if (!skb ||
3211 (!(bd_status & (R_F | R_L))) ||
3212 (bd_status & R_ERRORS_FATAL)) {
Li Yang890de952007-07-19 11:48:29 +08003213 if (netif_msg_rx_err(ugeth))
3214 ugeth_err("%s, %d: ERROR!!! skb - 0x%08x",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003215 __func__, __LINE__, (u32) skb);
Anton Vorontsov50f238f2009-07-07 08:38:42 +00003216 if (skb) {
3217 skb->data = skb->head + NET_SKB_PAD;
3218 __skb_queue_head(&ugeth->rx_recycle, skb);
3219 }
Li Yangce973b12006-08-14 23:00:11 -07003220
3221 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL;
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003222 dev->stats.rx_dropped++;
Li Yangce973b12006-08-14 23:00:11 -07003223 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003224 dev->stats.rx_packets++;
Li Yangce973b12006-08-14 23:00:11 -07003225 howmany++;
3226
3227 /* Prep the skb for the packet */
3228 skb_put(skb, length);
3229
3230 /* Tell the skb what kind of packet this is */
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003231 skb->protocol = eth_type_trans(skb, ugeth->ndev);
Li Yangce973b12006-08-14 23:00:11 -07003232
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003233 dev->stats.rx_bytes += length;
Li Yangce973b12006-08-14 23:00:11 -07003234 /* Send the packet up the stack */
Li Yangce973b12006-08-14 23:00:11 -07003235 netif_receive_skb(skb);
Li Yangce973b12006-08-14 23:00:11 -07003236 }
3237
Li Yangce973b12006-08-14 23:00:11 -07003238 skb = get_new_skb(ugeth, bd);
3239 if (!skb) {
Li Yang890de952007-07-19 11:48:29 +08003240 if (netif_msg_rx_err(ugeth))
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003241 ugeth_warn("%s: No Rx Data Buffer", __func__);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003242 dev->stats.rx_dropped++;
Li Yangce973b12006-08-14 23:00:11 -07003243 break;
3244 }
3245
3246 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = skb;
3247
3248 /* update to point at the next skb */
3249 ugeth->skb_currx[rxQ] =
3250 (ugeth->skb_currx[rxQ] +
3251 1) & RX_RING_MOD_MASK(ugeth->ug_info->bdRingLenRx[rxQ]);
3252
3253 if (bd_status & R_W)
3254 bd = ugeth->p_rx_bd_ring[rxQ];
3255 else
Li Yang18a8e862006-10-19 21:07:34 -05003256 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07003257
Andy Fleming6fee40e2008-05-02 13:01:23 -05003258 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003259 }
3260
3261 ugeth->rxBd[rxQ] = bd;
Li Yangce973b12006-08-14 23:00:11 -07003262 return howmany;
3263}
3264
3265static int ucc_geth_tx(struct net_device *dev, u8 txQ)
3266{
3267 /* Start from the next BD that should be filled */
Li Yang18a8e862006-10-19 21:07:34 -05003268 struct ucc_geth_private *ugeth = netdev_priv(dev);
Andy Fleming6fee40e2008-05-02 13:01:23 -05003269 u8 __iomem *bd; /* BD pointer */
Li Yangce973b12006-08-14 23:00:11 -07003270 u32 bd_status;
3271
3272 bd = ugeth->confBd[txQ];
Andy Fleming6fee40e2008-05-02 13:01:23 -05003273 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003274
3275 /* Normal processing. */
3276 while ((bd_status & T_R) == 0) {
Anton Vorontsov50f238f2009-07-07 08:38:42 +00003277 struct sk_buff *skb;
3278
Li Yangce973b12006-08-14 23:00:11 -07003279 /* BD contains already transmitted buffer. */
3280 /* Handle the transmitted buffer and release */
3281 /* the BD to be used with the current frame */
3282
Li Yanga394f012007-03-06 16:53:46 +08003283 if ((bd == ugeth->txBd[txQ]) && (netif_queue_stopped(dev) == 0))
Li Yangce973b12006-08-14 23:00:11 -07003284 break;
3285
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003286 dev->stats.tx_packets++;
Li Yangce973b12006-08-14 23:00:11 -07003287
Anton Vorontsov50f238f2009-07-07 08:38:42 +00003288 skb = ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]];
3289
3290 if (skb_queue_len(&ugeth->rx_recycle) < RX_BD_RING_LEN &&
3291 skb_recycle_check(skb,
3292 ugeth->ug_info->uf_info.max_rx_buf_length +
3293 UCC_GETH_RX_DATA_BUF_ALIGNMENT))
3294 __skb_queue_head(&ugeth->rx_recycle, skb);
3295 else
3296 dev_kfree_skb(skb);
3297
Li Yangce973b12006-08-14 23:00:11 -07003298 ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL;
3299 ugeth->skb_dirtytx[txQ] =
3300 (ugeth->skb_dirtytx[txQ] +
3301 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
3302
3303 /* We freed a buffer, so now we can restart transmission */
3304 if (netif_queue_stopped(dev))
3305 netif_wake_queue(dev);
3306
3307 /* Advance the confirmation BD pointer */
3308 if (!(bd_status & T_W))
Li Yanga394f012007-03-06 16:53:46 +08003309 bd += sizeof(struct qe_bd);
Li Yangce973b12006-08-14 23:00:11 -07003310 else
Li Yanga394f012007-03-06 16:53:46 +08003311 bd = ugeth->p_tx_bd_ring[txQ];
Andy Fleming6fee40e2008-05-02 13:01:23 -05003312 bd_status = in_be32((u32 __iomem *)bd);
Li Yangce973b12006-08-14 23:00:11 -07003313 }
Li Yanga394f012007-03-06 16:53:46 +08003314 ugeth->confBd[txQ] = bd;
Li Yangce973b12006-08-14 23:00:11 -07003315 return 0;
3316}
3317
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003318static int ucc_geth_poll(struct napi_struct *napi, int budget)
Li Yangce973b12006-08-14 23:00:11 -07003319{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003320 struct ucc_geth_private *ugeth = container_of(napi, struct ucc_geth_private, napi);
Michael Reiss702ff122007-04-13 01:26:11 -05003321 struct ucc_geth_info *ug_info;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003322 int howmany, i;
Li Yangce973b12006-08-14 23:00:11 -07003323
Michael Reiss702ff122007-04-13 01:26:11 -05003324 ug_info = ugeth->ug_info;
3325
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003326 /* Tx event processing */
3327 spin_lock(&ugeth->lock);
3328 for (i = 0; i < ug_info->numQueuesTx; i++)
3329 ucc_geth_tx(ugeth->ndev, i);
3330 spin_unlock(&ugeth->lock);
3331
Anton Vorontsov50f238f2009-07-07 08:38:42 +00003332 howmany = 0;
3333 for (i = 0; i < ug_info->numQueuesRx; i++)
3334 howmany += ucc_geth_rx(ugeth, i, budget - howmany);
3335
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003336 if (howmany < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08003337 napi_complete(napi);
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003338 setbits32(ugeth->uccf->p_uccm, UCCE_RX_EVENTS | UCCE_TX_EVENTS);
Michael Reiss702ff122007-04-13 01:26:11 -05003339 }
Li Yangce973b12006-08-14 23:00:11 -07003340
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003341 return howmany;
Li Yangce973b12006-08-14 23:00:11 -07003342}
Li Yangce973b12006-08-14 23:00:11 -07003343
David Howells7d12e782006-10-05 14:55:46 +01003344static irqreturn_t ucc_geth_irq_handler(int irq, void *info)
Li Yangce973b12006-08-14 23:00:11 -07003345{
Jeff Garzik06efcad2007-10-19 03:10:11 -04003346 struct net_device *dev = info;
Li Yang18a8e862006-10-19 21:07:34 -05003347 struct ucc_geth_private *ugeth = netdev_priv(dev);
3348 struct ucc_fast_private *uccf;
3349 struct ucc_geth_info *ug_info;
Michael Reiss702ff122007-04-13 01:26:11 -05003350 register u32 ucce;
3351 register u32 uccm;
Li Yangce973b12006-08-14 23:00:11 -07003352
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003353 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003354
Li Yangce973b12006-08-14 23:00:11 -07003355 uccf = ugeth->uccf;
3356 ug_info = ugeth->ug_info;
3357
Michael Reiss702ff122007-04-13 01:26:11 -05003358 /* read and clear events */
3359 ucce = (u32) in_be32(uccf->p_ucce);
3360 uccm = (u32) in_be32(uccf->p_uccm);
3361 ucce &= uccm;
3362 out_be32(uccf->p_ucce, ucce);
Li Yangce973b12006-08-14 23:00:11 -07003363
Michael Reiss702ff122007-04-13 01:26:11 -05003364 /* check for receive events that require processing */
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003365 if (ucce & (UCCE_RX_EVENTS | UCCE_TX_EVENTS)) {
Ben Hutchings288379f2009-01-19 16:43:59 -08003366 if (napi_schedule_prep(&ugeth->napi)) {
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003367 uccm &= ~(UCCE_RX_EVENTS | UCCE_TX_EVENTS);
Michael Reiss702ff122007-04-13 01:26:11 -05003368 out_be32(uccf->p_uccm, uccm);
Ben Hutchings288379f2009-01-19 16:43:59 -08003369 __napi_schedule(&ugeth->napi);
Li Yangce973b12006-08-14 23:00:11 -07003370 }
Michael Reiss702ff122007-04-13 01:26:11 -05003371 }
Li Yangce973b12006-08-14 23:00:11 -07003372
Michael Reiss702ff122007-04-13 01:26:11 -05003373 /* Errors and other events */
3374 if (ucce & UCCE_OTHER) {
Timur Tabi3bc53422009-01-11 00:25:21 -08003375 if (ucce & UCC_GETH_UCCE_BSY)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003376 dev->stats.rx_errors++;
Timur Tabi3bc53422009-01-11 00:25:21 -08003377 if (ucce & UCC_GETH_UCCE_TXE)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003378 dev->stats.tx_errors++;
Li Yangce973b12006-08-14 23:00:11 -07003379 }
Li Yangce973b12006-08-14 23:00:11 -07003380
3381 return IRQ_HANDLED;
3382}
3383
Anton Vorontsov26d29ea2008-02-01 16:22:54 +03003384#ifdef CONFIG_NET_POLL_CONTROLLER
3385/*
3386 * Polling 'interrupt' - used by things like netconsole to send skbs
3387 * without having to re-enable interrupts. It's not called while
3388 * the interrupt routine is executing.
3389 */
3390static void ucc_netpoll(struct net_device *dev)
3391{
3392 struct ucc_geth_private *ugeth = netdev_priv(dev);
3393 int irq = ugeth->ug_info->uf_info.irq;
3394
3395 disable_irq(irq);
3396 ucc_geth_irq_handler(irq, dev);
3397 enable_irq(irq);
3398}
3399#endif /* CONFIG_NET_POLL_CONTROLLER */
3400
Kevin Hao3d6593e2009-05-26 20:49:03 -07003401static int ucc_geth_set_mac_addr(struct net_device *dev, void *p)
3402{
3403 struct ucc_geth_private *ugeth = netdev_priv(dev);
3404 struct sockaddr *addr = p;
3405
3406 if (!is_valid_ether_addr(addr->sa_data))
3407 return -EADDRNOTAVAIL;
3408
3409 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3410
3411 /*
3412 * If device is not running, we will set mac addr register
3413 * when opening the device.
3414 */
3415 if (!netif_running(dev))
3416 return 0;
3417
3418 spin_lock_irq(&ugeth->lock);
3419 init_mac_station_addr_regs(dev->dev_addr[0],
3420 dev->dev_addr[1],
3421 dev->dev_addr[2],
3422 dev->dev_addr[3],
3423 dev->dev_addr[4],
3424 dev->dev_addr[5],
3425 &ugeth->ug_regs->macstnaddr1,
3426 &ugeth->ug_regs->macstnaddr2);
3427 spin_unlock_irq(&ugeth->lock);
3428
3429 return 0;
3430}
3431
Li Yangce973b12006-08-14 23:00:11 -07003432/* Called when something needs to use the ethernet device */
3433/* Returns 0 for success. */
3434static int ucc_geth_open(struct net_device *dev)
3435{
Li Yang18a8e862006-10-19 21:07:34 -05003436 struct ucc_geth_private *ugeth = netdev_priv(dev);
Li Yangce973b12006-08-14 23:00:11 -07003437 int err;
3438
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003439 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003440
3441 /* Test station address */
3442 if (dev->dev_addr[0] & ENET_GROUP_ADDR) {
Li Yang890de952007-07-19 11:48:29 +08003443 if (netif_msg_ifup(ugeth))
3444 ugeth_err("%s: Multicast address used for station address"
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003445 " - is this what you wanted?", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003446 return -EINVAL;
3447 }
3448
Anton Vorontsov79675902009-03-27 16:00:03 -07003449 err = init_phy(dev);
3450 if (err) {
3451 if (netif_msg_ifup(ugeth))
3452 ugeth_err("%s: Cannot initialize PHY, aborting.",
3453 dev->name);
3454 return err;
3455 }
3456
Kim Phillips728de4c92007-04-13 01:26:03 -05003457 err = ucc_struct_init(ugeth);
3458 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003459 if (netif_msg_ifup(ugeth))
3460 ugeth_err("%s: Cannot configure internal struct, aborting.", dev->name);
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00003461 goto out_err_stop;
Kim Phillips728de4c92007-04-13 01:26:03 -05003462 }
3463
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003464 napi_enable(&ugeth->napi);
Francois Romieu1a342d22008-07-11 00:34:40 +02003465
Li Yangce973b12006-08-14 23:00:11 -07003466 err = ucc_geth_startup(ugeth);
3467 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003468 if (netif_msg_ifup(ugeth))
3469 ugeth_err("%s: Cannot configure net device, aborting.",
3470 dev->name);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003471 goto out_err;
Li Yangce973b12006-08-14 23:00:11 -07003472 }
3473
3474 err = adjust_enet_interface(ugeth);
3475 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003476 if (netif_msg_ifup(ugeth))
3477 ugeth_err("%s: Cannot configure net device, aborting.",
3478 dev->name);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003479 goto out_err;
Li Yangce973b12006-08-14 23:00:11 -07003480 }
3481
3482 /* Set MACSTNADDR1, MACSTNADDR2 */
3483 /* For more details see the hardware spec. */
3484 init_mac_station_addr_regs(dev->dev_addr[0],
3485 dev->dev_addr[1],
3486 dev->dev_addr[2],
3487 dev->dev_addr[3],
3488 dev->dev_addr[4],
3489 dev->dev_addr[5],
3490 &ugeth->ug_regs->macstnaddr1,
3491 &ugeth->ug_regs->macstnaddr2);
3492
Kim Phillips728de4c92007-04-13 01:26:03 -05003493 phy_start(ugeth->phydev);
3494
Li Yangce973b12006-08-14 23:00:11 -07003495 err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
3496 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003497 if (netif_msg_ifup(ugeth))
3498 ugeth_err("%s: Cannot enable net device, aborting.", dev->name);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003499 goto out_err;
Li Yangce973b12006-08-14 23:00:11 -07003500 }
3501
Anton Vorontsov67c2fb82008-12-18 08:23:29 +00003502 err = request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler,
3503 0, "UCC Geth", dev);
3504 if (err) {
3505 if (netif_msg_ifup(ugeth))
3506 ugeth_err("%s: Cannot get IRQ for net device, aborting.",
3507 dev->name);
Anton Vorontsov67c2fb82008-12-18 08:23:29 +00003508 goto out_err;
3509 }
3510
Li Yangce973b12006-08-14 23:00:11 -07003511 netif_start_queue(dev);
3512
3513 return err;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003514
3515out_err:
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003516 napi_disable(&ugeth->napi);
Anton Vorontsov3e73fc92008-12-18 08:23:33 +00003517out_err_stop:
Anton Vorontsovba574692008-12-18 08:23:31 +00003518 ucc_geth_stop(ugeth);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003519 return err;
Li Yangce973b12006-08-14 23:00:11 -07003520}
3521
3522/* Stops the kernel queue, and halts the controller */
3523static int ucc_geth_close(struct net_device *dev)
3524{
Li Yang18a8e862006-10-19 21:07:34 -05003525 struct ucc_geth_private *ugeth = netdev_priv(dev);
Li Yangce973b12006-08-14 23:00:11 -07003526
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003527 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003528
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003529 napi_disable(&ugeth->napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003530
Li Yangce973b12006-08-14 23:00:11 -07003531 ucc_geth_stop(ugeth);
3532
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003533 free_irq(ugeth->ug_info->uf_info.irq, ugeth->ndev);
Anton Vorontsov67c2fb82008-12-18 08:23:29 +00003534
Li Yangce973b12006-08-14 23:00:11 -07003535 netif_stop_queue(dev);
3536
3537 return 0;
3538}
3539
Anton Vorontsovfdb614c2008-12-23 06:59:25 +00003540/* Reopen device. This will reset the MAC and PHY. */
3541static void ucc_geth_timeout_work(struct work_struct *work)
3542{
3543 struct ucc_geth_private *ugeth;
3544 struct net_device *dev;
3545
3546 ugeth = container_of(work, struct ucc_geth_private, timeout_work);
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003547 dev = ugeth->ndev;
Anton Vorontsovfdb614c2008-12-23 06:59:25 +00003548
3549 ugeth_vdbg("%s: IN", __func__);
3550
3551 dev->stats.tx_errors++;
3552
3553 ugeth_dump_regs(ugeth);
3554
3555 if (dev->flags & IFF_UP) {
3556 /*
3557 * Must reset MAC *and* PHY. This is done by reopening
3558 * the device.
3559 */
3560 ucc_geth_close(dev);
3561 ucc_geth_open(dev);
3562 }
3563
3564 netif_tx_schedule_all(dev);
3565}
3566
3567/*
3568 * ucc_geth_timeout gets called when a packet has not been
3569 * transmitted after a set amount of time.
3570 */
3571static void ucc_geth_timeout(struct net_device *dev)
3572{
3573 struct ucc_geth_private *ugeth = netdev_priv(dev);
3574
3575 netif_carrier_off(dev);
3576 schedule_work(&ugeth->timeout_work);
3577}
3578
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003579static phy_interface_t to_phy_interface(const char *phy_connection_type)
Kim Phillips728de4c92007-04-13 01:26:03 -05003580{
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003581 if (strcasecmp(phy_connection_type, "mii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003582 return PHY_INTERFACE_MODE_MII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003583 if (strcasecmp(phy_connection_type, "gmii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003584 return PHY_INTERFACE_MODE_GMII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003585 if (strcasecmp(phy_connection_type, "tbi") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003586 return PHY_INTERFACE_MODE_TBI;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003587 if (strcasecmp(phy_connection_type, "rmii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003588 return PHY_INTERFACE_MODE_RMII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003589 if (strcasecmp(phy_connection_type, "rgmii") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003590 return PHY_INTERFACE_MODE_RGMII;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003591 if (strcasecmp(phy_connection_type, "rgmii-id") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003592 return PHY_INTERFACE_MODE_RGMII_ID;
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06003593 if (strcasecmp(phy_connection_type, "rgmii-txid") == 0)
3594 return PHY_INTERFACE_MODE_RGMII_TXID;
3595 if (strcasecmp(phy_connection_type, "rgmii-rxid") == 0)
3596 return PHY_INTERFACE_MODE_RGMII_RXID;
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003597 if (strcasecmp(phy_connection_type, "rtbi") == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003598 return PHY_INTERFACE_MODE_RTBI;
Haiying Wang047584c2009-06-02 04:04:15 +00003599 if (strcasecmp(phy_connection_type, "sgmii") == 0)
3600 return PHY_INTERFACE_MODE_SGMII;
Kim Phillips728de4c92007-04-13 01:26:03 -05003601
3602 return PHY_INTERFACE_MODE_MII;
3603}
3604
Joakim Tjernlunda9dbae72009-03-20 21:09:14 +01003605static const struct net_device_ops ucc_geth_netdev_ops = {
3606 .ndo_open = ucc_geth_open,
3607 .ndo_stop = ucc_geth_close,
3608 .ndo_start_xmit = ucc_geth_start_xmit,
3609 .ndo_validate_addr = eth_validate_addr,
Kevin Hao3d6593e2009-05-26 20:49:03 -07003610 .ndo_set_mac_address = ucc_geth_set_mac_addr,
Joakim Tjernlunda9dbae72009-03-20 21:09:14 +01003611 .ndo_change_mtu = eth_change_mtu,
3612 .ndo_set_multicast_list = ucc_geth_set_multi,
3613 .ndo_tx_timeout = ucc_geth_timeout,
3614#ifdef CONFIG_NET_POLL_CONTROLLER
3615 .ndo_poll_controller = ucc_netpoll,
3616#endif
3617};
3618
Li Yang18a8e862006-10-19 21:07:34 -05003619static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *match)
Li Yangce973b12006-08-14 23:00:11 -07003620{
Li Yang18a8e862006-10-19 21:07:34 -05003621 struct device *device = &ofdev->dev;
3622 struct device_node *np = ofdev->node;
Li Yangce973b12006-08-14 23:00:11 -07003623 struct net_device *dev = NULL;
3624 struct ucc_geth_private *ugeth = NULL;
3625 struct ucc_geth_info *ug_info;
Li Yang18a8e862006-10-19 21:07:34 -05003626 struct resource res;
3627 struct device_node *phy;
Kim Phillips728de4c92007-04-13 01:26:03 -05003628 int err, ucc_num, max_speed = 0;
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003629 const u32 *fixed_link;
Li Yang18a8e862006-10-19 21:07:34 -05003630 const unsigned int *prop;
Timur Tabi9fb1e352007-12-03 15:17:59 -06003631 const char *sprop;
Li Yang9b4c7a42007-02-08 17:35:54 +08003632 const void *mac_addr;
Kim Phillips728de4c92007-04-13 01:26:03 -05003633 phy_interface_t phy_interface;
3634 static const int enet_to_speed[] = {
3635 SPEED_10, SPEED_10, SPEED_10,
3636 SPEED_100, SPEED_100, SPEED_100,
3637 SPEED_1000, SPEED_1000, SPEED_1000, SPEED_1000,
3638 };
3639 static const phy_interface_t enet_to_phy_interface[] = {
3640 PHY_INTERFACE_MODE_MII, PHY_INTERFACE_MODE_RMII,
3641 PHY_INTERFACE_MODE_RGMII, PHY_INTERFACE_MODE_MII,
3642 PHY_INTERFACE_MODE_RMII, PHY_INTERFACE_MODE_RGMII,
3643 PHY_INTERFACE_MODE_GMII, PHY_INTERFACE_MODE_RGMII,
3644 PHY_INTERFACE_MODE_TBI, PHY_INTERFACE_MODE_RTBI,
Haiying Wang047584c2009-06-02 04:04:15 +00003645 PHY_INTERFACE_MODE_SGMII,
Kim Phillips728de4c92007-04-13 01:26:03 -05003646 };
Li Yangce973b12006-08-14 23:00:11 -07003647
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003648 ugeth_vdbg("%s: IN", __func__);
Li Yangce973b12006-08-14 23:00:11 -07003649
Anton Vorontsov56626f32008-04-11 20:06:54 +04003650 prop = of_get_property(np, "cell-index", NULL);
3651 if (!prop) {
3652 prop = of_get_property(np, "device-id", NULL);
3653 if (!prop)
3654 return -ENODEV;
3655 }
3656
Li Yang18a8e862006-10-19 21:07:34 -05003657 ucc_num = *prop - 1;
3658 if ((ucc_num < 0) || (ucc_num > 7))
3659 return -ENODEV;
Li Yangce973b12006-08-14 23:00:11 -07003660
Li Yang18a8e862006-10-19 21:07:34 -05003661 ug_info = &ugeth_info[ucc_num];
Li Yang890de952007-07-19 11:48:29 +08003662 if (ug_info == NULL) {
3663 if (netif_msg_probe(&debug))
3664 ugeth_err("%s: [%d] Missing additional data!",
Harvey Harrisonb39d66a2008-08-20 16:52:04 -07003665 __func__, ucc_num);
Li Yang890de952007-07-19 11:48:29 +08003666 return -ENODEV;
3667 }
3668
Li Yang18a8e862006-10-19 21:07:34 -05003669 ug_info->uf_info.ucc_num = ucc_num;
Kim Phillips728de4c92007-04-13 01:26:03 -05003670
Timur Tabi9fb1e352007-12-03 15:17:59 -06003671 sprop = of_get_property(np, "rx-clock-name", NULL);
3672 if (sprop) {
3673 ug_info->uf_info.rx_clock = qe_clock_source(sprop);
3674 if ((ug_info->uf_info.rx_clock < QE_CLK_NONE) ||
3675 (ug_info->uf_info.rx_clock > QE_CLK24)) {
3676 printk(KERN_ERR
3677 "ucc_geth: invalid rx-clock-name property\n");
3678 return -EINVAL;
3679 }
3680 } else {
3681 prop = of_get_property(np, "rx-clock", NULL);
3682 if (!prop) {
3683 /* If both rx-clock-name and rx-clock are missing,
3684 we want to tell people to use rx-clock-name. */
3685 printk(KERN_ERR
3686 "ucc_geth: missing rx-clock-name property\n");
3687 return -EINVAL;
3688 }
3689 if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
3690 printk(KERN_ERR
3691 "ucc_geth: invalid rx-clock propperty\n");
3692 return -EINVAL;
3693 }
3694 ug_info->uf_info.rx_clock = *prop;
3695 }
3696
3697 sprop = of_get_property(np, "tx-clock-name", NULL);
3698 if (sprop) {
3699 ug_info->uf_info.tx_clock = qe_clock_source(sprop);
3700 if ((ug_info->uf_info.tx_clock < QE_CLK_NONE) ||
3701 (ug_info->uf_info.tx_clock > QE_CLK24)) {
3702 printk(KERN_ERR
3703 "ucc_geth: invalid tx-clock-name property\n");
3704 return -EINVAL;
3705 }
3706 } else {
Joakim Tjernlunde4105532008-04-29 13:03:57 +02003707 prop = of_get_property(np, "tx-clock", NULL);
Timur Tabi9fb1e352007-12-03 15:17:59 -06003708 if (!prop) {
3709 printk(KERN_ERR
3710 "ucc_geth: mising tx-clock-name property\n");
3711 return -EINVAL;
3712 }
3713 if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
3714 printk(KERN_ERR
3715 "ucc_geth: invalid tx-clock property\n");
3716 return -EINVAL;
3717 }
3718 ug_info->uf_info.tx_clock = *prop;
3719 }
3720
Li Yang18a8e862006-10-19 21:07:34 -05003721 err = of_address_to_resource(np, 0, &res);
3722 if (err)
3723 return -EINVAL;
3724
3725 ug_info->uf_info.regs = res.start;
3726 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003727 fixed_link = of_get_property(np, "fixed-link", NULL);
3728 if (fixed_link) {
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003729 phy = NULL;
3730 } else {
Grant Likely0b9da332009-04-25 12:53:23 +00003731 phy = of_parse_phandle(np, "phy-handle", 0);
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003732 if (phy == NULL)
3733 return -ENODEV;
Joakim Tjernlund3d137fd2008-04-11 00:54:43 +02003734 }
Grant Likely0b9da332009-04-25 12:53:23 +00003735 ug_info->phy_node = phy;
Kim Phillips728de4c92007-04-13 01:26:03 -05003736
Haiying Wangfb1001f2009-06-17 13:16:10 +00003737 /* Find the TBI PHY node. If it's not there, we don't support SGMII */
3738 ug_info->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
3739
Kim Phillips728de4c92007-04-13 01:26:03 -05003740 /* get the phy interface type, or default to MII */
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003741 prop = of_get_property(np, "phy-connection-type", NULL);
Kim Phillips728de4c92007-04-13 01:26:03 -05003742 if (!prop) {
3743 /* handle interface property present in old trees */
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003744 prop = of_get_property(phy, "interface", NULL);
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003745 if (prop != NULL) {
Kim Phillips728de4c92007-04-13 01:26:03 -05003746 phy_interface = enet_to_phy_interface[*prop];
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003747 max_speed = enet_to_speed[*prop];
3748 } else
Kim Phillips728de4c92007-04-13 01:26:03 -05003749 phy_interface = PHY_INTERFACE_MODE_MII;
3750 } else {
3751 phy_interface = to_phy_interface((const char *)prop);
3752 }
3753
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003754 /* get speed, or derive from PHY interface */
3755 if (max_speed == 0)
Kim Phillips728de4c92007-04-13 01:26:03 -05003756 switch (phy_interface) {
3757 case PHY_INTERFACE_MODE_GMII:
3758 case PHY_INTERFACE_MODE_RGMII:
3759 case PHY_INTERFACE_MODE_RGMII_ID:
Kim Phillipsbd0ceaa2007-11-26 16:17:58 -06003760 case PHY_INTERFACE_MODE_RGMII_RXID:
3761 case PHY_INTERFACE_MODE_RGMII_TXID:
Kim Phillips728de4c92007-04-13 01:26:03 -05003762 case PHY_INTERFACE_MODE_TBI:
3763 case PHY_INTERFACE_MODE_RTBI:
Haiying Wang047584c2009-06-02 04:04:15 +00003764 case PHY_INTERFACE_MODE_SGMII:
Kim Phillips728de4c92007-04-13 01:26:03 -05003765 max_speed = SPEED_1000;
3766 break;
3767 default:
3768 max_speed = SPEED_100;
3769 break;
3770 }
Kim Phillips728de4c92007-04-13 01:26:03 -05003771
3772 if (max_speed == SPEED_1000) {
Kim Phillips4e19b5c2007-05-11 18:25:07 -05003773 /* configure muram FIFOs for gigabit operation */
Kim Phillips728de4c92007-04-13 01:26:03 -05003774 ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT;
3775 ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT;
3776 ug_info->uf_info.urfset = UCC_GETH_URFSET_GIGA_INIT;
3777 ug_info->uf_info.utfs = UCC_GETH_UTFS_GIGA_INIT;
3778 ug_info->uf_info.utfet = UCC_GETH_UTFET_GIGA_INIT;
3779 ug_info->uf_info.utftt = UCC_GETH_UTFTT_GIGA_INIT;
Joakim Tjernlundffea31e2008-03-06 18:48:46 +08003780 ug_info->numThreadsTx = UCC_GETH_NUM_OF_THREADS_4;
Haiying Wang674e4f92009-05-01 15:40:49 -04003781
3782 /* If QE's snum number is 46 which means we need to support
3783 * 4 UECs at 1000Base-T simultaneously, we need to allocate
3784 * more Threads to Rx.
3785 */
3786 if (qe_get_num_of_snums() == 46)
3787 ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_6;
3788 else
3789 ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_4;
Kim Phillips728de4c92007-04-13 01:26:03 -05003790 }
3791
Li Yang890de952007-07-19 11:48:29 +08003792 if (netif_msg_probe(&debug))
3793 printk(KERN_INFO "ucc_geth: UCC%1d at 0x%8x (irq = %d) \n",
3794 ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs,
3795 ug_info->uf_info.irq);
Li Yangce973b12006-08-14 23:00:11 -07003796
Li Yangce973b12006-08-14 23:00:11 -07003797 /* Create an ethernet device instance */
3798 dev = alloc_etherdev(sizeof(*ugeth));
3799
3800 if (dev == NULL)
3801 return -ENOMEM;
3802
3803 ugeth = netdev_priv(dev);
3804 spin_lock_init(&ugeth->lock);
3805
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03003806 /* Create CQs for hash tables */
3807 INIT_LIST_HEAD(&ugeth->group_hash_q);
3808 INIT_LIST_HEAD(&ugeth->ind_hash_q);
3809
Li Yangce973b12006-08-14 23:00:11 -07003810 dev_set_drvdata(device, dev);
3811
3812 /* Set the dev->base_addr to the gfar reg region */
3813 dev->base_addr = (unsigned long)(ug_info->uf_info.regs);
3814
Li Yangce973b12006-08-14 23:00:11 -07003815 SET_NETDEV_DEV(dev, device);
3816
3817 /* Fill in the dev structure */
Li Yangac421852007-07-19 11:47:47 +08003818 uec_set_ethtool_ops(dev);
Joakim Tjernlunda9dbae72009-03-20 21:09:14 +01003819 dev->netdev_ops = &ucc_geth_netdev_ops;
Li Yangce973b12006-08-14 23:00:11 -07003820 dev->watchdog_timeo = TX_TIMEOUT;
Anton Vorontsov1762a292008-12-18 08:23:26 +00003821 INIT_WORK(&ugeth->timeout_work, ucc_geth_timeout_work);
Joakim Tjernlund0cededf2009-04-17 12:03:48 +00003822 netif_napi_add(dev, &ugeth->napi, ucc_geth_poll, 64);
Li Yangce973b12006-08-14 23:00:11 -07003823 dev->mtu = 1500;
Li Yangce973b12006-08-14 23:00:11 -07003824
Li Yang890de952007-07-19 11:48:29 +08003825 ugeth->msg_enable = netif_msg_init(debug.msg_enable, UGETH_MSG_DEFAULT);
Kim Phillips728de4c92007-04-13 01:26:03 -05003826 ugeth->phy_interface = phy_interface;
3827 ugeth->max_speed = max_speed;
3828
Li Yangce973b12006-08-14 23:00:11 -07003829 err = register_netdev(dev);
3830 if (err) {
Li Yang890de952007-07-19 11:48:29 +08003831 if (netif_msg_probe(ugeth))
3832 ugeth_err("%s: Cannot register net device, aborting.",
3833 dev->name);
Li Yangce973b12006-08-14 23:00:11 -07003834 free_netdev(dev);
3835 return err;
3836 }
3837
Timur Tabie9eb70c2007-02-21 14:40:12 -06003838 mac_addr = of_get_mac_address(np);
Li Yang9b4c7a42007-02-08 17:35:54 +08003839 if (mac_addr)
3840 memcpy(dev->dev_addr, mac_addr, 6);
Li Yangce973b12006-08-14 23:00:11 -07003841
Kim Phillips728de4c92007-04-13 01:26:03 -05003842 ugeth->ug_info = ug_info;
Anton Vorontsovda1aa632009-04-02 01:26:07 -07003843 ugeth->dev = device;
3844 ugeth->ndev = dev;
Haiying Wangb1c4a9dd2009-01-29 17:28:04 -08003845 ugeth->node = np;
Kim Phillips728de4c92007-04-13 01:26:03 -05003846
Li Yangce973b12006-08-14 23:00:11 -07003847 return 0;
3848}
3849
Li Yang18a8e862006-10-19 21:07:34 -05003850static int ucc_geth_remove(struct of_device* ofdev)
Li Yangce973b12006-08-14 23:00:11 -07003851{
Li Yang18a8e862006-10-19 21:07:34 -05003852 struct device *device = &ofdev->dev;
Li Yangce973b12006-08-14 23:00:11 -07003853 struct net_device *dev = dev_get_drvdata(device);
3854 struct ucc_geth_private *ugeth = netdev_priv(dev);
3855
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03003856 unregister_netdev(dev);
Li Yangce973b12006-08-14 23:00:11 -07003857 free_netdev(dev);
Anton Vorontsov80a9fad2008-02-01 16:22:48 +03003858 ucc_geth_memclean(ugeth);
3859 dev_set_drvdata(device, NULL);
Li Yangce973b12006-08-14 23:00:11 -07003860
3861 return 0;
3862}
3863
Li Yang18a8e862006-10-19 21:07:34 -05003864static struct of_device_id ucc_geth_match[] = {
3865 {
3866 .type = "network",
3867 .compatible = "ucc_geth",
3868 },
3869 {},
3870};
3871
3872MODULE_DEVICE_TABLE(of, ucc_geth_match);
3873
3874static struct of_platform_driver ucc_geth_driver = {
3875 .name = DRV_NAME,
3876 .match_table = ucc_geth_match,
3877 .probe = ucc_geth_probe,
3878 .remove = ucc_geth_remove,
Li Yangce973b12006-08-14 23:00:11 -07003879};
3880
3881static int __init ucc_geth_init(void)
3882{
Kim Phillips728de4c92007-04-13 01:26:03 -05003883 int i, ret;
3884
Li Yang890de952007-07-19 11:48:29 +08003885 if (netif_msg_drv(&debug))
3886 printk(KERN_INFO "ucc_geth: " DRV_DESC "\n");
Li Yangce973b12006-08-14 23:00:11 -07003887 for (i = 0; i < 8; i++)
3888 memcpy(&(ugeth_info[i]), &ugeth_primary_info,
3889 sizeof(ugeth_primary_info));
3890
Kim Phillips728de4c92007-04-13 01:26:03 -05003891 ret = of_register_platform_driver(&ucc_geth_driver);
3892
Kim Phillips728de4c92007-04-13 01:26:03 -05003893 return ret;
Li Yangce973b12006-08-14 23:00:11 -07003894}
3895
3896static void __exit ucc_geth_exit(void)
3897{
Kim Phillipsa4f0c2c2006-11-15 12:29:35 -06003898 of_unregister_platform_driver(&ucc_geth_driver);
Li Yangce973b12006-08-14 23:00:11 -07003899}
3900
3901module_init(ucc_geth_init);
3902module_exit(ucc_geth_exit);
3903
3904MODULE_AUTHOR("Freescale Semiconductor, Inc");
3905MODULE_DESCRIPTION(DRV_DESC);
Kim Phillipsc2bcf002007-04-13 01:26:36 -05003906MODULE_VERSION(DRV_VERSION);
Li Yangce973b12006-08-14 23:00:11 -07003907MODULE_LICENSE("GPL");