10 #include "uip_netif.h"
16 #define BBA_MINPKTSIZE 60
18 #define BBA_CID 0x04020200
20 #define BBA_CMD_IRMASKALL 0x00
21 #define BBA_CMD_IRMASKNONE 0xF8
23 #define BBA_NCRA 0x00 /* Network Control Register A, RW */
24 #define BBA_NCRA_RESET (1<<0) /* RESET */
25 #define BBA_NCRA_ST0 (1<<1) /* ST0, Start transmit command/status */
26 #define BBA_NCRA_ST1 (1<<2) /* ST1, " */
27 #define BBA_NCRA_SR (1<<3) /* SR, Start Receive */
29 #define BBA_NCRB 0x01 /* Network Control Register B, RW */
30 #define BBA_NCRB_PR (1<<0) /* PR, Promiscuous Mode */
31 #define BBA_NCRB_CA (1<<1) /* CA, Capture Effect Mode */
32 #define BBA_NCRB_PM (1<<2) /* PM, Pass Multicast */
33 #define BBA_NCRB_PB (1<<3) /* PB, Pass Bad Frame */
34 #define BBA_NCRB_AB (1<<4) /* AB, Accept Broadcast */
35 #define BBA_NCRB_HBD (1<<5) /* HBD, reserved */
36 #define BBA_NCRB_RXINTC0 (1<<6) /* RXINTC, Receive Interrupt Counter */
37 #define BBA_NCRB_RXINTC1 (1<<7) /* " */
38 #define BBA_NCRB_1_PACKET_PER_INT (0<<6) /* 0 0 */
39 #define BBA_NCRB_2_PACKETS_PER_INT (1<<6) /* 0 1 */
40 #define BBA_NCRB_4_PACKETS_PER_INT (2<<6) /* 1 0 */
41 #define BBA_NCRB_8_PACKETS_PER_INT (3<<6) /* 1 1 */
43 #define BBA_LTPS 0x04 /* Last Transmitted Packet Status, RO */
44 #define BBA_LRPS 0x05 /* Last Received Packet Status, RO */
46 #define BBA_IMR 0x08 /* Interrupt Mask Register, RW, 00h */
47 #define BBA_IMR_FRAGIM (1<<0) /* FRAGIM, Fragment Counter Int Mask */
48 #define BBA_IMR_RIM (1<<1) /* RIM, Receive Interrupt Mask */
49 #define BBA_IMR_TIM (1<<2) /* TIM, Transmit Interrupt Mask */
50 #define BBA_IMR_REIM (1<<3) /* REIM, Receive Error Interrupt Mask */
51 #define BBA_IMR_TEIM (1<<4) /* TEIM, Transmit Error Interrupt Mask */
52 #define BBA_IMR_FIFOEIM (1<<5) /* FIFOEIM, FIFO Error Interrupt Mask */
53 #define BBA_IMR_BUSEIM (1<<6) /* BUSEIM, BUS Error Interrupt Mask */
54 #define BBA_IMR_RBFIM (1<<7) /* RBFIM, RX Buffer Full Interrupt Mask */
56 #define BBA_IR 0x09 /* Interrupt Register, RW, 00h */
57 #define BBA_IR_FRAGI (1<<0) /* FRAGI, Fragment Counter Interrupt */
58 #define BBA_IR_RI (1<<1) /* RI, Receive Interrupt */
59 #define BBA_IR_TI (1<<2) /* TI, Transmit Interrupt */
60 #define BBA_IR_REI (1<<3) /* REI, Receive Error Interrupt */
61 #define BBA_IR_TEI (1<<4) /* TEI, Transmit Error Interrupt */
62 #define BBA_IR_FIFOEI (1<<5) /* FIFOEI, FIFO Error Interrupt */
63 #define BBA_IR_BUSEI (1<<6) /* BUSEI, BUS Error Interrupt */
64 #define BBA_IR_RBFI (1<<7) /* RBFI, RX Buffer Full Interrupt */
66 #define BBA_BP 0x0a/*+0x0b*/ /* Boundary Page Pointer Register */
67 #define BBA_TLBP 0x0c/*+0x0d*/ /* TX Low Boundary Page Pointer Register */
68 #define BBA_TWP 0x0e/*+0x0f*/ /* Transmit Buffer Write Page Pointer Register */
69 #define BBA_TRP 0x12/*+0x13*/ /* Transmit Buffer Read Page Pointer Register */
70 #define BBA_RWP 0x16/*+0x17*/ /* Receive Buffer Write Page Pointer Register */
71 #define BBA_RRP 0x18/*+0x19*/ /* Receive Buffer Read Page Pointer Register */
72 #define BBA_RHBP 0x1a/*+0x1b*/ /* Receive High Boundary Page Pointer Register */
74 #define BBA_RXINTT 0x14/*+0x15*/ /* Receive Interrupt Timer Register */
76 #define BBA_NAFR_PAR0 0x20 /* Physical Address Register Byte 0 */
77 #define BBA_NAFR_PAR1 0x21 /* Physical Address Register Byte 1 */
78 #define BBA_NAFR_PAR2 0x22 /* Physical Address Register Byte 2 */
79 #define BBA_NAFR_PAR3 0x23 /* Physical Address Register Byte 3 */
80 #define BBA_NAFR_PAR4 0x24 /* Physical Address Register Byte 4 */
81 #define BBA_NAFR_PAR5 0x25 /* Physical Address Register Byte 5 */
83 #define BBA_NWAYC 0x30 /* NWAY Configuration Register, RW, 84h */
84 #define BBA_NWAYC_FD (1<<0) /* FD, Full Duplex Mode */
85 #define BBA_NWAYC_PS100 (1<<1) /* PS100/10, Port Select 100/10 */
86 #define BBA_NWAYC_ANE (1<<2) /* ANE, Autonegotiation Enable */
87 #define BBA_NWAYC_ANS_RA (1<<3) /* ANS, Restart Autonegotiation */
88 #define BBA_NWAYC_LTE (1<<7) /* LTE, Link Test Enable */
90 #define BBA_NWAYS 0x31
91 #define BBA_NWAYS_LS10 (1<<0)
92 #define BBA_NWAYS_LS100 (1<<1)
93 #define BBA_NWAYS_LPNWAY (1<<2)
94 #define BBA_NWAYS_ANCLPT (1<<3)
95 #define BBA_NWAYS_100TXF (1<<4)
96 #define BBA_NWAYS_100TXH (1<<5)
97 #define BBA_NWAYS_10TXF (1<<6)
98 #define BBA_NWAYS_10TXH (1<<7)
100 #define BBA_GCA 0x32 /* GMAC Configuration A Register, RW, 00h */
101 #define BBA_GCA_ARXERRB (1<<3) /* ARXERRB, Accept RX packet with error */
103 #define BBA_MISC 0x3d /* MISC Control Register 1, RW, 3ch */
104 #define BBA_MISC_BURSTDMA (1<<0)
105 #define BBA_MISC_DISLDMA (1<<1)
107 #define BBA_TXFIFOCNT 0x3e/*0x3f*/ /* Transmit FIFO Counter Register */
108 #define BBA_WRTXFIFOD 0x48/*-0x4b*/ /* Write TX FIFO Data Port Register */
110 #define BBA_MISC2 0x50 /* MISC Control Register 2, RW, 00h */
111 #define BBA_MISC2_HBRLEN0 (1<<0) /* HBRLEN, Host Burst Read Length */
112 #define BBA_MISC2_HBRLEN1 (1<<1) /* " */
113 #define BBA_MISC2_RUNTSIZE (1<<2) /* " */
114 #define BBA_MISC2_DREQBCTRL (1<<3) /* " */
115 #define BBA_MISC2_RINTSEL (1<<4) /* " */
116 #define BBA_MISC2_ITPSEL (3<<5) /* " */
117 #define BBA_MISC2_AUTORCVR (1<<7) /* Auto RX Full Recovery */
119 #define BBA_RX_STATUS_BF (1<<0)
120 #define BBA_RX_STATUS_CRC (1<<1)
121 #define BBA_RX_STATUS_FAE (1<<2)
122 #define BBA_RX_STATUS_FO (1<<3)
123 #define BBA_RX_STATUS_RW (1<<4)
124 #define BBA_RX_STATUS_MF (1<<5)
125 #define BBA_RX_STATUS_RF (1<<6)
126 #define BBA_RX_STATUS_RERR (1<<7)
128 #define BBA_TX_STATUS_CC0 (1<<0)
129 #define BBA_TX_STATUS_CC1 (1<<1)
130 #define BBA_TX_STATUS_CC2 (1<<2)
131 #define BBA_TX_STATUS_CC3 (1<<3)
132 #define BBA_TX_STATUS_CCMASK (0x0f)
133 #define BBA_TX_STATUS_CRSLOST (1<<4)
134 #define BBA_TX_STATUS_UF (1<<5)
135 #define BBA_TX_STATUS_OWC (1<<6)
136 #define BBA_TX_STATUS_OWN (1<<7)
137 #define BBA_TX_STATUS_TERR (1<<7)
139 #define BBA_TX_MAX_PACKET_SIZE 1518 /* 14+1500+4 */
140 #define BBA_RX_MAX_PACKET_SIZE 1536 /* 6 pages * 256 bytes */
142 #define BBA_INIT_TLBP 0x00
143 #define BBA_INIT_BP 0x01
144 #define BBA_INIT_RHBP 0x0f
145 #define BBA_INIT_RWP BBA_INIT_BP
146 #define BBA_INIT_RRP BBA_INIT_BP
148 #define BBA_NAPI_WEIGHT 16
150 #define RX_BUFFERS 16
152 #define cpu_to_be16(x) (x)
153 #define cpu_to_be32(x) (x)
154 static inline u16
cpu_to_le16(u16 x
) { return (x
<<8) | (x
>>8);}
155 static inline u32
cpu_to_le32(u32 x
) { return((x
>>24) | ((x
>>8)&0xff00) | ((x
<<8)&0xff0000) | (x
<<24));}
157 #define cpu_to_le16p(addr) (cpu_to_le16(*(addr)))
158 #define cpu_to_le32p(addr) (cpu_to_le32(*(addr)))
159 #define cpu_to_be16p(addr) (cpu_to_be16(*(addr)))
160 #define cpu_to_be32p(addr) (cpu_to_be32(*(addr)))
162 static inline void cpu_to_le16s(u16
*a
) {*a
= cpu_to_le16(*a
);}
163 static inline void cpu_to_le32s(u32
*a
) {*a
= cpu_to_le32(*a
);}
164 static inline void cpu_to_be16s(u16
*a
) {*a
= cpu_to_be16(*a
);}
165 static inline void cpu_to_be32s(u32
*a
) {*a
= cpu_to_be32(*a
);}
167 #define le16_to_cpup(x) cpu_to_le16p(x)
168 #define le32_to_cpup(x) cpu_to_le32p(x)
169 #define be16_to_cpup(x) cpu_to_be16p(x)
170 #define be32_to_cpup(x) cpu_to_be32p(x)
172 #define le16_to_cpus(x) cpu_to_le16s(x)
173 #define le32_to_cpus(x) cpu_to_le32s(x)
174 #define be16_to_cpus(x) cpu_to_be16s(x)
175 #define be32_to_cpus(x) cpu_to_be32s(x)
182 struct uip_eth_addr
*ethaddr
;
187 u32
X(X(next_packet_ptr
:12, packet_len
:12), status
:8);
188 } __attribute((packed
));
190 #define _SHIFTL(v, s, w) \
191 ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
192 #define _SHIFTR(v, s, w) \
193 ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))
196 #define bba_select() EXI_Select(EXI_CHANNEL_0,EXI_DEVICE_2,EXI_SPEED32MHZ)
197 #define bba_deselect() EXI_Deselect(EXI_CHANNEL_0)
199 #define bba_in12(reg) ((bba_in8(reg)&0xff)|((bba_in8((reg)+1)&0x0f)<<8))
200 #define bba_out12(reg,val) do { \
201 bba_out8((reg),(val)&0xff); \
202 bba_out8((reg)+1,((val)&0x0f00)>>8); \
207 #define UIP_LOG(m) uip_log(__FILE__,__LINE__,m)
210 #endif /* UIP_LOGGING == 1 */
212 #if UIP_STATISTICS == 1
213 struct uip_stats uip_stat
;
214 #define UIP_STAT(s) s
217 #endif /* UIP_STATISTICS == 1 */
219 static s64 bba_arp_tmr
= 0;
221 static struct uip_pbuf
*bba_recv_pbufs
= NULL
;
222 static struct uip_netif
*bba_netif
= NULL
;
223 static struct bba_priv bba_device
;
224 static struct bba_descr cur_descr
;
226 static void bba_cmd_ins(u32 reg
,void *val
,u32 len
);
227 static void bba_cmd_outs(u32 reg
,void *val
,u32 len
);
228 static void bba_ins(u32 reg
,void *val
,u32 len
);
229 static void bba_outs(u32 reg
,void *val
,u32 len
);
231 static void bba_devpoll(u16
*pstatus
);
233 extern void udelay(int us
);
234 extern u32
diff_msec(long long start
,long long end
);
235 extern u32
diff_usec(long long start
,long long end
);
236 extern long long gettime();
238 static __inline__
void bba_cmd_insnosel(u32 reg
,void *val
,u32 len
)
242 EXI_Imm(EXI_CHANNEL_0
,&req
,sizeof(req
),EXI_WRITE
,NULL
);
243 EXI_Sync(EXI_CHANNEL_0
);
244 EXI_ImmEx(EXI_CHANNEL_0
,val
,len
,EXI_READ
);
247 static void bba_cmd_ins(u32 reg
,void *val
,u32 len
)
250 bba_cmd_insnosel(reg
,val
,len
);
254 static __inline__
void bba_cmd_outsnosel(u32 reg
,void *val
,u32 len
)
257 req
= (reg
<<8)|0x4000;
258 EXI_Imm(EXI_CHANNEL_0
,&req
,sizeof(req
),EXI_WRITE
,NULL
);
259 EXI_Sync(EXI_CHANNEL_0
);
260 EXI_ImmEx(EXI_CHANNEL_0
,val
,len
,EXI_WRITE
);
263 static void bba_cmd_outs(u32 reg
,void *val
,u32 len
)
266 bba_cmd_outsnosel(reg
,val
,len
);
270 static inline u8
bba_cmd_in8(u32 reg
)
273 bba_cmd_ins(reg
,&val
,sizeof(val
));
277 static inline u8
bba_cmd_in8_slow(u32 reg
)
281 bba_cmd_insnosel(reg
,&val
,sizeof(val
));
282 udelay(200); //usleep doesn't work on this amount, decrementer is based on 10ms, wait is 200us
287 static inline void bba_cmd_out8(u32 reg
,u8 val
)
289 bba_cmd_outs(reg
,&val
,sizeof(val
));
292 static inline u8
bba_in8(u32 reg
)
295 bba_ins(reg
,&val
,sizeof(val
));
299 static inline void bba_out8(u32 reg
,u8 val
)
301 bba_outs(reg
,&val
,sizeof(val
));
304 static inline void bba_insnosel(u32 reg
,void *val
,u32 len
)
307 req
= (reg
<<8)|0x80000000;
308 EXI_Imm(EXI_CHANNEL_0
,&req
,sizeof(req
),EXI_WRITE
,NULL
);
309 EXI_Sync(EXI_CHANNEL_0
);
310 EXI_ImmEx(EXI_CHANNEL_0
,val
,len
,EXI_READ
);
313 static void bba_ins(u32 reg
,void *val
,u32 len
)
316 bba_insnosel(reg
,val
,len
);
320 static inline void bba_outsnoselect(u32 reg
,void *val
,u32 len
)
323 req
= (reg
<<8)|0xC0000000;
324 EXI_Imm(EXI_CHANNEL_0
,&req
,sizeof(req
),EXI_WRITE
,NULL
);
325 EXI_Sync(EXI_CHANNEL_0
);
326 EXI_ImmEx(EXI_CHANNEL_0
,val
,len
,EXI_WRITE
);
329 static void bba_outs(u32 reg
,void *val
,u32 len
)
332 bba_outsnoselect(reg
,val
,len
);
336 static inline void bba_insregister(u32 reg
)
339 req
= (reg
<<8)|0x80000000;
340 EXI_Imm(EXI_CHANNEL_0
,&req
,sizeof(req
),EXI_WRITE
,NULL
);
341 EXI_Sync(EXI_CHANNEL_0
);
344 static inline void bba_insdata(void *val
,u32 len
)
346 EXI_ImmEx(EXI_CHANNEL_0
,val
,len
,EXI_READ
);
350 static inline void bba_outsregister(u32 reg
)
353 req
= (reg
<<8)|0xC0000000;
354 EXI_Imm(EXI_CHANNEL_0
,&req
,sizeof(req
),EXI_WRITE
,NULL
);
355 EXI_Sync(EXI_CHANNEL_0
);
358 static inline void bba_outsdata(void *val
,u32 len
)
360 EXI_ImmEx(EXI_CHANNEL_0
,val
,len
,EXI_WRITE
);
363 static __inline__ u32
__linkstate()
367 nways
= bba_in8(BBA_NWAYS
);
368 if(nways
&BBA_NWAYS_LS10
|| nways
&BBA_NWAYS_LS100
) return 1;
372 static u32
__bba_getlink_state_async()
377 if(EXI_Lock(EXI_CHANNEL_0
,EXI_DEVICE_2
,NULL
)==0) return 0;
379 EXI_Unlock(EXI_CHANNEL_0
);
384 static u32
__bba_read_cid()
390 EXI_Imm(EXI_CHANNEL_0
,&cmd
,2,EXI_WRITE
,NULL
);
391 EXI_Sync(EXI_CHANNEL_0
);
392 EXI_Imm(EXI_CHANNEL_0
,&cid
,4,EXI_READ
,NULL
);
393 EXI_Sync(EXI_CHANNEL_0
);
398 static void __bba_reset()
402 bba_cmd_in8_slow(0x0F);
404 bba_out8(BBA_NCRA
,BBA_NCRA_RESET
);
405 bba_out8(BBA_NCRA
,0x00);
408 static void __bba_recv_init()
410 bba_out8(BBA_NCRB
,(BBA_NCRB_CA
|BBA_NCRB_AB
));
411 bba_out8(BBA_MISC2
,(BBA_MISC2_AUTORCVR
));
413 bba_out12(BBA_TLBP
, BBA_INIT_TLBP
);
414 bba_out12(BBA_BP
,BBA_INIT_BP
);
415 bba_out12(BBA_RWP
,BBA_INIT_RWP
);
416 bba_out12(BBA_RRP
,BBA_INIT_RRP
);
417 bba_out12(BBA_RHBP
,BBA_INIT_RHBP
);
419 bba_out8(BBA_GCA
,BBA_GCA_ARXERRB
);
420 bba_out8(BBA_NCRA
,BBA_NCRA_SR
);
423 static void bba_process(struct uip_pbuf
*p
,struct uip_netif
*dev
)
425 struct uip_eth_hdr
*ethhdr
= NULL
;
426 struct bba_priv
*priv
= (struct bba_priv
*)dev
->state
;
427 const s32 ethhlen
= sizeof(struct uip_eth_hdr
);
431 switch(htons(ethhdr
->type
)) {
434 uip_pbuf_header(p
,-(ethhlen
));
437 case UIP_ETHTYPE_ARP
:
438 uip_arp_arpin(dev
,priv
->ethaddr
,p
);
447 static s8_t
bba_start_rx(struct uip_netif
*dev
,u32 budget
)
451 u32 pkt_status
,recvd
;
452 struct uip_pbuf
*p
,*q
;
454 UIP_LOG("bba_start_rx()\n");
457 rwp
= bba_in12(BBA_RWP
);
458 rrp
= bba_in12(BBA_RRP
);
459 while(recvd
<budget
&& rrp
!=rwp
) {
460 bba_ins(rrp
<<8,(void*)(&cur_descr
),sizeof(struct bba_descr
));
461 le32_to_cpus((u32
*)((void*)(&cur_descr
)));
463 size
= cur_descr
.packet_len
- 4;
464 pkt_status
= cur_descr
.status
;
465 if(size
>(BBA_RX_MAX_PACKET_SIZE
+4)) {
466 UIP_LOG("bba_start_rx: packet dropped due to big buffer.\n");
470 if(pkt_status
&(BBA_RX_STATUS_RERR
|BBA_RX_STATUS_FAE
)) {
471 UIP_LOG("bba_start_rx: packet dropped due to receive errors.\n");
472 rwp
= bba_in12(BBA_RWP
);
473 rrp
= bba_in12(BBA_RRP
);
478 top
= (BBA_INIT_RHBP
+1)<<8;
480 p
= uip_pbuf_alloc(UIP_PBUF_RAW
,size
,UIP_PBUF_POOL
);
482 for(q
=p
;q
!=NULL
;q
=q
->next
) {
484 bba_insregister(pos
);
486 bba_insdata(q
->payload
,size
);
491 pos
= BBA_INIT_RRP
<<8;
492 bba_insdata(q
->payload
,chunk
);
496 bba_insregister(pos
);
497 bba_insdata(q
->payload
+chunk
,size
);
503 EXI_Unlock(EXI_CHANNEL_0
);
505 EXI_Lock(EXI_CHANNEL_0
,EXI_DEVICE_2
,NULL
);
511 bba_out12(BBA_RRP
,(rrp
=cur_descr
.next_packet_ptr
));
512 rwp
= bba_in12(BBA_RWP
);
517 static inline void bba_interrupt(u16
*pstatus
)
521 ir
= bba_in8(BBA_IR
);
522 imr
= bba_in8(BBA_IMR
);
525 if(status
&BBA_IR_FRAGI
) {
526 bba_out8(BBA_IR
,BBA_IR_FRAGI
);
528 if(status
&BBA_IR_RI
) {
529 bba_start_rx(bba_netif
,0x10);
530 bba_out8(BBA_IR
,BBA_IR_RI
);
532 if(status
&BBA_IR_REI
) {
533 bba_out8(BBA_IR
,BBA_IR_REI
);
535 if(status
&BBA_IR_TI
) {
536 bba_out8(BBA_IR
,BBA_IR_TI
);
538 if(status
&BBA_IR_TEI
) {
539 bba_out8(BBA_IR
,BBA_IR_TEI
);
541 if(status
&BBA_IR_FIFOEI
) {
542 bba_out8(BBA_IR
,BBA_IR_FIFOEI
);
544 if(status
&BBA_IR_BUSEI
) {
545 bba_out8(BBA_IR
,BBA_IR_BUSEI
);
547 if(status
&BBA_IR_RBFI
) {
548 bba_start_rx(bba_netif
,0x10);
549 bba_out8(BBA_IR
,BBA_IR_RBFI
);
554 static s8_t
bba_dochallengeresponse()
559 UIP_LOG("bba_dochallengeresponse()\n");
560 /* as we do not have interrupts we've to poll the irqs */
564 bba_devpoll(&status
);
565 if(status
==0x1000) cnt
= 0;
566 } while(cnt
<100 && !(status
&0x0800));
568 if(cnt
>=1000) return UIP_ERR_IF
;
572 static s8_t
__bba_init(struct uip_netif
*dev
)
574 struct bba_priv
*priv
= (struct bba_priv
*)dev
->state
;
575 if(!priv
) return UIP_ERR_IF
;
579 priv
->revid
= bba_cmd_in8(0x01);
581 bba_cmd_outs(0x04,&priv
->devid
,2);
582 bba_cmd_out8(0x05,priv
->acstart
);
584 bba_out8(0x5b, (bba_in8(0x5b)&~0x80));
585 bba_out8(0x5e, 0x01);
586 bba_out8(0x5c, (bba_in8(0x5c)|0x04));
590 bba_ins(BBA_NAFR_PAR0
,priv
->ethaddr
->addr
, 6);
592 bba_out8(BBA_IR
,0xFF);
593 bba_out8(BBA_IMR
,0xFF&~BBA_IMR_FIFOEIM
);
595 bba_cmd_out8(0x02,BBA_CMD_IRMASKNONE
);
600 static s8_t
bba_init_one(struct uip_netif
*dev
)
603 struct bba_priv
*priv
= (struct bba_priv
*)dev
->state
;
605 if(!priv
) return UIP_ERR_IF
;
608 priv
->devid
= 0xD107;
609 priv
->acstart
= 0x4E;
611 ret
= __bba_init(dev
);
616 static s8_t
bba_probe(struct uip_netif
*dev
)
621 if(EXI_Lock(EXI_CHANNEL_0
,EXI_DEVICE_2
,NULL
)==0) return -1;
623 cid
= __bba_read_cid();
625 EXI_Unlock(EXI_CHANNEL_0
);
629 ret
= bba_init_one(dev
);
631 EXI_Unlock(EXI_CHANNEL_0
);
635 static u32
bba_calc_response(struct uip_netif
*dev
,u32 val
)
637 u8 revid_0
, revid_eth_0
, revid_eth_1
;
638 struct bba_priv
*priv
= (struct bba_priv
*)dev
->state
;
640 UIP_LOG("bba_calc_response()\n");
642 revid_0
= priv
->revid
;
643 revid_eth_0
= _SHIFTR(priv
->devid
,8,8);
644 revid_eth_1
= priv
->devid
&0xff;
647 i0
= (val
& 0xff000000) >> 24;
648 i1
= (val
& 0x00ff0000) >> 16;
649 i2
= (val
& 0x0000ff00) >> 8;
650 i3
= (val
& 0x000000ff);
653 c0
= ((i0
+ i1
* 0xc1 + 0x18 + revid_0
) ^ (i3
* i2
+ 0x90)
655 c1
= ((i1
+ i2
+ 0x90) ^ (c0
+ i0
- 0xc1)
657 c2
= ((i2
+ 0xc8) ^ (c0
+ ((revid_eth_0
+ revid_0
* 0x23) ^ 0x19))
659 c3
= ((i0
+ 0xc1) ^ (i3
+ ((revid_eth_1
+ 0xc8) ^ 0x90))
662 return ((c0
<< 24) | (c1
<< 16) | (c2
<< 8) | c3
);
665 static void bba_devpoll(u16
*pstatus
)
670 UIP_LOG("bba_devpoll()\n");
673 if(diff_msec(bba_arp_tmr
,now
)>=UIP_ARP_TMRINTERVAL
) {
675 bba_arp_tmr
= gettime();
680 if(EXI_Lock(EXI_CHANNEL_0
,EXI_DEVICE_2
,NULL
)==1) {
681 status
= bba_cmd_in8(0x03);
683 bba_cmd_out8(0x02,BBA_CMD_IRMASKALL
);
685 *pstatus
|= (status
<<8);
686 bba_interrupt(pstatus
);
687 bba_cmd_out8(0x03,0x80);
688 bba_cmd_out8(0x02,BBA_CMD_IRMASKNONE
);
689 EXI_Unlock(EXI_CHANNEL_0
);
693 *pstatus
|= (status
<<8);
694 __bba_init(bba_netif
);
695 bba_cmd_out8(0x03, 0x40);
696 bba_cmd_out8(0x02,BBA_CMD_IRMASKNONE
);
697 EXI_Unlock(EXI_CHANNEL_0
);
701 *pstatus
|= (status
<<8);
702 bba_cmd_out8(0x03, 0x20);
703 bba_cmd_out8(0x02,BBA_CMD_IRMASKNONE
);
704 EXI_Unlock(EXI_CHANNEL_0
);
708 u32 response
,challange
;
710 *pstatus
|= (status
<<8);
711 bba_cmd_out8(0x05,bba_device
.acstart
);
712 bba_cmd_ins(0x08,&challange
,sizeof(challange
));
713 response
= bba_calc_response(bba_netif
,challange
);
714 bba_cmd_outs(0x09,&response
,sizeof(response
));
715 bba_cmd_out8(0x03, 0x10);
716 bba_cmd_out8(0x02,BBA_CMD_IRMASKNONE
);
717 EXI_Unlock(EXI_CHANNEL_0
);
721 *pstatus
|= (status
<<8);
722 bba_cmd_out8(0x03, 0x08);
723 bba_cmd_out8(0x02,BBA_CMD_IRMASKNONE
);
724 EXI_Unlock(EXI_CHANNEL_0
);
728 *pstatus
|= (status
<<8);
729 bba_interrupt(pstatus
);
730 bba_cmd_out8(0x02,BBA_CMD_IRMASKNONE
);
732 EXI_Unlock(EXI_CHANNEL_0
);
736 static s8_t
__bba_start_tx(struct uip_netif
*dev
,struct uip_pbuf
*p
,struct uip_ip_addr
*ipaddr
)
738 return uip_arp_out(dev
,ipaddr
,p
);
741 static s8_t
__bba_link_tx(struct uip_netif
*dev
,struct uip_pbuf
*p
)
745 struct uip_pbuf
*tmp
;
747 if(EXI_Lock(EXI_CHANNEL_0
,EXI_DEVICE_2
,NULL
)==0) return UIP_ERR_IF
;
749 if(p
->tot_len
>BBA_TX_MAX_PACKET_SIZE
) {
750 UIP_LOG("__bba_link_tx: packet dropped due to big buffer.\n");
751 EXI_Unlock(EXI_CHANNEL_0
);
752 return UIP_ERR_PKTSIZE
;
756 EXI_Unlock(EXI_CHANNEL_0
);
760 while((bba_in8(BBA_NCRA
)&(BBA_NCRA_ST0
|BBA_NCRA_ST1
)));
763 bba_out12(BBA_TXFIFOCNT
,len
);
766 bba_outsregister(BBA_WRTXFIFOD
);
767 for(tmp
=p
;tmp
!=NULL
;tmp
=tmp
->next
) {
768 bba_outsdata(tmp
->payload
,tmp
->len
);
770 if(len
<BBA_MINPKTSIZE
) {
771 len
= (BBA_MINPKTSIZE
-len
);
772 bba_outsdata(pad
,len
);
776 bba_out8(BBA_NCRA
,((bba_in8(BBA_NCRA
)&~BBA_NCRA_ST0
)|BBA_NCRA_ST1
)); //&~BBA_NCRA_ST0
777 EXI_Unlock(EXI_CHANNEL_0
);
781 s8_t
uip_bba_init(struct uip_netif
*dev
)
786 ret
= bba_probe(dev
);
787 if(ret
<0) return ret
;
789 ret
= bba_dochallengeresponse();
790 if(ret
<0) return ret
;
796 } while((ret
=__bba_getlink_state_async())==0 && cnt
<10000);
797 if(!ret
) return UIP_ERR_IF
;
799 dev
->flags
|= UIP_NETIF_FLAG_LINK_UP
;
800 uip_netif_setup(dev
);
803 bba_recv_pbufs
= NULL
;
804 bba_arp_tmr
= gettime();
809 uipdev_s
uip_bba_create(struct uip_netif
*dev
)
811 dev
->name
[0] = IFNAME0
;
812 dev
->name
[1] = IFNAME1
;
814 dev
->output
= __bba_start_tx
;
815 dev
->linkoutput
= __bba_link_tx
;
817 dev
->flags
= UIP_NETIF_FLAG_BROADCAST
;
820 bba_device
.ethaddr
= (struct uip_eth_addr
*)dev
->hwaddr
;
821 bba_device
.state
= UIP_ERR_OK
;
827 void uip_bba_poll(struct uip_netif
*dev
)
831 UIP_LOG("uip_bba_poll()\n");
833 bba_devpoll(&status
);