📄 detect.c
字号:
/* * $QNXLicenseC: * Copyright 2007, QNX Software Systems. * * Licensed under the Apache License, Version 2.0 (the "License"). You * may not reproduce, modify or distribute this software except in * compliance with the License. You may obtain a copy of the License * at: http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OF ANY KIND, either express or implied. * * This file may contain contributions from others, either as * contributors under the License or as licensors under other terms. * Please review this entire file for other proprietary rights or license * notices, as well as the QNX Development Suite License Guide at * http://licensing.qnx.com/license-guide/ for other information. * $ */#include <crys8900.h>static int cs8900_parse_options( cs8900_dev_t *cs8900, const char *optstring, nic_config_t *cfg);/* * our own private crys8900 arguments table */int cs8900_verify(void *handle){ cs8900_dev_t *cs8900 = (cs8900_dev_t *)handle; uint32_t base; base = mmap_device_io(32, cs8900->cfg.io_window_base[0]); cs8900->map_flag = 1; if (((void *)base) == MAP_FAILED) { nic_slogf( _SLOGC_NETWORK, _SLOG_ERROR, "devn-crys8900: Unable to mmap_device_io" ); return (ENODEV); }#ifdef __X86__ if (nic_ne2000(base)) if ((inle16(base + CS8900_SIGNATURE) & 0xF000) == 0x3000)#endif if (cs8900_rpktpage(base, CS8900_PROD_ID) == CS8900_EISA_ID) { cs8900->cfg.io_window_size[0] = 32; cs8900->iobase = base; cs8900->map_flag = 0; return (0); } munmap_device_io(base, 32); return (ENODEV);}int cs8900_scan(void *dll_hdl, io_net_self_t *ion, void *handle){ cs8900_dev_t *cs8900 = (cs8900_dev_t *)handle; if (!cs8900_verify(cs8900)) { if (!cs8900_register_device(cs8900, ion, dll_hdl)) { cs8900_advertise(cs8900->reg_hdl, cs8900); return (0); } munmap_device_io(cs8900->iobase, 32); } return (ENODEV);}int cs8900_args( void *dll_hdl, io_net_self_t *ion, char *options){ cs8900_dev_t *cs8900; nic_config_t *cfg; int rval; if ((cs8900 = calloc(sizeof (*cs8900), 1)) == NULL) return -1; /* Set revision info */ cs8900->stats.revision = NIC_STATS_REVISION; cs8900->cfg.revision = NIC_CONFIG_REVISION; /* Ethernet stats we are interested in */ cs8900->stats.un.estats.valid_stats = NIC_ETHER_STAT_NO_CARRIER | NIC_ETHER_STAT_SQE_ERRORS | NIC_ETHER_STAT_SINGLE_COLLISIONS | NIC_ETHER_STAT_XCOLL_ABORTED | NIC_ETHER_STAT_SHORT_PACKETS | NIC_ETHER_STAT_OVERSIZED_PACKETS | NIC_ETHER_STAT_ALIGN_ERRORS | NIC_ETHER_STAT_FCS_ERRORS; /* Generic networking stats we are interested in */ cs8900->stats.valid_stats = NIC_STAT_TX_FAILED_ALLOCS | NIC_STAT_RX_FAILED_ALLOCS; cfg = &cs8900->cfg; /* set some defaults for the command line options */ cfg->flags = NIC_FLAG_MULTICAST; cfg->priority = NIC_PRIORITY; cfg->iftype = IFT_ETHER; cfg->connector = NIC_CONNECTOR_UTP; cfg->lan = -1; cfg->mtu = -1; cfg->mru = -1; cfg->media = -1; cfg->media_rate = -1; cfg->duplex = -1; strcpy(cfg->uptype, "en"); if (cs8900_parse_options(cs8900, options, &cs8900->cfg) == -1) return -1; /* If not set, default to half duplex */ if ( cfg->duplex == -1 ) cfg->duplex = 0; /* If media was not spcified on cmdline, default to NIC_MEDIA_802_3 */ if ( cfg->media == -1 ) { cs8900->cfg.media = NIC_MEDIA_802_3; cs8900->stats.media = cs8900->cfg.media = cs8900->cfg.media; } else cs8900->stats.media = cs8900->cfg.media = cs8900->cfg.media; if (cs8900->cfg.mtu == -1 || cs8900->cfg.mtu > ETH_MAX_PKT_LEN) cs8900->cfg.mtu = ETH_MAX_PKT_LEN; if (cs8900->cfg.mru == -1 || cs8900->cfg.mru > ETH_MAX_PKT_LEN) cs8900->cfg.mru = ETH_MAX_PKT_LEN;#ifdef __X86__ if (!cs8900->cfg.io_window_base[0]) { int iobase; for (iobase = 0x200; iobase <= 0x3E0; iobase += 0x20) { cs8900->cfg.io_window_base[0] = iobase; cs8900->cfg.num_io_windows = 1; if (!cs8900_verify(cs8900)) { if (!cs8900_register_device(cs8900, ion, dll_hdl)) { cs8900_advertise(cs8900->reg_hdl, cs8900); return (0); } munmap_device_io(cs8900->iobase, 32); break; } } return (ENODEV); }#endif if (rval = cs8900_scan(dll_hdl, ion, cs8900)) { free(cs8900); } return (rval);}int crys8900_detect( void *dll_hdl, io_net_self_t *ion, char *options ){ return (cs8900_args(dll_hdl, ion, options));}static char *cs8900_opts[] = { NULL};static int cs8900_parse_options( cs8900_dev_t *cs8900, const char *optstring, nic_config_t *cfg){ char *value; int opt; char *options, *freeptr; char *c; int rc = 0; int err = EOK; if (optstring == NULL) return 0; /* getsubopt() is destructive */ freeptr = options = strdup(optstring); while (options && *options != '\0') { c = options; if ((opt = getsubopt(&options, cs8900_opts, &value)) == -1) { if (nic_parse_options(cfg, value) == EOK) continue; goto error; } switch (opt) { /* private driver options here */ case 0: // Set Rx npkt cache size break; default: break; } continue;error: nic_slogf(_SLOGC_NETWORK, _SLOG_WARNING, "devn-crys8900: unknown option %s", c); err = EINVAL; rc = -1; } free(freeptr); errno = err; return rc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -