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: #include "netdrv.h"
53:
54:
55: IMPORT W GetDevConf(UB *name, W *val);
56:
57: 58: 59:
60: EXPORT NetInf Netinf[MAX_NETDEV];
61: EXPORT PRI TskPri;
62:
63: 64: 65:
66: IMPORT DrvDef DrvTab[];
67:
68: 69: 70:
71: LOCAL const GDefDev NETDRV_DDev = {
72: NULL,
73: "Neta",
74: 1,
75: 0,
76: 0,
77: 0,
78: 1,
79: OpenProc,
80: CloseProc,
81: NULL,
82: EventProc,
83: };
84: #define P_NETUNIT 3
85:
86: 87: 88: 89:
90: LOCAL B NetDevEnt[] = "NETDEV0";
91: #define P_NETNO 6
92:
93: 94: 95:
96: LOCAL ER RegistDevice(NetInf *inf)
97: {
98: ER er;
99: GDefDev devDef;
100:
101:
102: devDef = NETDRV_DDev;
103: devDef.exinf = inf;
104: devDef.devnm[P_NETUNIT] = inf->netno + 'a';
105:
106:
107: if ((er = GDefDevice(&devDef, NULL, &inf->Gdi)) >= E_OK) {
108: inf->devid = GDI_devid(inf->Gdi);
109: return E_OK;
110: }
111:
112: DP(("Net%c: RegistDevice [%#x]\n", NetUnit(inf), er));
113:
114: inf->devid = INVALID_DEVID;
115: return er;
116: }
117:
118: 119: 120:
121: EXPORT ID CreTask(FP entry, PRI pri, W name, UW par, W stksz)
122: {
123: T_CTSK ctsk;
124: ID tskid;
125: ER er;
126:
127:
128: ctsk.exinf = (VP)name;
129: ctsk.task = entry;
130: ctsk.itskpri = pri;
131: ctsk.stksz = stksz;
132: ctsk.tskatr = TA_HLNG | TA_RNG0;
133:
134: tskid = er = tk_cre_tsk(&ctsk);
135: if (er >= E_OK) {
136:
137: er = tk_sta_tsk(tskid, par);
138: if (er < E_OK) tk_del_tsk(tskid);
139: }
140: return (er >= E_OK) ? tskid : er;
141: }
142:
143: 144: 145:
146: LOCAL void MainTask(NetInf *inf)
147: {
148: ER er;
149:
150:
151: er = RegistDevice(inf);
152: if (er < E_OK) goto EEXIT1;
153:
154: inf->exist = TRUE;
155:
156:
157: if (inf->di.stat >= E_OK) {
158: if (DefIntHdr(inf, TRUE) < E_OK) {
159: inf->di.stat = E_LIMIT;
160: } else if (isFORCE_OPEN(inf)) {
161: OpenProc(inf->devid, 0, inf->Gdi);
162: }
163: }
164:
165:
166: AcceptRequest(inf);
167:
168:
169: EEXIT1:
170: if (inf->initfn != NULL) (*(inf->initfn))(inf, -1);
171:
172: DP(("Net%c: MainTask [%#x]\n", NetUnit(inf), er));
173:
174: tk_exd_tsk();
175: }
176:
177: 178: 179:
180: EXPORT ER NetDrv(INT ac, B *av[])
181: {
182: W i, n, k, kk;
183: VP tskname;
184: W v[L_DEVCONF_VAL];
185: NetInf *inf;
186: B *arg;
187: static W ndrv = 0;
188:
189: if (ac < 0) {
190: 191: 192: 193:
194: for (inf = &Netinf[0]; ndrv > 0; ndrv--, inf++) {
195: inf->opencnt = 0;
196: CloseProc(inf->devid, 0, inf->Gdi);
197: if (inf->di.stat >= E_OK) DefIntHdr(inf, FALSE);
198: tk_ter_tsk(inf->tskid);
199: GDelDevice(inf->Gdi);
200: if (inf->initfn != NULL) (*(inf->initfn))(inf, -1);
201: }
202: return E_OK;
203: }
204:
205: TskPri = DEFAULT_PRI;
206: SetOBJNAME(tskname, "netd");
207:
208:
209: memset(v, 0, sizeof(v));
210: if (ac > 1 && (arg = av[1]) != NULL) {
211: switch (*arg++) {
212: case '!':
213: TskPri = strtol(arg, (VP)&arg, 0);
214: break;
215: case '=':
216: v[0] = strtol(arg, (VP)&arg, 0);
217: if (*arg++ == '.') {
218: v[1] = strtol(arg, (VP)&arg, 0);
219: if (*arg++ == '.') {
220: v[2] = strtol(arg, (VP)&arg, 0);
221: }
222: }
223: break;
224: default:
225: return E_PAR;
226: }
227: }
228:
229:
230: memset(Netinf, 0, sizeof(Netinf));
231: for (i = 0; i < MAX_NETDEV; i++) Netinf[i].pciadr = -1;
232:
233:
234: for (ndrv = i = 0; i < MAX_NETDEV; i++) {
235:
236:
237: NetDevEnt[P_NETNO] = i + '0';
238: if (i != 0 || v[0] == 0) {
239: memset(v, 0, sizeof(v));
240: if (GetDevConf(NetDevEnt, v) <= 0 || v[0] <= 0)
241: continue;
242: }
243:
244: inf = &Netinf[i];
245: inf->netno = i;
246: inf->di.kind = v[0];
247: inf->di.iobase =
248: inf->orgbase = v[1];
249: inf->di.intno = v[2];
250: inf->bufsz.minsz = MINPKTLEN;
251: inf->bufsz.maxsz = MAXPKTLEN;
252:
253:
254: if ((kk = v[0] & HK_MASK) == HK_PCI) {
255: for (n = 0; (k = DrvTab[n].kind) != 0; n++) {
256: if ((k & HK_PCI) != 0 && PciProbe(inf,
257: DrvTab[n].pcitab) >= E_OK) break;
258: }
259: } else {
260: for (n = 0; (k = DrvTab[n].kind) != 0 && k != kk; n++);
261: if ((k & HK_PCI) != 0 &&
262: PciProbe(inf, DrvTab[n].pcitab) < E_OK) k = 0;
263: }
264: if (k != 0 && (*(DrvTab[n].initfn))(inf, 0) >= E_OK) {
265: inf->initfn = DrvTab[n].initfn;
266:
267:
268: if ((inf->tskid = CreTask((FP)MainTask, TskPri,
269: (W)tskname, (UW)inf, TASK_STKSZ)) >= E_OK) {
270: ndrv++;
271: continue;
272: }
273:
274: (*(inf->initfn))(inf, -1);
275: inf->initfn = NULL;
276: }
277: }
278: return (ndrv > 0) ? E_OK : E_NOMDA;
279: }
280: