2 * CFE OS Independent Layer
4 * Copyright (C) 2010, Broadcom Corporation. All Rights Reserved.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * $Id: cfe_osl.c,v 1.22 2009-07-10 22:43:40 Exp $
26 /* Global ASSERT type */
27 uint32 g_assert_type
= 0;
30 osl_attach(void *pdev
)
34 osh
= (osl_t
*)KMALLOC(sizeof(osl_t
), 0);
37 bzero(osh
, sizeof(osl_t
));
43 osl_detach(osl_t
*osh
)
47 KFREE((void*) KERNADDR(PHYSADDR((ulong
)osh
)));
56 ASSERT(len
<= LBDATASZ
);
58 if (!(buf
= KMALLOC(LBUFSZ
, 0)))
61 lb
= (struct lbuf
*) &buf
[LBDATASZ
];
62 bzero(lb
, sizeof(struct lbuf
));
63 lb
->head
= lb
->data
= buf
;
66 lb
->tail
= lb
->data
+ len
;
71 osl_pktfree(osl_t
*osh
, struct lbuf
*lb
, bool send
)
75 if (send
&& osh
->tx_fn
)
76 osh
->tx_fn(osh
->tx_ctx
, lb
, 0);
78 for (; lb
; lb
= next
) {
81 KFREE((void *) KERNADDR(PHYSADDR((ulong
) lb
->head
)));
86 osl_pktdup(struct lbuf
*lb
)
90 if (!(dup
= osl_pktget(lb
->len
)))
93 bcopy(lb
->data
, dup
->data
, lb
->len
);
99 osl_pktsetlen(struct lbuf
*lb
, uint len
)
101 ASSERT((lb
->data
+ len
) <= lb
->end
);
104 lb
->tail
= lb
->data
+ len
;
108 osl_pktpush(struct lbuf
*lb
, uint bytes
)
110 ASSERT((lb
->data
- bytes
) >= lb
->head
);
119 osl_pktpull(struct lbuf
*lb
, uint bytes
)
121 ASSERT((lb
->data
+ bytes
) <= lb
->end
);
122 ASSERT(lb
->len
>= bytes
);
131 osl_dma_alloc_consistent(uint size
, uint16 align_bits
, uint
*alloced
, ulong
*pap
)
134 uint16 align
= (1 << align_bits
);
136 /* fix up the alignment requirements first */
137 if (!ISALIGNED(DMA_CONSISTENT_ALIGN
, align
))
141 if (!(buf
= KMALLOC(size
, DMA_CONSISTENT_ALIGN
)))
144 *((ulong
*) pap
) = PHYSADDR((ulong
) buf
);
146 cfe_flushcache(CFE_CACHE_FLUSH_D
);
148 return (void *) UNCADDR((ulong
) buf
);
152 osl_dma_free_consistent(void *va
)
154 KFREE((void *) KERNADDR(PHYSADDR((ulong
) va
)));
159 osl_assert(char *exp
, char *file
, int line
)
161 printf("assertion \"%s\" failed: file \"%s\", line %d\n", exp
, file
, line
);
164 #endif /* BCMDBG_ASSERT */
167 osl_busprobe(uint32
*val
, uint32 addr
)
169 *val
= R_REG(NULL
, (volatile uint32
*) addr
);
174 /* translate bcmerros */
176 osl_error(int bcmerror
)
184 /* Converts a OS packet to driver packet.
185 * The original packet data is copied to the new driver packet
188 osl_pkt_frmnative(iocb_buffer_t
*buffer
, struct lbuf
*lb
)
190 bcopy(buffer
->buf_ptr
, PKTDATA(NULL
, lb
), buffer
->buf_length
);
193 /* Converts a driver packet into OS packet.
194 * The data is copied to the OS packet
197 osl_pkt_tonative(struct lbuf
* lb
, iocb_buffer_t
*buffer
)
199 bcopy(PKTDATA(NULL
, lb
), buffer
->buf_ptr
, PKTLEN(NULL
, lb
));
200 buffer
->buf_retlen
= PKTLEN(NULL
, lb
);
202 /* RFC894: Minimum length of IP over Ethernet packet is 46 octets */
203 if (buffer
->buf_retlen
< 60) {
204 bzero(buffer
->buf_ptr
+ buffer
->buf_retlen
, 60 - buffer
->buf_retlen
);
205 buffer
->buf_retlen
= 60;