blob: 03e3bf7c168077d1e7c101227fb5730454cfab34 [file] [log] [blame]
Wolfgang Denkba94a1b2006-05-30 15:56:48 +02001/*
2 * (C) Copyright 2005-2006
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#if 0
25#define DEBUG /* define for debug output */
26#endif
27
28#include <config.h>
29#include <common.h>
30#include <net.h>
31#include <miiphy.h>
32#include <malloc.h>
33#include <asm/processor.h>
34#include <asm/arch-ixp/ixp425.h>
35
36#include <IxOsal.h>
37#include <IxEthAcc.h>
38#include <IxEthDB.h>
39#include <IxNpeDl.h>
40#include <IxQMgr.h>
41#include <IxNpeMh.h>
42#include <ix_ossl.h>
43#include <IxFeatureCtrl.h>
44
45#include <npe.h>
46
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020047static IxQMgrDispatcherFuncPtr qDispatcherFunc = NULL;
48static int npe_exists[NPE_NUM_PORTS];
49static int npe_used[NPE_NUM_PORTS];
50
51/* A little extra so we can align to cacheline. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020052static u8 npe_alloc_pool[NPE_MEM_POOL_SIZE + CONFIG_SYS_CACHELINE_SIZE - 1];
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020053static u8 *npe_alloc_end;
54static u8 *npe_alloc_free;
55
56static void *npe_alloc(int size)
57{
58 static int count = 0;
59 void *p = NULL;
60
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020061 size = (size + (CONFIG_SYS_CACHELINE_SIZE-1)) & ~(CONFIG_SYS_CACHELINE_SIZE-1);
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020062 count++;
63
64 if ((npe_alloc_free + size) < npe_alloc_end) {
65 p = npe_alloc_free;
66 npe_alloc_free += size;
67 } else {
Wolfgang Denk25dbe982008-07-13 23:07:35 +020068 printf("npe_alloc: failed (count=%d, size=%d)!\n", count, size);
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020069 }
70 return p;
71}
72
73/* Not interrupt safe! */
74static void mbuf_enqueue(IX_OSAL_MBUF **q, IX_OSAL_MBUF *new)
75{
76 IX_OSAL_MBUF *m = *q;
77
78 IX_OSAL_MBUF_NEXT_PKT_IN_CHAIN_PTR(new) = NULL;
79
80 if (m) {
81 while(IX_OSAL_MBUF_NEXT_PKT_IN_CHAIN_PTR(m))
82 m = IX_OSAL_MBUF_NEXT_PKT_IN_CHAIN_PTR(m);
83 IX_OSAL_MBUF_NEXT_PKT_IN_CHAIN_PTR(m) = new;
84 } else
85 *q = new;
86}
87
88/* Not interrupt safe! */
89static IX_OSAL_MBUF *mbuf_dequeue(IX_OSAL_MBUF **q)
90{
91 IX_OSAL_MBUF *m = *q;
92 if (m)
93 *q = IX_OSAL_MBUF_NEXT_PKT_IN_CHAIN_PTR(m);
94 return m;
95}
96
97static void reset_tx_mbufs(struct npe* p_npe)
98{
99 IX_OSAL_MBUF *m;
100 int i;
101
102 p_npe->txQHead = NULL;
103
104 for (i = 0; i < CONFIG_DEVS_ETH_INTEL_NPE_MAX_TX_DESCRIPTORS; i++) {
105 m = &p_npe->tx_mbufs[i];
106
107 memset(m, 0, sizeof(*m));
108
109 IX_OSAL_MBUF_MDATA(m) = (void *)&p_npe->tx_pkts[i * NPE_PKT_SIZE];
110 IX_OSAL_MBUF_MLEN(m) = IX_OSAL_MBUF_PKT_LEN(m) = NPE_PKT_SIZE;
111 mbuf_enqueue(&p_npe->txQHead, m);
112 }
113}
114
115static void reset_rx_mbufs(struct npe* p_npe)
116{
117 IX_OSAL_MBUF *m;
118 int i;
119
120 p_npe->rxQHead = NULL;
121
122 HAL_DCACHE_INVALIDATE(p_npe->rx_pkts, NPE_PKT_SIZE *
123 CONFIG_DEVS_ETH_INTEL_NPE_MAX_RX_DESCRIPTORS);
124
125 for (i = 0; i < CONFIG_DEVS_ETH_INTEL_NPE_MAX_RX_DESCRIPTORS; i++) {
126 m = &p_npe->rx_mbufs[i];
127
128 memset(m, 0, sizeof(*m));
129
130 IX_OSAL_MBUF_MDATA(m) = (void *)&p_npe->rx_pkts[i * NPE_PKT_SIZE];
131 IX_OSAL_MBUF_MLEN(m) = IX_OSAL_MBUF_PKT_LEN(m) = NPE_PKT_SIZE;
132
133 if(ixEthAccPortRxFreeReplenish(p_npe->eth_id, m) != IX_SUCCESS) {
134 printf("ixEthAccPortRxFreeReplenish failed for port %d\n", p_npe->eth_id);
135 break;
136 }
137 }
138}
139
140static void init_rx_mbufs(struct npe* p_npe)
141{
142 p_npe->rxQHead = NULL;
143
144 p_npe->rx_pkts = npe_alloc(NPE_PKT_SIZE *
145 CONFIG_DEVS_ETH_INTEL_NPE_MAX_RX_DESCRIPTORS);
146 if (p_npe->rx_pkts == NULL) {
147 printf("alloc of packets failed.\n");
148 return;
149 }
150
151 p_npe->rx_mbufs = (IX_OSAL_MBUF *)
152 npe_alloc(sizeof(IX_OSAL_MBUF) *
153 CONFIG_DEVS_ETH_INTEL_NPE_MAX_RX_DESCRIPTORS);
154 if (p_npe->rx_mbufs == NULL) {
155 printf("alloc of mbufs failed.\n");
156 return;
157 }
158
159 reset_rx_mbufs(p_npe);
160}
161
162static void init_tx_mbufs(struct npe* p_npe)
163{
164 p_npe->tx_pkts = npe_alloc(NPE_PKT_SIZE *
165 CONFIG_DEVS_ETH_INTEL_NPE_MAX_TX_DESCRIPTORS);
166 if (p_npe->tx_pkts == NULL) {
167 printf("alloc of packets failed.\n");
168 return;
169 }
170
171 p_npe->tx_mbufs = (IX_OSAL_MBUF *)
172 npe_alloc(sizeof(IX_OSAL_MBUF) *
173 CONFIG_DEVS_ETH_INTEL_NPE_MAX_TX_DESCRIPTORS);
174 if (p_npe->tx_mbufs == NULL) {
175 printf("alloc of mbufs failed.\n");
176 return;
177 }
178
179 reset_tx_mbufs(p_npe);
180}
181
182/* Convert IX_ETH_PORT_n to IX_NPEMH_NPEID_NPEx */
183static int __eth_to_npe(int eth_id)
184{
185 switch(eth_id) {
186 case IX_ETH_PORT_1:
187 return IX_NPEMH_NPEID_NPEB;
188
189 case IX_ETH_PORT_2:
190 return IX_NPEMH_NPEID_NPEC;
191
192 case IX_ETH_PORT_3:
193 return IX_NPEMH_NPEID_NPEA;
194 }
195 return 0;
196}
197
198/* Poll the CSR machinery. */
199static void npe_poll(int eth_id)
200{
201 if (qDispatcherFunc != NULL) {
202 ixNpeMhMessagesReceive(__eth_to_npe(eth_id));
203 (*qDispatcherFunc)(IX_QMGR_QUELOW_GROUP);
204 }
205}
206
207/* ethAcc RX callback */
208static void npe_rx_callback(u32 cbTag, IX_OSAL_MBUF *m, IxEthAccPortId portid)
209{
210 struct npe* p_npe = (struct npe *)cbTag;
211
212 if (IX_OSAL_MBUF_MLEN(m) > 0) {
213 mbuf_enqueue(&p_npe->rxQHead, m);
214
215 if (p_npe->rx_write == ((p_npe->rx_read-1) & (PKTBUFSRX-1))) {
216 debug("Rx overflow: rx_write=%d rx_read=%d\n",
217 p_npe->rx_write, p_npe->rx_read);
218 } else {
219 debug("Received message #%d (len=%d)\n", p_npe->rx_write,
220 IX_OSAL_MBUF_MLEN(m));
221 memcpy((void *)NetRxPackets[p_npe->rx_write], IX_OSAL_MBUF_MDATA(m),
222 IX_OSAL_MBUF_MLEN(m));
223 p_npe->rx_len[p_npe->rx_write] = IX_OSAL_MBUF_MLEN(m);
224 p_npe->rx_write++;
225 if (p_npe->rx_write == PKTBUFSRX)
226 p_npe->rx_write = 0;
227
228#ifdef CONFIG_PRINT_RX_FRAMES
229 {
230 u8 *ptr = IX_OSAL_MBUF_MDATA(m);
231 int i;
232
233 for (i=0; i<60; i++) {
234 debug("%02x ", *ptr++);
235 }
236 debug("\n");
237 }
238#endif
239 }
240
241 m = mbuf_dequeue(&p_npe->rxQHead);
242 } else {
243 debug("Received frame with length 0!!!\n");
244 m = mbuf_dequeue(&p_npe->rxQHead);
245 }
246
247 /* Now return mbuf to NPE */
248 IX_OSAL_MBUF_MLEN(m) = IX_OSAL_MBUF_PKT_LEN(m) = NPE_PKT_SIZE;
249 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR(m) = NULL;
250 IX_OSAL_MBUF_FLAGS(m) = 0;
251
252 if(ixEthAccPortRxFreeReplenish(p_npe->eth_id, m) != IX_SUCCESS) {
253 debug("npe_rx_callback: Error returning mbuf.\n");
254 }
255}
256
257/* ethAcc TX callback */
258static void npe_tx_callback(u32 cbTag, IX_OSAL_MBUF *m)
259{
260 struct npe* p_npe = (struct npe *)cbTag;
261
262 debug("%s\n", __FUNCTION__);
263
264 IX_OSAL_MBUF_MLEN(m) = IX_OSAL_MBUF_PKT_LEN(m) = NPE_PKT_SIZE;
265 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR(m) = NULL;
266 IX_OSAL_MBUF_FLAGS(m) = 0;
267
268 mbuf_enqueue(&p_npe->txQHead, m);
269}
270
271
272static int npe_set_mac_address(struct eth_device *dev)
273{
274 struct npe *p_npe = (struct npe *)dev->priv;
275 IxEthAccMacAddr npeMac;
276
277 debug("%s\n", __FUNCTION__);
278
279 /* Set MAC address */
280 memcpy(npeMac.macAddress, dev->enetaddr, 6);
281
282 if (ixEthAccPortUnicastMacAddressSet(p_npe->eth_id, &npeMac) != IX_ETH_ACC_SUCCESS) {
283 printf("Error setting unicast address! %02x:%02x:%02x:%02x:%02x:%02x\n",
284 npeMac.macAddress[0], npeMac.macAddress[1],
285 npeMac.macAddress[2], npeMac.macAddress[3],
286 npeMac.macAddress[4], npeMac.macAddress[5]);
287 return 0;
288 }
289
290 return 1;
291}
292
293/* Boot-time CSR library initialization. */
294static int npe_csr_load(void)
295{
296 int i;
297
298 if (ixQMgrInit() != IX_SUCCESS) {
299 debug("Error initialising queue manager!\n");
300 return 0;
301 }
302
303 ixQMgrDispatcherLoopGet(&qDispatcherFunc);
304
305 if(ixNpeMhInitialize(IX_NPEMH_NPEINTERRUPTS_YES) != IX_SUCCESS) {
306 printf("Error initialising NPE Message handler!\n");
307 return 0;
308 }
309
310 if (npe_used[IX_ETH_PORT_1] && npe_exists[IX_ETH_PORT_1] &&
311 ixNpeDlNpeInitAndStart(IX_NPEDL_NPEIMAGE_NPEB_ETH_LEARN_FILTER_SPAN_FIREWALL_VLAN_QOS)
312 != IX_SUCCESS) {
313 printf("Error downloading firmware to NPE-B!\n");
314 return 0;
315 }
316
317 if (npe_used[IX_ETH_PORT_2] && npe_exists[IX_ETH_PORT_2] &&
318 ixNpeDlNpeInitAndStart(IX_NPEDL_NPEIMAGE_NPEC_ETH_LEARN_FILTER_SPAN_FIREWALL_VLAN_QOS)
319 != IX_SUCCESS) {
320 printf("Error downloading firmware to NPE-C!\n");
321 return 0;
322 }
323
324 /* don't need this for U-Boot */
325 ixFeatureCtrlSwConfigurationWrite(IX_FEATURECTRL_ETH_LEARNING, FALSE);
326
327 if (ixEthAccInit() != IX_ETH_ACC_SUCCESS) {
328 printf("Error initialising Ethernet access driver!\n");
329 return 0;
330 }
331
332 for (i = 0; i < IX_ETH_ACC_NUMBER_OF_PORTS; i++) {
333 if (!npe_used[i] || !npe_exists[i])
334 continue;
335 if (ixEthAccPortInit(i) != IX_ETH_ACC_SUCCESS) {
336 printf("Error initialising Ethernet port%d!\n", i);
337 }
338 if (ixEthAccTxSchedulingDisciplineSet(i, FIFO_NO_PRIORITY) != IX_ETH_ACC_SUCCESS) {
339 printf("Error setting scheduling discipline for port %d.\n", i);
340 }
341 if (ixEthAccPortRxFrameAppendFCSDisable(i) != IX_ETH_ACC_SUCCESS) {
342 printf("Error disabling RX FCS for port %d.\n", i);
343 }
344 if (ixEthAccPortTxFrameAppendFCSEnable(i) != IX_ETH_ACC_SUCCESS) {
345 printf("Error enabling TX FCS for port %d.\n", i);
346 }
347 }
348
349 return 1;
350}
351
352static int npe_init(struct eth_device *dev, bd_t * bis)
353{
354 struct npe *p_npe = (struct npe *)dev->priv;
355 int i;
356 u16 reg_short;
357 int speed;
358 int duplex;
359
360 debug("%s: 1\n", __FUNCTION__);
361
362 miiphy_read (dev->name, p_npe->phy_no, PHY_BMSR, &reg_short);
363
364 /*
365 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
366 */
367 if ((reg_short & PHY_BMSR_AUTN_ABLE) && !(reg_short & PHY_BMSR_AUTN_COMP)) {
368 puts ("Waiting for PHY auto negotiation to complete");
369 i = 0;
370 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
371 /*
372 * Timeout reached ?
373 */
374 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
375 puts (" TIMEOUT !\n");
376 break;
377 }
378
379 if ((i++ % 1000) == 0) {
380 putc ('.');
381 miiphy_read (dev->name, p_npe->phy_no, PHY_BMSR, &reg_short);
382 }
383 udelay (1000); /* 1 ms */
384 }
385 puts (" done\n");
386 udelay (500000); /* another 500 ms (results in faster booting) */
387 }
388
389 speed = miiphy_speed (dev->name, p_npe->phy_no);
390 duplex = miiphy_duplex (dev->name, p_npe->phy_no);
391
392 if (p_npe->print_speed) {
393 p_npe->print_speed = 0;
394 printf ("ENET Speed is %d Mbps - %s duplex connection\n",
395 (int) speed, (duplex == HALF) ? "HALF" : "FULL");
396 }
397
398 npe_alloc_end = npe_alloc_pool + sizeof(npe_alloc_pool);
399 npe_alloc_free = (u8 *)(((unsigned)npe_alloc_pool +
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200400 CONFIG_SYS_CACHELINE_SIZE - 1) & ~(CONFIG_SYS_CACHELINE_SIZE - 1));
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200401
402 /* initialize mbuf pool */
403 init_rx_mbufs(p_npe);
404 init_tx_mbufs(p_npe);
405
406 if (ixEthAccPortRxCallbackRegister(p_npe->eth_id, npe_rx_callback,
407 (u32)p_npe) != IX_ETH_ACC_SUCCESS) {
408 printf("can't register RX callback!\n");
Ben Warren422b1a02008-01-09 18:15:53 -0500409 return -1;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200410 }
411
412 if (ixEthAccPortTxDoneCallbackRegister(p_npe->eth_id, npe_tx_callback,
413 (u32)p_npe) != IX_ETH_ACC_SUCCESS) {
414 printf("can't register TX callback!\n");
Ben Warren422b1a02008-01-09 18:15:53 -0500415 return -1;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200416 }
417
418 npe_set_mac_address(dev);
419
420 if (ixEthAccPortEnable(p_npe->eth_id) != IX_ETH_ACC_SUCCESS) {
421 printf("can't enable port!\n");
Ben Warren422b1a02008-01-09 18:15:53 -0500422 return -1;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200423 }
424
425 p_npe->active = 1;
426
Ben Warren422b1a02008-01-09 18:15:53 -0500427 return 0;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200428}
429
430#if 0 /* test-only: probably have to deal with it when booting linux (for a clean state) */
431/* Uninitialize CSR library. */
432static void npe_csr_unload(void)
433{
434 ixEthAccUnload();
435 ixEthDBUnload();
436 ixNpeMhUnload();
437 ixQMgrUnload();
438}
439
440/* callback which is used by ethAcc to recover RX buffers when stopping */
441static void npe_rx_stop_callback(u32 cbTag, IX_OSAL_MBUF *m, IxEthAccPortId portid)
442{
443 debug("%s\n", __FUNCTION__);
444}
445
446/* callback which is used by ethAcc to recover TX buffers when stopping */
447static void npe_tx_stop_callback(u32 cbTag, IX_OSAL_MBUF *m)
448{
449 debug("%s\n", __FUNCTION__);
450}
451#endif
452
453static void npe_halt(struct eth_device *dev)
454{
455 struct npe *p_npe = (struct npe *)dev->priv;
456 int i;
457
458 debug("%s\n", __FUNCTION__);
459
460 /* Delay to give time for recovery of mbufs */
461 for (i = 0; i < 100; i++) {
462 npe_poll(p_npe->eth_id);
463 udelay(100);
464 }
465
466#if 0 /* test-only: probably have to deal with it when booting linux (for a clean state) */
467 if (ixEthAccPortRxCallbackRegister(p_npe->eth_id, npe_rx_stop_callback,
468 (u32)p_npe) != IX_ETH_ACC_SUCCESS) {
469 debug("Error registering rx callback!\n");
470 }
471
472 if (ixEthAccPortTxDoneCallbackRegister(p_npe->eth_id, npe_tx_stop_callback,
473 (u32)p_npe) != IX_ETH_ACC_SUCCESS) {
474 debug("Error registering tx callback!\n");
475 }
476
477 if (ixEthAccPortDisable(p_npe->eth_id) != IX_ETH_ACC_SUCCESS) {
478 debug("npe_stop: Error disabling NPEB!\n");
479 }
480
481 /* Delay to give time for recovery of mbufs */
482 for (i = 0; i < 100; i++) {
483 npe_poll(p_npe->eth_id);
484 udelay(10000);
485 }
486
487 /*
488 * For U-Boot only, we are probably launching Linux or other OS that
489 * needs a clean slate for its NPE library.
490 */
491#if 0 /* test-only */
492 for (i = 0; i < IX_ETH_ACC_NUMBER_OF_PORTS; i++) {
493 if (npe_used[i] && npe_exists[i])
494 if (ixNpeDlNpeStopAndReset(__eth_to_npe(i)) != IX_SUCCESS)
495 printf("Failed to stop and reset NPE B.\n");
496 }
497#endif
498
499#endif
500 p_npe->active = 0;
501}
502
503
504static int npe_send(struct eth_device *dev, volatile void *packet, int len)
505{
506 struct npe *p_npe = (struct npe *)dev->priv;
507 u8 *dest;
508 int err;
509 IX_OSAL_MBUF *m;
510
511 debug("%s\n", __FUNCTION__);
512 m = mbuf_dequeue(&p_npe->txQHead);
513 dest = IX_OSAL_MBUF_MDATA(m);
514 IX_OSAL_MBUF_PKT_LEN(m) = IX_OSAL_MBUF_MLEN(m) = len;
515 IX_OSAL_MBUF_NEXT_PKT_IN_CHAIN_PTR(m) = NULL;
516
517 memcpy(dest, (char *)packet, len);
518
519 if ((err = ixEthAccPortTxFrameSubmit(p_npe->eth_id, m, IX_ETH_ACC_TX_DEFAULT_PRIORITY))
520 != IX_ETH_ACC_SUCCESS) {
521 printf("npe_send: Can't submit frame. err[%d]\n", err);
522 mbuf_enqueue(&p_npe->txQHead, m);
523 return 0;
524 }
525
526#ifdef DEBUG_PRINT_TX_FRAMES
527 {
528 u8 *ptr = IX_OSAL_MBUF_MDATA(m);
529 int i;
530
531 for (i=0; i<IX_OSAL_MBUF_MLEN(m); i++) {
532 printf("%02x ", *ptr++);
533 }
534 printf(" (tx-len=%d)\n", IX_OSAL_MBUF_MLEN(m));
535 }
536#endif
537
538 npe_poll(p_npe->eth_id);
539
540 return len;
541}
542
543static int npe_rx(struct eth_device *dev)
544{
545 struct npe *p_npe = (struct npe *)dev->priv;
546
547 debug("%s\n", __FUNCTION__);
548 npe_poll(p_npe->eth_id);
549
550 debug("%s: rx_write=%d rx_read=%d\n", __FUNCTION__, p_npe->rx_write, p_npe->rx_read);
551 while (p_npe->rx_write != p_npe->rx_read) {
552 debug("Reading message #%d\n", p_npe->rx_read);
553 NetReceive(NetRxPackets[p_npe->rx_read], p_npe->rx_len[p_npe->rx_read]);
554 p_npe->rx_read++;
555 if (p_npe->rx_read == PKTBUFSRX)
556 p_npe->rx_read = 0;
557 }
558
559 return 0;
560}
561
562int npe_initialize(bd_t * bis)
563{
564 static int virgin = 0;
565 struct eth_device *dev;
566 int eth_num = 0;
567 struct npe *p_npe = NULL;
568
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200569 for (eth_num = 0; eth_num < CONFIG_SYS_NPE_NUMS; eth_num++) {
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200570
571 /* See if we can actually bring up the interface, otherwise, skip it */
572 switch (eth_num) {
573 default: /* fall through */
574 case 0:
575 if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
576 continue;
577 }
578 break;
579#ifdef CONFIG_HAS_ETH1
580 case 1:
581 if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) {
582 continue;
583 }
584 break;
585#endif
586 }
587
588 /* Allocate device structure */
589 dev = (struct eth_device *)malloc(sizeof(*dev));
590 if (dev == NULL) {
591 printf ("%s: Cannot allocate eth_device %d\n", __FUNCTION__, eth_num);
592 return -1;
593 }
594 memset(dev, 0, sizeof(*dev));
595
596 /* Allocate our private use data */
597 p_npe = (struct npe *)malloc(sizeof(struct npe));
598 if (p_npe == NULL) {
599 printf("%s: Cannot allocate private hw data for eth_device %d",
600 __FUNCTION__, eth_num);
601 free(dev);
602 return -1;
603 }
604 memset(p_npe, 0, sizeof(struct npe));
605
606 switch (eth_num) {
607 default: /* fall through */
608 case 0:
609 memcpy(dev->enetaddr, bis->bi_enetaddr, 6);
610 p_npe->eth_id = 0;
611 p_npe->phy_no = CONFIG_PHY_ADDR;
612 break;
613
614#ifdef CONFIG_HAS_ETH1
615 case 1:
616 memcpy(dev->enetaddr, bis->bi_enet1addr, 6);
617 p_npe->eth_id = 1;
618 p_npe->phy_no = CONFIG_PHY1_ADDR;
619 break;
620#endif
621 }
622
623 sprintf(dev->name, "NPE%d", eth_num);
624 dev->priv = (void *)p_npe;
625 dev->init = npe_init;
626 dev->halt = npe_halt;
627 dev->send = npe_send;
628 dev->recv = npe_rx;
629
630 p_npe->print_speed = 1;
631
632 if (0 == virgin) {
633 virgin = 1;
634
635 if (ixFeatureCtrlDeviceRead() == IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X) {
636 switch (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK) {
637 case IX_FEATURE_CTRL_SILICON_TYPE_B0:
638 /*
639 * If it is B0 Silicon, we only enable port when its corresponding
640 * Eth Coprocessor is available.
641 */
642 if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) ==
643 IX_FEATURE_CTRL_COMPONENT_ENABLED)
644 npe_exists[IX_ETH_PORT_1] = TRUE;
645
646 if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH1) ==
647 IX_FEATURE_CTRL_COMPONENT_ENABLED)
648 npe_exists[IX_ETH_PORT_2] = TRUE;
649 break;
650 case IX_FEATURE_CTRL_SILICON_TYPE_A0:
651 /*
652 * If it is A0 Silicon, we enable both as both Eth Coprocessors
653 * are available.
654 */
655 npe_exists[IX_ETH_PORT_1] = TRUE;
656 npe_exists[IX_ETH_PORT_2] = TRUE;
657 break;
658 }
659 } else if (ixFeatureCtrlDeviceRead() == IX_FEATURE_CTRL_DEVICE_TYPE_IXP46X) {
660 if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) ==
661 IX_FEATURE_CTRL_COMPONENT_ENABLED)
662 npe_exists[IX_ETH_PORT_1] = TRUE;
663
664 if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH1) ==
665 IX_FEATURE_CTRL_COMPONENT_ENABLED)
666 npe_exists[IX_ETH_PORT_2] = TRUE;
667 }
668
669 npe_used[IX_ETH_PORT_1] = 1;
670 npe_used[IX_ETH_PORT_2] = 1;
671
672 npe_alloc_end = npe_alloc_pool + sizeof(npe_alloc_pool);
673 npe_alloc_free = (u8 *)(((unsigned)npe_alloc_pool +
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200674 CONFIG_SYS_CACHELINE_SIZE - 1)
675 & ~(CONFIG_SYS_CACHELINE_SIZE - 1));
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200676
677 if (!npe_csr_load())
678 return 0;
679 }
680
681 eth_register(dev);
682
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500683#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200684 miiphy_register(dev->name, npe_miiphy_read, npe_miiphy_write);
685#endif
686
687 } /* end for each supported device */
688
689 return 1;
690}