Changeset 8f5e2527 in mainline for uspace/srv/hw/netif/dp8390/dp8390.c
- Timestamp:
- 2011-01-06T13:58:09Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 95ff5c4
- Parents:
- 4765152
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/netif/dp8390/dp8390.c
r4765152 r8f5e2527 1 /*2 * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system in source and binary forms, with or without modification, are permitted provided that the following conditions are met:3 *4 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.5 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.6 * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.7 * * Any deviations from these conditions require written permission from the copyright holder in advance8 *9 *10 * Disclaimer11 *12 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR13 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES14 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.15 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,18 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY19 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.22 *23 * Changes:24 * 2009 ported to HelenOS, Lukas Mejdrech25 */26 27 1 /** @addtogroup dp8390 28 2 * @{ … … 43 17 #include "dp8390_drv.h" 44 18 #include "dp8390_port.h" 45 46 /*47 * dp8390.c48 *49 * Created: before Dec 28, 1992 by Philip Homburg <philip@f-mnx.phicoh.com>50 *51 * Modified Mar 10 1994 by Philip Homburg52 * Become a generic dp8390 driver.53 *54 * Modified Dec 20 1996 by G. Falzoni <falzoni@marina.scn.de>55 * Added support for 3c503 boards.56 */57 19 58 20 #include "local.h" … … 81 43 static void outsw(port_t port, void * buf, size_t size); 82 44 83 //static u16_t eth_ign_proto;84 //static char *progname;85 86 /* Configuration */87 /*typedef struct dp_conf88 {89 port_t dpc_port;90 int dpc_irq;91 phys_bytes dpc_mem;92 char *dpc_envvar;93 } dp_conf_t;94 */95 //dp_conf_t dp_conf[]= /* Card addresses */96 //{97 /* I/O port, IRQ, Buffer address, Env. var. */98 /* { 0x280, 3, 0xD0000, "DPETH0" },99 { 0x300, 5, 0xC8000, "DPETH1" },100 { 0x380, 10, 0xD8000, "DPETH2" },101 };102 */103 /* Test if dp_conf has exactly DE_PORT_NR entries. If not then you will see104 * the error: "array size is negative".105 */106 //extern int ___dummy[DE_PORT_NR == sizeof(dp_conf)/sizeof(dp_conf[0]) ? 1 : -1];107 108 /* Card inits configured out? */109 #if !ENABLE_WDETH110 #define wdeth_probe(dep) (0)111 #endif112 #if !ENABLE_NE2000113 #define ne_probe(dep) (0)114 #endif115 #if !ENABLE_3C503116 #define el2_probe(dep) (0)117 #endif118 119 45 /* Some clones of the dp8390 and the PC emulator 'Bochs' require the CR_STA 120 46 * on writes to the CR register. Additional CR_STAs do not appear to hurt … … 123 49 #define CR_EXTRA CR_STA 124 50 125 //#if ENABLE_PCI126 //_PROTOTYPE(static void pci_conf, (void) );127 //#endif128 //_PROTOTYPE(static void do_vwrite, (message *mp, int from_int,129 // int vectored) );130 //_PROTOTYPE(static void do_vwrite_s, (message *mp, int from_int) );131 //_PROTOTYPE(static void do_vread, (message *mp, int vectored) );132 //_PROTOTYPE(static void do_vread_s, (message *mp) );133 //_PROTOTYPE(static void do_init, (message *mp) );134 //_PROTOTYPE(static void do_int, (dpeth_t *dep) );135 //_PROTOTYPE(static void do_getstat, (message *mp) );136 //_PROTOTYPE(static void do_getstat_s, (message *mp) );137 //_PROTOTYPE(static void do_getname, (message *mp) );138 //_PROTOTYPE(static void do_stop, (message *mp) );139 51 _PROTOTYPE(static void dp_init, (dpeth_t *dep) ); 140 //_PROTOTYPE(static void dp_confaddr, (dpeth_t *dep) );141 52 _PROTOTYPE(static void dp_reinit, (dpeth_t *dep) ); 142 53 _PROTOTYPE(static void dp_reset, (dpeth_t *dep) ); 143 //_PROTOTYPE(static void dp_check_ints, (dpeth_t *dep) );144 54 _PROTOTYPE(static void dp_recv, (dpeth_t *dep) ); 145 55 _PROTOTYPE(static void dp_send, (dpeth_t *dep) ); 146 //_PROTOTYPE(static void dp8390_stop, (void) );147 _PROTOTYPE(static void dp_getblock, (dpeth_t *dep, int page,148 size_t offset, size_t size, void *dst) );149 56 _PROTOTYPE(static void dp_pio8_getblock, (dpeth_t *dep, int page, 150 57 size_t offset, size_t size, void *dst) ); … … 153 60 _PROTOTYPE(static int dp_pkt2user, (dpeth_t *dep, int page, 154 61 int length) ); 155 //_PROTOTYPE(static int dp_pkt2user_s, (dpeth_t *dep, int page,156 // int length) );157 _PROTOTYPE(static void dp_user2nic, (dpeth_t *dep, iovec_dat_t *iovp,158 vir_bytes offset, int nic_addr, vir_bytes count) );159 //_PROTOTYPE(static void dp_user2nic_s, (dpeth_t *dep, iovec_dat_s_t *iovp,160 // vir_bytes offset, int nic_addr, vir_bytes count) );161 62 _PROTOTYPE(static void dp_pio8_user2nic, (dpeth_t *dep, 162 63 iovec_dat_t *iovp, vir_bytes offset, 163 64 int nic_addr, vir_bytes count) ); 164 //_PROTOTYPE(static void dp_pio8_user2nic_s, (dpeth_t *dep,165 // iovec_dat_s_t *iovp, vir_bytes offset,166 // int nic_addr, vir_bytes count) );167 65 _PROTOTYPE(static void dp_pio16_user2nic, (dpeth_t *dep, 168 66 iovec_dat_t *iovp, vir_bytes offset, 169 67 int nic_addr, vir_bytes count) ); 170 //_PROTOTYPE(static void dp_pio16_user2nic_s, (dpeth_t *dep,171 // iovec_dat_s_t *iovp, vir_bytes offset,172 // int nic_addr, vir_bytes count) );173 _PROTOTYPE(static void dp_nic2user, (dpeth_t *dep, int nic_addr,174 iovec_dat_t *iovp, vir_bytes offset, vir_bytes count) );175 //_PROTOTYPE(static void dp_nic2user_s, (dpeth_t *dep, int nic_addr,176 // iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) );177 68 _PROTOTYPE(static void dp_pio8_nic2user, (dpeth_t *dep, int nic_addr, 178 69 iovec_dat_t *iovp, vir_bytes offset, vir_bytes count) ); 179 //_PROTOTYPE(static void dp_pio8_nic2user_s, (dpeth_t *dep, int nic_addr,180 // iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) );181 70 _PROTOTYPE(static void dp_pio16_nic2user, (dpeth_t *dep, int nic_addr, 182 71 iovec_dat_t *iovp, vir_bytes offset, vir_bytes count) ); 183 //_PROTOTYPE(static void dp_pio16_nic2user_s, (dpeth_t *dep, int nic_addr,184 // iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) );185 72 _PROTOTYPE(static void dp_next_iovec, (iovec_dat_t *iovp) ); 186 //_PROTOTYPE(static void dp_next_iovec_s, (iovec_dat_s_t *iovp) );187 73 _PROTOTYPE(static void conf_hw, (dpeth_t *dep) ); 188 //_PROTOTYPE(static void update_conf, (dpeth_t *dep, dp_conf_t *dcp) );189 _PROTOTYPE(static void map_hw_buffer, (dpeth_t *dep) );190 //_PROTOTYPE(static int calc_iovec_size, (iovec_dat_t *iovp) );191 //_PROTOTYPE(static int calc_iovec_size_s, (iovec_dat_s_t *iovp) );192 74 _PROTOTYPE(static void reply, (dpeth_t *dep, int err, int may_block) ); 193 //_PROTOTYPE(static void mess_reply, (message *req, message *reply) );194 75 _PROTOTYPE(static void get_userdata, (int user_proc, 195 76 vir_bytes user_addr, vir_bytes count, void *loc_addr) ); 196 //_PROTOTYPE(static void get_userdata_s, (int user_proc,197 // cp_grant_id_t grant, vir_bytes offset, vir_bytes count,198 // void *loc_addr) );199 //_PROTOTYPE(static void put_userdata, (int user_proc,200 // vir_bytes user_addr, vir_bytes count, void *loc_addr) );201 //_PROTOTYPE(static void put_userdata_s, (int user_proc,202 // cp_grant_id_t grant, size_t count, void *loc_addr) );203 77 _PROTOTYPE(static void insb, (port_t port, void *buf, size_t size) ); 204 78 _PROTOTYPE(static void insw, (port_t port, void *buf, size_t size) ); 205 //_PROTOTYPE(static void do_vir_insb, (port_t port, int proc,206 // vir_bytes buf, size_t size) );207 //_PROTOTYPE(static void do_vir_insw, (port_t port, int proc,208 // vir_bytes buf, size_t size) );209 //_PROTOTYPE(static void do_vir_outsb, (port_t port, int proc,210 // vir_bytes buf, size_t size) );211 //_PROTOTYPE(static void do_vir_outsw, (port_t port, int proc,212 // vir_bytes buf, size_t size) );213 79 214 80 int do_probe(dpeth_t * dep){ … … 494 360 i < 5 ? ':' : '\n'); 495 361 } 496 497 /* Map buffer */498 map_hw_buffer(dep);499 362 500 363 /* Initialization of the dp8390 following the mandatory procedure … … 567 430 dep->de_sendq_head= 0; 568 431 dep->de_sendq_tail= 0; 569 if (!dep->de_prog_IO) 570 { 571 dep->de_user2nicf= dp_user2nic; 572 // dep->de_user2nicf_s= dp_user2nic_s; 573 dep->de_nic2userf= dp_nic2user; 574 // dep->de_nic2userf_s= dp_nic2user_s; 575 dep->de_getblockf= dp_getblock; 576 } 577 else if (dep->de_16bit) 432 if (dep->de_16bit) 578 433 { 579 434 dep->de_user2nicf= dp_pio16_user2nic; … … 938 793 939 794 /*===========================================================================* 940 * dp_getblock *941 *===========================================================================*/942 static void dp_getblock(dep, page, offset, size, dst)943 dpeth_t *dep;944 int page;945 size_t offset;946 size_t size;947 void *dst;948 {949 // int r;950 951 offset = page * DP_PAGESIZE + offset;952 953 memcpy(dst, dep->de_locmem + offset, size);954 }955 956 /*===========================================================================*957 795 * dp_pio8_getblock * 958 796 *===========================================================================*/ … … 1051 889 } 1052 890 return OK; 1053 }1054 1055 /*===========================================================================*1056 * dp_user2nic *1057 *===========================================================================*/1058 static void dp_user2nic(dep, iovp, offset, nic_addr, count)1059 dpeth_t *dep;1060 iovec_dat_t *iovp;1061 vir_bytes offset;1062 int nic_addr;1063 vir_bytes count;1064 {1065 vir_bytes vir_hw;//, vir_user;1066 //int bytes, i, r;1067 int i, r;1068 vir_bytes bytes;1069 1070 vir_hw = (vir_bytes)dep->de_locmem + nic_addr;1071 1072 i= 0;1073 while (count > 0)1074 {1075 if (i >= IOVEC_NR)1076 {1077 dp_next_iovec(iovp);1078 i= 0;1079 continue;1080 }1081 assert(i < iovp->iod_iovec_s);1082 if (offset >= iovp->iod_iovec[i].iov_size)1083 {1084 offset -= iovp->iod_iovec[i].iov_size;1085 i++;1086 continue;1087 }1088 bytes = iovp->iod_iovec[i].iov_size - offset;1089 if (bytes > count)1090 bytes = count;1091 1092 r= sys_vircopy(iovp->iod_proc_nr, D,1093 iovp->iod_iovec[i].iov_addr + offset,1094 SELF, D, vir_hw, bytes);1095 if (r != OK)1096 panic("DP8390", "dp_user2nic: sys_vircopy failed", r);1097 1098 count -= bytes;1099 vir_hw += bytes;1100 offset += bytes;1101 }1102 assert(count == 0);1103 891 } 1104 892 … … 1281 1069 1282 1070 /*===========================================================================* 1283 * dp_nic2user *1284 *===========================================================================*/1285 static void dp_nic2user(dep, nic_addr, iovp, offset, count)1286 dpeth_t *dep;1287 int nic_addr;1288 iovec_dat_t *iovp;1289 vir_bytes offset;1290 vir_bytes count;1291 {1292 vir_bytes vir_hw;//, vir_user;1293 vir_bytes bytes;1294 int i, r;1295 1296 vir_hw = (vir_bytes)dep->de_locmem + nic_addr;1297 1298 i= 0;1299 while (count > 0)1300 {1301 if (i >= IOVEC_NR)1302 {1303 dp_next_iovec(iovp);1304 i= 0;1305 continue;1306 }1307 assert(i < iovp->iod_iovec_s);1308 if (offset >= iovp->iod_iovec[i].iov_size)1309 {1310 offset -= iovp->iod_iovec[i].iov_size;1311 i++;1312 continue;1313 }1314 bytes = iovp->iod_iovec[i].iov_size - offset;1315 if (bytes > count)1316 bytes = count;1317 1318 r= sys_vircopy(SELF, D, vir_hw,1319 iovp->iod_proc_nr, D,1320 iovp->iod_iovec[i].iov_addr + offset, bytes);1321 if (r != OK)1322 panic("DP8390", "dp_nic2user: sys_vircopy failed", r);1323 1324 count -= bytes;1325 vir_hw += bytes;1326 offset += bytes;1327 }1328 assert(count == 0);1329 }1330 1331 /*===========================================================================*1332 1071 * dp_pio8_nic2user * 1333 1072 *===========================================================================*/ … … 1514 1253 // if (dep->de_mode != DEM_ENABLED) 1515 1254 // return; 1516 if (!wdeth_probe(dep) && !ne_probe(dep) && !el2_probe(dep)) 1517 { 1255 if (!ne_probe(dep)) { 1518 1256 printf("%s: No ethernet card found at %#lx\n", 1519 1257 dep->de_name, dep->de_base_port); … … 1528 1266 dep->de_flags = DEF_EMPTY; 1529 1267 // dep->de_stat = empty_stat; 1530 }1531 1532 /*===========================================================================*1533 * map_hw_buffer *1534 *===========================================================================*/1535 static void map_hw_buffer(dep)1536 dpeth_t *dep;1537 {1538 // int r;1539 // size_t o, size;1540 // char *buf, *abuf;1541 1542 if (dep->de_prog_IO)1543 {1544 #if 01545 if(debug){1546 printf(1547 "map_hw_buffer: programmed I/O, no need to map buffer\n");1548 }1549 #endif1550 dep->de_locmem = (char *)-dep->de_ramsize; /* trap errors */1551 return;1552 }else{1553 printf("map_hw_buffer: no buffer!\n");1554 }1555 1556 // size = dep->de_ramsize + PAGE_SIZE; /* Add PAGE_SIZE for1557 // * alignment1558 // */1559 // buf= malloc(size);1560 // if (buf == NULL)1561 // panic(__FILE__, "map_hw_buffer: cannot malloc size", size);1562 // o= PAGE_SIZE - ((vir_bytes)buf % PAGE_SIZE);1563 // abuf= buf + o;1564 // printf("buf at 0x%x, abuf at 0x%x\n", buf, abuf);1565 1566 // r= sys_vm_map(SELF, 1 /* map */, (vir_bytes)abuf,1567 // dep->de_ramsize, (phys_bytes)dep->de_linmem);1568 // if (r != OK)1569 // panic(__FILE__, "map_hw_buffer: sys_vm_map failed", r);1570 // dep->de_locmem = abuf;1571 1268 } 1572 1269 … … 1665 1362 } 1666 1363 1667 /*1668 * $PchId: dp8390.c,v 1.25 2005/02/10 17:32:07 philip Exp $1669 */1670 1671 1364 /** @} 1672 1365 */
Note:
See TracChangeset
for help on using the changeset viewer.