114 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
116 #define DRV_NAME "nmclan_cs"
117 #define DRV_VERSION "0.16"
125 #define RESET_ON_TIMEOUT 1
126 #define TX_INTERRUPTABLE 1
127 #define RESET_XILINX 0
133 #include <linux/module.h>
134 #include <linux/kernel.h>
136 #include <linux/ptrace.h>
137 #include <linux/slab.h>
138 #include <linux/string.h>
141 #include <linux/in.h>
143 #include <linux/ethtool.h>
144 #include <linux/netdevice.h>
147 #include <linux/if_arp.h>
149 #include <linux/bitops.h>
155 #include <asm/uaccess.h>
162 #define MACE_LADRF_LEN 8
166 #define MACE_MAX_IR_ITERATIONS 10
167 #define MACE_MAX_RX_ITERATIONS 12
183 #define AM2150_MAX_TX_FRAMES 4
184 #define AM2150_MAX_RX_FRAMES 12
187 #define AM2150_RCV 0x00
188 #define AM2150_XMT 0x04
189 #define AM2150_XMT_SKIP 0x09
190 #define AM2150_RCV_NEXT 0x0A
191 #define AM2150_RCV_FRAME_COUNT 0x0B
192 #define AM2150_MACE_BANK 0x0C
193 #define AM2150_MACE_BASE 0x10
196 #define MACE_RCVFIFO 0
197 #define MACE_XMTFIFO 1
203 #define MACE_FIFOFC 7
207 #define MACE_BIUCC 11
208 #define MACE_FIFOCC 12
209 #define MACE_MACCC 13
210 #define MACE_PLSCC 14
211 #define MACE_PHYCC 15
212 #define MACE_CHIPIDL 16
213 #define MACE_CHIPIDH 17
216 #define MACE_LADRF 20
222 #define MACE_RNTPC 26
223 #define MACE_RCVCC 27
230 #define MACE_XMTRC_EXDEF 0x80
231 #define MACE_XMTRC_XMTRC 0x0F
233 #define MACE_XMTFS_XMTSV 0x80
234 #define MACE_XMTFS_UFLO 0x40
235 #define MACE_XMTFS_LCOL 0x20
236 #define MACE_XMTFS_MORE 0x10
237 #define MACE_XMTFS_ONE 0x08
238 #define MACE_XMTFS_DEFER 0x04
239 #define MACE_XMTFS_LCAR 0x02
240 #define MACE_XMTFS_RTRY 0x01
242 #define MACE_RCVFS_RCVSTS 0xF000
243 #define MACE_RCVFS_OFLO 0x8000
244 #define MACE_RCVFS_CLSN 0x4000
245 #define MACE_RCVFS_FRAM 0x2000
246 #define MACE_RCVFS_FCS 0x1000
248 #define MACE_FIFOFC_RCVFC 0xF0
249 #define MACE_FIFOFC_XMTFC 0x0F
251 #define MACE_IR_JAB 0x80
252 #define MACE_IR_BABL 0x40
253 #define MACE_IR_CERR 0x20
254 #define MACE_IR_RCVCCO 0x10
255 #define MACE_IR_RNTPCO 0x08
256 #define MACE_IR_MPCO 0x04
257 #define MACE_IR_RCVINT 0x02
258 #define MACE_IR_XMTINT 0x01
260 #define MACE_MACCC_PROM 0x80
261 #define MACE_MACCC_DXMT2PD 0x40
262 #define MACE_MACCC_EMBA 0x20
263 #define MACE_MACCC_RESERVED 0x10
264 #define MACE_MACCC_DRCVPA 0x08
265 #define MACE_MACCC_DRCVBC 0x04
266 #define MACE_MACCC_ENXMT 0x02
267 #define MACE_MACCC_ENRCV 0x01
269 #define MACE_PHYCC_LNKFL 0x80
270 #define MACE_PHYCC_DLNKTST 0x40
271 #define MACE_PHYCC_REVPOL 0x20
272 #define MACE_PHYCC_DAPC 0x10
273 #define MACE_PHYCC_LRT 0x08
274 #define MACE_PHYCC_ASEL 0x04
275 #define MACE_PHYCC_RWAKE 0x02
276 #define MACE_PHYCC_AWAKE 0x01
278 #define MACE_IAC_ADDRCHG 0x80
279 #define MACE_IAC_PHYADDR 0x04
280 #define MACE_IAC_LOGADDR 0x02
282 #define MACE_UTR_RTRE 0x80
283 #define MACE_UTR_RTRD 0x40
284 #define MACE_UTR_RPA 0x20
285 #define MACE_UTR_FCOLL 0x10
286 #define MACE_UTR_RCVFCSE 0x08
287 #define MACE_UTR_LOOP_INCL_MENDEC 0x06
288 #define MACE_UTR_LOOP_NO_MENDEC 0x04
289 #define MACE_UTR_LOOP_EXTERNAL 0x02
290 #define MACE_UTR_LOOP_NONE 0x00
291 #define MACE_UTR_RESERVED 0x01
294 #define MACEBANK(win_num) outb((win_num), ioaddr + AM2150_MACE_BANK)
296 #define MACE_IMR_DEFAULT \
307 #undef MACE_IMR_DEFAULT
308 #define MACE_IMR_DEFAULT 0x00
310 #define TX_TIMEOUT ((400*HZ)/1000)
380 static const char *if_names[]={
381 "Auto",
"10baseT",
"BNC",
393 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
403 static int nmclan_config(
struct pcmcia_device *
link);
404 static void nmclan_release(
struct pcmcia_device *
link);
415 static int mace_rx(
struct net_device *
dev,
unsigned char RxCnt);
418 static const struct ethtool_ops netdev_ethtool_ops;
421 static void nmclan_detach(
struct pcmcia_device *p_dev);
424 .ndo_open = mace_open,
425 .ndo_stop = mace_close,
426 .ndo_start_xmit = mace_start_xmit,
427 .ndo_tx_timeout = mace_tx_timeout,
428 .ndo_set_config = mace_config,
429 .ndo_get_stats = mace_get_stats,
430 .ndo_set_rx_mode = set_multicast_list,
436 static int nmclan_probe(
struct pcmcia_device *
link)
441 dev_dbg(&link->dev,
"nmclan_attach()\n");
447 lp = netdev_priv(dev);
452 link->resource[0]->end = 32;
453 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
454 link->config_flags |= CONF_ENABLE_IRQ;
455 link->config_index = 1;
456 link->config_regs = PRESENT_OPTION;
464 return nmclan_config(link);
467 static void nmclan_detach(
struct pcmcia_device *link)
471 dev_dbg(&link->dev,
"nmclan_detach\n");
475 nmclan_release(link);
501 spin_unlock_irqrestore(&lp->
bank_lock, flags);
514 static void mace_write(
mace_private *lp,
unsigned int ioaddr,
int reg,
528 spin_unlock_irqrestore(&lp->
bank_lock, flags);
537 static int mace_init(
mace_private *lp,
unsigned int ioaddr,
char *enet_addr)
544 while (mace_read(lp, ioaddr,
MACE_BIUCC) & 0x01) {
548 pr_err(
"reset failed, card removed?\n");
559 mace_write(lp, ioaddr,
MACE_IMR, 0xFF);
595 pr_err(
"ADDRCHG timeout, card removed?\n");
601 mace_write(lp, ioaddr,
MACE_PADR, enet_addr[i]);
610 static int nmclan_config(
struct pcmcia_device *link)
619 dev_dbg(&link->dev,
"nmclan_config\n");
625 ret = pcmcia_request_exclusive_irq(link, mace_interrupt);
632 dev->
irq = link->irq;
633 dev->
base_addr = link->resource[0]->start;
638 len = pcmcia_get_tuple(link, 0x80, &buf);
639 if (!buf || len < ETH_ALEN) {
652 if ((sig[0] == 0x40) && ((sig[1] & 0x0F) == 0x09)) {
653 dev_dbg(&link->dev,
"nmclan_cs configured: mace id=%x %x\n",
656 pr_notice(
"mace id not found: %x %x should be 0x40 0x?9\n",
662 if(mace_init(lp, ioaddr, dev->
dev_addr) == -1)
669 pr_notice(
"invalid if_port requested\n");
679 netdev_info(dev,
"nmclan: port %#3lx, irq %d, %s port, hw_addr %pM\n",
684 nmclan_release(link);
688 static void nmclan_release(
struct pcmcia_device *link)
690 dev_dbg(&link->dev,
"nmclan_release\n");
694 static int nmclan_suspend(
struct pcmcia_device *link)
704 static int nmclan_resume(
struct pcmcia_device *link)
721 static void nmclan_reset(
struct net_device *dev)
726 struct pcmcia_device *link = &lp->link;
733 dev_dbg(&link->dev,
"nmclan_reset: OrigCorValue=0x%x, resetting...\n",
754 restore_multicast_list(dev);
766 if (map->
port <= 2) {
768 netdev_info(dev,
"switched to %s port\n", if_names[dev->
if_port]);
783 struct pcmcia_device *link = lp->
p_dev;
792 netif_start_queue(dev);
806 struct pcmcia_device *link = lp->
p_dev;
808 dev_dbg(&link->dev,
"%s: shutting down ethercard.\n", dev->
name);
814 netif_stop_queue(dev);
819 static void netdev_get_drvinfo(
struct net_device *dev,
828 static const struct ethtool_ops netdev_ethtool_ops = {
829 .get_drvinfo = netdev_get_drvinfo,
843 static void mace_tx_timeout(
struct net_device *dev)
846 struct pcmcia_device *link = lp->
p_dev;
848 netdev_notice(dev,
"transmit timed out -- ");
853 pr_cont(
"NOT resetting card\n");
856 netif_wake_queue(dev);
865 netif_stop_queue(dev);
867 pr_debug(
"%s: mace_start_xmit(length = %ld) called.\n",
870 #if (!TX_INTERRUPTABLE)
899 netif_start_queue(dev);
903 #if (!TX_INTERRUPTABLE)
927 pr_debug(
"mace_interrupt(): irq 0x%X for unknown device.\n",
937 msg =
"Interrupt with tx_irq_disabled";
939 msg =
"Re-entering the interrupt handler";
940 netdev_notice(dev,
"%s [isr=%02X, imr=%02X]\n",
948 if (!netif_device_present(dev)) {
949 netdev_dbg(dev,
"interrupt from dead card\n");
957 pr_debug(
"mace_interrupt: irq 0x%X status 0x%X.\n", irq, status);
964 unsigned char fifofc;
1021 netif_wake_queue(dev);
1062 static int mace_rx(
struct net_device *dev,
unsigned char RxCnt)
1066 unsigned char rx_framecnt;
1071 (rx_framecnt <= 12) &&
1076 pr_debug(
"%s: in mace_rx(), framecnt 0x%X, rx_status"
1077 " 0x%X.\n", dev->
name, rx_framecnt, rx_status);
1094 short pkt_len = (rx_status & ~MACE_RCVFS_RCVSTS) - 4;
1103 pr_debug(
" receiving packet size 0x%X rx_status"
1104 " 0x%X.\n", pkt_len, rx_status);
1106 skb = netdev_alloc_skb(dev, pkt_len + 2);
1109 skb_reserve(skb, 2);
1122 pr_debug(
"%s: couldn't allocate a sk_buff of size"
1123 " %d.\n", dev->
name, pkt_len);
1139 pr_debug(
" rx_packets=%-7ld tx_packets=%ld\n",
1141 pr_debug(
" rx_errors=%-7ld tx_errors=%ld\n",
1143 pr_debug(
" rx_dropped=%-7ld tx_dropped=%ld\n",
1145 pr_debug(
" multicast=%-7ld collisions=%ld\n",
1148 pr_debug(
" rx_length_errors=%-7ld rx_over_errors=%ld\n",
1150 pr_debug(
" rx_crc_errors=%-7ld rx_frame_errors=%ld\n",
1152 pr_debug(
" rx_fifo_errors=%-7ld rx_missed_errors=%ld\n",
1155 pr_debug(
" tx_aborted_errors=%-7ld tx_carrier_errors=%ld\n",
1157 pr_debug(
" tx_fifo_errors=%-7ld tx_heartbeat_errors=%ld\n",
1159 pr_debug(
" tx_window_errors=%ld\n",
1191 pr_debug(
" rfs_rntpc=%-7d rfs_rcvcc=%d\n",
1226 static void update_stats(
unsigned int ioaddr,
struct net_device *dev)
1288 #ifdef BROKEN_MULTICAST
1290 static void updateCRC(
int *
CRC,
int bit)
1292 static const int poly[]={
1303 for (j = 32; j > 0; j--)
1309 for (j = 0; j < 32; j++)
1322 static void BuildLAF(
int *ladrf,
int *adr)
1331 for (byte = 0; byte < 6; byte++)
1332 for (i = 0; i < 8; i++)
1333 updateCRC(CRC, (adr[byte] >> i) & 1);
1336 for (i = 0; i < 6; i++)
1337 hashcode = (hashcode << 1) + CRC[
i];
1339 byte = hashcode >> 3;
1340 ladrf[
byte] |= (1 << (hashcode & 7));
1346 for (i = 0; i < 8; i++)
1361 static void restore_multicast_list(
struct net_device *dev)
1369 pr_debug(
"%s: restoring Rx mode to %d addresses.\n",
1370 dev->
name, num_addrs);
1372 if (num_addrs > 0) {
1374 pr_debug(
"Attempt to restore multicast list detected.\n");
1378 while (mace_read(lp, ioaddr,
MACE_IAC) & MACE_IAC_ADDRCHG)
1382 mace_write(lp, ioaddr,
MACE_LADRF, ladrf[i]);
1387 }
else if (num_addrs < 0) {
1418 static void set_multicast_list(
struct net_device *dev)
1429 pr_debug(
"%s: setting Rx mode to %d addresses.\n",
1439 if (num_addrs > 0) {
1448 restore_multicast_list(dev);
1454 static void restore_multicast_list(
struct net_device *dev)
1459 pr_debug(
"%s: restoring Rx mode to %d addresses.\n", dev->
name,
1475 static void set_multicast_list(
struct net_device *dev)
1484 pr_debug(
"%s: setting Rx mode to %d addresses.\n",
1491 restore_multicast_list(dev);
1496 PCMCIA_DEVICE_PROD_ID12(
"New Media Corporation",
"Ethernet", 0x085a850b, 0x00b2e941),
1497 PCMCIA_DEVICE_PROD_ID12(
"Portable Add-ons",
"Ethernet+", 0xebf1d60, 0xad673aaf),
1502 static struct pcmcia_driver nmclan_cs_driver = {
1504 .name =
"nmclan_cs",
1505 .probe = nmclan_probe,
1506 .remove = nmclan_detach,
1507 .id_table = nmclan_ids,
1508 .suspend = nmclan_suspend,
1509 .resume = nmclan_resume,
1512 static int __init init_nmclan_cs(
void)
1517 static void __exit exit_nmclan_cs(
void)