Commit | Line | Data |
---|---|---|
a6e960e7 | 1 | /* if_uba.c 6.2 84/08/29 */ |
961945a8 SL |
2 | |
3 | #include "../machine/pte.h" | |
0468e5fa | 4 | |
a6e960e7 JB |
5 | #include "param.h" |
6 | #include "systm.h" | |
7 | #include "mbuf.h" | |
8 | #include "map.h" | |
9 | #include "buf.h" | |
10 | #include "cmap.h" | |
11 | #include "vmmac.h" | |
12 | #include "socket.h" | |
eaa60542 | 13 | |
8a13b737 | 14 | #include "../net/if.h" |
eaa60542 BJ |
15 | |
16 | #include "../vax/mtpr.h" | |
a6e960e7 | 17 | #include "if_uba.h" |
eaa60542 BJ |
18 | #include "../vaxuba/ubareg.h" |
19 | #include "../vaxuba/ubavar.h" | |
0468e5fa BJ |
20 | |
21 | /* | |
22 | * Routines supporting UNIBUS network interfaces. | |
23 | * | |
24 | * TODO: | |
25 | * Support interfaces using only one BDP statically. | |
26 | */ | |
27 | ||
28 | /* | |
29 | * Init UNIBUS for interface on uban whose headers of size hlen are to | |
30 | * end on a page boundary. We allocate a UNIBUS map register for the page | |
31 | * with the header, and nmr more UNIBUS map registers for i/o on the adapter, | |
32 | * doing this twice: once for reading and once for writing. We also | |
33 | * allocate page frames in the mbuffer pool for these pages. | |
34 | */ | |
35 | if_ubainit(ifu, uban, hlen, nmr) | |
36 | register struct ifuba *ifu; | |
37 | int uban, hlen, nmr; | |
38 | { | |
97da2a42 BJ |
39 | register caddr_t cp; |
40 | int i, ncl; | |
0468e5fa | 41 | |
97da2a42 | 42 | ncl = clrnd(nmr + CLSIZE) / CLSIZE; |
176c481f BJ |
43 | if (ifu->ifu_r.ifrw_addr) |
44 | cp = ifu->ifu_r.ifrw_addr - (CLBYTES - hlen); | |
45 | else { | |
46 | cp = m_clalloc(2 * ncl, MPG_SPACE); | |
47 | if (cp == 0) | |
48 | return (0); | |
49 | ifu->ifu_r.ifrw_addr = cp + CLBYTES - hlen; | |
50 | ifu->ifu_w.ifrw_addr = ifu->ifu_r.ifrw_addr + ncl * CLBYTES; | |
51 | ifu->ifu_hlen = hlen; | |
52 | ifu->ifu_uban = uban; | |
53 | ifu->ifu_uba = uba_hd[uban].uh_uba; | |
54 | } | |
b454c3ea | 55 | if (if_ubaalloc(ifu, &ifu->ifu_r, nmr) == 0) |
0468e5fa | 56 | goto bad; |
b454c3ea | 57 | if (if_ubaalloc(ifu, &ifu->ifu_w, nmr) == 0) |
0468e5fa | 58 | goto bad2; |
b454c3ea | 59 | for (i = 0; i < nmr; i++) |
97da2a42 | 60 | ifu->ifu_wmap[i] = ifu->ifu_w.ifrw_mr[i]; |
8a13b737 | 61 | ifu->ifu_xswapd = 0; |
0468e5fa BJ |
62 | return (1); |
63 | bad2: | |
8a13b737 | 64 | ubarelse(ifu->ifu_uban, &ifu->ifu_r.ifrw_info); |
0468e5fa | 65 | bad: |
97da2a42 | 66 | m_pgfree(cp, 2 * ncl); |
176c481f | 67 | ifu->ifu_r.ifrw_addr = 0; |
0468e5fa BJ |
68 | return (0); |
69 | } | |
70 | ||
71 | /* | |
72 | * Setup either a ifrw structure by allocating UNIBUS map registers, | |
d6391cba SL |
73 | * possibly a buffered data path, and initializing the fields of |
74 | * the ifrw structure to minimize run-time overhead. | |
0468e5fa BJ |
75 | */ |
76 | static | |
b454c3ea | 77 | if_ubaalloc(ifu, ifrw, nmr) |
0468e5fa BJ |
78 | struct ifuba *ifu; |
79 | register struct ifrw *ifrw; | |
b454c3ea | 80 | int nmr; |
0468e5fa BJ |
81 | { |
82 | register int info; | |
83 | ||
84 | info = | |
b454c3ea | 85 | uballoc(ifu->ifu_uban, ifrw->ifrw_addr, nmr*NBPG + ifu->ifu_hlen, |
d6391cba | 86 | ifu->ifu_flags); |
0468e5fa | 87 | if (info == 0) |
8a13b737 | 88 | return (0); |
0468e5fa BJ |
89 | ifrw->ifrw_info = info; |
90 | ifrw->ifrw_bdp = UBAI_BDP(info); | |
97da2a42 | 91 | ifrw->ifrw_proto = UBAMR_MRV | (UBAI_BDP(info) << UBAMR_DPSHIFT); |
8a13b737 BJ |
92 | ifrw->ifrw_mr = &ifu->ifu_uba->uba_map[UBAI_MR(info) + 1]; |
93 | return (1); | |
0468e5fa BJ |
94 | } |
95 | ||
96 | /* | |
f1b2fa5b BJ |
97 | * Pull read data off a interface. |
98 | * Len is length of data, with local net header stripped. | |
99 | * Off is non-zero if a trailer protocol was used, and | |
100 | * gives the offset of the trailer information. | |
101 | * We copy the trailer information and then all the normal | |
102 | * data into mbufs. When full cluster sized units are present | |
103 | * on the interface on cluster boundaries we can get them more | |
104 | * easily by remapping, and take advantage of this here. | |
0468e5fa BJ |
105 | */ |
106 | struct mbuf * | |
f1b2fa5b | 107 | if_rubaget(ifu, totlen, off0) |
0468e5fa | 108 | register struct ifuba *ifu; |
f1b2fa5b | 109 | int totlen, off0; |
0468e5fa | 110 | { |
b454c3ea BJ |
111 | struct mbuf *top, **mp, *m; |
112 | int off = off0, len; | |
97da2a42 | 113 | register caddr_t cp = ifu->ifu_r.ifrw_addr + ifu->ifu_hlen; |
0468e5fa | 114 | |
0468e5fa | 115 | |
f1b2fa5b BJ |
116 | top = 0; |
117 | mp = ⊤ | |
118 | while (totlen > 0) { | |
cce93e4b | 119 | MGET(m, M_DONTWAIT, MT_DATA); |
0468e5fa | 120 | if (m == 0) |
8a13b737 | 121 | goto bad; |
f1b2fa5b BJ |
122 | if (off) { |
123 | len = totlen - off; | |
124 | cp = ifu->ifu_r.ifrw_addr + ifu->ifu_hlen + off; | |
125 | } else | |
126 | len = totlen; | |
97da2a42 | 127 | if (len >= CLBYTES) { |
b454c3ea | 128 | struct mbuf *p; |
0468e5fa | 129 | struct pte *cpte, *ppte; |
b454c3ea | 130 | int x, *ip, i; |
0468e5fa BJ |
131 | |
132 | MCLGET(p, 1); | |
133 | if (p == 0) | |
134 | goto nopage; | |
97da2a42 | 135 | len = m->m_len = CLBYTES; |
0468e5fa | 136 | m->m_off = (int)p - (int)m; |
b454c3ea | 137 | if (!claligned(cp)) |
0468e5fa BJ |
138 | goto copy; |
139 | ||
140 | /* | |
b454c3ea BJ |
141 | * Switch pages mapped to UNIBUS with new page p, |
142 | * as quick form of copy. Remap UNIBUS and invalidate. | |
0468e5fa | 143 | */ |
b454c3ea BJ |
144 | cpte = &Mbmap[mtocl(cp)*CLSIZE]; |
145 | ppte = &Mbmap[mtocl(p)*CLSIZE]; | |
8a13b737 | 146 | x = btop(cp - ifu->ifu_r.ifrw_addr); |
97da2a42 | 147 | ip = (int *)&ifu->ifu_r.ifrw_mr[x]; |
0468e5fa BJ |
148 | for (i = 0; i < CLSIZE; i++) { |
149 | struct pte t; | |
b454c3ea | 150 | t = *ppte; *ppte++ = *cpte; *cpte = t; |
0468e5fa | 151 | *ip++ = |
8a13b737 | 152 | cpte++->pg_pfnum|ifu->ifu_r.ifrw_proto; |
0468e5fa | 153 | mtpr(TBIS, cp); |
8a13b737 | 154 | cp += NBPG; |
0468e5fa | 155 | mtpr(TBIS, (caddr_t)p); |
8a13b737 | 156 | p += NBPG / sizeof (*p); |
0468e5fa BJ |
157 | } |
158 | goto nocopy; | |
159 | } | |
160 | nopage: | |
161 | m->m_len = MIN(MLEN, len); | |
162 | m->m_off = MMINOFF; | |
163 | copy: | |
164 | bcopy(cp, mtod(m, caddr_t), (unsigned)m->m_len); | |
165 | cp += m->m_len; | |
166 | nocopy: | |
f1b2fa5b BJ |
167 | *mp = m; |
168 | mp = &m->m_next; | |
169 | if (off) { | |
b454c3ea | 170 | /* sort of an ALGOL-W style for statement... */ |
f1b2fa5b BJ |
171 | off += m->m_len; |
172 | if (off == totlen) { | |
173 | cp = ifu->ifu_r.ifrw_addr + ifu->ifu_hlen; | |
174 | off = 0; | |
97da2a42 | 175 | totlen = off0; |
f1b2fa5b | 176 | } |
97da2a42 | 177 | } else |
c7a4fdbf | 178 | totlen -= m->m_len; |
0468e5fa BJ |
179 | } |
180 | return (top); | |
181 | bad: | |
182 | m_freem(top); | |
183 | return (0); | |
184 | } | |
185 | ||
186 | /* | |
187 | * Map a chain of mbufs onto a network interface | |
188 | * in preparation for an i/o operation. | |
189 | * The argument chain of mbufs includes the local network | |
190 | * header which is copied to be in the mapped, aligned | |
191 | * i/o space. | |
192 | */ | |
193 | if_wubaput(ifu, m) | |
194 | register struct ifuba *ifu; | |
195 | register struct mbuf *m; | |
196 | { | |
197 | register struct mbuf *mp; | |
198 | register caddr_t cp, dp; | |
199 | register int i; | |
b454c3ea BJ |
200 | int xswapd = 0; |
201 | int x, cc; | |
0468e5fa | 202 | |
0468e5fa BJ |
203 | cp = ifu->ifu_w.ifrw_addr; |
204 | while (m) { | |
205 | dp = mtod(m, char *); | |
97da2a42 | 206 | if (claligned(cp) && claligned(dp) && m->m_len == CLBYTES) { |
0468e5fa | 207 | struct pte *pte; int *ip; |
b454c3ea | 208 | pte = &Mbmap[mtocl(dp)*CLSIZE]; |
0468e5fa | 209 | x = btop(cp - ifu->ifu_w.ifrw_addr); |
97da2a42 | 210 | ip = (int *)&ifu->ifu_w.ifrw_mr[x]; |
0468e5fa BJ |
211 | for (i = 0; i < CLSIZE; i++) |
212 | *ip++ = | |
213 | ifu->ifu_w.ifrw_proto | pte++->pg_pfnum; | |
97da2a42 | 214 | xswapd |= 1 << (x>>(CLSHIFT-PGSHIFT)); |
b454c3ea BJ |
215 | mp = m->m_next; |
216 | m->m_next = ifu->ifu_xtofree; | |
217 | ifu->ifu_xtofree = m; | |
218 | cp += m->m_len; | |
219 | } else { | |
0468e5fa | 220 | bcopy(mtod(m, caddr_t), cp, (unsigned)m->m_len); |
b454c3ea BJ |
221 | cp += m->m_len; |
222 | MFREE(m, mp); | |
223 | } | |
0468e5fa BJ |
224 | m = mp; |
225 | } | |
b454c3ea BJ |
226 | |
227 | /* | |
228 | * Xswapd is the set of clusters we just mapped out. Ifu->ifu_xswapd | |
229 | * is the set of clusters mapped out from before. We compute | |
230 | * the number of clusters involved in this operation in x. | |
231 | * Clusters mapped out before and involved in this operation | |
232 | * should be unmapped so original pages will be accessed by the device. | |
233 | */ | |
234 | cc = cp - ifu->ifu_w.ifrw_addr; | |
235 | x = ((cc - ifu->ifu_hlen) + CLBYTES - 1) >> CLSHIFT; | |
97da2a42 | 236 | ifu->ifu_xswapd &= ~xswapd; |
0468e5fa | 237 | xswapd &= ~ifu->ifu_xswapd; |
97da2a42 BJ |
238 | while (i = ffs(ifu->ifu_xswapd)) { |
239 | i--; | |
240 | if (i >= x) | |
241 | break; | |
242 | ifu->ifu_xswapd &= ~(1<<i); | |
243 | i *= CLSIZE; | |
244 | for (x = 0; x < CLSIZE; x++) { | |
245 | ifu->ifu_w.ifrw_mr[i] = ifu->ifu_wmap[i]; | |
246 | i++; | |
0468e5fa | 247 | } |
97da2a42 | 248 | } |
b454c3ea BJ |
249 | ifu->ifu_xswapd |= xswapd; |
250 | return (cc); | |
0468e5fa | 251 | } |