2 * CFE OS Independent Layer
4 * Copyright 2004, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
20 osl_attach(void *pdev
)
24 osh
= (osl_t
*)KMALLOC(sizeof(osl_t
), 0);
27 bzero(osh
, sizeof(osl_t
));
33 osl_detach(osl_t
*osh
)
37 KFREE((void*) KERNADDR(PHYSADDR((ulong
)osh
)));
46 ASSERT(len
<= LBDATASZ
);
48 if (!(buf
= KMALLOC(LBUFSZ
, 0)))
51 lb
= (struct lbuf
*) &buf
[LBDATASZ
];
52 bzero(lb
, sizeof(struct lbuf
));
53 lb
->head
= lb
->data
= buf
;
56 lb
->tail
= lb
->data
+ len
;
62 osl_pktfree(osl_t
*osh
, struct lbuf
*lb
, bool send
)
66 if (send
&& osh
->tx_fn
)
67 osh
->tx_fn(osh
->tx_ctx
, lb
, 0);
69 for (; lb
; lb
= next
) {
72 KFREE((void *) KERNADDR(PHYSADDR((ulong
) lb
->head
)));
77 osl_pktdup(struct lbuf
*lb
)
81 if (!(dup
= osl_pktget(lb
->len
)))
84 bcopy(lb
->data
, dup
->data
, lb
->len
);
91 osl_pktsetlen(struct lbuf
*lb
, uint len
)
93 ASSERT((lb
->data
+ len
) <= lb
->end
);
96 lb
->tail
= lb
->data
+ len
;
100 osl_pktpush(struct lbuf
*lb
, uint bytes
)
102 ASSERT((lb
->data
- bytes
) >= lb
->head
);
111 osl_pktpull(struct lbuf
*lb
, uint bytes
)
113 ASSERT((lb
->data
+ bytes
) <= lb
->end
);
114 ASSERT(lb
->len
>= bytes
);
123 osl_dma_alloc_consistent(uint size
, ulong
*pap
)
127 if (!(buf
= KMALLOC(size
, DMA_CONSISTENT_ALIGN
)))
130 *((ulong
*) pap
) = PHYSADDR((ulong
) buf
);
132 cfe_flushcache(CFE_CACHE_FLUSH_D
);
134 return (void *) UNCADDR((ulong
) buf
);
138 osl_dma_free_consistent(void *va
)
140 KFREE((void *) KERNADDR(PHYSADDR((ulong
) va
)));
145 osl_assert(char *exp
, char *file
, int line
)
147 printf("assertion \"%s\" failed: file \"%s\", line %d\n", exp
, file
, line
);
150 #endif /* BCMDBG_ASSERT */
153 osl_busprobe(uint32
*val
, uint32 addr
)
155 *val
= R_REG(NULL
, (volatile uint32
*) addr
);
160 /* translate bcmerros */
162 osl_error(int bcmerror
)
170 /* Converts a OS packet to driver packet.
171 * The original packet data is copied to the new driver packet
174 osl_pkt_frmnative(iocb_buffer_t
*buffer
, struct lbuf
*lb
)
176 bcopy(buffer
->buf_ptr
, PKTDATA(NULL
, lb
), buffer
->buf_length
);
179 /* Converts a driver packet into OS packet.
180 * The data is copied to the OS packet
183 osl_pkt_tonative(struct lbuf
* lb
, iocb_buffer_t
*buffer
)
185 bcopy(PKTDATA(NULL
, lb
), buffer
->buf_ptr
, PKTLEN(NULL
, lb
));
186 buffer
->buf_retlen
= PKTLEN(NULL
, lb
);
188 /* RFC894: Minimum length of IP over Ethernet packet is 46 octets */
189 if (buffer
->buf_retlen
< 60) {
190 bzero(buffer
->buf_ptr
+ buffer
->buf_retlen
, 60 - buffer
->buf_retlen
);
191 buffer
->buf_retlen
= 60;