66 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
68 #include <linux/module.h>
69 #include <linux/kernel.h>
71 #include <linux/ptrace.h>
72 #include <linux/slab.h>
73 #include <linux/string.h>
78 #include <linux/ethtool.h>
79 #include <linux/netdevice.h>
82 #include <linux/if_arp.h>
84 #include <linux/bitops.h>
85 #include <linux/mii.h>
92 #include <asm/uaccess.h>
95 #define MANFID_COMPAQ 0x0138
96 #define MANFID_COMPAQ2 0x0183
102 #define TX_TIMEOUT ((400*HZ)/1000)
119 #define XIRCREG_ESR 0
128 #define XIRCREG_EDP 4
129 #define XIRCREG_ISR 6
139 #define XIRCREG1_IMR0 12
140 #define XIRCREG1_IMR1 13
141 #define XIRCREG0_TSO 8
142 #define XIRCREG0_TRS 10
143 #define XIRCREG0_DO 12
144 #define XIRCREG0_RSR 12
153 #define XIRCREG0_PTR 13
154 #define XIRCREG0_RBC 14
155 #define XIRCREG1_ECR 14
163 #define XIRCREG2_RBS 8
164 #define XIRCREG2_LED 10
175 #define XIRCREG2_MSR 12
177 #define XIRCREG4_GPR0 8
178 #define XIRCREG4_GPR1 9
179 #define XIRCREG2_GPR2 13
180 #define XIRCREG4_BOV 10
181 #define XIRCREG4_LMA 12
182 #define XIRCREG4_LMD 14
184 #define XIRCREG40_CMD0 8
194 #define XIRCREG5_RHSA0 10
195 #define XIRCREG40_RXST0 9
196 #define XIRCREG40_TXST0 11
197 #define XIRCREG40_TXST1 12
198 #define XIRCREG40_RMASK0 13
199 #define XIRCREG40_TMASK0 14
200 #define XIRCREG40_TMASK1 15
201 #define XIRCREG42_SWC0 8
202 #define XIRCREG42_SWC1 9
203 #define XIRCREG42_BOC 10
204 #define XIRCREG44_TDR0 8
205 #define XIRCREG44_TDR1 9
206 #define XIRCREG44_RXBC_LO 10
207 #define XIRCREG44_RXBC_HI 11
208 #define XIRCREG45_REV 15
209 #define XIRCREG50_IA 8
211 static const char *if_names[] = {
"Auto",
"10BaseT",
"10Base2",
"AUI",
"100BaseT" };
214 #define XIR_UNKNOWN 0
236 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
252 static unsigned maxrx_bytes = 22000;
255 static void mii_idle(
unsigned int ioaddr);
256 static void mii_putbit(
unsigned int ioaddr,
unsigned data);
257 static int mii_getbit(
unsigned int ioaddr);
258 static void mii_wbits(
unsigned int ioaddr,
unsigned data,
int len);
261 unsigned data,
int len);
263 static int has_ce2_string(
struct pcmcia_device *
link);
264 static int xirc2ps_config(
struct pcmcia_device *
link);
265 static void xirc2ps_release(
struct pcmcia_device *
link);
266 static void xirc2ps_detach(
struct pcmcia_device *p_dev);
272 struct pcmcia_device *
p_dev;
296 static int set_card_type(
struct pcmcia_device *
link);
300 static const struct ethtool_ops netdev_ethtool_ops;
308 #define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR)
309 #define GetByte(reg) ((unsigned)inb(ioaddr + (reg)))
310 #define GetWord(reg) ((unsigned)inw(ioaddr + (reg)))
311 #define PutByte(reg,value) outb((value), ioaddr+(reg))
312 #define PutWord(reg,value) outw((value), ioaddr+(reg))
325 for (i = 0; i < 8; i++)
328 for (page = 0; page <= 8; page++) {
331 for (i = 8; i < 16; i++)
335 for (page=0x40 ; page <= 0x5f; page++) {
336 if (page == 0x43 || (page >= 0x46 && page <= 0x4f) ||
337 (page >= 0x51 && page <=0x5e))
341 for (i = 8; i < 16; i++)
355 mii_idle(
unsigned int ioaddr)
367 mii_putbit(
unsigned int ioaddr,
unsigned data)
400 mii_getbit(
unsigned int ioaddr)
413 mii_wbits(
unsigned int ioaddr,
unsigned data,
int len)
415 unsigned m = 1 << (len-1);
417 mii_putbit(ioaddr, data & m);
427 for (i=0; i < 32; i++)
428 mii_putbit(ioaddr, 1);
429 mii_wbits(ioaddr, 0x06, 4);
430 mii_wbits(ioaddr, phyaddr, 5);
431 mii_wbits(ioaddr, phyreg, 5);
435 for (m = 1<<15;
m; m >>= 1)
436 if (mii_getbit(ioaddr))
443 mii_wr(
unsigned int ioaddr,
u_char phyaddr,
u_char phyreg,
unsigned data,
449 for (i=0; i < 32; i++)
450 mii_putbit(ioaddr, 1);
451 mii_wbits(ioaddr, 0x05, 4);
452 mii_wbits(ioaddr, phyaddr, 5);
453 mii_wbits(ioaddr, phyreg, 5);
454 mii_putbit(ioaddr, 1);
455 mii_putbit(ioaddr, 0);
456 mii_wbits(ioaddr, data, len);
465 .ndo_start_xmit = do_start_xmit,
466 .ndo_tx_timeout = xirc_tx_timeout,
467 .ndo_set_config = do_config,
468 .ndo_do_ioctl = do_ioctl,
469 .ndo_set_rx_mode = set_multicast_list,
476 xirc2ps_probe(
struct pcmcia_device *
link)
481 dev_dbg(&link->dev,
"attach()\n");
487 local = netdev_priv(dev);
493 link->config_index = 1;
501 return xirc2ps_config(link);
505 xirc2ps_detach(
struct pcmcia_device *link)
509 dev_dbg(&link->dev,
"detach\n");
513 xirc2ps_release(link);
537 set_card_type(
struct pcmcia_device *link)
542 unsigned int cisrev, mediaid, prodid;
547 dev_err(&link->dev,
"invalid CIS -- sorry\n");
555 dev_dbg(&link->dev,
"cisrev=%02x mediaid=%02x prodid=%02x\n",
556 cisrev, mediaid, prodid);
562 if (!(prodid & 0x40)) {
566 if (!(mediaid & 0x01)) {
570 if (mediaid & 0x10) {
572 switch(prodid & 15) {
588 switch(prodid & 15) {
598 pr_notice(
"Sorry, this is an old CE card\n");
602 pr_notice(
"unknown card (mediaid=%02x prodid=%02x)\n", mediaid, prodid);
613 has_ce2_string(
struct pcmcia_device * p_dev)
615 if (p_dev->prod_id[2] &&
strstr(p_dev->prod_id[2],
"CE2"))
621 xirc2ps_config_modem(
struct pcmcia_device *p_dev,
void *priv_data)
625 if ((p_dev->resource[0]->start & 0xf) == 8)
628 p_dev->resource[0]->end = 16;
629 p_dev->resource[1]->end = 8;
630 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
631 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
632 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
633 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
634 p_dev->io_lines = 10;
636 p_dev->resource[1]->start = p_dev->resource[0]->start;
637 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
638 p_dev->resource[0]->start = ioaddr;
646 xirc2ps_config_check(
struct pcmcia_device *p_dev,
void *priv_data)
648 int *pass = priv_data;
651 tmp += (*pass ? (p_dev->config_index & 0x20 ? -24 : 8)
652 : (p_dev->config_index & 0x20 ? 8 : -24));
654 if ((p_dev->resource[0]->start & 0xf) == 8)
657 p_dev->resource[0]->end = 18;
658 p_dev->resource[1]->end = 8;
659 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
660 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
661 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
662 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
663 p_dev->io_lines = 10;
665 p_dev->resource[1]->start = p_dev->resource[0]->start;
666 p_dev->resource[0]->start =
tmp;
671 static int pcmcia_get_mac_ce(
struct pcmcia_device *p_dev,
684 for (i = 2; i < 6; i++)
691 xirc2ps_config(
struct pcmcia_device * link)
702 dev_dbg(&link->dev,
"config\n");
705 if (link->has_manf_id == 0) {
710 switch (link->manf_id) {
728 pr_notice(
"Unknown Card Manufacturer ID: 0x%04x\n",
729 (
unsigned)link->manf_id);
734 if (!set_card_type(link)) {
735 pr_notice(
"this card is not supported\n");
740 err = pcmcia_get_mac_from_cis(link, dev);
744 len = pcmcia_get_tuple(link, 0x89, &buf);
746 if (buf && len == 8) {
749 for (i = 2; i < 6; i++)
758 err = pcmcia_loop_tuple(link,
CISTPL_FUNCE, pcmcia_get_mac_ce, dev);
767 link->config_flags |= CONF_AUTO_SET_IO;
772 if (!pcmcia_loop_config(link, xirc2ps_config_modem,
NULL))
780 for (pass=0; pass < 2; pass++)
781 if (!pcmcia_loop_config(link, xirc2ps_config_check,
791 link->resource[0]->end = 16;
792 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
793 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
794 link->resource[0]->start = ioaddr;
798 link->resource[0]->start = 0;
813 link->config_flags |= CONF_ENABLE_IRQ;
815 link->config_flags |= CONF_ENABLE_SPKR;
827 link->resource[1]->start & 0xff);
832 (link->resource[1]->start >> 8) & 0xff);
840 link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM |
842 link->resource[2]->start = link->resource[2]->end = 0;
854 ioaddr = link->resource[0]->start;
862 for (i=0; i < 7; i++) {
868 for (i=0; i < 4; i++) {
874 for (i=0; i < 10; i++) {
897 pr_notice(
"invalid if_port requested\n");
900 dev->
irq = link->irq;
901 dev->
base_addr = link->resource[0]->start;
914 netdev_info(dev,
"%s: port %#3lx, irq %d, hwaddr %pM\n",
921 xirc2ps_release(link);
929 xirc2ps_release(
struct pcmcia_device *link)
931 dev_dbg(&link->dev,
"release\n");
933 if (link->resource[2]->end) {
945 static int xirc2ps_suspend(
struct pcmcia_device *link)
957 static int xirc2ps_resume(
struct pcmcia_device *link)
990 if (!netif_device_present(dev))
998 pr_debug(
"%s: interrupt %d at %#x.\n", dev->
name, irq, ioaddr);
1007 if (int_status == 0xff) {
1008 pr_debug(
"%s: interrupt %d for dead card\n", dev->
name, irq);
1021 pr_debug(
"%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
1022 dev->
name, int_status, eth_status, rx_status, tx_status);
1028 if (bytes_rcvd > maxrx_bytes && (rsr &
PktRxOk)) {
1031 dev->
stats.rx_dropped++;
1033 }
else if (rsr & PktRxOk) {
1039 pr_debug(
"rsr=%#02x packet_length=%u\n", rsr, pktlen);
1042 skb = netdev_alloc_skb(dev, pktlen + 3);
1044 pr_notice(
"low memory, packet dropped (size=%u)\n", pktlen);
1045 dev->
stats.rx_dropped++;
1047 skb_reserve(skb, 2);
1057 if (rhsa + pktlen > 0x8000) {
1060 for (i=0; i <
pktlen ; i++, rhsa++) {
1062 if (rhsa == 0x8000) {
1069 skb_put(skb, pktlen), (pktlen+1)>>1);
1086 for (i=0; i <
len ; i += 4, p++) {
1101 dev->
stats.rx_packets++;
1104 dev->
stats.multicast++;
1110 dev->
stats.rx_frame_errors++;
1114 dev->
stats.rx_crc_errors++;
1118 dev->
stats.rx_fifo_errors++;
1128 if (rx_status & 0x10) {
1129 dev->
stats.rx_over_errors++;
1131 pr_debug(
"receive overrun cleared\n");
1142 dev->
stats.tx_packets += 256 -
n;
1147 netif_wake_queue(dev);
1149 if (tx_status & 0x0002) {
1150 pr_debug(
"tx restarted due to execssive collissions\n");
1153 if (tx_status & 0x0040)
1154 dev->
stats.tx_aborted_errors++;
1160 if (bytes_rcvd > 1000) {
1163 if (duration >=
HZ/10) {
1164 maxrx_bytes = (bytes_rcvd * (
HZ/10)) /
duration;
1165 if (maxrx_bytes < 2000)
1167 else if (maxrx_bytes > 22000)
1168 maxrx_bytes = 22000;
1169 pr_debug(
"set maxrx=%u (rcvd=%u ticks=%lu)\n",
1170 maxrx_bytes, bytes_rcvd, duration);
1171 }
else if (!duration && maxrx_bytes < 22000) {
1173 maxrx_bytes += 2000;
1174 if (maxrx_bytes > 22000)
1175 maxrx_bytes = 22000;
1176 pr_debug(
"set maxrx=%u\n", maxrx_bytes);
1205 netif_wake_queue(dev);
1212 dev->
stats.tx_errors++;
1213 netdev_notice(dev,
"transmit timed out\n");
1224 unsigned pktlen = skb->
len;
1226 pr_debug(
"do_start_xmit(skb=%p, dev=%p) len=%u\n",
1244 netif_stop_queue(dev);
1248 okay = freespace & 0x8000;
1249 freespace &= 0x7fff;
1251 okay = pktlen +2 < freespace;
1252 pr_debug(
"%s: avail. tx space=%u%s\n",
1253 dev->
name, freespace, okay ?
" (okay)":
" (not enough)");
1259 outsw(ioaddr+XIRCREG_EDP, skb->
data, pktlen>>1);
1266 dev_kfree_skb (skb);
1268 netif_start_queue(dev);
1281 unsigned int ioaddr = sa_info->
ioaddr;
1284 for (i = 0; i < 6; i++) {
1285 if (sa_info->
reg_nr > 15) {
1302 static void set_addresses(
struct net_device *dev)
1380 netdev_info(dev,
"switching to %s port\n", if_names[dev->
if_port]);
1393 struct pcmcia_device *link = lp->
p_dev;
1395 dev_dbg(&link->dev,
"do_open(%p)\n", dev);
1405 netif_start_queue(dev);
1411 static void netdev_get_drvinfo(
struct net_device *dev,
1418 static const struct ethtool_ops netdev_ethtool_ops = {
1419 .get_drvinfo = netdev_get_drvinfo,
1429 pr_debug(
"%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
1478 pr_debug(
"%s: do_reset(%p,%d)\n", dev? dev->
name:
"eth?", dev, full);
1507 }
else if (dev->
if_port == 2) {
1568 if (full && local->
mohawk && init_mii(dev)) {
1570 netdev_info(dev,
"MII selected\n");
1575 netdev_info(dev,
"MII detected; using 10mbs\n");
1603 set_multicast_list(dev);
1620 netdev_info(dev,
"media %s, silicon revision %d\n",
1640 if (if_port == 4 || if_port == 1) {
1646 status = mii_rd(ioaddr, 0, 1);
1647 if ((status & 0xff00) != 0x7800)
1650 local->
new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
1658 mii_wr(ioaddr, 0, 0, control, 16);
1660 control = mii_rd(ioaddr, 0, 0);
1662 if (control & 0x0400) {
1663 netdev_notice(dev,
"can't take PHY out of isolation mode\n");
1673 for (i=0; i < 35; i++) {
1675 status = mii_rd(ioaddr, 0, 1);
1676 if ((status & 0x0020) && (status & 0x0004))
1680 if (!(status & 0x0020)) {
1681 netdev_info(dev,
"autonegotiation failed; using 10mbs\n");
1684 mii_wr(ioaddr, 0, 0, control, 16);
1690 linkpartner = mii_rd(ioaddr, 0, 5);
1691 netdev_info(dev,
"MII link partner: %04x\n", linkpartner);
1692 if (linkpartner & 0x0080) {
1708 pr_debug(
"do_powerdown(%p)\n", dev);
1720 struct pcmcia_device *link = lp->
p_dev;
1722 dev_dbg(&link->dev,
"do_stop(%p)\n", dev);
1727 netif_stop_queue(dev);
1742 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
1743 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
1744 PCMCIA_PFC_DEVICE_PROD_ID13(0,
"Xircom",
"CEM28", 0x2e3ee845, 0x0ea978ea),
1745 PCMCIA_PFC_DEVICE_PROD_ID13(0,
"Xircom",
"CEM33", 0x2e3ee845, 0x80609023),
1746 PCMCIA_PFC_DEVICE_PROD_ID13(0,
"Xircom",
"CEM56", 0x2e3ee845, 0xa650c32a),
1747 PCMCIA_PFC_DEVICE_PROD_ID13(0,
"Xircom",
"REM10", 0x2e3ee845, 0x76df1d29),
1748 PCMCIA_PFC_DEVICE_PROD_ID13(0,
"Xircom",
"XEM5600", 0x2e3ee845, 0xf1403719),
1749 PCMCIA_PFC_DEVICE_PROD_ID12(0,
"Xircom",
"CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
1750 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
1751 PCMCIA_DEVICE_PROD_ID13(
"Toshiba Information Systems",
"TPCENET", 0x1b3b94fe, 0xf381c1a2),
1752 PCMCIA_DEVICE_PROD_ID13(
"Xircom",
"CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
1753 PCMCIA_DEVICE_PROD_ID13(
"Xircom",
"PS-CE2-10", 0x2e3ee845, 0x947d9073),
1754 PCMCIA_DEVICE_PROD_ID13(
"Xircom",
"R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
1755 PCMCIA_DEVICE_PROD_ID13(
"Xircom",
"RE-10", 0x2e3ee845, 0x3e08d609),
1756 PCMCIA_DEVICE_PROD_ID13(
"Xircom",
"XE2000", 0x2e3ee845, 0xf7188e46),
1757 PCMCIA_DEVICE_PROD_ID12(
"Compaq",
"Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
1758 PCMCIA_DEVICE_PROD_ID12(
"Compaq",
"Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
1759 PCMCIA_DEVICE_PROD_ID12(
"Intel",
"EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
1760 PCMCIA_DEVICE_PROD_ID12(
"Toshiba",
"10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
1768 static struct pcmcia_driver xirc2ps_cs_driver = {
1770 .name =
"xirc2ps_cs",
1771 .probe = xirc2ps_probe,
1772 .remove = xirc2ps_detach,
1773 .id_table = xirc2ps_ids,
1774 .suspend = xirc2ps_suspend,
1775 .resume = xirc2ps_resume,
1779 init_xirc2ps_cs(
void)
1785 exit_xirc2ps_cs(
void)
1794 static int __init setup_xirc2ps_cs(
char *
str)
1798 int ints[10] = { -1 };
1802 #define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; }
1812 __setup(
"xirc2ps_cs=", setup_xirc2ps_cs);