aboutsummaryrefslogtreecommitdiffstats
path: root/shared/cfe_osl.c
blob: b77268b1222f3194840ed6c78e856081695c7285 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * CFE OS Independent Layer
 *
 * Copyright 2007, Broadcom Corporation
 * All Rights Reserved.
 * 
 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
 *
 * $Id: cfe_osl.c,v 1.1.1.1 2008/07/21 09:20:53 james26_jang Exp $
 */

#include <typedefs.h>
#include <bcmdefs.h>
#include <osl.h>

osl_t *
osl_attach(void *pdev)
{
	osl_t *osh;

	osh = (osl_t *)KMALLOC(sizeof(osl_t), 0);
	ASSERT(osh);

	bzero(osh, sizeof(osl_t));
	osh->pdev = pdev;
	return osh;
}

void
osl_detach(osl_t *osh)
{
	if (osh == NULL)
		return;
	KFREE((void*) KERNADDR(PHYSADDR((ulong)osh)));
}

struct lbuf *
osl_pktget(uint len)
{
	uchar *buf;
	struct lbuf *lb;

	ASSERT(len <= LBDATASZ);

	if (!(buf = KMALLOC(LBUFSZ, 0)))
		return NULL;

	lb = (struct lbuf *) &buf[LBDATASZ];
	bzero(lb, sizeof(struct lbuf));
	lb->head = lb->data = buf;
	lb->end = buf + len;
	lb->len = len;
	lb->tail = lb->data + len;
	return lb;
}

void
osl_pktfree(osl_t *osh, struct lbuf *lb, bool send)
{
	struct lbuf *next;

	if (send && osh->tx_fn)
		osh->tx_fn(osh->tx_ctx, lb, 0);

	for (; lb; lb = next) {
		ASSERT(!lb->link);
		next = lb->next;
		KFREE((void *) KERNADDR(PHYSADDR((ulong) lb->head)));
	}
}

struct lbuf *
osl_pktdup(struct lbuf *lb)
{
	struct lbuf *dup;

	if (!(dup = osl_pktget(lb->len)))
		return NULL;

	bcopy(lb->data, dup->data, lb->len);
	ASSERT(!lb->link);
	return dup;
}

void
osl_pktsetlen(struct lbuf *lb, uint len)
{
	ASSERT((lb->data + len) <= lb->end);

	lb->len = len;
	lb->tail = lb->data + len;
}

uchar *
osl_pktpush(struct lbuf *lb, uint bytes)
{
	ASSERT((lb->data - bytes) >= lb->head);

	lb->data -= bytes;
	lb->len += bytes;

	return lb->data;
}

uchar *
osl_pktpull(struct lbuf *lb, uint bytes)
{
	ASSERT((lb->data + bytes) <= lb->end);
	ASSERT(lb->len >= bytes);

	lb->data += bytes;
	lb->len -= bytes;

	return lb->data;
}

void *
osl_dma_alloc_consistent(uint size, ulong *pap)
{
	void *buf;

	if (!(buf = KMALLOC(size, DMA_CONSISTENT_ALIGN)))
		return NULL;

	*((ulong *) pap) = PHYSADDR((ulong) buf);

	cfe_flushcache(CFE_CACHE_FLUSH_D);

	return (void *) UNCADDR((ulong) buf);
}

void
osl_dma_free_consistent(void *va)
{
	KFREE((void *) KERNADDR(PHYSADDR((ulong) va)));
}

#ifdef BCMDBG_ASSERT
void
osl_assert(char *exp, char *file, int line)
{
	printf("assertion \"%s\" failed: file \"%s\", line %d\n", exp, file, line);
	*((int *) 0) = 0;
}
#endif /* BCMDBG_ASSERT */

int
osl_busprobe(uint32 *val, uint32 addr)
{
	*val = R_REG(NULL, (volatile uint32 *) addr);

	return 0;
}

/* translate bcmerros */
int
osl_error(int bcmerror)
{
	if (bcmerror)
		return -1;
	else
		return 0;
}

/* Converts a OS packet to driver packet.
 * The original packet data is copied to the new driver packet
 */
void
osl_pkt_frmnative(iocb_buffer_t *buffer, struct lbuf *lb)
{
	bcopy(buffer->buf_ptr, PKTDATA(NULL, lb), buffer->buf_length);
}

/* Converts a driver packet into OS packet.
 * The data is copied to the OS packet
 */
void
osl_pkt_tonative(struct lbuf* lb, iocb_buffer_t *buffer)
{
	bcopy(PKTDATA(NULL, lb), buffer->buf_ptr, PKTLEN(NULL, lb));
	buffer->buf_retlen = PKTLEN(NULL, lb);

	/* RFC894: Minimum length of IP over Ethernet packet is 46 octets */
	if (buffer->buf_retlen < 60) {
		bzero(buffer->buf_ptr + buffer->buf_retlen, 60 - buffer->buf_retlen);
		buffer->buf_retlen = 60;
	}
}
bues.ch cgit interface