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