/*
* axf_usbgem.c : ASIX AX88172/772 USB to Fast Ethernet Driver for Solaris
*
* Copyright (c) 2004-2012 Masayuki Murayama. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
*
* 3. Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
#pragma ident "@(#)axf_usbgem.c 1.3 12/02/09"
/*
* Changelog:
*/
/*
* TODO
* handle RXMODE_ENABLE in set_rx_filter()
*/
/* ======================================================= */
/*
* Solaris system header files and macros
*/
/* minimum kernel headers for drivers */
#include <sys/byteorder.h>
/* ethernet stuff */
#include <sys/ethernet.h>
/* interface card depend stuff */
#include "usbgem.h"
/* hardware stuff */
#include "usbgem_mii.h"
#include "ax88172reg.h"
char ident[] = "ax88x72 usbnic driver v" VERSION;
/*
* Useful macros
*/
/*
* Debugging
*/
#ifdef DEBUG_LEVEL
#else
#endif
/*
* Our configration for ax88172
*/
/* timeouts */
/*
*/
/*
* Local device definitions
*/
struct chip_info {
int type;
char *name;
#define CHIP_TYPE_AX88172 0
};
/* AX88172 */
{
/* Planex UE2-100TX, Hawking UF200, TrendNet TU2-ET100 */
/*
* the default setting covers below:
* gpio bit2 has to be 0 and gpio bit0 has to be 1
*/
{0, 0},
{0, 0},
"Planex UE2-100TX", /* tested */
},
{
{0x9f, 0x9e}, {0, 0}, {0, 0},
"D-Link dube100", /* XXX */
},
{
"Linksys USB200M",
},
{
"Netgear FA120",
},
{
"Intellinet, ST Lab USB Ethernet",
},
{
"Billionton Systems, USB2AR",
},
{
"ATEN UC210T",
},
{
"Buffalo LUA-U2-KTX",
},
{
"Sitecom LN-029 USB 2.0 10/100 Ethernet adapter",
},
{
"corega FEther USB2-TX",
},
{
"Surecom EP-1427X-2",
},
{
"goodway corp usb gwusb2e",
},
/* AX88772 and AX88178 */
{
{0, 0}, {0, 0}, {0, 0},
"Linksys USB200M rev.2",
},
{
{0, 0}, {0, 0}, {0, 0},
"0Q0 cable ethernet",
},
{
{0, 0}, {0, 0}, {0, 0},
"DLink DUB E100 ver B1",
},
{
{0, 0}, {0, 0}, {0, 0},
"DLink DUB E100 ver B1(2)",
},
{
{0, 0}, {0, 0}, {0, 0},
"Apple Ethernet USB Adapter",
},
{
{0, 0}, {0, 0}, {0, 0},
"Linksys USB1000",
},
{
{0, 0}, {0, 0}, {0, 0},
"Buffalo LUA-U2-KGT/LUA-U2-GT",
},
{
{0, 0}, {0, 0}, {0, 0},
"I/O DATA ETG-US2",
},
{
{0, 0}, {0, 0}, {0, 0},
"Belkin F5D5055",
},
{
/* generic ax88772 must be the last entry */
/* planex UE-200TX-G */
{0, 0}, {0, 0}, {0, 0},
},
};
struct axf_dev {
/*
* Misc HW information
*/
};
/*
* private functions
*/
/* mii operations */
/* nic operations */
static int axf_reset_chip(struct usbgem_dev *);
static int axf_init_chip(struct usbgem_dev *);
static int axf_start_chip(struct usbgem_dev *);
static int axf_stop_chip(struct usbgem_dev *);
static int axf_set_media(struct usbgem_dev *);
static int axf_set_rx_filter(struct usbgem_dev *);
static int axf_get_stats(struct usbgem_dev *);
/* packet operations */
/* =============================================================== */
/*
* I/O functions
*/
/* =============================================================== */
/* BEGIN CSTYLED */
/* bmRequestType */ USB_DEV_REQ_HOST_TO_DEV \
/* bRequest */ (req), \
/* wValue */ (val), \
/* wIndex */ (ix), \
/* wLength */ (len), \
/* value */ (buf), \
/* bmRequestType */ USB_DEV_REQ_DEV_TO_HOST \
/* bRequest */ (req), \
/* wValue */ (val), \
/* wIndex */ (ix), \
/* wLength */ (len), \
/* valuep */ (buf), \
/* END CSTYLED */
/* =============================================================== */
/*
* Hardware manupilation
*/
/* =============================================================== */
static int
{
int err;
/* reset MII PHY */
} else {
drv_usecwait(1000);
}
return (USB_SUCCESS);
return (USB_FAILURE);
}
static int
{
/* there are no ways to reset nic */
return (USB_SUCCESS);
}
#ifdef NEVER
#endif
return (err);
}
/*
* Setup ax88172
*/
static int
{
int i;
/* rx conrol register: read default value */
/* clear rx control */
}
/* Media status register */
#ifdef notdef
#else
#endif
} else {
}
/* write IPG0-2 registers */
} else {
/* EMPTY */
}
#ifdef ENABLE_RX_IN_INIT_CHIP
/* enable Rx */
#endif
return (err);
}
static int
{
#ifndef ENABLE_RX_IN_INIT_CHIP
/* enable Rx */
#endif
return (err);
}
static int
{
/* Disable Rx */
/*
* Restore factory mac address
* if we have changed current mac address
*/
ETHERADDRL) != 0) {
}
return (axf_reset_chip(dp));
}
static int
{
/* empty */
return (USB_SUCCESS);
}
static uint_t
{
}
static int
{
int i;
uint_t h;
/* set promiscuous mode before changing it. */
}
/* promiscious mode implies all multicast and all physical */
/* accept all multicast packets */
/*
* make hash table to select interresting
* multicast address only.
*/
}
}
/*
* we use promiscious mode instead of changing the
* mac address in ax88172
*/
}
} else {
}
/* set multicast hash table */
/* need to set up multicast hash table */
}
/* update rcr */
#if DEBUG_LEVEL > 1
/* verify rxctrl reg */
#endif
return (err);
}
static int
{
/* setup speed */
/* EMPTY */
} else {
case USBGEM_SPD_1000:
break;
case USBGEM_SPD_100:
break;
case USBGEM_SPD_10:
break;
}
}
/* select duplex */
if (dp->full_duplex) {
/* select flow control */
switch (dp->flow_control) {
case FLOW_CONTROL_TX_PAUSE:
case FLOW_CONTROL_SYMMETRIC:
case FLOW_CONTROL_RX_PAUSE:
break;
}
} else {
switch (dp->flow_control) {
case FLOW_CONTROL_TX_PAUSE:
break;
case FLOW_CONTROL_SYMMETRIC:
break;
case FLOW_CONTROL_RX_PAUSE:
break;
}
}
}
/* update medium status register */
/* LED control required for some products */
}
return (err);
}
}
/*
*/
static mblk_t *
{
int n;
int pad_size;
#ifdef notdef
align_mask = 63;
#else
align_mask = 511;
#endif
header_size = 0;
(len & align_mask) != 0) {
/* use the mp "as is" */
return (mp);
}
} else {
align_mask = 511;
}
/*
* re-allocate the mp
*/
/* minimum ethernet packet size of ETHERMIN */
/* padding is required in usb communication */
} else {
pad_size = 0;
}
return (NULL);
}
if (header_size) {
/* add a header */
bp += header_size;
}
/* copy contents of the buffer */
bp += n;
}
/* add pads for ethernet packets */
*bp++ = 0;
}
/* add a zero-length pad segment for usb communications */
if (pad_size) {
/* add a dummy header for zero-length packet */
FILL_PKT_HEADER(bp, 0);
}
/* close the payload of the packet */
return (new);
}
static void
{
int i;
}
}
static mblk_t *
{
return (mp);
}
if (rest <= PKT_HEADER_SIZE) {
/*
* the usb bulk-in frame doesn't include any valid
* ethernet packets.
*/
return (NULL);
}
for (; ; ) {
/* analyse the header of the received usb frame */
/* test if the header is valid */
/* discard whole the packet */
"!%s: %s: corrupted header:%04x %04x",
return (NULL);
}
#if DEBUG_LEVEL > 0
"!%s: %s: incorrect pktsize:%d",
}
#endif
/* extract a ethernet packet from the bulk-in frame */
if (len & 1) {
/*
* skip a tailing pad byte if the packet
* length is odd
*/
len++;
}
if (rest <= PKT_HEADER_SIZE) {
/* no more vaild ethernet packets */
break;
}
#if DEBUG_LEVEL > 10
#endif
/* allocate a mblk_t header for the next ethernet packet */
}
return (mp);
}
/*
* MII Interfaces
*/
static uint16_t
{
/* switch to software MII operation mode */
/* Read MII register */
/* switch to hardware MII operation mode */
return (0);
}
static void
{
/* switch software MII operation mode */
/* Write to the specified MII register */
/* switch to hardware MII operation mode */
;
}
static void
{
"!%s: %s: size:%d, %02x %02x %02x %02x %02x %02x %02x %02x",
}
}
/* ======================================================== */
/*
* OS depend (device driver DKI) routine
*/
/* ======================================================== */
#ifdef DEBUG_LEVEL
static void
{
int i;
int err;
err = USB_SUCCESS;
for (i = 0; i < size; i += 4) {
i,
}
;
}
#endif
static int
{
int err;
int ret;
#ifdef CONFIG_FULLSIZE_VLAN
#endif
#ifdef DEBUG_LEVEL
#endif
ret = USB_SUCCESS;
/*
* mac address in EEPROM has loaded to ID registers.
*/
/*
* setup IPG values
*/
/*
* We cannot scan phy because the nic returns undefined
* value, i.e. remained garbage, when MII phy is not at the
* specified index.
*/
#ifdef DEBUG_LEVELx
/*
* restore the original phy address of brain
* damaged Planex UE2-100TX
*/
}
#endif
} else {
/* use built-in phy */
}
#ifdef CONFIG_FULLSIZE_VLAN
/* check max packet size in srom */
"!%s: %s: max packet size in srom is too small, "
"changing %d -> %d, do power cycle for the device",
/* need to power off the device */
ret = USB_FAILURE;
}
}
#endif
#ifdef DEBUG_LEVEL
"!%s: %s: ipg 0x%02x 0x%02x 0x%02x, gpio 0x%b",
#endif
/* fix rx buffer size */
}
#if DEBUG_LEVEL > 0
#endif
return (ret);
return (USB_FAILURE);
}
static boolean_t
{
int i;
int err;
int phy_addr_saved;
/* special probe routine for unreliable MII addr */
#define PROBE_PAT \
for (i = 0; i < 32; i++) {
dp->mii_phy_addr = i;
if (err != USBGEM_SUCCESS) {
break;
}
if (err != USBGEM_SUCCESS) {
break;
}
if (val != 0) {
continue;
}
if (err != USBGEM_SUCCESS) {
break;
}
if (err != USBGEM_SUCCESS) {
break;
}
"index:%d, pat:%x != val:%b",
continue;
}
/* found */
return (i);
}
if (i == 32) {
} else {
}
return (-1);
}
static int
{
int my_guess;
int err;
(void) axf_reset_phy(dp);
/*
* phy addr in srom is wrong, need to fix it
*/
#if 1
/* XXX - read back, but it doesn't work, why? */
#endif
"%04x -> %04x",
return (USBGEM_FAILURE);
"!%s: %s: failed to patch phy addr, "
"current: %04x",
return (USBGEM_FAILURE);
}
}
return (usbgem_mii_probe_default(dp));
}
static int
{
if (!lp->phy_has_reset) {
(void) axf_reset_phy(dp);
}
/* prepare to reset phy on the next reconnect or resume */
return (USB_SUCCESS);
}
static int
{
int i;
int ret;
int revid;
int unit;
int vid;
int pid;
struct chip_info *p;
int len;
const char *drv_name;
void *base;
if (cmd == DDI_ATTACH) {
/*
* Check if the chip is supported.
*/
"usb-vendor-id", -1);
"usb-product-id", -1);
"usb-revision-id", -1);
for (i = 0, p = chiptbl_88x7x; i < CHIPTABLESIZE; i++, p++) {
/* found */
"(vid: 0x%04x, did: 0x%04x, revid: 0x%02x)",
goto chip_found;
}
}
/* Not found */
/* assume 88772 */
/*
* construct usbgem configration
*/
/* name */
/*
* softmac requires that ppa is the instance number
* of the device, otherwise it hangs in seaching the device.
*/
ugcp->usbgc_ifnum = 0;
ugcp->usbgc_rx_header_len = 0;
/* time out parameters */
/* flow control */
/*
* XXX - flow control caused link down frequently under
* heavy traffic
*/
/* MII timeout parameters */
ugcp->usbgc_mii_an_wait = 0;
/* I/O methods */
/* mac operation */
/* packet operation */
/* mii operations */
/* mtu */
lp->last_link_state = 0;
return (DDI_SUCCESS);
}
err:
return (DDI_FAILURE);
}
if (cmd == DDI_RESUME) {
return (usbgem_resume(dip));
}
return (DDI_FAILURE);
}
static int
{
int ret;
if (cmd == DDI_DETACH) {
if (ret != DDI_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
if (cmd == DDI_SUSPEND) {
return (usbgem_suspend(dip));
}
return (DDI_FAILURE);
}
/* ======================================================== */
/*
* OS depend (loadable streams driver) routine
*/
/* ======================================================== */
#ifdef USBGEM_CONFIG_GLDv3
#else
0, /* mi_idnum */
"axf", /* mi_idname */
0, /* mi_minpsz */
ETHERMTU, /* mi_maxpsz */
1, /* mi_lowat */
};
(int (*)()) NULL, /* qi_putp */
usbgem_rsrv, /* qi_srvp */
usbgem_open, /* qi_qopen */
usbgem_close, /* qi_qclose */
(int (*)()) NULL, /* qi_qadmin */
&axfminfo, /* qi_minfo */
NULL /* qi_mstat */
};
usbgem_wput, /* qi_putp */
usbgem_wsrv, /* qi_srvp */
(int (*)()) NULL, /* qi_qopen */
(int (*)()) NULL, /* qi_qclose */
(int (*)()) NULL, /* qi_qadmin */
&axfminfo, /* qi_minfo */
NULL /* qi_mstat */
};
&axfrinit, /* st_rdinit */
&axfwinit, /* st_wrinit */
NULL, /* st_muxrinit */
NULL /* st_muxwrinit */
};
nulldev, /* cb_open */
nulldev, /* cb_close */
nodev, /* cb_strategy */
nodev, /* cb_print */
nodev, /* cb_dump */
nodev, /* cb_read */
nodev, /* cb_write */
nodev, /* cb_ioctl */
nodev, /* cb_devmap */
nodev, /* cb_mmap */
nodev, /* cb_segmap */
nochpoll, /* cb_chpoll */
ddi_prop_op, /* cb_prop_op */
&axf_info, /* cb_stream */
};
DEVO_REV, /* devo_rev */
0, /* devo_refcnt */
usbgem_getinfo, /* devo_getinfo */
nulldev, /* devo_identify */
nulldev, /* devo_probe */
axfattach, /* devo_attach */
axfdetach, /* devo_detach */
nodev, /* devo_reset */
&cb_axf_ops, /* devo_cb_ops */
NULL, /* devo_bus_ops */
usbgem_power, /* devo_power */
#if DEVO_REV >= 4
usbgem_quiesce, /* devo_quiesce */
#endif
};
#endif
&mod_driverops, /* Type of module. This one is a driver */
ident,
&axf_ops, /* driver ops */
};
};
/* ======================================================== */
/*
* _init : done
*/
/* ======================================================== */
int
_init(void)
{
int status;
if (status != DDI_SUCCESS) {
return (status);
}
if (status != DDI_SUCCESS) {
}
return (status);
}
/*
* _fini : done
*/
int
_fini(void)
{
int status;
if (status == DDI_SUCCESS) {
}
return (status);
}
int
{
}