Newer
Older
if (!send_pcb(dev, &adapter->tx_pcb)) {
adapter->busy = 0;
}
/* if this happens, we die */
if (test_and_set_bit(0, (void *) &adapter->dmaing))
printk(KERN_DEBUG "%s: tx: DMA %d in progress\n", dev->name, adapter->current_dma.direction);
adapter->current_dma.direction = 1;
adapter->current_dma.start_time = jiffies;
if ((unsigned long)(skb->data + nlen) >= MAX_DMA_ADDRESS || nlen != skb->len) {
skb_copy_from_linear_data(skb, adapter->dma_buffer, nlen);
memset(adapter->dma_buffer+skb->len, 0, nlen-skb->len);
target = isa_virt_to_bus(adapter->dma_buffer);
}
else {
target = isa_virt_to_bus(skb->data);
}
adapter->current_dma.skb = skb;
flags=claim_dma_lock();
disable_dma(dev->dma);
clear_dma_ff(dev->dma);
set_dma_mode(dev->dma, 0x48); /* dma memory -> io */
set_dma_addr(dev->dma, target);
set_dma_count(dev->dma, nlen);
outb_control(adapter->hcr_val | DMAE | TCEN, dev);
enable_dma(dev->dma);
release_dma_lock(flags);
if (elp_debug >= 3)
printk(KERN_DEBUG "%s: DMA transfer started\n", dev->name);
}
/*
* The upper layer thinks we timed out
*/
static void elp_timeout(struct net_device *dev)
{
int stat;
stat = inb_status(dev->base_addr);
printk(KERN_WARNING "%s: transmit timed out, lost %s?\n", dev->name, (stat & ACRF) ? "interrupt" : "command");
if (elp_debug >= 1)
printk(KERN_DEBUG "%s: status %#02x\n", dev->name, stat);
dev->trans_start = jiffies;
dev->stats.tx_dropped++;
netif_wake_queue(dev);
}
/******************************************************
*
* start the transmitter
* return 0 if sent OK, else return 1
*
******************************************************/
static int elp_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
unsigned long flags;
elp_device *adapter = netdev_priv(dev);
spin_lock_irqsave(&adapter->lock, flags);
check_3c505_dma(dev);
if (elp_debug >= 3)
printk(KERN_DEBUG "%s: request to send packet of length %d\n", dev->name, (int) skb->len);
netif_stop_queue(dev);
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
/*
* send the packet at skb->data for skb->len
*/
if (!send_packet(dev, skb)) {
if (elp_debug >= 2) {
printk(KERN_DEBUG "%s: failed to transmit packet\n", dev->name);
}
spin_unlock_irqrestore(&adapter->lock, flags);
return 1;
}
if (elp_debug >= 3)
printk(KERN_DEBUG "%s: packet of length %d sent\n", dev->name, (int) skb->len);
/*
* start the transmit timeout
*/
dev->trans_start = jiffies;
prime_rx(dev);
spin_unlock_irqrestore(&adapter->lock, flags);
netif_start_queue(dev);
return 0;
}
/******************************************************
*
* return statistics on the board
*
******************************************************/
static struct net_device_stats *elp_get_stats(struct net_device *dev)
{
elp_device *adapter = netdev_priv(dev);
if (elp_debug >= 3)
printk(KERN_DEBUG "%s: request for stats\n", dev->name);
/* If the device is closed, just return the latest stats we have,
- we cannot ask from the adapter without interrupts */
if (!netif_running(dev))
/* send a get statistics command to the board */
adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
adapter->tx_pcb.length = 0;
adapter->got[CMD_NETWORK_STATISTICS] = 0;
if (!send_pcb(dev, &adapter->tx_pcb))
printk(KERN_ERR "%s: couldn't send get statistics command\n", dev->name);
else {
unsigned long timeout = jiffies + TIMEOUT;
while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && time_before(jiffies, timeout));
if (time_after_eq(jiffies, timeout)) {
TIMEOUT_MSG(__LINE__);
}
}
/* statistics are now up to date */
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
}
static void netdev_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *info)
{
strcpy(info->driver, DRV_NAME);
strcpy(info->version, DRV_VERSION);
sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr);
}
static u32 netdev_get_msglevel(struct net_device *dev)
{
return debug;
}
static void netdev_set_msglevel(struct net_device *dev, u32 level)
{
debug = level;
}
static const struct ethtool_ops netdev_ethtool_ops = {
.get_drvinfo = netdev_get_drvinfo,
.get_msglevel = netdev_get_msglevel,
.set_msglevel = netdev_set_msglevel,
};
/******************************************************
*
* close the board
*
******************************************************/
static int elp_close(struct net_device *dev)
{
elp_device *adapter = netdev_priv(dev);
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
if (elp_debug >= 3)
printk(KERN_DEBUG "%s: request to close device\n", dev->name);
netif_stop_queue(dev);
/* Someone may request the device statistic information even when
* the interface is closed. The following will update the statistics
* structure in the driver, so we'll be able to give current statistics.
*/
(void) elp_get_stats(dev);
/*
* disable interrupts on the board
*/
outb_control(0, dev);
/*
* release the IRQ
*/
free_irq(dev->irq, dev);
free_dma(dev->dma);
free_pages((unsigned long) adapter->dma_buffer, get_order(DMA_BUFFER_SIZE));
return 0;
}
/************************************************************
*
* Set multicast list
* num_addrs==0: clear mc_list
* num_addrs==-1: set promiscuous mode
* num_addrs>0: set mc_list
*
************************************************************/
static void elp_set_mc_list(struct net_device *dev)
{
elp_device *adapter = netdev_priv(dev);
struct dev_mc_list *dmi = dev->mc_list;
int i;
unsigned long flags;
if (elp_debug >= 3)
printk(KERN_DEBUG "%s: request to set multicast list\n", dev->name);
spin_lock_irqsave(&adapter->lock, flags);
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
if (!(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) {
/* send a "load multicast list" command to the board, max 10 addrs/cmd */
/* if num_addrs==0 the list will be cleared */
adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
adapter->tx_pcb.length = 6 * dev->mc_count;
for (i = 0; i < dev->mc_count; i++) {
memcpy(adapter->tx_pcb.data.multicast[i], dmi->dmi_addr, 6);
dmi = dmi->next;
}
adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
if (!send_pcb(dev, &adapter->tx_pcb))
printk(KERN_ERR "%s: couldn't send set_multicast command\n", dev->name);
else {
unsigned long timeout = jiffies + TIMEOUT;
while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && time_before(jiffies, timeout));
if (time_after_eq(jiffies, timeout)) {
TIMEOUT_MSG(__LINE__);
}
}
if (dev->mc_count)
adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
else /* num_addrs == 0 */
adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
} else
adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_PROMISC;
/*
* configure adapter to receive messages (as specified above)
* and wait for response
*/
if (elp_debug >= 3)
printk(KERN_DEBUG "%s: sending 82586 configure command\n", dev->name);
adapter->tx_pcb.command = CMD_CONFIGURE_82586;
adapter->tx_pcb.length = 2;
adapter->got[CMD_CONFIGURE_82586] = 0;
if (!send_pcb(dev, &adapter->tx_pcb))
{
spin_unlock_irqrestore(&adapter->lock, flags);
printk(KERN_ERR "%s: couldn't send 82586 configure command\n", dev->name);
}
else {
unsigned long timeout = jiffies + TIMEOUT;
spin_unlock_irqrestore(&adapter->lock, flags);
while (adapter->got[CMD_CONFIGURE_82586] == 0 && time_before(jiffies, timeout));
if (time_after_eq(jiffies, timeout))
TIMEOUT_MSG(__LINE__);
}
}
/************************************************************
*
* A couple of tests to see if there's 3C505 or not
* Called only by elp_autodetect
************************************************************/
static int __init elp_sense(struct net_device *dev)
{
int addr = dev->base_addr;
const char *name = dev->name;
byte orig_HSR;
if (!request_region(addr, ELP_IO_EXTENT, "3c505"))
return -ENODEV;
orig_HSR = inb_status(addr);
if (elp_debug > 0)
printk(search_msg, name, addr);
if (orig_HSR == 0xff) {
if (elp_debug > 0)
printk(notfound_msg, 1);
goto out;
}
/* Wait for a while; the adapter may still be booting up */
if (elp_debug > 0)
printk(stilllooking_msg);
if (orig_HSR & DIR) {
/* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
outb(0, dev->base_addr + PORT_CONTROL);
msleep(300);
if (inb_status(addr) & DIR) {
if (elp_debug > 0)
printk(notfound_msg, 2);
goto out;
}
} else {
/* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
outb(DIR, dev->base_addr + PORT_CONTROL);
msleep(300);
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
if (!(inb_status(addr) & DIR)) {
if (elp_debug > 0)
printk(notfound_msg, 3);
goto out;
}
}
/*
* It certainly looks like a 3c505.
*/
if (elp_debug > 0)
printk(found_msg);
return 0;
out:
release_region(addr, ELP_IO_EXTENT);
return -ENODEV;
}
/*************************************************************
*
* Search through addr_list[] and try to find a 3C505
* Called only by eplus_probe
*************************************************************/
static int __init elp_autodetect(struct net_device *dev)
{
int idx = 0;
/* if base address set, then only check that address
otherwise, run through the table */
if (dev->base_addr != 0) { /* dev->base_addr == 0 ==> plain autodetect */
if (elp_sense(dev) == 0)
return dev->base_addr;
} else
while ((dev->base_addr = addr_list[idx++])) {
if (elp_sense(dev) == 0)
return dev->base_addr;
}
/* could not find an adapter */
if (elp_debug > 0)
printk(couldnot_msg, dev->name);
return 0; /* Because of this, the layer above will return -ENODEV */
}
static const struct net_device_ops elp_netdev_ops = {
.ndo_open = elp_open,
.ndo_stop = elp_close,
.ndo_get_stats = elp_get_stats,
.ndo_start_xmit = elp_start_xmit,
.ndo_tx_timeout = elp_timeout,
.ndo_set_multicast_list = elp_set_mc_list,
.ndo_change_mtu = eth_change_mtu,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
};
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
/******************************************************
*
* probe for an Etherlink Plus board at the specified address
*
******************************************************/
/* There are three situations we need to be able to detect here:
* a) the card is idle
* b) the card is still booting up
* c) the card is stuck in a strange state (some DOS drivers do this)
*
* In case (a), all is well. In case (b), we wait 10 seconds to see if the
* card finishes booting, and carry on if so. In case (c), we do a hard reset,
* loop round, and hope for the best.
*
* This is all very unpleasant, but hopefully avoids the problems with the old
* probe code (which had a 15-second delay if the card was idle, and didn't
* work at all if it was in a weird state).
*/
static int __init elplus_setup(struct net_device *dev)
{
elp_device *adapter = netdev_priv(dev);
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
int i, tries, tries1, okay;
unsigned long timeout;
unsigned long cookie = 0;
int err = -ENODEV;
/*
* setup adapter structure
*/
dev->base_addr = elp_autodetect(dev);
if (!dev->base_addr)
return -ENODEV;
adapter->send_pcb_semaphore = 0;
for (tries1 = 0; tries1 < 3; tries1++) {
outb_control((adapter->hcr_val | CMDE) & ~DIR, dev);
/* First try to write just one byte, to see if the card is
* responding at all normally.
*/
timeout = jiffies + 5*HZ/100;
okay = 0;
while (time_before(jiffies, timeout) && !(inb_status(dev->base_addr) & HCRE));
if ((inb_status(dev->base_addr) & HCRE)) {
outb_command(0, dev->base_addr); /* send a spurious byte */
timeout = jiffies + 5*HZ/100;
while (time_before(jiffies, timeout) && !(inb_status(dev->base_addr) & HCRE));
if (inb_status(dev->base_addr) & HCRE)
okay = 1;
}
if (!okay) {
/* Nope, it's ignoring the command register. This means that
* either it's still booting up, or it's died.
*/
printk(KERN_ERR "%s: command register wouldn't drain, ", dev->name);
if ((inb_status(dev->base_addr) & 7) == 3) {
/* If the adapter status is 3, it *could* still be booting.
* Give it the benefit of the doubt for 10 seconds.
*/
printk("assuming 3c505 still starting\n");
timeout = jiffies + 10*HZ;
while (time_before(jiffies, timeout) && (inb_status(dev->base_addr) & 7));
if (inb_status(dev->base_addr) & 7) {
printk(KERN_ERR "%s: 3c505 failed to start\n", dev->name);
} else {
okay = 1; /* It started */
}
} else {
/* Otherwise, it must just be in a strange
* state. We probably need to kick it.
*/
printk("3c505 is sulking\n");
}
}
for (tries = 0; tries < 5 && okay; tries++) {
/*
* Try to set the Ethernet address, to make sure that the board
* is working.
*/
adapter->tx_pcb.command = CMD_STATION_ADDRESS;
adapter->tx_pcb.length = 0;
cookie = probe_irq_on();
if (!send_pcb(dev, &adapter->tx_pcb)) {
printk(KERN_ERR "%s: could not send first PCB\n", dev->name);
probe_irq_off(cookie);
continue;
}
if (!receive_pcb(dev, &adapter->rx_pcb)) {
printk(KERN_ERR "%s: could not read first PCB\n", dev->name);
probe_irq_off(cookie);
continue;
}
if ((adapter->rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
(adapter->rx_pcb.length != 6)) {
printk(KERN_ERR "%s: first PCB wrong (%d, %d)\n", dev->name, adapter->rx_pcb.command, adapter->rx_pcb.length);
probe_irq_off(cookie);
continue;
}
goto okay;
}
/* It's broken. Do a hard reset to re-initialise the board,
* and try again.
*/
printk(KERN_INFO "%s: resetting adapter\n", dev->name);
outb_control(adapter->hcr_val | FLSH | ATTN, dev);
outb_control(adapter->hcr_val & ~(FLSH | ATTN), dev);
}
printk(KERN_ERR "%s: failed to initialise 3c505\n", dev->name);
goto out;
okay:
if (dev->irq) { /* Is there a preset IRQ? */
int rpt = probe_irq_off(cookie);
if (dev->irq != rpt) {
printk(KERN_WARNING "%s: warning, irq %d configured but %d detected\n", dev->name, dev->irq, rpt);
}
/* if dev->irq == probe_irq_off(cookie), all is well */
} else /* No preset IRQ; just use what we can detect */
dev->irq = probe_irq_off(cookie);
switch (dev->irq) { /* Legal, sane? */
case 0:
printk(KERN_ERR "%s: IRQ probe failed: check 3c505 jumpers.\n",
dev->name);
goto out;
case 1:
case 6:
case 8:
case 13:
printk(KERN_ERR "%s: Impossible IRQ %d reported by probe_irq_off().\n",
dev->name, dev->irq);
goto out;
}
/*
* Now we have the IRQ number so we can disable the interrupts from
* the board until the board is opened.
*/
outb_control(adapter->hcr_val & ~CMDE, dev);
/*
* copy Ethernet address into structure
*/
for (i = 0; i < 6; i++)
dev->dev_addr[i] = adapter->rx_pcb.data.eth_addr[i];
/* find a DMA channel */
if (!dev->dma) {
if (dev->mem_start) {
dev->dma = dev->mem_start & 7;
}
else {
printk(KERN_WARNING "%s: warning, DMA channel not specified, using default\n", dev->name);
dev->dma = ELP_DMA;
}
}
/*
* print remainder of startup message
*/
printk(KERN_INFO "%s: 3c505 at %#lx, irq %d, dma %d, "
dev->name, dev->base_addr, dev->irq, dev->dma,
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
/*
* read more information from the adapter
*/
adapter->tx_pcb.command = CMD_ADAPTER_INFO;
adapter->tx_pcb.length = 0;
if (!send_pcb(dev, &adapter->tx_pcb) ||
!receive_pcb(dev, &adapter->rx_pcb) ||
(adapter->rx_pcb.command != CMD_ADAPTER_INFO_RESPONSE) ||
(adapter->rx_pcb.length != 10)) {
printk("not responding to second PCB\n");
}
printk("rev %d.%d, %dk\n", adapter->rx_pcb.data.info.major_vers, adapter->rx_pcb.data.info.minor_vers, adapter->rx_pcb.data.info.RAM_sz);
/*
* reconfigure the adapter memory to better suit our purposes
*/
adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
adapter->tx_pcb.length = 12;
adapter->tx_pcb.data.memconf.cmd_q = 8;
adapter->tx_pcb.data.memconf.rcv_q = 8;
adapter->tx_pcb.data.memconf.mcast = 10;
adapter->tx_pcb.data.memconf.frame = 10;
adapter->tx_pcb.data.memconf.rcv_b = 10;
adapter->tx_pcb.data.memconf.progs = 0;
if (!send_pcb(dev, &adapter->tx_pcb) ||
!receive_pcb(dev, &adapter->rx_pcb) ||
(adapter->rx_pcb.command != CMD_CONFIGURE_ADAPTER_RESPONSE) ||
(adapter->rx_pcb.length != 2)) {
printk(KERN_ERR "%s: could not configure adapter memory\n", dev->name);
}
if (adapter->rx_pcb.data.configure) {
printk(KERN_ERR "%s: adapter configuration failed\n", dev->name);
}
dev->netdev_ops = &elp_netdev_ops;
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
dev->watchdog_timeo = 10*HZ;
dev->ethtool_ops = &netdev_ethtool_ops; /* local */
dev->mem_start = dev->mem_end = 0;
err = register_netdev(dev);
if (err)
goto out;
return 0;
out:
release_region(dev->base_addr, ELP_IO_EXTENT);
return err;
}
#ifndef MODULE
struct net_device * __init elplus_probe(int unit)
{
struct net_device *dev = alloc_etherdev(sizeof(elp_device));
int err;
if (!dev)
return ERR_PTR(-ENOMEM);
sprintf(dev->name, "eth%d", unit);
netdev_boot_setup_check(dev);
err = elplus_setup(dev);
if (err) {
free_netdev(dev);
return ERR_PTR(err);
}
return dev;
}
#else
static struct net_device *dev_3c505[ELP_MAX_CARDS];
static int io[ELP_MAX_CARDS];
static int irq[ELP_MAX_CARDS];
static int dma[ELP_MAX_CARDS];
module_param_array(io, int, NULL, 0);
module_param_array(irq, int, NULL, 0);
module_param_array(dma, int, NULL, 0);
MODULE_PARM_DESC(io, "EtherLink Plus I/O base address(es)");
MODULE_PARM_DESC(irq, "EtherLink Plus IRQ number(s) (assigned)");
MODULE_PARM_DESC(dma, "EtherLink Plus DMA channel(s)");
int __init init_module(void)
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
{
int this_dev, found = 0;
for (this_dev = 0; this_dev < ELP_MAX_CARDS; this_dev++) {
struct net_device *dev = alloc_etherdev(sizeof(elp_device));
if (!dev)
break;
dev->irq = irq[this_dev];
dev->base_addr = io[this_dev];
if (dma[this_dev]) {
dev->dma = dma[this_dev];
} else {
dev->dma = ELP_DMA;
printk(KERN_WARNING "3c505.c: warning, using default DMA channel,\n");
}
if (io[this_dev] == 0) {
if (this_dev) {
free_netdev(dev);
break;
}
printk(KERN_NOTICE "3c505.c: module autoprobe not recommended, give io=xx.\n");
}
if (elplus_setup(dev) != 0) {
printk(KERN_WARNING "3c505.c: Failed to register card at 0x%x.\n", io[this_dev]);
free_netdev(dev);
break;
}
dev_3c505[this_dev] = dev;
found++;
}
if (!found)
return -ENODEV;
return 0;
}
void __exit cleanup_module(void)
{
int this_dev;
for (this_dev = 0; this_dev < ELP_MAX_CARDS; this_dev++) {
struct net_device *dev = dev_3c505[this_dev];
if (dev) {
unregister_netdev(dev);
release_region(dev->base_addr, ELP_IO_EXTENT);
free_netdev(dev);
}
}
}
#endif /* MODULE */
MODULE_LICENSE("GPL");